mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-06 00:25:55 +00:00
Merge pull request #78 from benbjohnson/import-cache
Fix import cache updates
This commit is contained in:
commit
d76aa17e9c
2 changed files with 13 additions and 2 deletions
|
|
@ -14,6 +14,10 @@ func TestClient_Import(t *testing.T) {
|
|||
idx := MustOpenIndex()
|
||||
defer idx.Close()
|
||||
|
||||
// Load bitmap into cache to ensure cache gets updated.
|
||||
f := idx.MustCreateFragmentIfNotExists("d", "f", 0)
|
||||
f.Bitmap(0)
|
||||
|
||||
s := NewServer()
|
||||
defer s.Close()
|
||||
s.Handler.Host = s.Host()
|
||||
|
|
@ -32,7 +36,6 @@ func TestClient_Import(t *testing.T) {
|
|||
}
|
||||
|
||||
// Verify data.
|
||||
f := idx.MustCreateFragmentIfNotExists("d", "f", 0)
|
||||
if a := f.Bitmap(0).Bits(); !reflect.DeepEqual(a, []uint64{1, 5}) {
|
||||
t.Fatalf("unexpected bits: %+v", a)
|
||||
}
|
||||
|
|
|
|||
10
fragment.go
10
fragment.go
|
|
@ -827,8 +827,10 @@ func (f *Fragment) Import(bitmapIDs, profileIDs []uint64) error {
|
|||
// If an error occurs then reopen the storage.
|
||||
if err := func() error {
|
||||
for i := range bitmapIDs {
|
||||
bitmapID, profileID := bitmapIDs[i], profileIDs[i]
|
||||
|
||||
// Determine the position of the bit in the storage.
|
||||
pos, err := f.pos(bitmapIDs[i], profileIDs[i])
|
||||
pos, err := f.pos(bitmapID, profileID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -837,6 +839,12 @@ func (f *Fragment) Import(bitmapIDs, profileIDs []uint64) error {
|
|||
if _, err := f.storage.Add(pos); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Invalidate block checksum.
|
||||
delete(f.checksums, int(bitmapID/HashBlockSize))
|
||||
|
||||
// Update the cache.
|
||||
f.bitmap(bitmapID).SetBit(profileID)
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue