Merge pull request #1529 from travisturner/cache-bitdepth

[Core-370] Cache BitDepth on bsiGroup during index.Open
This commit is contained in:
Matthew Jaffee 2021-03-15 07:38:05 -05:00 committed by GitHub
commit c6ea56bbad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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
}