Skip to content

Commit

Permalink
sstable: don't skipBackward past empty blocks with hideObsolete
Browse files Browse the repository at this point in the history
Currently, if we skipBackward in singleLevelIterator and come
across a seemingly empty data block, we stop right there. This
is not safe if hide obsolete points is true, as the block could
have just been obsolete in its entirety. This change makes the
iterator continue iterating backward until some other termination
condition is exhausted.

This matches the behaviour for two-level iterators, as well as
for skipForward in single-level iterators.

Fixes cockroachdb#3761.
  • Loading branch information
itsbilal committed Jul 22, 2024
1 parent de0e731 commit 3a0bea1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sstable/reader_iter_single_lvl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,12 @@ func (i *singleLevelIterator) skipBackward() *base.InternalKV {
}
kv := i.data.Last()
if kv == nil {
if i.transforms.HideObsoletePoints {
// The block iter could have hid some obsolete points, so it isn't
// safe to assume that there are no keys if we keep skipping backwards.
// Check the previous block.
continue
}
return nil
}
if i.blockLower != nil && i.cmp(kv.K.UserKey, i.blockLower) < 0 {
Expand Down
18 changes: 18 additions & 0 deletions sstable/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,17 @@ func TestReaderHideObsolete(t *testing.T) {
t, opts, "testdata/reader_hide_obsolete",
nil /* Reader */, true)
})
opts = WriterOptions{
TableFormat: TableFormatPebblev4,
BlockSize: blockSize,
IndexBlockSize: 1 << 30, // Force a single-level index block.
Comparer: testkeys.Comparer,
}
t.Run(fmt.Sprintf("singleLevel/blockSize=%s", dName), func(t *testing.T) {
runTestReader(
t, opts, "testdata/reader_hide_obsolete",
nil /* Reader */, true)
})
}
}

Expand Down Expand Up @@ -797,6 +808,13 @@ func runTestReader(t *testing.T, o WriterOptions, dir string, r *Reader, printVa
require.True(t, retHideObsoletePoints)
}
}
if d.HasArg("hide-obsolete-points-without-filter") {
var hideObsoletePoints bool
d.ScanArgs(t, "hide-obsolete-points-without-filter", &hideObsoletePoints)
if hideObsoletePoints {
transforms.HideObsoletePoints = true
}
}
var filterer *BlockPropertiesFilterer
if len(bpfs) > 0 {
filterer = newBlockPropertiesFilterer(bpfs, nil, nil)
Expand Down
26 changes: 26 additions & 0 deletions sstable/testdata/reader_hide_obsolete/iter
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,29 @@ d.SINGLEDEL.40:
d.MERGE.30:D30
----
MERGE not supported in a strict-obsolete sstable

# Regression test for #3761. If an entire block contains obsolete points,
# skipBackward should still skip to blocks earlier in the sstable.

build writing-to-lowest-level
a.SET.10:A10
force-obsolete: b.DEL.5:
force-obsolete: b.SETWITHDEL.2:foo
force-obsolete: c.DEL.0:
force-obsolete: cc.DEL.5:
----

iter hide-obsolete-points-without-filter=true
last
----
<a:10>:A10

iter hide-obsolete-points-without-filter=true
seek-lt d
----
<a:10>:A10

iter hide-obsolete-points-without-filter=true
seek-lt c
----
<a:10>:A10

0 comments on commit 3a0bea1

Please sign in to comment.