mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-05 08:10:50 +00:00
Merge pull request #1529 from travisturner/cache-bitdepth
[Core-370] Cache BitDepth on bsiGroup during index.Open
This commit is contained in:
commit
c6ea56bbad
3 changed files with 40 additions and 3 deletions
17
field.go
17
field.go
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
6
index.go
6
index.go
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue