Skip to content

Optimize compaction for standalone range deletion files - #13078

Closed
jowlyzhang wants to merge 6 commits into
meta:mainfrom
jowlyzhang:standalone_rangedel_file
Closed

jowlyzhang wants to merge 6 commits into
meta:mainfrom
jowlyzhang:standalone_rangedel_file

Conversation

@jowlyzhang

@jowlyzhang jowlyzhang commented Oct 17, 2024 •

Copy link
Copy Markdown
Contributor

This PR adds some optimization for compacting standalone range deletion files. A standalone range deletion file is one with just a single range deletion. Currently, such a file is used in bulk loading to achieve something like atomically delete old version of all data with one big range deletion and adding new version of data. These are the changes included in the PR:

  1. When a standalone range deletion file is ingested via bulk loading, it's marked for compaction.
  2. When picking input files during compaction picking, we attempt to only pick a standalone range deletion file when oldest snapshot is at or above the file's seqno. To do this, PickCompaction API is updated to take existing snapshots as an input. This is only done for the universal compaction + UDT disabled combination, we save querying for existing snapshots and not pass it for all other cases.
  3. At Compaction construction time, the input files will be filtered to examine if any of them can be skipped for compaction iterator. For example, if all the data of the file is deleted by a standalone range tombstone, and the oldest snapshot is at or above such range tombstone, this file will be filtered out.
  4. Every time a snapshot is released, we examine if any column family has standalone range deletion files that becomes eligible to be scheduled for compaction. And schedule one for it.

Potential future improvements:

  • Add some dedicated statistics for the filtered files.
  • Extend this input filtering to L0 files' compactions cases when a newer L0 file could shadow an older L0 file

Test plan:
Added unit tests and stress tested a few rounds

@jowlyzhang
jowlyzhang force-pushed the standalone_rangedel_file branch 2 times, most recently from d06bb7f to a2c0de6 Compare October 17, 2024 18:58
Comment thread db/db_impl/db_impl.cc Resolved
@jowlyzhang
jowlyzhang force-pushed the standalone_rangedel_file branch 2 times, most recently from b09c843 to 191f53d Compare October 17, 2024 23:18

@cbi42 cbi42 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some initial comments without digging into tests. Mostly about the compaction picking logic.

Comment thread db/compaction/compaction.cc Resolved
Comment thread db/compaction/compaction.cc Resolved
Comment thread db/compaction/compaction_job.cc Resolved
Comment thread db/compaction/compaction_job.cc Resolved
Comment thread db/compaction/compaction.h Resolved
Comment thread db/compaction/compaction.cc Resolved

@pdillinger pdillinger left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good to me!

Thanks @cbi42 for digging into many details

Comment thread db/compaction/compaction.cc Resolved
Comment thread db/db_impl/db_impl.cc Resolved
Comment thread db/external_sst_file_basic_test.cc Resolved

@cbi42 cbi42 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comments are mostly suggestions/questions other than the one for compaction picker.

Comment thread db/compaction/compaction_picker.cc Resolved
Comment thread db_stress_tool/no_batched_ops_stress.cc Resolved
Comment thread db_stress_tool/no_batched_ops_stress.cc Resolved
Comment thread db/external_sst_file_basic_test.cc Resolved
@jowlyzhang
jowlyzhang force-pushed the standalone_rangedel_file branch from 4f99ad7 to f6146f7 Compare October 24, 2024 03:00
@jowlyzhang

Copy link
Copy Markdown
Contributor Author

@cbi42 and @pdillinger Thank you a lot for the quick and thorough reviews!

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@jowlyzhang has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@cbi42

cbi42 commented Oct 25, 2024

Copy link
Copy Markdown
Contributor

Add a change log?

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@jowlyzhang has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@jowlyzhang has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@jowlyzhang merged this pull request in 9c94559.

