Skip to content

Expose partition_wal_usage in db_bench, db_stress and crashtest (#15227) - #15227

Open
JustinGaoF wants to merge 6 commits into
meta:mainfrom
JustinGaoF:export-D118371518
Open

JustinGaoF wants to merge 6 commits into
meta:mainfrom
JustinGaoF:export-D118371518

Conversation

@JustinGaoF

@JustinGaoF JustinGaoF commented Sep 16, 2026 •

Copy link
Copy Markdown

Summary:

Exposes partition_wal_usage in the tooling. No production behaviour change — everything it drives was built in the diffs below.

Adds --partition_wal_usage to db_bench and db_stress, and randomises it in db_crashtest between none and wal_index_single_file. Both tools parse the flag through GetDBOptionsFromString rather than a private string table, so they accept exactly what DBOptions accepts and cannot drift from it as values are added.

Adds the release note: indexed WALs are fail-closed for older binaries, and rolling back means setting kNone, flushing every column family so indexed WALs become obsolete, waiting for those files to be deleted, then downgrading.

Also adds the compressed-path coverage that needs the whole feature working end to end.

Differential Revision: D118371518

@meta-cla meta-cla Bot added the CLA Signed label Sep 16, 2026
@meta-codesync meta-codesync Bot changed the title Expose partition_wal_usage in db_bench, db_stress and crashtest Expose partition_wal_usage in db_bench, db_stress and crashtest (#15227) Sep 17, 2026
JustinGaoF added a commit to JustinGaoF/rocksdb that referenced this pull request Sep 17, 2026
…#15227)

Summary:

Exposes `partition_wal_usage` in the tooling. No production behaviour change — everything it drives was built in the diffs below.

Adds `--partition_wal_usage` to db_bench and db_stress, and randomises it in db_crashtest between `none` and `wal_index_single_file`. Both tools parse the flag through `GetDBOptionsFromString` rather than a private string table, so they accept exactly what `DBOptions` accepts and cannot drift from it as values are added.

Adds the release note: indexed WALs are fail-closed for older binaries, and rolling back means setting `kNone`, flushing every column family so indexed WALs become obsolete, waiting for those files to be deleted, then downgrading.

Also adds the compressed-path coverage that needs the whole feature working end to end.

Differential Revision: D118371518
JustinGaoF added a commit to JustinGaoF/rocksdb that referenced this pull request Sep 17, 2026
…#15227)

Summary:

Exposes `partition_wal_usage` in the tooling. No production behaviour change — everything it drives was built in the diffs below.

Adds `--partition_wal_usage` to db_bench and db_stress, and randomises it in db_crashtest between `none` and `wal_index_single_file`. Both tools parse the flag through `GetDBOptionsFromString` rather than a private string table, so they accept exactly what `DBOptions` accepts and cannot drift from it as values are added.

Adds the release note: indexed WALs are fail-closed for older binaries, and rolling back means setting `kNone`, flushing every column family so indexed WALs become obsolete, waiting for those files to be deleted, then downgrading.

Also adds the compressed-path coverage that needs the whole feature working end to end.

Differential Revision: D118371518
@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

⚠️ clang-tidy: 1 warning(s) on changed lines

Completed in 1427.8s.

Summary by check

Check Count
performance-inefficient-string-concatenation 1
Total 1

Details

test_util/testutil.cc (1 warning(s))
test_util/testutil.cc:613:42: warning: string concatenation results in allocation of unnecessary temporary strings; consider using 'operator+=' or 'string::append()' instead [performance-inefficient-string-concatenation]

@github-actions

Copy link
Copy Markdown

✅ Claude Code Review

Auto-triggered after CI passed — reviewing commit d0f559f


Summary

Well-structured PR that adds WAL index (per-record ordering numbers) to the WAL format, integrates it into all write paths, and provides comprehensive test coverage. The WAL format extension is carefully designed for fail-closed compatibility with older binaries. The code is generally correct and well-tested.

High-severity findings (2):

  • [db/db_impl/db_impl_open.cc:~265] Missing ValidateOptions rejection of unordered_write with WAL index -- unordered_write uses ConcurrentWriteGroupToWAL and WriteImplWALOnly, which now include WAL index logic, but no incompatibility check exists.
  • [db/db_impl/db_impl_write.cc:~2340] AllocateSequenceAndWALIndex under sequence_wal_index_mutex_ reads LastSequence() / LastAllocatedSequence() which are atomics typically protected by mutex_ or wal_write_mutex_ for ordered publish -- the catch-up logic may race with WriteRecoverableState or IngestExternalFile advancing last_sequence_ concurrently, potentially publishing a stale catch-up value.
Full review (click to expand)

Findings

🔴 HIGH

H1. Missing unordered_write + WAL index validation -- db/db_impl/db_impl_open.cc
  • Issue: ValidateOptions rejects two_write_queues with WAL index but does not reject unordered_write. The unordered_write path dispatches to WriteImplWALOnly (which calls ConcurrentWriteGroupToWAL), and both functions now include WAL index logic. Since ConcurrentWriteGroupToWAL asserts two_write_queues_ || unordered_write, an unordered_write + WAL_index configuration is reachable and the new AllocateSequenceAndWALIndex call within it will execute. However, the sequence allocation semantics differ under unordered_write (it uses kDoPublishLastSeq and kDoAssignOrder), and this combination has not been tested.
  • Root cause: The validation only checks two_write_queues but ConcurrentWriteGroupToWAL is shared by both modes.
  • Suggested fix: Add a validation in ValidateOptions:
    if (log::WALIndexEnabled(db_options.partition_wal_usage) &&
        db_options.unordered_write) {
      return Status::NotSupported(
          "partition_wal_usage is not supported with unordered_write. ");
    }
H2. Potential race in AllocateSequenceAndWALIndex catch-up logic -- db/db_impl/db_impl_write.cc:~2340
  • Issue: The function reads versions_->LastSequence() and versions_->LastAllocatedSequence() under sequence_wal_index_mutex_ but WITHOUT mutex_ or wal_write_mutex_. The comment says "WriteRecoverableState and external file ingestion advance last_sequence_ directly" -- these advances happen under different locks. While the atomics prevent data races, there is a TOCTOU window: between reading LastSequence() and calling FetchAddLastAllocatedSequence(), another thread could advance LastSequence() further, causing this thread to allocate a sequence block that partially overlaps with the externally advanced range.
  • Root cause: The catch-up + allocate is not atomic with respect to the external sequence advancers.
  • Suggested fix: Document the safety argument more precisely. If WriteRecoverableState and external file ingestion always happen under mutex_ (which prevents concurrent user writes), then the race is benign because no other thread is calling AllocateSequenceAndWALIndex simultaneously. If this invariant holds, add an assertion or comment. If it does not hold under all configurations, this needs the DB mutex_ or an alternative synchronization mechanism.

🟡 MEDIUM

M1. Burned WAL index on write failure -- db/log_writer.cc
  • Issue: The TODO in AddRecord notes that if the append fails after AllocateSequenceAndWALIndex has been called, the wal_index is consumed but never persisted. This creates a gap in the wal_index sequence that downstream gap-detection (when implemented) would interpret as data loss.
  • Root cause: The wal_index is allocated before the I/O, not after.
  • Suggested fix: The TODO is appropriate for now since no gap-detection consumer exists yet. Ensure this is resolved before any completeness-check feature lands. Consider emitting an explicit "burned index" placeholder record, or deferring allocation until after successful I/O.
M2. next_wal_index_ not recovered on restart -- db/db_impl/db_impl.h:~3389
  • Issue: next_wal_index_ is initialized to kWALIndexStartNumber (1) and never loaded from existing WALs during recovery. After a restart, wal_index values restart from 1 even if old WALs with higher indices are still live. The test WALIndexNumberingRestartsAcrossLiveWALs documents this.
  • Root cause: Intentional limitation for the initial implementation.
  • Suggested fix: This is documented and tested, which is good. Ensure the limitation is mentioned in the public API documentation for partition_wal_usage and in any release notes. A future PR should recover the high-water mark from existing WALs during DB::Open.
M3. MaybeAddWALIndexMarkerRecord not called from async WAL precreate path -- db/db_impl/db_impl_open.cc
  • Issue: StartWALFile adds the marker record, and CreateWAL calls StartWALFile. However, the async WAL precreate path (BGWorkAsyncWALPrecreate) calls CreateWALWriter directly without StartWALFile. If a precreated WAL is later used, SetPartitionWALUsage is applied in CreateWALWriter (per the diff), but the marker record is only emitted in StartWALFile. Verify the full precreate -> use path calls StartWALFile or MaybeAddWALIndexMarkerRecord before data records are written.
M4. Record checksum recomputation waste for fragmented indexed records -- db/log_reader.cc:~490
  • Issue: For fragmented records, hash_state_ is streamed across all fragments producing a checksum over (wal_index_prefix || payload). Then MaybeStripAndVerifyWALIndex replaces *record_checksum with XXH3_64bits(record->data(), record->size()) computed over just the payload. The streamed hash computation is wasted work.
  • Suggested fix: Minor perf concern, acceptable for initial implementation. Optimize if needed later.
M5. Verify wal_index parameter has no default value -- db/log_writer.h (truncated)
  • Issue: Per CLAUDE.md, new defaulted parameters are the Miss Spelling in README #1 refactoring trap. The full header change is in the truncated portion of the diff. Based on test code (writer_->AddRecord(WriteOptions(), Slice(msg), /*seqno=*/0, wal_index)), wal_index appears to be explicit (good), but this must be verified.

🟢 LOW / NIT

L1. Duplicate C API implementations in c_api_gen/ and db/c.cc
  • Issue: rocksdb_options_set/get_partition_wal_usage appears in both auto-generated and manual C API files. Verify only one is compiled.
L2. Test helper ReadWALRecordTypes uses magic byte offsets instead of named constants
  • Issue: Minor maintainability concern in test code.

Cross-Component Analysis

Context Executes? Safe? Action
two_write_queues NO (rejected) N/A Safe
unordered_write YES (not rejected!) UNKNOWN H1
ReadOnly DB NO N/A Safe
PipelinedWrite YES YES Safe
WAL compression YES (tested) YES Safe
Recycled logs YES (tested) YES Safe
UDT Orthogonal YES Safe
External file ingestion Partial (seq advances) Likely safe H2
WriteRecoverableState Partial (seq advances) Likely safe (under mutex_) H2

Positive Observations

  • Fail-closed compatibility: WAL index types below kRecordTypeSafeIgnoreMask with static_asserts -- older binaries reject rather than silently misinterpret.
  • HeaderSelectionUnchangedForPreWALIndexTypes: Excellent compile-time guard ensuring the IsRecyclableRecordType() refactoring doesn't change behavior for existing record types.
  • Comprehensive tests: Round-trip, compression, fragmentation, block boundary straddling, marker placement, corruption detection, concurrent allocation, disableWAL, external file ingestion, cross-file continuity.
  • Writer monotonicity enforcement: Non-increasing wal_index rejected with IOStatus::Corruption, not a debug-only assert.
  • Clear burned-index TODO: Known limitation documented with resolution path.

ℹ️ 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

JustinGaoF added a commit to JustinGaoF/rocksdb that referenced this pull request Oct 7, 2026
…#15227)

Summary:
Pull Request resolved: meta#15227

Exposes `partition_wal_usage` in the tooling. No production behaviour change — everything it drives was built in the diffs below.

Adds `--partition_wal_usage` to db_bench and db_stress, and randomises it in db_crashtest between `none` and `wal_index_single_file`. Both tools parse the flag through `GetDBOptionsFromString` rather than a private string table, so they accept exactly what `DBOptions` accepts and cannot drift from it as values are added.

Adds the release note: indexed WALs are fail-closed for older binaries, and rolling back means setting `kNone`, flushing every column family so indexed WALs become obsolete, waiting for those files to be deleted, then downgrading.

Also adds the compressed-path coverage that needs the whole feature working end to end.

Differential Revision: D118371518
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
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#15226

Makes `DBImpl` the owner of WAL index allocation, and wires indexing into the write path.

WAL recovery treats `wal_index` order as the durable proxy for sequence-number order. Allocating the two with independent atomics lets concurrent partition writers reverse those orders, so truncating an index prefix could leave an undetectable hole in sequence space. `AllocateSequenceAndWALIndex` reserves the sequence block and, when a WAL record will be written, its `wal_index`, under one short DB-wide `InstrumentedMutex`. The assigned index is then passed into `log::Writer::AddRecord`.

A mutex was chosen over a 16-byte atomic so the future durability-watermark `RegisterPending` can join the same critical section. The lock covers only counter updates — batch merging, WAL append, compression, sync and all other I/O stay outside it. The `kNone` path never takes it. An exhausted counter fails the write inside the lock rather than wrapping, since wrapping would break the monotonicity ordering depends on.

Also binds `SetPartitionWALUsage` on each newly created WAL writer and emits the marker from `StartWALFile`, so both WAL-creation paths — DB open and WAL switch — are covered by one call site.

Sequence-only writes use the same allocator without consuming an index; `disableWAL` is covered directly. External-file ingestion already fences both write queues across its sequence assignment, so no indexed allocation can interleave with it. `two_write_queues` is rejected, since its second allocation site would need a broader ordering change. (`kPartitionByColumnFamily` is also rejected at `DB::Open`, but that rejection now lands with the enum itself in D118367634 rather than here, so no revision of the tree accepts a value it cannot honor.)

The counter is **not** restored across restarts — it starts at `kWALIndexStartNumber` on every open, so indices are unique among WALs written by one process, not for all time. This is reachable with plain writes rather than only in theory: any write after a reopen starts a second live WAL numbering from `kWALIndexStartNumber` again, and `WALIndexNumberingRestartsAcrossLiveWALs` pins that state so a future fix has to change the test deliberately. Harmless while nothing consumes the index; to be resolved before anything does.

The burned-index window from the diff below is wider here, because allocation now precedes write-group merging and payload preparation rather than happening inside `AddRecord`. It still spans no additional I/O, and the existing `TODO` continues to track it.

Differential Revision: D119600943
…#15227)

Summary:
Pull Request resolved: meta#15227

Exposes `partition_wal_usage` in the tooling. No production behaviour change — everything it drives was built in the diffs below.

Adds `--partition_wal_usage` to db_bench and db_stress, and randomises it in db_crashtest between `none` and `wal_index_single_file`. Both tools parse the flag through `GetDBOptionsFromString` rather than a private string table, so they accept exactly what `DBOptions` accepts and cannot drift from it as values are added.

Adds the release note: indexed WALs are fail-closed for older binaries, and rolling back means setting `kNone`, flushing every column family so indexed WALs become obsolete, waiting for those files to be deleted, then downgrading.

Also adds the compressed-path coverage that needs the whole feature working end to end.

Differential Revision: D118371518
@meta-codesync

meta-codesync Bot commented Oct 20, 2026

Copy link
Copy Markdown

@JustinGaoF has exported this pull request. If you are a Meta employee, you can view the originating Diff in D118371518.

JustinGaoF added a commit to JustinGaoF/rocksdb that referenced this pull request Oct 20, 2026
…#15227)

Summary:
Pull Request resolved: meta#15227

Exposes `partition_wal_usage` in the tooling. No production behaviour change — everything it drives was built in the diffs below.

Adds `--partition_wal_usage` to db_bench and db_stress, and randomises it in db_crashtest between `none` and `wal_index_single_file`. Both tools parse the flag through `GetDBOptionsFromString` rather than a private string table, so they accept exactly what `DBOptions` accepts and cannot drift from it as values are added.

Adds the release note: indexed WALs are fail-closed for older binaries, and rolling back means setting `kNone`, flushing every column family so indexed WALs become obsolete, waiting for those files to be deleted, then downgrading.

Also adds the compressed-path coverage that needs the whole feature working end to end.

Differential Revision: D118371518
JustinGaoF added a commit to JustinGaoF/rocksdb that referenced this pull request Nov 19, 2026
…test

Summary:
Pull Request resolved: meta#15227

Exposes `partition_wal_usage` in the tooling. No production behaviour change — everything it drives was built in the diffs below.

Adds `--partition_wal_usage` to db_bench and db_stress, and randomises it in db_crashtest between `none` and `partition_by_column_family`. Both tools parse the flag through `GetDBOptionsFromString` rather than a private string table, so they accept exactly what `DBOptions` accepts and cannot drift from it as values are added.

Adds the release note: older binaries only report indexed WAL records (in the default point-in-time recovery mode they open the DB without them), and rolling back means setting `kNone` and reopening, flushing every column family so indexed WALs become obsolete, waiting for those files to be deleted, purging the WAL archive (or waiting out `WAL_ttl_seconds` / `WAL_size_limit_MB`), then downgrading. D126533192 adds the `ldb check_wal_index` step that confirms it.

Also adds the compressed-path coverage that needs the whole feature working end to end.

M1: Absorbs GC04 release-note part (older-versions sentence + base procedure; guard/ldb clauses stay in S-A).

Changes visible to existing users:
- New `--partition_wal_usage` flag in db_bench and db_stress (default `none`, so default runs do not change).
- db_crashtest.py now picks `partition_wal_usage` at random, so about half of default crash-test runs write the indexed WAL format. Runs with `two_write_queues=1` always use `none`. Runs with `disable_wal=1` and an indexed WAL get `recycle_log_file_num=0`, since indexed WALs still reject `disableWAL` with recycling (the crash-test default is already 0).

Test Plan:
Two compressed round-trip tests in `db/log_test.cc`:

- `CompressionLogTest.WALIndexReadWrite` — indices survive WAL compression, including a record large enough to fragment across blocks.
- `CompressionLogTest.WALIndexLargeIncompressible` — `BigString` compresses away to almost nothing and completes in a single `Compress()` call, so this uses incompressible random data (`3 * kBlockSize / 2`) to force the streaming compressor to loop with `compress_remaining > 0`, which is the path the index prefix has to survive.

Flag parsing exercised end to end through the shared parser:

```
$ db_bench --benchmarks=fillseq --num=10 --partition_wal_usage=partition_by_column_family
fillseq      :    2094.300 micros/op 476 ops/sec

$ db_bench --benchmarks=fillseq --num=10 --partition_wal_usage=bogus
Cannot parse partition_wal_usage: bogus
```

```
$ buck2 run fbcode//internal_repo_rocksdb/repo:log_test
[==========] 303 tests from 4 test suites ran.
[  PASSED  ] 303 tests.
```

Crashtest, which the earlier revision of this diff did not run even though it is the diff that introduces the randomisation:

```
$ python3 db_crashtest.py blackbox --partition_wal_usage=partition_by_column_family \
    --duration=180 --interval=30 --max_key=10000 --ops_per_thread=20000
(Re-)verified 4069 unique IDs
Crash-recovery verification passed :)
Verification successful
[exited with code 0]
```

Both runs above were recorded with an earlier spelling of the same value (`wal_index_single_file`), which no longer parses; the outputs are from those runs and were not re-run with the current spelling.

The `two_write_queues` constraint added here is checked directly against the generator, since `DB::Open` rejects that pairing as of the diff below:

```
$ python3 -c "<draw 4000 default+txn param sets, run finalize_and_sanitize>"
before: 1031 / 4000 draws produced partition_wal_usage != none with two_write_queues=1
after:     0 / 4000 draws, with indexing still selected in 1025 of them
```

The constraint clears `partition_wal_usage` rather than `two_write_queues`: `WRITE_PREPARED` with `unordered_write` requires `two_write_queues` (`pessimistic_transaction_db.cc`), so forcing the queues off would trade one rejected combination for another.

`buck2 build fbcode//internal_repo_rocksdb/repo:db_bench fbcode//internal_repo_rocksdb/repo:db_stress` — both build. `arc lint -a` on all changed files — 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`.

M1: doc-only; tip suites 7870/0.
M1 re-verification (2026-10-20, after rebasing the stack onto master f0c3a35689fc and clang-formatting): per-diff gate at this diff passed (CI format check, `rocksdb_lib` build, touched test targets); tip suites 8126/0; N=1 byte identity equals T0.

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: 315 pass.

M5 fold: Absorbs 2 A.1 entries (GC29a 2): GC29a Q3 (a) help text.

M5 B.1: PASS (clang-format 21.1.2 on the changed lines, make check-sources, debug build of log_test, db_stress, db_bench); 315 tests, 0 failed.

Reviewers: kinbertchou, anand76, taopeng, xbw, rbanerjee2, rajivharlalka, dyao, #rocksdb, huixiao

Subscribers: jewoongh, rbanerjee2, anand76

Differential Revision: https://phabricator.intern.facebook.com/D118371518
JustinGaoF added a commit to JustinGaoF/rocksdb that referenced this pull request Nov 19, 2026
…test

Summary:
Pull Request resolved: meta#15227

Exposes `partition_wal_usage` in the tooling. No production behaviour change — everything it drives was built in the diffs below.

Adds `--partition_wal_usage` to db_bench and db_stress, and randomises it in db_crashtest between `none` and `partition_by_column_family`. Both tools parse the flag through `GetDBOptionsFromString` rather than a private string table, so they accept exactly what `DBOptions` accepts and cannot drift from it as values are added.

Adds the release note: older binaries only report indexed WAL records (in the default point-in-time recovery mode they open the DB without them), and rolling back means setting `kNone` and reopening, flushing every column family so indexed WALs become obsolete, waiting for those files to be deleted, purging the WAL archive (or waiting out `WAL_ttl_seconds` / `WAL_size_limit_MB`), then downgrading. D126533192 adds the `ldb check_wal_index` step that confirms it.

Also adds the compressed-path coverage that needs the whole feature working end to end.

M1: Absorbs GC04 release-note part (older-versions sentence + base procedure; guard/ldb clauses stay in S-A).

Changes visible to existing users:
- New `--partition_wal_usage` flag in db_bench and db_stress (default `none`, so default runs do not change).
- db_crashtest.py now picks `partition_wal_usage` at random, so about half of default crash-test runs write the indexed WAL format. Runs with `two_write_queues=1` always use `none`. Runs with `disable_wal=1` and an indexed WAL get `recycle_log_file_num=0`, since indexed WALs still reject `disableWAL` with recycling (the crash-test default is already 0).

Test Plan:
Two compressed round-trip tests in `db/log_test.cc`:

- `CompressionLogTest.WALIndexReadWrite` — indices survive WAL compression, including a record large enough to fragment across blocks.
- `CompressionLogTest.WALIndexLargeIncompressible` — `BigString` compresses away to almost nothing and completes in a single `Compress()` call, so this uses incompressible random data (`3 * kBlockSize / 2`) to force the streaming compressor to loop with `compress_remaining > 0`, which is the path the index prefix has to survive.

Flag parsing exercised end to end through the shared parser:

```
$ db_bench --benchmarks=fillseq --num=10 --partition_wal_usage=partition_by_column_family
fillseq      :    2094.300 micros/op 476 ops/sec

$ db_bench --benchmarks=fillseq --num=10 --partition_wal_usage=bogus
Cannot parse partition_wal_usage: bogus
```

```
$ buck2 run fbcode//internal_repo_rocksdb/repo:log_test
[==========] 303 tests from 4 test suites ran.
[  PASSED  ] 303 tests.
```

Crashtest, which the earlier revision of this diff did not run even though it is the diff that introduces the randomisation:

```
$ python3 db_crashtest.py blackbox --partition_wal_usage=partition_by_column_family \
    --duration=180 --interval=30 --max_key=10000 --ops_per_thread=20000
(Re-)verified 4069 unique IDs
Crash-recovery verification passed :)
Verification successful
[exited with code 0]
```

Both runs above were recorded with an earlier spelling of the same value (`wal_index_single_file`), which no longer parses; the outputs are from those runs and were not re-run with the current spelling.

The `two_write_queues` constraint added here is checked directly against the generator, since `DB::Open` rejects that pairing as of the diff below:

```
$ python3 -c "<draw 4000 default+txn param sets, run finalize_and_sanitize>"
before: 1031 / 4000 draws produced partition_wal_usage != none with two_write_queues=1
after:     0 / 4000 draws, with indexing still selected in 1025 of them
```

The constraint clears `partition_wal_usage` rather than `two_write_queues`: `WRITE_PREPARED` with `unordered_write` requires `two_write_queues` (`pessimistic_transaction_db.cc`), so forcing the queues off would trade one rejected combination for another.

`buck2 build fbcode//internal_repo_rocksdb/repo:db_bench fbcode//internal_repo_rocksdb/repo:db_stress` — both build. `arc lint -a` on all changed files — 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`.

M1: doc-only; tip suites 7870/0.
M1 re-verification (2026-10-20, after rebasing the stack onto master f0c3a35689fc and clang-formatting): per-diff gate at this diff passed (CI format check, `rocksdb_lib` build, touched test targets); tip suites 8126/0; N=1 byte identity equals T0.

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: 315 pass.

M5 fold: Absorbs 2 A.1 entries (GC29a 2): GC29a Q3 (a) help text.

M5 B.1: PASS (clang-format 21.1.2 on the changed lines, make check-sources, debug build of log_test, db_stress, db_bench); 315 tests, 0 failed.

Reviewers: kinbertchou, anand76, taopeng, xbw, rbanerjee2, rajivharlalka, dyao, #rocksdb, huixiao

Subscribers: jewoongh, rbanerjee2, anand76

Differential Revision: https://phabricator.intern.facebook.com/D118371518

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant