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 <fuweid89@gmail.com>
  • Loading branch information
fuweid committed Aug 7, 2024
1 parent ee33652 commit bbdc941
Show file tree
Hide file tree
Showing 4 changed files with 499 additions and 97 deletions.
14 changes: 14 additions & 0 deletions server/storage/mvcc/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ func (h *kvHasher) WriteKeyValue(k, v []byte) {
if !upper.GreaterThan(kr) {
return
}

isTombstone := BytesToBucketKey(k).tombstone

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 @@ -71,6 +74,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 && isTombstone {
return
}

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

0 comments on commit bbdc941

Please sign in to comment.