@jowlyzhang
jowlyzhang deleted the standalone_rangedel_file branch October 28, 2024 17:31
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 29, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- The output level is not the last level. The cut tombstone no longer hides older values in the levels below, so they become visible again. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 29, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- The output level is not the last level. The cut tombstone no longer hides older values in the levels below, so they become visible again. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 29, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- The output level is not the last level. The cut tombstone no longer hides older values in the levels below, so they become visible again. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 29, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- The output level is not the last level. The cut tombstone no longer hides older values in the levels below, so they become visible again. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 29, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- The output level is not the last level. The cut tombstone no longer hides older values in the levels below, so they become visible again. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 29, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- The output level is not the last level. The cut tombstone no longer hides older values in the levels below, so they become visible again. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 29, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- The output level is not the last level. The cut tombstone no longer hides older values in the levels below, so they become visible again. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 29, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- The output level is not the last level. The cut tombstone no longer hides older values in the levels below, so they become visible again. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 29, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- The output level is not the last level. The cut tombstone no longer hides older values in the levels below, so they become visible again. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 29, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- The output level is not the last level. The cut tombstone no longer hides older values in the levels below, so they become visible again. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 29, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- The output level is not the last level. The cut tombstone no longer hides older values in the levels below, so they become visible again. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- An older version of a key sits in a level below the kept file, under the kept file's range tombstone. The cut tombstone no longer hides it. If that level is below the output level, reads see the old value again. If that level is a lower input level of the same compaction, the compaction writes the old value to the output, also when the output is the last level. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value. This happens both when the compaction writes into L5 and when it also reads the L6 file and writes into L6. The tests below reproduce both shapes.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not. These two kinds read only the start level and the next non-empty level, so the hidden older value always sits below the output level or in the kept file itself.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`. Such a compaction can read three or more levels and write into the last level, so the hidden older value can also sit in a lower input level of the same compaction.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- An older version of a key sits in a level below the kept file, under the kept file's range tombstone. The cut tombstone no longer hides it. If that level is below the output level, reads see the old value again. If that level is a lower input level of the same compaction, the compaction writes the old value to the output, also when the output is the last level. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value. This happens both when the compaction writes into L5 and when it also reads the L6 file and writes into L6. The tests below reproduce both shapes.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not. These two kinds read only the start level and the next non-empty level, so the hidden older value always sits below the output level or in the kept file itself.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`. Such a compaction can read three or more levels and write into the last level, so the hidden older value can also sit in a lower input level of the same compaction.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- An older version of a key sits in a level below the kept file, under the kept file's range tombstone. The cut tombstone no longer hides it. If that level is below the output level, reads see the old value again. If that level is a lower input level of the same compaction, the compaction writes the old value to the output, also when the output is the last level. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value. This happens both when the compaction writes into L5 and when it also reads the L6 file and writes into L6. The tests below reproduce both shapes.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not. These two kinds read only the start level and the next non-empty level, so the hidden older value always sits below the output level or in the kept file itself.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`. Such a compaction can read three or more levels and write into the last level, so the hidden older value can also sit in a lower input level of the same compaction.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- An older version of a key sits in a level below the kept file, under the kept file's range tombstone. The cut tombstone no longer hides it. If that level is below the output level, reads see the old value again. If that level is a lower input level of the same compaction, the compaction writes the old value to the output, also when the output is the last level. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value. This happens both when the compaction writes into L5 and when it also reads the L6 file and writes into L6. The tests below reproduce both shapes.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not. These two kinds read only the start level and the next non-empty level, so the hidden older value always sits below the output level or in the kept file itself.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`. Such a compaction can read three or more levels and write into the last level, so the hidden older value can also sit in a lower input level of the same compaction.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- An older version of a key sits in a level below the kept file, under the kept file's range tombstone. The cut tombstone no longer hides it. If that level is below the output level, reads see the old value again. If that level is a lower input level of the same compaction, the compaction writes the old value to the output, also when the output is the last level. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value. This happens both when the compaction writes into L5 and when it also reads the L6 file and writes into L6. The tests below reproduce both shapes.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not. These two kinds read only the start level and the next non-empty level, so the hidden older value always sits below the output level or in the kept file itself.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`. Such a compaction can read three or more levels and write into the last level, so the hidden older value can also sit in a lower input level of the same compaction.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- An older version of a key sits in a level below the kept file, under the kept file's range tombstone. The cut tombstone no longer hides it. If that level is below the output level, reads see the old value again. If that level is a lower input level of the same compaction, the compaction writes the old value to the output, also when the output is the last level. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value. This happens both when the compaction writes into L5 and when it also reads the L6 file and writes into L6. The tests below reproduce both shapes.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not. These two kinds read only the start level and the next non-empty level, so the hidden older value always sits below the output level or in the kept file itself.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`. Such a compaction can read three or more levels and write into the last level, so the hidden older value can also sit in a lower input level of the same compaction.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- An older version of a key sits in a level below the kept file, under the kept file's range tombstone. The cut tombstone no longer hides it. If that level is below the output level, reads see the old value again. If that level is a lower input level of the same compaction, the compaction writes the old value to the output, also when the output is the last level. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value. This happens both when the compaction writes into L5 and when it also reads the L6 file and writes into L6. The tests below reproduce both shapes.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not. These two kinds read only the start level and the next non-empty level, so the hidden older value always sits below the output level or in the kept file itself.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`. Such a compaction can read three or more levels and write into the last level, so the hidden older value can also sit in a lower input level of the same compaction.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- An older version of a key sits in a level below the kept file, under the kept file's range tombstone. The cut tombstone no longer hides it. If that level is below the output level, reads see the old value again. If that level is a lower input level of the same compaction, the compaction writes the old value to the output, also when the output is the last level. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value. This happens both when the compaction writes into L5 and when it also reads the L6 file and writes into L6. The tests below reproduce both shapes.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not. These two kinds read only the start level and the next non-empty level, so the hidden older value always sits below the output level or in the kept file itself.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`. Such a compaction can read three or more levels and write into the last level, so the hidden older value can also sit in a lower input level of the same compaction.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- An older version of a key sits in a level below the kept file, under the kept file's range tombstone. The cut tombstone no longer hides it. If that level is below the output level, reads see the old value again. If that level is a lower input level of the same compaction, the compaction writes the old value to the output, also when the output is the last level. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value. This happens both when the compaction writes into L5 and when it also reads the L6 file and writes into L6. The tests below reproduce both shapes.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not. These two kinds read only the start level and the next non-empty level, so the hidden older value always sits below the output level or in the kept file itself.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`. Such a compaction can read three or more levels and write into the last level, so the hidden older value can also sit in a lower input level of the same compaction.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- An older version of a key sits in a level below the kept file, under the kept file's range tombstone. The cut tombstone no longer hides it. If that level is below the output level, reads see the old value again. If that level is a lower input level of the same compaction, the compaction writes the old value to the output, also when the output is the last level. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value. This happens both when the compaction writes into L5 and when it also reads the L6 file and writes into L6. The tests below reproduce both shapes.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not. These two kinds read only the start level and the next non-empty level, so the hidden older value always sits below the output level or in the kept file itself.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`. Such a compaction can read three or more levels and write into the last level, so the hidden older value can also sit in a lower input level of the same compaction.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- An older version of a key sits in a level below the kept file, under the kept file's range tombstone. The cut tombstone no longer hides it. If that level is below the output level, reads see the old value again. If that level is a lower input level of the same compaction, the compaction writes the old value to the output, also when the output is the last level. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value. This happens both when the compaction writes into L5 and when it also reads the L6 file and writes into L6. The tests below reproduce both shapes.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not. These two kinds read only the start level and the next non-empty level, so the hidden older value always sits below the output level or in the kept file itself.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`. Such a compaction can read three or more levels and write into the last level, so the hidden older value can also sit in a lower input level of the same compaction.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- An older version of a key sits in a level below the kept file, under the kept file's range tombstone. The cut tombstone no longer hides it. If that level is below the output level, reads see the old value again. If that level is a lower input level of the same compaction, the compaction writes the old value to the output, also when the output is the last level. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value. This happens both when the compaction writes into L5 and when it also reads the L6 file and writes into L6. The tests below reproduce both shapes.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not. These two kinds read only the start level and the next non-empty level, so the hidden older value always sits below the output level or in the kept file itself.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`. Such a compaction can read three or more levels and write into the last level, so the hidden older value can also sit in a lower input level of the same compaction.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- An older version of a key sits in a level below the kept file, under the kept file's range tombstone. The cut tombstone no longer hides it. If that level is below the output level, reads see the old value again. If that level is a lower input level of the same compaction, the compaction writes the old value to the output, also when the output is the last level. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value. This happens both when the compaction writes into L5 and when it also reads the L6 file and writes into L6. The tests below reproduce both shapes.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not. These two kinds read only the start level and the next non-empty level, so the hidden older value always sits below the output level or in the kept file itself.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`. Such a compaction can read three or more levels and write into the last level, so the hidden older value can also sit in a lower input level of the same compaction.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- An older version of a key sits in a level below the kept file, under the kept file's range tombstone. The cut tombstone no longer hides it. If that level is below the output level, reads see the old value again. If that level is a lower input level of the same compaction, the compaction writes the old value to the output, also when the output is the last level. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value. This happens both when the compaction writes into L5 and when it also reads the L6 file and writes into L6. The tests below reproduce both shapes.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not. These two kinds read only the start level and the next non-empty level, so the hidden older value always sits below the output level or in the kept file itself.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`. Such a compaction can read three or more levels and write into the last level, so the hidden older value can also sit in a lower input level of the same compaction.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- An older version of a key sits in a level below the kept file, under the kept file's range tombstone. The cut tombstone no longer hides it. If that level is below the output level, reads see the old value again. If that level is a lower input level of the same compaction, the compaction writes the old value to the output, also when the output is the last level. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value. This happens both when the compaction writes into L5 and when it also reads the L6 file and writes into L6. The tests below reproduce both shapes.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not. These two kinds read only the start level and the next non-empty level, so the hidden older value always sits below the output level or in the kept file itself.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`. Such a compaction can read three or more levels and write into the last level, so the hidden older value can also sit in a lower input level of the same compaction.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- An older version of a key sits in a level below the kept file, under the kept file's range tombstone. The cut tombstone no longer hides it. If that level is below the output level, reads see the old value again. If that level is a lower input level of the same compaction, the compaction writes the old value to the output, also when the output is the last level. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value. This happens both when the compaction writes into L5 and when it also reads the L6 file and writes into L6. The tests below reproduce both shapes.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not. These two kinds read only the start level and the next non-empty level, so the hidden older value always sits below the output level or in the kept file itself.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`. Such a compaction can read three or more levels and write into the last level, so the hidden older value can also sit in a lower input level of the same compaction.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- An older version of a key sits in a level below the kept file, under the kept file's range tombstone. The cut tombstone no longer hides it. If that level is below the output level, reads see the old value again. If that level is a lower input level of the same compaction, the compaction writes the old value to the output, also when the output is the last level. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value. This happens both when the compaction writes into L5 and when it also reads the L6 file and writes into L6. The tests below reproduce both shapes.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not. These two kinds read only the start level and the next non-empty level, so the hidden older value always sits below the output level or in the kept file itself.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`. Such a compaction can read three or more levels and write into the last level, so the hidden older value can also sit in a lower input level of the same compaction.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- An older version of a key sits in a level below the kept file, under the kept file's range tombstone. The cut tombstone no longer hides it. If that level is below the output level, reads see the old value again. If that level is a lower input level of the same compaction, the compaction writes the old value to the output, also when the output is the last level. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value. This happens both when the compaction writes into L5 and when it also reads the L6 file and writes into L6. The tests below reproduce both shapes.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not. These two kinds read only the start level and the next non-empty level, so the hidden older value always sits below the output level or in the kept file itself.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`. Such a compaction can read three or more levels and write into the last level, so the hidden older value can also sit in a lower input level of the same compaction.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
xingbowang added a commit to xingbowang/rocksdb that referenced this pull request Nov 30, 2026
…on inputs

