From 57c30b9dae0907e5103a5b59dc418ab5c8cde4dc Mon Sep 17 00:00:00 2001 From: Travis Date: Thu, 19 Mar 2020 11:11:33 -0500 Subject: [PATCH] support mutex/bool fields in anti-entropy --- api.go | 6 ------ field.go | 18 ++++++++++-------- holder_test.go | 18 +++++++++++++++++- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/api.go b/api.go index ba4482c11..63d249c16 100644 --- a/api.go +++ b/api.go @@ -415,12 +415,6 @@ func (api *API) ImportRoaring(ctx context.Context, indexName, fieldName string, return newNotFoundError(ErrFieldNotFound) } - // only set and time fields are supported - // TODO: get rid of this (need to confirm other field types) - if field.Type() != FieldTypeSet && field.Type() != FieldTypeTime && field.Type() != FieldTypeInt && field.Type() != FieldTypeDecimal { - return NewBadRequestError(errors.Errorf("roaring import is only supported for set, time, int, and decimal fields, not '%s' fields.", field.Type())) - } - errCh := make(chan error, len(nodes)) for _, node := range nodes { diff --git a/field.go b/field.go index 046159c76..96ccfa278 100644 --- a/field.go +++ b/field.go @@ -1084,17 +1084,19 @@ func (f *Field) deleteView(name string) error { // Row returns a row of the standard view. // It seems this method is only being used by the test // package, and the fact that it's only allowed on -// `set` fields is odd. This may be considered for -// deprecation in a future version. +// `set`,`mutex`, and `bool` fields is odd. This may +// be considered for deprecation in a future version. func (f *Field) Row(rowID uint64) (*Row, error) { - if f.Type() != FieldTypeSet { + switch f.Type() { + case FieldTypeSet, FieldTypeMutex, FieldTypeBool: + view := f.view(viewStandard) + if view == nil { + return nil, ErrInvalidView + } + return view.row(rowID), nil + default: return nil, errors.Errorf("row method unsupported for field type: %s", f.Type()) } - view := f.view(viewStandard) - if view == nil { - return nil, ErrInvalidView - } - return view.row(rowID), nil } // SetBit sets a bit on a view within the field. diff --git a/holder_test.go b/holder_test.go index cc14798fa..d9d11f3f6 100644 --- a/holder_test.go +++ b/holder_test.go @@ -409,10 +409,14 @@ func TestHolderSyncer_SyncHolder(t *testing.T) { if err != nil { t.Fatalf("creating field f0: %v", err) } - _, err = c[0].API.CreateField(context.Background(), "y", "z", pilosa.OptFieldTypeSet(pilosa.DefaultCacheType, pilosa.DefaultCacheSize)) + _, err = c[0].API.CreateField(context.Background(), "y", "z", pilosa.OptFieldTypeMutex(pilosa.DefaultCacheType, pilosa.DefaultCacheSize)) if err != nil { t.Fatalf("creating field z in y: %v", err) } + _, err = c[0].API.CreateField(context.Background(), "y", "b", pilosa.OptFieldTypeBool()) + if err != nil { + t.Fatalf("creating field b in y: %v", err) + } hldr0 := &test.Holder{Holder: c[0].Server.Holder()} hldr1 := &test.Holder{Holder: c[1].Server.Holder()} @@ -427,6 +431,7 @@ func TestHolderSyncer_SyncHolder(t *testing.T) { // Set a bit to create the fragment. hldr0.SetBit("y", "z", 0, 0) + hldr0.SetBit("y", "b", 0, 0) // rowID = 0 means false // Set data on the remote holder. hldr1.SetBit("i", "f", 0, 4000) @@ -437,6 +442,10 @@ func TestHolderSyncer_SyncHolder(t *testing.T) { hldr1.SetBit("y", "z", 10, (3*ShardWidth)+5) hldr1.SetBit("y", "z", 10, (3*ShardWidth)+7) + hldr1.SetBit("y", "b", 1, (3*ShardWidth)+4) // true + hldr1.SetBit("y", "b", 0, (3*ShardWidth)+5) // false + hldr1.SetBit("y", "b", 1, (3*ShardWidth)+7) // true + err = c[0].Server.SyncData() if err != nil { t.Fatalf("syncing node 0: %v", err) @@ -471,6 +480,13 @@ func TestHolderSyncer_SyncHolder(t *testing.T) { if a := hldr.Row("y", "z", 10).Columns(); !reflect.DeepEqual(a, []uint64{(3 * ShardWidth) + 4, (3 * ShardWidth) + 5, (3 * ShardWidth) + 7}) { t.Errorf("unexpected columns(%d/y/z): %+v", i, a) } + + if a := hldr.Row("y", "b", 0).Columns(); !reflect.DeepEqual(a, []uint64{0, (3 * ShardWidth) + 5}) { + t.Errorf("unexpected false columns(%d/y/b): %+v", i, a) + } + if a := hldr.Row("y", "b", 1).Columns(); !reflect.DeepEqual(a, []uint64{(3 * ShardWidth) + 4, (3 * ShardWidth) + 7}) { + t.Errorf("unexpected true columns(%d/y/b): %+v", i, a) + } } }