Repository navigation
Add WAL index stripping and verification to log::Reader (#15222) - #15222
JustinGaoF wants to merge 4 commits into
Conversation
d53ec3e to
16553a2
Compare
16553a2 to
f7ecf30
Compare
|
@JustinGaoF has exported this pull request. If you are a Meta employee, you can view the originating Diff in D118369608. |
Summary: Pull Request resolved: meta#15222 Teaches `log::Reader` and `FragmentBufferedReader` to decode WAL index records. `MaybeStripAndVerifyWALIndex` extracts the leading fixed64 into `last_read_wal_index_`, strips it from the record, and recomputes the logical-record checksum over the stripped payload so upper layers see the same bytes and checksum they would without indexing. It reports corruption if a record's type claims an index but the payload is too short to hold one, and clears the index for records that carry none, so `GetLastReadWALIndex()` always describes the record just returned. **There is no gap or continuity checking here, deliberately.** wal_index is consecutive across the WAL partition as a whole, not within any single file, so a jump between successive records in one file is normal. Treating it as a gap would be a false positive, and the response to a detected gap is truncation — so the detector is left out until the sequence-to-index correlation it would depend on is resolved. Decoding is driven purely by the record type at all eight dispatch sites in both readers, so a file may hold indexed and plain records and each is handled on its own terms. The marker record is not required to decode anything; it is only checked for position, reporting corruption if it appears after a data record, matching how `kSetCompressionType` is handled. `ReadPhysicalRecord` selects header size via `IsRecyclableRecordType`, and `FragmentBufferedReader` tracks whether the in-progress fragmented record is indexed so mismatched fragment types are reported. Exposes one accessor, `GetLastReadWALIndex()`. Per-record state, zero when the record carried no index. Differential Revision: D118369608
f7ecf30 to
51c3b5d
Compare
✅ clang-tidy: No findings on changed linesCompleted in 510.9s. |
Summary: Teaches `log::Reader` and `FragmentBufferedReader` to decode WAL index records. `MaybeStripAndVerifyWALIndex` extracts the leading fixed64 into `last_read_wal_index_`, strips it from the record, and recomputes the logical-record checksum over the stripped payload so upper layers see the same bytes and checksum they would without indexing. It reports corruption if a record's type claims an index but the payload is too short to hold one, and clears the index for records that carry none, so `GetLastReadWALIndex()` always describes the record just returned. **There is no gap or continuity checking here, deliberately.** wal_index is consecutive across the WAL partition as a whole, not within any single file, so a jump between successive records in one file is normal. Treating it as a gap would be a false positive, and the response to a detected gap is truncation — so the detector is left out until the sequence-to-index correlation it would depend on is resolved. Decoding is driven purely by the record type at all eight dispatch sites in both readers, so a file may hold indexed and plain records and each is handled on its own terms. The marker record is not required to decode anything; it is only checked for position, reporting corruption if it appears after a data record, matching how `kSetCompressionType` is handled. `ReadPhysicalRecord` selects header size via `IsRecyclableRecordType`, and `FragmentBufferedReader` tracks whether the in-progress fragmented record is indexed so mismatched fragment types are reported. Exposes one accessor, `GetLastReadWALIndex()`. Per-record state, zero when the record carried no index. Differential Revision: D118369608
51c3b5d to
33eb2e7
Compare
Summary: Teaches `log::Reader` and `FragmentBufferedReader` to decode WAL index records. `MaybeStripAndVerifyWALIndex` extracts the leading fixed64 into `last_read_wal_index_`, strips it from the record, and recomputes the logical-record checksum over the stripped payload so upper layers see the same bytes and checksum they would without indexing. It reports corruption if a record's type claims an index but the payload is too short to hold one, and clears the index for records that carry none, so `GetLastReadWALIndex()` always describes the record just returned. **There is no gap or continuity checking here, deliberately.** wal_index is consecutive across the WAL partition as a whole, not within any single file, so a jump between successive records in one file is normal. Treating it as a gap would be a false positive, and the response to a detected gap is truncation — so the detector is left out until the sequence-to-index correlation it would depend on is resolved. Decoding is driven purely by the record type at all eight dispatch sites in both readers, so a file may hold indexed and plain records and each is handled on its own terms. The marker record is not required to decode anything; it is only checked for position, reporting corruption if it appears after a data record, matching how `kSetCompressionType` is handled. `ReadPhysicalRecord` selects header size via `IsRecyclableRecordType`, and `FragmentBufferedReader` tracks whether the in-progress fragmented record is indexed so mismatched fragment types are reported. Exposes one accessor, `GetLastReadWALIndex()`. Per-record state, zero when the record carried no index. Differential Revision: D118369608
33eb2e7 to
14bf790
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 14bf790 SummaryWell-structured, carefully implemented addition of WAL index support to log::Reader and log::Writer. The on-disk format change is designed for safe downgrade (indexed types fail-closed on older readers). The code correctly handles fragmentation, compression, checksums, mixed indexed/plain records, and both Reader and FragmentBufferedReader. One high-severity finding (defaulted parameter violates CLAUDE.md policy), one medium-severity finding, and several low-severity items. High-severity findings (1):
Full review (click to expand)Findings🔴 HIGHH1. New defaulted parameter on
|
| Context | Executes? | Assumptions hold? | Action needed? |
|---|---|---|---|
| WritePreparedTxnDB | No new interaction | N/A | Safe |
| ReadOnly DB | Reader-only | YES | Safe |
| WAL compression | Writer merges index before compress; reader decompresses before strip | YES | Safe |
| Recycled WAL files | All WAL index types have recyclable variants | YES | Safe |
| User-defined timestamps | Coexists; both are metadata records | YES | Safe |
| Old RocksDB readers | static_assert ensures types < 128 (fail-closed) | YES | Safe |
Positive Observations
-
Excellent downgrade safety: static_asserts ensure WAL index types stay below the safe-ignore mask. The constexpr
HeaderSelectionUnchangedForPreWALIndexTypestest catches backward compatibility regressions at compile time. -
Thorough test coverage: 20+ new test cases covering round-trip, byte layout, boundary conditions (index straddling block boundary), fragmentation, large values, cross-file indices, marker validation, corruption detection, and mixed record types. Tests are well-structured and parameterized across recyclable/non-recyclable modes.
-
Clean refactoring:
IsRecyclableRecordType()andIsWALIndexRecordType()helpers consolidate previously scattered inline checks, reducing duplication in both readers. -
Correct CRC computation: The
Crc32cCombine-based approach inEmitPhysicalRecordcorrectly handles the split prefix+payload without unnecessary copies, with a proper null-pointer guard for empty payloads. -
Exhaustive switch in
WALIndexEnabled(): Nodefaultcase means adding a newPartitionWALUsageenum value forces explicit classification at compile time. -
Well-documented TODO: The burned-index TODO clearly identifies the gap where a failed write after index allocation loses the index, and outlines solutions.
ℹ️ 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: Teaches `log::Reader` and `FragmentBufferedReader` to decode WAL index records. `MaybeStripAndVerifyWALIndex` extracts the leading fixed64 into `last_read_wal_index_`, strips it from the record, and recomputes the logical-record checksum over the stripped payload so upper layers see the same bytes and checksum they would without indexing. It reports corruption if a record's type claims an index but the payload is too short to hold one, and clears the index for records that carry none, so `GetLastReadWALIndex()` always describes the record just returned. **There is no gap or continuity checking here, deliberately.** wal_index is consecutive across the WAL partition as a whole, not within any single file, so a jump between successive records in one file is normal. Treating it as a gap would be a false positive, and the response to a detected gap is truncation — so the detector is left out until the sequence-to-index correlation it would depend on is resolved. Decoding is driven purely by the record type at all eight dispatch sites in both readers, so a file may hold indexed and plain records and each is handled on its own terms. The marker record is not required to decode anything; it is only checked for position, reporting corruption if it appears after a data record, matching how `kSetCompressionType` is handled. `ReadPhysicalRecord` selects header size via `IsRecyclableRecordType`, and `FragmentBufferedReader` tracks whether the in-progress fragmented record is indexed so mismatched fragment types are reported. Exposes one accessor, `GetLastReadWALIndex()`. Per-record state, zero when the record carried no index. Differential Revision: D118369608
14bf790 to
3331875
Compare
Summary: Teaches `log::Reader` and `FragmentBufferedReader` to decode WAL index records. `MaybeStripAndVerifyWALIndex` extracts the leading fixed64 into `last_read_wal_index_`, strips it from the record, and recomputes the logical-record checksum over the stripped payload so upper layers see the same bytes and checksum they would without indexing. It reports corruption if a record's type claims an index but the payload is too short to hold one, and clears the index for records that carry none, so `GetLastReadWALIndex()` always describes the record just returned. **There is no gap or continuity checking here, deliberately.** wal_index is consecutive across the WAL partition as a whole, not within any single file, so a jump between successive records in one file is normal. Treating it as a gap would be a false positive, and the response to a detected gap is truncation — so the detector is left out until the sequence-to-index correlation it would depend on is resolved. Decoding is driven purely by the record type at all eight dispatch sites in both readers, so a file may hold indexed and plain records and each is handled on its own terms. The marker record is not required to decode anything; it is only checked for position, reporting corruption if it appears after a data record, matching how `kSetCompressionType` is handled. `ReadPhysicalRecord` selects header size via `IsRecyclableRecordType`, and `FragmentBufferedReader` tracks whether the in-progress fragmented record is indexed so mismatched fragment types are reported. Exposes one accessor, `GetLastReadWALIndex()`. Per-record state, zero when the record carried no index. Differential Revision: D118369608
Summary: Pull Request resolved: meta#15222 Teaches `log::Reader` and `FragmentBufferedReader` to decode WAL index records. `MaybeStripAndVerifyWALIndex` extracts the leading fixed64 into `last_read_wal_index_`, strips it from the record, and recomputes the logical-record checksum over the stripped payload so upper layers see the same bytes and checksum they would without indexing. It reports corruption if a record's type claims an index but the payload is too short to hold one, and clears the index for records that carry none, so `GetLastReadWALIndex()` always describes the record just returned. **There is no gap or continuity checking here, deliberately.** wal_index is consecutive across the WAL partition as a whole, not within any single file, so a jump between successive records in one file is normal. Treating it as a gap would be a false positive, and the response to a detected gap is truncation — so the detector is left out until the sequence-to-index correlation it would depend on is resolved. Decoding is driven purely by the record type at all eight dispatch sites in both readers, so a file may hold indexed and plain records and each is handled on its own terms. The marker record is not required to decode anything; it is only checked for position, reporting corruption if it appears after a data record, matching how `kSetCompressionType` is handled. `ReadPhysicalRecord` selects header size via `IsRecyclableRecordType`, and `FragmentBufferedReader` tracks whether the in-progress fragmented record is indexed so mismatched fragment types are reported. Exposes one accessor, `GetLastReadWALIndex()`. Per-record state, zero when the record carried no index. Differential Revision: D118369608
3331875 to
3d6870d
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 3d6870d SummaryWell-structured PR that adds WAL index (LSN) stripping and verification to High-severity findings (2):
Full review (click to expand)Findings🔴 HIGHH1. Missing
|
| Context | Executes? | Assumptions hold? | Action needed? |
|---|---|---|---|
| WritePreparedTxnDB | Not yet (no DB integration) | N/A | Safe |
| ReadOnly DB | Reader decodes during recovery | YES | None |
| WAL compression | Writer prepends index before compress; reader strips after decompress | YES but untested (M1) | Add test |
| Recycled logs | Recyclable WAL index types exist; IsRecyclableRecordType updated |
YES | None |
| Downgrade | WAL index types < safe-ignore bit → older binary reports corruption | YES — correct fail-closed | None |
| User-defined timestamps | Independent metadata; no interaction | YES | None |
Positive Observations
- The
IsRecyclableRecordType()refactoring eliminates 3 duplicated inline checks. TheHeaderSelectionUnchangedForPreWALIndexTypescompile-time test is an excellent regression guard. - Static asserts ensuring WAL index types stay below
kRecordTypeSafeIgnoreMaskprovide strong downgrade safety. - Self-describing fragment design is robust against partial writes and mixed files.
- The
TODOabout burned WAL index values on write failure is honest and well-placed. - The
WALIndexEnabled()allowlist switch with nodefaultforces compile-time review of new enum values. - CRC computation in
EmitPhysicalRecordusingCrc32cCombinefor the prefix+payload is mathematically correct and avoids an extra memory copy.
ℹ️ 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: Pull Request resolved: meta#15219 Defines the `PartitionWALUsage` enum and plumbs `DBOptions::partition_wal_usage` through the options machinery. This is the API surface for per-record WAL ordering numbers; no WAL format code and no on-disk change yet. The enum has three values. Every value other than `kNone` prefixes each WAL record with a persisted monotonically increasing ordering number, so they share one on-disk format change and differ only in WAL layout: - `kNone` (0x00) -- disabled, WAL stays bit-for-bit compatible with older versions. - `kRecordOrderingSingleFile` (0x01) -- records carry an ordering number, WAL layout unchanged. Isolates the format change from any routing change so the two roll out separately. - `kPartitionByColumnFamily` (0x02) -- reserved for partitioning WALs by column family. Not implemented, and `DBImpl::ValidateOptions` now rejects it with `NotSupported` **in this diff** rather than in a later one, so no revision of the tree ever accepts an option value it cannot honor. Without that, the value would be accepted and inert here, and once the writer diffs land it would silently mean "ordering numbers, no partitioning". Why three values rather than a boolean: they are a rollout ladder, not a taxonomy. `kRecordOrderingSingleFile` exists to be the middle rung -- it turns on the persisted on-disk format change while leaving WAL routing untouched, so the format can bake in production before any routing behavior changes. A boolean cannot express that: "partitioned or not" forces the format change and the routing change to ship as one flip, which is precisely the rollout risk the middle rung removes. `kPartitionByColumnFamily` is the top rung, and rejecting it until it works keeps the ladder from ever exposing a rung that is accepted but inert. The value names describe observable behavior rather than the mechanism: `wal_index` stays the internal term for the ordering number, in implementation code and in the WAL record format, but it no longer appears in the public enum. Nothing has shipped, so there are no compatibility aliases for the previous spellings (`kWALIndexSingleFile`, `kWALIndexPartitionByColumnFamily`). Documentation: the `partition_wal_usage` field comment and the `PartitionWALUsage` enum contract disagreed -- the field comment said a non-`kNone` value also tags the WAL file with an identifying marker record, which the enum's own documentation never mentioned. The on-disk contract now lives in one place, the enum header comment, and the field comment points at it instead of restating it. Wiring: the field on `DBOptions` (default `kNone`) and `ImmutableDBOptions`, propagation in `BuildDBOptions`, registration via `OptionTypeInfo::Enum` against `GetPartitionWALUsageStringMap()`, the copy constructor, and `ROCKS_LOG_HEADER`. The string map accepts six keys -- a `kFoo` and a `snake_case` spelling for each of the three values -- so OPTIONS files and the tooling flags all parse through one table. `BuildDBOptions` propagation is easy to miss: `partition_wal_usage` lives only in `ImmutableDBOptions`, and `options_settable_test`, which would otherwise catch a missing assignment, is compiled out under clang. Differential Revision: D118367634
Summary: Pull Request resolved: meta#15220 Adds the WAL index record types to the log format. Header-only; no writer, reader or on-disk change yet. Marker types `kWALIndexMarkerType` (12) and `kRecyclableWALIndexMarkerType` (13) tag a file as carrying per-record ordering numbers. Indexed data record types `kWALIndexFullType`..`kRecyclableWALIndexLastType` (14-21) mirror the existing full/first/middle/last set, with a recyclable twin for each, so every existing record shape has an indexed counterpart. Each fragment is self-describing: the marker is not required to decode a record, and the marker itself carries no payload. Also adds `IsWALIndexRecordType`, extends `IsRecyclableRecordType` to cover the new recyclable types, and defines `kWALIndexSize = 8` for the fixed64 prefix. All new types stay below `kRecordTypeSafeIgnoreMask`, which is what makes indexed WALs fail closed: an older binary must reject an indexed record rather than silently ignore it and report success. A `static_assert` naming all ten WAL index types enforces that, so renumbering any of them into the ignorable range breaks the build instead of turning into silent data loss. Differential Revision: D118369740
Summary: Pull Request resolved: meta#15221 Teaches `log::Writer` to emit WAL index records. The writer does not allocate the index — it receives one from the caller and encodes it. Allocation lands in a later diff, where the sequence number is also assigned. `SetPartitionWALUsage` turns indexing on for a writer; `WALIndexEnabled` reports it. `MaybeAddWALIndexMarkerRecord` emits the leading marker. The marker carries **no payload** — the record type alone identifies the file, and its value is positional: it is the first record, so an older binary fails on record #1 rather than partway through replay. `AddRecord` takes the assigned `wal_index`, encodes it as a fixed64 ahead of the record, and picks the matching indexed record type via `SelectRecordType`. Because the index counts as part of the record's payload for checksum and fragmentation, it survives both. Debug asserts enforce that indices are strictly increasing and sequence numbers non-decreasing per writer; a zero index with indexing enabled is rejected outright. The uncompressed path passes the index to `EmitPhysicalRecord` as a **separate 8-byte prefix**, so the caller's payload is never copied. Compression still requires one contiguous input, so that path keeps the joined buffer. `wal_compression` defaults to `kNoCompression`, so the common path avoids the allocation and the full write-batch copy. On-disk bytes, record boundaries and checksums are identical either way. `EmitPhysicalRecord` now selects the header size via `IsRecyclableRecordType` rather than a hand-maintained whitelist. With indexing disabled the output is byte-identical to before, and a `static_assert` in the tests pins that by checking the new predicate agrees with the old whitelist on every pre-existing record type. One hazard is documented rather than fixed: a failed append burns an allocated index. Harmless until a completeness check exists; the `TODO` names the two remedies. Measured on the no-copy path, with the full stack applied so `db_bench` can drive it — `--benchmarks=fillseq --partition_wal_usage=wal_index_single_file --wal_compression=none --compression_type=none --disable_auto_compactions=true --threads=1`, medians of 3 runs on one AMD EPYC-Genoa host, ~512 MiB written per run: | Value size | Entries | Copying prefix | Separate prefix | Latency change | | 64 KiB | 8,192 | 224.908 us/op, 4,445 ops/s | 215.764 us/op, 4,628 ops/s | -4.1% | | 1 MiB | 512 | 2,813.432 us/op, 355 ops/s | 2,373.035 us/op, 421 ops/s | -15.7% | Differential Revision: D118369607
3d6870d to
09f5958
Compare
Summary: Teaches `log::Reader` and `FragmentBufferedReader` to decode WAL index records. `MaybeStripAndVerifyWALIndex` extracts the leading fixed64 into `last_read_wal_index_`, strips it from the record, and recomputes the logical-record checksum over the stripped payload so upper layers see the same bytes and checksum they would without indexing. It reports corruption if a record's type claims an index but the payload is too short to hold one, and clears the index for records that carry none, so `GetLastReadWALIndex()` always describes the record just returned. **There is no gap or continuity checking here, deliberately.** wal_index is consecutive across the WAL partition as a whole, not within any single file, so a jump between successive records in one file is normal. Treating it as a gap would be a false positive, and the response to a detected gap is truncation — so the detector is left out until the sequence-to-index correlation it would depend on is resolved. Decoding is driven purely by the record type at all eight dispatch sites in both readers, so a file may hold indexed and plain records and each is handled on its own terms. The marker record is not required to decode anything; it is only checked for position, reporting corruption if it appears after a data record, matching how `kSetCompressionType` is handled. `ReadPhysicalRecord` selects header size via `IsRecyclableRecordType`, and `FragmentBufferedReader` tracks whether the in-progress fragmented record is indexed so mismatched fragment types are reported. Exposes one accessor, `GetLastReadWALIndex()`. Per-record state, zero when the record carried no index. Differential Revision: D118369608
Claude Code Review - OBSOLETESuperseded by a newer AI review. Expand to see the original review.✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit 09f5958 SummaryThis PR adds WAL index record types and reader/writer support for stripping and verifying per-record ordering numbers. The design is well-structured with proper downgrade safety, comprehensive tests, and a clean separation of reader-side decoding from future DB-level integration. The CRC computation for the prefix+payload split is correct, fragmented record handling is consistent across both Reader and FragmentBufferedReader, and the High-severity findings (1):
Full review (click to expand)Findings🔴 HIGHH1. New defaulted parameter on
|
| Context | Affected? | Analysis |
|---|---|---|
| WritePreparedTxnDB | No | WAL index is writer/reader infrastructure only; no DB integration yet |
| ReadOnly DB | No | Reader changes are passive (new record types in dispatch) |
| WAL Recovery | Partially | ReadRecord now handles new types; all recovery modes pass through the same dispatch. Marker-after-data corruption respects existing mode handling. |
| Compressed WAL | Yes | Compression path correctly builds indexed_payload with prefix before compression. Reader decompresses first, then strips. Verified correct. |
| Recycled WAL | Yes | IsRecyclableRecordType correctly includes new recyclable WAL index types. Verified by static_assert(HeaderSelectionUnchangedForPreWALIndexTypes()). |
| User-defined timestamps | No | UDT records are orthogonal; no interaction. |
Positive Observations
- Downgrade safety: The
static_assertensuring WAL index types stay belowkRecordTypeSafeIgnoreMaskis excellent -- old readers reject indexed WALs rather than silently misreading them. - Self-describing format: Each physical fragment carries its own type, so the marker is not required for correct decoding. Robust design.
- Compile-time backward compat verification:
HeaderSelectionUnchangedForPreWALIndexTypes()is aconstexprfunction withstatic_assertproving theIsRecyclableRecordTyperefactoring preserves header selection for all pre-WAL-index types. Defensive engineering at its best. WALIndexEnabled()as allowlist with exhaustive switch: Adding a newPartitionWALUsagevalue forces a build failure. Prevents accidental opt-in.- Consistent dual-reader handling: Both
ReaderandFragmentBufferedReaderhandle the new types with parallel structure, including marker interruption and fragment consistency checks. - Comprehensive test coverage: 20+ new test cases covering round-trip, byte layout, fragmentation, block boundary straddling, large values, mixed records, corruption detection, non-consecutive indices, cross-writer interleaving, and marker positioning. Well-structured.
- TODO for burned index: The
db/log_writer.cccomment acknowledging the burned-index problem (index allocated but write fails) shows production awareness with appropriate deferral.
ℹ️ 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
09f5958 to
19119ea
Compare
Summary: Teaches `log::Reader` and `FragmentBufferedReader` to decode WAL index records. `MaybeStripAndVerifyWALIndex` extracts the leading fixed64 into `last_read_wal_index_`, strips it from the record, and recomputes the logical-record checksum over the stripped payload so upper layers see the same bytes and checksum they would without indexing. It reports corruption if a record's type claims an index but the payload is too short to hold one, and clears the index for records that carry none, so `GetLastReadWALIndex()` always describes the record just returned. **There is no gap or continuity checking here, deliberately.** wal_index is consecutive across the WAL partition as a whole, not within any single file, so a jump between successive records in one file is normal. Treating it as a gap would be a false positive, and the response to a detected gap is truncation — so the detector is left out until the sequence-to-index correlation it would depend on is resolved. Decoding is driven purely by the record type at all eight dispatch sites in both readers, so a file may hold indexed and plain records and each is handled on its own terms. The marker record is not required to decode anything; it is only checked for position, reporting corruption if it appears after a data record, matching how `kSetCompressionType` is handled. `ReadPhysicalRecord` selects header size via `IsRecyclableRecordType`, and `FragmentBufferedReader` tracks whether the in-progress fragmented record is indexed so mismatched fragment types are reported. Exposes one accessor, `GetLastReadWALIndex()`. Per-record state, zero when the record carried no index. Differential Revision: D118369608
Claude Code Review - OBSOLETESuperseded by a newer AI review. Expand to see the original review.✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit 19119ea SummaryWell-structured PR that lays clean groundwork for WAL indexing in High-severity findings (1):
Full review (click to expand)Findings🔴 HIGHH1. New defaulted parameter on
|
| Context | Executes? | Assumptions hold? | Notes |
|---|---|---|---|
| WritePreparedTxnDB | Not yet (no DB integration) | N/A | DB-level code doesn't call SetPartitionWALUsage yet |
| ReadOnly DB | Reader only | Yes | Reader handles new types correctly |
| WAL compression | Yes (writer path) | Needs testing (M2) | Compressed+indexed path builds contiguous buffer |
| Recycled logs | Yes | Yes | Both recyclable and non-recyclable variants exist |
| WAL recovery modes | Yes | Yes | Marker corruption respects existing patterns |
| User-defined timestamps | Yes | Yes | Independent record types, no interaction |
| Downgrade to older binary | Yes | Safe | Types < 128 cause corruption report (desired) |
Positive Observations
- The
static_assertensuring all WAL index types are belowkRecordTypeSafeIgnoreMaskis excellent downgrade safety. - The
HeaderSelectionUnchangedForPreWALIndexTypesconstexpr validation prevents regressions cleverly. - The
IsRecyclableRecordType()consolidation removes duplicated logic from 4 sites. - The
WALIndexEnabled()allowlist pattern (switch without default) forces build failures on new enum values. - Comprehensive test coverage: 20+ tests covering round-trip, layout, corruption, fragmentation, cross-writer, and mixed record types.
- The TODO about burned indices honestly acknowledges a known gap.
- The marker record design mirrors
kSetCompressionTypehandling, maintaining consistency.
ℹ️ 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
19119ea to
2168cd3
Compare
Summary: Teaches `log::Reader` and `FragmentBufferedReader` to decode WAL index records. `MaybeStripAndVerifyWALIndex` extracts the leading fixed64 into `last_read_wal_index_`, strips it from the record, and recomputes the logical-record checksum over the stripped payload so upper layers see the same bytes and checksum they would without indexing. It reports corruption if a record's type claims an index but the payload is too short to hold one, and clears the index for records that carry none, so `GetLastReadWALIndex()` always describes the record just returned. **There is no gap or continuity checking here, deliberately.** wal_index is consecutive across the WAL partition as a whole, not within any single file, so a jump between successive records in one file is normal. Treating it as a gap would be a false positive, and the response to a detected gap is truncation — so the detector is left out until the sequence-to-index correlation it would depend on is resolved. Decoding is driven purely by the record type at all eight dispatch sites in both readers, so a file may hold indexed and plain records and each is handled on its own terms. The marker record is not required to decode anything; it is only checked for position, reporting corruption if it appears after a data record, matching how `kSetCompressionType` is handled. `ReadPhysicalRecord` selects header size via `IsRecyclableRecordType`, and `FragmentBufferedReader` tracks whether the in-progress fragmented record is indexed so mismatched fragment types are reported. Exposes one accessor, `GetLastReadWALIndex()`. Per-record state, zero when the record carried no index. Differential Revision: D118369608
Summary: Pull Request resolved: meta#15222 Teaches `log::Reader` and `FragmentBufferedReader` to decode WAL index records. `MaybeStripAndVerifyWALIndex` extracts the leading fixed64 into `last_read_wal_index_`, strips it from the record, and recomputes the logical-record checksum over the stripped payload so upper layers see the same bytes and checksum they would without indexing. It reports corruption if a record's type claims an index but the payload is too short to hold one, and clears the index for records that carry none, so `GetLastReadWALIndex()` always describes the record just returned. **There is no gap or continuity checking here, deliberately.** wal_index is consecutive across the WAL partition as a whole, not within any single file, so a jump between successive records in one file is normal. Treating it as a gap would be a false positive, and the response to a detected gap is truncation — so the detector is left out until the sequence-to-index correlation it would depend on is resolved. Decoding is driven purely by the record type at all eight dispatch sites in both readers, so a file may hold indexed and plain records and each is handled on its own terms. The marker record is not required to decode anything; it is only checked for position, reporting corruption if it appears after a data record, matching how `kSetCompressionType` is handled. `ReadPhysicalRecord` selects header size via `IsRecyclableRecordType`, and `FragmentBufferedReader` tracks whether the in-progress fragmented record is indexed so mismatched fragment types are reported. Exposes one accessor, `GetLastReadWALIndex()`. Per-record state, zero when the record carried no index. Differential Revision: D118369608
2168cd3 to
4b64c12
Compare
✅ Claude Code ReviewAuto-triggered after CI passed — reviewing commit 4b64c12 SummaryWell-structured PR that adds WAL index record types and reader/writer support. The design is sound — self-describing record types, fail-closed on older readers, and clean separation between indexing and the existing format. No high-severity correctness bugs found. The main concerns are a defaulted parameter addition (violating CLAUDE.md guidance), missing test coverage for compression+WAL-index interaction, a missing High-severity findings (1):
Full review (click to expand)Findings🔴 HIGHH1. New defaulted parameter on
|
| Context | Does code execute? | Assumptions hold? | Action needed? |
|---|---|---|---|
| WAL compression | YES (writer compression path) | YES — indexed_payload concatenation handles it |
Test needed (M1) |
| Recycled log files | YES (kRecyclable* types) | YES — IsRecyclableRecordType handles all new types |
None |
| User-defined timestamps | N/A (orthogonal marker records) | YES — processed independently | None |
| WritePreparedTxnDB | NO — WAL index not plumbed to DB layer yet | N/A | Future PR |
| ReadOnly DB / SecondaryInstance | NO — WAL index not plumbed yet | N/A | Future PR |
| Manual WAL flush | YES (marker record conditional flush) | YES | None |
| PredecessorWALInfo | Orthogonal | YES | None |
| Big-endian | YES — EncodeFixed64/DecodeFixed64 are little-endian |
YES — portable encoding | None |
Positive Observations
- Fail-closed downgrade safety: The
static_assertensuring all WAL index types are belowkRecordTypeSafeIgnoreMask(128) is excellent — older readers will reject rather than silently misinterpret indexed records. - Self-describing records: Each physical fragment's type indicates whether it carries a wal_index, so a file can hold mixed record types. This is a robust design that doesn't depend on file-level state.
constexpr HeaderSelectionUnchangedForPreWALIndexTypes(): Compile-time verification that theIsRecyclableRecordType()refactoring doesn't change behavior for existing types is a great defensive pattern.WALIndexEnabled()as allowlist with no default: Forces compile-time classification of newPartitionWALUsagevalues rather than inheriting "indexed" by omission.- TODO for burned index: The comment acknowledging that a failed write burns an allocated wal_index and deferring resolution is honest and appropriate.
- Thorough edge-case tests: Tests for block-boundary straddling, large values, inconsistent fragment types, marker positioning, cross-writer interleaving, and mixed indexed/plain records show excellent attention to edge cases.
- Consistent reader behavior: Both
ReaderandFragmentBufferedReaderhandle all eight WAL index dispatch sites symmetrically, including fragment type consistency checking and marker interruption of partial records.
ℹ️ 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: Pull Request resolved: meta#15222 Teaches `log::Reader` and `FragmentBufferedReader` to decode WAL index records. `MaybeStripAndVerifyWALIndex` extracts the leading fixed64 into `last_read_wal_index_`, strips it from the record, and recomputes the logical-record checksum over the stripped payload so upper layers see the same bytes and checksum they would without indexing. It reports corruption if a record's type claims an index but the payload is too short to hold one, and clears the index for records that carry none, so `GetLastReadWALIndex()` always describes the record just returned. **There is no gap or continuity checking here, deliberately.** wal_index is consecutive across the WAL partition as a whole, not within any single file, so a jump between successive records in one file is normal. Treating it as a gap would be a false positive, and the response to a detected gap is truncation — so the detector is left out until the sequence-to-index correlation it would depend on is resolved. Decoding is driven purely by the record type at all eight dispatch sites in both readers, so a file may hold indexed and plain records and each is handled on its own terms. The marker record is not required to decode anything; it is only checked for position, reporting corruption if it appears after a data record, matching how `kSetCompressionType` is handled. `ReadPhysicalRecord` selects header size via `IsRecyclableRecordType`, and `FragmentBufferedReader` tracks whether the in-progress fragmented record is indexed so mismatched fragment types are reported. Exposes one accessor, `GetLastReadWALIndex()`. Per-record state, zero when the record carried no index. Differential Revision: D118369608
Summary: Pull Request resolved: meta#15222 Teaches `log::Reader` and `FragmentBufferedReader` to decode WAL index records. `MaybeStripAndVerifyWALIndex` extracts the leading fixed64 into `last_read_wal_index_`, strips it from the record, and recomputes the logical-record checksum over the stripped payload so upper layers see the same bytes and checksum they would without indexing. It reports corruption if a record's type claims an index but the payload is too short to hold one, and clears the index for records that carry none, so `GetLastReadWALIndex()` always describes the record just returned. **There is no gap or continuity checking here, deliberately.** wal_index is consecutive across the WAL partition as a whole, not within any single file, so a jump between successive records in one file is normal. Treating it as a gap would be a false positive, and the response to a detected gap is truncation — so the detector is left out until the sequence-to-index correlation it would depend on is resolved. Decoding is driven purely by the record type at all eight dispatch sites in both readers, so a file may hold indexed and plain records and each is handled on its own terms. The marker record is not required to decode anything; it is only checked for position, reporting corruption if it appears after a data record, matching how `kSetCompressionType` is handled. `ReadPhysicalRecord` selects header size via `IsRecyclableRecordType`, and `FragmentBufferedReader` tracks whether the in-progress fragmented record is indexed so mismatched fragment types are reported. Exposes one accessor, `GetLastReadWALIndex()`. Per-record state, zero when the record carried no index. Differential Revision: D118369608
Summary: Pull Request resolved: meta#15222 Teaches `log::Reader` and `FragmentBufferedReader` to decode WAL index records. `MaybeStripAndVerifyWALIndex` extracts the leading fixed64 into `last_read_wal_index_`, strips it from the record, and recomputes the logical-record checksum over the stripped payload so upper layers see the same bytes and checksum they would without indexing. It reports corruption if a record's type claims an index but the payload is too short to hold one, and clears the index for records that carry none, so `GetLastReadWALIndex()` always describes the record just returned. **There is no gap or continuity checking here, deliberately.** wal_index is consecutive across the WAL partition as a whole, not within any single file, so a jump between successive records in one file is normal. Treating it as a gap would be a false positive, and the response to a detected gap is truncation — so the detector is left out until the sequence-to-index correlation it would depend on is resolved. Decoding is driven purely by the record type at all eight dispatch sites in both readers, so a file may hold indexed and plain records and each is handled on its own terms. The marker record is not required to decode anything; it is only checked for position, reporting corruption if it appears after a data record, matching how `kSetCompressionType` is handled. `ReadPhysicalRecord` selects header size via `IsRecyclableRecordType`, and `FragmentBufferedReader` tracks whether the in-progress fragmented record is indexed so mismatched fragment types are reported. Exposes one accessor, `GetLastReadWALIndex()`. Per-record state, zero when the record carried no index. A marker that interrupts a fragmented record (before or after the first record has been returned) reports corruption and abandons the partial record in both readers, and `Reader` also resets its streaming checksum. Both readers therefore reject the same input instead of completing a record from its tail alone. Test Plan: Reader-focused tests added to `db/log_test.cc`, parameterised over recycling x retry-read (so both `Reader` and `FragmentBufferedReader` are covered): - `WALIndexReadWrite` — round trip; four records read back as indices 1-4 with payloads intact. - `WALIndexDisabledStaysVanilla` — with indexing off, no indexed or marker record types appear on disk. - `WALIndexRecordsDoNotRequireMarker` — indexed records decode with no marker present. - `WALIndexNonConsecutiveWithinFileIsAccepted` — a jump between indices in one file is not reported as corruption. Regression guard for the per-file gap check being reintroduced. - `WALIndexMixedWithPlainRecords` — a plain record following an indexed one keeps its full payload and reports index 0. - `WALIndexTooShortRecordReportsCorruption` — a record typed as indexed with a payload under 8 bytes is reported, not over-read. - `WALIndexInconsistentFragmentTypesReportsCorruption` — fragments of one logical record disagreeing about carrying an index is reported. - `WALIndexMarkerAfterDataRecordReportsCorruption` — a marker following a data record is reported. - `WALIndexLargeValueRoundTrips` — a high-bit index survives the fixed64 encoding. - `WALIndexLargeRecord` — the index survives fragmentation across 32KiB blocks. - `WALIndexMarkerInsidePartialRecordReportsCorruption`, `WALIndexMarkerInsidePartialRecordAfterFirstRecord` -- a marker interrupting a fragmented record is reported and the partial record dropped, before and after the first returned record. - `WALIndexFirstFragmentByteLayout`, `WALIndexEmptyRecordByteLayout`, `WALIndexStraddlesBlockBoundary` -- raw-byte layout and round trip of the writer's separate 8-byte prefix, including an index split across a block boundary. - `WALIndexNotAssignedWhenDisabled` -- with indexing off, a `wal_index` passed to `AddRecord` is not written and the reader reports 0. - `WALIndexConsecutiveAcrossFilesInPartition` — two writers sharing one counter; each file alone skips values, while the union read back from both files is exactly the contiguous run the counter issued. Corruption-path tests were verified to fail without the checks they cover: neutering both `ReportCorruption` calls fails all 8 parameterisations, and the mixed-records test fails on all 4 without the index reset. ``` $ buck2 run fbcode//internal_repo_rocksdb/repo:log_test [==========] 279 tests from 4 test suites ran. [ PASSED ] 279 tests. ``` `arc lint -a` on `log_reader.cc`, `log_reader.h`, `log_test.cc` — no issues. Formatting verified per file rather than asserted: `clang-format <file> | diff - <file>` is empty for every changed file, using the repo-pinned `tools/third-party/clang-format/clang-format`. M3 B.1 at this diff (clang-format 21.1.2 on its changed lines, make check-sources, debug build, touched test binaries): PASS; log_test: 299 pass. M5 fold: Absorbs 4 A.1 entries (GC27 4): GC27 Q9 (c) rename in ReadRecord. M5 B.1: PASS (clang-format 21.1.2 on the changed lines, make check-sources, debug build of log_test); 299 tests, 0 failed. Reviewers: kinbertchou, huixiao, dyao, taopeng, rajivharlalka, anand76, xbw, rbanerjee2, generatedunixname1816288208882371 Subscribers: jewoongh, rbanerjee2, anand76 Differential Revision: https://phabricator.intern.facebook.com/D118369608
Summary:
Teaches
log::ReaderandFragmentBufferedReaderto decode WAL index records.MaybeStripAndVerifyWALIndexextracts the leading fixed64 intolast_read_wal_index_, strips it from the record, and recomputes the logical-record checksum over the stripped payload so upper layers see the same bytes and checksum they would without indexing. It reports corruption if a record's type claims an index but the payload is too short to hold one, and clears the index for records that carry none, soGetLastReadWALIndex()always describes the record just returned.There is no gap or continuity checking here, deliberately. wal_index is consecutive across the WAL partition as a whole, not within any single file, so a jump between successive records in one file is normal. Treating it as a gap would be a false positive, and the response to a detected gap is truncation — so the detector is left out until the sequence-to-index correlation it would depend on is resolved.
Decoding is driven purely by the record type at all eight dispatch sites in both readers, so a file may hold indexed and plain records and each is handled on its own terms. The marker record is not required to decode anything; it is only checked for position, reporting corruption if it appears after a data record, matching how
kSetCompressionTypeis handled.ReadPhysicalRecordselects header size viaIsRecyclableRecordType, andFragmentBufferedReadertracks whether the in-progress fragmented record is indexed so mismatched fragment types are reported.Exposes one accessor,
GetLastReadWALIndex(). Per-record state, zero when the record carried no index.Differential Revision: D118369608