Summary:
Background: in universal compaction, a compaction can start with a standalone range deletion file, which is a file that holds only one range tombstone (usually from an ingestion that replaces a key range). When that tombstone is visible to the earliest snapshot, `Compaction::FilterInputsForCompactionIterator()` leaves out each input file of the other input levels that the tombstone fully covers (whole-file filtering, added in PR meta#13078). `Compaction::input_levels(i)` then returns only the kept files, and the compaction reads only those.

The compaction reads each non-L0 input level with a `LevelIterator`. When it opens a file, it cuts the range tombstones of that file to the file's atomic compaction unit boundary. An atomic compaction unit is a run of files in one level that share user keys at their edges and must be compacted together. `Compaction::boundaries(i)` gives one boundary per file, and `LevelIterator` reads it by the file's position in `input_levels(i)`.

The problem: `boundaries(i)` follows the list of all input files of the level, not the list of kept files. After a file is left out, every later kept file in that level reads the boundary of a different (earlier) file. Its range tombstones are cut to that wrong key range and can stop covering keys they should hide. Two cases lose data:
- An older version of a key sits in a level below the kept file, under the kept file's range tombstone. The cut tombstone no longer hides it. If that level is below the output level, reads see the old value again. If that level is a lower input level of the same compaction, the compaction writes the old value to the output, also when the output is the last level. For example, with L5 files ["a", "b"] and ["c", "z"], where the second file holds a tombstone ["d", "e") that hides "d" in L6, a standalone deletion ["a", "d") leaves out the first file. The second file then reads the boundary ["a", "b"], its tombstone is dropped, and Get("d") returns the old L6 value. This happens both when the compaction writes into L5 and when it also reads the L6 file and writes into L6. The tests below reproduce both shapes.
- The kept file itself holds an older version of a key under its own range tombstone, for example because a snapshot kept it when the file was written and was released later. The cut tombstone does not hide that version, so it is written to the output and becomes visible again, also when the output is the last level.
A deleted key comes back in both cases. Keys that an earlier compaction already brought back stay visible; this change does not repair them.

Fix: when `FilterInputsForCompactionIterator()` checks the input files against a standalone range deletion, it also builds, for each input level, the list of boundaries of the kept files, in the same order as `input_levels(i)`. Each kept file keeps the boundary of its own unit, as computed from all input files, which is the same cut the compaction would use without filtering. When a left-out file was in the same unit as a kept file, that boundary is wider than the kept file. The extra key range lies inside the standalone deletion, which is newer than any key the kept file's tombstones could hide there, so the wider cut hides no extra live keys (derived from the code; one test below checks such a case). `boundaries(i)` returns the kept list when this check ran and the original list otherwise. A debug check in the `Compaction` constructor asserts that each non-L0 level has one boundary per file in `input_levels(i)`.

`CompactionIterator::BuildMultiFileUnitRanges()` also reads `boundaries(i)` and `input_levels(i)` by file position. It asserts that the two lists have the same size, and its comment says that both name the same files by position.

Who is affected: universal compaction where a standalone range deletion file starts the compaction and leaves out at least one file before a kept file in the same input level.
- On the primary, only delete-triggered and read-triggered universal compactions filter their inputs. Other universal compactions and `DB::CompactFiles()` on the primary do not. These two kinds read only the start level and the next non-empty level, so the hidden older value always sits below the output level or in the kept file itself.
- A remote compaction worker rebuilds every universal compaction with the earliest snapshot and filters its inputs, so on the worker any universal compaction that starts with a standalone range deletion file can be affected, including one from `DB::CompactFiles()`. Such a compaction can read three or more levels and write into the last level, so the hidden older value can also sit in a lower input level of the same compaction.
- Level and FIFO compaction do not filter inputs.
The fix is in `Compaction`, so it covers the primary and the remote worker.

Compatibility: no format, option or public API change. `boundaries()` has two callers: the compaction input iterator (`VersionSet::MakeInputIterator()`) and `CompactionIterator::BuildMultiFileUnitRanges()`. Both pair it with `input_levels(i)` by position. The subcompaction and stats code in `CompactionJob` uses `input_levels(i)` and does not read boundaries.

Differential Revision: D134907303
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants