fix import cache updates

This commit fixes a bug in the import where the cache was not being
updated and the block checksum was not being invalidated.
This commit is contained in:
Ben Johnson 2016-05-11 17:32:28 -06:00
parent 736b4f8b17
commit a206d55834
No known key found for this signature in database
GPG key ID: CBD06EAD6DFD9529
2 changed files with 13 additions and 2 deletions

View file

@ -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)
}

View file

@ -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 {