Repository navigation
Add internal MANIFEST row model and row changes of each MANIFEST write - #15734
xingbowang wants to merge 1 commit into
Conversation
|
@xingbowang has exported this pull request. If you are a Meta employee, you can view the originating Diff in D133208529. |
|
| Check | Count |
|---|---|
bugprone-argument-comment |
7 |
| Total | 7 |
Details
db/version_set_test.cc (7 warning(s))
db/version_set_test.cc:1460:48: warning: argument name 'db_directory' in comment does not match parameter name 'dir_contains_current_file' [bugprone-argument-comment]
db/version_set_test.cc:3252:39: warning: argument name 'count' in comment does not match parameter name 'garbage_blob_count' [bugprone-argument-comment]
db/version_set_test.cc:3252:52: warning: argument name 'bytes' in comment does not match parameter name 'garbage_blob_bytes' [bugprone-argument-comment]
db/version_set_test.cc:3471:37: warning: argument name 'count' in comment does not match parameter name 'garbage_blob_count' [bugprone-argument-comment]
db/version_set_test.cc:3471:50: warning: argument name 'bytes' in comment does not match parameter name 'garbage_blob_bytes' [bugprone-argument-comment]
db/version_set_test.cc:3477:39: warning: argument name 'count' in comment does not match parameter name 'garbage_blob_count' [bugprone-argument-comment]
db/version_set_test.cc:3477:52: warning: argument name 'bytes' in comment does not match parameter name 'garbage_blob_bytes' [bugprone-argument-comment]
a8275d7 to
f6e291e
Compare
f6e291e to
e915b65
Compare
Claude Code Review - OBSOLETESuperseded by a newer AI review. Expand to see the original review.✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit e915b65 SummaryWell-structured addition of an internal MANIFEST row model with thorough debug-build verification. The two-phase debug check design correctly accounts for mutex boundaries, and the row model faithfully mirrors the existing VersionEdit/VersionSet state. No release-build impact. High-severity findings (0): No high-severity findings. Full review (click to expand)Findings🔴 HIGHNone. 🟡 MEDIUMM1.
|
| Context | Does debug check execute? | Safe? |
|---|---|---|
| Primary DB (ProcessManifestWrites) | YES | YES |
| ReadOnly DB | NO (no PMW) | N/A |
| Secondary/Follower (ReactiveVersionSet) | NO (doesn't call PMW) | N/A |
| CompactionService worker | NO (doesn't write MANIFEST) | N/A |
| DB::Open recovery | First PMW call initializes rows | YES |
Positive Observations
-
Excellent compile-time safety net: The
ManifestRowFieldOfTagandManifestRowFieldOfNewFileTagswitch statements with nodefaultcase ensure that adding a new VersionEdit tag forces updating the row model. This is a clever use of-Wswitch -Werror. -
Well-designed two-phase check: Phase 1 (without mutex) checks everything it safely can, minimizing mutex-held work. Phase 2 (with mutex) handles only the fields that require the installed state.
-
Thorough test coverage:
ManifestRowsRoundTripexercises all row fields including edge cases (UDT with timestamp removal, path_id, blob files with garbage, dropped blob files, committed options file number).ManifestRowChangesMatchVersionscovers file add/delete, trivial move, compaction, blob garbage leading to blob file removal, atomic groups across CFs, WAL add/delete/rejection, options file, CF add/drop, and dummy writes. -
Clean separation of concerns: The row model is self-contained in manifest_rows.h/cc with no production code path dependency. The debug check hooks in version_set.cc are minimal and well-guarded.
-
Intentional in-memory difference handling: The PR carefully documents and handles differences between the row state and in-memory state (next_file_number, max_column_family, committed_options_file_number, log_number of empty CFs, marked_for_compaction). The bounds checks in phase 2 are appropriately permissive.
-
Good use of AddExistingFile for field copying: Using
AddExistingFileto create file rows ensures that the row contains exactly the fields that a MANIFEST stores, automatically staying in sync with any new persisted FileMetaData fields.
ℹ️ About this response
Generated by Claude Code.
Review methodology: claude_md/ci_review_prompt.md
Limitations:
- Claude may miss context from files not in the diff
- Large PRs may be truncated
- Always apply human judgment to AI suggestions
Commands:
/claude-review [context]— Request a code review/claude-query <question>— Ask about the PR or codebase
e915b65 to
38a29b8
Compare
Claude Code Review - OBSOLETESuperseded by a newer AI review. Expand to see the original review.✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit 38a29b8 SummaryWell-designed, carefully documented change that adds an internal MANIFEST row model with comprehensive debug-build verification. The code demonstrates strong awareness of concurrency constraints and correctly places all three hooks (fill, phase 1, phase 2) relative to the DB mutex boundaries. No high-severity findings. High-severity findings (0): No high-severity findings. Full review (click to expand)Findings🟡 MEDIUMM1. Fill step runs unnecessarily for skip_manifest_write paths —
|
| Context | Does code execute? | Assumptions hold? | Action needed? |
|---|---|---|---|
| ReactiveVersionSet / Secondary | NO (doesn't run ProcessManifestWrites) | N/A | Safe |
| ReadOnly DB | NO (doesn't write MANIFEST) | N/A | Safe |
| WritePreparedTxnDB | YES (same ProcessManifestWrites) | YES | Safe |
| DB::Open (first PMW call) | YES (fill step initializes rows) | YES | Safe |
| skip_manifest_write | Partial (fill runs, no check) | YES | Minor waste (M1) |
| Concurrent SuggestCompactRange | YES (can set marked_for_compaction) | YES (phase 1 only reads number/level for shared files) | Safe, documented |
DB Mutex Analysis:
- Fill step: mutex held. Copies all file metadata — expensive but bounded and infrequent (first call or after WAL rejection).
- Phase 1: NO mutex. Safe because (1) only one thread runs PMW, (2) wals_ is only modified by PMW thread, (3) new Versions not yet visible to other threads, (4) shared FileMetaData only has number/level read (immutable fields).
- Phase 2: mutex held. Cost is O(edits + live WALs + levels for added CF) — documented as lightweight.
WAL rejection recovery path: When BuildManifestRowChanges rejects a WAL edit, debug_manifest_rows_ is reset to null. The next PMW call refills from scratch. This is correct because the WAL edit rejection means ProcessManifestWrites will also fail to install (same WalSet logic), so the installed state hasn't changed.
Positive Observations
- Excellent documentation: The header comments in
manifest_rows.handmanifest_rows.ccare thorough, documenting invariants, thread safety, in-memory differences, and cost. The phase table indebug_manifest_rows_is particularly helpful. - Build-time tag exhaustiveness: The
ManifestRowFieldOfTagswitch with no default case, combined with-Wswitch -Werror, ensures that adding a new VersionEdit tag forces updating the row model. This is a clever compile-time safety mechanism. - Careful thread safety reasoning: Phase 1 is carefully designed to read only immutable fields of shared FileMetaData objects, with detailed comments explaining why each access is safe without the mutex.
- Correct WAL consistency: The use of
WalSetcopy in BuildManifestRowChanges mirrors the actual WAL application logic in ProcessManifestWrites, ensuring the debug check and the real logic agree. - Good test coverage: ManifestRowsRoundTrip covers all field types including UDT, path IDs, blob files, dropped CFs, WALs, and OPTIONS files. ManifestRowChangesMatchVersions covers file adds, trivial moves, compactions, blob garbage, atomic groups, WAL operations, CF add/drop, and the WAL rejection recovery path.
- No release-build impact: All new code in ProcessManifestWrites is guarded by
#ifndef NDEBUG. The new files (manifest_rows.h/cc) are compiled into the library but their functions are only called from debug hooks and tests.
ℹ️ About this response
Generated by Claude Code.
Review methodology: claude_md/ci_review_prompt.md
Limitations:
- Claude may miss context from files not in the diff
- Large PRs may be truncated
- Always apply human judgment to AI suggestions
Commands:
/claude-review [context]— Request a code review/claude-query <question>— Ask about the PR or codebase
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation - Row model: `db/manifest_rows.h` defines `ManifestDbRow`, `ManifestCfRow`, `ManifestFileRow` (level plus the persisted `FileMetaData` fields), `ManifestBlobFileRow` and the WAL rows, grouped in `ManifestRows`. The overview comment at the top of the header lists the VersionEdit content that has no row field, and why. - State to rows: `VersionSet::GetManifestRows()` reads the current state into rows. - Rows to records: `ManifestRowsToRecords()` turns rows into full-state VersionEdit records that the existing recovery code replays. Its header comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`. - Comparison: `ManifestRowsEqual()` compares two sets of rows and names the first difference. Its header comment says which rows it compares field by field and which through their encoding. - Row changes: `BuildManifestRowChanges()` turns one MANIFEST write into a `ManifestRowChanges` (the new DB row, the rows to upsert and the keys to delete), and `ApplyManifestRowChanges()` applies it. The `BuildManifestRowChanges()` header comment holds all rules (DB row, prev log number, files, column family row, blob file rows, WAL rows) and the in-memory differences. `BaseReferencedVersionBuilder::version()` returns the base Version of a batch. - Debug check: three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()` (fill, phase 1 without the DB mutex, phase 2 with the DB mutex held). The comment of `VersionSet::debug_manifest_rows_` has the timeline, a table of what each phase checks, and why phase 1 needs no DB mutex. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top and the row structs. 2. `db/version_set.h`: the `GetManifestRows()` declaration, then `db/manifest_rows.cc`: `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()` (state to rows). 3. `db/manifest_rows.cc`: `ManifestRowsToRecords()`, side by side with `VersionSet::WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. `db/manifest_rows.h`: `ManifestRowChanges` and `ApplyManifestRowChanges()`, then their code in `db/manifest_rows.cc`. 5. `db/manifest_rows.h`: `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, then its code; `db/version_builder.h`: `BaseReferencedVersionBuilder::version()`. 6. `db/version_set.h`: the `debug_manifest_rows_` comment with the phase table; `db/version_set.cc`: the three `#ifndef NDEBUG` hooks in `ProcessManifestWrites()`; then in `db/manifest_rows.cc` phase 1 (`DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()`) and phase 2 (`DebugCheckRowsAfterInstall()`, `VersionSet::SetManifestDbRowAndWals()`). 7. `db/version_set_test.cc`: `ManifestRowFieldOfTag()`, `ManifestRowFieldOfNewFileTag()`, `ManifestRowsRoundTrip`, then `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It does this with the DB mutex held. The first call is the first MANIFEST write of the VersionSet: often the one of `DB::Open()`, or a later write when `DB::Open()` writes no MANIFEST record. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Differential Revision: D133208529
38a29b8 to
d00992c
Compare
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation - Row model: `db/manifest_rows.h` defines `ManifestDbRow`, `ManifestCfRow`, `ManifestFileRow` (level plus the persisted `FileMetaData` fields), `ManifestBlobFileRow` and the WAL rows, grouped in `ManifestRows`. The overview comment at the top of the header lists the VersionEdit content that has no row field, and why. - State to rows: `VersionSet::GetManifestRows()` reads the current state into rows. - Rows to records: `ManifestRowsToRecords()` turns rows into full-state VersionEdit records that the existing recovery code replays. Its header comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`. - Comparison: `ManifestRowsEqual()` compares two sets of rows and names the first difference. Its header comment says which rows it compares field by field and which through their encoding. - Row changes: `BuildManifestRowChanges()` turns one MANIFEST write into a `ManifestRowChanges` (the new DB row, the rows to upsert and the keys to delete), and `ApplyManifestRowChanges()` applies it. The `BuildManifestRowChanges()` header comment holds all rules (DB row, prev log number, files, column family row, blob file rows, WAL rows) and the in-memory differences. `BaseReferencedVersionBuilder::version()` returns the base Version of a batch. - Debug check: three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()` (fill, phase 1 without the DB mutex, phase 2 with the DB mutex held). The comment of `VersionSet::debug_manifest_rows_` has the timeline, a table of what each phase checks, and why phase 1 needs no DB mutex. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top and the row structs. 2. `db/version_set.h`: the `GetManifestRows()` declaration, then `db/manifest_rows.cc`: `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()` (state to rows). 3. `db/manifest_rows.cc`: `ManifestRowsToRecords()`, side by side with `VersionSet::WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. `db/manifest_rows.h`: `ManifestRowChanges` and `ApplyManifestRowChanges()`, then their code in `db/manifest_rows.cc`. 5. `db/manifest_rows.h`: `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, then its code; `db/version_builder.h`: `BaseReferencedVersionBuilder::version()`. 6. `db/version_set.h`: the `debug_manifest_rows_` comment with the phase table; `db/version_set.cc`: the three `#ifndef NDEBUG` hooks in `ProcessManifestWrites()`; then in `db/manifest_rows.cc` phase 1 (`DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()`) and phase 2 (`DebugCheckRowsAfterInstall()`, `VersionSet::SetManifestDbRowAndWals()`). 7. `db/version_set_test.cc`: `ManifestRowFieldOfTag()`, `ManifestRowFieldOfNewFileTag()`, `ManifestRowsRoundTrip`, then `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It does this with the DB mutex held. The first call is the first MANIFEST write of the VersionSet: often the one of `DB::Open()`, or a later write when `DB::Open()` writes no MANIFEST record. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Differential Revision: D133208529
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation - Row model: `db/manifest_rows.h` defines `ManifestDbRow`, `ManifestCfRow`, `ManifestFileRow` (level plus the persisted `FileMetaData` fields), `ManifestBlobFileRow` and the WAL rows, grouped in `ManifestRows`. The overview comment at the top of the header lists the VersionEdit content that has no row field, and why. - State to rows: `VersionSet::GetManifestRows()` reads the current state into rows. - Rows to records: `ManifestRowsToRecords()` turns rows into full-state VersionEdit records that the existing recovery code replays. Its header comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`. - Comparison: `ManifestRowsEqual()` compares two sets of rows and names the first difference. Its header comment says which rows it compares field by field and which through their encoding. - Row changes: `BuildManifestRowChanges()` turns one MANIFEST write into a `ManifestRowChanges` (the new DB row, the rows to upsert and the keys to delete), and `ApplyManifestRowChanges()` applies it. The `BuildManifestRowChanges()` header comment holds all rules (DB row, prev log number, files, column family row, blob file rows, WAL rows) and the in-memory differences. `BaseReferencedVersionBuilder::version()` returns the base Version of a batch. - Debug check: three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()` (fill, phase 1 without the DB mutex, phase 2 with the DB mutex held). The comment of `VersionSet::debug_manifest_rows_` has the timeline, a table of what each phase checks, and why phase 1 needs no DB mutex. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top and the row structs. 2. `db/version_set.h`: the `GetManifestRows()` declaration, then `db/manifest_rows.cc`: `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()` (state to rows). 3. `db/manifest_rows.cc`: `ManifestRowsToRecords()`, side by side with `VersionSet::WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. `db/manifest_rows.h`: `ManifestRowChanges` and `ApplyManifestRowChanges()`, then their code in `db/manifest_rows.cc`. 5. `db/manifest_rows.h`: `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, then its code; `db/version_builder.h`: `BaseReferencedVersionBuilder::version()`. 6. `db/version_set.h`: the `debug_manifest_rows_` comment with the phase table; `db/version_set.cc`: the three `#ifndef NDEBUG` hooks in `ProcessManifestWrites()`; then in `db/manifest_rows.cc` phase 1 (`DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()`) and phase 2 (`DebugCheckRowsAfterInstall()`, `VersionSet::SetManifestDbRowAndWals()`). 7. `db/version_set_test.cc`: `ManifestRowFieldOfTag()`, `ManifestRowFieldOfNewFileTag()`, `ManifestRowsRoundTrip`, then `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It does this with the DB mutex held. The first call is the first MANIFEST write of the VersionSet: often the one of `DB::Open()`, or a later write when `DB::Open()` writes no MANIFEST record. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Differential Revision: D133208529
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation - Row model: `db/manifest_rows.h` defines `ManifestDbRow`, `ManifestCfRow`, `ManifestFileRow` (level plus the persisted `FileMetaData` fields), `ManifestBlobFileRow` and the WAL rows, grouped in `ManifestRows`. The overview comment at the top of the header lists the VersionEdit content that has no row field, and why. - State to rows: `VersionSet::GetManifestRows()` reads the current state into rows. - Rows to records: `ManifestRowsToRecords()` turns rows into full-state VersionEdit records that the existing recovery code replays. Its header comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`. - Comparison: `ManifestRowsEqual()` compares two sets of rows and names the first difference. Its header comment says which rows it compares field by field and which through their encoding. - Row changes: `BuildManifestRowChanges()` turns one MANIFEST write into a `ManifestRowChanges` (the new DB row, the rows to upsert and the keys to delete), and `ApplyManifestRowChanges()` applies it. The `BuildManifestRowChanges()` header comment holds all rules (DB row, prev log number, files, column family row, blob file rows, WAL rows) and the in-memory differences. `BaseReferencedVersionBuilder::version()` returns the base Version of a batch. - Debug check: three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()` (fill, phase 1 without the DB mutex, phase 2 with the DB mutex held). The comment of `VersionSet::debug_manifest_rows_` has the timeline, a table of what each phase checks, and why phase 1 needs no DB mutex. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top and the row structs. 2. `db/version_set.h`: the `GetManifestRows()` declaration, then `db/manifest_rows.cc`: `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()` (state to rows). 3. `db/manifest_rows.cc`: `ManifestRowsToRecords()`, side by side with `VersionSet::WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. `db/manifest_rows.h`: `ManifestRowChanges` and `ApplyManifestRowChanges()`, then their code in `db/manifest_rows.cc`. 5. `db/manifest_rows.h`: `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, then its code; `db/version_builder.h`: `BaseReferencedVersionBuilder::version()`. 6. `db/version_set.h`: the `debug_manifest_rows_` comment with the phase table; `db/version_set.cc`: the three `#ifndef NDEBUG` hooks in `ProcessManifestWrites()`; then in `db/manifest_rows.cc` phase 1 (`DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()`) and phase 2 (`DebugCheckRowsAfterInstall()`, `VersionSet::SetManifestDbRowAndWals()`). 7. `db/version_set_test.cc`: `ManifestRowFieldOfTag()`, `ManifestRowFieldOfNewFileTag()`, `ManifestRowsRoundTrip`, then `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It does this with the DB mutex held. The first call is the first MANIFEST write of the VersionSet: often the one of `DB::Open()`, or a later write when `DB::Open()` writes no MANIFEST record. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Differential Revision: D133208529
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation - Row model: `db/manifest_rows.h` defines `ManifestDbRow`, `ManifestCfRow`, `ManifestFileRow` (level plus the persisted `FileMetaData` fields), `ManifestBlobFileRow` and the WAL rows, grouped in `ManifestRows`. The overview comment at the top of the header lists the VersionEdit content that has no row field, and why. - State to rows: `VersionSet::GetManifestRows()` reads the current state into rows. - Rows to records: `ManifestRowsToRecords()` turns rows into full-state VersionEdit records that the existing recovery code replays. Its header comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`. - Comparison: `ManifestRowsEqual()` compares two sets of rows and names the first difference. Its header comment says which rows it compares field by field and which through their encoding. - Row changes: `BuildManifestRowChanges()` turns one MANIFEST write into a `ManifestRowChanges` (the new DB row, the rows to upsert and the keys to delete), and `ApplyManifestRowChanges()` applies it. The `BuildManifestRowChanges()` header comment holds all rules (DB row, prev log number, files, column family row, blob file rows, WAL rows) and the in-memory differences. `BaseReferencedVersionBuilder::version()` returns the base Version of a batch. - Debug check: three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()` (fill, phase 1 without the DB mutex, phase 2 with the DB mutex held). The comment of `VersionSet::debug_manifest_rows_` has the timeline, a table of what each phase checks, and why phase 1 needs no DB mutex. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top and the row structs. 2. `db/version_set.h`: the `GetManifestRows()` declaration, then `db/manifest_rows.cc`: `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()` (state to rows). 3. `db/manifest_rows.cc`: `ManifestRowsToRecords()`, side by side with `VersionSet::WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. `db/manifest_rows.h`: `ManifestRowChanges` and `ApplyManifestRowChanges()`, then their code in `db/manifest_rows.cc`. 5. `db/manifest_rows.h`: `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, then its code; `db/version_builder.h`: `BaseReferencedVersionBuilder::version()`. 6. `db/version_set.h`: the `debug_manifest_rows_` comment with the phase table; `db/version_set.cc`: the three `#ifndef NDEBUG` hooks in `ProcessManifestWrites()`; then in `db/manifest_rows.cc` phase 1 (`DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()`) and phase 2 (`DebugCheckRowsAfterInstall()`, `VersionSet::SetManifestDbRowAndWals()`). 7. `db/version_set_test.cc`: `ManifestRowFieldOfTag()`, `ManifestRowFieldOfNewFileTag()`, `ManifestRowsRoundTrip`, then `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It does this with the DB mutex held. The first call is the first MANIFEST write of the VersionSet: often the one of `DB::Open()`, or a later write when `DB::Open()` writes no MANIFEST record. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Differential Revision: D133208529
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation - Row model: `db/manifest_rows.h` defines `ManifestDbRow`, `ManifestCfRow`, `ManifestFileRow` (level plus the persisted `FileMetaData` fields), `ManifestBlobFileRow` and the WAL rows, grouped in `ManifestRows`. The overview comment at the top of the header lists the VersionEdit content that has no row field, and why. - State to rows: `VersionSet::GetManifestRows()` reads the current state into rows. - Rows to records: `ManifestRowsToRecords()` turns rows into full-state VersionEdit records that the existing recovery code replays. Its header comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`. - Comparison: `ManifestRowsEqual()` compares two sets of rows and names the first difference. Its header comment says which rows it compares field by field and which through their encoding. - Row changes: `BuildManifestRowChanges()` turns one MANIFEST write into a `ManifestRowChanges` (the new DB row, the rows to upsert and the keys to delete), and `ApplyManifestRowChanges()` applies it. The `BuildManifestRowChanges()` header comment holds all rules (DB row, prev log number, files, column family row, blob file rows, WAL rows) and the in-memory differences. `BaseReferencedVersionBuilder::version()` returns the base Version of a batch. - Debug check: three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()` (fill, phase 1 without the DB mutex, phase 2 with the DB mutex held). The comment of `VersionSet::debug_manifest_rows_` has the timeline, a table of what each phase checks, and why phase 1 needs no DB mutex. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top and the row structs. 2. `db/version_set.h`: the `GetManifestRows()` declaration, then `db/manifest_rows.cc`: `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()` (state to rows). 3. `db/manifest_rows.cc`: `ManifestRowsToRecords()`, side by side with `VersionSet::WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. `db/manifest_rows.h`: `ManifestRowChanges` and `ApplyManifestRowChanges()`, then their code in `db/manifest_rows.cc`. 5. `db/manifest_rows.h`: `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, then its code; `db/version_builder.h`: `BaseReferencedVersionBuilder::version()`. 6. `db/version_set.h`: the `debug_manifest_rows_` comment with the phase table; `db/version_set.cc`: the three `#ifndef NDEBUG` hooks in `ProcessManifestWrites()`; then in `db/manifest_rows.cc` phase 1 (`DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()`) and phase 2 (`DebugCheckRowsAfterInstall()`, `VersionSet::SetManifestDbRowAndWals()`). 7. `db/version_set_test.cc`: `ManifestRowFieldOfTag()`, `ManifestRowFieldOfNewFileTag()`, `ManifestRowsRoundTrip`, then `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It does this with the DB mutex held. The first call is the first MANIFEST write of the VersionSet: often the one of `DB::Open()`, or a later write when `DB::Open()` writes no MANIFEST record. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Differential Revision: D133208529
d00992c to
7f3d96c
Compare
Claude Code Review - OBSOLETESuperseded by a newer AI review. Expand to see the original review.✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit 7f3d96c SummaryWell-structured, carefully designed debug-only infrastructure for MANIFEST row change verification. The code is debug-only (#ifndef NDEBUG), introduces no behavior change in release builds, and the thread safety analysis is thorough and well-documented. The two-phase check design correctly separates expensive file-level verification (phase 1, without mutex) from lightweight state checks (phase 2, with mutex). High-severity findings (0): No high-severity findings. Full review (click to expand)Findings🔴 HIGHNone. 🟡 MEDIUMM1.
|
| Context | Does code execute? | Assumptions hold? | Action needed? |
|---|---|---|---|
| WritePreparedTxnDB | YES (same ProcessManifestWrites) | YES (debug hooks only read row state) | None |
| ReadOnly DB | NO (no MANIFEST writes) | N/A | None |
| Secondary/Follower | NO (no MANIFEST writes) | N/A | None |
| CompactionService | NO (remote worker uses own file) | N/A | None |
| User-defined timestamps | YES | YES (timestamp_size handled, EncodeTo uses ts_sz) | None |
| MemPurge | YES | YES (no memtable interaction) | None |
| FIFO/Universal compaction | YES | YES (compaction style irrelevant) | None |
| BlobDB | YES | YES (blob file rows explicitly handled) | None |
| Old snapshots | YES | YES (no snapshot state read) | None |
DB Mutex Analysis:
- Fill step: mutex held, O(files). Matches existing
WriteCurrentStateToManifestpatterns. Debug-only. - Phase 1: no mutex. Thread safety well-documented. Only
ProcessManifestWritesthread modifieswals_,debug_manifest_rows_, and installs Versions. Safe reads of immutable CFD fields and referenced Versions. - Phase 2: mutex held. O(edits + WALs + levels for CF add). No regression.
- No mutex contention or hold-time impact in release builds.
Positive Observations
- Excellent documentation: The header comments in
manifest_rows.hare thorough, well-organized, and clearly explain the design rationale, known limitations, and in-memory differences. - Build-time tag coverage: The
ManifestRowFieldOfTagswitch with no default case ensures that adding a new VersionEdit tag forces the developer to update the row model. This is a clever defense against silent regressions. - Two-phase check design: Separating expensive file verification (phase 1) from lightweight state checks (phase 2) minimizes mutex hold time in debug builds.
- Thread safety documentation: The
debug_manifest_rows_comment inversion_set.hhas an unusually thorough thread safety analysis, listing each object read in phase 1 and why it's safe. - Test quality: Both tests are well-designed. The round-trip test covers every field with non-default values and verifies that changes are detected. The row-changes test covers all MANIFEST write kinds and counts checks to ensure no write is missed.
- Defensive coding: The
assert(base_cf != old_rows.cfs.end())with a fallback that keeps release builds from reading past the end is good defensive practice.
ℹ️ About this response
Generated by Claude Code.
Review methodology: claude_md/ci_review_prompt.md
Limitations:
- Claude may miss context from files not in the diff
- Large PRs may be truncated
- Always apply human judgment to AI suggestions
Commands:
/claude-review [context]— Request a code review/claude-query <question>— Ask about the PR or codebase
3a5eca0 to
5c9f5f4
Compare
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation Key choices: - The rules that turn one MANIFEST write into row changes are in the `BuildManifestRowChanges()` comment in `db/manifest_rows.h`. - The debug check runs in two phases. Phase 1 does the work that grows with the number of files, and it runs without the DB mutex, before the new Versions are installed. Phase 2 checks the values that only the installed in-memory state has (the DB row, the WAL rows, the log number, `full_history_ts_low`, the dropped flag), with the DB mutex held. Each step of phase 2 is a few lookups. Phase 2 also erases the debug rows of a dropped column family, because no later MANIFEST write names it. - When the WAL set rejects a WAL edit, the MANIFEST write has happened but the write is not installed. The debug rows are then dropped and filled again from the installed state at the next write, so the check keeps comparing with what memory holds. - Some values change in memory without a MANIFEST write (for example the log number of an empty column family). The rows keep the values from the edits. The "In-memory differences" paragraph at the top of `db/manifest_rows.h` lists these values. Symbols: - Row model: `db/manifest_rows.h` defines `ManifestDbRow`, `ManifestCfRow`, `ManifestFileRow` (level plus the persisted `FileMetaData` fields), `ManifestBlobFileRow` and the WAL rows, grouped in `ManifestRows`. The overview comment at the top of the header lists the VersionEdit content that has no row field, and why. - State to rows: `VersionSet::GetManifestRows()` reads the current state into rows. - Rows to records: `ManifestRowsToRecords()` turns rows into full-state VersionEdit records that the existing recovery code replays. Its header comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`. - Comparison: `ManifestRowsEqual()` compares two sets of rows and names the first difference. Its header comment says which rows it compares field by field and which through their encoding. - Row changes: `BuildManifestRowChanges()` turns one MANIFEST write into a `ManifestRowChanges` (the new DB row, the rows to upsert and the keys to delete; an upsert adds a row or replaces the row with the same key), and `ApplyManifestRowChanges()` applies it. The `BuildManifestRowChanges()` header comment holds all rules (DB row, prev log number, files, column family row, blob file rows, WAL rows). `BaseReferencedVersionBuilder::version()` returns the base Version that the edits of one column family in a batch are applied to. - Debug check: `MakeManifestBatchVersions()` pairs each new Version with its base Version for phase 1. Three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()` run the check: fill, phase 1 without the DB mutex, and phase 2 with the DB mutex held. The comment of `VersionSet::debug_manifest_rows_` has the timeline, a table of what each phase checks, and why phase 1 needs no DB mutex. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It does this with the DB mutex held. The first call is the first `LogAndApply()` of the VersionSet. This is often the MANIFEST write of `DB::Open()`. It can also be a call that writes no MANIFEST record, such as the dummy edit of `DB::SetOptions()`. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files and blob files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`, because the drop edit lists no deleted files and the drop installs no new Version. The files are deleted later, when the last reference to the column family is released, and no MANIFEST write records that. `ManifestRowsToRecords()` skips these rows, so recovery does not see them. The debug check erases them from its own copy. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first `LogAndApply()` of the VersionSet, and again after a rejected WAL edit. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top and the row structs. 2. `db/version_set.h`: the `GetManifestRows()` declaration, then `db/manifest_rows.cc`: `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()` (state to rows). 3. `db/manifest_rows.cc`: `ManifestRowsToRecords()`, side by side with `VersionSet::WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. `db/manifest_rows.h`: `ManifestRowChanges` and `ApplyManifestRowChanges()`, then their code in `db/manifest_rows.cc`. 5. `db/manifest_rows.h`: `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, then its code; `db/version_builder.h`: `BaseReferencedVersionBuilder::version()`. 6. `db/version_set.h`: the `debug_manifest_rows_` comment with the phase table; `db/version_set.cc`: the three `#ifndef NDEBUG` hooks in `ProcessManifestWrites()`; then in `db/manifest_rows.cc` phase 1 (`MakeManifestBatchVersions()`, `DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()`) and phase 2 (`DebugCheckRowsAfterInstall()`, `VersionSet::SetManifestDbRowAndWals()`). 7. `db/version_set_test.cc`: `ManifestRowFieldOfTag()`, `ManifestRowFieldOfNewFileTag()`, `ManifestRowsRoundTrip`, then `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Differential Revision: D133208529
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation Key choices: - The rules that turn one MANIFEST write into row changes are in the `BuildManifestRowChanges()` comment in `db/manifest_rows.h`. - The debug check runs in two phases. Phase 1 does the work that grows with the number of files, and it runs without the DB mutex, before the new Versions are installed. Phase 2 checks the values that only the installed in-memory state has (the DB row, the WAL rows, the log number, `full_history_ts_low`, the dropped flag), with the DB mutex held. Each step of phase 2 is a few lookups. Phase 2 also erases the debug rows of a dropped column family, because no later MANIFEST write names it. - When the WAL set rejects a WAL edit, the MANIFEST write has happened but the write is not installed. The debug rows are then dropped and filled again from the installed state at the next write, so the check keeps comparing with what memory holds. - Some values change in memory without a MANIFEST write (for example the log number of an empty column family). The rows keep the values from the edits. The "In-memory differences" paragraph at the top of `db/manifest_rows.h` lists these values. Symbols: - Row model: `db/manifest_rows.h` defines `ManifestDbRow`, `ManifestCfRow`, `ManifestFileRow` (level plus the persisted `FileMetaData` fields), `ManifestBlobFileRow` and the WAL rows, grouped in `ManifestRows`. The overview comment at the top of the header lists the VersionEdit content that has no row field, and why. - State to rows: `VersionSet::GetManifestRows()` reads the current state into rows. - Rows to records: `ManifestRowsToRecords()` turns rows into full-state VersionEdit records that the existing recovery code replays. Its header comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`. - Comparison: `ManifestRowsEqual()` compares two sets of rows and names the first difference. Its header comment says which rows it compares field by field and which through their encoding. - Row changes: `BuildManifestRowChanges()` turns one MANIFEST write into a `ManifestRowChanges` (the new DB row, the rows to upsert and the keys to delete; an upsert adds a row or replaces the row with the same key), and `ApplyManifestRowChanges()` applies it. The `BuildManifestRowChanges()` header comment holds all rules (DB row, prev log number, files, column family row, blob file rows, WAL rows). `BaseReferencedVersionBuilder::version()` returns the base Version that the edits of one column family in a batch are applied to. - Debug check: `MakeManifestBatchVersions()` pairs each new Version with its base Version for phase 1. Three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()` run the check: fill, phase 1 without the DB mutex, and phase 2 with the DB mutex held. The comment of `VersionSet::debug_manifest_rows_` has the timeline, a table of what each phase checks, and why phase 1 needs no DB mutex. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It does this with the DB mutex held. The first call is the first `LogAndApply()` of the VersionSet. This is often the MANIFEST write of `DB::Open()`. It can also be a call that writes no MANIFEST record, such as the dummy edit of `DB::SetOptions()`. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files and blob files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`, because the drop edit lists no deleted files and the drop installs no new Version. The files are deleted later, when the last reference to the column family is released, and no MANIFEST write records that. `ManifestRowsToRecords()` skips these rows, so recovery does not see them. The debug check erases them from its own copy. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first `LogAndApply()` of the VersionSet, and again after a rejected WAL edit. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top and the row structs. 2. `db/version_set.h`: the `GetManifestRows()` declaration, then `db/manifest_rows.cc`: `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()` (state to rows). 3. `db/manifest_rows.cc`: `ManifestRowsToRecords()`, side by side with `VersionSet::WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. `db/manifest_rows.h`: `ManifestRowChanges` and `ApplyManifestRowChanges()`, then their code in `db/manifest_rows.cc`. 5. `db/manifest_rows.h`: `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, then its code; `db/version_builder.h`: `BaseReferencedVersionBuilder::version()`. 6. `db/version_set.h`: the `debug_manifest_rows_` comment with the phase table; `db/version_set.cc`: the three `#ifndef NDEBUG` hooks in `ProcessManifestWrites()`; then in `db/manifest_rows.cc` phase 1 (`MakeManifestBatchVersions()`, `DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()`) and phase 2 (`DebugCheckRowsAfterInstall()`, `VersionSet::SetManifestDbRowAndWals()`). 7. `db/version_set_test.cc`: `ManifestRowFieldOfTag()`, `ManifestRowFieldOfNewFileTag()`, `ManifestRowsRoundTrip`, then `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Differential Revision: D133208529
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation Key choices: - The rules that turn one MANIFEST write into row changes are in the `BuildManifestRowChanges()` comment in `db/manifest_rows.h`. - The debug check runs in two phases. Phase 1 does the work that grows with the number of files, and it runs without the DB mutex, before the new Versions are installed. Phase 2 checks the values that only the installed in-memory state has (the DB row, the WAL rows, the log number, `full_history_ts_low`, the dropped flag), with the DB mutex held. Each step of phase 2 is a few lookups. Phase 2 also erases the debug rows of a dropped column family, because no later MANIFEST write names it. - When the WAL set rejects a WAL edit, the MANIFEST write has happened but the write is not installed. The debug rows are then dropped and filled again from the installed state at the next write, so the check keeps comparing with what memory holds. - Some values change in memory without a MANIFEST write (for example the log number of an empty column family). The rows keep the values from the edits. The "In-memory differences" paragraph at the top of `db/manifest_rows.h` lists these values. Symbols: - Row model: `db/manifest_rows.h` defines `ManifestDbRow`, `ManifestCfRow`, `ManifestFileRow` (level plus the persisted `FileMetaData` fields), `ManifestBlobFileRow` and the WAL rows, grouped in `ManifestRows`. The overview comment at the top of the header lists the VersionEdit content that has no row field, and why. - State to rows: `VersionSet::GetManifestRows()` reads the current state into rows. - Rows to records: `ManifestRowsToRecords()` turns rows into full-state VersionEdit records that the existing recovery code replays. Its header comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`. - Comparison: `ManifestRowsEqual()` compares two sets of rows and names the first difference. Its header comment says which rows it compares field by field and which through their encoding. - Row changes: `BuildManifestRowChanges()` turns one MANIFEST write into a `ManifestRowChanges` (the new DB row, the rows to upsert and the keys to delete; an upsert adds a row or replaces the row with the same key), and `ApplyManifestRowChanges()` applies it. The `BuildManifestRowChanges()` header comment holds all rules (DB row, prev log number, files, column family row, blob file rows, WAL rows). `BaseReferencedVersionBuilder::version()` returns the base Version that the edits of one column family in a batch are applied to. - Debug check: `MakeManifestBatchVersions()` pairs each new Version with its base Version for phase 1. Three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()` run the check: fill, phase 1 without the DB mutex, and phase 2 with the DB mutex held. The comment of `VersionSet::debug_manifest_rows_` has the timeline, a table of what each phase checks, and why phase 1 needs no DB mutex. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It does this with the DB mutex held. The first call is the first `LogAndApply()` of the VersionSet. This is often the MANIFEST write of `DB::Open()`. It can also be a call that writes no MANIFEST record, such as the dummy edit of `DB::SetOptions()`. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files and blob files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`, because the drop edit lists no deleted files and the drop installs no new Version. The files are deleted later, when the last reference to the column family is released, and no MANIFEST write records that. `ManifestRowsToRecords()` skips these rows, so recovery does not see them. The debug check erases them from its own copy. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first `LogAndApply()` of the VersionSet, and again after a rejected WAL edit. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top and the row structs. 2. `db/version_set.h`: the `GetManifestRows()` declaration, then `db/manifest_rows.cc`: `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()` (state to rows). 3. `db/manifest_rows.cc`: `ManifestRowsToRecords()`, side by side with `VersionSet::WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. `db/manifest_rows.h`: `ManifestRowChanges` and `ApplyManifestRowChanges()`, then their code in `db/manifest_rows.cc`. 5. `db/manifest_rows.h`: `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, then its code; `db/version_builder.h`: `BaseReferencedVersionBuilder::version()`. 6. `db/version_set.h`: the `debug_manifest_rows_` comment with the phase table; `db/version_set.cc`: the three `#ifndef NDEBUG` hooks in `ProcessManifestWrites()`; then in `db/manifest_rows.cc` phase 1 (`MakeManifestBatchVersions()`, `DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()`) and phase 2 (`DebugCheckRowsAfterInstall()`, `VersionSet::SetManifestDbRowAndWals()`). 7. `db/version_set_test.cc`: `ManifestRowFieldOfTag()`, `ManifestRowFieldOfNewFileTag()`, `ManifestRowsRoundTrip`, then `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Differential Revision: D133208529
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation Key choices: - The rules that turn one MANIFEST write into row changes are in the `BuildManifestRowChanges()` comment in `db/manifest_rows.h`. - The debug check runs in two phases. Phase 1 does the work that grows with the number of files, and it runs without the DB mutex, before the new Versions are installed. Phase 2 checks the values that only the installed in-memory state has (the DB row, the WAL rows, the log number, `full_history_ts_low`, the dropped flag), with the DB mutex held. Each step of phase 2 is a few lookups. Phase 2 also erases the debug rows of a dropped column family, because no later MANIFEST write names it. - When the WAL set rejects a WAL edit, the MANIFEST write has happened but the write is not installed. The debug rows are then dropped and filled again from the installed state at the next write, so the check keeps comparing with what memory holds. - Some values change in memory without a MANIFEST write (for example the log number of an empty column family). The rows keep the values from the edits. The "In-memory differences" paragraph at the top of `db/manifest_rows.h` lists these values. Symbols: - Row model: `db/manifest_rows.h` defines `ManifestDbRow`, `ManifestCfRow`, `ManifestFileRow` (level plus the persisted `FileMetaData` fields), `ManifestBlobFileRow` and the WAL rows, grouped in `ManifestRows`. The overview comment at the top of the header lists the VersionEdit content that has no row field, and why. - State to rows: `VersionSet::GetManifestRows()` reads the current state into rows. - Rows to records: `ManifestRowsToRecords()` turns rows into full-state VersionEdit records that the existing recovery code replays. Its header comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`. - Comparison: `ManifestRowsEqual()` compares two sets of rows and names the first difference. Its header comment says which rows it compares field by field and which through their encoding. - Row changes: `BuildManifestRowChanges()` turns one MANIFEST write into a `ManifestRowChanges` (the new DB row, the rows to upsert and the keys to delete; an upsert adds a row or replaces the row with the same key), and `ApplyManifestRowChanges()` applies it. The `BuildManifestRowChanges()` header comment holds all rules (DB row, prev log number, files, column family row, blob file rows, WAL rows). `BaseReferencedVersionBuilder::version()` returns the base Version that the edits of one column family in a batch are applied to. - Debug check: `MakeManifestBatchVersions()` pairs each new Version with its base Version for phase 1. Three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()` run the check: fill, phase 1 without the DB mutex, and phase 2 with the DB mutex held. The comment of `VersionSet::debug_manifest_rows_` has the timeline, a table of what each phase checks, and why phase 1 needs no DB mutex. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It does this with the DB mutex held. The first call is the first `LogAndApply()` of the VersionSet. This is often the MANIFEST write of `DB::Open()`. It can also be a call that writes no MANIFEST record, such as the dummy edit of `DB::SetOptions()`. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files and blob files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`, because the drop edit lists no deleted files and the drop installs no new Version. The files are deleted later, when the last reference to the column family is released, and no MANIFEST write records that. `ManifestRowsToRecords()` skips these rows, so recovery does not see them. The debug check erases them from its own copy. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first `LogAndApply()` of the VersionSet, and again after a rejected WAL edit. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top and the row structs. 2. `db/version_set.h`: the `GetManifestRows()` declaration, then `db/manifest_rows.cc`: `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()` (state to rows). 3. `db/manifest_rows.cc`: `ManifestRowsToRecords()`, side by side with `VersionSet::WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. `db/manifest_rows.h`: `ManifestRowChanges` and `ApplyManifestRowChanges()`, then their code in `db/manifest_rows.cc`. 5. `db/manifest_rows.h`: `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, then its code; `db/version_builder.h`: `BaseReferencedVersionBuilder::version()`. 6. `db/version_set.h`: the `debug_manifest_rows_` comment with the phase table; `db/version_set.cc`: the three `#ifndef NDEBUG` hooks in `ProcessManifestWrites()`; then in `db/manifest_rows.cc` phase 1 (`MakeManifestBatchVersions()`, `DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()`) and phase 2 (`DebugCheckRowsAfterInstall()`, `VersionSet::SetManifestDbRowAndWals()`). 7. `db/version_set_test.cc`: `ManifestRowFieldOfTag()`, `ManifestRowFieldOfNewFileTag()`, `ManifestRowsRoundTrip`, then `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Differential Revision: D133208529
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation Key choices: - The rules that turn one MANIFEST write into row changes are in the `BuildManifestRowChanges()` comment in `db/manifest_rows.h`. - The debug check runs in two phases. Phase 1 does the work that grows with the number of files, and it runs without the DB mutex, before the new Versions are installed. Phase 2 checks the values that only the installed in-memory state has (the DB row, the WAL rows, the log number, `full_history_ts_low`, the dropped flag), with the DB mutex held. Each step of phase 2 is a few lookups. Phase 2 also erases the debug rows of a dropped column family, because no later MANIFEST write names it. - When the WAL set rejects a WAL edit, the MANIFEST write has happened but the write is not installed. The debug rows are then dropped and filled again from the installed state at the next write, so the check keeps comparing with what memory holds. - Some values change in memory without a MANIFEST write (for example the log number of an empty column family). The rows keep the values from the edits. The "In-memory differences" paragraph at the top of `db/manifest_rows.h` lists these values. Symbols: - Row model: `db/manifest_rows.h` defines `ManifestDbRow`, `ManifestCfRow`, `ManifestFileRow` (level plus the persisted `FileMetaData` fields), `ManifestBlobFileRow` and the WAL rows, grouped in `ManifestRows`. The overview comment at the top of the header lists the VersionEdit content that has no row field, and why. - State to rows: `VersionSet::GetManifestRows()` reads the current state into rows. - Rows to records: `ManifestRowsToRecords()` turns rows into full-state VersionEdit records that the existing recovery code replays. Its header comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`. - Comparison: `ManifestRowsEqual()` compares two sets of rows and names the first difference. Its header comment says which rows it compares field by field and which through their encoding. - Row changes: `BuildManifestRowChanges()` turns one MANIFEST write into a `ManifestRowChanges` (the new DB row, the rows to upsert and the keys to delete; an upsert adds a row or replaces the row with the same key), and `ApplyManifestRowChanges()` applies it. The `BuildManifestRowChanges()` header comment holds all rules (DB row, prev log number, files, column family row, blob file rows, WAL rows). `BaseReferencedVersionBuilder::version()` returns the base Version that the edits of one column family in a batch are applied to. - Debug check: `MakeManifestBatchVersions()` pairs each new Version with its base Version for phase 1. Three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()` run the check: fill, phase 1 without the DB mutex, and phase 2 with the DB mutex held. The comment of `VersionSet::debug_manifest_rows_` has the timeline, a table of what each phase checks, and why phase 1 needs no DB mutex. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It does this with the DB mutex held. The first call is the first `LogAndApply()` of the VersionSet. This is often the MANIFEST write of `DB::Open()`. It can also be a call that writes no MANIFEST record, such as the dummy edit of `DB::SetOptions()`. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files and blob files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`, because the drop edit lists no deleted files and the drop installs no new Version. The files are deleted later, when the last reference to the column family is released, and no MANIFEST write records that. `ManifestRowsToRecords()` skips these rows, so recovery does not see them. The debug check erases them from its own copy. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first `LogAndApply()` of the VersionSet, and again after a rejected WAL edit. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top and the row structs. 2. `db/version_set.h`: the `GetManifestRows()` declaration, then `db/manifest_rows.cc`: `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()` (state to rows). 3. `db/manifest_rows.cc`: `ManifestRowsToRecords()`, side by side with `VersionSet::WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. `db/manifest_rows.h`: `ManifestRowChanges` and `ApplyManifestRowChanges()`, then their code in `db/manifest_rows.cc`. 5. `db/manifest_rows.h`: `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, then its code; `db/version_builder.h`: `BaseReferencedVersionBuilder::version()`. 6. `db/version_set.h`: the `debug_manifest_rows_` comment with the phase table; `db/version_set.cc`: the three `#ifndef NDEBUG` hooks in `ProcessManifestWrites()`; then in `db/manifest_rows.cc` phase 1 (`MakeManifestBatchVersions()`, `DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()`) and phase 2 (`DebugCheckRowsAfterInstall()`, `VersionSet::SetManifestDbRowAndWals()`). 7. `db/version_set_test.cc`: `ManifestRowFieldOfTag()`, `ManifestRowFieldOfNewFileTag()`, `ManifestRowsRoundTrip`, then `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Differential Revision: D133208529
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation Key choices: - The rules that turn one MANIFEST write into row changes are in the `BuildManifestRowChanges()` comment in `db/manifest_rows.h`. - The debug check runs in two phases. Phase 1 does the work that grows with the number of files, and it runs without the DB mutex, before the new Versions are installed. Phase 2 checks the values that only the installed in-memory state has (the DB row, the WAL rows, the log number, `full_history_ts_low`, the dropped flag), with the DB mutex held. Each step of phase 2 is a few lookups. Phase 2 also erases the debug rows of a dropped column family, because no later MANIFEST write names it. - When the WAL set rejects a WAL edit, the MANIFEST write has happened but the write is not installed. The debug rows are then dropped and filled again from the installed state at the next write, so the check keeps comparing with what memory holds. - Some values change in memory without a MANIFEST write (for example the log number of an empty column family). The rows keep the values from the edits. The "In-memory differences" paragraph at the top of `db/manifest_rows.h` lists these values. Symbols: - Row model: `db/manifest_rows.h` defines `ManifestDbRow`, `ManifestCfRow`, `ManifestFileRow` (level plus the persisted `FileMetaData` fields), `ManifestBlobFileRow` and the WAL rows, grouped in `ManifestRows`. The overview comment at the top of the header lists the VersionEdit content that has no row field, and why. - State to rows: `VersionSet::GetManifestRows()` reads the current state into rows. - Rows to records: `ManifestRowsToRecords()` turns rows into full-state VersionEdit records that the existing recovery code replays. Its header comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`. - Comparison: `ManifestRowsEqual()` compares two sets of rows and names the first difference. Its header comment says which rows it compares field by field and which through their encoding. - Row changes: `BuildManifestRowChanges()` turns one MANIFEST write into a `ManifestRowChanges` (the new DB row, the rows to upsert and the keys to delete; an upsert adds a row or replaces the row with the same key), and `ApplyManifestRowChanges()` applies it. The `BuildManifestRowChanges()` header comment holds all rules (DB row, prev log number, files, column family row, blob file rows, WAL rows). `BaseReferencedVersionBuilder::version()` returns the base Version that the edits of one column family in a batch are applied to. - Debug check: `MakeManifestBatchVersions()` pairs each new Version with its base Version for phase 1. Three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()` run the check: fill, phase 1 without the DB mutex, and phase 2 with the DB mutex held. The comment of `VersionSet::debug_manifest_rows_` has the timeline, a table of what each phase checks, and why phase 1 needs no DB mutex. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It does this with the DB mutex held. The first call is the first `LogAndApply()` of the VersionSet. This is often the MANIFEST write of `DB::Open()`. It can also be a call that writes no MANIFEST record, such as the dummy edit of `DB::SetOptions()`. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files and blob files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`, because the drop edit lists no deleted files and the drop installs no new Version. The files are deleted later, when the last reference to the column family is released, and no MANIFEST write records that. `ManifestRowsToRecords()` skips these rows, so recovery does not see them. The debug check erases them from its own copy. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first `LogAndApply()` of the VersionSet, and again after a rejected WAL edit. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top and the row structs. 2. `db/version_set.h`: the `GetManifestRows()` declaration, then `db/manifest_rows.cc`: `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()` (state to rows). 3. `db/manifest_rows.cc`: `ManifestRowsToRecords()`, side by side with `VersionSet::WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. `db/manifest_rows.h`: `ManifestRowChanges` and `ApplyManifestRowChanges()`, then their code in `db/manifest_rows.cc`. 5. `db/manifest_rows.h`: `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, then its code; `db/version_builder.h`: `BaseReferencedVersionBuilder::version()`. 6. `db/version_set.h`: the `debug_manifest_rows_` comment with the phase table; `db/version_set.cc`: the three `#ifndef NDEBUG` hooks in `ProcessManifestWrites()`; then in `db/manifest_rows.cc` phase 1 (`MakeManifestBatchVersions()`, `DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()`) and phase 2 (`DebugCheckRowsAfterInstall()`, `VersionSet::SetManifestDbRowAndWals()`). 7. `db/version_set_test.cc`: `ManifestRowFieldOfTag()`, `ManifestRowFieldOfNewFileTag()`, `ManifestRowsRoundTrip`, then `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Differential Revision: D133208529
Claude Code Review - OBSOLETESuperseded by a newer AI review. Expand to see the original review.✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit 5c9f5f4 SummaryWell-designed and carefully documented PR that adds an internal MANIFEST row model with comprehensive debug-time verification. The two-phase check design (phase 1 without DB mutex, phase 2 with mutex) is sound, and the thread safety reasoning is thorough. The code follows RocksDB conventions, has zero cost in release builds, and includes strong test coverage via both explicit tests and implicit verification on every High-severity findings (0): Full review (click to expand)Findings🔴 HIGHNo high-severity findings. 🟡 MEDIUMM1.
|
| Context | Affected? | Safe? | Notes |
|---|---|---|---|
| WritePreparedTxnDB | Yes | Yes | Debug check only reads MANIFEST-level metadata |
| ReadOnly DB / Secondary | No | N/A | Does not call ProcessManifestWrites |
| CompactionService | No | N/A | Workers don't write DB MANIFEST |
| User-defined timestamps | Yes | Yes | Tested in ManifestRowsRoundTrip |
| BlobDB | Yes | Yes | Blob file rows explicitly handled |
| FIFO / Universal compaction | Yes | Yes | Same MANIFEST write path |
DB Mutex verification:
- Phase 2 work under mutex:
SetManifestDbRowAndWals(O(1) + O(live WALs) copy) + O(edits) lookups. Well bounded. - Fill step under mutex: copies all file metadata. Runs only on first call or after WAL rejection.
wals_modification sites verified: all in ProcessManifestWrites thread or recovery/reset (not concurrent).
Positive Observations
- Build-time safety net:
ManifestRowFieldOfTagswitch with no default ensures adding a new VersionEdit tag without updating the row model causes a build failure. - Zero release-build cost: All debug check code properly guarded by
#ifndef NDEBUG. - Comprehensive implicit test coverage: Every existing test that calls
ProcessManifestWritesin debug builds exercises this code. - Thorough documentation: Header comments in
manifest_rows.hare well-structured, documenting what's stored, what's not, in-memory differences, and thread safety reasoning.
ℹ️ About this response
Generated by Claude Code.
Review methodology: claude_md/ci_review_prompt.md
Limitations:
- Claude may miss context from files not in the diff
- Large PRs may be truncated
- Always apply human judgment to AI suggestions
Commands:
/claude-review [context]— Request a code review/claude-query <question>— Ask about the PR or codebase
5c9f5f4 to
178a61b
Compare
4204215 to
efaaba0
Compare
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation Key choices: - The rules that turn one MANIFEST write into row changes are in the `BuildManifestRowChanges()` comment in `db/manifest_rows.h`. - The debug check runs in two phases. Phase 1 does the work that grows with the number of files, and it runs without the DB mutex, before the new Versions are installed. Phase 2 checks the values that only the installed in-memory state has (the DB row, the WAL rows, the log number, `full_history_ts_low`, the dropped flag), with the DB mutex held. With the DB mutex held, phase 2 costs a few lookups for each edit, O(live WALs) and O(levels) for an added column family. For a dropped column family, phase 1 frees its file and blob file rows from the debug copy, and phase 2 erases only its small column family row. - When the WAL set rejects a WAL edit, the MANIFEST write has happened but the write is not installed. The debug rows are then dropped and filled again from the installed state at the next write, so the check keeps comparing with what memory holds. - Some values change in memory without a MANIFEST write (for example the log number of an empty column family). The rows keep the values from the edits. The "In-memory differences" paragraph at the top of `db/manifest_rows.h` lists these values. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It holds the DB mutex while it makes this copy. The first call is the first `LogAndApply()` of the VersionSet. That call is often the MANIFEST write of `DB::Open()`. It can also be a call that writes no MANIFEST record, such as the dummy edit of `DB::SetOptions()`. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files and blob files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`; `ManifestRowsToRecords()` skips them. The comment of `ManifestCfRow::dropped` describes these rows. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first `LogAndApply()` of the VersionSet, and again after a rejected WAL edit. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top ("Background", the VersionEdit content that has no row field, "In-memory differences"), then the row structs from `ManifestDbRow` to `ManifestRows`, with the layout diagram. 2. State to rows: the `VersionSet::GetManifestRows()` declaration in `db/version_set.h`, then in `db/manifest_rows.cc` `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()`. 3. Rows to records and comparison: `ManifestRowsToRecords()` (its comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`), read next to `WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. Row changes: `ManifestRowChanges` and `ApplyManifestRowChanges()`; then `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, which holds all rules, and its code. `BaseReferencedVersionBuilder::version()` in `db/version_builder.h` is a one-line accessor for the base Version. 5. Debug check: the `debug_manifest_rows_` comment in `db/version_set.h` (timeline, phase table, threads); the three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()`; then in `db/manifest_rows.cc` `MakeManifestBatchVersions()`, `DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()` and `DebugCheckRowsAfterInstall()`. 6. Tests in `db/version_set_test.cc`: `ManifestRowFieldOfTag()` and `ManifestRowFieldOfNewFileTag()` (the checklist for new tags), then `ManifestRowsRoundTrip` and `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Differential Revision: D133208529
Claude Code Review - OBSOLETESuperseded by a newer AI review. Expand to see the original review.✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit 4204215 SummaryWell-designed feature that adds a structured row model for MANIFEST data with thorough debug-only verification. The code is carefully structured to minimize DB mutex impact (heavy work in phase 1 without mutex, lightweight phase 2 with mutex). Thread safety analysis is convincing. Documentation is excellent. High-severity findings (0): No high-severity findings. Full review (click to expand)Findings🟡 MEDIUMM1.
|
| Context | Executes? | Safe? | Action |
|---|---|---|---|
| WritePreparedTxnDB | YES (debug) | YES -- rows model MANIFEST, not txn visibility | None |
| ReadOnly/Secondary DB | NO -- no ProcessManifestWrites | N/A | None |
| User-defined timestamps | YES -- tested | YES -- timestamp_size plumbed correctly | None |
| BlobDB | YES -- tested | YES | None |
| Concurrent writers | YES -- single PMW thread | YES | None |
| FIFO/Universal compaction | YES (debug) | YES -- compaction-style independent | None |
Positive Observations
- Excellent documentation: Thorough header comments including "In-memory differences", row layout diagram, and per-function rules.
- Sound two-phase design: Phase 1 (heavy, no mutex) + phase 2 (lightweight, with mutex) minimizes mutex hold time.
- Comprehensive tests: Round-trip test covers all fields (UDT, path IDs, blob files, dropped CFs, compact cursors, OPTIONS). Match test covers all edit types including atomic groups, WAL rejection, CF add/drop.
- Tag checklist mechanism:
-WswitchbasedManifestRowFieldOfTagensures new tags are accounted for. - Thread safety documentation: Explicit per-object justification for phase 1 safety.
- Build systems: All three (Make, CMake, BUCK) correctly updated.
ℹ️ About this response
Generated by Claude Code.
Review methodology: claude_md/ci_review_prompt.md
Limitations:
- Claude may miss context from files not in the diff
- Large PRs may be truncated
- Always apply human judgment to AI suggestions
Commands:
/claude-review [context]— Request a code review/claude-query <question>— Ask about the PR or codebase
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation Key choices: - The rules that turn one MANIFEST write into row changes are in the `BuildManifestRowChanges()` comment in `db/manifest_rows.h`. - The debug check runs in two phases. Phase 1 does the work that grows with the number of files, and it runs without the DB mutex, before the new Versions are installed. Phase 2 checks the values that only the installed in-memory state has (the DB row, the WAL rows, the log number, `full_history_ts_low`, the dropped flag), with the DB mutex held. With the DB mutex held, phase 2 costs a few lookups for each edit, O(live WALs) and O(levels) for an added column family. For a dropped column family, phase 1 frees its file and blob file rows from the debug copy, and phase 2 erases only its small column family row. - When the WAL set rejects a WAL edit, the MANIFEST write has happened but the write is not installed. The debug rows are then dropped and filled again from the installed state at the next write, so the check keeps comparing with what memory holds. - Some values change in memory without a MANIFEST write (for example the log number of an empty column family). The rows keep the values from the edits. The "In-memory differences" paragraph at the top of `db/manifest_rows.h` lists these values. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It holds the DB mutex while it makes this copy. The first call is the first `LogAndApply()` of the VersionSet. That call is often the MANIFEST write of `DB::Open()`. It can also be a call that writes no MANIFEST record, such as the dummy edit of `DB::SetOptions()`. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files and blob files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`; `ManifestRowsToRecords()` skips them. The comment of `ManifestCfRow::dropped` describes these rows. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first `LogAndApply()` of the VersionSet, and again after a rejected WAL edit. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top ("Background", the VersionEdit content that has no row field, "In-memory differences"), then the row structs from `ManifestDbRow` to `ManifestRows`, with the layout diagram. 2. State to rows: the `VersionSet::GetManifestRows()` declaration in `db/version_set.h`, then in `db/manifest_rows.cc` `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()`. 3. Rows to records and comparison: `ManifestRowsToRecords()` (its comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`), read next to `WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. Row changes: `ManifestRowChanges` and `ApplyManifestRowChanges()`; then `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, which holds all rules, and its code. `BaseReferencedVersionBuilder::version()` in `db/version_builder.h` is a one-line accessor for the base Version. 5. Debug check: the `debug_manifest_rows_` comment in `db/version_set.h` (timeline, phase table, threads); the three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()`; then in `db/manifest_rows.cc` `MakeManifestBatchVersions()`, `DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()` and `DebugCheckRowsAfterInstall()`. 6. Tests in `db/version_set_test.cc`: `ManifestRowFieldOfTag()` and `ManifestRowFieldOfNewFileTag()` (the checklist for new tags), then `ManifestRowsRoundTrip` and `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Differential Revision: D133208529
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation Key choices: - The rules that turn one MANIFEST write into row changes are in the `BuildManifestRowChanges()` comment in `db/manifest_rows.h`. - The debug check runs in two phases. Phase 1 does the work that grows with the number of files, and it runs without the DB mutex, before the new Versions are installed. Phase 2 checks the values that only the installed in-memory state has (the DB row, the WAL rows, the log number, `full_history_ts_low`, the dropped flag), with the DB mutex held. With the DB mutex held, phase 2 costs a few lookups for each edit, O(live WALs) and O(levels) for an added column family. For a dropped column family, phase 1 frees its file and blob file rows from the debug copy, and phase 2 erases only its small column family row. - When the WAL set rejects a WAL edit, the MANIFEST write has happened but the write is not installed. The debug rows are then dropped and filled again from the installed state at the next write, so the check keeps comparing with what memory holds. - Some values change in memory without a MANIFEST write (for example the log number of an empty column family). The rows keep the values from the edits. The "In-memory differences" paragraph at the top of `db/manifest_rows.h` lists these values. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It holds the DB mutex while it makes this copy. The first call is the first `LogAndApply()` of the VersionSet. That call is often the MANIFEST write of `DB::Open()`. It can also be a call that writes no MANIFEST record, such as the dummy edit of `DB::SetOptions()`. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files and blob files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`; `ManifestRowsToRecords()` skips them. The comment of `ManifestCfRow::dropped` describes these rows. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first `LogAndApply()` of the VersionSet, and again after a rejected WAL edit. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top ("Background", the VersionEdit content that has no row field, "In-memory differences"), then the row structs from `ManifestDbRow` to `ManifestRows`, with the layout diagram. 2. State to rows: the `VersionSet::GetManifestRows()` declaration in `db/version_set.h`, then in `db/manifest_rows.cc` `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()`. 3. Rows to records and comparison: `ManifestRowsToRecords()` (its comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`), read next to `WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. Row changes: `ManifestRowChanges` and `ApplyManifestRowChanges()`; then `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, which holds all rules, and its code. `BaseReferencedVersionBuilder::version()` in `db/version_builder.h` is a one-line accessor for the base Version. 5. Debug check: the `debug_manifest_rows_` comment in `db/version_set.h` (timeline, phase table, threads); the three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()`; then in `db/manifest_rows.cc` `MakeManifestBatchVersions()`, `DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()` and `DebugCheckRowsAfterInstall()`. 6. Tests in `db/version_set_test.cc`: `ManifestRowFieldOfTag()` and `ManifestRowFieldOfNewFileTag()` (the checklist for new tags), then `ManifestRowsRoundTrip` and `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Differential Revision: D133208529
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation Key choices: - The rules that turn one MANIFEST write into row changes are in the `BuildManifestRowChanges()` comment in `db/manifest_rows.h`. - The debug check runs in two phases. Phase 1 does the work that grows with the number of files, and it runs without the DB mutex, before the new Versions are installed. Phase 2 checks the values that only the installed in-memory state has (the DB row, the WAL rows, the log number, `full_history_ts_low`, the dropped flag), with the DB mutex held. With the DB mutex held, phase 2 costs a few lookups for each edit, O(live WALs) and O(levels) for an added column family. For a dropped column family, phase 1 frees its file and blob file rows from the debug copy, and phase 2 erases only its small column family row. - When the WAL set rejects a WAL edit, the MANIFEST write has happened but the write is not installed. The debug rows are then dropped and filled again from the installed state at the next write, so the check keeps comparing with what memory holds. - Some values change in memory without a MANIFEST write (for example the log number of an empty column family). The rows keep the values from the edits. The "In-memory differences" paragraph at the top of `db/manifest_rows.h` lists these values. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It holds the DB mutex while it makes this copy. The first call is the first `LogAndApply()` of the VersionSet. That call is often the MANIFEST write of `DB::Open()`. It can also be a call that writes no MANIFEST record, such as the dummy edit of `DB::SetOptions()`. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files and blob files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`; `ManifestRowsToRecords()` skips them. The comment of `ManifestCfRow::dropped` describes these rows. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first `LogAndApply()` of the VersionSet, and again after a rejected WAL edit. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top ("Background", the VersionEdit content that has no row field, "In-memory differences"), then the row structs from `ManifestDbRow` to `ManifestRows`, with the layout diagram. 2. State to rows: the `VersionSet::GetManifestRows()` declaration in `db/version_set.h`, then in `db/manifest_rows.cc` `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()`. 3. Rows to records and comparison: `ManifestRowsToRecords()` (its comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`), read next to `WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. Row changes: `ManifestRowChanges` and `ApplyManifestRowChanges()`; then `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, which holds all rules, and its code. `BaseReferencedVersionBuilder::version()` in `db/version_builder.h` is a one-line accessor for the base Version. 5. Debug check: the `debug_manifest_rows_` comment in `db/version_set.h` (timeline, phase table, threads); the three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()`; then in `db/manifest_rows.cc` `MakeManifestBatchVersions()`, `DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()` and `DebugCheckRowsAfterInstall()`. 6. Tests in `db/version_set_test.cc`: `ManifestRowFieldOfTag()` and `ManifestRowFieldOfNewFileTag()` (the checklist for new tags), then `ManifestRowsRoundTrip` and `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Differential Revision: D133208529
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation Key choices: - The rules that turn one MANIFEST write into row changes are in the `BuildManifestRowChanges()` comment in `db/manifest_rows.h`. - The debug check runs in two phases. Phase 1 does the work that grows with the number of files, and it runs without the DB mutex, before the new Versions are installed. Phase 2 checks the values that only the installed in-memory state has (the DB row, the WAL rows, the log number, `full_history_ts_low`, the dropped flag), with the DB mutex held. With the DB mutex held, phase 2 costs a few lookups for each edit, O(live WALs) and O(levels) for an added column family. For a dropped column family, phase 1 frees its file and blob file rows from the debug copy, and phase 2 erases only its small column family row. - When the WAL set rejects a WAL edit, the MANIFEST write has happened but the write is not installed. The debug rows are then dropped and filled again from the installed state at the next write, so the check keeps comparing with what memory holds. - Some values change in memory without a MANIFEST write (for example the log number of an empty column family). The rows keep the values from the edits. The "In-memory differences" paragraph at the top of `db/manifest_rows.h` lists these values. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It holds the DB mutex while it makes this copy. The first call is the first `LogAndApply()` of the VersionSet. That call is often the MANIFEST write of `DB::Open()`. It can also be a call that writes no MANIFEST record, such as the dummy edit of `DB::SetOptions()`. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files and blob files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`; `ManifestRowsToRecords()` skips them. The comment of `ManifestCfRow::dropped` describes these rows. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first `LogAndApply()` of the VersionSet, and again after a rejected WAL edit. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top ("Background", the VersionEdit content that has no row field, "In-memory differences"), then the row structs from `ManifestDbRow` to `ManifestRows`, with the layout diagram. 2. State to rows: the `VersionSet::GetManifestRows()` declaration in `db/version_set.h`, then in `db/manifest_rows.cc` `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()`. 3. Rows to records and comparison: `ManifestRowsToRecords()` (its comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`), read next to `WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. Row changes: `ManifestRowChanges` and `ApplyManifestRowChanges()`; then `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, which holds all rules, and its code. `BaseReferencedVersionBuilder::version()` in `db/version_builder.h` is a one-line accessor for the base Version. 5. Debug check: the `debug_manifest_rows_` comment in `db/version_set.h` (timeline, phase table, threads); the three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()`; then in `db/manifest_rows.cc` `MakeManifestBatchVersions()`, `DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()` and `DebugCheckRowsAfterInstall()`. 6. Tests in `db/version_set_test.cc`: `ManifestRowFieldOfTag()` and `ManifestRowFieldOfNewFileTag()` (the checklist for new tags), then `ManifestRowsRoundTrip` and `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Differential Revision: D133208529
Claude Code Review - OBSOLETESuperseded by a newer AI review. Expand to see the original review.✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit efaaba0 SummaryWell-structured PR that adds an internal MANIFEST row model with comprehensive debug checks and no release-build impact. The two-phase debug check design correctly accounts for mutex boundaries, the ManifestRowFieldOfTag switch pattern is a clever build-time guardrail, and the round-trip test provides strong coverage. The code is thorough and well-documented. High-severity findings (0): No high-severity findings. Full review (click to expand)Findings🔴 HIGHNo high-severity findings. 🟡 MEDIUMM1.
|
| Context | Executes? | Safe? | Notes |
|---|---|---|---|
| WritePreparedTxnDB | YES | YES | Debug check only compares metadata, not key visibility |
| ReadOnly DB / SecondaryInstance | NO | N/A | They don't write MANIFEST |
| Recovery | NO | N/A | ProcessManifestWrites not called during recovery |
| CompactionService | NO | N/A | Remote workers don't run ProcessManifestWrites |
| User-defined timestamps | YES | YES | Correctly handled via timestamp_size and persist_user_defined_timestamps |
Concurrent SuggestCompactRange |
YES | YES | Phase 1 only reads number/level of existing files |
Assumption verification:
- "No change in release builds" — VERIFIED. All
version_set.ccchanges inside#ifndef NDEBUG. Structs defined unconditionally but only used in NDEBUG-guarded code and tests. - "BlobFileMetaData immutable" — VERIFIED. Copy/move deleted, all members set at construction.
- "Only PMW thread changes
wals_" — VERIFIED. Modified at Reset (recovery), install path (PMW), and VersionEditHandler (recovery). No concurrent access. - "Base Versions referenced" — VERIFIED.
BaseReferencedVersionBuildercallsversion_->Ref()atversion_builder.cc:2202. - "WAL rejection recovery" — VERIFIED. Reset to null, re-fill on next call.
Positive Observations
- Build-time tag checklist:
ManifestRowFieldOfTagandManifestRowFieldOfNewFileTagswitches with nodefaultcase force build failures when new tags are added. Excellent guardrail. - Two-phase debug check: Phase 1 (no mutex, O(files)) and phase 2 (mutex held, O(edits)) minimizes mutex hold time while verifying all fields.
- Comprehensive documentation: The 60+ line
debug_manifest_rows_comment inversion_set.hand the "In-memory differences" section inmanifest_rows.hare thorough. - Defensive WAL rejection handling: Robust reset-and-refill on the next call.
- Test quality:
ManifestRowChangesMatchVersionscovers file add/move/compaction, blob garbage/removal, atomic groups, WAL operations, CF add/drop, options edits, dummy edits, and verifies check counts via sync points.ManifestRowsRoundTripsets every field to non-default values.
ℹ️ About this response
Generated by Claude Code.
Review methodology: claude_md/ci_review_prompt.md
Limitations:
- Claude may miss context from files not in the diff
- Large PRs may be truncated
- Always apply human judgment to AI suggestions
Commands:
/claude-review [context]— Request a code review/claude-query <question>— Ask about the PR or codebase
efaaba0 to
74d9581
Compare
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation Key choices: - The rules that turn one MANIFEST write into row changes are in the `BuildManifestRowChanges()` comment in `db/manifest_rows.h`. - The debug check runs in two phases. Phase 1 does the work that grows with the number of files, and it runs without the DB mutex, before the new Versions are installed. Phase 2 checks the values that only the installed in-memory state has (the DB row, the WAL rows, the log number, `full_history_ts_low`, the dropped flag), with the DB mutex held. With the DB mutex held, phase 2 costs a few lookups for each edit, O(live WALs) and O(levels) for an added column family. For a dropped column family, phase 1 frees its file and blob file rows from the debug copy, and phase 2 erases only its small column family row. - When the WAL set rejects a WAL edit, the MANIFEST write has happened but the write is not installed. The debug rows are then dropped and filled again from the installed state at the next write, so the check keeps comparing with what memory holds. - Some values change in memory without a MANIFEST write (for example the log number of an empty column family). The rows keep the values from the edits. The "In-memory differences" paragraph at the top of `db/manifest_rows.h` lists these values. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It holds the DB mutex while it makes this copy. The first call is the first `LogAndApply()` of the VersionSet. That call is often the MANIFEST write of `DB::Open()`. It can also be a call that writes no MANIFEST record, such as the dummy edit of `DB::SetOptions()`. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files and blob files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`; `ManifestRowsToRecords()` skips them. The comment of `ManifestCfRow::dropped` describes these rows. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first `LogAndApply()` of the VersionSet, and again after a rejected WAL edit. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top ("Background", the VersionEdit content that has no row field, "In-memory differences"), then the row structs from `ManifestDbRow` to `ManifestRows`, with the layout diagram. 2. State to rows: the `VersionSet::GetManifestRows()` declaration in `db/version_set.h`, then in `db/manifest_rows.cc` `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()`. 3. Rows to records and comparison: `ManifestRowsToRecords()` (its comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`), read next to `WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. Row changes: `ManifestRowChanges` and `ApplyManifestRowChanges()`; then `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, which holds all rules, and its code. `BaseReferencedVersionBuilder::version()` in `db/version_builder.h` is a one-line accessor for the base Version. 5. Debug check: the `debug_manifest_rows_` comment in `db/version_set.h` (timeline, phase table, threads); the three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()`; then in `db/manifest_rows.cc` `MakeManifestBatchVersions()`, `DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()` and `DebugCheckRowsAfterInstall()`. 6. Tests in `db/version_set_test.cc`: `ManifestRowFieldOfTag()` and `ManifestRowFieldOfNewFileTag()` (the checklist for new tags), then `ManifestRowsRoundTrip` and `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Differential Revision: D133208529
74d9581 to
0943ba7
Compare
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation Key choices: - The rules that turn one MANIFEST write into row changes are in the `BuildManifestRowChanges()` comment in `db/manifest_rows.h`. - The debug check runs in two phases. Phase 1 does the work that grows with the number of files, and it runs without the DB mutex, before the new Versions are installed. Phase 2 checks the values that only the installed in-memory state has (the DB row, the WAL rows, the log number, `full_history_ts_low`, the dropped flag), with the DB mutex held. With the DB mutex held, phase 2 costs a few lookups for each edit, O(live WALs) and O(levels) for an added column family. For a dropped column family, phase 1 frees its file and blob file rows from the debug copy, and phase 2 erases only its small column family row. - When the WAL set rejects a WAL edit, the MANIFEST write has happened but the write is not installed. The debug rows are then dropped and filled again from the installed state at the next write, so the check keeps comparing with what memory holds. - Some values change in memory without a MANIFEST write (for example the log number of an empty column family). The rows keep the values from the edits. The "In-memory differences" paragraph at the top of `db/manifest_rows.h` lists these values. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It holds the DB mutex while it makes this copy. The first call is the first `LogAndApply()` of the VersionSet. That call is often the MANIFEST write of `DB::Open()`. It can also be a call that writes no MANIFEST record, such as the dummy edit of `DB::SetOptions()`. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files and blob files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`; `ManifestRowsToRecords()` skips them. The comment of `ManifestCfRow::dropped` describes these rows. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first `LogAndApply()` of the VersionSet, and again after a rejected WAL edit. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top ("Background", the VersionEdit content that has no row field, "In-memory differences"), then the row structs from `ManifestDbRow` to `ManifestRows`, with the layout diagram. 2. State to rows: the `VersionSet::GetManifestRows()` declaration in `db/version_set.h`, then in `db/manifest_rows.cc` `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()`. 3. Rows to records and comparison: `ManifestRowsToRecords()` (its comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`), read next to `WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. Row changes: `ManifestRowChanges` and `ApplyManifestRowChanges()`; then `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, which holds all rules, and its code. `BaseReferencedVersionBuilder::version()` in `db/version_builder.h` is a one-line accessor for the base Version. 5. Debug check: the `debug_manifest_rows_` comment in `db/version_set.h` (timeline, phase table, threads); the three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()`; then in `db/manifest_rows.cc` `MakeManifestBatchVersions()`, `DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()` and `DebugCheckRowsAfterInstall()`. 6. Tests in `db/version_set_test.cc`: `ManifestRowFieldOfTag()` and `ManifestRowFieldOfNewFileTag()` (the checklist for new tags), then `ManifestRowsRoundTrip` and `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Differential Revision: D133208529
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation Key choices: - The rules that turn one MANIFEST write into row changes are in the `BuildManifestRowChanges()` comment in `db/manifest_rows.h`. - The debug check runs in two phases. Phase 1 does the work that grows with the number of files, and it runs without the DB mutex, before the new Versions are installed. Phase 2 checks the values that only the installed in-memory state has (the DB row, the WAL rows, the log number, `full_history_ts_low`, the dropped flag), with the DB mutex held. With the DB mutex held, phase 2 costs a few lookups for each edit, O(live WALs) and O(levels) for an added column family. For a dropped column family, phase 1 frees its file and blob file rows from the debug copy, and phase 2 erases only its small column family row. - When the WAL set rejects a WAL edit, the MANIFEST write has happened but the write is not installed. The debug rows are then dropped and filled again from the installed state at the next write, so the check keeps comparing with what memory holds. - Some values change in memory without a MANIFEST write (for example the log number of an empty column family). The rows keep the values from the edits. The "In-memory differences" paragraph at the top of `db/manifest_rows.h` lists these values. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It holds the DB mutex while it makes this copy. The first call is the first `LogAndApply()` of the VersionSet. That call is often the MANIFEST write of `DB::Open()`. It can also be a call that writes no MANIFEST record, such as the dummy edit of `DB::SetOptions()`. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files and blob files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`; `ManifestRowsToRecords()` skips them. The comment of `ManifestCfRow::dropped` describes these rows. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first `LogAndApply()` of the VersionSet, and again after a rejected WAL edit. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top ("Background", the VersionEdit content that has no row field, "In-memory differences"), then the row structs from `ManifestDbRow` to `ManifestRows`, with the layout diagram. 2. State to rows: the `VersionSet::GetManifestRows()` declaration in `db/version_set.h`, then in `db/manifest_rows.cc` `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()`. 3. Rows to records and comparison: `ManifestRowsToRecords()` (its comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`), read next to `WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. Row changes: `ManifestRowChanges` and `ApplyManifestRowChanges()`; then `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, which holds all rules, and its code. `BaseReferencedVersionBuilder::version()` in `db/version_builder.h` is a one-line accessor for the base Version. 5. Debug check: the `debug_manifest_rows_` comment in `db/version_set.h` (timeline, phase table, threads); the three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()`; then in `db/manifest_rows.cc` `MakeManifestBatchVersions()`, `DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()` and `DebugCheckRowsAfterInstall()`. 6. Tests in `db/version_set_test.cc`: `ManifestRowFieldOfTag()` and `ManifestRowFieldOfNewFileTag()` (the checklist for new tags), then `ManifestRowsRoundTrip` and `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Differential Revision: D133208529
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation Key choices: - The rules that turn one MANIFEST write into row changes are in the `BuildManifestRowChanges()` comment in `db/manifest_rows.h`. - The debug check runs in two phases. Phase 1 does the work that grows with the number of files, and it runs without the DB mutex, before the new Versions are installed. Phase 2 checks the values that only the installed in-memory state has (the DB row, the WAL rows, the log number, `full_history_ts_low`, the dropped flag), with the DB mutex held. With the DB mutex held, phase 2 costs a few lookups for each edit, O(live WALs) and O(levels) for an added column family. For a dropped column family, phase 1 frees its file and blob file rows from the debug copy, and phase 2 erases only its small column family row. - When the WAL set rejects a WAL edit, the MANIFEST write has happened but the write is not installed. The debug rows are then dropped and filled again from the installed state at the next write, so the check keeps comparing with what memory holds. - Some values change in memory without a MANIFEST write (for example the log number of an empty column family). The rows keep the values from the edits. The "In-memory differences" paragraph at the top of `db/manifest_rows.h` lists these values. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It holds the DB mutex while it makes this copy. The first call is the first `LogAndApply()` of the VersionSet. That call is often the MANIFEST write of `DB::Open()`. It can also be a call that writes no MANIFEST record, such as the dummy edit of `DB::SetOptions()`. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files and blob files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`; `ManifestRowsToRecords()` skips them. The comment of `ManifestCfRow::dropped` describes these rows. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first `LogAndApply()` of the VersionSet, and again after a rejected WAL edit. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top ("Background", the VersionEdit content that has no row field, "In-memory differences"), then the row structs from `ManifestDbRow` to `ManifestRows`, with the layout diagram. 2. State to rows: the `VersionSet::GetManifestRows()` declaration in `db/version_set.h`, then in `db/manifest_rows.cc` `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()`. 3. Rows to records and comparison: `ManifestRowsToRecords()` (its comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`), read next to `WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. Row changes: `ManifestRowChanges` and `ApplyManifestRowChanges()`; then `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, which holds all rules, and its code. `BaseReferencedVersionBuilder::version()` in `db/version_builder.h` is a one-line accessor for the base Version. 5. Debug check: the `debug_manifest_rows_` comment in `db/version_set.h` (timeline, phase table, threads); the three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()`; then in `db/manifest_rows.cc` `MakeManifestBatchVersions()`, `DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()` and `DebugCheckRowsAfterInstall()`. 6. Tests in `db/version_set_test.cc`: `ManifestRowFieldOfTag()` and `ManifestRowFieldOfNewFileTag()` (the checklist for new tags), then `ManifestRowsRoundTrip` and `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Differential Revision: D133208529
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation Key choices: - The rules that turn one MANIFEST write into row changes are in the `BuildManifestRowChanges()` comment in `db/manifest_rows.h`. - The debug check runs in two phases. Phase 1 does the work that grows with the number of files, and it runs without the DB mutex, before the new Versions are installed. Phase 2 checks the values that only the installed in-memory state has (the DB row, the WAL rows, the log number, `full_history_ts_low`, the dropped flag), with the DB mutex held. With the DB mutex held, phase 2 costs a few lookups for each edit, O(live WALs) and O(levels) for an added column family. For a dropped column family, phase 1 frees its file and blob file rows from the debug copy, and phase 2 erases only its small column family row. - When the WAL set rejects a WAL edit, the MANIFEST write has happened but the write is not installed. The debug rows are then dropped and filled again from the installed state at the next write, so the check keeps comparing with what memory holds. - Some values change in memory without a MANIFEST write (for example the log number of an empty column family). The rows keep the values from the edits. The "In-memory differences" paragraph at the top of `db/manifest_rows.h` lists these values. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It holds the DB mutex while it makes this copy. The first call is the first `LogAndApply()` of the VersionSet. That call is often the MANIFEST write of `DB::Open()`. It can also be a call that writes no MANIFEST record, such as the dummy edit of `DB::SetOptions()`. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files and blob files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`; `ManifestRowsToRecords()` skips them. The comment of `ManifestCfRow::dropped` describes these rows. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first `LogAndApply()` of the VersionSet, and again after a rejected WAL edit. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top ("Background", the VersionEdit content that has no row field, "In-memory differences"), then the row structs from `ManifestDbRow` to `ManifestRows`, with the layout diagram. 2. State to rows: the `VersionSet::GetManifestRows()` declaration in `db/version_set.h`, then in `db/manifest_rows.cc` `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()`. 3. Rows to records and comparison: `ManifestRowsToRecords()` (its comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`), read next to `WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. Row changes: `ManifestRowChanges` and `ApplyManifestRowChanges()`; then `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, which holds all rules, and its code. `BaseReferencedVersionBuilder::version()` in `db/version_builder.h` is a one-line accessor for the base Version. 5. Debug check: the `debug_manifest_rows_` comment in `db/version_set.h` (timeline, phase table, threads); the three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()`; then in `db/manifest_rows.cc` `MakeManifestBatchVersions()`, `DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()` and `DebugCheckRowsAfterInstall()`. 6. Tests in `db/version_set_test.cc`: `ManifestRowFieldOfTag()` and `ManifestRowFieldOfNewFileTag()` (the checklist for new tags), then `ManifestRowsRoundTrip` and `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Differential Revision: D133208529
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation Key choices: - The rules that turn one MANIFEST write into row changes are in the `BuildManifestRowChanges()` comment in `db/manifest_rows.h`. - The debug check runs in two phases. Phase 1 does the work that grows with the number of files, and it runs without the DB mutex, before the new Versions are installed. Phase 2 checks the values that only the installed in-memory state has (the DB row, the WAL rows, the log number, `full_history_ts_low`, the dropped flag), with the DB mutex held. With the DB mutex held, phase 2 costs a few lookups for each edit, O(live WALs) and O(levels) for an added column family. For a dropped column family, phase 1 frees its file and blob file rows from the debug copy, and phase 2 erases only its small column family row. - When the WAL set rejects a WAL edit, the MANIFEST write has happened but the write is not installed. The debug rows are then dropped and filled again from the installed state at the next write, so the check keeps comparing with what memory holds. - Some values change in memory without a MANIFEST write (for example the log number of an empty column family). The rows keep the values from the edits. The "In-memory differences" paragraph at the top of `db/manifest_rows.h` lists these values. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It holds the DB mutex while it makes this copy. The first call is the first `LogAndApply()` of the VersionSet. That call is often the MANIFEST write of `DB::Open()`. It can also be a call that writes no MANIFEST record, such as the dummy edit of `DB::SetOptions()`. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files and blob files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`; `ManifestRowsToRecords()` skips them. The comment of `ManifestCfRow::dropped` describes these rows. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first `LogAndApply()` of the VersionSet, and again after a rejected WAL edit. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top ("Background", the VersionEdit content that has no row field, "In-memory differences"), then the row structs from `ManifestDbRow` to `ManifestRows`, with the layout diagram. 2. State to rows: the `VersionSet::GetManifestRows()` declaration in `db/version_set.h`, then in `db/manifest_rows.cc` `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()`. 3. Rows to records and comparison: `ManifestRowsToRecords()` (its comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`), read next to `WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. Row changes: `ManifestRowChanges` and `ApplyManifestRowChanges()`; then `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, which holds all rules, and its code. `BaseReferencedVersionBuilder::version()` in `db/version_builder.h` is a one-line accessor for the base Version. 5. Debug check: the `debug_manifest_rows_` comment in `db/version_set.h` (timeline, phase table, threads); the three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()`; then in `db/manifest_rows.cc` `MakeManifestBatchVersions()`, `DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()` and `DebugCheckRowsAfterInstall()`. 6. Tests in `db/version_set_test.cc`: `ManifestRowFieldOfTag()` and `ManifestRowFieldOfNewFileTag()` (the checklist for new tags), then `ManifestRowsRoundTrip` and `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Differential Revision: D133208529
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation Key choices: - The rules that turn one MANIFEST write into row changes are in the `BuildManifestRowChanges()` comment in `db/manifest_rows.h`. - The debug check runs in two phases. Phase 1 does the work that grows with the number of files, and it runs without the DB mutex, before the new Versions are installed. Phase 2 checks the values that only the installed in-memory state has (the DB row, the WAL rows, the log number, `full_history_ts_low`, the dropped flag), with the DB mutex held. With the DB mutex held, phase 2 costs a few lookups for each edit, O(live WALs) and O(levels) for an added column family. For a dropped column family, phase 1 frees its file and blob file rows from the debug copy, and phase 2 erases only its small column family row. - When the WAL set rejects a WAL edit, the MANIFEST write has happened but the write is not installed. The debug rows are then dropped and filled again from the installed state at the next write, so the check keeps comparing with what memory holds. - Some values change in memory without a MANIFEST write (for example the log number of an empty column family). The rows keep the values from the edits. The "In-memory differences" paragraph at the top of `db/manifest_rows.h` lists these values. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It holds the DB mutex while it makes this copy. The first call is the first `LogAndApply()` of the VersionSet. That call is often the MANIFEST write of `DB::Open()`. It can also be a call that writes no MANIFEST record, such as the dummy edit of `DB::SetOptions()`. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files and blob files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`; `ManifestRowsToRecords()` skips them. The comment of `ManifestCfRow::dropped` describes these rows. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first `LogAndApply()` of the VersionSet, and again after a rejected WAL edit. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top ("Background", the VersionEdit content that has no row field, "In-memory differences"), then the row structs from `ManifestDbRow` to `ManifestRows`, with the layout diagram. 2. State to rows: the `VersionSet::GetManifestRows()` declaration in `db/version_set.h`, then in `db/manifest_rows.cc` `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()`. 3. Rows to records and comparison: `ManifestRowsToRecords()` (its comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`), read next to `WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. Row changes: `ManifestRowChanges` and `ApplyManifestRowChanges()`; then `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, which holds all rules, and its code. `BaseReferencedVersionBuilder::version()` in `db/version_builder.h` is a one-line accessor for the base Version. 5. Debug check: the `debug_manifest_rows_` comment in `db/version_set.h` (timeline, phase table, threads); the three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()`; then in `db/manifest_rows.cc` `MakeManifestBatchVersions()`, `DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()` and `DebugCheckRowsAfterInstall()`. 6. Tests in `db/version_set_test.cc`: `ManifestRowFieldOfTag()` and `ManifestRowFieldOfNewFileTag()` (the checklist for new tags), then `ManifestRowsRoundTrip` and `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Differential Revision: D133208529
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation Key choices: - The rules that turn one MANIFEST write into row changes are in the `BuildManifestRowChanges()` comment in `db/manifest_rows.h`. - The debug check runs in two phases. Phase 1 does the work that grows with the number of files, and it runs without the DB mutex, before the new Versions are installed. Phase 2 checks the values that only the installed in-memory state has (the DB row, the WAL rows, the log number, `full_history_ts_low`, the dropped flag), with the DB mutex held. With the DB mutex held, phase 2 costs a few lookups for each edit, O(live WALs) and O(levels) for an added column family. For a dropped column family, phase 1 frees its file and blob file rows from the debug copy, and phase 2 erases only its small column family row. - When the WAL set rejects a WAL edit, the MANIFEST write has happened but the write is not installed. The debug rows are then dropped and filled again from the installed state at the next write, so the check keeps comparing with what memory holds. - Some values change in memory without a MANIFEST write (for example the log number of an empty column family). The rows keep the values from the edits. The "In-memory differences" paragraph at the top of `db/manifest_rows.h` lists these values. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It holds the DB mutex while it makes this copy. The first call is the first `LogAndApply()` of the VersionSet. That call is often the MANIFEST write of `DB::Open()`. It can also be a call that writes no MANIFEST record, such as the dummy edit of `DB::SetOptions()`. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files and blob files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`; `ManifestRowsToRecords()` skips them. The comment of `ManifestCfRow::dropped` describes these rows. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first `LogAndApply()` of the VersionSet, and again after a rejected WAL edit. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top ("Background", the VersionEdit content that has no row field, "In-memory differences"), then the row structs from `ManifestDbRow` to `ManifestRows`, with the layout diagram. 2. State to rows: the `VersionSet::GetManifestRows()` declaration in `db/version_set.h`, then in `db/manifest_rows.cc` `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()`. 3. Rows to records and comparison: `ManifestRowsToRecords()` (its comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`), read next to `WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. Row changes: `ManifestRowChanges` and `ApplyManifestRowChanges()`; then `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, which holds all rules, and its code. `BaseReferencedVersionBuilder::version()` in `db/version_builder.h` is a one-line accessor for the base Version. 5. Debug check: the `debug_manifest_rows_` comment in `db/version_set.h` (timeline, phase table, threads); the three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()`; then in `db/manifest_rows.cc` `MakeManifestBatchVersions()`, `DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()` and `DebugCheckRowsAfterInstall()`. 6. Tests in `db/version_set_test.cc`: `ManifestRowFieldOfTag()` and `ManifestRowFieldOfNewFileTag()` (the checklist for new tags), then `ManifestRowsRoundTrip` and `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Differential Revision: D133208529
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation Key choices: - The rules that turn one MANIFEST write into row changes are in the `BuildManifestRowChanges()` comment in `db/manifest_rows.h`. - The debug check runs in two phases. Phase 1 does the work that grows with the number of files, and it runs without the DB mutex, before the new Versions are installed. Phase 2 checks the values that only the installed in-memory state has (the DB row, the WAL rows, the log number, `full_history_ts_low`, the dropped flag), with the DB mutex held. With the DB mutex held, phase 2 costs a few lookups for each edit, O(live WALs) and O(levels) for an added column family. For a dropped column family, phase 1 frees its file and blob file rows from the debug copy, and phase 2 erases only its small column family row. - When the WAL set rejects a WAL edit, the MANIFEST write has happened but the write is not installed. The debug rows are then dropped and filled again from the installed state at the next write, so the check keeps comparing with what memory holds. - Some values change in memory without a MANIFEST write (for example the log number of an empty column family). The rows keep the values from the edits. The "In-memory differences" paragraph at the top of `db/manifest_rows.h` lists these values. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It holds the DB mutex while it makes this copy. The first call is the first `LogAndApply()` of the VersionSet. That call is often the MANIFEST write of `DB::Open()`. It can also be a call that writes no MANIFEST record, such as the dummy edit of `DB::SetOptions()`. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files and blob files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`; `ManifestRowsToRecords()` skips them. The comment of `ManifestCfRow::dropped` describes these rows. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first `LogAndApply()` of the VersionSet, and again after a rejected WAL edit. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top ("Background", the VersionEdit content that has no row field, "In-memory differences"), then the row structs from `ManifestDbRow` to `ManifestRows`, with the layout diagram. 2. State to rows: the `VersionSet::GetManifestRows()` declaration in `db/version_set.h`, then in `db/manifest_rows.cc` `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()`. 3. Rows to records and comparison: `ManifestRowsToRecords()` (its comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`), read next to `WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. Row changes: `ManifestRowChanges` and `ApplyManifestRowChanges()`; then `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, which holds all rules, and its code. `BaseReferencedVersionBuilder::version()` in `db/version_builder.h` is a one-line accessor for the base Version. 5. Debug check: the `debug_manifest_rows_` comment in `db/version_set.h` (timeline, phase table, threads); the three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()`; then in `db/manifest_rows.cc` `MakeManifestBatchVersions()`, `DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()` and `DebugCheckRowsAfterInstall()`. 6. Tests in `db/version_set_test.cc`: `ManifestRowFieldOfTag()` and `ManifestRowFieldOfNewFileTag()` (the checklist for new tags), then `ManifestRowsRoundTrip` and `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Differential Revision: D133208529
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes, applies them to a debug copy of the rows, and checks the result against the new Versions. A mismatch stops the process with an assert. Implementation Key choices: - The rules that turn one MANIFEST write into row changes are in the `BuildManifestRowChanges()` comment in `db/manifest_rows.h`. - The debug check runs in two phases. Phase 1 does the work that grows with the number of files, and it runs without the DB mutex, before the new Versions are installed. Phase 2 checks the values that only the installed in-memory state has (the DB row, the WAL rows, the log number, `full_history_ts_low`, the dropped flag), with the DB mutex held. With the DB mutex held, phase 2 costs a few lookups for each edit, O(live WALs) and O(levels) for an added column family. For a dropped column family, phase 1 frees its file and blob file rows from the debug copy, and phase 2 erases only its small column family row. - When the WAL set rejects a WAL edit, the MANIFEST write has happened but the write is not installed. The debug rows are then dropped and filled again from the installed state at the next write, so the check keeps comparing with what memory holds. - Some values change in memory without a MANIFEST write (for example the log number of an empty column family). The rows keep the values from the edits. The "In-memory differences" paragraph at the top of `db/manifest_rows.h` lists these values. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It holds the DB mutex while it makes this copy. The first call is the first `LogAndApply()` of the VersionSet. That call is often the MANIFEST write of `DB::Open()`. It can also be a call that writes no MANIFEST record, such as the dummy edit of `DB::SetOptions()`. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files and blob files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`; `ManifestRowsToRecords()` skips them. The comment of `ManifestCfRow::dropped` describes these rows. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first `LogAndApply()` of the VersionSet, and again after a rejected WAL edit. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top ("Background", the VersionEdit content that has no row field, "In-memory differences"), then the row structs from `ManifestDbRow` to `ManifestRows`, with the layout diagram. 2. State to rows: the `VersionSet::GetManifestRows()` declaration in `db/version_set.h`, then in `db/manifest_rows.cc` `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()`. 3. Rows to records and comparison: `ManifestRowsToRecords()` (its comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`), read next to `WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. Row changes: `ManifestRowChanges` and `ApplyManifestRowChanges()`; then `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, which holds all rules, and its code. `BaseReferencedVersionBuilder::version()` in `db/version_builder.h` is a one-line accessor for the base Version. 5. Debug check: the `debug_manifest_rows_` comment in `db/version_set.h` (timeline, phase table, threads); the three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()`; then in `db/manifest_rows.cc` `MakeManifestBatchVersions()`, `DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()` and `DebugCheckRowsAfterInstall()`. 6. Tests in `db/version_set_test.cc`: `ManifestRowFieldOfTag()` and `ManifestRowFieldOfNewFileTag()` (the checklist for new tags), then `ManifestRowsRoundTrip` and `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Differential Revision: D133208529
Claude Code Review - OBSOLETESuperseded by a newer AI review. Expand to see the original review.✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit 0943ba7 SummaryWell-structured, carefully designed addition of an internal MANIFEST row model for debug-only verification. The code is debug-only (#ifndef NDEBUG), creates no release-build impact, makes no format or public API changes, and includes thorough tests with tag checklists that force build failures when new tags are added without updating the row model. The locking protocol is correctly designed with a two-phase check that minimizes DB mutex hold time. High-severity findings (0): No high-severity findings. Full review (click to expand)Findings🔴 HIGHNone. 🟡 MEDIUMM1.
|
| Context | Affected? | Assessment |
|---|---|---|
| Release builds | NO | All new code behind #ifndef NDEBUG |
| Secondary/Follower instances | NO | Don't run ProcessManifestWrites |
| WritePreparedTxnDB | YES (debug builds) | Safe: uses same ProcessManifestWrites path |
| ReadOnly DB | NO | No MANIFEST writes |
| Recovery | YES (fill step) | Safe: fills from installed state under mutex |
| Concurrent writers | Safe | Only one PMW thread at a time; debug_manifest_rows_ is single-threaded |
| DB mutex hold time (phase 2) | Minimal | O(edits) + O(live WALs) + O(levels for CF add) |
| DB mutex hold time (fill step) | O(total files) | One-time cost, debug builds only |
Assumption stress-test:
- Claim: "Only one thread runs ProcessManifestWrites at a time" — Verified:
manifest_writers_queue serializes; only the front writer runs PMW. - Claim: "Phase 1 reads of wals_ are safe without mutex" — Verified: only PMW thread changes
wals_(and recovery, which doesn't overlap with PMW). - Claim: "FileMetaData immutable fields are safe to read without mutex" — Verified for number and level (phase 1 only reads these for shared files).
marked_for_compactioncan be changed by other threads, but phase 1 only reads it for newly added files (which are not yet shared). - Claim: "BlobFileMetaData objects are immutable" — Verified: BlobFileMetaData has deleted copy/move constructors and no mutable methods.
Positive Observations
-
Tag checklist pattern: The
ManifestRowFieldOfTag()andManifestRowFieldOfNewFileTag()functions with exhaustive switches (no default case) are an excellent pattern that forces build failures when new tags are added without updating the row model. This is a maintainability best practice. -
Two-phase debug check design: Splitting the check into phase 1 (no mutex, O(files)) and phase 2 (mutex held, O(edits)) is well-designed to minimize mutex contention in debug builds.
-
Comprehensive test coverage: The
ManifestRowsRoundTriptest covers all row fields including user-defined timestamps, path IDs, blob files, compaction cursors, dropped CFs, WALs, and OPTIONS file numbers. TheManifestRowChangesMatchVersionstest covers all MANIFEST write kinds (file add/move/compact, blob garbage, atomic groups, WAL add/delete/reject, CF add/drop, OPTIONS edits). -
Clear documentation: The header file (
manifest_rows.h) provides excellent documentation of the design, including the row layout diagram, the rules forBuildManifestRowChanges(), the in-memory differences, and the lifecycle ofdebug_manifest_rows_. -
Thread safety documentation: The
debug_manifest_rows_comment inversion_set.hexhaustively lists what phase 1 reads and why each is safe, which is valuable for future maintainers. -
WAL rejection handling: The design correctly handles the edge case where a WAL edit is rejected:
debug_manifest_rows_is reset, and the next call re-fills from the installed state. The test covers this case.
ℹ️ About this response
Generated by Claude Code.
Review methodology: claude_md/ci_review_prompt.md
Limitations:
- Claude may miss context from files not in the diff
- Large PRs may be truncated
- Always apply human judgment to AI suggestions
Commands:
/claude-review [context]— Request a code review/claude-query <question>— Ask about the PR or codebase
0e232e2 to
d53f540
Compare
meta#15734) Summary: Pull Request resolved: meta#15734 Background A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows. The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks. Previous behavior RocksDB has no row form of the MANIFEST state. New behavior No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes and applies them to a debug copy of the rows. The check then compares the number and level of every SST in each new Version, and the persisted SST fields of the files whose rows the write adds or updates. The phase table at `debug_manifest_rows_` in `db/version_set.h` lists the column family, blob file, DB and WAL checks. "In-memory differences" in `db/manifest_rows.h` lists the differences that the check allows. A mismatch stops the process with an assert. Implementation Key choices: - The rules that turn one MANIFEST write into row changes are in the `BuildManifestRowChanges()` comment in `db/manifest_rows.h`. - The debug check runs in two phases. Phase 1 does the work that grows with the number of files, and it runs without the DB mutex, before the new Versions are installed. Phase 2 checks the values that only the installed in-memory state has (the DB row, the WAL rows, the log number, `full_history_ts_low`, the dropped flag), with the DB mutex held. With the DB mutex held, phase 2 costs a few lookups for each edit, O(live WALs) and O(levels) for an added column family. For a dropped column family, phase 1 frees its file and blob file rows from the debug copy, and phase 2 erases only its small column family row. - When the WAL set rejects a WAL edit, the MANIFEST write has happened but the write is not installed. The debug rows are then dropped and filled again from the installed state at the next write, so the check keeps comparing with what memory holds. - Some values change in memory without a MANIFEST write (for example the log number of an empty column family). The rows keep the values from the edits. The "In-memory differences" paragraph at the top of `db/manifest_rows.h` lists these values. Safety No format change, no public API change and no behavior change in release builds. - `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path. - In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It holds the DB mutex while it makes this copy. The first call is the first `LogAndApply()` of the VersionSet. That call is often the MANIFEST write of `DB::Open()`. It can also be a call that writes no MANIFEST record, such as the dummy edit of `DB::SetOptions()`. - On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, O(live WALs) for the WAL rows, and O(levels) for a column family that the write adds. - Secondary and follower instances do not write the MANIFEST, so they never run the check. Known limitations: - `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given. - Rows of the files and blob files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`; `ManifestRowsToRecords()` skips them. The comment of `ManifestCfRow::dropped` describes these rows. - Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen. Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first `LogAndApply()` of the VersionSet, and again after a rejected WAL edit. How to read this diff 1. `db/manifest_rows.h`: the overview comment at the top ("Background", the VersionEdit content that has no row field, "In-memory differences"), then the row structs from `ManifestDbRow` to `ManifestRows`, with the layout diagram. 2. State to rows: the `VersionSet::GetManifestRows()` declaration in `db/version_set.h`, then in `db/manifest_rows.cc` `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()`. 3. Rows to records and comparison: `ManifestRowsToRecords()` (its comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`), read next to `WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`. 4. Row changes: `ManifestRowChanges` and `ApplyManifestRowChanges()`; then `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, which holds all rules, and its code. `BaseReferencedVersionBuilder::version()` in `db/version_builder.h` is a one-line accessor for the base Version. 5. Debug check: the `debug_manifest_rows_` comment in `db/version_set.h` (timeline, phase table, threads); the three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()`; then in `db/manifest_rows.cc` `MakeManifestBatchVersions()`, `DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()` and `DebugCheckRowsAfterInstall()`. 6. Tests in `db/version_set_test.cc`: `ManifestRowFieldOfTag()` and `ManifestRowFieldOfNewFileTag()` (the checklist for new tags), then `ManifestRowsRoundTrip` and `ManifestRowChangesMatchVersions`. The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file. Differential Revision: D133208529
Claude Code Review - OBSOLETESuperseded by a newer AI review. Expand to see the original review.✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit d53f540 SummaryWell-designed debug infrastructure for MANIFEST row model validation. The two-phase check (phase 1 without mutex for file-heavy work, phase 2 with mutex for installed state) is a sound approach that minimizes mutex hold time for routine writes while still performing comprehensive validation on every debug MANIFEST write. High-severity findings (0): No high-severity findings. Full review (click to expand)Findings🟡 MEDIUMM1. Fill step holds DB mutex while copying all file metadata —
|
| Context | Does code execute? | Assumptions hold? | Action needed? |
|---|---|---|---|
| Release builds | NO — all under #ifndef NDEBUG |
N/A | None |
| ReactiveVersionSet (secondary/follower) | NO — doesn't call ProcessManifestWrites |
N/A | None |
| ReadOnly DB | NO — no MANIFEST writes | N/A | None |
| WritePreparedTxnDB | YES — PMW is shared | YES — debug check validates metadata, not data visibility | None |
| Recovery | Partial — fill step runs on first PMW call post-recovery | YES — recovery and PMW don't overlap | None |
| DB::Close() / destructor | Safe — debug_manifest_rows_ is owned by VersionSet, destroyed when VS is destroyed |
YES — no PMW runs during destruction | None |
Concurrent SuggestCompactRange |
YES — can set marked_for_compaction on shared FileMetaData |
YES — phase 1 only reads number+level of existing files, reads all fields only for new (upserted) files that no other thread can see | None |
Thread safety verification:
SetDropped()only called from PMW (version_set.cc:6657) and recovery (version_edit_handler.cc:527). Recovery never overlaps with PMW. ✅wals_mutations only in PMW (6610, 6612),Reset()(construction), and recovery handlers. No overlap. ✅BlobFileMetaDatais non-copyable, non-movable, factory-constructed with all fields set at creation. Truly immutable. ✅- CF manipulation (add/drop) is never grouped with other writes (line 6178, 6299-6303). The assertion at line 6188 enforces this. ✅
DB Mutex analysis:
- Fill step (mutex held): O(total files) but runs only on first call (typically DB::Open) and after rare WAL rejection. Acceptable.
- Phase 1 (no mutex): O(edits + changed files + blob files + WALs). Bounded by write size. No mutex contention.
- Phase 2 (mutex held): O(edits + live WALs + levels for CF add). Typically a few lookups. Very cheap.
- No new blocking I/O, waits, or callbacks under the mutex.
Positive Observations
-
Excellent documentation: The PR has exceptionally thorough documentation — the overview comment in
manifest_rows.h, theBuildManifestRowChanges()rules, the phase table atdebug_manifest_rows_, and the "In-memory differences" section. This makes the code highly maintainable. -
Future-proof tag checklist:
ManifestRowFieldOfTag()andManifestRowFieldOfNewFileTag()use exhaustive switches with no default case, so the build fails (-Wswitch -Werror) when a new VersionEdit tag or NewFileCustomTag is added without updating the row model. This is an elegant way to prevent silent field omissions. -
Sound two-phase design: Splitting the debug check into mutex-free phase 1 (file-heavy) and mutex-held phase 2 (lightweight) demonstrates careful attention to the DB mutex as a hot lock. The cost under the mutex for routine writes is minimal.
-
Comprehensive test coverage:
ManifestRowsRoundTriptests every row field with non-default values, including edge cases like UDT timestamp stripping, path IDs, blob files with garbage, compaction cursors, and dropped column families.ManifestRowChangesMatchVersionscovers all write types including atomic groups, WAL rejection/recovery, CF add/drop, and dummy writes. -
Clean separation: The row model is completely self-contained in
manifest_rows.{h,cc}. It doesn't modify any existing data structures or code paths in release builds. The only changes to existing files are the debug hooks inProcessManifestWrites, theversion()accessor, and build file updates. -
Correct WAL rejection recovery: When
BuildManifestRowChangesencounters a WAL error, it resetsdebug_manifest_rows_to null, causing the next PMW call to refill from the installed state. This correctly handles the case where the MANIFEST write succeeded but the in-memory WAL state is inconsistent.
ℹ️ About this response
Generated by Claude Code.
Review methodology: claude_md/ci_review_prompt.md
Limitations:
- Claude may miss context from files not in the diff
- Large PRs may be truncated
- Always apply human judgment to AI suggestions
Commands:
/claude-review [context]— Request a code review/claude-query <question>— Ask about the PR or codebase
Summary:
Background
A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in `VersionSet::ProcessManifestWrites()`) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows.
The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks.
Previous behavior
RocksDB has no row form of the MANIFEST state.
New behavior
No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes and applies them to a debug copy of the rows. The check then compares the number and level of every SST in each new Version, and the persisted SST fields of the files whose rows the write adds or updates. The phase table at `debug_manifest_rows_` in `db/version_set.h` lists the column family, blob file, DB and WAL checks. "In-memory differences" in `db/manifest_rows.h` lists the differences that the check allows. A mismatch stops the process with an assert.
Implementation
Key choices:
- The rules that turn one MANIFEST write into row changes are in the `BuildManifestRowChanges()` comment in `db/manifest_rows.h`.
- The debug check runs in two phases. Phase 1 does the work that grows with the number of files, and it runs without the DB mutex, before the new Versions are installed. Phase 2 checks the values that only the installed in-memory state has (the DB row, the WAL rows, the log number, `full_history_ts_low`, the dropped flag), with the DB mutex held. With the DB mutex held, phase 2 costs a few lookups for each edit, a compare of the WAL rows with the live WAL set in place (O(live WALs), with no copy), and O(levels) for an added column family. For a dropped column family, phase 1 frees its file and blob file rows from the debug copy, and phase 2 erases only its small column family row.
- When the WAL set rejects a WAL edit, the MANIFEST write has happened but the write is not installed. The debug rows are then dropped and filled again from the installed state at the next write, so the check keeps comparing with what memory holds.
- Some values change in memory without a MANIFEST write (for example the log number of an empty column family). The rows keep the values from the edits. The "In-memory differences" paragraph at the top of `db/manifest_rows.h` lists these values.
Safety
No format change, no public API change and no behavior change in release builds.
- `VersionSet::GetManifestRows()` requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path.
- In debug builds, `ProcessManifestWrites()` copies the metadata of every live file into `debug_manifest_rows_` on its first call in a VersionSet and on its first call after a rejected WAL edit. It holds the DB mutex while it makes this copy. The cost of this copy was not measured. The first call is the first `LogAndApply()` of the VersionSet. That call is often the MANIFEST write of `DB::Open()`. It can also be a call that writes no MANIFEST record, such as the dummy edit of `DB::SetOptions()`.
- On each later write, the work that grows with the number of files runs without the DB mutex, and reads only file fields that no other thread changes. With the DB mutex held, the check costs a few lookups for each edit, an in-place compare of the WAL rows (O(live WALs), with no copy), and O(levels) for a column family that the write adds.
- Secondary and follower instances do not write the MANIFEST, so they never run the check.
Known limitations:
- `VersionSet::GetManifestRows()` never produces rows of dropped column families; `ManifestRowsToRecords()` skips such rows when they are given.
- Rows of the files and blob files of a dropped column family stay in the rows after `ApplyManifestRowChanges()`; `ManifestRowsToRecords()` skips them. The comment of `ManifestCfRow::dropped` describes these rows.
- Recovery from the records of `ManifestRowsToRecords()` sets the next file number to the recorded value plus one, as after every reopen.
Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first `LogAndApply()` of the VersionSet, and again after a rejected WAL edit.
How to read this diff
1. `db/manifest_rows.h`: the overview comment at the top ("Background", the VersionEdit content that has no row field, "In-memory differences"), then the row structs from `ManifestDbRow` to `ManifestRows`, with the layout diagram.
2. State to rows: the `VersionSet::GetManifestRows()` declaration in `db/version_set.h`, then in `db/manifest_rows.cc` `MakeManifestCfRow()`, `MakeBlobFileRow()`, `MakeFileRow()`, `SetManifestCfRows()` and `VersionSet::GetManifestRows()`.
3. Rows to records and comparison: `ManifestRowsToRecords()` (its comment gives the record order and the differences from `VersionSet::WriteCurrentStateToManifest()`), read next to `WriteCurrentStateToManifest()` in `db/version_set.cc`; then `SameCfRow()`, `SameFileRow()` and `ManifestRowsEqual()`.
4. Row changes: `ManifestRowChanges` and `ApplyManifestRowChanges()`; then `ManifestBatchVersion` and the `BuildManifestRowChanges()` comment, which holds all rules, and its code. `BaseReferencedVersionBuilder::version()` in `db/version_builder.h` is a one-line accessor for the base Version.
5. Debug check: the `debug_manifest_rows_` comment in `db/version_set.h` (timeline, phase table, threads); the three `#ifndef NDEBUG` hooks in `VersionSet::ProcessManifestWrites()`; then in `db/manifest_rows.cc` `MakeManifestBatchVersions()`, `DebugCheckRowsBeforeInstall()`, `AssertCfRowsMatchVersion()` and `DebugCheckRowsAfterInstall()`.
6. Tests in `db/version_set_test.cc`: `ManifestRowFieldOfTag()` and `ManifestRowFieldOfNewFileTag()` (the checklist for new tags), then `ManifestRowsRoundTrip` and `ManifestRowChangesMatchVersions`.
The build files (`src.mk`, `CMakeLists.txt`, `BUCK`) only add the new source file.
Differential Revision: D133208529
✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit 76193e8 SummaryWell-designed debug-only infrastructure for verifying MANIFEST row changes against installed Versions. The code is carefully structured with a two-phase check that minimizes DB mutex hold time, thorough documentation of thread safety invariants, and comprehensive tests. No high-severity issues found. High-severity findings (0): Full review (click to expand)Findings🟡 MEDIUMM1. Fill step runs under DB mutex for
|
| Context | Affected? | Safe? | Reason |
|---|---|---|---|
| WritePreparedTxnDB | Yes (debug) | Yes | Checks MANIFEST rows, not memtable visibility |
| ReadOnly/Secondary | No | N/A | No MANIFEST writes |
| User-defined timestamps | Yes | Yes | Tested in ManifestRowsRoundTrip with UDT CF |
| BlobDB | Yes | Yes | Blob file rows tracked and tested |
| Concurrent writers | Yes | Yes | Only one PMW thread; documented thread safety |
| skip_manifest_write | Partial | Yes | Fill step runs; no check runs (M1 above) |
Positive Observations
- Excellent documentation: The
debug_manifest_rows_comment inversion_set.h(lifecycle, phases, thread safety, what each phase checks) is exemplary. - Two-phase design: O(files) work without mutex, O(edits + WALs) with mutex -- minimizes debug impact on contention.
- Tag checklist tests: No-default switches in
ManifestRowFieldOfTag/ManifestRowFieldOfNewFileTagforce updating the row model when new tags are added -- excellent maintenance pattern. - Comprehensive round-trip test: Every field set to non-default, with UDT timestamp removal exercised.
- Zero release-build cost: Everything inside
#ifndef NDEBUG.
ℹ️ About this response
Generated by Claude Code.
Review methodology: claude_md/ci_review_prompt.md
Limitations:
- Claude may miss context from files not in the diff
- Large PRs may be truncated
- Always apply human judgment to AI suggestions
Commands:
/claude-review [context]— Request a code review/claude-query <question>— Ask about the PR or codebase
Summary:
Background
A planned feature stores the DB metadata (the MANIFEST content) as structured rows in an external metadata store, instead of as a log of VersionEdit records in a file. Each row holds the resulting values of one object: the DB, a column family, an SST file, a blob file or a WAL. A reader gets the whole state by reading all rows, with no history. To keep such rows up to date, each MANIFEST write (one batch of VersionEdits in
VersionSet::ProcessManifestWrites()) must be turned into the rows it changes. This diff adds the in-memory row model, the conversions between rows and the existing VersionSet and VersionEdit code, and the row changes of each MANIFEST write. In debug builds it checks the row changes of every installed MANIFEST write against the Versions that the write installs. Only tests and this debug check use the rows.The external store is not in this diff. This diff lands the row model and the conversion rules first, so that every debug test and debug crash test checks the rules on each MANIFEST write. When the store is added, it reuses these functions and their checks.
Previous behavior
RocksDB has no row form of the MANIFEST state.
New behavior
No change in release builds. In debug builds, every MANIFEST write that is installed also builds its row changes and applies them to a debug copy of the rows. The check then compares the number and level of every SST in each new Version, and the persisted SST fields of the files whose rows the write adds or updates. The phase table at
debug_manifest_rows_indb/version_set.hlists the column family, blob file, DB and WAL checks. "In-memory differences" indb/manifest_rows.hlists the differences that the check allows. A mismatch stops the process with an assert.Implementation
Key choices:
BuildManifestRowChanges()comment indb/manifest_rows.h.full_history_ts_low, the dropped flag), with the DB mutex held. With the DB mutex held, phase 2 costs a few lookups for each edit, a compare of the WAL rows with the live WAL set in place (O(live WALs), with no copy), and O(levels) for an added column family. For a dropped column family, phase 1 frees its file and blob file rows from the debug copy, and phase 2 erases only its small column family row.db/manifest_rows.hlists these values.Safety
No format change, no public API change and no behavior change in release builds.
VersionSet::GetManifestRows()requires the caller to hold the DB mutex, and it copies the metadata of every live file while the mutex is held, so the function is meant for tests, debug checks and tools, not for the write path.ProcessManifestWrites()copies the metadata of every live file intodebug_manifest_rows_on its first call in a VersionSet and on its first call after a rejected WAL edit. It holds the DB mutex while it makes this copy. The cost of this copy was not measured. The first call is the firstLogAndApply()of the VersionSet. That call is often the MANIFEST write ofDB::Open(). It can also be a call that writes no MANIFEST record, such as the dummy edit ofDB::SetOptions().Known limitations:
VersionSet::GetManifestRows()never produces rows of dropped column families;ManifestRowsToRecords()skips such rows when they are given.ApplyManifestRowChanges();ManifestRowsToRecords()skips them. The comment ofManifestCfRow::droppeddescribes these rows.ManifestRowsToRecords()sets the next file number to the recorded value plus one, as after every reopen.Changes visible to existing users: none in release builds. Debug builds do more work per MANIFEST write and stop with an assert when the row changes do not match. Debug builds also keep a copy of the metadata of all live files in memory. The copy is made under the DB mutex on the first
LogAndApply()of the VersionSet, and again after a rejected WAL edit.How to read this diff
db/manifest_rows.h: the overview comment at the top ("Background", the VersionEdit content that has no row field, "In-memory differences"), then the row structs fromManifestDbRowtoManifestRows, with the layout diagram.VersionSet::GetManifestRows()declaration indb/version_set.h, then indb/manifest_rows.ccMakeManifestCfRow(),MakeBlobFileRow(),MakeFileRow(),SetManifestCfRows()andVersionSet::GetManifestRows().ManifestRowsToRecords()(its comment gives the record order and the differences fromVersionSet::WriteCurrentStateToManifest()), read next toWriteCurrentStateToManifest()indb/version_set.cc; thenSameCfRow(),SameFileRow()andManifestRowsEqual().ManifestRowChangesandApplyManifestRowChanges(); thenManifestBatchVersionand theBuildManifestRowChanges()comment, which holds all rules, and its code.BaseReferencedVersionBuilder::version()indb/version_builder.his a one-line accessor for the base Version.debug_manifest_rows_comment indb/version_set.h(timeline, phase table, threads); the three#ifndef NDEBUGhooks inVersionSet::ProcessManifestWrites(); then indb/manifest_rows.ccMakeManifestBatchVersions(),DebugCheckRowsBeforeInstall(),AssertCfRowsMatchVersion()andDebugCheckRowsAfterInstall().db/version_set_test.cc:ManifestRowFieldOfTag()andManifestRowFieldOfNewFileTag()(the checklist for new tags), thenManifestRowsRoundTripandManifestRowChangesMatchVersions.The build files (
src.mk,CMakeLists.txt,BUCK) only add the new source file.Differential Revision: D133208529