Skip to content

Commit

Permalink
colblk: fix summary table bounds
Browse files Browse the repository at this point in the history
Fix an off-by-one on the summary table end bound. This could cause SeekSetBitGE
to return the wrong index in bitmaps with more than 4096 represented bits.
  • Loading branch information
jbowens committed Oct 25, 2024
1 parent 3ebaf7d commit 2147e2b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion sstable/colblk/bitmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,11 @@ func (b Bitmap) SeekUnsetBitLE(i int) int {
return (wordIdx << 6) + 63 - bits.LeadingZeros64(^word)
}

// summaryTableBounds returns the indexes of the bitmap words containing the
// summary table. The summary table's words lie within [startOffset, endOffset).
func (b Bitmap) summaryTableBounds() (startOffset, endOffset int) {
startOffset = (b.bitCount + 63) >> 6
endOffset = startOffset + startOffset>>6
endOffset = startOffset + (startOffset+63)>>6
return startOffset, endOffset
}

Expand Down
4 changes: 2 additions & 2 deletions sstable/colblk/bitmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func TestBitmapRandom(t *testing.T) {
}
}

fixedSizes := []int{1, 2, 3, 4, 16, 63, 64, 65, 128, 129, 256, 257, 1024, 1025, 4096}
fixedSizes := []int{1, 2, 3, 4, 16, 63, 64, 65, 128, 129, 256, 257, 1024, 1025, 4096, 4097, 8012, 8200}
fixedProbabilities := []float64{0.00001, 0.0001, 0.001, 0.1, 0.5, 0.9999}
for _, p := range fixedProbabilities {
t.Run(fmt.Sprintf("p=%05f", p), func(t *testing.T) {
Expand All @@ -252,7 +252,7 @@ func TestBitmapRandom(t *testing.T) {
for i := 0; i < 10; i++ {
p := rng.ExpFloat64() * 0.1
t.Run(fmt.Sprintf("p=%05f", p), func(t *testing.T) {
testWithProbability(t, p, rng.IntN(4096)+1, rng.IntN(2) == 1)
testWithProbability(t, p, rng.IntN(8200)+1, rng.IntN(2) == 1)
})
}
}
Expand Down

0 comments on commit 2147e2b

Please sign in to comment.