Repository navigation
[Java] Add statistics JNI bindings - #122
Merged
Merged
Conversation
added 17 commits
April 14, 2014 21:06
Conflicts: Makefile java/Makefile java/org/rocksdb/Options.java java/rocksjni/portal.h
Contributor
|
Merging since it was accepted by @yhchiang |
igorcanadi
added a commit
that referenced
this pull request
Apr 18, 2014
[Java] Add statistics JNI bindings
abbccdda
pushed a commit
to abbccdda/rocksdb
that referenced
this pull request
Aug 21, 2021
* Make CloudEnv, CloudStorageProvider, and CloudLogController into Configurable Makes it possible to configure them from strings/maps. Added CreateFromString methods for creating them.
Nazgolze
pushed a commit
to Nazgolze/rocksdb-1
that referenced
this pull request
Sep 21, 2021
JustinGaoF
added a commit
to JustinGaoF/rocksdb
that referenced
this pull request
Nov 9, 2026
Summary: The diff works to provide container of the WAL files handler to replace existing one wal file. Stack: this diff sits on D117280372 with the write-path prep stack on D119751506 (per author direction; the prep content is unchanged from the D120171238-based version, and the base delta is read-path/test/comment-only, see Test Plan). `DBImpl::logs_` and `DBImpl::alive_wal_files_` become one deque per WAL partition: `std::vector<std::deque<...>>`, sized 1 at construction. `wal_partitions > 1` is still rejected at Open, `SelectWalForWrite()` remains the only WAL-selection seam, and no public header, option, or on-disk format changes. Write-path point accesses bind partition 0; walks (obsolete-file selection, sync bookkeeping, size accounting, close) loop partitions in ascending index order under the same locks as before. Locking documentation: the numbered cases are unchanged in content but reframed from "the deque" to "partition p's deque" under an explicit two-level split (the vectors are sized at construction and never resized, so they need no lock; every deque access holds the same global mutexes as before, since mutex splitting is out of scope). The back()/getting_synced observations are scoped to one partition's deque. Enforcement is mechanical where it can be: all access goes through the `WalLogs(p)` / `AliveWalFiles(p)` / `NumWalPartitions()` chokepoint with bounds and equal-length asserts, replacing direct member uses; the container abstraction itself still lands later once real N-partition usage is known. Lifetime: each partition's deque keeps independent per-entry bookkeeping and removal stays per-entry (pop/erase), so a future reference-driven scheme can replace per-entry removal without reshaping; element addresses stay stable (deque elements never move, vectors never resized), which is what `CurrentWal()` references and `WalContext::wal_file_number_size` pointers rely on. This diff also carries a one-word rebase-merge correction that belongs to the D117251771 rebase (`ConcurrentWriteGroupToWAL`'s cover call referenced `log_writer`, which the WalContext refactor removed; it now passes `wal_context.writer` like the two sibling sites). It lands here instead of in that diff per the no-touch rule for existing diffs; the rebased intermediate does not compile without it. Behaviour preservation: the change is semantics-preserving by construction (same deque objects, same lock holds, loops run once), so most hunks have no neuter check available. Neutered instead: forcing `NumWalPartitions()` to 0 fails 8 `db_wal_test` tests (sync and WAL-lifecycle coverage incl. the new test below), proving the loops are load-bearing. No existing test caught a mistake during the change itself: the first full-matrix run passed, and the one real defect found (the `log_writer` merge breakage above) was caught by the compiler. New coverage is one pinning test, `DBWALTest.SingleWalPartition`, asserting exactly one partition across open, write, WAL roll, flush, and reopen; all existing tests pass unmodified. Test Plan: `buck2 test fbcode//internal_repo_rocksdb/repo:db_wal_test fbcode//internal_repo_rocksdb/repo:db_write_test fbcode//internal_repo_rocksdb/repo:db_basic_test fbcode//internal_repo_rocksdb/repo:db_flush_test fbcode//internal_repo_rocksdb/repo:db_options_test fbcode//internal_repo_rocksdb/repo:repair_test fbcode//internal_repo_rocksdb/repo:log_test` - Pass 2888, Fail 0 on the submitted base. Targeted locking-route runs: `DBWALTest.SingleWalPartition`, `DBWALTest.WALWriteErrorNoRecovery`, `DBWALIndexTest.TwoWriteQueuesIsRejected`, `DBBasicTest.EmptyFlush` (all option configs incl. two_write_queues on), `DBBasicTest.DBCloseFlushError`, `DBBasicTest.ReadOnlyDBFlushWAL`, `DBWriteTestUnparameterized.PipelinedWriteRace` - all pass. Neuter (`NumWalPartitions()` forced to 0): 8 `db_wal_test` failures, reverted with byte-identical diff. R5 WAL byte comparison: fixed `db_bench fillseq` workload (num=20000, seed=12345) run against parent and new binaries - WAL bytes identical for `partition_wal_usage=none` and `record_ordering_single_file` (self-consistency verified first), identical Open rejection for `partition_by_column_family`; evidence gathered on D120171238-based binaries, and the move to D119751506 only drops a read-path/test/comment-only delta (reader validation, `log_test` cases, comment-only `log_writer.h`) touching none of this diff's files nor the write path, so the conclusion transfers - happy to re-run on request. 180s blackbox crash test with `--partition_wal_usage=record_ordering_single_file` on `db_stress` rebuilt from this commit: passed. `arc lint -a`: clean. `clang-format --dry-run --Werror` (v21.1.2, repo `.clang-format`): clean on all touched lines (two remaining violations are pre-existing rebase lines outside this diff). M3 B.1 at this diff (clang-format 21.1.2 on its changed lines, make check-sources, debug build, touched test binaries): PASS; db_wal_test: 2059 pass. M5 fold: Absorbs 9 A.1 entries (GC31 8, GC33 1): GC31 Q2 (b) per-partition wals_total_size_ (WalsTotalSizeCounter, wal_partition_sizes_, readers, open reset); GC33's N=1 WalsTotalSize; GC27's compaction-service secondary test. Not here after B.1: GC27's compaction-service test and its helper go to D123079329 (X35-M5). Exceptions: X3-M5 (the test); X17-M5 (the WriteToWAL account at D122274088; X35-M5: GC27#119-meta#122 (MyTestCompactionService's options map and OpenAndCompactAtPartitionedPrimary, X3-M5) moved from D121858039 to D123079329: below D123079329 Open refuses N>1 with no testing hook (B.1). Hand-splits (rows below the hunk's top row get their slice by a per-row edit): GC31#347 (db_impl.h test accessors): TEST_wals_total_size via WalsTotalSize() at D121858039, TEST_CachedRecoverableStateEmpty at D123079329, TEST_UnpublishedSyncGroups at D123551605. M5 B.1: PASS (clang-format 21.1.2 on the changed lines, make check-sources, debug build of db_wal_test); 2062 tests, 0 failed. Differential Revision: https://phabricator.intern.facebook.com/D121858039
JustinGaoF
added a commit
to JustinGaoF/rocksdb
that referenced
this pull request
Nov 9, 2026
Summary: Reviewer question: is the memtable-switch gate sufficient to exclude every other partition's leader from a memtable/WAL switch -- a leader enters it in PreprocessWrite() before binding a WAL and leaves it only when its group exits (including the parallel-follower and unordered_write exits), and a leader that must switch closes it from PreprocessWrite() before entering, so no leader ever waits on itself? **Blocked decisions** 1. M0.8, route-then-group: already decided and implemented by D122869562; not reopened. Each writer carries the route resolved once in WriteImpl and joins the queue of that partition. Reversing it (group-then-route) would need WriteThread to release leadership between WAL selection and the append. 2. Memtable fork: **A, allow_concurrent_memtable_write.** N leaders insert into the same memtables, and A needs no new lock or lock ordering. It keeps unordered_write working (which requires A), and B's serialization cost does not need measuring because nothing is serialized. Its cost: wal_partitions > 1 requires a SkipList memtable, and enable_blob_direct_write cannot be combined with it (ColumnFamilyData::ValidateOptions already rejects blob direct write with concurrent memtable writes). Enforced at Open: wal_partitions > 1 with allow_concurrent_memtable_write=false is now NotSupported, and this check runs before the general wal_partitions > 1 rejection, so it is reachable and tested. Reversing to B: drop that Open check, give each leader a memtable-insert lock around its insert at N > 1 (and let single-writer groups insert serially again), and reject unordered_write at N > 1 instead. **Why** Routing (D122869562) decides which WAL a write binds to, but every writer still joins the one write_thread_, so writers to different partitions are still serialized behind one leader. D122660502's 36.8 ms join-wait tail is unrelieved. This diff makes N > 1 mean N concurrent leaders, each appending to its own WAL. **Previous behavior** One WriteThread write_thread_ and one nonmem_write_thread_. The per-partition containers were always sized 1: Open created partition 0's WAL only, and SwitchMemtable rotated partition 0 only. At N > 1 the default write path also read LastSequence() as its allocation, published with SetLastSequence() (which asserts monotonicity), and inserted single-writer groups with concurrent_memtable_writes=false -- all of which assume one leader. **New behavior (only at N > 1, still unreachable outside tests)** - One WriteThread and one nonmem WriteThread per partition (write_threads_/nonmem_write_threads_, sized with the other partition containers in the constructor). A writer joins its routed partition's queue, so each partition has its own newest_writer_ and leader. There is no cross-partition election. - One log::Writer per partition: Open creates N WALs and SwitchMemtable rotates all N together, under all N WAL write mutexes. Partition 0 keeps the lowest number of each generation, so cur_wal_number_, memtable NextLogNumber and obsolescence keep their meaning. - Sequence allocation stays inside each partition's leader critical section. The default (!two_write_queues) path allocates through AllocateSequenceAndWALIndex, the counter the WAL-index path and both two_write_queues queues already use, so sequences and wal_index stay unique across partitions and queues. The two-queue path still allocates under WalWriteMutex(p), which both queues of a partition share. - Every leader inserts in concurrent mode (forced parallel path), because other partitions insert into the same memtables. - Memtable-switch gate: PreprocessWrite()'s SwitchWAL / HandleWriteBufferManagerFlush / ScheduleFlushes close the gate and wait for leaders past it. Callers outside the write path (flush, SetOptions, CF create/drop, ingestion, LockWAL, ResumeImpl, ...) enter every partition's queue unbatched in ascending order (AllPartitionsWriter). - Publication: PublishLastSequence() skips a publish a higher one already overtook (CAS-max), so LastSequence() never moves backwards. Publication order is not established here (see limitations). - Stalls and delays act on the leader's own partition queue; UnlockWAL and WaitForPendingWrites cover every queue. **Neuter checks at one partition (R5)** NumWalPartitions() == 1 returns from all four gate functions immediately; `parallel` keeps `write_group.size > 1`; the allocator condition reduces to WALIndexEnabled; PublishLastSequence calls SetLastSequence; stats keep `concurrent = two_write_queues_`; the constructor's resize, Open's extra-WAL loop, SwitchMemtable's extra-WAL loops and its any-partition-non-empty loop are all empty; AllWalWriteMutexesLock in SwitchMemtable takes exactly WalWriteMutex(0); AllPartitionsWriter uses an inline writer for partition 0, with no allocation, i.e. the same single EnterUnbatched as before. The R2 assertion and its per-file tracker are debug-only. Changes without a neuter: last_batch_group_size_ is now RelaxedAtomic (relaxed load/store); IsMainWriteThread replaces `&write_thread == &write_thread_` with one comparison at N=1; UnlockWAL keeps its stall counts in two size-1 vectors (a cold path); WriteToWAL/WriteGroupToWAL take a sequence_count used only by the debug assertion. None of these changes control flow or WAL bytes at N=1. **Safety, compatibility, limitations** - wal_partitions > 1 remains rejected at Open. Tests reach N > 1 only through the debug sync point DBImpl::ValidateOptions:AllowWalPartitions. Read-only and secondary instances always size to one partition. No public header changes. - Deferred to follow-up diffs, as agreed, and unsafe at N > 1 until then: publication order (a reader can see sequence S before a lower sequence from another partition is inserted, much like unordered_write's visibility); enable_pipelined_write (per-WriteThread last_sequence_ allocation, ordered SetLastSequence); sync=true writes (one leader syncs every partition's files while other partitions append); WBWI ingestion (switches memtables inside a gated leader); Merge batches (still inserted non-concurrently because of max_successive_merges); cached_recoverable_state_ without two_write_queues; timed write delays now run per partition in parallel; WALIOStatusCheck resets partition 0's writer on non-paranoid errors. None of these configurations is rejected: the coordination they need belongs to the follow-ups. - Durability watermark (07), completion gate (08) and multi-WAL recovery are out of scope. A crash at N > 1 can leave holes, and reopening an N > 1 DB is not supported. - Adaptive yield is unchanged: WriteThread's AdaptationContexts are file-scope statics shared by every instance, so they already adapt to aggregate traffic rather than to one queue's 1/N share. **Folded in from round 12 (D124911745)** Merge batches and WBWI ingestion are no longer deferred; this replaces those two items under limitations. Every N>1 memtable insert is now concurrent-safe: - Merge batches stay on the parallel insert path at N>1 (`assert(parallel || N==1)`). Rejecting `max_successive_merges>0` covers the only part of Merge that isn't concurrent-safe. - `IngestWriteBatchWithIndex` is rejected at runtime in `WriteImpl` at N>1 (`assert(N==1)` in `IngestWBWIAsMemtable`). - At N>1, Open rejects `max_successive_merges>0` and non-SkipList memtables. VectorRep passes the generic concurrent check, so only this new guard rejects it. - Tests: `MergeBatchesInsertConcurrentlyAcrossPartitions`, `IngestWriteBatchWithIndexRejectedAtNPartitions`, `ConcurrentUnsafeConfigsRejectedAtOpen` (4 rejects + control), `N1ConcurrentUnsafeOptionsStillAccepted`. - Neuters: revert the Merge guard -> the `parallel || N==1` assert aborts. Revert the WBWI check -> the `N==1` assert aborts. Revert the CF guards -> the vector_rep and merges cases open -> fail. M1: Absorbs 14 entries: GC13 Q1 gate opt-in + `WalPartitionsTestingOptIn`, Q3 ingestion stall + test, Q4 asserts; GC15 Q6 import stall + test, Q7 asserts (AMB-10 comment line lives in D123701876; SilentAtN1 lives in D123551605). M2 fold (2026-10-22, `M2-FoldTasks.md` + `M2-Amendment.md`): Absorbs (M2) GC06 Q2-Q5/Q8: option rejections, `WriteWithCallback` and OCC rejections, fixture, `UnindexedWalPartitionsAlwaysRejected`, `WalPartitionsUpperBound`, `ValidatePolicyAtNPartitions`, bypasses; GC10 Q1-Q4: recoverable-state cache, per-partition group size, WBM stall, `DelayWrite` arg, `WritePrepared` fixture and tests; GC11: a1 rejection (N>1 requires `track_and_verify_wals_in_manifest`), fixture tracking, `ReadOnlyAndSecondaryApplyPartitionChecks`; GC07 Q5/Q6: version_set assertions, `WriteRecoverableState` bump, `PublishAboveAllocatedAsserts`, `ConcurrentRecoverableStateCaching` rewrite. Exception X11 (GC11 tracking line in GC06's OCC test lands here). GitHub migration (2026-10-23): `PublishAboveAllocatedAsserts` falls back to `::testing::GTEST_FLAG(death_test_style)` when `GTEST_FLAG_SET` is unavailable (upstream bundles googletest 1.8.1). Test-only. M3 fold: Absorbs - GC12 Q1: GetCurrentWalFile refuses at N>1 (and the db.h doc); the checkpoint WAL inclusion bound is the newest current WAL over every partition (NewestAliveWalNumber); checkpoint quiesces every write queue until the open WAL sizes are read. GC12 Q8: ReadOnlyCompactedOpenAppliesPartitionChecks (AMB-M3-12). GC12: PreparedHeap::push/erase keep the heap sorted under out-of-order prepares, with PreparedHeap.BasicsTest (exception X4, AMB-M3-1: here rather than D123476301, because WritePrepared already runs at N>1 in this diff). - GC14b Q2: ConcurrentPreparesAcrossPartitions enabled; fixture comment. - GC08 Q4: WalContext::sync_failed_wal_number, the first WALIOStatusCheck argument in WriteImpl, SwitchMemtable failure attribution, TEST_WalRecoveryCutoff (exception X5: the leadership-sync attribution is hand-ported into this diff's inline sync loop; D123971668 re-extracts it). GC08 Q5 reset-and-continue assert, Q8 ConcurrentRecoverableStateCaching with 20 releases, Q9 AssertLastSequenceCoversAllocated, Q10 CreateMutex before the parallel memtable writers. - GC14a Q6: checkpoint pins a LockWAL count when another thread holds LockWAL, and unlocks after the size read. - GC17 Q4 constructor line (wal_empties_), Q6 (snapshots_version_ atomic, UpdateSnapshots never stores an older list, OlderSnapshotListNeverWins), Q3 MalformedBatchFailsAsAtN1. Exceptions recorded: X1 (GC12's Q1 copy tests sit at D123928339), X4, X5. Test Plan: - Pinned-base gate: passed with one recorded discrepancy. HEAD was exactly 4b70127fb45f, `sl status` was clean, and `only(., public())` listed the 25 dispatched commits in the dispatched order. The base's own subject still carries `[Codex]` (prefix not stripped locally); the requester confirmed proceeding on the pinned hash. This diff is a new commit on top; nothing below it was amended. - Required suites, default dev mode (ASan/UBSan): `buck2 test` of db_write_test, db_wal_test, write_batch_test, transaction_test, db_basic_test, plus db_options_test (validation changed): passed, 5,631 tests, 0 failures/timeouts/build failures. No existing test was modified. - TSan (`@fbcode//mode/dev-tsan`), the five required suites: passed, 5,580 tests, 0 failures, no ThreadSanitizer reports. This includes the eight new N > 1 tests. - R1, appends overlap: `DBWritePartitionTest.PartitionLeadersAppendConcurrently` (16 partitions; two_write_queues off and on, and with two queues also through the nonmem queue): every write holds its WAL append open until all of them are inside one, and all 16 of 16 appends were in flight at once. Neuter verified: routing every writer to partition 0's queue makes the maximum 1 and the test fails. - R2, sequence order equals byte order per file: debug assertion `sequence > log_writer->last_sequence_consumed()` in WriteToWAL. `DBWritePartitionTest.SequenceOrderHoldsUnderConcurrentSwitches` runs 16 partitions with 16 writer threads x 200 writes (a quarter WAL-only with two queues), plus a thread issuing Flush(). db_write_buffer_size and max_total_wal_size are small, so leaders keep switching memtables and rotating all 16 WALs. The assertion held and every write reads back. Neuter verified: moving the two-queue sequence allocation outside WalWriteMutex(p) trips the assertion. - Switch gate: `DBWritePartitionTest.SwitchWaitsForOtherPartitionsLeaders` holds one partition's append open and has another partition's leader schedule and run a memtable switch; the switch starts only after the open append completes. Neuter verified: with CloseMemTableSwitchGate() a no-op, the switch runs while the append is open and the test fails. - R3: `DBWritePartitionTest.MemtableDecisionEnforcedAtOpen`: wal_partitions=4 with allow_concurrent_memtable_write=false is NotSupported naming that option, even with the test bypass of the general N > 1 rejection; with it true, Open sizes 4 partitions. The existing db_options_test still sees "wal_partitions > 1 is not supported yet" without the bypass. - R5, byte-identical WAL at one partition: opt-mode db_bench built from 4b70127fb45f and from this diff; fillseq + fillrandom, 5,000 ops each, one thread, compression off, avoid_flush_during_shutdown. Run on the default path, enable_pipelined_write, and two_write_queues (via an options file; the OPTIONS files confirmed each setting). Base and new WALs were byte-identical in all three, `cmp` clean, sha256 913a88100f64e31e5faa17c0c5101fb0c838e6777096afa6845a210fbb22ffbb, 690,143 bytes. - Blackbox crash test, dbg-mode db_stress rebuilt from this diff (asserts on), 600 s with a 60 s interval: - two_write_queues=0: 11 kill/reopen iterations, and the final verification and DB cleanup ran (the success path). The exit status was not captured because I killed its wrapper shell while restarting the other run; no error, assertion or traceback appears in the log. - two_write_queues=1 (with enable_blob_direct_write=0 and file_scope_wal_write_faults=0, because the crash script's sanitizer otherwise forces two queues off): 11 iterations, every one with --two_write_queues=1, exit 0. - Formatting: the repo-pinned clang-format (/usr/local/bin/clang-format 21.1.2) via clang-format-diff.py over every changed range of the submitted state leaves no changes. `arc f` reports "No linters to run" for this subtree. - `arc lint -a` on all nine files: no lint issues. - Not run: whitebox crash test (not required). The comparison against D122660502's join-wait histogram: wal_partitions > 1 cannot be opened outside tests until the completion gate exists, so no db_bench configuration exercises N > 1. Crash/recovery at N > 1: unsupported until 08 and multi-WAL recovery. CMake/Make, macOS and Windows builds. **After folding in round 12 / 12.1 (D124911745, D125113461):** - `buck2 test fbcode//internal_repo_rocksdb/repo:db_write_test fbcode//internal_repo_rocksdb/repo:error_handler_fs_test` at this commit: Pass 154, Fail 0 (https://www.internalfb.com/intern/testinfra/testrun/32088147390513887). - Neuter, TSan and byte-identity evidence for the folded-in items: see the Test Plans of D124911745 and D125113461. They ran on the same code, now split across this stack. M1 gate at fold: `db_write_test` 88/0, options matrix 55/0. 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. M2 fold: new or moved tests here: UnindexedWalPartitionsAlwaysRejected, WalPartitionsUpperBound, ReadOnlyAndSecondaryApplyPartitionChecks, PublishAboveAllocatedAsserts, ValidatePolicyAtNPartitions, WritePreparedPartitionedWalTest.*. B.1 at this diff (format check, `rocksdb_lib`, touched test targets): PASS; db_write_test + optimistic_transaction_test + write_prepared_transaction_test 1019 pass. M3 B.1 at this diff (clang-format 21.1.2 on its changed lines, make check-sources, debug build, touched test binaries): PASS; db_write_test + optimistic_transaction_test + write_prepared_transaction_test: 1017 pass. M5 fold: Absorbs 62 A.1 entries (GC28 18, GC27 5, GC30 1, GC31 16, GC33 9, GC29b 13): GC28 switch-gate counters (EnterMemTableSwitchGate(p)), JoinWaitTimerOffAtDefaultStatsLevel; GC31 Q1 flush path, Q2 (a) DB-stat shards (InternalStats), Q7 recoverable-state slots, A9; GC33 Q1 (WriteImpl's DB-stat adds: half of the frame restore) and Q3 (QuiescedWriteBufferManagerFlush, WriteBufferManagerFlushWouldAct, its two tests); GC29b T5 and comments; the N>1 option tests of GC27/GC30. M5-F1 (A.8): F1.4 (a) GetDBStats' single counter without shards, (b) the last leg of WbmFlushQuiesceSkippedWhenNothingToSwitch, (c) WriteImpl's comment without "as before GC31", (d) both Wbm tests bypass N>1. Exceptions: X13-M5 (the join-timer test); X14-M5 (WalPartitionsSetOptionsRuntimeConflicts); X32-M5: GC29b#677 (transaction_test.h JoinThreadsOnExit) moved here from D123551605, with its lowest users GC29b#678 and meta#679 (B.1: 'JoinThreadsOnExit' was not declared); X35-M5: GC27#119-meta#122 (MyTestCompactionService's options map and OpenAndCompactAtPartitionedPrimary, X3-M5) moved from D121858039 to D123079329: below D123079329 Open refuses N>1 with no testing hook (B.1); X36-M5: WalPartitionsOptionRefusalsUnchanged (GC30#245, with GC29b#616) moved from D123079329 to D123701876: the pipelined-write and paranoid_checks refusals it pins first exist here (B.1). Hand-splits (rows below the hunk's top row get their slice by a per-row edit): GC28#46 (AllocateSequenceAndWALIndex re-indent, H5): D119600943 takes the scope block, SequenceWalIndexLock, the Allocated sync point and re-indents its lines; D123079329 re-indents the three lines it brings in; D123476301 registers both trackers inside the scope; GC31#347 (db_impl.h test accessors): TEST_wals_total_size via WalsTotalSize() at D121858039, TEST_CachedRecoverableStateEmpty at D123079329, TEST_UnpublishedSyncGroups at D123551605. X14-M5 hook (rule 2.4): the AllowWalPartitions callback before the first N>1 open of DBWriteTestUnparameterized.WalPartitionsSetOptionsRuntimeConflicts and CompactionServiceTest.OpenAndCompactAtPartitionedPrimary (the latter found by B.1); FLIP removes it. M5 B.1: PASS (clang-format 21.1.2 on the changed lines, make check-sources, debug build of compaction_service_test, db_write_test, optimistic_transaction_test, write_prepared_transaction_test); 1090 tests, 0 failed. M6 fold: Absorbs GC34 Q5 and the stack-owner follow-up: the file-scope `test_holds_abandoned` flag and `WaitForReleaseOrAbandon` (every `GC28Hold` hold lets its thread go once a still-running `DBWalAppendFailureTest::Writer` is unwound; arming clears the flag); `write_prepared_transaction_test` `OlderSnapshotListNeverWins` fails instead of terminating. M6 B.1: PASS (debug build and build_tools/gtest-parallel run of compaction_service_test db_write_test optimistic_transaction_test write_prepared_transaction_test: 1090/1090). Reviewers: #rocksdb, anand76, jewoongh, rbanerjee2 Subscribers: jewoongh, rbanerjee2 Differential Revision: https://phabricator.intern.facebook.com/D123079329
JustinGaoF
added a commit
to JustinGaoF/rocksdb
that referenced
this pull request
Nov 10, 2026
Summary: The diff works to provide container of the WAL files handler to replace existing one wal file. Stack: this diff sits on D117280372 with the write-path prep stack on D119751506 (per author direction; the prep content is unchanged from the D120171238-based version, and the base delta is read-path/test/comment-only, see Test Plan). `DBImpl::logs_` and `DBImpl::alive_wal_files_` become one deque per WAL partition: `std::vector<std::deque<...>>`, sized 1 at construction. `wal_partitions > 1` is still rejected at Open, `SelectWalForWrite()` remains the only WAL-selection seam, and no public header, option, or on-disk format changes. Write-path point accesses bind partition 0; walks (obsolete-file selection, sync bookkeeping, size accounting, close) loop partitions in ascending index order under the same locks as before. Locking documentation: the numbered cases are unchanged in content but reframed from "the deque" to "partition p's deque" under an explicit two-level split (the vectors are sized at construction and never resized, so they need no lock; every deque access holds the same global mutexes as before, since mutex splitting is out of scope). The back()/getting_synced observations are scoped to one partition's deque. Enforcement is mechanical where it can be: all access goes through the `WalLogs(p)` / `AliveWalFiles(p)` / `NumWalPartitions()` chokepoint with bounds and equal-length asserts, replacing direct member uses; the container abstraction itself still lands later once real N-partition usage is known. Lifetime: each partition's deque keeps independent per-entry bookkeeping and removal stays per-entry (pop/erase), so a future reference-driven scheme can replace per-entry removal without reshaping; element addresses stay stable (deque elements never move, vectors never resized), which is what `CurrentWal()` references and `WalContext::wal_file_number_size` pointers rely on. This diff also carries a one-word rebase-merge correction that belongs to the D117251771 rebase (`ConcurrentWriteGroupToWAL`'s cover call referenced `log_writer`, which the WalContext refactor removed; it now passes `wal_context.writer` like the two sibling sites). It lands here instead of in that diff per the no-touch rule for existing diffs; the rebased intermediate does not compile without it. Behaviour preservation: the change is semantics-preserving by construction (same deque objects, same lock holds, loops run once), so most hunks have no neuter check available. Neutered instead: forcing `NumWalPartitions()` to 0 fails 8 `db_wal_test` tests (sync and WAL-lifecycle coverage incl. the new test below), proving the loops are load-bearing. No existing test caught a mistake during the change itself: the first full-matrix run passed, and the one real defect found (the `log_writer` merge breakage above) was caught by the compiler. New coverage is one pinning test, `DBWALTest.SingleWalPartition`, asserting exactly one partition across open, write, WAL roll, flush, and reopen; all existing tests pass unmodified. Test Plan: `buck2 test fbcode//internal_repo_rocksdb/repo:db_wal_test fbcode//internal_repo_rocksdb/repo:db_write_test fbcode//internal_repo_rocksdb/repo:db_basic_test fbcode//internal_repo_rocksdb/repo:db_flush_test fbcode//internal_repo_rocksdb/repo:db_options_test fbcode//internal_repo_rocksdb/repo:repair_test fbcode//internal_repo_rocksdb/repo:log_test` - Pass 2888, Fail 0 on the submitted base. Targeted locking-route runs: `DBWALTest.SingleWalPartition`, `DBWALTest.WALWriteErrorNoRecovery`, `DBWALIndexTest.TwoWriteQueuesIsRejected`, `DBBasicTest.EmptyFlush` (all option configs incl. two_write_queues on), `DBBasicTest.DBCloseFlushError`, `DBBasicTest.ReadOnlyDBFlushWAL`, `DBWriteTestUnparameterized.PipelinedWriteRace` - all pass. Neuter (`NumWalPartitions()` forced to 0): 8 `db_wal_test` failures, reverted with byte-identical diff. R5 WAL byte comparison: fixed `db_bench fillseq` workload (num=20000, seed=12345) run against parent and new binaries - WAL bytes identical for `partition_wal_usage=none` and `record_ordering_single_file` (self-consistency verified first), identical Open rejection for `partition_by_column_family`; evidence gathered on D120171238-based binaries, and the move to D119751506 only drops a read-path/test/comment-only delta (reader validation, `log_test` cases, comment-only `log_writer.h`) touching none of this diff's files nor the write path, so the conclusion transfers - happy to re-run on request. 180s blackbox crash test with `--partition_wal_usage=record_ordering_single_file` on `db_stress` rebuilt from this commit: passed. `arc lint -a`: clean. `clang-format --dry-run --Werror` (v21.1.2, repo `.clang-format`): clean on all touched lines (two remaining violations are pre-existing rebase lines outside this diff). M3 B.1 at this diff (clang-format 21.1.2 on its changed lines, make check-sources, debug build, touched test binaries): PASS; db_wal_test: 2059 pass. M5 fold: Absorbs 9 A.1 entries (GC31 8, GC33 1): GC31 Q2 (b) per-partition wals_total_size_ (WalsTotalSizeCounter, wal_partition_sizes_, readers, open reset); GC33's N=1 WalsTotalSize; GC27's compaction-service secondary test. Not here after B.1: GC27's compaction-service test and its helper go to D123079329 (X35-M5). Exceptions: X3-M5 (the test); X17-M5 (the WriteToWAL account at D122274088; X35-M5: GC27#119-meta#122 (MyTestCompactionService's options map and OpenAndCompactAtPartitionedPrimary, X3-M5) moved from D121858039 to D123079329: below D123079329 Open refuses N>1 with no testing hook (B.1). Hand-splits (rows below the hunk's top row get their slice by a per-row edit): GC31#347 (db_impl.h test accessors): TEST_wals_total_size via WalsTotalSize() at D121858039, TEST_CachedRecoverableStateEmpty at D123079329, TEST_UnpublishedSyncGroups at D123551605. M5 B.1: PASS (clang-format 21.1.2 on the changed lines, make check-sources, debug build of db_wal_test); 2062 tests, 0 failed. Differential Revision: https://phabricator.intern.facebook.com/D121858039
JustinGaoF
added a commit
to JustinGaoF/rocksdb
that referenced
this pull request
Nov 10, 2026
Summary: Reviewer question: is the memtable-switch gate sufficient to exclude every other partition's leader from a memtable/WAL switch -- a leader enters it in PreprocessWrite() before binding a WAL and leaves it only when its group exits (including the parallel-follower and unordered_write exits), and a leader that must switch closes it from PreprocessWrite() before entering, so no leader ever waits on itself? **Blocked decisions** 1. M0.8, route-then-group: already decided and implemented by D122869562; not reopened. Each writer carries the route resolved once in WriteImpl and joins the queue of that partition. Reversing it (group-then-route) would need WriteThread to release leadership between WAL selection and the append. 2. Memtable fork: **A, allow_concurrent_memtable_write.** N leaders insert into the same memtables, and A needs no new lock or lock ordering. It keeps unordered_write working (which requires A), and B's serialization cost does not need measuring because nothing is serialized. Its cost: wal_partitions > 1 requires a SkipList memtable, and enable_blob_direct_write cannot be combined with it (ColumnFamilyData::ValidateOptions already rejects blob direct write with concurrent memtable writes). Enforced at Open: wal_partitions > 1 with allow_concurrent_memtable_write=false is now NotSupported, and this check runs before the general wal_partitions > 1 rejection, so it is reachable and tested. Reversing to B: drop that Open check, give each leader a memtable-insert lock around its insert at N > 1 (and let single-writer groups insert serially again), and reject unordered_write at N > 1 instead. **Why** Routing (D122869562) decides which WAL a write binds to, but every writer still joins the one write_thread_, so writers to different partitions are still serialized behind one leader. D122660502's 36.8 ms join-wait tail is unrelieved. This diff makes N > 1 mean N concurrent leaders, each appending to its own WAL. **Previous behavior** One WriteThread write_thread_ and one nonmem_write_thread_. The per-partition containers were always sized 1: Open created partition 0's WAL only, and SwitchMemtable rotated partition 0 only. At N > 1 the default write path also read LastSequence() as its allocation, published with SetLastSequence() (which asserts monotonicity), and inserted single-writer groups with concurrent_memtable_writes=false -- all of which assume one leader. **New behavior (only at N > 1, still unreachable outside tests)** - One WriteThread and one nonmem WriteThread per partition (write_threads_/nonmem_write_threads_, sized with the other partition containers in the constructor). A writer joins its routed partition's queue, so each partition has its own newest_writer_ and leader. There is no cross-partition election. - One log::Writer per partition: Open creates N WALs and SwitchMemtable rotates all N together, under all N WAL write mutexes. Partition 0 keeps the lowest number of each generation, so cur_wal_number_, memtable NextLogNumber and obsolescence keep their meaning. - Sequence allocation stays inside each partition's leader critical section. The default (!two_write_queues) path allocates through AllocateSequenceAndWALIndex, the counter the WAL-index path and both two_write_queues queues already use, so sequences and wal_index stay unique across partitions and queues. The two-queue path still allocates under WalWriteMutex(p), which both queues of a partition share. - Every leader inserts in concurrent mode (forced parallel path), because other partitions insert into the same memtables. - Memtable-switch gate: PreprocessWrite()'s SwitchWAL / HandleWriteBufferManagerFlush / ScheduleFlushes close the gate and wait for leaders past it. Callers outside the write path (flush, SetOptions, CF create/drop, ingestion, LockWAL, ResumeImpl, ...) enter every partition's queue unbatched in ascending order (AllPartitionsWriter). - Publication: PublishLastSequence() skips a publish a higher one already overtook (CAS-max), so LastSequence() never moves backwards. Publication order is not established here (see limitations). - Stalls and delays act on the leader's own partition queue; UnlockWAL and WaitForPendingWrites cover every queue. **Neuter checks at one partition (R5)** NumWalPartitions() == 1 returns from all four gate functions immediately; `parallel` keeps `write_group.size > 1`; the allocator condition reduces to WALIndexEnabled; PublishLastSequence calls SetLastSequence; stats keep `concurrent = two_write_queues_`; the constructor's resize, Open's extra-WAL loop, SwitchMemtable's extra-WAL loops and its any-partition-non-empty loop are all empty; AllWalWriteMutexesLock in SwitchMemtable takes exactly WalWriteMutex(0); AllPartitionsWriter uses an inline writer for partition 0, with no allocation, i.e. the same single EnterUnbatched as before. The R2 assertion and its per-file tracker are debug-only. Changes without a neuter: last_batch_group_size_ is now RelaxedAtomic (relaxed load/store); IsMainWriteThread replaces `&write_thread == &write_thread_` with one comparison at N=1; UnlockWAL keeps its stall counts in two size-1 vectors (a cold path); WriteToWAL/WriteGroupToWAL take a sequence_count used only by the debug assertion. None of these changes control flow or WAL bytes at N=1. **Safety, compatibility, limitations** - wal_partitions > 1 remains rejected at Open. Tests reach N > 1 only through the debug sync point DBImpl::ValidateOptions:AllowWalPartitions. Read-only and secondary instances always size to one partition. No public header changes. - Deferred to follow-up diffs, as agreed, and unsafe at N > 1 until then: publication order (a reader can see sequence S before a lower sequence from another partition is inserted, much like unordered_write's visibility); enable_pipelined_write (per-WriteThread last_sequence_ allocation, ordered SetLastSequence); sync=true writes (one leader syncs every partition's files while other partitions append); WBWI ingestion (switches memtables inside a gated leader); Merge batches (still inserted non-concurrently because of max_successive_merges); cached_recoverable_state_ without two_write_queues; timed write delays now run per partition in parallel; WALIOStatusCheck resets partition 0's writer on non-paranoid errors. None of these configurations is rejected: the coordination they need belongs to the follow-ups. - Durability watermark (07), completion gate (08) and multi-WAL recovery are out of scope. A crash at N > 1 can leave holes, and reopening an N > 1 DB is not supported. - Adaptive yield is unchanged: WriteThread's AdaptationContexts are file-scope statics shared by every instance, so they already adapt to aggregate traffic rather than to one queue's 1/N share. **Folded in from round 12 (D124911745)** Merge batches and WBWI ingestion are no longer deferred; this replaces those two items under limitations. Every N>1 memtable insert is now concurrent-safe: - Merge batches stay on the parallel insert path at N>1 (`assert(parallel || N==1)`). Rejecting `max_successive_merges>0` covers the only part of Merge that isn't concurrent-safe. - `IngestWriteBatchWithIndex` is rejected at runtime in `WriteImpl` at N>1 (`assert(N==1)` in `IngestWBWIAsMemtable`). - At N>1, Open rejects `max_successive_merges>0` and non-SkipList memtables. VectorRep passes the generic concurrent check, so only this new guard rejects it. - Tests: `MergeBatchesInsertConcurrentlyAcrossPartitions`, `IngestWriteBatchWithIndexRejectedAtNPartitions`, `ConcurrentUnsafeConfigsRejectedAtOpen` (4 rejects + control), `N1ConcurrentUnsafeOptionsStillAccepted`. - Neuters: revert the Merge guard -> the `parallel || N==1` assert aborts. Revert the WBWI check -> the `N==1` assert aborts. Revert the CF guards -> the vector_rep and merges cases open -> fail. M1: Absorbs 14 entries: GC13 Q1 gate opt-in + `WalPartitionsTestingOptIn`, Q3 ingestion stall + test, Q4 asserts; GC15 Q6 import stall + test, Q7 asserts (AMB-10 comment line lives in D123701876; SilentAtN1 lives in D123551605). M2 fold (2026-10-22, `M2-FoldTasks.md` + `M2-Amendment.md`): Absorbs (M2) GC06 Q2-Q5/Q8: option rejections, `WriteWithCallback` and OCC rejections, fixture, `UnindexedWalPartitionsAlwaysRejected`, `WalPartitionsUpperBound`, `ValidatePolicyAtNPartitions`, bypasses; GC10 Q1-Q4: recoverable-state cache, per-partition group size, WBM stall, `DelayWrite` arg, `WritePrepared` fixture and tests; GC11: a1 rejection (N>1 requires `track_and_verify_wals_in_manifest`), fixture tracking, `ReadOnlyAndSecondaryApplyPartitionChecks`; GC07 Q5/Q6: version_set assertions, `WriteRecoverableState` bump, `PublishAboveAllocatedAsserts`, `ConcurrentRecoverableStateCaching` rewrite. Exception X11 (GC11 tracking line in GC06's OCC test lands here). GitHub migration (2026-10-23): `PublishAboveAllocatedAsserts` falls back to `::testing::GTEST_FLAG(death_test_style)` when `GTEST_FLAG_SET` is unavailable (upstream bundles googletest 1.8.1). Test-only. M3 fold: Absorbs - GC12 Q1: GetCurrentWalFile refuses at N>1 (and the db.h doc); the checkpoint WAL inclusion bound is the newest current WAL over every partition (NewestAliveWalNumber); checkpoint quiesces every write queue until the open WAL sizes are read. GC12 Q8: ReadOnlyCompactedOpenAppliesPartitionChecks (AMB-M3-12). GC12: PreparedHeap::push/erase keep the heap sorted under out-of-order prepares, with PreparedHeap.BasicsTest (exception X4, AMB-M3-1: here rather than D123476301, because WritePrepared already runs at N>1 in this diff). - GC14b Q2: ConcurrentPreparesAcrossPartitions enabled; fixture comment. - GC08 Q4: WalContext::sync_failed_wal_number, the first WALIOStatusCheck argument in WriteImpl, SwitchMemtable failure attribution, TEST_WalRecoveryCutoff (exception X5: the leadership-sync attribution is hand-ported into this diff's inline sync loop; D123971668 re-extracts it). GC08 Q5 reset-and-continue assert, Q8 ConcurrentRecoverableStateCaching with 20 releases, Q9 AssertLastSequenceCoversAllocated, Q10 CreateMutex before the parallel memtable writers. - GC14a Q6: checkpoint pins a LockWAL count when another thread holds LockWAL, and unlocks after the size read. - GC17 Q4 constructor line (wal_empties_), Q6 (snapshots_version_ atomic, UpdateSnapshots never stores an older list, OlderSnapshotListNeverWins), Q3 MalformedBatchFailsAsAtN1. Exceptions recorded: X1 (GC12's Q1 copy tests sit at D123928339), X4, X5. Test Plan: - Pinned-base gate: passed with one recorded discrepancy. HEAD was exactly 4b70127fb45f, `sl status` was clean, and `only(., public())` listed the 25 dispatched commits in the dispatched order. The base's own subject still carries `[Codex]` (prefix not stripped locally); the requester confirmed proceeding on the pinned hash. This diff is a new commit on top; nothing below it was amended. - Required suites, default dev mode (ASan/UBSan): `buck2 test` of db_write_test, db_wal_test, write_batch_test, transaction_test, db_basic_test, plus db_options_test (validation changed): passed, 5,631 tests, 0 failures/timeouts/build failures. No existing test was modified. - TSan (`@fbcode//mode/dev-tsan`), the five required suites: passed, 5,580 tests, 0 failures, no ThreadSanitizer reports. This includes the eight new N > 1 tests. - R1, appends overlap: `DBWritePartitionTest.PartitionLeadersAppendConcurrently` (16 partitions; two_write_queues off and on, and with two queues also through the nonmem queue): every write holds its WAL append open until all of them are inside one, and all 16 of 16 appends were in flight at once. Neuter verified: routing every writer to partition 0's queue makes the maximum 1 and the test fails. - R2, sequence order equals byte order per file: debug assertion `sequence > log_writer->last_sequence_consumed()` in WriteToWAL. `DBWritePartitionTest.SequenceOrderHoldsUnderConcurrentSwitches` runs 16 partitions with 16 writer threads x 200 writes (a quarter WAL-only with two queues), plus a thread issuing Flush(). db_write_buffer_size and max_total_wal_size are small, so leaders keep switching memtables and rotating all 16 WALs. The assertion held and every write reads back. Neuter verified: moving the two-queue sequence allocation outside WalWriteMutex(p) trips the assertion. - Switch gate: `DBWritePartitionTest.SwitchWaitsForOtherPartitionsLeaders` holds one partition's append open and has another partition's leader schedule and run a memtable switch; the switch starts only after the open append completes. Neuter verified: with CloseMemTableSwitchGate() a no-op, the switch runs while the append is open and the test fails. - R3: `DBWritePartitionTest.MemtableDecisionEnforcedAtOpen`: wal_partitions=4 with allow_concurrent_memtable_write=false is NotSupported naming that option, even with the test bypass of the general N > 1 rejection; with it true, Open sizes 4 partitions. The existing db_options_test still sees "wal_partitions > 1 is not supported yet" without the bypass. - R5, byte-identical WAL at one partition: opt-mode db_bench built from 4b70127fb45f and from this diff; fillseq + fillrandom, 5,000 ops each, one thread, compression off, avoid_flush_during_shutdown. Run on the default path, enable_pipelined_write, and two_write_queues (via an options file; the OPTIONS files confirmed each setting). Base and new WALs were byte-identical in all three, `cmp` clean, sha256 913a88100f64e31e5faa17c0c5101fb0c838e6777096afa6845a210fbb22ffbb, 690,143 bytes. - Blackbox crash test, dbg-mode db_stress rebuilt from this diff (asserts on), 600 s with a 60 s interval: - two_write_queues=0: 11 kill/reopen iterations, and the final verification and DB cleanup ran (the success path). The exit status was not captured because I killed its wrapper shell while restarting the other run; no error, assertion or traceback appears in the log. - two_write_queues=1 (with enable_blob_direct_write=0 and file_scope_wal_write_faults=0, because the crash script's sanitizer otherwise forces two queues off): 11 iterations, every one with --two_write_queues=1, exit 0. - Formatting: the repo-pinned clang-format (/usr/local/bin/clang-format 21.1.2) via clang-format-diff.py over every changed range of the submitted state leaves no changes. `arc f` reports "No linters to run" for this subtree. - `arc lint -a` on all nine files: no lint issues. - Not run: whitebox crash test (not required). The comparison against D122660502's join-wait histogram: wal_partitions > 1 cannot be opened outside tests until the completion gate exists, so no db_bench configuration exercises N > 1. Crash/recovery at N > 1: unsupported until 08 and multi-WAL recovery. CMake/Make, macOS and Windows builds. **After folding in round 12 / 12.1 (D124911745, D125113461):** - `buck2 test fbcode//internal_repo_rocksdb/repo:db_write_test fbcode//internal_repo_rocksdb/repo:error_handler_fs_test` at this commit: Pass 154, Fail 0 (https://www.internalfb.com/intern/testinfra/testrun/32088147390513887). - Neuter, TSan and byte-identity evidence for the folded-in items: see the Test Plans of D124911745 and D125113461. They ran on the same code, now split across this stack. M1 gate at fold: `db_write_test` 88/0, options matrix 55/0. 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. M2 fold: new or moved tests here: UnindexedWalPartitionsAlwaysRejected, WalPartitionsUpperBound, ReadOnlyAndSecondaryApplyPartitionChecks, PublishAboveAllocatedAsserts, ValidatePolicyAtNPartitions, WritePreparedPartitionedWalTest.*. B.1 at this diff (format check, `rocksdb_lib`, touched test targets): PASS; db_write_test + optimistic_transaction_test + write_prepared_transaction_test 1019 pass. M3 B.1 at this diff (clang-format 21.1.2 on its changed lines, make check-sources, debug build, touched test binaries): PASS; db_write_test + optimistic_transaction_test + write_prepared_transaction_test: 1017 pass. M5 fold: Absorbs 62 A.1 entries (GC28 18, GC27 5, GC30 1, GC31 16, GC33 9, GC29b 13): GC28 switch-gate counters (EnterMemTableSwitchGate(p)), JoinWaitTimerOffAtDefaultStatsLevel; GC31 Q1 flush path, Q2 (a) DB-stat shards (InternalStats), Q7 recoverable-state slots, A9; GC33 Q1 (WriteImpl's DB-stat adds: half of the frame restore) and Q3 (QuiescedWriteBufferManagerFlush, WriteBufferManagerFlushWouldAct, its two tests); GC29b T5 and comments; the N>1 option tests of GC27/GC30. M5-F1 (A.8): F1.4 (a) GetDBStats' single counter without shards, (b) the last leg of WbmFlushQuiesceSkippedWhenNothingToSwitch, (c) WriteImpl's comment without "as before GC31", (d) both Wbm tests bypass N>1. Exceptions: X13-M5 (the join-timer test); X14-M5 (WalPartitionsSetOptionsRuntimeConflicts); X32-M5: GC29b#677 (transaction_test.h JoinThreadsOnExit) moved here from D123551605, with its lowest users GC29b#678 and meta#679 (B.1: 'JoinThreadsOnExit' was not declared); X35-M5: GC27#119-meta#122 (MyTestCompactionService's options map and OpenAndCompactAtPartitionedPrimary, X3-M5) moved from D121858039 to D123079329: below D123079329 Open refuses N>1 with no testing hook (B.1); X36-M5: WalPartitionsOptionRefusalsUnchanged (GC30#245, with GC29b#616) moved from D123079329 to D123701876: the pipelined-write and paranoid_checks refusals it pins first exist here (B.1). Hand-splits (rows below the hunk's top row get their slice by a per-row edit): GC28#46 (AllocateSequenceAndWALIndex re-indent, H5): D119600943 takes the scope block, SequenceWalIndexLock, the Allocated sync point and re-indents its lines; D123079329 re-indents the three lines it brings in; D123476301 registers both trackers inside the scope; GC31#347 (db_impl.h test accessors): TEST_wals_total_size via WalsTotalSize() at D121858039, TEST_CachedRecoverableStateEmpty at D123079329, TEST_UnpublishedSyncGroups at D123551605. X14-M5 hook (rule 2.4): the AllowWalPartitions callback before the first N>1 open of DBWriteTestUnparameterized.WalPartitionsSetOptionsRuntimeConflicts and CompactionServiceTest.OpenAndCompactAtPartitionedPrimary (the latter found by B.1); FLIP removes it. M5 B.1: PASS (clang-format 21.1.2 on the changed lines, make check-sources, debug build of compaction_service_test, db_write_test, optimistic_transaction_test, write_prepared_transaction_test); 1090 tests, 0 failed. M6 fold: Absorbs GC34 Q5 and the stack-owner follow-up: the file-scope `test_holds_abandoned` flag and `WaitForReleaseOrAbandon` (every `GC28Hold` hold lets its thread go once a still-running `DBWalAppendFailureTest::Writer` is unwound; arming clears the flag); `write_prepared_transaction_test` `OlderSnapshotListNeverWins` fails instead of terminating. M6 B.1: PASS (debug build and build_tools/gtest-parallel run of compaction_service_test db_write_test optimistic_transaction_test write_prepared_transaction_test: 1090/1090). Reviewers: #rocksdb, anand76, jewoongh, rbanerjee2 Subscribers: jewoongh, rbanerjee2 Differential Revision: https://phabricator.intern.facebook.com/D123079329
JustinGaoF
added a commit
to JustinGaoF/rocksdb
that referenced
this pull request
Nov 19, 2026
Summary: The diff works to provide container of the WAL files handler to replace existing one wal file. Stack: this diff sits on D117280372; the write-path prep stack (D117251769..D117280372) sits on D121674557. `DBImpl::logs_` and `DBImpl::alive_wal_files_` become one deque per WAL partition: `std::vector<std::deque<...>>`, sized 1 at construction. `wal_partitions > 1` is still rejected at Open, `SelectWalForWrite()` remains the only WAL-selection seam, and no public header, option, or on-disk format changes. Write-path point accesses bind partition 0; walks (obsolete-file selection, sync bookkeeping, size accounting, close) loop partitions in ascending index order under the same locks as before. Locking documentation: the numbered cases are unchanged in content but reframed from "the deque" to "partition p's deque" under an explicit two-level split (the vectors are sized at construction and never resized, so they need no lock; every deque access holds the same global mutexes as before, since mutex splitting is out of scope). The back()/getting_synced observations are scoped to one partition's deque. Enforcement is mechanical where it can be: all access goes through the `WalLogs(p)` / `AliveWalFiles(p)` / `NumWalPartitions()` chokepoint with bounds and equal-length asserts, replacing direct member uses; the container abstraction itself still lands later once real N-partition usage is known. Lifetime: each partition's deque keeps independent per-entry bookkeeping and removal stays per-entry (pop/erase), so a future reference-driven scheme can replace per-entry removal without reshaping; element addresses stay stable (deque elements never move, vectors never resized), which is what `CurrentWal()` references and `WalContext::wal_file_number_size` pointers rely on. Behaviour preservation: the change is semantics-preserving by construction (same deque objects, same lock holds, loops run once), so most hunks have no neuter check available. Neutered instead: forcing `NumWalPartitions()` to 0 fails 8 `db_wal_test` tests (sync and WAL-lifecycle coverage incl. the new test below), proving the loops are load-bearing. No existing test caught a mistake during the change itself: the first full-matrix run passed. New coverage is one pinning test, `DBWALTest.SingleWalPartition`, asserting exactly one partition across open, write, WAL roll, flush, and reopen; all existing tests pass unmodified. Size accounting: `wals_total_size_` stays partition 0's counter, and `wal_partition_sizes_` adds one cache-line-padded counter for each further partition (`WalsTotalSizeCounter(p)`). Readers (`WalsTotalSize()`, used by the max_total_wal_size check, the atomic-flush error path and `TEST_wals_total_size()`) sum them, and `RestoreAliveLogFiles` resets them all. At one partition `wal_partition_sizes_` is empty and the read is the old single relaxed load. `TEST_NumWalPartitions()` is added for the new test. Test Plan: `buck2 test fbcode//internal_repo_rocksdb/repo:db_wal_test fbcode//internal_repo_rocksdb/repo:db_write_test fbcode//internal_repo_rocksdb/repo:db_basic_test fbcode//internal_repo_rocksdb/repo:db_flush_test fbcode//internal_repo_rocksdb/repo:db_options_test fbcode//internal_repo_rocksdb/repo:repair_test fbcode//internal_repo_rocksdb/repo:log_test` - Pass 2888, Fail 0 on the submitted base. Targeted locking-route runs: `DBWALTest.SingleWalPartition`, `DBWALTest.WALWriteErrorNoRecovery`, `DBWALIndexTest.TwoWriteQueuesIsRejected`, `DBBasicTest.EmptyFlush` (all option configs incl. two_write_queues on), `DBBasicTest.DBCloseFlushError`, `DBBasicTest.ReadOnlyDBFlushWAL`, `DBWriteTestUnparameterized.PipelinedWriteRace` - all pass. Neuter (`NumWalPartitions()` forced to 0): 8 `db_wal_test` failures, reverted with byte-identical diff. R5 WAL byte comparison: fixed `db_bench fillseq` workload (num=20000, seed=12345) run against parent and new binaries - WAL bytes identical for `partition_wal_usage=none` and `record_ordering_single_file` (self-consistency verified first), identical Open rejection for `partition_by_column_family`; evidence gathered on D120171238-based binaries, and the move to D119751506 only drops a read-path/test/comment-only delta (reader validation, `log_test` cases, comment-only `log_writer.h`) touching none of this diff's files nor the write path, so the conclusion transfers - happy to re-run on request. 180s blackbox crash test with `--partition_wal_usage=record_ordering_single_file` on `db_stress` rebuilt from this commit: passed. `arc lint -a`: clean. `clang-format --dry-run --Werror` (v21.1.2, repo `.clang-format`): clean on all touched lines (two remaining violations are pre-existing rebase lines outside this diff). M3 B.1 at this diff (clang-format 21.1.2 on its changed lines, make check-sources, debug build, touched test binaries): PASS; db_wal_test: 2059 pass. M5 fold: Absorbs 9 A.1 entries (GC31 8, GC33 1): GC31 Q2 (b) per-partition wals_total_size_ (WalsTotalSizeCounter, wal_partition_sizes_, readers, open reset); GC33's N=1 WalsTotalSize; GC27's compaction-service secondary test. Not here after B.1: GC27's compaction-service test and its helper go to D123079329 (X35-M5). Exceptions: X3-M5 (the test); X17-M5 (the WriteToWAL account at D122274088; X35-M5: GC27#119-meta#122 (MyTestCompactionService's options map and OpenAndCompactAtPartitionedPrimary, X3-M5) moved from D121858039 to D123079329: below D123079329 Open refuses N>1 with no testing hook (B.1). Hand-splits (rows below the hunk's top row get their slice by a per-row edit): GC31#347 (db_impl.h test accessors): TEST_wals_total_size via WalsTotalSize() at D121858039, TEST_CachedRecoverableStateEmpty at D123079329, TEST_UnpublishedSyncGroups at D123551605. M5 B.1: PASS (clang-format 21.1.2 on the changed lines, make check-sources, debug build of db_wal_test); 2062 tests, 0 failed. Differential Revision: https://phabricator.intern.facebook.com/D121858039
JustinGaoF
added a commit
to JustinGaoF/rocksdb
that referenced
this pull request
Nov 19, 2026
Summary: Reviewer question: is the memtable-switch gate sufficient to exclude every other partition's leader from a memtable/WAL switch -- a leader enters it in PreprocessWrite() before binding a WAL and leaves it only when its group exits (including the parallel-follower and unordered_write exits), and a leader that must switch closes it from PreprocessWrite() before entering, so no leader ever waits on itself? **Blocked decisions** 1. M0.8, route-then-group: already decided and implemented by D122869562; not reopened. Each writer carries the route resolved once in WriteImpl and joins the queue of that partition. Reversing it (group-then-route) would need WriteThread to release leadership between WAL selection and the append. 2. Memtable fork: **A, allow_concurrent_memtable_write.** N leaders insert into the same memtables, and A needs no new lock or lock ordering. B's serialization cost does not need measuring because nothing is serialized. unordered_write, which would also need A, is rejected at N > 1 in this diff. Its cost: wal_partitions > 1 requires a SkipList memtable, and enable_blob_direct_write cannot be combined with it (ColumnFamilyData::ValidateOptions already rejects blob direct write with concurrent memtable writes). Enforced at Open: wal_partitions > 1 with allow_concurrent_memtable_write=false is now NotSupported, and this check runs before the general wal_partitions > 1 rejection, so it is reachable and tested. Reversing to B: drop that Open check, give each leader a memtable-insert lock around its insert at N > 1 (and let single-writer groups insert serially again), and keep the unordered_write rejection at N > 1. **Why** Routing (D122869562) decides which WAL a write binds to, but every writer still joins the one write_thread_, so writers to different partitions are still serialized behind one leader. D122660502's 36.8 ms join-wait tail is unrelieved. This diff makes N > 1 mean N concurrent leaders, each appending to its own WAL. **Previous behavior** One WriteThread write_thread_ and one nonmem_write_thread_. The per-partition containers were always sized 1: Open created partition 0's WAL only, and SwitchMemtable rotated partition 0 only. At N > 1 the default write path also read LastSequence() as its allocation, published with SetLastSequence() (which asserts monotonicity), and inserted single-writer groups with concurrent_memtable_writes=false -- all of which assume one leader. **New behavior (only at N > 1, still unreachable outside tests)** - One WriteThread and one nonmem WriteThread per partition (write_threads_/nonmem_write_threads_, sized with the other partition containers in the constructor). A writer joins its routed partition's queue, so each partition has its own newest_writer_ and leader. There is no cross-partition election. - One log::Writer per partition: Open creates N WALs and SwitchMemtable rotates all N together, under all N WAL write mutexes. Partition 0 keeps the lowest number of each generation, so cur_wal_number_, memtable NextLogNumber and obsolescence keep their meaning. - Sequence allocation stays inside each partition's leader critical section. The default (!two_write_queues) path allocates through AllocateSequenceAndWALIndex, the counter the WAL-index path already uses, so sequences and wal_index stay unique across partitions. two_write_queues is rejected at N > 1 for every partition_wal_usage, because N > 1 requires indexed WALs and indexed WALs already reject two_write_queues. - Every leader inserts in concurrent mode (forced parallel path), because other partitions insert into the same memtables. - Memtable-switch gate: PreprocessWrite()'s SwitchWAL / HandleWriteBufferManagerFlush / ScheduleFlushes close the gate and wait for leaders past it. Callers outside the write path (flush, SetOptions, CF create/drop, ingestion, LockWAL, ResumeImpl, ...) enter every partition's queue unbatched in ascending order (AllPartitionsWriter). - Publication: PublishLastSequence() skips a publish a higher one already overtook (CAS-max), so LastSequence() never moves backwards. Publication order is not established here (see limitations). - Stalls and delays act on the leader's own partition queue; UnlockWAL and WaitForPendingWrites cover every queue. **Neuter checks at one partition (R5)** NumWalPartitions() == 1 returns from all four gate functions immediately; `parallel` keeps `write_group.size > 1`; the allocator condition reduces to WALIndexEnabled; PublishLastSequence calls SetLastSequence; stats keep `concurrent = two_write_queues_`; the constructor's resize, Open's extra-WAL loop, SwitchMemtable's extra-WAL loops and its any-partition-non-empty loop are all empty; AllWalWriteMutexesLock in SwitchMemtable takes exactly WalWriteMutex(0); AllPartitionsWriter uses an inline writer for partition 0, with no allocation, i.e. the same single EnterUnbatched as before. The R2 assertion and its per-file tracker are debug-only. Changes without a neuter: last_batch_group_size_ becomes one RelaxedAtomic per partition (relaxed load/store); IsMainWriteThread replaces `&write_thread == &write_thread_` with one comparison at N=1; UnlockWAL keeps its stall counts in two size-1 vectors (a cold path); WriteToWAL/WriteGroupToWAL take a sequence_count used only by the debug assertion. None of these changes control flow or WAL bytes at N=1. **Safety, compatibility, limitations** - wal_partitions > 1 remains rejected at Open. Tests reach N > 1 only through experimental_allow_wal_partitions_for_testing (indexed partition_wal_usage only) or the debug sync point DBImpl::ValidateOptions:AllowWalPartitions. Read-only and secondary instances always size to one partition. The only public header change is a note in include/rocksdb/db.h that GetCurrentWalFile returns NotSupported at N > 1. - Deferred to follow-up diffs, as agreed, and unsafe at N > 1 until then: publication order (a reader can see sequence S before a lower sequence from another partition is inserted, much like unordered_write's visibility); enable_pipelined_write (per-WriteThread last_sequence_ allocation, ordered SetLastSequence); sync=true writes (one leader syncs every partition's files while other partitions append); WBWI ingestion (switches memtables inside a gated leader); Merge batches (still inserted non-concurrently because of max_successive_merges); cached_recoverable_state_ without two_write_queues; timed write delays now run per partition in parallel; WALIOStatusCheck resets partition 0's writer on non-paranoid errors. None of these configurations is rejected: the coordination they need belongs to the follow-ups. What is rejected at N > 1: Open refuses two_write_queues, unordered_write, track_and_verify_wals, recycle_log_file_num > 0 and track_and_verify_wals_in_manifest=false; ColumnFamilyData::ValidateOptions refuses inplace_update_support, enable_blob_direct_write and persist_user_defined_timestamps=false; OptimisticTransactionDB refuses OccValidationPolicy::kValidateSerial; and WriteWithCallback with a WriteCallback returns NotSupported. - Durability watermark (07), completion gate (08) and multi-WAL recovery are out of scope. A crash at N > 1 can leave holes, and reopening an N > 1 DB is not supported. - Adaptive yield is unchanged: WriteThread's AdaptationContexts are file-scope statics shared by every instance, so they already adapt to aggregate traffic rather than to one queue's 1/N share. **Folded in from round 12 (D124911745)** Merge batches and WBWI ingestion are no longer deferred; this replaces those two items under limitations. Every N>1 memtable insert is now concurrent-safe: - Merge batches stay on the parallel insert path at N>1 (`assert(parallel || N==1)`). Rejecting `max_successive_merges>0` covers the only part of Merge that isn't concurrent-safe. - `IngestWriteBatchWithIndex` is rejected at runtime in `WriteImpl` at N>1 (`assert(N==1)` in `IngestWBWIAsMemtable`). - At N>1, Open rejects `max_successive_merges>0` and non-SkipList memtables. VectorRep passes the generic concurrent check, so only this new guard rejects it. - Tests: `MergeBatchesInsertConcurrentlyAcrossPartitions`, `IngestWriteBatchWithIndexRejectedAtNPartitions`, `ConcurrentUnsafeConfigsRejectedAtOpen` (4 rejects + control), `N1ConcurrentUnsafeOptionsStillAccepted`. - Neuters: revert the Merge guard -> the `parallel || N==1` assert aborts. Revert the WBWI check -> the `N==1` assert aborts. Revert the CF guards -> the vector_rep and merges cases open -> fail. M1: Absorbs 14 entries: GC13 Q1 gate opt-in + `WalPartitionsTestingOptIn`, Q3 ingestion stall + test, Q4 asserts; GC15 Q6 import stall + test, Q7 asserts (AMB-10 comment line lives in D123701876; SilentAtN1 lives in D123551605). M2 fold (2026-10-22, `M2-FoldTasks.md` + `M2-Amendment.md`): Absorbs (M2) GC06 Q2-Q5/Q8: option rejections, `WriteWithCallback` and OCC rejections, fixture, `UnindexedWalPartitionsAlwaysRejected`, `WalPartitionsUpperBound`, `ValidatePolicyAtNPartitions`, bypasses; GC10 Q1-Q4: recoverable-state cache, per-partition group size, WBM stall, `DelayWrite` arg, `WritePrepared` fixture and tests; GC11: a1 rejection (N>1 requires `track_and_verify_wals_in_manifest`), fixture tracking, `ReadOnlyAndSecondaryApplyPartitionChecks`; GC07 Q5/Q6: version_set assertions, `WriteRecoverableState` bump, `PublishAboveAllocatedAsserts`, `ConcurrentRecoverableStateCaching` rewrite. Exception X11 (GC11 tracking line in GC06's OCC test lands here). GitHub migration (2026-10-23): `PublishAboveAllocatedAsserts` falls back to `::testing::GTEST_FLAG(death_test_style)` when `GTEST_FLAG_SET` is unavailable (upstream bundles googletest 1.8.1). Test-only. M3 fold: Absorbs - GC12 Q1: GetCurrentWalFile refuses at N>1 (and the db.h doc); the checkpoint WAL inclusion bound is the newest current WAL over every partition (NewestAliveWalNumber); checkpoint quiesces every write queue until the open WAL sizes are read. GC12 Q8: ReadOnlyCompactedOpenAppliesPartitionChecks (AMB-M3-12). GC12: PreparedHeap::push/erase keep the heap sorted under out-of-order prepares, with PreparedHeap.BasicsTest (exception X4, AMB-M3-1: here rather than D123476301, because WritePrepared already runs at N>1 in this diff). - GC14b Q2: ConcurrentPreparesAcrossPartitions enabled; fixture comment. - GC08 Q4: WalContext::sync_failed_wal_number, the first WALIOStatusCheck argument in WriteImpl, SwitchMemtable failure attribution, TEST_WalRecoveryCutoff (exception X5: the leadership-sync attribution is hand-ported into this diff's inline sync loop; D123971668 re-extracts it). GC08 Q5 reset-and-continue assert, Q8 ConcurrentRecoverableStateCaching with 20 releases, Q9 AssertLastSequenceCoversAllocated, Q10 CreateMutex before the parallel memtable writers. - GC14a Q6: checkpoint pins a LockWAL count when another thread holds LockWAL, and unlocks after the size read. - GC17 Q4 constructor line (wal_empties_), Q6 (snapshots_version_ atomic, UpdateSnapshots never stores an older list, OlderSnapshotListNeverWins), Q3 MalformedBatchFailsAsAtN1. Exceptions recorded: X1 (GC12's Q1 copy tests sit at D123928339), X4, X5. Changes visible to existing users: - The main and nonmem write queues are now heap-allocated (write_threads_[0], nonmem_write_threads_[0]), so every write reaches its WriteThread through one more pointer. - WritePreparedTxnDB: snapshots_version_ is now atomic, and UpdateSnapshots() no longer stores a snapshot list older than the one already stored. PreparedHeap::push now scans from the back to keep the heap sorted; this is one comparison when prepares arrive in order. - InternalStats gains a shard array that stays unused at wal_partitions = 1, and GetDBStats() checks it. log::Writer grows by 8 bytes. Test Plan: - Pinned-base gate: passed with one recorded discrepancy. HEAD was exactly 4b70127fb45f, `sl status` was clean, and `only(., public())` listed the 25 dispatched commits in the dispatched order. The base's own subject still carries `[Codex]` (prefix not stripped locally); the requester confirmed proceeding on the pinned hash. This diff is a new commit on top; nothing below it was amended. - Required suites, default dev mode (ASan/UBSan): `buck2 test` of db_write_test, db_wal_test, write_batch_test, transaction_test, db_basic_test, plus db_options_test (validation changed): passed, 5,631 tests, 0 failures/timeouts/build failures. No existing test was modified. - TSan (`@fbcode//mode/dev-tsan`), the five required suites: passed, 5,580 tests, 0 failures, no ThreadSanitizer reports. This includes the eight new N > 1 tests. - R1, appends overlap: `DBWritePartitionTest.PartitionLeadersAppendConcurrently` (16 partitions; two_write_queues off and on, and with two queues also through the nonmem queue): every write holds its WAL append open until all of them are inside one, and all 16 of 16 appends were in flight at once. Neuter verified: routing every writer to partition 0's queue makes the maximum 1 and the test fails. - R2, sequence order equals byte order per file: debug assertion `sequence > log_writer->last_sequence_consumed()` in WriteToWAL. `DBWritePartitionTest.SequenceOrderHoldsUnderConcurrentSwitches` runs 16 partitions with 16 writer threads x 200 writes (a quarter WAL-only with two queues), plus a thread issuing Flush(). db_write_buffer_size and max_total_wal_size are small, so leaders keep switching memtables and rotating all 16 WALs. The assertion held and every write reads back. Neuter verified: moving the two-queue sequence allocation outside WalWriteMutex(p) trips the assertion. - Switch gate: `DBWritePartitionTest.SwitchWaitsForOtherPartitionsLeaders` holds one partition's append open and has another partition's leader schedule and run a memtable switch; the switch starts only after the open append completes. Neuter verified: with CloseMemTableSwitchGate() a no-op, the switch runs while the append is open and the test fails. - R3: `DBWritePartitionTest.MemtableDecisionEnforcedAtOpen`: wal_partitions=4 with allow_concurrent_memtable_write=false is NotSupported naming that option, even with the test bypass of the general N > 1 rejection; with it true, Open sizes 4 partitions. The existing db_options_test still sees "wal_partitions > 1 is not supported yet" without the bypass. - R5, byte-identical WAL at one partition: opt-mode db_bench built from 4b70127fb45f and from this diff; fillseq + fillrandom, 5,000 ops each, one thread, compression off, avoid_flush_during_shutdown. Run on the default path, enable_pipelined_write, and two_write_queues (via an options file; the OPTIONS files confirmed each setting). Base and new WALs were byte-identical in all three, `cmp` clean, sha256 913a88100f64e31e5faa17c0c5101fb0c838e6777096afa6845a210fbb22ffbb, 690,143 bytes. - Blackbox crash test, dbg-mode db_stress rebuilt from this diff (asserts on), 600 s with a 60 s interval: - two_write_queues=0: 11 kill/reopen iterations, and the final verification and DB cleanup ran (the success path). The exit status was not captured because I killed its wrapper shell while restarting the other run; no error, assertion or traceback appears in the log. - two_write_queues=1 (with enable_blob_direct_write=0 and file_scope_wal_write_faults=0, because the crash script's sanitizer otherwise forces two queues off): 11 iterations, every one with --two_write_queues=1, exit 0. - Formatting: the repo-pinned clang-format (/usr/local/bin/clang-format 21.1.2) via clang-format-diff.py over every changed range of the submitted state leaves no changes. `arc f` reports "No linters to run" for this subtree. - `arc lint -a` on all nine files: no lint issues. - Not run: whitebox crash test (not required). The comparison against D122660502's join-wait histogram: wal_partitions > 1 cannot be opened outside tests until the completion gate exists, so no db_bench configuration exercises N > 1. Crash/recovery at N > 1: unsupported until 08 and multi-WAL recovery. CMake/Make, macOS and Windows builds. **After folding in round 12 / 12.1 (D124911745, D125113461):** - `buck2 test fbcode//internal_repo_rocksdb/repo:db_write_test fbcode//internal_repo_rocksdb/repo:error_handler_fs_test` at this commit: Pass 154, Fail 0 (https://www.internalfb.com/intern/testinfra/testrun/32088147390513887). - Neuter, TSan and byte-identity evidence for the folded-in items: see the Test Plans of D124911745 and D125113461. They ran on the same code, now split across this stack. M1 gate at fold: `db_write_test` 88/0, options matrix 55/0. 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. M2 fold: new or moved tests here: UnindexedWalPartitionsAlwaysRejected, WalPartitionsUpperBound, ReadOnlyAndSecondaryApplyPartitionChecks, PublishAboveAllocatedAsserts, ValidatePolicyAtNPartitions, WritePreparedPartitionedWalTest.*. B.1 at this diff (format check, `rocksdb_lib`, touched test targets): PASS; db_write_test + optimistic_transaction_test + write_prepared_transaction_test 1019 pass. M3 B.1 at this diff (clang-format 21.1.2 on its changed lines, make check-sources, debug build, touched test binaries): PASS; db_write_test + optimistic_transaction_test + write_prepared_transaction_test: 1017 pass. M5 fold: Absorbs 62 A.1 entries (GC28 18, GC27 5, GC30 1, GC31 16, GC33 9, GC29b 13): GC28 switch-gate counters (EnterMemTableSwitchGate(p)), JoinWaitTimerOffAtDefaultStatsLevel; GC31 Q1 flush path, Q2 (a) DB-stat shards (InternalStats), Q7 recoverable-state slots, A9; GC33 Q1 (WriteImpl's DB-stat adds: half of the frame restore) and Q3 (QuiescedWriteBufferManagerFlush, WriteBufferManagerFlushWouldAct, its two tests); GC29b T5 and comments; the N>1 option tests of GC27/GC30. M5-F1 (A.8): F1.4 (a) GetDBStats' single counter without shards, (b) the last leg of WbmFlushQuiesceSkippedWhenNothingToSwitch, (c) WriteImpl's comment without "as before GC31", (d) both Wbm tests bypass N>1. Exceptions: X13-M5 (the join-timer test); X14-M5 (WalPartitionsSetOptionsRuntimeConflicts); X32-M5: GC29b#677 (transaction_test.h JoinThreadsOnExit) moved here from D123551605, with its lowest users GC29b#678 and meta#679 (B.1: 'JoinThreadsOnExit' was not declared); X35-M5: GC27#119-meta#122 (MyTestCompactionService's options map and OpenAndCompactAtPartitionedPrimary, X3-M5) moved from D121858039 to D123079329: below D123079329 Open refuses N>1 with no testing hook (B.1); X36-M5: WalPartitionsOptionRefusalsUnchanged (GC30#245, with GC29b#616) moved from D123079329 to D123701876: the pipelined-write and paranoid_checks refusals it pins first exist here (B.1). Hand-splits (rows below the hunk's top row get their slice by a per-row edit): GC28#46 (AllocateSequenceAndWALIndex re-indent, H5): D119600943 takes the scope block, SequenceWalIndexLock, the Allocated sync point and re-indents its lines; D123079329 re-indents the three lines it brings in; D123476301 registers both trackers inside the scope; GC31#347 (db_impl.h test accessors): TEST_wals_total_size via WalsTotalSize() at D121858039, TEST_CachedRecoverableStateEmpty at D123079329, TEST_UnpublishedSyncGroups at D123551605. X14-M5 hook (rule 2.4): the AllowWalPartitions callback before the first N>1 open of DBWriteTestUnparameterized.WalPartitionsSetOptionsRuntimeConflicts and CompactionServiceTest.OpenAndCompactAtPartitionedPrimary (the latter found by B.1); FLIP removes it. M5 B.1: PASS (clang-format 21.1.2 on the changed lines, make check-sources, debug build of compaction_service_test, db_write_test, optimistic_transaction_test, write_prepared_transaction_test); 1090 tests, 0 failed. M6 fold: Absorbs GC34 Q5 and the stack-owner follow-up: the file-scope `test_holds_abandoned` flag and `WaitForReleaseOrAbandon` (every `GC28Hold` hold lets its thread go once a still-running `DBWalAppendFailureTest::Writer` is unwound; arming clears the flag); `write_prepared_transaction_test` `OlderSnapshotListNeverWins` fails instead of terminating. M6 B.1: PASS (debug build and build_tools/gtest-parallel run of compaction_service_test db_write_test optimistic_transaction_test write_prepared_transaction_test: 1090/1090). Reviewers: #rocksdb, anand76, jewoongh, rbanerjee2 Subscribers: jewoongh, rbanerjee2 Differential Revision: https://phabricator.intern.facebook.com/D123079329
JustinGaoF
added a commit
to JustinGaoF/rocksdb
that referenced
this pull request
Nov 19, 2026
Summary: The diff works to provide container of the WAL files handler to replace existing one wal file. Stack: this diff sits on D117280372; the write-path prep stack (D117251769..D117280372) sits on D121674557. `DBImpl::logs_` and `DBImpl::alive_wal_files_` become one deque per WAL partition: `std::vector<std::deque<...>>`, sized 1 at construction. `wal_partitions > 1` is still rejected at Open, `SelectWalForWrite()` remains the only WAL-selection seam, and no public header, option, or on-disk format changes. Write-path point accesses bind partition 0; walks (obsolete-file selection, sync bookkeeping, size accounting, close) loop partitions in ascending index order under the same locks as before. Locking documentation: the numbered cases are unchanged in content but reframed from "the deque" to "partition p's deque" under an explicit two-level split (the vectors are sized at construction and never resized, so they need no lock; every deque access holds the same global mutexes as before, since mutex splitting is out of scope). The back()/getting_synced observations are scoped to one partition's deque. Enforcement is mechanical where it can be: all access goes through the `WalLogs(p)` / `AliveWalFiles(p)` / `NumWalPartitions()` chokepoint with bounds and equal-length asserts, replacing direct member uses; the container abstraction itself still lands later once real N-partition usage is known. Lifetime: each partition's deque keeps independent per-entry bookkeeping and removal stays per-entry (pop/erase), so a future reference-driven scheme can replace per-entry removal without reshaping; element addresses stay stable (deque elements never move, vectors never resized), which is what `CurrentWal()` references and `WalContext::wal_file_number_size` pointers rely on. Behaviour preservation: the change is semantics-preserving by construction (same deque objects, same lock holds, loops run once), so most hunks have no neuter check available. Neutered instead: forcing `NumWalPartitions()` to 0 fails 8 `db_wal_test` tests (sync and WAL-lifecycle coverage incl. the new test below), proving the loops are load-bearing. No existing test caught a mistake during the change itself: the first full-matrix run passed. New coverage is one pinning test, `DBWALTest.SingleWalPartition`, asserting exactly one partition across open, write, WAL roll, flush, and reopen; all existing tests pass unmodified. Size accounting: `wals_total_size_` stays partition 0's counter, and `wal_partition_sizes_` adds one cache-line-padded counter for each further partition (`WalsTotalSizeCounter(p)`). Readers (`WalsTotalSize()`, used by the max_total_wal_size check, the atomic-flush error path and `TEST_wals_total_size()`) sum them, and `RestoreAliveLogFiles` resets them all. At one partition `wal_partition_sizes_` is empty and the read is the old single relaxed load. `TEST_NumWalPartitions()` is added for the new test. Test Plan: `buck2 test fbcode//internal_repo_rocksdb/repo:db_wal_test fbcode//internal_repo_rocksdb/repo:db_write_test fbcode//internal_repo_rocksdb/repo:db_basic_test fbcode//internal_repo_rocksdb/repo:db_flush_test fbcode//internal_repo_rocksdb/repo:db_options_test fbcode//internal_repo_rocksdb/repo:repair_test fbcode//internal_repo_rocksdb/repo:log_test` - Pass 2888, Fail 0 on the submitted base. Targeted locking-route runs: `DBWALTest.SingleWalPartition`, `DBWALTest.WALWriteErrorNoRecovery`, `DBWALIndexTest.TwoWriteQueuesIsRejected`, `DBBasicTest.EmptyFlush` (all option configs incl. two_write_queues on), `DBBasicTest.DBCloseFlushError`, `DBBasicTest.ReadOnlyDBFlushWAL`, `DBWriteTestUnparameterized.PipelinedWriteRace` - all pass. Neuter (`NumWalPartitions()` forced to 0): 8 `db_wal_test` failures, reverted with byte-identical diff. R5 WAL byte comparison: fixed `db_bench fillseq` workload (num=20000, seed=12345) run against parent and new binaries - WAL bytes identical for `partition_wal_usage=none` and `record_ordering_single_file` (self-consistency verified first), identical Open rejection for `partition_by_column_family`; evidence gathered on D120171238-based binaries, and the move to D119751506 only drops a read-path/test/comment-only delta (reader validation, `log_test` cases, comment-only `log_writer.h`) touching none of this diff's files nor the write path, so the conclusion transfers - happy to re-run on request. 180s blackbox crash test with `--partition_wal_usage=record_ordering_single_file` on `db_stress` rebuilt from this commit: passed. `arc lint -a`: clean. `clang-format --dry-run --Werror` (v21.1.2, repo `.clang-format`): clean on all touched lines (two remaining violations are pre-existing rebase lines outside this diff). M3 B.1 at this diff (clang-format 21.1.2 on its changed lines, make check-sources, debug build, touched test binaries): PASS; db_wal_test: 2059 pass. M5 fold: Absorbs 9 A.1 entries (GC31 8, GC33 1): GC31 Q2 (b) per-partition wals_total_size_ (WalsTotalSizeCounter, wal_partition_sizes_, readers, open reset); GC33's N=1 WalsTotalSize; GC27's compaction-service secondary test. Not here after B.1: GC27's compaction-service test and its helper go to D123079329 (X35-M5). Exceptions: X3-M5 (the test); X17-M5 (the WriteToWAL account at D122274088; X35-M5: GC27#119-meta#122 (MyTestCompactionService's options map and OpenAndCompactAtPartitionedPrimary, X3-M5) moved from D121858039 to D123079329: below D123079329 Open refuses N>1 with no testing hook (B.1). Hand-splits (rows below the hunk's top row get their slice by a per-row edit): GC31#347 (db_impl.h test accessors): TEST_wals_total_size via WalsTotalSize() at D121858039, TEST_CachedRecoverableStateEmpty at D123079329, TEST_UnpublishedSyncGroups at D123551605. M5 B.1: PASS (clang-format 21.1.2 on the changed lines, make check-sources, debug build of db_wal_test); 2062 tests, 0 failed. Differential Revision: https://phabricator.intern.facebook.com/D121858039
JustinGaoF
added a commit
to JustinGaoF/rocksdb
that referenced
this pull request
Nov 19, 2026
Summary: Reviewer question: is the memtable-switch gate sufficient to exclude every other partition's leader from a memtable/WAL switch -- a leader enters it in PreprocessWrite() before binding a WAL and leaves it only when its group exits (including the parallel-follower and unordered_write exits), and a leader that must switch closes it from PreprocessWrite() before entering, so no leader ever waits on itself? **Blocked decisions** 1. M0.8, route-then-group: already decided and implemented by D122869562; not reopened. Each writer carries the route resolved once in WriteImpl and joins the queue of that partition. Reversing it (group-then-route) would need WriteThread to release leadership between WAL selection and the append. 2. Memtable fork: **A, allow_concurrent_memtable_write.** N leaders insert into the same memtables, and A needs no new lock or lock ordering. B's serialization cost does not need measuring because nothing is serialized. unordered_write, which would also need A, is rejected at N > 1 in this diff. Its cost: wal_partitions > 1 requires a SkipList memtable, and enable_blob_direct_write cannot be combined with it (ColumnFamilyData::ValidateOptions already rejects blob direct write with concurrent memtable writes). Enforced at Open: wal_partitions > 1 with allow_concurrent_memtable_write=false is now NotSupported, and this check runs before the general wal_partitions > 1 rejection, so it is reachable and tested. Reversing to B: drop that Open check, give each leader a memtable-insert lock around its insert at N > 1 (and let single-writer groups insert serially again), and keep the unordered_write rejection at N > 1. **Why** Routing (D122869562) decides which WAL a write binds to, but every writer still joins the one write_thread_, so writers to different partitions are still serialized behind one leader. D122660502's 36.8 ms join-wait tail is unrelieved. This diff makes N > 1 mean N concurrent leaders, each appending to its own WAL. **Previous behavior** One WriteThread write_thread_ and one nonmem_write_thread_. The per-partition containers were always sized 1: Open created partition 0's WAL only, and SwitchMemtable rotated partition 0 only. At N > 1 the default write path also read LastSequence() as its allocation, published with SetLastSequence() (which asserts monotonicity), and inserted single-writer groups with concurrent_memtable_writes=false -- all of which assume one leader. **New behavior (only at N > 1, still unreachable outside tests)** - One WriteThread and one nonmem WriteThread per partition (write_threads_/nonmem_write_threads_, sized with the other partition containers in the constructor). A writer joins its routed partition's queue, so each partition has its own newest_writer_ and leader. There is no cross-partition election. - One log::Writer per partition: Open creates N WALs and SwitchMemtable rotates all N together, under all N WAL write mutexes. Partition 0 keeps the lowest number of each generation, so cur_wal_number_, memtable NextLogNumber and obsolescence keep their meaning. - Sequence allocation stays inside each partition's leader critical section. The default (!two_write_queues) path allocates through AllocateSequenceAndWALIndex, the counter the WAL-index path already uses, so sequences and wal_index stay unique across partitions. two_write_queues is rejected at N > 1 for every partition_wal_usage, because N > 1 requires indexed WALs and indexed WALs already reject two_write_queues. - Every leader inserts in concurrent mode (forced parallel path), because other partitions insert into the same memtables. - Memtable-switch gate: PreprocessWrite()'s SwitchWAL / HandleWriteBufferManagerFlush / ScheduleFlushes close the gate and wait for leaders past it. Callers outside the write path (flush, SetOptions, CF create/drop, ingestion, LockWAL, ResumeImpl, ...) enter every partition's queue unbatched in ascending order (AllPartitionsWriter). - Publication: PublishLastSequence() skips a publish a higher one already overtook (CAS-max), so LastSequence() never moves backwards. Publication order is not established here (see limitations). - Stalls and delays act on the leader's own partition queue; UnlockWAL and WaitForPendingWrites cover every queue. **Neuter checks at one partition (R5)** NumWalPartitions() == 1 returns from all four gate functions immediately; `parallel` keeps `write_group.size > 1`; the allocator condition reduces to WALIndexEnabled; PublishLastSequence calls SetLastSequence; stats keep `concurrent = two_write_queues_`; the constructor's resize, Open's extra-WAL loop, SwitchMemtable's extra-WAL loops and its any-partition-non-empty loop are all empty; AllWalWriteMutexesLock in SwitchMemtable takes exactly WalWriteMutex(0); AllPartitionsWriter uses an inline writer for partition 0, with no allocation, i.e. the same single EnterUnbatched as before. The R2 assertion and its per-file tracker are debug-only. Changes without a neuter: last_batch_group_size_ becomes one RelaxedAtomic per partition (relaxed load/store); IsMainWriteThread replaces `&write_thread == &write_thread_` with one comparison at N=1; UnlockWAL keeps its stall counts in two size-1 vectors (a cold path); WriteToWAL/WriteGroupToWAL take a sequence_count used only by the debug assertion. None of these changes control flow or WAL bytes at N=1. **Safety, compatibility, limitations** - wal_partitions > 1 remains rejected at Open. Tests reach N > 1 only through experimental_allow_wal_partitions_for_testing (indexed partition_wal_usage only) or the debug sync point DBImpl::ValidateOptions:AllowWalPartitions. Read-only and secondary instances always size to one partition. The only public header change is a note in include/rocksdb/db.h that GetCurrentWalFile returns NotSupported at N > 1. - Deferred to follow-up diffs, as agreed, and unsafe at N > 1 until then: publication order (a reader can see sequence S before a lower sequence from another partition is inserted, much like unordered_write's visibility); enable_pipelined_write (per-WriteThread last_sequence_ allocation, ordered SetLastSequence); sync=true writes (one leader syncs every partition's files while other partitions append); WBWI ingestion (switches memtables inside a gated leader); Merge batches (still inserted non-concurrently because of max_successive_merges); cached_recoverable_state_ without two_write_queues; timed write delays now run per partition in parallel; WALIOStatusCheck resets partition 0's writer on non-paranoid errors. None of these configurations is rejected: the coordination they need belongs to the follow-ups. What is rejected at N > 1: Open refuses two_write_queues, unordered_write, track_and_verify_wals, recycle_log_file_num > 0 and track_and_verify_wals_in_manifest=false; ColumnFamilyData::ValidateOptions refuses inplace_update_support, enable_blob_direct_write and persist_user_defined_timestamps=false; OptimisticTransactionDB refuses OccValidationPolicy::kValidateSerial; and WriteWithCallback with a WriteCallback returns NotSupported. - Durability watermark (07), completion gate (08) and multi-WAL recovery are out of scope. A crash at N > 1 can leave holes, and reopening an N > 1 DB is not supported. - Adaptive yield is unchanged: WriteThread's AdaptationContexts are file-scope statics shared by every instance, so they already adapt to aggregate traffic rather than to one queue's 1/N share. **Folded in from round 12 (D124911745)** Merge batches and WBWI ingestion are no longer deferred; this replaces those two items under limitations. Every N>1 memtable insert is now concurrent-safe: - Merge batches stay on the parallel insert path at N>1 (`assert(parallel || N==1)`). Rejecting `max_successive_merges>0` covers the only part of Merge that isn't concurrent-safe. - `IngestWriteBatchWithIndex` is rejected at runtime in `WriteImpl` at N>1 (`assert(N==1)` in `IngestWBWIAsMemtable`). - At N>1, Open rejects `max_successive_merges>0` and non-SkipList memtables. VectorRep passes the generic concurrent check, so only this new guard rejects it. - Tests: `MergeBatchesInsertConcurrentlyAcrossPartitions`, `IngestWriteBatchWithIndexRejectedAtNPartitions`, `ConcurrentUnsafeConfigsRejectedAtOpen` (4 rejects + control), `N1ConcurrentUnsafeOptionsStillAccepted`. - Neuters: revert the Merge guard -> the `parallel || N==1` assert aborts. Revert the WBWI check -> the `N==1` assert aborts. Revert the CF guards -> the vector_rep and merges cases open -> fail. M1: Absorbs 14 entries: GC13 Q1 gate opt-in + `WalPartitionsTestingOptIn`, Q3 ingestion stall + test, Q4 asserts; GC15 Q6 import stall + test, Q7 asserts (AMB-10 comment line lives in D123701876; SilentAtN1 lives in D123551605). M2 fold (2026-10-22, `M2-FoldTasks.md` + `M2-Amendment.md`): Absorbs (M2) GC06 Q2-Q5/Q8: option rejections, `WriteWithCallback` and OCC rejections, fixture, `UnindexedWalPartitionsAlwaysRejected`, `WalPartitionsUpperBound`, `ValidatePolicyAtNPartitions`, bypasses; GC10 Q1-Q4: recoverable-state cache, per-partition group size, WBM stall, `DelayWrite` arg, `WritePrepared` fixture and tests; GC11: a1 rejection (N>1 requires `track_and_verify_wals_in_manifest`), fixture tracking, `ReadOnlyAndSecondaryApplyPartitionChecks`; GC07 Q5/Q6: version_set assertions, `WriteRecoverableState` bump, `PublishAboveAllocatedAsserts`, `ConcurrentRecoverableStateCaching` rewrite. Exception X11 (GC11 tracking line in GC06's OCC test lands here). GitHub migration (2026-10-23): `PublishAboveAllocatedAsserts` falls back to `::testing::GTEST_FLAG(death_test_style)` when `GTEST_FLAG_SET` is unavailable (upstream bundles googletest 1.8.1). Test-only. M3 fold: Absorbs - GC12 Q1: GetCurrentWalFile refuses at N>1 (and the db.h doc); the checkpoint WAL inclusion bound is the newest current WAL over every partition (NewestAliveWalNumber); checkpoint quiesces every write queue until the open WAL sizes are read. GC12 Q8: ReadOnlyCompactedOpenAppliesPartitionChecks (AMB-M3-12). GC12: PreparedHeap::push/erase keep the heap sorted under out-of-order prepares, with PreparedHeap.BasicsTest (exception X4, AMB-M3-1: here rather than D123476301, because WritePrepared already runs at N>1 in this diff). - GC14b Q2: ConcurrentPreparesAcrossPartitions enabled; fixture comment. - GC08 Q4: WalContext::sync_failed_wal_number, the first WALIOStatusCheck argument in WriteImpl, SwitchMemtable failure attribution, TEST_WalRecoveryCutoff (exception X5: the leadership-sync attribution is hand-ported into this diff's inline sync loop; D123971668 re-extracts it). GC08 Q5 reset-and-continue assert, Q8 ConcurrentRecoverableStateCaching with 20 releases, Q9 AssertLastSequenceCoversAllocated, Q10 CreateMutex before the parallel memtable writers. - GC14a Q6: checkpoint pins a LockWAL count when another thread holds LockWAL, and unlocks after the size read. - GC17 Q4 constructor line (wal_empties_), Q6 (snapshots_version_ atomic, UpdateSnapshots never stores an older list, OlderSnapshotListNeverWins), Q3 MalformedBatchFailsAsAtN1. Exceptions recorded: X1 (GC12's Q1 copy tests sit at D123928339), X4, X5. Changes visible to existing users: - The main and nonmem write queues are now heap-allocated (write_threads_[0], nonmem_write_threads_[0]), so every write reaches its WriteThread through one more pointer. - WritePreparedTxnDB: snapshots_version_ is now atomic, and UpdateSnapshots() no longer stores a snapshot list older than the one already stored. PreparedHeap::push now scans from the back to keep the heap sorted; this is one comparison when prepares arrive in order. - InternalStats gains a shard array that stays unused at wal_partitions = 1, and GetDBStats() checks it. log::Writer grows by 8 bytes. Test Plan: - Pinned-base gate: passed with one recorded discrepancy. HEAD was exactly 4b70127fb45f, `sl status` was clean, and `only(., public())` listed the 25 dispatched commits in the dispatched order. The base's own subject still carries `[Codex]` (prefix not stripped locally); the requester confirmed proceeding on the pinned hash. This diff is a new commit on top; nothing below it was amended. - Required suites, default dev mode (ASan/UBSan): `buck2 test` of db_write_test, db_wal_test, write_batch_test, transaction_test, db_basic_test, plus db_options_test (validation changed): passed, 5,631 tests, 0 failures/timeouts/build failures. No existing test was modified. - TSan (`@fbcode//mode/dev-tsan`), the five required suites: passed, 5,580 tests, 0 failures, no ThreadSanitizer reports. This includes the eight new N > 1 tests. - R1, appends overlap: `DBWritePartitionTest.PartitionLeadersAppendConcurrently` (16 partitions; two_write_queues off and on, and with two queues also through the nonmem queue): every write holds its WAL append open until all of them are inside one, and all 16 of 16 appends were in flight at once. Neuter verified: routing every writer to partition 0's queue makes the maximum 1 and the test fails. - R2, sequence order equals byte order per file: debug assertion `sequence > log_writer->last_sequence_consumed()` in WriteToWAL. `DBWritePartitionTest.SequenceOrderHoldsUnderConcurrentSwitches` runs 16 partitions with 16 writer threads x 200 writes (a quarter WAL-only with two queues), plus a thread issuing Flush(). db_write_buffer_size and max_total_wal_size are small, so leaders keep switching memtables and rotating all 16 WALs. The assertion held and every write reads back. Neuter verified: moving the two-queue sequence allocation outside WalWriteMutex(p) trips the assertion. - Switch gate: `DBWritePartitionTest.SwitchWaitsForOtherPartitionsLeaders` holds one partition's append open and has another partition's leader schedule and run a memtable switch; the switch starts only after the open append completes. Neuter verified: with CloseMemTableSwitchGate() a no-op, the switch runs while the append is open and the test fails. - R3: `DBWritePartitionTest.MemtableDecisionEnforcedAtOpen`: wal_partitions=4 with allow_concurrent_memtable_write=false is NotSupported naming that option, even with the test bypass of the general N > 1 rejection; with it true, Open sizes 4 partitions. The existing db_options_test still sees "wal_partitions > 1 is not supported yet" without the bypass. - R5, byte-identical WAL at one partition: opt-mode db_bench built from 4b70127fb45f and from this diff; fillseq + fillrandom, 5,000 ops each, one thread, compression off, avoid_flush_during_shutdown. Run on the default path, enable_pipelined_write, and two_write_queues (via an options file; the OPTIONS files confirmed each setting). Base and new WALs were byte-identical in all three, `cmp` clean, sha256 913a88100f64e31e5faa17c0c5101fb0c838e6777096afa6845a210fbb22ffbb, 690,143 bytes. - Blackbox crash test, dbg-mode db_stress rebuilt from this diff (asserts on), 600 s with a 60 s interval: - two_write_queues=0: 11 kill/reopen iterations, and the final verification and DB cleanup ran (the success path). The exit status was not captured because I killed its wrapper shell while restarting the other run; no error, assertion or traceback appears in the log. - two_write_queues=1 (with enable_blob_direct_write=0 and file_scope_wal_write_faults=0, because the crash script's sanitizer otherwise forces two queues off): 11 iterations, every one with --two_write_queues=1, exit 0. - Formatting: the repo-pinned clang-format (/usr/local/bin/clang-format 21.1.2) via clang-format-diff.py over every changed range of the submitted state leaves no changes. `arc f` reports "No linters to run" for this subtree. - `arc lint -a` on all nine files: no lint issues. - Not run: whitebox crash test (not required). The comparison against D122660502's join-wait histogram: wal_partitions > 1 cannot be opened outside tests until the completion gate exists, so no db_bench configuration exercises N > 1. Crash/recovery at N > 1: unsupported until 08 and multi-WAL recovery. CMake/Make, macOS and Windows builds. **After folding in round 12 / 12.1 (D124911745, D125113461):** - `buck2 test fbcode//internal_repo_rocksdb/repo:db_write_test fbcode//internal_repo_rocksdb/repo:error_handler_fs_test` at this commit: Pass 154, Fail 0 (https://www.internalfb.com/intern/testinfra/testrun/32088147390513887). - Neuter, TSan and byte-identity evidence for the folded-in items: see the Test Plans of D124911745 and D125113461. They ran on the same code, now split across this stack. M1 gate at fold: `db_write_test` 88/0, options matrix 55/0. 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. M2 fold: new or moved tests here: UnindexedWalPartitionsAlwaysRejected, WalPartitionsUpperBound, ReadOnlyAndSecondaryApplyPartitionChecks, PublishAboveAllocatedAsserts, ValidatePolicyAtNPartitions, WritePreparedPartitionedWalTest.*. B.1 at this diff (format check, `rocksdb_lib`, touched test targets): PASS; db_write_test + optimistic_transaction_test + write_prepared_transaction_test 1019 pass. M3 B.1 at this diff (clang-format 21.1.2 on its changed lines, make check-sources, debug build, touched test binaries): PASS; db_write_test + optimistic_transaction_test + write_prepared_transaction_test: 1017 pass. M5 fold: Absorbs 62 A.1 entries (GC28 18, GC27 5, GC30 1, GC31 16, GC33 9, GC29b 13): GC28 switch-gate counters (EnterMemTableSwitchGate(p)), JoinWaitTimerOffAtDefaultStatsLevel; GC31 Q1 flush path, Q2 (a) DB-stat shards (InternalStats), Q7 recoverable-state slots, A9; GC33 Q1 (WriteImpl's DB-stat adds: half of the frame restore) and Q3 (QuiescedWriteBufferManagerFlush, WriteBufferManagerFlushWouldAct, its two tests); GC29b T5 and comments; the N>1 option tests of GC27/GC30. M5-F1 (A.8): F1.4 (a) GetDBStats' single counter without shards, (b) the last leg of WbmFlushQuiesceSkippedWhenNothingToSwitch, (c) WriteImpl's comment without "as before GC31", (d) both Wbm tests bypass N>1. Exceptions: X13-M5 (the join-timer test); X14-M5 (WalPartitionsSetOptionsRuntimeConflicts); X32-M5: GC29b#677 (transaction_test.h JoinThreadsOnExit) moved here from D123551605, with its lowest users GC29b#678 and meta#679 (B.1: 'JoinThreadsOnExit' was not declared); X35-M5: GC27#119-meta#122 (MyTestCompactionService's options map and OpenAndCompactAtPartitionedPrimary, X3-M5) moved from D121858039 to D123079329: below D123079329 Open refuses N>1 with no testing hook (B.1); X36-M5: WalPartitionsOptionRefusalsUnchanged (GC30#245, with GC29b#616) moved from D123079329 to D123701876: the pipelined-write and paranoid_checks refusals it pins first exist here (B.1). Hand-splits (rows below the hunk's top row get their slice by a per-row edit): GC28#46 (AllocateSequenceAndWALIndex re-indent, H5): D119600943 takes the scope block, SequenceWalIndexLock, the Allocated sync point and re-indents its lines; D123079329 re-indents the three lines it brings in; D123476301 registers both trackers inside the scope; GC31#347 (db_impl.h test accessors): TEST_wals_total_size via WalsTotalSize() at D121858039, TEST_CachedRecoverableStateEmpty at D123079329, TEST_UnpublishedSyncGroups at D123551605. X14-M5 hook (rule 2.4): the AllowWalPartitions callback before the first N>1 open of DBWriteTestUnparameterized.WalPartitionsSetOptionsRuntimeConflicts and CompactionServiceTest.OpenAndCompactAtPartitionedPrimary (the latter found by B.1); FLIP removes it. M5 B.1: PASS (clang-format 21.1.2 on the changed lines, make check-sources, debug build of compaction_service_test, db_write_test, optimistic_transaction_test, write_prepared_transaction_test); 1090 tests, 0 failed. M6 fold: Absorbs GC34 Q5 and the stack-owner follow-up: the file-scope `test_holds_abandoned` flag and `WaitForReleaseOrAbandon` (every `GC28Hold` hold lets its thread go once a still-running `DBWalAppendFailureTest::Writer` is unwound; arming clears the flag); `write_prepared_transaction_test` `OlderSnapshotListNeverWins` fails instead of terminating. M6 B.1: PASS (debug build and build_tools/gtest-parallel run of compaction_service_test db_write_test optimistic_transaction_test write_prepared_transaction_test: 1090/1090). Reviewers: #rocksdb, anand76, jewoongh, rbanerjee2 Subscribers: jewoongh, rbanerjee2 Differential Revision: https://phabricator.intern.facebook.com/D123079329
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
make rocksdbjava
make sample
Reviewers: haobo, yhchiang, sdong, dhruba, rsumbaly, zzbennett, swapnilghike
Reviewed By: yhchiang
CC: leveldb
Differential Revision: https://reviews.facebook.net/D17811