Skip to content

Commit 1e09c7f

Browse files
committed
compact: include expected size in MissizedDeleteCallback
Fix one of the instances where we report a missized DELSIZED tombstone but did not include the expected tombstone size. If a DELSIZED tombstone with a non-zero value meets another tombstone during a compaction, it indicates the more recent DELSIZED was missized--it deleted a key that did not exist (and was already deleted). Previously when invoking a callback to report this missizing, the compaction iterator passed expectedSize=0. This was misleading because the DELSIZED explicitly carried a non-zero size which allowed to us to determine there was a missizing in the first place. This commit adapts the compaction iterator to decode the DELSIZED's value in this case and propagate it into the missized delete callback.
1 parent 5a3aa66 commit 1e09c7f

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

internal/compact/iterator.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,12 +1201,23 @@ func (i *Iter) deleteSizedNext() *base.InternalKV {
12011201
//
12021202
// We treat both cases the same functionally, adopting the identity
12031203
// of the lower-sequence numbered tombstone. However in the second
1204-
// case, we also increment the stat counting missized tombstones.
1204+
// case, we also increment the stat counting missized tombstones and
1205+
// report the missizing via the callback.
12051206
if i.kv.V.Len() > 0 {
12061207
// The original DELSIZED key was missized. The key that the user
12071208
// thought they were deleting does not exist.
1209+
//
1210+
// We decode the original DELSIZED's value so that we can invoke
1211+
// the callback with the additional context. Note that the
1212+
// tombstone's value must be in-place.
1213+
v := i.kv.V.InPlaceValue()
1214+
expectedSize, n := binary.Uvarint(v)
1215+
if n != len(v) {
1216+
i.err = base.CorruptionErrorf("DELSIZED holds invalid value: %x", errors.Safe(v))
1217+
return nil
1218+
}
12081219
i.stats.CountMissizedDels++
1209-
i.cfg.MissizedDeleteCallback(i.kv.K.UserKey, 0, 0)
1220+
i.cfg.MissizedDeleteCallback(i.kv.K.UserKey, 0, expectedSize)
12101221
}
12111222
// If the tombstone has a value, it must be in-place. To save it, we
12121223
// can just copy the in-place value directly.

internal/compact/testdata/iter_delete_sized

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,3 +1877,24 @@ b#7,DEL:
18771877
c#6,DELSIZED:
18781878
missized-dels=2
18791879
missized-delete-info: a (elided=4, expected=20); b (elided=4, expected=15)
1880+
1881+
# Test a delete sized that doesn't delete a key, because it meets another
1882+
# tombstone.
1883+
1884+
define
1885+
a.SET.1:hello
1886+
b.DELSIZED.9:varint(6)
1887+
b.DELSIZED.4:varint(6)
1888+
b.SET.2:world
1889+
----
1890+
1891+
iter print-missized-dels print-missized-del-info
1892+
first
1893+
next
1894+
next
1895+
----
1896+
a#1,SET:hello
1897+
b#9,DELSIZED:
1898+
.
1899+
missized-dels=1
1900+
missized-delete-info: b (elided=0, expected=6)

0 commit comments

Comments
 (0)