Skip to content

Commit

Permalink
*: keep tombstone if revision == compactAtRev
Browse files Browse the repository at this point in the history
Before this patch, the tombstone can be deleted if its revision is equal
compacted revision. It causes that the watch subscriber won't get this
DELETE event. Based on Compact API[1], we should keep tombstone revision
if it's not less than the compaction revision.

> CompactionRequest compacts the key-value store up to a given revision.
> All superseded keys with a revision less than the compaction revision
> will be removed.

[1]: https://etcd.io/docs/latest/dev-guide/api_reference_v3/

Signed-off-by: Wei Fu <[email protected]>
(cherry picked from commit bbdc941)
Signed-off-by: Wei Fu <[email protected]>
  • Loading branch information
fuweid committed Aug 20, 2024
1 parent db701a5 commit 8d98510
Show file tree
Hide file tree
Showing 4 changed files with 501 additions and 95 deletions.
14 changes: 14 additions & 0 deletions server/mvcc/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func (h *kvHasher) WriteKeyValue(k, v []byte) {
if !upper.GreaterThan(kr) {
return
}

isTombstoneRev := isTombstone(k)

lower := revision{main: h.compactRevision + 1}
// skip revisions that are scheduled for deletion
// due to compacting; don't skip if there isn't one.
Expand All @@ -70,6 +73,17 @@ func (h *kvHasher) WriteKeyValue(k, v []byte) {
return
}
}

// When performing compaction, if the compacted revision is a
// tombstone, older versions (<= 3.5.15 or <= 3.4.33) will delete
// the tombstone. But newer versions (> 3.5.15 or > 3.4.33) won't
// delete it. So we should skip the tombstone in such cases when
// computing the hash to ensure that both older and newer versions
// can always generate the same hash values.
if kr.main == h.compactRevision && isTombstoneRev {
return
}

h.hash.Write(k)
h.hash.Write(v)
}
Expand Down
Loading

0 comments on commit 8d98510

Please sign in to comment.