Cache BitDepth on bsiGroup during index.Open.

Before this change, we were only caching the BitDepth on the
field.options. This was ok as long as applyOptions() was called after
that. But unfortunately, during startup, applyOptions() was called prior
to that being set. So with this commit, we explicitly set the value in
bsiGroup.BitDepth as well.
This commit is contained in:
Travis 2021-03-12 16:32:32 -06:00
parent 9b3cce619a
commit 314cf3461d
No known key found for this signature in database
GPG key ID: 37080CC2042BA34E
3 changed files with 40 additions and 3 deletions

View file

@ -730,6 +730,23 @@ func (f *Field) bitDepth() (uint64, error) {
return maxBitDepth, nil
}
// cacheBitDepth is used by Index.setFieldBitDepths() to updated the in-memory
// bitDepth values for each field and its bsiGroup.
func (f *Field) cacheBitDepth(bd uint64) error {
// Get the assocated bsiGroup so that its bitDepth can be updated as well.
bsig := f.bsiGroup(f.name)
f.mu.Lock()
defer f.mu.Unlock()
f.options.BitDepth = bd
if bsig != nil {
bsig.BitDepth = bd
}
return nil
}
// openViews opens and initializes the views inside the field.
func (f *Field) openViews() error {
view2shards := f.idx.fieldView2shard.getViewsForField(f.name)

View file

@ -950,6 +950,16 @@ func TestField_SaveMeta(t *testing.T) {
t.Fatalf("expected BitDepth after set to be: %d, got: %d", expBitDepth, f.options.BitDepth)
}
tx2 := f.idx.holder.txf.NewTx(Txo{Index: f.idx, Field: f.Field, Shard: 0})
defer tx2.Rollback()
if rslt, ok, err := f.Value(tx2, colID); err != nil {
t.Fatal(err)
} else if !ok {
t.Fatal("expected Value() to return exists = true")
} else if rslt != val {
t.Fatalf("expected value to be: %d, got: %d", val, rslt)
}
// Reload field and verify that it is persisted.
if err := f.Reopen(); err != nil {
t.Fatal(err)
@ -958,4 +968,14 @@ func TestField_SaveMeta(t *testing.T) {
if f.options.BitDepth != expBitDepth {
t.Fatalf("expected BitDepth after reopen to be: %d, got: %d", expBitDepth, f.options.BitDepth)
}
tx3 := f.idx.holder.txf.NewTx(Txo{Index: f.idx, Field: f.Field, Shard: 0})
defer tx3.Rollback()
if rslt, ok, err := f.Value(tx3, colID); err != nil {
t.Fatal(err)
} else if !ok {
t.Fatal("expected Value() after reopen to return exists = true")
} else if rslt != val {
t.Fatalf("expected value after reopen to be: %d, got: %d", val, rslt)
}
}

View file

@ -438,9 +438,9 @@ func (i *Index) setFieldBitDepths() error {
if err != nil {
return errors.Wrapf(err, "getting bit depth for field: %s", name)
}
f.mu.Lock()
f.options.BitDepth = bd
f.mu.Unlock()
if err := f.cacheBitDepth(bd); err != nil {
return errors.Wrapf(err, "caching field bitDepth: %d", bd)
}
}
return nil
}