Skip to content

Commit

Permalink
sstable: fix nil pointer in twoLevelIterator.NextPrefix
Browse files Browse the repository at this point in the history
  • Loading branch information
jbowens committed Aug 21, 2024
1 parent 9f97b7b commit aa96305
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
3 changes: 1 addition & 2 deletions sstable/reader_iter_two_lvl.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,6 @@ func (i *twoLevelIterator[D, PD]) NextPrefix(succKey []byte) *base.InternalKV {

// Did not find prefix in the existing second-level index block. This is the
// slow-path where we seek the iterator.
var ikv *base.InternalKV
if !i.topLevelIndex.SeekGE(succKey) {
PD(&i.secondLevel.data).Invalidate()
i.secondLevel.index.Invalidate()
Expand All @@ -812,7 +811,7 @@ func (i *twoLevelIterator[D, PD]) NextPrefix(succKey []byte) *base.InternalKV {
// span multiple index blocks. If upper is exclusive we use >= below,
// else we use >.
if i.secondLevel.upper != nil {
cmp := i.secondLevel.cmp(ikv.K.UserKey, i.secondLevel.upper)
cmp := i.secondLevel.cmp(i.topLevelIndex.Separator(), i.secondLevel.upper)
if (!i.secondLevel.endKeyInclusive && cmp >= 0) || cmp > 0 {
i.secondLevel.exhaustedBounds = +1
}
Expand Down
47 changes: 47 additions & 0 deletions sstable/testdata/block_properties
Original file line number Diff line number Diff line change
Expand Up @@ -696,3 +696,50 @@ filter point-filter=(suffix-point-keys-only,10,20)
----
points: false
ranges: true (no filters provided)

build collectors=(suffix-point-keys-only) index-block-size=48 block-size=1
a@10.SET.1:foo
a@9.SET.2:bar
a@8.SET.2:baz
a@7.SET.2:bax
aa@9.SET.3:mop
aa@8.SET.3:box
f@5.SET.3:mop
----
point: [a@10#1,SET-f@5#3,SET]
seqnums: [1-3]

block-props
----
a@9#2,SET:
0: [9, 11)
a@10#1,SET:
0: [10, 11)
a@9#2,SET:
0: [9, 10)
a@7#2,SET:
0: [7, 9)
a@8#2,SET:
0: [8, 9)
a@7#2,SET:
0: [7, 8)
b#inf,SEPARATOR:
0: [8, 10)
aa@9#3,SET:
0: [9, 10)
b#inf,SEPARATOR:
0: [8, 9)
g#inf,SEPARATOR:
0: [5, 6)
g#inf,SEPARATOR:
0: [5, 6)

# Regression test for a nil-pointer when we find a second-level index block
# irrelevant and enforce an upper bound.

iter point-key-filter=(suffix-point-keys-only,5,8) upper=c
seek-ge a
next-prefix
----
<a@7:2>
.

0 comments on commit aa96305

Please sign in to comment.