Skip to content

Commit

Permalink
db: fix sstable bound inversion in ingestSynthesizeShared
Browse files Browse the repository at this point in the history
Previously, for shared file ingestions, we could have seqnum
substitution result in invalid bounds (eg. smallest > largest).
This change detects this case as an artifact of seqnum substitution
and addresses it.

Fixes cockroachdb#3225.
  • Loading branch information
itsbilal committed Jan 17, 2024
1 parent b162166 commit 4b750a6
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ func ingestSynthesizeShared(
if sm.LargestPointKey.IsExclusiveSentinel() {
largestPointKey = base.MakeRangeDeleteSentinelKey(sm.LargestPointKey.UserKey)
}
if opts.Comparer.Equal(smallestPointKey.UserKey, largestPointKey.UserKey) &&
smallestPointKey.Trailer < largestPointKey.Trailer {
// We get kinds from the sender, however we substitute our own sequence
// numbers. This can result in cases where an sstable [b#5,SET-b#4,DELSIZED]
// becomes [b#0,SET-b#0,DELSIZED] when we synthesize it here, but the
// kinds need to be reversed now because DelSized > Set.
smallestPointKey, largestPointKey = largestPointKey, smallestPointKey
}
meta.ExtendPointKeyBounds(opts.Comparer.Compare, smallestPointKey, largestPointKey)
}
if err := meta.Validate(opts.Comparer.Compare, opts.Comparer.FormatKey); err != nil {
Expand Down
57 changes: 57 additions & 0 deletions testdata/ingest_shared
Original file line number Diff line number Diff line change
Expand Up @@ -1240,3 +1240,60 @@ c: (., [c-cc) @7=foo UPDATED)
dd: (., [dd-e) @7=foo UPDATED)
.
.

# Regression test for https://github.com/cockroachdb/pebble/issues/3225
# Handle cases where an sstable starts and ends at the same user key but different
# internal key, and the ordering of internal key kinds changes due to seqnum
# substitution.

reset
----

switch 1
----
ok

batch
set a foo
----

file-only-snapshot s11
a z
----
ok

batch
del a
----

flush
----

compact a-z
----
ok

lsm
----
6:
000005:[a#11,DEL-a#10,SET]

replicate 1 2 a z
----
replicated 1 shared SSTs

switch 2
----
ok

lsm
----
6:
000005:[a#10,SET-a#10,DEL]

iter
first
next
----
.
.

0 comments on commit 4b750a6

Please sign in to comment.