Repository navigation
Disable read-path range tombstone conversion with unordered_write (#15741) - #15741
xingbowang wants to merge 2 commits into
Conversation
|
@xingbowang has exported this pull request. If you are a Meta employee, you can view the originating Diff in D133500312. |
✅ clang-tidy: No findings on changed linesCompleted in 600.2s. |
785bbf1 to
fc76825
Compare
Claude Code Review - OBSOLETESuperseded by a newer AI review. Expand to see the original review.✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit fc76825 SummaryWell-scoped, correct bug fix for a real data loss scenario. The one-line guard ( High-severity findings (0): No high-severity findings. Full review (click to expand)Findings🟡 MEDIUMM1. Test timeout too short for CI —
|
| Context | Does code execute? | Assumptions hold? | Action needed? |
|---|---|---|---|
| WritePreparedTxnDB + two_write_queues + unordered_write | YES | YES (conservatively disabled) | None |
| WriteUnpreparedTxnDB | NO — incompatible with unordered_write | N/A | None |
| WriteCommittedTxnDB | NO — incompatible with unordered_write | N/A | None |
| ReadOnly DB / Secondary | N/A — no writes, active_mem null |
N/A | None |
| Pipelined writes | NO — mutually exclusive with unordered_write | N/A | None |
| User-defined timestamps | YES | YES — orthogonal guard | None |
| Dynamic SetOptions | N/A — unordered_write is ImmutableDBOptions |
N/A | None |
DB Mutex Analysis: The change is in the DBIter constructor initializer list, outside DBImpl::mutex_. Simple bool read on immutable struct — zero overhead, no locking concerns.
Pipelined Write Safety: Verified pipelined writes do NOT have the same race. In pipelined writes, the reader-visible LastSequence is published only AFTER memtable insertion (db_impl_write.cc:1761). Only unordered_write publishes sequence numbers to readers before memtable insertion (db_impl_write.cc:1094-1106).
Invariant Verification:
min_tombstones_for_range_conversion_is only set in the constructor initializer list; no subsequent assignments exist. Guard is permanent for iterator lifetime.ImmutableDBOptions::unordered_writecannot change after DB open.- No other code path inserts "converted" range tombstones outside
MaybeInsertRangeTombstone.
Positive Observations
- Correct placement: Guard added at the same level as existing guards (table_filter, read_tier, prefix, timestamp) — consistent pattern.
- Good test design: Uses sync points (not sleeps),
std::future/std::promise,Deferfor cleanup, and verifies both negative (no conversion) and positive (key visible after writer completes) cases. - Clear documentation: Comment in
db_iter.ccexplains the race,advanced_options.hlists the disabled configuration, release note is concise. - ASSERT_EQ fix: Prevents potential UB in WritePrepared test.
ℹ️ About this response
Generated by Claude Code.
Review methodology: claude_md/ci_review_prompt.md
Limitations:
- Claude may miss context from files not in the diff
- Large PRs may be truncated
- Always apply human judgment to AI suggestions
Commands:
/claude-review [context]— Request a code review/claude-query <question>— Ask about the PR or codebase
…ta#15741) Summary: Pull Request resolved: meta#15741 Background: `min_tombstones_for_range_conversion` lets a forward or reverse scan replace a series of adjacent point tombstones, with no live key between them, by one range tombstone `[first_tombstone_key, next_live_key)`. The scan inserts the range tombstone into the active memtable at the scan's read sequence number. This is safe only if the scan saw every key in that series that its snapshot includes. With `DBOptions::unordered_write`, a write publishes its sequence number before it inserts its keys into the memtable. A scan can therefore read at a snapshot that includes a write whose key is not in the memtable yet. Previous behavior: such a scan could convert the point tombstones around the missing key. The converted range tombstone has a larger sequence number than the pending write. When the write finished, its key was covered by the range tombstone and was lost for every later read, also after flush and compaction. This is permanent data loss, not only the relaxed snapshot guarantee that `unordered_write` documents. New behavior: the `DBIter` constructor disables read-path conversion when `unordered_write` is true, next to the existing gates for table filters, read tiers, prefix mode and timestamp visibility. Scans under `unordered_write` never insert converted range tombstones. Implementation: - `db/db_iter.cc`: add `!ioptions.unordered_write` to the condition that sets `min_tombstones_for_range_conversion_`, and explain why in the existing comment. - `include/rocksdb/advanced_options.h`: list `unordered_write` among the configurations where conversion is disabled (comment only). - `unreleased_history/bug_fixes/unordered_write_range_conversion.md`: release note. Safety and unsupported cases: other write modes are not changed. The default write path, pipelined writes, concurrent memtable writes and `two_write_queues` without `unordered_write` publish a sequence number only after the memtable insert finishes, so a scan cannot miss a key that its snapshot includes. WritePrepared and WriteUnprepared transactions keep their existing guard: a scan does not convert when its snapshot is at or above the oldest uncommitted sequence number. Known limitations: conversion is also disabled for a WritePrepared transaction DB that uses `unordered_write` (which requires `two_write_queues`), although the existing uncommitted-write guard would make it safe there, as long as every write goes through the transaction DB. We expect the lost benefit to be small: with `two_write_queues`, that guard already refuses a conversion unless the main write queue has moved past the scan's snapshot, for example while a prepared transaction is open. Changes visible to existing users: DBs, including transaction DBs, that set both `unordered_write` and `min_tombstones_for_range_conversion` do not get read-path range tombstones, so their scans over long tombstone runs do not get faster. Differential Revision: D133500312
fc76825 to
4c23a0d
Compare
Claude Code Review - OBSOLETESuperseded by a newer AI review. Expand to see the original review.✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit 4c23a0d SummaryThis is a well-targeted bug fix that correctly disables read-path range tombstone conversion when High-severity findings (0): Full review (click to expand)Findings🟡 MEDIUMM1. Pipelined writes may have a similar (less severe) vulnerability —
|
| Context | Affected? | Safe? | Notes |
|---|---|---|---|
| Default write path | No | Yes | Sequence published after memtable insert |
unordered_write=true |
Yes | Yes (with fix) | Conversion disabled |
enable_pipelined_write |
No | Yes | versions_->SetLastSequence() after memtable insert |
| WritePreparedTxnDB + unordered_write | Yes | Yes | Both min_uncommitted guard AND new guard apply (conservative) |
| WritePreparedTxnDB without unordered_write | No | Yes | Existing min_uncommitted guard sufficient |
| ReadOnly DB | No | N/A | active_mem is null, conversion already disabled |
| Iterator Refresh | Yes | Yes | Re-creates DBIter, re-evaluates condition |
two_write_queues without unordered_write |
No | Yes | Sequence published after memtable insert in this mode |
Assumption stress-test results:
-
Claim: "sequence published before memtable insert with unordered_write" — Confirmed at
db/db_impl/db_impl_write.cc:1093-1107.WriteImplWALOnlywithkDoPublishLastSeqpublishes viaversions_->SetLastSequence()(line 2065), thenBeforeUnorderedWriteMemtablesync point fires, thenUnorderedWriteMemtable()does the insert. -
Claim: "converted tombstone has larger seqno than pending write" — Confirmed. The tombstone is inserted at
sequence_(the iterator's read sequence, db/db_iter.cc:1902), which must be >= the pending write's sequence (since the write's sequence was already published and the iterator was created after). -
Claim: "other write modes are safe" — Confirmed for default path (memtable insert happens within the write group before
SetLastSequence). Confirmed for pipelined writes (SetLastSequence at line 1761 after memtable insert).enable_pipelined_writeis also incompatible withunordered_write(line 980-983).
Positive Observations
- Minimal, surgical fix: The change adds a single boolean check in exactly the right place (the constructor guard that determines if conversion is enabled for the iterator's lifetime). No new code paths, no new data members.
- Well-documented: The code comment explains WHY unordered_write is unsafe, not just WHAT the check does. The PR description includes a thorough safety analysis.
- Known limitation documented: The PR honestly acknowledges that WritePrepared+unordered_write loses conversion benefit unnecessarily, and explains why the conservative approach is acceptable.
- Good test: The test correctly simulates the race condition using an existing sync point, uses
Deferfor cleanup, and has a timeout to prevent hangs. The final verification checks both point reads and iteration. - ASSERT_EQ upgrade: Changing
EXPECT_EQtoASSERT_EQforinserted_ranges.size()prevents potential out-of-bounds access — a subtle but important improvement.
ℹ️ About this response
Generated by Claude Code.
Review methodology: claude_md/ci_review_prompt.md
Limitations:
- Claude may miss context from files not in the diff
- Large PRs may be truncated
- Always apply human judgment to AI suggestions
Commands:
/claude-review [context]— Request a code review/claude-query <question>— Ask about the PR or codebase
4c23a0d to
32b951f
Compare
Claude Code Review - OBSOLETESuperseded by a newer AI review. Expand to see the original review.✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit 32b951f SummaryThis is a well-targeted bug fix for a real data-loss scenario. The fix is conservative (disables an optimization) rather than adding complex logic, and the approach is correct. The test is well-designed, using sync points to deterministically reproduce the race condition. The comment and documentation updates are accurate and well-placed. High-severity findings (0): Full review (click to expand)Findings🟡 MEDIUMM1. Test comment says "two deletes on each side" but only deletes b1, b2, b4, b5 —
|
| Context | Affected? | Analysis |
|---|---|---|
| Plain DB + unordered_write | YES | The fix correctly disables conversion. No data loss. |
| WritePreparedTxnDB + ordered_write | NO | unordered_write is false; existing read_callback guard handles this. |
| WritePreparedTxnDB + unordered_write + two_write_queues | YES | Conservatively disabled. The read_callback guard would also catch it, but double protection is safe. |
| WriteUnpreparedTxnDB | NO | Incompatible with unordered_write (rejected at open time). |
| ReadOnly DB | NO | active_mem_ is nullptr; conversion already disabled. |
| User-defined timestamps | Independent | Separate guard (HasFullTimestampVisibility) handles this. |
| Concurrent memtable writes | NO impact | The guard is in the constructor; unordered_write is an ImmutableDBOption set at open time. |
| Iterator Refresh | Safe | DoRefresh re-constructs DBIter with the same ioptions, so the guard is reapplied. |
Assumption stress test:
-
Claim: "With unordered_write, a scan can miss a key that its snapshot includes."
- Precondition 1: Writer publishes seqno before memtable insert → TRUE by design (db_impl_write.cc:1097
kDoPublishLastSeqbefore line 1106-1108 memtable insert). - Precondition 2: Another writer can advance published seq while first is pending → TRUE (concurrent writers).
- Precondition 3: Scanner at advanced seq misses the pending key → TRUE (key not in memtable).
- All preconditions verified. The bug scenario is real.
- Precondition 1: Writer publishes seqno before memtable insert → TRUE by design (db_impl_write.cc:1097
-
Claim: "Disabling conversion prevents data loss."
- If min_tombstones_for_range_conversion_ is 0,
TrackContiguousTombstoneandMaybeInsertRangeTombstoneare never reached (guarded bymin_tombstones_for_range_conversion_ > 0checks at lines 653, 980, 1083, 1139, 1877). No range tombstone is inserted. The pending write is not covered. Verified correct.
- If min_tombstones_for_range_conversion_ is 0,
DB Mutex analysis: This change does not affect any code path that runs under DBImpl::mutex_. The guard is evaluated in the DBIter constructor, which runs outside the DB mutex. No mutex-related concerns.
Positive Observations
- The fix is minimal and surgical — one boolean check added to an existing guard chain.
- The sync point
BeforeUnorderedWriteMemtablealready exists in the codebase and is the correct point to pause the writer between WAL publish and memtable insert. - The test uses
Deferfor cleanup, ensuring the writer thread is always joined even when assertions fail — good test hygiene. - The
std::future::wait_forwith 10-second timeout ensures the test fails rather than hangs if the sync point is never reached. - The
EXPECT_EQ→ASSERT_EQupgrade in the WritePrepared test prevents potential crashes on test failure. - The PR description's "Safety and unsupported cases" and "Known limitations" sections demonstrate thorough analysis of the fix's scope and trade-offs.
ℹ️ About this response
Generated by Claude Code.
Review methodology: claude_md/ci_review_prompt.md
Limitations:
- Claude may miss context from files not in the diff
- Large PRs may be truncated
- Always apply human judgment to AI suggestions
Commands:
/claude-review [context]— Request a code review/claude-query <question>— Ask about the PR or codebase
32b951f to
4d3ea63
Compare
…ta#15741) Summary: Pull Request resolved: meta#15741 Background: with `min_tombstones_for_range_conversion`, a forward or reverse scan that steps over enough adjacent point tombstones, with no live key between them, adds one range tombstone over the keys it found deleted. The point tombstones stay; the range tombstone is redundant, and later scans use it to seek past the covered keys in older memtables and SST files. The scan inserts the range tombstone into the active memtable at the scan's read sequence number. This is safe only if the scan saw every key in that range that its snapshot includes. With `DBOptions::unordered_write`, a write publishes its sequence number before it inserts its keys into the memtable. A scan can therefore read at a snapshot that includes a write whose key is not in the memtable yet. Previous behavior: such a scan could convert the point tombstones around the missing key. While the first write was pending, a later write could publish a higher sequence number. An iterator opened at that higher sequence number could miss the pending key, and the converted range tombstone, inserted at the read sequence number, is newer than the pending write. When the write finished, its key was covered by the range tombstone and was lost for every later read, also after flush and compaction. This is permanent data loss, not only the relaxed snapshot guarantee that `unordered_write` documents. New behavior: the `DBIter` constructor disables read-path conversion when `unordered_write` is true, next to the existing gates for table filters, read tiers, prefix mode and timestamp visibility. Scans under `unordered_write` never insert converted range tombstones. Implementation: - `db/db_iter.cc`: add `!ioptions.unordered_write` to the condition that sets `min_tombstones_for_range_conversion_`, and explain why in the existing comment. - `include/rocksdb/advanced_options.h`: list `unordered_write` among the configurations where conversion is disabled (comment only). - `unreleased_history/bug_fixes/unordered_write_range_conversion.md`: release note. Safety and unsupported cases: other write modes are not changed. The default write path, pipelined writes, concurrent memtable writes and `two_write_queues` without `unordered_write` publish a sequence number only after the memtable insert finishes, so a scan cannot miss a key that its snapshot includes. WritePrepared and WriteUnprepared transactions keep their existing guard: a scan does not convert when its snapshot is at or above the oldest uncommitted sequence number. Known limitations: conversion is also disabled for a WritePrepared transaction DB that uses `unordered_write` (which requires `two_write_queues`), although the existing guard would make it safe there, as long as every write goes through the transaction DB. That guard refuses a conversion when the scan's read sequence number is at or above the `min_uncommitted` bound saved with the scan's snapshot, which is a conservative bound for the oldest uncommitted write. The lost benefit was not measured. Changes visible to existing users: DBs, including transaction DBs, that set both `unordered_write` and `min_tombstones_for_range_conversion` do not get read-path range tombstones, so their scans over long tombstone runs do not get faster. Differential Revision: D133500312
…ta#15741) Summary: Pull Request resolved: meta#15741 Background: with `min_tombstones_for_range_conversion`, a forward or reverse scan that steps over enough adjacent point tombstones, with no live key between them, adds one range tombstone over the keys it found deleted. The point tombstones stay; the range tombstone is redundant, and later scans use it to seek past the covered keys in older memtables and SST files. The scan inserts the range tombstone into the active memtable at the scan's read sequence number. This is safe only if the scan saw every key in that range that its snapshot includes. With `DBOptions::unordered_write`, a write publishes its sequence number before it inserts its keys into the memtable. A scan can therefore read at a snapshot that includes a write whose key is not in the memtable yet. Previous behavior: such a scan could convert the point tombstones around the missing key. While the first write was pending, a later write could publish a higher sequence number. An iterator opened at that higher sequence number could miss the pending key, and the converted range tombstone, inserted at the read sequence number, is newer than the pending write. When the write finished, its key was covered by the range tombstone and was lost for every later read, also after flush and compaction. This is permanent data loss, not only the relaxed snapshot guarantee that `unordered_write` documents. New behavior: the `DBIter` constructor disables read-path conversion when `unordered_write` is true, next to the existing gates for table filters, read tiers, prefix mode and timestamp visibility. Scans under `unordered_write` never insert converted range tombstones. Implementation: - `db/db_iter.cc`: add `!ioptions.unordered_write` to the condition that sets `min_tombstones_for_range_conversion_`, and explain why in the existing comment. - `include/rocksdb/advanced_options.h`: list `unordered_write` among the configurations where conversion is disabled (comment only). - `unreleased_history/bug_fixes/unordered_write_range_conversion.md`: release note. Safety and unsupported cases: other write modes are not changed. The default write path, pipelined writes, concurrent memtable writes and `two_write_queues` without `unordered_write` publish a sequence number only after the memtable insert finishes, so a scan cannot miss a key that its snapshot includes. WritePrepared and WriteUnprepared transactions keep their existing guard: a scan does not convert when its snapshot is at or above the oldest uncommitted sequence number. Known limitations: conversion is also disabled for a WritePrepared transaction DB that uses `unordered_write` (which requires `two_write_queues`), although the existing guard would make it safe there, as long as every write goes through the transaction DB. That guard refuses a conversion when the scan's read sequence number is at or above the `min_uncommitted` bound saved with the scan's snapshot, which is a conservative bound for the oldest uncommitted write. The lost benefit was not measured. Changes visible to existing users: DBs, including transaction DBs, that set both `unordered_write` and `min_tombstones_for_range_conversion` do not get read-path range tombstones, so their scans over long tombstone runs do not get faster. Differential Revision: D133500312
✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit 4d3ea63 SummaryWell-scoped, correct bug fix for a real data-loss scenario with High-severity findings (0): Full review (click to expand)Findings🔴 HIGHNone. 🟡 MEDIUMNone. 🟢 LOW / NITL1. Guard placement in short-circuit chain —
|
| Context | Affected? | Analysis |
|---|---|---|
| Regular DB + unordered_write | YES | Fix correctly disables conversion. The only production caller of AddLogicallyRedundantRangeTombstone is DBIter::MaybeInsertRangeTombstone (db/db_iter.cc:1932). |
| WritePrepared + two_write_queues + unordered_write | YES | Conservatively disabled. The existing read_callback_ guard (db/db_iter.cc:1905) would prevent the bug, but the fix disables conversion earlier. PR documents this as a known limitation with unmeasured benefit loss. |
| WritePrepared + one_write_queue (no unordered_write) | NO | unordered_write is false, so the new guard doesn't trigger. Existing read_callback_ guard handles this case. |
| WriteUnprepared + unordered_write | YES | Same as WritePrepared — conservatively disabled. |
| ReadOnly DB / SecondaryInstance | NO | active_mem is null, so conversion is already disabled. |
| PipelinedWrite | NO | Incompatible with unordered_write (db/db_impl/db_impl_write.cc:980-983). |
| Dynamic option change | N/A | unordered_write is an ImmutableDBOptions field (options/db_options.h:72), cannot change after DB open. The constructor-time guard is therefore correct. |
Assumption Stress Test
Claim: "disabling at construction time is sufficient."
- Precondition:
unordered_writecannot change after DB open. - Verified: It's in
ImmutableDBOptions(options/db_options.h:72), set fromDBOptionsat DB open (options/db_options.cc:850). NoSetDBOptionspath modifies it. - Result: Valid. Constructor-time is sufficient.
Claim: "the fix covers all insertion paths."
- Precondition:
MaybeInsertRangeTombstoneis the only production caller ofAddLogicallyRedundantRangeTombstone. - Verified: Grep confirms only db/db_iter.cc:1932 calls it in production. db/db_flush_test.cc:4436 is test-only.
- Result: Valid. The fix covers the only path.
Claim: "other write modes are not changed."
- Verified: The check
!ioptions.unordered_writeonly triggers whenunordered_writeis true. Default write path, pipelined writes, and concurrent memtable writes are unaffected. - Result: Valid.
Positive Observations
-
Correct root cause analysis. The PR description accurately identifies the race: seqno publication before memtable insertion allows a scan to convert tombstones at a seqno that covers the pending write. This is permanent data loss, not the relaxed-snapshot behavior
unordered_writedocuments. -
Follows existing guard pattern. Adding to the constructor's boolean condition chain is exactly how the other guards (table_filter, read_tier, prefix, timestamp) work. This is consistent and maintainable.
-
Good test construction. The new test correctly uses sync points to pause the writer between WAL write and memtable insert, advances the published sequence, and verifies both that the scan cannot see the pending key and that the key survives after the write completes. The
Deferpattern ensures cleanup even on assertion failure. -
ASSERT_EQ improvement. Changing
EXPECT_EQtoASSERT_EQforinserted_ranges.size()prevents undefined behavior in the subsequent element access. -
Clear, accurate documentation. The inline comment in db/db_iter.cc explains the race precisely. The comment in advanced_options.h and the release note are appropriately concise.
-
Explicit "Changes visible to existing users" section. The PR description clearly states that DBs with both options set will lose the scan optimization, which is the correct trade-off for data integrity.
ℹ️ About this response
Generated by Claude Code.
Review methodology: claude_md/ci_review_prompt.md
Limitations:
- Claude may miss context from files not in the diff
- Large PRs may be truncated
- Always apply human judgment to AI suggestions
Commands:
/claude-review [context]— Request a code review/claude-query <question>— Ask about the PR or codebase
c96e29f to
70d7ac3
Compare
…eta#15798) Summary: Pull Request resolved: meta#15798 Background: with `min_tombstones_for_range_conversion`, a scan that steps over enough adjacent point tombstones inserts one range tombstone over them into the active memtable, at the scan's read sequence number. Later reads at that sequence number or higher see the range tombstone. A SuperVersion references the memtables and the Version (the list of SST files) of a column family. Reads that pick their own sequence number use one of two orders: - Iterator creation, single column family `MultiGet()`, and a `Refresh()` that rebuilds the iterator reference their SuperVersion first and read the last sequence number after that. This is the pin-first rule: the referenced SuperVersion keeps every key version that a later sequence number can need, so a flush or a compaction cannot drop data that the read needs. - A multi column family read (multi-CF `MultiGet()`, `NewIterators()`) reads one sequence number first and then references the SuperVersions of the group. It retries the whole group if a memtable is newer than that sequence number. A file ingestion publishes the ingested files' sequence number S before it installs the SuperVersion that has the files. So a read can get the old SuperVersion and a sequence number at or above S. If the ingestion does not flush the active memtable, the old and the new SuperVersion share it. Previous behavior: without conversion, such a read sees the state from before the ingestion, which is a consistent view. With conversion, a newer iterator that sees the ingested files can convert a run that a delete in an ingested file completes, at S, into the shared active memtable. The old read then sees that range tombstone, but not the other keys of the ingested file. For example: - An SST file holds `b`. The memtable deletes `a` and `c`, and `d` is live. - An ingested file puts `ax` and deletes `b`, at S. - A read references the old SuperVersion and then reads S. - A newer iterator sees `b` and `c` deleted and converts [`b`, `d`) at S. - The old read sees neither `ax` nor `b`. Before the ingestion, it would see `b`; after it, `ax`. A single-key `Get()` cannot show the problem: the range tombstone hides a key only if the key is deleted at S, so the result is the key's value at S. So `GetImpl()` is not changed, and the fix has four call sites. New behavior: such a read uses the SuperVersion that has the ingested files, so it sees the whole ingestion. Implementation: - `ColumnFamilyData::last_ingest_version_number_` holds the number of the Version that installed the latest successful ingestion, also one that assigns no new sequence number. The ingestion stores it under the DB mutex after `LogAndApply()` and before it publishes its sequence numbers. It is separate from the memtable conversion barrier, which serves scans that try to insert a converted range tombstone. The sequence number store has release ordering and the read's load has acquire ordering, so a read that sees an ingested sequence number also sees this value. - `DBImpl::SuperVersionMissesIngestion()` returns true if the SuperVersion's Version number is older than that value. A read calls it after it has its sequence number. - `DBImpl::ReplaceSuperVersionMissingIngestion()` takes the DB mutex, references the current SuperVersion and releases the old one. The ingestion holds the DB mutex from before it publishes its sequence numbers until it installs its SuperVersion, so the new SuperVersion has every ingestion whose sequence number was published before the call. - After the replacement, the read reads its sequence number again, so the pin-first rule holds for the new SuperVersion. Without this, a write and a flush between the first sequence number and the new reference could drop a key version that the old sequence number needs, and the read would miss a live key. The read repeats the check, because another ingestion can publish its sequence number between the new reference and the new read. Each repeat needs a new ingestion. - The checks that a read runs on its first SuperVersion also run on each new one, with the same errors: a read with `ReadOptions::timestamp` checks it against `full_history_ts_low`, because the new SuperVersion can have files whose older history was already collapsed; an iterator with `ReadOptions::table_filter` checks that conversion is off, because `SetOptions()` can turn it on in between. - Entry points that replace the SuperVersion (pin-first): - `NewIterator()` without a snapshot reads its sequence number in the new `DBImpl::ReadIteratorSequence()`, which runs the loop and the checks and can return an error. `NewIteratorImpl()` then builds the iterator with the sequence number that its caller passes. Its other callers already pass one: the WritePrepared and WriteUnprepared transaction DBs take a snapshot first, and multi column family `NewIterators()` gets its sequence number from `MultiCFSnapshot()`. The sync points `DBImpl::NewIterator:1` to `:4` moved with the sequence number read, so they run only for `NewIterator()` without a snapshot. - The single column family path of `MultiCFSnapshot()` (`MultiGet()`, `MultiGetEntity()`). - `ArenaWrappedDBIter::DoRefresh()`, the `Refresh()` path that rebuilds the iterator. - The multi column family retry loop of `MultiCFSnapshot()` (multi-CF `MultiGet()`, `NewIterators()`, multi-CF iterators) reads one sequence number first, so it does not replace a SuperVersion: it treats a missing ingestion as one more reason to try the whole group again. Its last try holds the DB mutex while it references the SuperVersions. That try now reads the sequence number after it takes the mutex, when the read has no snapshot. Reading it before the mutex left a window in which a flush could drop a version that the sequence number needs. This window existed before this diff, but the extra retries for an ingestion make the last try easier to reach. - Reads with a snapshot that the caller passes skip the check. Such a snapshot already existed when the SuperVersion was referenced, and a snapshot at or above S can be created only after the ingestion installs its SuperVersion. - The in-place path of `Refresh()`, which keeps its iterator tree and only moves the sequence number, needs no check here. It refreshes its memtable range tombstones before it checks the SuperVersion number again, and if it finds range tombstones that its tree has no slot for, it rebuilds the tree at once. A conversion that depends on an ingested file can only happen after the column family installs the ingestion's SuperVersion, so a refresh that sees that conversion also sees the new SuperVersion number and rebuilds. Cost: Each `NewIterator()`, `MultiGet()` and `Refresh()` without a snapshot does two loads (the column family value and the Version number of the SuperVersion) and one compare. The replacement runs only when the compare finds the SuperVersion's Version older than the Version of the latest ingestion, that is, when an ingestion installed its Version after the read referenced its SuperVersion and before the compare. An ingestion that assigns no new sequence number also counts. Each replacement takes the DB mutex once; the loop repeats only for another such ingestion. Releasing the old SuperVersion can take the DB mutex again if that was its last reference. Measured with release db_bench, base vs this change, on an AMD EPYC 9D85 host: a DB of 1M keys (16-byte keys, 100-byte values) after a full compaction, 1 GB block cache, one thread pinned to one CPU, 300,000 operations per run, 3 rounds with the two builds swapped between two CPUs in each round. | Benchmark | Instructions per op, base | Change | Time per op, base | Time per op, this change | |---|---|---|---|---| | seekrandom (a new iterator and one Seek per op) | about 16,600 | +44 to +50 (+0.3%) | 3.05 to 3.18 us | 3.01 to 3.13 us | | multireadrandom (MultiGet of 8 keys) | about 9,900 | within +-3 | 1.89 to 2.07 us | 1.88 to 2.01 us | The time per op does not change beyond the spread between runs. The cause of the extra instructions in seekrandom was not found; moving the retry into a function that is never inlined did not change it. How to read this diff: 1. db/column_family.h: `last_ingest_version_number_` and its accessors; db/db_impl/db_impl.cc `IngestExternalFiles()`, where the ingestion records it before it publishes its sequence numbers. 2. db/db_impl/db_impl.h: the overview at `SuperVersionMissesIngestion()` (the pin-first rule, the problem, the fix), then `ReplaceSuperVersionMissingIngestion()` and `ReadIteratorSequence()`. 3. db/db_impl/db_impl.cc: `NewIterator()` and `ReadIteratorSequence()`, then `MultiCFSnapshot()` (the single column family loop, then the multi column family retry and its last try). 4. db/arena_wrapped_db_iter.cc: `DoRefresh()`. 5. db/db_iterator_test.cc: the `ReadPathRangeTombstoneTest` cases listed in the Test Plan. Changes visible to existing users: the check runs for every user, also with conversion off. An iterator, `MultiGet()` or `Refresh()` that gets a SuperVersion from before an ingestion together with a sequence number from after it now takes the DB mutex, gets the current SuperVersion, reads its sequence number again, and sees the ingested files. Before, it saw the view from before the ingestion. The existing test `IngestedFileSurvivesIteratorWithOlderSuperVersion` (db/db_iterator_test.cc) changes accordingly: its iterator now sees the ingested keys and converts nothing. Differential Revision: D134584125
…ta#15741) Summary: Pull Request resolved: meta#15741 Background: with `min_tombstones_for_range_conversion`, a forward or reverse scan that steps over enough adjacent point tombstones, with no live key between them, adds one range tombstone over the keys it found deleted. The point tombstones stay; the range tombstone is redundant, and later scans use it to seek past the covered keys in older memtables and SST files. The scan inserts the range tombstone into the active memtable at the scan's read sequence number. This is safe only if the scan saw every key in that range that its snapshot includes. With `DBOptions::unordered_write`, a write publishes its sequence number before it inserts its keys into the memtable. An iterator can therefore get a read sequence number at or above a pending write's sequence number while that write's key is still absent from the memtable. Previous behavior: such a scan could convert the point tombstones around the missing key. While the first write was pending, a later write could publish a higher sequence number. An iterator opened at that higher sequence number could miss the pending key, and the converted range tombstone, inserted at the read sequence number, is newer than the pending write. When the write finished, its key was still covered by the range tombstone for every read at the scan's sequence number or higher, also after flush and compaction. This is permanent data loss, not only the relaxed snapshot guarantee that `unordered_write` documents. New behavior: the `DBIter` constructor disables read-path conversion when `unordered_write` is true, next to the existing gates for table filters, read tiers, prefix mode and timestamp visibility. Scans under `unordered_write` never insert converted range tombstones. Implementation: - `db/db_iter.cc`: add `!ioptions.unordered_write` to the condition that sets `min_tombstones_for_range_conversion_`, and explain why in the existing comment. - `include/rocksdb/advanced_options.h`: list `unordered_write` among the configurations where conversion is disabled (comment only). - `unreleased_history/bug_fixes/unordered_write_range_conversion.md`: release note. Safety and unsupported cases: other write modes are not changed. The default write path, pipelined writes, concurrent memtable writes and `two_write_queues` without `unordered_write` publish a sequence number only after the memtable insert finishes, so a scan cannot miss a key that its snapshot includes. WritePrepared and WriteUnprepared transactions keep their existing guard: a scan does not convert when its snapshot is at or above the oldest uncommitted sequence number. Known limitations: conversion is also disabled for a WritePrepared transaction DB that uses `unordered_write` (which requires `two_write_queues`), although the existing guard could make it safe there. A WritePrepared iterator carries `min_uncommitted`, a conservative lower bound on the sequence number of the oldest pending write that the transaction DB tracks, and conversion refuses a scan whose sequence number reaches that bound. This guard covers a pending write only if the write goes through the transaction DB, which registers its sequence number. A write to the base DB under the transaction DB (for example through `GetBaseDB()`) is not registered, so the guard does not cover it. So `unordered_write` turns conversion off for the whole configuration, also for a transaction DB. The lost benefit was not measured. Changes visible to existing users: DBs, including transaction DBs, that set both `unordered_write` and `min_tombstones_for_range_conversion` do not get read-path range tombstones, so their scans over long tombstone runs do not get faster. Differential Revision: D133500312
70d7ac3 to
de7dab8
Compare
…ta#15741) Summary: Pull Request resolved: meta#15741 Background: with `min_tombstones_for_range_conversion`, a forward or reverse scan that steps over enough adjacent point tombstones, with no live key between them, adds one range tombstone over the keys it found deleted. The point tombstones stay; the range tombstone is redundant, and later scans use it to seek past the covered keys in older memtables and SST files. The scan inserts the range tombstone into the active memtable at the scan's read sequence number. This is safe only if the scan saw every key in that range that its snapshot includes. With `DBOptions::unordered_write`, a write publishes its sequence number before it inserts its keys into the memtable. An iterator can therefore get a read sequence number at or above a pending write's sequence number while that write's key is still absent from the memtable. Previous behavior: such a scan could convert the point tombstones around the missing key. While the first write was pending, a later write could publish a higher sequence number. An iterator opened at that higher sequence number could miss the pending key, and the converted range tombstone, inserted at the read sequence number, is newer than the pending write. When the write finished, its key was still covered by the range tombstone for every read at the scan's sequence number or higher, also after flush and compaction. This is permanent data loss, not only the relaxed snapshot guarantee that `unordered_write` documents. New behavior: the `DBIter` constructor disables read-path conversion when `unordered_write` is true, next to the existing gates for table filters, read tiers, prefix mode and timestamp visibility. Scans under `unordered_write` never insert converted range tombstones. Implementation: - `db/db_iter.cc`: add `!ioptions.unordered_write` to the condition that sets `min_tombstones_for_range_conversion_`, and explain why in the existing comment. - `include/rocksdb/advanced_options.h`: list `unordered_write` among the configurations where conversion is disabled (comment only). - `unreleased_history/bug_fixes/unordered_write_range_conversion.md`: release note. Safety and unsupported cases: other write modes are not changed. The default write path, pipelined writes, concurrent memtable writes and `two_write_queues` without `unordered_write` publish a sequence number only after the memtable insert finishes, so a scan cannot miss a key that its snapshot includes. WritePrepared and WriteUnprepared transactions keep their existing guard: a scan does not convert when its snapshot is at or above the oldest uncommitted sequence number. Known limitations: conversion is also disabled for a WritePrepared transaction DB that uses `unordered_write` (which requires `two_write_queues`), although the existing guard could make it safe there. A WritePrepared iterator carries `min_uncommitted`, a conservative lower bound on the sequence number of the oldest pending write that the transaction DB tracks, and conversion refuses a scan whose sequence number reaches that bound. This guard covers a pending write only if the write goes through the transaction DB, which registers its sequence number. A write to the base DB under the transaction DB (for example through `GetBaseDB()`) is not registered, so the guard does not cover it. So `unordered_write` turns conversion off for the whole configuration, also for a transaction DB. The lost benefit was not measured. Changes visible to existing users: DBs, including transaction DBs, that set both `unordered_write` and `min_tombstones_for_range_conversion` do not get read-path range tombstones, so their scans over long tombstone runs do not get faster. Differential Revision: D133500312
…ta#15741) Summary: Pull Request resolved: meta#15741 Background: with `min_tombstones_for_range_conversion`, a forward or reverse scan that steps over enough adjacent point tombstones, with no live key between them, adds one range tombstone over the keys it found deleted. The point tombstones stay; the range tombstone is redundant, and later scans use it to seek past the covered keys in older memtables and SST files. The scan inserts the range tombstone into the active memtable at the scan's read sequence number. This is safe only if the scan saw every key in that range that its snapshot includes. With `DBOptions::unordered_write`, a write publishes its sequence number before it inserts its keys into the memtable. An iterator can therefore get a read sequence number at or above a pending write's sequence number while that write's key is still absent from the memtable. Previous behavior: such a scan could convert the point tombstones around the missing key. While the first write was pending, a later write could publish a higher sequence number. An iterator opened at that higher sequence number could miss the pending key, and the converted range tombstone, inserted at the read sequence number, is newer than the pending write. When the write finished, its key was still covered by the range tombstone for every read at the scan's sequence number or higher, also after flush and compaction. This is permanent data loss, not only the relaxed snapshot guarantee that `unordered_write` documents. New behavior: the `DBIter` constructor disables read-path conversion when `unordered_write` is true, next to the existing gates for table filters, read tiers, prefix mode and timestamp visibility. Scans under `unordered_write` never insert converted range tombstones. Implementation: - `db/db_iter.cc`: add `!ioptions.unordered_write` to the condition that sets `min_tombstones_for_range_conversion_`, and explain why in the existing comment. - `include/rocksdb/advanced_options.h`: list `unordered_write` among the configurations where conversion is disabled (comment only). - `unreleased_history/bug_fixes/unordered_write_range_conversion.md`: release note. Safety and unsupported cases: other write modes are not changed. The default write path, pipelined writes, concurrent memtable writes and `two_write_queues` without `unordered_write` publish a sequence number only after the memtable insert finishes, so a scan cannot miss a key that its snapshot includes. WritePrepared and WriteUnprepared transactions keep their existing guard: a scan does not convert when its snapshot is at or above the oldest uncommitted sequence number. Known limitations: conversion is also disabled for a WritePrepared transaction DB that uses `unordered_write` (which requires `two_write_queues`), although the existing guard could make it safe there. A WritePrepared iterator carries `min_uncommitted`, a conservative lower bound on the sequence number of the oldest pending write that the transaction DB tracks, and conversion refuses a scan whose sequence number reaches that bound. This guard covers a pending write only if the write goes through the transaction DB, which registers its sequence number. A write to the base DB under the transaction DB (for example through `GetBaseDB()`) is not registered, so the guard does not cover it. So `unordered_write` turns conversion off for the whole configuration, also for a transaction DB. The lost benefit was not measured. Changes visible to existing users: DBs, including transaction DBs, that set both `unordered_write` and `min_tombstones_for_range_conversion` do not get read-path range tombstones, so their scans over long tombstone runs do not get faster. Differential Revision: D133500312
…ta#15741) Summary: Background: with `min_tombstones_for_range_conversion`, a forward or reverse scan that steps over enough adjacent point tombstones, with no live key between them, adds one range tombstone over the keys it found deleted. The point tombstones stay; the range tombstone is redundant, and later scans use it to seek past the covered keys in older memtables and SST files. The scan inserts the range tombstone into the active memtable at the scan's read sequence number. This is safe only if the scan saw every key in that range that its snapshot includes. With `DBOptions::unordered_write`, a write publishes its sequence number before it inserts its keys into the memtable. An iterator can therefore get a read sequence number at or above a pending write's sequence number while that write's key is still absent from the memtable. Previous behavior: such a scan could convert the point tombstones around the missing key. While the first write was pending, a later write could publish a higher sequence number. An iterator opened at that higher sequence number could miss the pending key, and the converted range tombstone, inserted at the read sequence number, is newer than the pending write. When the write finished, its key was still covered by the range tombstone for every read at the scan's sequence number or higher, also after flush and compaction. This is permanent data loss, not only the relaxed snapshot guarantee that `unordered_write` documents. New behavior: the `DBIter` constructor disables read-path conversion when `unordered_write` is true, next to the existing gates for table filters, read tiers, prefix mode and timestamp visibility. Scans under `unordered_write` never insert converted range tombstones. Implementation: - `db/db_iter.cc`: add `!ioptions.unordered_write` to the condition that sets `min_tombstones_for_range_conversion_`, and explain why in the existing comment. - `include/rocksdb/advanced_options.h`: list `unordered_write` among the configurations where conversion is disabled (comment only). - `unreleased_history/bug_fixes/unordered_write_range_conversion.md`: release note. Safety and unsupported cases: other write modes are not changed. The default write path, pipelined writes, concurrent memtable writes and `two_write_queues` without `unordered_write` publish a sequence number only after the memtable insert finishes, so a scan cannot miss a key that its snapshot includes. WritePrepared and WriteUnprepared transactions keep their existing guard: a scan does not convert when its snapshot is at or above the oldest uncommitted sequence number. Known limitations: conversion is also disabled for a WritePrepared transaction DB that uses `unordered_write` (which requires `two_write_queues`), although the existing guard could make it safe there. A WritePrepared iterator carries `min_uncommitted`, a conservative lower bound on the sequence number of the oldest pending write that the transaction DB tracks, and conversion refuses a scan whose sequence number reaches that bound. This guard covers a pending write only if the write goes through the transaction DB, which registers its sequence number. A write to the base DB under the transaction DB (for example through `GetBaseDB()`) is not registered, so the guard does not cover it. So `unordered_write` turns conversion off for the whole configuration, also for a transaction DB. The lost benefit was not measured. Changes visible to existing users: DBs, including transaction DBs, that set both `unordered_write` and `min_tombstones_for_range_conversion` do not get read-path range tombstones, so their scans over long tombstone runs do not get faster. Differential Revision: D133500312
…ta#15741) Summary: Pull Request resolved: meta#15741 Background: with `min_tombstones_for_range_conversion`, a forward or reverse scan that steps over enough adjacent point tombstones, with no live key between them, adds one range tombstone over the keys it found deleted. The point tombstones stay; the range tombstone is redundant, and later scans use it to seek past the covered keys in older memtables and SST files. The scan inserts the range tombstone into the active memtable at the scan's read sequence number. This is safe only if the scan saw every key in that range that its snapshot includes. With `DBOptions::unordered_write`, a write publishes its sequence number before it inserts its keys into the memtable. An iterator can therefore get a read sequence number at or above a pending write's sequence number while that write's key is still absent from the memtable. Previous behavior: such a scan could convert the point tombstones around the missing key. While the first write was pending, a later write could publish a higher sequence number. An iterator opened at that higher sequence number could miss the pending key, and the converted range tombstone, inserted at the read sequence number, is newer than the pending write. When the write finished, its key was still covered by the range tombstone for every read at the scan's sequence number or higher, also after flush and compaction. This is permanent data loss, not only the relaxed snapshot guarantee that `unordered_write` documents. New behavior: the `DBIter` constructor disables read-path conversion when `unordered_write` is true, next to the existing gates for table filters, read tiers, prefix mode and timestamp visibility. Scans under `unordered_write` never insert converted range tombstones. Implementation: - `db/db_iter.cc`: add `!ioptions.unordered_write` to the condition that sets `min_tombstones_for_range_conversion_`, and explain why in the existing comment. - `include/rocksdb/advanced_options.h`: list `unordered_write` among the configurations where conversion is disabled (comment only). - `unreleased_history/bug_fixes/unordered_write_range_conversion.md`: release note. Safety and unsupported cases: other write modes are not changed. The default write path, pipelined writes, concurrent memtable writes and `two_write_queues` without `unordered_write` publish a sequence number only after the memtable insert finishes, so a scan cannot miss a key that its snapshot includes. WritePrepared and WriteUnprepared transactions keep their existing guard: a scan does not convert when its snapshot is at or above the oldest uncommitted sequence number. Known limitations: conversion is also disabled for a WritePrepared transaction DB that uses `unordered_write` (which requires `two_write_queues`), although the existing guard could make it safe there. A WritePrepared iterator carries `min_uncommitted`, a conservative lower bound on the sequence number of the oldest pending write that the transaction DB tracks, and conversion refuses a scan whose sequence number reaches that bound. This guard covers a pending write only if the write goes through the transaction DB, which registers its sequence number. A write to the base DB under the transaction DB (for example through `GetBaseDB()`) is not registered, so the guard does not cover it. So `unordered_write` turns conversion off for the whole configuration, also for a transaction DB. The lost benefit was not measured. Changes visible to existing users: DBs, including transaction DBs, that set both `unordered_write` and `min_tombstones_for_range_conversion` do not get read-path range tombstones, so their scans over long tombstone runs do not get faster. Differential Revision: D133500312
…ta#15741) Summary: Pull Request resolved: meta#15741 Background: with `min_tombstones_for_range_conversion`, a forward or reverse scan that steps over enough adjacent point tombstones, with no live key between them, adds one range tombstone over the keys it found deleted. The point tombstones stay; the range tombstone is redundant, and later scans use it to seek past the covered keys in older memtables and SST files. The scan inserts the range tombstone into the active memtable at the scan's read sequence number. This is safe only if the scan saw every key in that range that its snapshot includes. With `DBOptions::unordered_write`, a write publishes its sequence number before it inserts its keys into the memtable. An iterator can therefore get a read sequence number at or above a pending write's sequence number while that write's key is still absent from the memtable. Previous behavior: such a scan could convert the point tombstones around the missing key. While the first write was pending, a later write could publish a higher sequence number. An iterator opened at that higher sequence number could miss the pending key, and the converted range tombstone, inserted at the read sequence number, is newer than the pending write. When the write finished, its key was still covered by the range tombstone for every read at the scan's sequence number or higher, also after flush and compaction. This is permanent data loss, not only the relaxed snapshot guarantee that `unordered_write` documents. New behavior: the `DBIter` constructor disables read-path conversion when `unordered_write` is true, next to the existing gates for table filters, read tiers, prefix mode and timestamp visibility. Scans under `unordered_write` never insert converted range tombstones. Implementation: - `db/db_iter.cc`: add `!ioptions.unordered_write` to the condition that sets `min_tombstones_for_range_conversion_`, and explain why in the existing comment. - `include/rocksdb/advanced_options.h`: list `unordered_write` among the configurations where conversion is disabled (comment only). - `unreleased_history/bug_fixes/unordered_write_range_conversion.md`: release note. Safety and unsupported cases: other write modes are not changed. The default write path, pipelined writes, concurrent memtable writes and `two_write_queues` without `unordered_write` publish a sequence number only after the memtable insert finishes, so a scan cannot miss a key that its snapshot includes. WritePrepared and WriteUnprepared transactions keep their existing guard: a scan does not convert when its snapshot is at or above the oldest uncommitted sequence number. Known limitations: conversion is also disabled for a WritePrepared transaction DB that uses `unordered_write` (which requires `two_write_queues`), although the existing guard could make it safe there. A WritePrepared iterator carries `min_uncommitted`, a conservative lower bound on the sequence number of the oldest pending write that the transaction DB tracks, and conversion refuses a scan whose sequence number reaches that bound. This guard covers a pending write only if the write goes through the transaction DB, which registers its sequence number. A write to the base DB under the transaction DB (for example through `GetBaseDB()`) is not registered, so the guard does not cover it. So `unordered_write` turns conversion off for the whole configuration, also for a transaction DB. The lost benefit was not measured. Changes visible to existing users: DBs, including transaction DBs, that set both `unordered_write` and `min_tombstones_for_range_conversion` do not get read-path range tombstones, so their scans over long tombstone runs do not get faster. Differential Revision: D133500312
…ta#15741) Summary: Pull Request resolved: meta#15741 Background: with `min_tombstones_for_range_conversion`, a forward or reverse scan that steps over enough adjacent point tombstones, with no live key between them, adds one range tombstone over the keys it found deleted. The point tombstones stay; the range tombstone is redundant, and later scans use it to seek past the covered keys in older memtables and SST files. The scan inserts the range tombstone into the active memtable at the scan's read sequence number. This is safe only if the scan saw every key in that range that its snapshot includes. With `DBOptions::unordered_write`, a write publishes its sequence number before it inserts its keys into the memtable. An iterator can therefore get a read sequence number at or above a pending write's sequence number while that write's key is still absent from the memtable. Previous behavior: such a scan could convert the point tombstones around the missing key. While the first write was pending, a later write could publish a higher sequence number. An iterator opened at that higher sequence number could miss the pending key, and the converted range tombstone, inserted at the read sequence number, is newer than the pending write. When the write finished, its key was still covered by the range tombstone for every read at the scan's sequence number or higher, also after flush and compaction. This is permanent data loss, not only the relaxed snapshot guarantee that `unordered_write` documents. New behavior: the `DBIter` constructor disables read-path conversion when `unordered_write` is true, next to the existing gates for table filters, read tiers, prefix mode and timestamp visibility. Scans under `unordered_write` never insert converted range tombstones. Implementation: - `db/db_iter.cc`: add `!ioptions.unordered_write` to the condition that sets `min_tombstones_for_range_conversion_`, and explain why in the existing comment. - `include/rocksdb/advanced_options.h`: list `unordered_write` among the configurations where conversion is disabled (comment only). - `unreleased_history/bug_fixes/unordered_write_range_conversion.md`: release note. Safety and unsupported cases: other write modes are not changed. The default write path, pipelined writes, concurrent memtable writes and `two_write_queues` without `unordered_write` publish a sequence number only after the memtable insert finishes, so a scan cannot miss a key that its snapshot includes. WritePrepared and WriteUnprepared transactions keep their existing guard: a scan does not convert when its snapshot is at or above the oldest uncommitted sequence number. Known limitations: conversion is also disabled for a WritePrepared transaction DB that uses `unordered_write` (which requires `two_write_queues`), although the existing guard could make it safe there. A WritePrepared iterator carries `min_uncommitted`, a conservative lower bound on the sequence number of the oldest pending write that the transaction DB tracks, and conversion refuses a scan whose sequence number reaches that bound. This guard covers a pending write only if the write goes through the transaction DB, which registers its sequence number. A write to the base DB under the transaction DB (for example through `GetBaseDB()`) is not registered, so the guard does not cover it. So `unordered_write` turns conversion off for the whole configuration, also for a transaction DB. The lost benefit was not measured. Changes visible to existing users: DBs, including transaction DBs, that set both `unordered_write` and `min_tombstones_for_range_conversion` do not get read-path range tombstones, so their scans over long tombstone runs do not get faster. Differential Revision: D133500312
Summary:
Background: with
min_tombstones_for_range_conversion, a forward or reverse scan that steps over enough adjacent point tombstones, with no live key between them, adds one range tombstone over the keys it found deleted. The point tombstones stay; the range tombstone is redundant, and later scans use it to seek past the covered keys in older memtables and SST files. The scan inserts the range tombstone into the active memtable at the scan's read sequence number. This is safe only if the scan saw every key in that range that its snapshot includes.With
DBOptions::unordered_write, a write publishes its sequence number before it inserts its keys into the memtable. An iterator can therefore get a read sequence number at or above a pending write's sequence number while that write's key is still absent from the memtable.Previous behavior: such a scan could convert the point tombstones around the missing key. While the first write was pending, a later write could publish a higher sequence number. An iterator opened at that higher sequence number could miss the pending key, and the converted range tombstone, inserted at the read sequence number, is newer than the pending write. When the write finished, its key was still covered by the range tombstone for every read at the scan's sequence number or higher, also after flush and compaction. This is permanent data loss, not only the relaxed snapshot guarantee that
unordered_writedocuments.New behavior: the
DBIterconstructor disables read-path conversion whenunordered_writeis true, next to the existing gates for table filters, read tiers, prefix mode and timestamp visibility. Scans underunordered_writenever insert converted range tombstones.Implementation:
db/db_iter.cc: add!ioptions.unordered_writeto the condition that setsmin_tombstones_for_range_conversion_, and explain why in the existing comment.include/rocksdb/advanced_options.h: listunordered_writeamong the configurations where conversion is disabled (comment only).unreleased_history/bug_fixes/unordered_write_range_conversion.md: release note.Safety and unsupported cases: other write modes are not changed. The default write path, pipelined writes, concurrent memtable writes and
two_write_queueswithoutunordered_writepublish a sequence number only after the memtable insert finishes, so a scan cannot miss a key that its snapshot includes. WritePrepared and WriteUnprepared transactions keep their existing guard: a scan does not convert when its snapshot is at or above the oldest uncommitted sequence number.Known limitations: conversion is also disabled for a WritePrepared transaction DB that uses
unordered_write(which requirestwo_write_queues), although the existing guard could make it safe there. A WritePrepared iterator carriesmin_uncommitted, a conservative lower bound on the sequence number of the oldest pending write that the transaction DB tracks, and conversion refuses a scan whose sequence number reaches that bound. This guard covers a pending write only if the write goes through the transaction DB, which registers its sequence number. A write to the base DB under the transaction DB (for example throughGetBaseDB()) is not registered, so the guard does not cover it. Sounordered_writeturns conversion off for the whole configuration, also for a transaction DB. The lost benefit was not measured.Changes visible to existing users: DBs, including transaction DBs, that set both
unordered_writeandmin_tombstones_for_range_conversiondo not get read-path range tombstones, so their scans over long tombstone runs do not get faster.Differential Revision: D133500312