-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/base: add SetWithDelete key kind
Currently, SingleDelete is only guaranteed to behave correctly if the key has been Set _at most once_. Undefined behavior results outside of this requirement. cockroachdb/cockroach#69891 identified a sequence of operations that can result in non-deterministic, undefined behavior, due to the way in which early intents are removed and cause the DB to "forget" whether a key has been Set at most once, violating the key assumption for SingleDeletes. Consider the following sequence (where `=>` implies "happens-before"): ``` a.SET.1 => a.(DEL|SINGLEDEL).2 => a.SET.3 => a.SINGLEDEL.4 ``` If the middle two operations meet in a single compaction, the intermediate sequence would become: ``` a.SET.1 => a.SET.3 => a.SINGLEDEL.4 ``` A second compaction of this intermediate sequence would result in just `a.SET.1`, as `a.SET.3` and `a.SINGLEDEL.4` will be elided. This incorrectly "resurrects" `a.SET.1`. This undefined behavior was demonstrated in #1252. A solution, outlined in #1255, works as follows: - A new key kind, SetWithDelete, represents a Set that has potentially consumed a Delete or SingleDelete in a compaction. - The existing Set key kind now represents a promise that it has not consumed a Delete or SingleDelete. This is what will be written when a caller uses `pebble.Writer.Set`. - A `SET => SINGLEDEL` continues to cause both to be consumed. - A `SETWITHDEL => SINGLEDEL` is "upgraded" into a regular `DEL`, reflecting the fact that there may be deleted entries under the SetWithDelete that should not be resurrected. This patch introduces the new key kind and implements the logic described above, required for writing out these new keys during a compaction to improve the determinism of the `SET => SINGLEDEL` semantics. This new record type is gated behind a format major version, to ensure that older DBs continue to use the existing semantics, while newer DBs will make use of the new semantics during compactions. This change is one-way (i.e. once migrated, an older version of the DB cannot read sstables written by a newer version). Addresses #1255, cockroachdb/cockroach#69891.
- Loading branch information
Showing
22 changed files
with
2,855 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.