diff --git a/client_test.go b/client_test.go index ee5ae7c25..569caa6ba 100644 --- a/client_test.go +++ b/client_test.go @@ -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) } diff --git a/fragment.go b/fragment.go index 55f80c15c..1770d25c3 100644 --- a/fragment.go +++ b/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 {