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 1, 2024
1 parent 242fdbd commit 3ea0462
Show file tree
Hide file tree
Showing 4 changed files with 489 additions and 97 deletions.
13 changes: 13 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,16 @@ func (h *kvHasher) WriteKeyValue(k, v []byte) {
return
}
}

// NOTE: If the previous compacted revision was tombstone, existing
// releases already deleted that key(s). However, new releases won't
// delete the key(s) on compacted revision, no matter what type key it
// is. So, we should skip previous compacted revision to keep consistent
// with existing releases.
if kr.Main == h.compactRevision && isTombstone {
return
}

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

0 comments on commit 3ea0462

Please sign in to comment.