Merge pull request #89 from tgruben/bug-q2-double-delete

bit remove leaves internals corrupt on empty edge case
This commit is contained in:
tgruben 2020-01-12 16:25:31 -06:00 committed by GitHub
commit ba70bf3079
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 1 deletions

View file

@ -3576,3 +3576,47 @@ func TestFragmentConcurrentReadWrite(t *testing.T) {
t.Logf("%d", acc)
}
func TestFragment_Bug_Q2DoubleDelete(t *testing.T) {
f := mustOpenFragment("i", "f", viewStandard, 0, "")
b := []byte{60, 48, 0, 0, 1, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 24, 0, 0, 0, 1, 0}
defer f.Clean(t)
err := f.importRoaringT(b, false)
if err != nil {
t.Fatalf("importing roaring: %v", err)
}
//check the bit
res := f.row(1).Columns()
if len(res) < 1 || f.row(1).Columns()[0] != 1 {
t.Fatalf("expecting 1 got: %v", res)
}
//clear the bit
changed, _ := f.clearBit(1, 1)
if !changed {
t.Fatalf("expected change got %v", changed)
}
//check missing
res = f.row(1).Columns()
if len(res) != 0 {
t.Fatalf("expected nothing got %v", res)
}
// import again
err = f.importRoaringT(b, false)
if err != nil {
t.Fatalf("importing roaring: %v", err)
}
//check
res = f.row(1).Columns()
if len(res) < 1 || f.row(1).Columns()[0] != 1 {
t.Fatalf("again expecting 1 got: %v", res)
}
changed, _ = f.clearBit(1, 1)
if !changed {
t.Fatalf("again expected change got %v", changed)
}
//check missing
res = f.row(1).Columns()
if len(res) != 0 {
t.Fatalf("expected nothing got %v", res)
}
}

View file

@ -422,7 +422,11 @@ func (b *Bitmap) remove(v uint64) bool {
c := b.Containers.Get(highbits(v))
newC, changed := c.remove(lowbits(v))
if newC != c {
b.Containers.Put(highbits(v), newC)
if newC != nil {
b.Containers.Put(highbits(v), newC)
} else {
b.Containers.Remove(highbits(v))
}
}
return changed
}