Skip to content

Commit 1a2a77b

Browse files
committed
db: interleave range deletion boundaries in levelIter
Previously, levelIter would sometimes interleave fake keys at file boundaries or user-provided iteration boundaries when a file contains range deletions. This commit reworks the levelIter to instead interleave the individual bounds of the range deletions themselves, using an interleaving iterator. This simplifies the levelIter. Because range deletions are now read in two places: once for interleaving bounds and once to expose a rangeDelIter to the mergingIter, this commit requires opening a file's range deletion iterator twice. This is an intermediary state until #2863 is completed when the mergingIter will consult the levelIter's interleaving iterator to determine which range deletions overlap the current iterator position. Informs #2863.
1 parent 903f29d commit 1a2a77b

File tree

9 files changed

+242
-324
lines changed

9 files changed

+242
-324
lines changed

internal/keyspan/interleaving_iter.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,9 +1036,10 @@ func (i *InterleavingIter) verify(kv *base.InternalKV) *base.InternalKV {
10361036
switch {
10371037
case i.dir == -1 && i.spanMarkerTruncated:
10381038
panic("pebble: invariant violation: truncated span key in reverse iteration")
1039-
case kv != nil && i.opts.LowerBound != nil && i.cmp(kv.K.UserKey, i.opts.LowerBound) < 0:
1039+
case kv != nil && i.opts.LowerBound != nil && !kv.K.IsExclusiveSentinel() &&
1040+
i.cmp(kv.K.UserKey, i.opts.LowerBound) < 0:
10401041
panic("pebble: invariant violation: key < lower bound")
1041-
case kv != nil && i.opts.UpperBound != nil &&
1042+
case kv != nil && i.opts.UpperBound != nil && !kv.K.IsExclusiveSentinel() &&
10421043
!base.UserKeyExclusive(i.opts.UpperBound).IsUpperBoundForInternalKey(i.comparer.Compare, kv.K):
10431044
panic("pebble: invariant violation: key ≥ upper bound")
10441045
case i.err != nil && kv != nil:

level_checker_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/cockroachdb/errors"
1818
"github.com/cockroachdb/pebble/internal/base"
1919
"github.com/cockroachdb/pebble/internal/invalidating"
20+
"github.com/cockroachdb/pebble/internal/invariants"
2021
"github.com/cockroachdb/pebble/internal/keyspan"
2122
"github.com/cockroachdb/pebble/internal/manifest"
2223
"github.com/cockroachdb/pebble/internal/private"
@@ -85,6 +86,10 @@ func (f *failMerger) Close() error {
8586
}
8687

8788
func TestCheckLevelsCornerCases(t *testing.T) {
89+
if invariants.Enabled {
90+
t.Skip("disabled under invariants; relies on violating invariants to detect them")
91+
}
92+
8893
memFS := vfs.NewMem()
8994
var levels [][]*fileMetadata
9095
formatKey := testkeys.Comparer.FormatKey

0 commit comments

Comments
 (0)