Skip to content

Commit

Permalink
db: handle truncation of shared files with no points
Browse files Browse the repository at this point in the history
Previously, our iterator creation code created invalid iterators
instead of returning nil for point iterators if we tried to create
point iterators on a file with `hasPointKeys == false`. This change
addresses that, and also updates `truncateSharedFile` to handle
cases where the point key iterator is nil.

Fixes cockroachdb#3761.
  • Loading branch information
itsbilal committed Jul 18, 2024
1 parent 9a4ea4d commit 3a0a53d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
10 changes: 8 additions & 2 deletions scan_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,10 @@ func (d *DB) truncateSharedFile(
if needsLowerTruncate {
sst.SmallestPointKey.UserKey = sst.SmallestPointKey.UserKey[:0]
sst.SmallestPointKey.Trailer = 0
kv := iter.SeekGE(lower, base.SeekGEFlagsNone)
var kv *base.InternalKV
if iter != nil {
kv = iter.SeekGE(lower, base.SeekGEFlagsNone)
}
foundPointKey := kv != nil
if kv != nil {
sst.SmallestPointKey.CopyFrom(kv.K)
Expand Down Expand Up @@ -598,7 +601,10 @@ func (d *DB) truncateSharedFile(
if needsUpperTruncate {
sst.LargestPointKey.UserKey = sst.LargestPointKey.UserKey[:0]
sst.LargestPointKey.Trailer = 0
kv := iter.SeekLT(upper, base.SeekLTFlagsNone)
var kv *base.InternalKV
if iter != nil {
kv = iter.SeekLT(upper, base.SeekLTFlagsNone)
}
foundPointKey := kv != nil
if kv != nil {
sst.LargestPointKey.CopyFrom(kv.K)
Expand Down
2 changes: 1 addition & 1 deletion table_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ func (c *tableCacheShard) newIters(
if kinds.RangeDeletion() && file.HasPointKeys && err == nil {
iters.rangeDeletion, err = c.newRangeDelIter(ctx, file, cr, dbOpts)
}
if kinds.Point() && err == nil {
if kinds.Point() && file.HasPointKeys && err == nil {
iters.point, err = c.newPointIter(ctx, v, file, cr, opts, internalOpts, dbOpts)
}
if err != nil {
Expand Down
50 changes: 50 additions & 0 deletions testdata/ingest_shared
Original file line number Diff line number Diff line change
Expand Up @@ -1307,3 +1307,53 @@ next
----
.
.

# Regression test for #3761. Replicate an sstable
# which does not have point keys.

reset
----

switch 2
----
ok

batch
range-key-set a c @4 value
----

flush
----

compact a-z
----
ok

lsm
----
L6:
000005:[a#10,RANGEKEYSET-c#inf,RANGEKEYSET]

switch 1
----
ok

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

lsm
----
L6:
000005(000005):[a#11,RANGEKEYSET-c#inf,RANGEKEYDEL]

iter
first
next
next
next
----
a: (., [a-c) @4=value UPDATED)
.
.
.

0 comments on commit 3a0a53d

Please sign in to comment.