Repository navigation
[GC] GC20: Write-path fixes: sync durability, error severity, zero-count tracker, cover race - #12
Closed
JustinGaoF wants to merge 1 commit into
Closed
JustinGaoF wants to merge 1 commit into
JustinGaoF wants to merge 1 commit into
Conversation
…unt tracker, cover race
[GC] GC20 -- write-path fixes at N>1 (FU14 H1, M-a, K1, K3; GC18 carry-over Q5-Q9)
Reviewer question: At N>1, is every acknowledged sync=true write fsynced,
does a failed sync fence only its own range and stay hidden, does another
partition's recoverable WAL error stay recoverable, does publication never
run ahead of an in-flight range, and is the void-cover append serialized
with every buffer flush?
Short answer: yes, for all nine questions, each with a test that fails at
the base (or under its neuter) and passes here. N=1 is byte-identical. The
residual limits are listed under Assumptions.
## Q1 -- Every acknowledged sync=true write is fsynced, any count (H1)
Property: a sync=true write returns OK only after an fsync that started
after its own append, on every partition, whatever its count.
How: RunCoalescedGateSync numbers gate syncs as they start
(wal_gate_sync_started_epoch_) and records the number of the latest one
that succeeded (wal_gate_synced_epoch_). A gate is covered by any sync
numbered above the last one started when it asked. A group that consumes
sequences is still also covered by the old test (a successful sync whose
safe-point read reached its target), so coalescing for ordinary sync writes
is unchanged. A zero-count group's target is the sequence below its record,
so only the epoch test applies to it. The second round
(pre_sync_safe_point < target) is correct as is: *covered is the safe point
of a sync that started after the append.
Evidence:
- TransactionPartitionedWalTest.SyncPrepareAfterSyncCommitSurvivesCrash
(repro, unmodified): base fails ("1 vs 1", xid2 lost); passes here.
- New DBWritePartitionTest.SyncZeroCountWriteAfterSyncWriteSyncs: a sync
LogData-only batch after a sync write. WAL_FILE_SYNCED advances, and
DropUnsyncedFileData truncates no WAL. Base: no sync, and WAL bytes go
121 -> 88 at the crash.
- Neuter (target-only early return `wal_gate_synced_upto_ >= target`): both
fail.
- Measured: GC16 trigger cells, see the Q1 measurement table below.
## Q2 -- Another partition's recoverable WAL error stays recoverable (M-a)
Property: a gate sync that meets a previously failed writer, or a WAL at or
below wal_recovery_cutoff_, returns the stored background error, does not
reclassify it, and does not touch the handle.
How: SyncWalPartitionFiles takes an optional `previously_failed`
out-parameter (the gate path passes it; the N=1 leadership sync passes
null, so N=1 is unchanged). With it, WALs at or below the cutoff are
skipped, and the sync uses WritableFileWriter::Sync(opts, use_fsync,
&seen_error) (equivalent to the old Fsync/Sync call). When set,
SyncWalsFromCompletionGate skips WALIOStatusCheck and returns the
background error, as SyncWalImpl/SyncWAL already do.
Evidence:
- DBWalAppendFailureTest.GateSyncKeepsOtherPartitionsErrorResumable
(repro, unmodified): base Hard (2) -> Fatal (3), Resume fails; here it
stays Hard and Resume() succeeds (the held write returns the stored
"injected" error).
- Neuter (pass nullptr for previously_failed): it fails again.
## Q3 -- A zero-count entry never moves a safe point past the last
## allocated sequence (K1)
Property: a record that consumes no sequence pins low = S (last allocated
+ 1) while in flight, and completes durable or applied only through S - 1.
How: such a record registers the empty range [S, S - 1] (high = last
allocated + count, uniformly). WalDurabilityTracker accepts high == low - 1
(assert low <= high + 1); Complete then raises durable_upto only to S - 1.
The call sites drop their `count == 0 ? low : ...` special cases, and the
failed-range record stores [start, failed_wal_sequence] so Release matches.
The clamp min(SafePoint, LastAllocatedSequence) in
PublishAppliedFrontierLocked is now an assert.
Evidence (both written first, both fail at the base):
- New WalDurabilityTrackerTest.ZeroCountEntryStaysBelowItsLow. Base: aborts
at `assert(low <= high)` in Register.
- New DBWritePartitionTest.ZeroCountMarkerNeverPublishesInFlightSequence:
marker, then X allocating S held before its append, then Y on another
partition completing first. Asserts LastSequence() stays at S - 1 until X
completes. Base: aborts at PublishAppliedFrontierLocked's
`PendingLow(p) > frontier` assertion (it publishes S).
- Neuter (tracker treats [S, S - 1] as [S, S]): the tracker test fails
(safe point 5, not 4); the DB test aborts at the new
`frontier <= LastAllocatedSequence()` assertion.
## Q4 -- The void-cover append is serialized with every flush (K3)
Property: the cover takes the partition's WAL mutex whenever WriteToWAL
would (N>1, or manual_wal_flush && !two_write_queues); the call site that
holds it does not relock.
How: CoverBurnedWALIndex takes (wal_partition, wal_mutex_held) and locks
under WriteToWAL's condition. WriteImpl and PipelinedWriteImpl pass false;
ConcurrentWriteGroupToWAL passes true (asserted held).
Evidence: new DBWritePartitionTest.CoverAppendSerializedWithFlushWAL:
indexed, manual_wal_flush, N=2, a protected batch whose log entry is
corrupted (VerifyChecksum fails before any append, healthy writer), and a
concurrent FlushWAL loop. TSan (clang): base 3/3 runs report 3 data races
each (AlignedBuffer::Append in CoverBurnedWALIndex vs WriteBuffer in
FlushWAL); here 0/3. Neuter (no lock): 3/3 runs, 3 races each.
## Q5 -- A failed gate fsync fences only its group's range (D-7)
Property: a failed gate sync fences exactly [low, target] of its group,
plus each sync group that queued on the failed sync (each fences its own
range). Writes outside keep their outcome; the flush drops only the fenced
ranges; the indeterminate record covers only them. Append fences (D-1) are
unchanged (open-ended).
How:
- InstallFailedGateSyncFence(low, high, status): an "exact" fence closed
from the start (InstallWalGateFence gains `high`; WalGateFence gains
`exact`), RecordIndeterminateWriteSequence(1, low, high), and the read
mask (Q6).
- Closed fences do not bound publication: only open fences do, as before.
- An exact fence matches a gate only if the group starts at or below its
high (WaitForWalDurability/WalGateFenceStatus take the group's low). A
zero-count group stamped right after the failed one (target == its high)
is outside it.
- An exact fence wakes no parked gate: it holds only its own group, whose
thread installs it.
- Flushes drop entries in the failed ranges (FlushJob::DropEntriesAtOrAbove
takes the ranges; SequenceFloorIterator hides them) beside everything at
or above the lowest open fence.
- Coalescing: a gate that queued on a sync that fails
(wal_gate_sync_failed_epoch_ >= the first sync it queued on) returns that
failure and fences its own range, instead of retrying.
Evidence:
- New DBWalAppendFailureTest.FailedGateSyncKeepsAckedWritesAbove: B (sync,
p0) held in its fsync; C (async, p1, above B) acknowledged; B's fsync
fails (FailingWalFS, retryable). C readable before and after Resume(), in
an L0 SST after Resume() with an empty active memtable, and after a clean
reopen; B absent throughout. Base: B readable ("value_b"), and C
NOT_FOUND after Resume().
- Neuter (GC18's open-ended fence): C NOT_FOUND after Resume().
- New DBWalAppendFailureTest.FailedGateSyncSparesZeroCountWriteAbove: Z, a
LogData-only write allocated right after B (target == B's high), keeps OK
when B's fsync fails. Neuter (match an exact fence by target alone): Z
fails with B's error. Base: fails too (open fence).
- GatePostWaitSyncFailureWakesParkedGate is restored to its pre-GC18 body
(the D-N71 (b) expectation; the test function is byte-identical to
29df5aa^). Argument: W is above B but outside B's range and not
acknowledged; under D-7 a failed sync fences only its own group, so W
wakes on the error, parks again (w_parks == 2, one waiter), and fails only
when M's append fails below it. At the base it fails (W returns early).
- GC18's FailedGateSyncWriteStaysInvisible passes unmodified. Neuter
(disable the coalesced failure): D's own retry succeeds, D stays parked
behind A2, and the test hangs (killed at 300 s).
## Q6 -- A failed sync write is hidden once its failure returns (D-8)
Property: from when B's call returns the error, no new read, snapshot read
or iterator sees B's range: before Resume(), after Resume() and its flush,
and after a reopen in every recovery mode. Writes outside are unaffected;
N=1 is unchanged.
How: new header db/db_impl/wal_gate_read_mask.h: WalGateReadMask, a
ReadCallback that hides the failed ranges and defers to the read's own
callback (transaction, timestamp, newer-version tracking) for everything
else. DBImpl keeps the ranges copy-on-write (wal_gate_read_masks_, leaf
mutex, flag) for the DB's lifetime. GetImpl, both MultiGet paths and
NewIteratorImpl wrap their callback while any range exists (iterators own
the wrapper via RegisterCleanup, so it survives Refresh()). With no range
(always at N=1) this costs one acquire load. The range is installed before
B's gate returns. The window limit is documented at wal_partitions.
Evidence: DBWalAppendFailureTest.FailedGateSyncStaysInvisibleAtNPartitions,
ported from pwal/ab/gc18-muse-PR9 (a304bec) with the two required
fixes:
- every recovery mode must open (ASSERT_OK, no `continue`);
- the crash leg uses SetInjectUnsyncedDataLoss(true) and a control key
written last that must be lost. Without the first fix the control key
survived, so the original leg was vacuous.
Results: base: the failed key reads "v" right after the failure. Here:
passes at N in {2, 8}. Neuter (no mask): "v" before and after Resume().
## Q7 -- The fence goes in with its background error, atomically
Property: no recovery flush can pick a memtable between a gate sync's error
and its fence.
How: RunCoalescedGateSync sets a thread-local intent (db, low, target)
around sync(). The WALIOStatusCheck that classifies the failure runs on
that thread (from SyncWalsFromCompletionGate, SyncWalImpl or FlushWAL). It
installs the exact fence and the mask in the mutex_ section that calls
SetBGError. Memtable picks read the ranges under mutex_
(FailedGateSyncFlushDrops). FenceFailedGateSync installs afterwards only
when no classification ran (an earlier failure's error, or a non-WAL
error). New sync point DBImpl::RunCoalescedGateSync:AfterFailedSync marks
where GC18 installed it.
Evidence: new DBWalAppendFailureTest.FailedGateSyncFenceGoesInWithItsError:
auto-resume on; B is a two-CF batch; the gate is held at the sync point
until recovery has completed. B is absent in both CFs after recovery and
after a reopen. Neuter (install only after sync returns): after the reopen
B is present in both CFs ("value_b"). Base: fails.
## Q8 -- A zero-count group whose gate sync fails leaves no fence
Property: no fence when low > target; the zero-count write still fails.
After Resume() the next write succeeds and nothing is recorded
indeterminate.
How: FenceFailedGateSync and InstallFailedGateSyncFence return when
low > target. The indeterminate record goes with the fence, so none is
recorded (argued).
Evidence: new TransactionPartitionedWalTest.FailedSyncPrepareLeavesNoStaleFence
(WriteCommitted sync Prepare, gate fsync fails, N=2): Prepare IOError,
TEST_WalGateFences() empty, Resume(), Put succeeds at L + 1. Base and
neuter (GC18's unconditional open fence): a fence remains and the Put fails
with "injected gate sync error".
## Q9 -- GC18's flip tests prove what they claim (test-only)
- db_wal_partitions_open_test.cc: 200 writes with every fifth synced, then
an async tail of 10. The crash leg asserts the recovered set is a prefix,
includes every synced write, and lost part of the tail
(recovered < kWrites).
- WalPartitionsValidation: ASSERT_EQ(1U, DBOptions().wal_partitions), and
the "with indexing it opens" case (ported).
Evidence: release build (DEBUG_LEVEL=0, NDEBUG; linked by hand against
librocksdb.a, since the debug-only db_test_util in librocksdb_test does not
build in release): 2/2 pass. Neuter (key 100 treated as missing): "write
101 recovered above a hole", both params fail.
## Q1 measurement
GC16 trigger cells: tools/partition_wal_sweep.py --ns 8 --sync-modes mix
(each run includes the N=1 baselines), release db_bench, 3 interleaved
pairs (base_1, head_1, base_2, head_2, base_3, head_3), --reps 3 each; the
values are per-run medians in ops/s and us. Host load at each run's end:
43.1, 42.0, 7.7, 15.5, 28.5, 25.5. base_1 overlapped the end of the
1000-cycle oracle run.
| cell | base ops/s (runs) | head ops/s (runs) | head/base (median) | base write p99 us | head write p99 us |
|---|---|---|---|---|---|
| N=1 none 1000us mix 1024B t16 | 3317, 3318, 3579 | 4839, 3280, 5758 | 1.458 | 13834, 13844, 13608 | 9736, 13857, 6462 |
| N=1 part 1000us mix 1024B t16 | 3288, 3041, 5627 | 5704, 3156, 5635 | 1.714 | 13778, 13937, 6497 | 6511, 16403, 6484 |
| N=1 none 1000us mix 1024B t32 | 9296, 5233, 6116 | 5760, 5226, 6161 | 0.942 | 8709, 16546, 13175 | 14327, 18093, 12772 |
| N=1 part 1000us mix 1024B t32 | 9265, 5149, 9058 | 9285, 5946, 9659 | 1.025 | 8870, 15377, 7912 | 8118, 13819, 7318 |
| N=8 part 1000us mix 100B t16 | 1820, 2143, 1588 | 1315, 1538, 3555 | 0.845 | 140566, 128919, 155104 | 295638, 155926, 48952 |
| N=8 part 1000us mix 1024B t16 | 1776, 1666, 1613 | 2891, 1506, 3498 | 1.735 | 144446, 150960, 151694 | 70660, 164983, 50610 |
| N=8 part 1000us mix 1024B t32 | 3081, 2843, 5429 | 5145, 3116, 5433 | 1.670 | 148746, 152857, 67336 | 70440, 147982, 65198 |
| N=8 part 1000us mix 1024B t16 slow | 1314, 1022, 1345 | 1323, 1062, 1183 | 0.900 | 113119, 189284, 107077 | 107714, 161292, 124626 |
| N=8 part 200us mix 100B t16 | 1891, 8452, 1954 | 4975, 1898, 10200 | 2.546 | 155854, 28103, 152457 | 46870, 156767, 22000 |
| N=8 part 200us mix 1024B t16 | 1842, 8347, 1950 | 6802, 1576, 10590 | 3.488 | 156510, 28943, 154478 | 32062, 164013, 21601 |
| N=8 part 50us mix 100B t16 | 1867, 5799, 2776 | 6656, 1819, 12529 | 2.398 | 155439, 46637, 101164 | 41872, 156506, 20709 |
| N=8 part 50us mix 1024B t16 | 1918, 7918, 2776 | 7374, 1868, 11700 | 2.656 | 155468, 31421, 102658 | 32144, 156637, 20653 |
| N=8 part 5000us mix 100B t16 | 719, 718, 732 | 906, 889, 955 | 1.260 | 286804, 279228, 247332 | 169307, 195981, 166496 |
| N=8 part 5000us mix 1024B t16 | 719, 794, 721 | 937, 725, 949 | 1.300 | 279029, 244712, 292117 | 168154, 300619, 165848 |
base trigger: ['0.0008 fires=False', '0.0007 fires=False', '0.0007 fires=False']
head trigger: ['0.0015 fires=False', '0.0007 fires=False', '0.0028 fires=False']
Reading: the host is shared and noisy. The same cell is bimodal (about
1.8k or about 8k ops/s) on both sides from run to run, and the N=1 cells,
whose code path this change does not touch, swing 0.94x-1.71x. Within that
noise no regression is visible: head's median is at or above base's in 11
of 14 cells. The three below 1.0 (N=1 none t32 0.94, N=8 1000us 100B 0.85,
the slow-partition cell 0.90) each have overlapping run ranges. The
abandon trigger does not fire in any run (largest ratio 0.0028, threshold
0.10). This measurement cannot resolve effects smaller than the noise.
## Fold-back split
Adding diffs from `git blame` at the base plus each commit's Differential
Revision line. GC18's lines (29df5aa, no such line) go to D123551605 as
the doc rules.
- Q1 -> D123551605: db_impl_write.cc RunCoalescedGateSync epoch checks
(blame D123551605); db_impl.h wal_gate_sync_*_epoch_ fields and the
RunCoalescedGateSync comment (D123551605). Tests:
SyncZeroCountWriteAfterSyncWriteSyncs (new, db_write_test.cc).
- Q2 -> D123971668: db_impl.cc SyncWalPartitionFiles (blame D123971668);
db_impl.h declaration (D123971668); db_impl_write.cc SyncEveryWalPartition
pass-through (:3519 D123971668, :3487 D123551605). -> D123551605:
SyncWalsFromCompletionGate error path (blame D123551605).
- Q3 -> D123476301: wal_durability_tracker.h Register/Complete comments and
assert; db_impl_write.cc AllocateSequenceAndWALIndex,
PublishAppliedPrefix, PublishAppliedFrontierLocked (the clamp lines blame
D123476301 and GC18), WriteGroupToWAL Complete, ConcurrentWriteGroupToWAL
Register/Complete (all blame D123476301). -> D123701876: WALIOStatusCheck
failed_wal_ranges_ push (blame D123701876). Tests:
ZeroCountEntryStaysBelowItsLow, ZeroCountMarkerNeverPublishesInFlightSequence.
- Q4 -> D119751506: CoverBurnedWALIndex and its WriteImpl/Pipelined call
sites, db_impl.h declaration (blame D119751506); the ConcurrentWriteGroupToWAL
call site (blame D117251771).
Test: CoverAppendSerializedWithFlushWAL.
- Q5, Q7, Q8 -> D123551605: RunCoalescedGateSync failure, coalesced failure
and intent, FenceFailedGateSync (GC18 lines), RunCompletionGate's
WaitForWalDurability call (D123551605), thread-local intent struct (new
code, here); db_impl.h FenceFailedGateSync/RunCoalescedGateSync
declarations (GC18/D123551605). -> D123701876: InstallWalGateFence
`high`/exact/signal, WalGateFenceStatusLocked low, WaitForWalDurability
low pass-through, WALIOStatusCheck intent install,
InstallFailedGateSyncFence (new, with the fence code), flush range drop
(flush_job.{h,cc} SequenceFloorIterator and DropEntriesAtOrAbove,
db_impl_compaction_flush.cc call sites: all blame D123701876), db_impl.h
WalGateFence/fence declarations (D123701876). Tests (at or above
D123079329): FailedGateSyncKeepsAckedWritesAbove,
FailedGateSyncSparesZeroCountWriteAbove,
FailedGateSyncFenceGoesInWithItsError, FailedSyncPrepareLeavesNoStaleFence
(transaction_test.cc), and the GatePostWaitSyncFailureWakesParkedGate
restore (GC18 lines -> D123551605).
- Q6 -> D123701876 / D123551605 (new code going with the fence code):
db/db_impl/wal_gate_read_mask.h (new); db_impl.h mask members and
WalGateReadMaskRanges/FailedGateSyncFlushDrops; the read-path hunks in
db_impl_sync_and_async.h GetImpl/MultiGetCommon (upstream D109346179
context), db_impl.cc MultiGetWithCallbackImpl (upstream D23790762
context) and NewIteratorImpl (upstream D98766843 lines replaced by the
wrapped return); include/rocksdb/options.h wal_partitions doc paragraph
(doc lines blame D117251769). Test: FailedGateSyncStaysInvisibleAtNPartitions.
- Q9 -> GC18's flip diff (standalone, never folded):
db_wal_partitions_open_test.cc. -> D117251769: db_options_test.cc
WalPartitionsValidation.
## Assumptions
1. Q1 mechanism: sync-start epoch plus the existing safe-point test for
groups with a count (keeps coalescing for ordinary sync writes).
2. Q3 representation: the empty range [S, S - 1]; the clamp is kept as an
assert.
3. Q5 "coalesced into the same failed sync": a gate that queued on a sync
(from the one running when it asked) shares that sync's failure and
fences its own range. A gate that arrives after a failure runs its own
sync. After a real fsync failure the writer is poisoned, so that sync
fails through the Q2 path with the stored error.
4. Q6 mask: a ReadCallback wrapper at GetImpl, MultiGet and NewIteratorImpl,
kept for the DB's lifetime (a flush or an iterator may still hold the
range; post-failure reads pay a callback). Not masked, and documented at
wal_partitions:
- tailing iterators (ForwardIterator, which reads past publication);
- range deletions in the failed write (ReadCallback does not filter
range tombstones, and the flush keeps tombstones below the open-fence
floor);
- a read or iterator that started before the failure returned.
5. Q6/Q7 residual, argued, not tested: a flush that installed its output
before the sync failed, or a recovery flush for an earlier failure that
picked the memtable before this sync's fence (the Q2 path, where no
classification runs), persists the failed write to an SST. In-process
the mask still hides it; after a reopen it is visible. Closing this
needs a flush-side filter keyed on in-flight gate syncs, out of scope.
6. Q7 uses a thread-local intent rather than plumbing the range through
SyncWAL/FlushWAL/SyncWalImpl, so the post-wait round keeps calling
SyncWAL() (GatePostWaitSyncFailureWakesParkedGate injects there).
7. Exact fences do not signal parked gates and do not match a zero-count
group whose low is above them (a new test, beyond the doc).
8. Q2: when a WAL was skipped or already failed but no background error is
recorded (recovery done, cutoff not yet cleared), the gate returns OK
after syncing the rest, as SyncWAL does.
9. The repro test SyncPrepareAfterSyncCommitSurvivesCrash still sets the
callback for the deleted sync point DBImpl::ValidateOptions:AllowWalPartitions;
harmless, left unmodified.
10. Q9's release build: linked by hand (Makefile flags, -lrocksdb_test
replaced by testharness.o and gtest-all.o), since librocksdb_test's
db_test_util.cc does not compile with DEBUG_LEVEL=0.
## Not done
none
## Test plan
Debug unless noted; TEST_TMPDIR under ~/pwal-3p/gc-20-claude-tmp;
gtest-parallel -w 60-80 (half the host's 166 cores).
- Repro tests, unmodified: SyncPrepareAfterSyncCommitSurvivesCrash and
GateSyncKeepsOtherPartitionsErrorResumable fail at the base with the
recorded symptoms and pass here.
- New tests run against the base code (test files applied to the base
worktree): every one fails at the base except
CoverAppendSerializedWithFlushWAL, which passes in debug and races under
TSan (below). Symptoms are under each question.
- Required suites, debug, one gtest-parallel run of db_write_test,
db_wal_test, transaction_test, write_prepared_transaction_test,
error_handler_fs_test, db_wal_oracle_test, checkpoint_test, plus
db_options_test, db_wal_partitions_open_test, flush_job_test and
db_flush_test (flush code changed): 7145/7145 passed. That run's binaries
predate only whitespace formatting and the new header's copyright line.
After those, debug rebuild smoke: the 31 gate/tracker/new db_write_test
tests, the 5 TransactionPartitionedWalTest tests and the 5
WalPartitions db_options tests all pass.
- An earlier db_write_test + transaction_test run (3787 tests) found one
failure: GatePostWaitSyncFailureWakesParkedGate/0, w_parks 3 vs 2. Cause:
the new exact fence's SignalAll added a spurious wake. Fixed (exact
fences do not signal; zero-count groups above them are not matched), and
the test then passed 100/100 debug and 100/100 TSan.
- 100 repeats, debug: the 12 new/changed db_write_test tests
(WalDurabilityTrackerTest.ZeroCountEntryStaysBelowItsLow,
SyncZeroCountWriteAfterSyncWriteSyncs,
ZeroCountMarkerNeverPublishesInFlightSequence,
CoverAppendSerializedWithFlushWAL, FailedGateSyncKeepsAckedWritesAbove,
FailedGateSyncSparesZeroCountWriteAbove,
FailedGateSyncStaysInvisibleAtNPartitions,
FailedGateSyncFenceGoesInWithItsError,
GateSyncKeepsOtherPartitionsErrorResumable,
GatePostWaitSyncFailureWakesParkedGate/0,
FailedGateSyncWriteStaysInvisible/0,/1): 1200/1200. The two
TransactionPartitionedWalTest tests (H1 repro, Q8): 200/200.
- TSan (clang, USE_CLANG=1 COMPILE_WITH_TSAN=1): the same 14 tests x100:
1400/1400 passed, 0 ThreadSanitizer reports. Q4: base 3/3 runs racy (3
reports each), neuter 3/3 racy, fix 0/3.
- Neuters (each verified by file hash before the build; restored after):
Q1, Q2, Q3, Q4, Q5, Q5b, Q6, Q7, Q8, coalesced failure, Q9. Each fails as
described above. The first Q5b attempt did not compile (unused `low`)
and ran a stale binary; it was redone with `(void)low;` and failed as
stated.
- GC15 oracle: ROCKSDB_WAL_ORACLE_CYCLES=1000, RecoveredStateIsPrefixOfHistory:
passed. 1000 cycles from seed 20261019 in 1241.7 s; N=2 in 507, N=8 in
493; 172923 acknowledged, 170875 recovered; power loss in 528 cycles,
losing an acknowledged write in 380 (not vacuous); 0 violations.
- N=1 byte identity (DEBUG_LEVEL=0 db_bench fillseq, --num=10000
--seed=20260928 --threads=1 --disable_auto_compactions=1): base and head
WAL 000004.log SHA-256 identical. none:
6d1351117a289a2784449a68d5421b1aa385ab0b383273c2c5918befa9181b09.
partition_by_column_family:
9a69a3fc66777fadce05e8a999479a5f57364aca27cd6d22aa00e4631adfc796.
- Q9 release build: db_wal_partitions_open_test 2/2 pass; neuter fails.
- GC16 trigger-cell sweep: table under Q1 measurement.
- make check-format (clang-format 21.1.2): "Nothing needs to be
reformatted"; the new header was checked with clang-format directly.
make check-sources: clean.
- db_stress / crash test: not run (deferred by the owner, 2026-10-27).
- ASan/UBSan: not run (not required by the doc).
JustinGaoF
force-pushed
the
pwal/gc20-claude
branch
from
October 28, 2026 20:35
5ef2201 to
f97741e
Compare
Owner
Author
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.
[GC] GC20 -- write-path fixes at N>1 (FU14 H1, M-a, K1, K3; GC18 carry-over Q5-Q9)
Reviewer question: At N>1, is every acknowledged sync=true write fsynced,
does a failed sync fence only its own range and stay hidden, does another
partition's recoverable WAL error stay recoverable, does publication never
run ahead of an in-flight range, and is the void-cover append serialized
with every buffer flush?
Short answer: yes, for all nine questions, each with a test that fails at
the base (or under its neuter) and passes here. N=1 is byte-identical. The
residual limits are listed under Assumptions.
Q1 -- Every acknowledged sync=true write is fsynced, any count (H1)
Property: a sync=true write returns OK only after an fsync that started
after its own append, on every partition, whatever its count.
How: RunCoalescedGateSync numbers gate syncs as they start
(wal_gate_sync_started_epoch_) and records the number of the latest one
that succeeded (wal_gate_synced_epoch_). A gate is covered by any sync
numbered above the last one started when it asked. A group that consumes
sequences is still also covered by the old test (a successful sync whose
safe-point read reached its target), so coalescing for ordinary sync writes
is unchanged. A zero-count group's target is the sequence below its record,
so only the epoch test applies to it. The second round
(pre_sync_safe_point < target) is correct as is: *covered is the safe point
of a sync that started after the append.
Evidence:
(repro, unmodified): base fails ("1 vs 1", xid2 lost); passes here.
LogData-only batch after a sync write. WAL_FILE_SYNCED advances, and
DropUnsyncedFileData truncates no WAL. Base: no sync, and WAL bytes go
121 -> 88 at the crash.
wal_gate_synced_upto_ >= target): bothfail.
Q2 -- Another partition's recoverable WAL error stays recoverable (M-a)
Property: a gate sync that meets a previously failed writer, or a WAL at or
below wal_recovery_cutoff_, returns the stored background error, does not
reclassify it, and does not touch the handle.
How: SyncWalPartitionFiles takes an optional
previously_failedout-parameter (the gate path passes it; the N=1 leadership sync passes
null, so N=1 is unchanged). With it, WALs at or below the cutoff are
skipped, and the sync uses WritableFileWriter::Sync(opts, use_fsync,
&seen_error) (equivalent to the old Fsync/Sync call). When set,
SyncWalsFromCompletionGate skips WALIOStatusCheck and returns the
background error, as SyncWalImpl/SyncWAL already do.
Evidence:
(repro, unmodified): base Hard (2) -> Fatal (3), Resume fails; here it
stays Hard and Resume() succeeds (the held write returns the stored
"injected" error).
Q3 -- A zero-count entry never moves a safe point past the last
allocated sequence (K1)
Property: a record that consumes no sequence pins low = S (last allocated
How: such a record registers the empty range [S, S - 1] (high = last
allocated + count, uniformly). WalDurabilityTracker accepts high == low - 1
(assert low <= high + 1); Complete then raises durable_upto only to S - 1.
The call sites drop their
count == 0 ? low : ...special cases, and thefailed-range record stores [start, failed_wal_sequence] so Release matches.
The clamp min(SafePoint, LastAllocatedSequence) in
PublishAppliedFrontierLocked is now an assert.
Evidence (both written first, both fail at the base):
at
assert(low <= high)in Register.marker, then X allocating S held before its append, then Y on another
partition completing first. Asserts LastSequence() stays at S - 1 until X
completes. Base: aborts at PublishAppliedFrontierLocked's
PendingLow(p) > frontierassertion (it publishes S).(safe point 5, not 4); the DB test aborts at the new
frontier <= LastAllocatedSequence()assertion.Q4 -- The void-cover append is serialized with every flush (K3)
Property: the cover takes the partition's WAL mutex whenever WriteToWAL
would (N>1, or manual_wal_flush && !two_write_queues); the call site that
holds it does not relock.
How: CoverBurnedWALIndex takes (wal_partition, wal_mutex_held) and locks
under WriteToWAL's condition. WriteImpl and PipelinedWriteImpl pass false;
ConcurrentWriteGroupToWAL passes true (asserted held).
Evidence: new DBWritePartitionTest.CoverAppendSerializedWithFlushWAL:
indexed, manual_wal_flush, N=2, a protected batch whose log entry is
corrupted (VerifyChecksum fails before any append, healthy writer), and a
concurrent FlushWAL loop. TSan (clang): base 3/3 runs report 3 data races
each (AlignedBuffer::Append in CoverBurnedWALIndex vs WriteBuffer in
FlushWAL); here 0/3. Neuter (no lock): 3/3 runs, 3 races each.
Q5 -- A failed gate fsync fences only its group's range (D-7)
Property: a failed gate sync fences exactly [low, target] of its group,
plus each sync group that queued on the failed sync (each fences its own
range). Writes outside keep their outcome; the flush drops only the fenced
ranges; the indeterminate record covers only them. Append fences (D-1) are
unchanged (open-ended).
How:
from the start (InstallWalGateFence gains
high; WalGateFence gainsexact), RecordIndeterminateWriteSequence(1, low, high), and the readmask (Q6).
high (WaitForWalDurability/WalGateFenceStatus take the group's low). A
zero-count group stamped right after the failed one (target == its high)
is outside it.
thread installs it.
takes the ranges; SequenceFloorIterator hides them) beside everything at
or above the lowest open fence.
(wal_gate_sync_failed_epoch_ >= the first sync it queued on) returns that
failure and fences its own range, instead of retrying.
Evidence:
p0) held in its fsync; C (async, p1, above B) acknowledged; B's fsync
fails (FailingWalFS, retryable). C readable before and after Resume(), in
an L0 SST after Resume() with an empty active memtable, and after a clean
reopen; B absent throughout. Base: B readable ("value_b"), and C
NOT_FOUND after Resume().
LogData-only write allocated right after B (target == B's high), keeps OK
when B's fsync fails. Neuter (match an exact fence by target alone): Z
fails with B's error. Base: fails too (open fence).
(the D-N71 (b) expectation; the test function is byte-identical to
29df5aa^). Argument: W is above B but outside B's range and not
acknowledged; under D-7 a failed sync fences only its own group, so W
wakes on the error, parks again (w_parks == 2, one waiter), and fails only
when M's append fails below it. At the base it fails (W returns early).
(disable the coalesced failure): D's own retry succeeds, D stays parked
behind A2, and the test hangs (killed at 300 s).
Q6 -- A failed sync write is hidden once its failure returns (D-8)
Property: from when B's call returns the error, no new read, snapshot read
or iterator sees B's range: before Resume(), after Resume() and its flush,
and after a reopen in every recovery mode. Writes outside are unaffected;
N=1 is unchanged.
How: new header db/db_impl/wal_gate_read_mask.h: WalGateReadMask, a
ReadCallback that hides the failed ranges and defers to the read's own
callback (transaction, timestamp, newer-version tracking) for everything
else. DBImpl keeps the ranges copy-on-write (wal_gate_read_masks_, leaf
mutex, flag) for the DB's lifetime. GetImpl, both MultiGet paths and
NewIteratorImpl wrap their callback while any range exists (iterators own
the wrapper via RegisterCleanup, so it survives Refresh()). With no range
(always at N=1) this costs one acquire load. The range is installed before
B's gate returns. The window limit is documented at wal_partitions.
Evidence: DBWalAppendFailureTest.FailedGateSyncStaysInvisibleAtNPartitions,
ported from pwal/ab/gc18-muse-PR9 (a304bec) with the two required
fixes:
continue);written last that must be lost. Without the first fix the control key
survived, so the original leg was vacuous.
Results: base: the failed key reads "v" right after the failure. Here:
passes at N in {2, 8}. Neuter (no mask): "v" before and after Resume().
Q7 -- The fence goes in with its background error, atomically
Property: no recovery flush can pick a memtable between a gate sync's error
and its fence.
How: RunCoalescedGateSync sets a thread-local intent (db, low, target)
around sync(). The WALIOStatusCheck that classifies the failure runs on
that thread (from SyncWalsFromCompletionGate, SyncWalImpl or FlushWAL). It
installs the exact fence and the mask in the mutex_ section that calls
SetBGError. Memtable picks read the ranges under mutex_
(FailedGateSyncFlushDrops). FenceFailedGateSync installs afterwards only
when no classification ran (an earlier failure's error, or a non-WAL
error). New sync point DBImpl::RunCoalescedGateSync:AfterFailedSync marks
where GC18 installed it.
Evidence: new DBWalAppendFailureTest.FailedGateSyncFenceGoesInWithItsError:
auto-resume on; B is a two-CF batch; the gate is held at the sync point
until recovery has completed. B is absent in both CFs after recovery and
after a reopen. Neuter (install only after sync returns): after the reopen
B is present in both CFs ("value_b"). Base: fails.
Q8 -- A zero-count group whose gate sync fails leaves no fence
Property: no fence when low > target; the zero-count write still fails.
After Resume() the next write succeeds and nothing is recorded
indeterminate.
How: FenceFailedGateSync and InstallFailedGateSyncFence return when
low > target. The indeterminate record goes with the fence, so none is
recorded (argued).
Evidence: new TransactionPartitionedWalTest.FailedSyncPrepareLeavesNoStaleFence
(WriteCommitted sync Prepare, gate fsync fails, N=2): Prepare IOError,
TEST_WalGateFences() empty, Resume(), Put succeeds at L + 1. Base and
neuter (GC18's unconditional open fence): a fence remains and the Put fails
with "injected gate sync error".
Q9 -- GC18's flip tests prove what they claim (test-only)
an async tail of 10. The crash leg asserts the recovered set is a prefix,
includes every synced write, and lost part of the tail
(recovered < kWrites).
the "with indexing it opens" case (ported).
Evidence: release build (DEBUG_LEVEL=0, NDEBUG; linked by hand against
librocksdb.a, since the debug-only db_test_util in librocksdb_test does not
build in release): 2/2 pass. Neuter (key 100 treated as missing): "write
101 recovered above a hole", both params fail.
Q1 measurement
GC16 trigger cells: tools/partition_wal_sweep.py --ns 8 --sync-modes mix
(each run includes the N=1 baselines), release db_bench, 3 interleaved
pairs (base_1, head_1, base_2, head_2, base_3, head_3), --reps 3 each; the
values are per-run medians in ops/s and us. Host load at each run's end:
43.1, 42.0, 7.7, 15.5, 28.5, 25.5. base_1 overlapped the end of the
1000-cycle oracle run.
Reading: the host is shared and noisy. The same cell is bimodal (about
1.8k or about 8k ops/s) on both sides from run to run, and the N=1 cells,
whose code path this change does not touch, swing 0.94x-1.71x. Within that
noise no regression is visible: head's median is at or above base's in 11
of 14 cells. The three below 1.0 (N=1 none t32 0.94, N=8 1000us 100B 0.85,
the slow-partition cell 0.90) each have overlapping run ranges. The
abandon trigger does not fire in any run (largest ratio 0.0028, threshold
0.10). This measurement cannot resolve effects smaller than the noise.
Fold-back split
Adding diffs from
git blameat the base plus each commit's DifferentialRevision line. GC18's lines (29df5aa, no such line) go to D123551605 as
the doc rules.
(blame D123551605); db_impl.h wal_gate_sync_*epoch fields and the
RunCoalescedGateSync comment (D123551605). Tests:
SyncZeroCountWriteAfterSyncWriteSyncs (new, db_write_test.cc).
db_impl.h declaration (D123971668); db_impl_write.cc SyncEveryWalPartition
pass-through (:3519 D123971668, :3487 D123551605). -> D123551605:
SyncWalsFromCompletionGate error path (blame D123551605).
assert; db_impl_write.cc AllocateSequenceAndWALIndex,
PublishAppliedPrefix, PublishAppliedFrontierLocked (the clamp lines blame
D123476301 and GC18), WriteGroupToWAL Complete, ConcurrentWriteGroupToWAL
Register/Complete (all blame D123476301). -> D123701876: WALIOStatusCheck
failed_wal_ranges_ push (blame D123701876). Tests:
ZeroCountEntryStaysBelowItsLow, ZeroCountMarkerNeverPublishesInFlightSequence.
sites, db_impl.h declaration (blame D119751506); the ConcurrentWriteGroupToWAL
call site (blame D117251771).
Test: CoverAppendSerializedWithFlushWAL.
and intent, FenceFailedGateSync (GC18 lines), RunCompletionGate's
WaitForWalDurability call (D123551605), thread-local intent struct (new
code, here); db_impl.h FenceFailedGateSync/RunCoalescedGateSync
declarations (GC18/D123551605). -> D123701876: InstallWalGateFence
high/exact/signal, WalGateFenceStatusLocked low, WaitForWalDurabilitylow pass-through, WALIOStatusCheck intent install,
InstallFailedGateSyncFence (new, with the fence code), flush range drop
(flush_job.{h,cc} SequenceFloorIterator and DropEntriesAtOrAbove,
db_impl_compaction_flush.cc call sites: all blame D123701876), db_impl.h
WalGateFence/fence declarations (D123701876). Tests (at or above
D123079329): FailedGateSyncKeepsAckedWritesAbove,
FailedGateSyncSparesZeroCountWriteAbove,
FailedGateSyncFenceGoesInWithItsError, FailedSyncPrepareLeavesNoStaleFence
(transaction_test.cc), and the GatePostWaitSyncFailureWakesParkedGate
restore (GC18 lines -> D123551605).
db/db_impl/wal_gate_read_mask.h (new); db_impl.h mask members and
WalGateReadMaskRanges/FailedGateSyncFlushDrops; the read-path hunks in
db_impl_sync_and_async.h GetImpl/MultiGetCommon (upstream D109346179
context), db_impl.cc MultiGetWithCallbackImpl (upstream D23790762
context) and NewIteratorImpl (upstream D98766843 lines replaced by the
wrapped return); include/rocksdb/options.h wal_partitions doc paragraph
(doc lines blame D117251769). Test: FailedGateSyncStaysInvisibleAtNPartitions.
db_wal_partitions_open_test.cc. -> D117251769: db_options_test.cc
WalPartitionsValidation.
Assumptions
groups with a count (keeps coalescing for ordinary sync writes).
assert.
(from the one running when it asked) shares that sync's failure and
fences its own range. A gate that arrives after a failure runs its own
sync. After a real fsync failure the writer is poisoned, so that sync
fails through the Q2 path with the stored error.
kept for the DB's lifetime (a flush or an iterator may still hold the
range; post-failure reads pay a callback). Not masked, and documented at
wal_partitions:
range tombstones, and the flush keeps tombstones below the open-fence
floor);
before the sync failed, or a recovery flush for an earlier failure that
picked the memtable before this sync's fence (the Q2 path, where no
classification runs), persists the failed write to an SST. In-process
the mask still hides it; after a reopen it is visible. Closing this
needs a flush-side filter keyed on in-flight gate syncs, out of scope.
SyncWAL/FlushWAL/SyncWalImpl, so the post-wait round keeps calling
SyncWAL() (GatePostWaitSyncFailureWakesParkedGate injects there).
group whose low is above them (a new test, beyond the doc).
recorded (recovery done, cutoff not yet cleared), the gate returns OK
after syncing the rest, as SyncWAL does.
callback for the deleted sync point DBImpl::ValidateOptions:AllowWalPartitions;
harmless, left unmodified.
replaced by testharness.o and gtest-all.o), since librocksdb_test's
db_test_util.cc does not compile with DEBUG_LEVEL=0.
Not done
none
Test plan
Debug unless noted; TEST_TMPDIR under ~/pwal-3p/gc-20-claude-tmp;
gtest-parallel -w 60-80 (half the host's 166 cores).
GateSyncKeepsOtherPartitionsErrorResumable fail at the base with the
recorded symptoms and pass here.
worktree): every one fails at the base except
CoverAppendSerializedWithFlushWAL, which passes in debug and races under
TSan (below). Symptoms are under each question.
db_wal_test, transaction_test, write_prepared_transaction_test,
error_handler_fs_test, db_wal_oracle_test, checkpoint_test, plus
db_options_test, db_wal_partitions_open_test, flush_job_test and
db_flush_test (flush code changed): 7145/7145 passed. That run's binaries
predate only whitespace formatting and the new header's copyright line.
After those, debug rebuild smoke: the 31 gate/tracker/new db_write_test
tests, the 5 TransactionPartitionedWalTest tests and the 5
WalPartitions db_options tests all pass.
failure: GatePostWaitSyncFailureWakesParkedGate/0, w_parks 3 vs 2. Cause:
the new exact fence's SignalAll added a spurious wake. Fixed (exact
fences do not signal; zero-count groups above them are not matched), and
the test then passed 100/100 debug and 100/100 TSan.
(WalDurabilityTrackerTest.ZeroCountEntryStaysBelowItsLow,
SyncZeroCountWriteAfterSyncWriteSyncs,
ZeroCountMarkerNeverPublishesInFlightSequence,
CoverAppendSerializedWithFlushWAL, FailedGateSyncKeepsAckedWritesAbove,
FailedGateSyncSparesZeroCountWriteAbove,
FailedGateSyncStaysInvisibleAtNPartitions,
FailedGateSyncFenceGoesInWithItsError,
GateSyncKeepsOtherPartitionsErrorResumable,
GatePostWaitSyncFailureWakesParkedGate/0,
FailedGateSyncWriteStaysInvisible/0,/1): 1200/1200. The two
TransactionPartitionedWalTest tests (H1 repro, Q8): 200/200.
1400/1400 passed, 0 ThreadSanitizer reports. Q4: base 3/3 runs racy (3
reports each), neuter 3/3 racy, fix 0/3.
Q1, Q2, Q3, Q4, Q5, Q5b, Q6, Q7, Q8, coalesced failure, Q9. Each fails as
described above. The first Q5b attempt did not compile (unused
low)and ran a stale binary; it was redone with
(void)low;and failed asstated.
passed. 1000 cycles from seed 20261019 in 1241.7 s; N=2 in 507, N=8 in
493; 172923 acknowledged, 170875 recovered; power loss in 528 cycles,
losing an acknowledged write in 380 (not vacuous); 0 violations.
--seed=20260928 --threads=1 --disable_auto_compactions=1): base and head
WAL 000004.log SHA-256 identical. none:
6d1351117a289a2784449a68d5421b1aa385ab0b383273c2c5918befa9181b09.
partition_by_column_family:
9a69a3fc66777fadce05e8a999479a5f57364aca27cd6d22aa00e4631adfc796.
reformatted"; the new header was checked with clang-format directly.
make check-sources: clean.