Skip to content

Commit c70ddd4

Browse files
committed
db: test replica removal of snapshot sstable
In CockroachDB snapshot reception ingests sstables. In some circumstances and verisons of CockroachDB, these sstables have RANGEDEL and RANGEKEYDEL keys spanning the entirety of the KV range's span in order to clear any previous range state. When a replica is destroyed, CockroachDB may choose to write a RANGEDEL (and possibly a RANGEKEYDEL) over the replica's span to delete the data. If an original sstable from snapshot reception still exists, we would like this sstable to be dropped by a simple deletion-only compaction. This commit adds a unit test that demonstrates this behavior.
1 parent c532754 commit c70ddd4

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

compaction_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,17 @@ func TestCompactionDeleteOnlyHints(t *testing.T) {
13541354
datadriven.RunTest(t, "testdata/compaction_delete_only_hints",
13551355
func(t *testing.T, td *datadriven.TestData) string {
13561356
switch td.Cmd {
1357+
case "batch":
1358+
b := d.NewBatch()
1359+
err := runBatchDefineCmd(td, b)
1360+
if err != nil {
1361+
return err.Error()
1362+
}
1363+
if err = b.Commit(Sync); err != nil {
1364+
return err.Error()
1365+
}
1366+
return ""
1367+
13571368
case "define":
13581369
opts, err = reset()
13591370
if err != nil {
@@ -1368,6 +1379,12 @@ func TestCompactionDeleteOnlyHints(t *testing.T) {
13681379
d.mu.Unlock()
13691380
return s
13701381

1382+
case "flush":
1383+
if err := d.Flush(); err != nil {
1384+
return err.Error()
1385+
}
1386+
return runLSMCmd(td, d)
1387+
13711388
case "force-set-hints":
13721389
d.mu.Lock()
13731390
defer d.mu.Unlock()
@@ -1518,6 +1535,13 @@ func TestCompactionDeleteOnlyHints(t *testing.T) {
15181535
}
15191536
return ""
15201537

1538+
case "snapshot":
1539+
// NB: It's okay that we're letting the snapshot out of scope
1540+
// without closing it; the close snapshot command will pull the
1541+
// relevant seqnum off the DB to close it.
1542+
s := d.NewSnapshot()
1543+
return fmt.Sprintf("snapshot seqnum: %d", s.seqNum)
1544+
15211545
case "ingest":
15221546
if err = runBuildCmd(td, d, d.opts.FS); err != nil {
15231547
return err.Error()

testdata/compaction_delete_only_hints

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,3 +702,55 @@ o: (o, .)
702702
get-hints
703703
----
704704
(none)
705+
706+
# Reset the database.
707+
708+
reset
709+
----
710+
711+
# Simulate an ingestion of a CockroachDB snapshot sstable with a range delete and a
712+
# range key delete covering the keyspace.
713+
714+
ingest ext
715+
set c c
716+
set d d
717+
set e e
718+
set f f
719+
set g g
720+
del-range c h
721+
range-key-del c h
722+
----
723+
OK
724+
725+
describe-lsm
726+
----
727+
L6:
728+
000004:[c#10,RANGEKEYDEL-h#inf,RANGEDEL]
729+
730+
snapshot
731+
----
732+
snapshot seqnum: 11
733+
734+
# Simulate a replica removal of the previously ingested snapshot through a range
735+
# delete and range key delete.
736+
737+
batch
738+
del-range c h
739+
range-key-del c h
740+
----
741+
742+
flush
743+
----
744+
L0.0:
745+
000006:[c#12,RANGEKEYDEL-h#inf,RANGEDEL]
746+
L6:
747+
000004:[c#10,RANGEKEYDEL-h#inf,RANGEDEL]
748+
749+
get-hints
750+
----
751+
L0.000006 c-h seqnums(tombstone=11-12, file-smallest=10, type=point-and-range-key)
752+
753+
close-snapshot
754+
11
755+
----
756+
[JOB 100] compacted(delete-only) L6 [000004] (966B) Score=0.00 -> L6 [] (0B), in 1.0s (2.0s total), output rate 0B/s

0 commit comments

Comments
 (0)