Repository navigation
[GC] GC22: Keep N>1 timestamped snapshots in order; refuse partitioned WALs before secondary replay - #14
Closed
JustinGaoF wants to merge 1 commit into
Closed
[GC] GC22: Keep N>1 timestamped snapshots in order; refuse partitioned WALs before secondary replay#14JustinGaoF wants to merge 1 commit into
JustinGaoF wants to merge 1 commit into
Conversation
…d WALs before secondary replay [GC] GC22 -- gap-close2 FU14 H2 and M-b, on pwal/gc22-base @ 5c602c3. Reviewer question: At N>1, does the snapshot list stay in sequence order when a commit creates a timestamped snapshot, and does a secondary instance refuse a partitioned WAL set before applying anything? Yes to both. Q1 (FU14 H2). Does the snapshot list stay sorted when a commit creates a timestamped snapshot at N>1? Property. At N>1 snapshots_ stays sorted by sequence. Compaction and flush keep every version the timestamped snapshot at S can see, including versions written between S's publication and the callback. When the commit succeeds and the timestamps agree with the sequences, the snapshot is created even if callbacks on different partitions run out of sequence order. N=1 is unchanged. How: - DBImpl::WriteImpl (N>1 groups with a post-memtable callback only): before the group inserts and publishes, insert a reserved SnapshotImpl at the group's last sequence into snapshots_ under mutex_. The group's range is registered and not yet applied, so the published frontier is below it. Any snapshot taken, and any flush or compaction started, after the frontier passes S sees S in the list. The completion-gate wrapper owns the reservation through a shared_ptr whose deleter calls ReleaseSnapshot. It is released when the write group is destroyed, which happens after the callback (still run after the gate, as before) has created the real timestamped snapshot at S. The reservation is also released when the gate is skipped or fails. It is never exposed to users: timestamped_snapshots_ is only filled after the gate, so no reader can read at S before S is published. - SnapshotList::New inserts in sequence order, walking back from the tail. A GetSnapshot() taken while a reservation sits above the published sequence would otherwise land after it. When the list is already sorted (always the case at N=1) the loop runs zero iterations, so the list and its order are unchanged. - CreateTimestampedSnapshotImpl at N>1: when the latest timestamped snapshot has a higher sequence than the new one (another partition's callback ran first), check against the latest one at or below the new sequence with the existing rules. The next one above must then have a larger timestamp, or the call returns InvalidArgument. New helper TimestampedSnapshotList::GetLatestAtOrBelow. Before this change the debug build failed `assert(latest_snap_seq <= snapshot_seq)`, and the release build refused a consistent request with "snapshot exists with larger timestamp". Evidence: - FU14TimestampedSnapshotListStaysSorted. Base: `snapshots_ list order: 7 2 (t1 snapshot 2, reader snapshot 7)`. Now: passes, unmodified. - FU14TimestampedSnapshotSurvivesCompaction. Base: debug abort at compaction_iterator.cc:223 `snapshots_->at(i - 1) < snapshots_->at(i)`. Now: passes, unmodified. - New GC22TimestampedSnapshotReservedBeforePublish (assert-free value check). T1 is held at its gate after publishing S, K@(S+1)="new" is written, cf is flushed and compacted, then T1 is released. Snapshot S must read "old". Without the reservation the flush drops K@(S-1) and S reads NotFound. - New GC22TimestampedSnapshotsOutOfSequenceOrder. T1 (ts 10) is held while T2 (ts 20) on the other partition creates its snapshot first. Both snapshots must exist, ordered by ts and sequence. Then the inverted case: T3 (ts 30) below T4 (ts 25) gets no snapshot, its commit still succeeds, and snapshots_ stays sorted. - Neuters (each built, binary confirmed rebuilt, test run): - Today's placement (all Q1 production hunks reverted): both repro tests fail as at base. ReservedBeforePublish fails with NotFound / "" instead of "old". OutOfSequenceOrder aborts at db_impl.cc `latest_snap_seq <= snapshot_seq`. - Reservation only removed: ReservedBeforePublish fails (NotFound). The repro tests pass, because sorted insert alone fixes the order but not the flush window. - Sorted insert only removed: ListStaysSorted fails (`7 2`), SurvivesCompaction aborts at compaction_iterator.cc:223, and OutOfSequenceOrder fails is_sorted. - Timestamp check only removed: OutOfSequenceOrder aborts at `latest_snap_seq <= snapshot_seq`. Q2 (FU14 M-b). Does the secondary refuse a partitioned WAL set before applying any record? Property. In a catch-up round (and at OpenAsSecondary), the secondary applies nothing and creates no reader if any WAL in the round may belong to a partitioned set: a marker naming a partition other than 0, or, when some WAL in the round carries the WAL index, a WAL whose head is empty or has nothing readable yet, or whose records carry the WAL index without a marker. It returns NotSupported, and a later round retries. kNone WALs never carry the index, so non-partitioned secondaries take the old path. How: new DBImplSecondary::CheckNoPartitionedWal runs at the top of RecoverLogFiles, before MaybeInitLogReader or any replay. For each WAL it uses the existing reader's state when that reader has consumed the head (SawWALIndexMarker or LastRecordEnd > 0). Otherwise it reads the head afresh: one ReadRecord on a fresh log::Reader, as ReadWALPartition does, which it replaces. MaybeInitLogReader's per-reader ReadWALPartition check is removed. The in-loop WALPartition() check stays as the backstop for a marker that lands between the scan and the replay. Evidence: - FU14CatchUpRefusesBeforeApplyingPartitionZero. Base: `TryCatchUpWithPrimary -> OK`, `secondary sees p0_big0=1 p1_lower=0`. Now: NotSupported ("WAL 25 has no readable WAL index marker while other WALs carry one ..."), `p0_big0=0 p1_lower=0`. Passes, unmodified. - New GC22RefusesMarkerlessIndexedWal (N=1, indexed). The secondary catches up across a WAL switch whose new marker is on disk (no false refusal). After the head marker record of the current WAL is stripped, OpenAsSecondary returns NotSupported. - All existing db_secondary_test tests pass (75/75 before the new test). - Neuters: - Today's per-reader check (Q2 production hunks reverted): the repro fails as at base. GC22RefusesMarkerlessIndexedWal fails (open succeeds). - Empty-head rule only removed: the repro fails (OK, p0_big0=1 p1_lower=0). - Markerless-indexed rule only removed: GC22RefusesMarkerlessIndexedWal fails. Fold-back split (absorbing diffs per the map; tests go with their code): - Q1 -> D123551605 (callback placement): - db/db_impl/db_impl_write.cc, the hunk in WriteImpl's has_post_memtable_callback block (reservation and capture). It modifies D123551605 lines. - db/snapshot_impl.h, SnapshotList::New sorted insert. It modifies upstream lines (D35783919 / initial checkin), new code serving D123551605. - db/snapshot_impl.h, TimestampedSnapshotList::GetLatestAtOrBelow (new code). - db/db_impl/db_impl.cc, the CreateTimestampedSnapshotImpl N>1 hunk (new code in upstream D35783919 lines, beside D123551605's N>1 branch). - Tests: utilities/transactions/transaction_test.cc RunWithCommitHeldAtGate, GC22TimestampedSnapshotReservedBeforePublish and GC22TimestampedSnapshotsOutOfSequenceOrder (new, appended after the repro tests; they reuse the repro's FU14SnapshotRace Open/Close without changing it). - Q2 -> D127093323 (secondary refusal): - db/db_impl/db_impl_secondary.cc, MaybeInitLogReader: removal of the ReadWALPartition check (D127093323 lines). - db/db_impl/db_impl_secondary.cc, new CheckNoPartitionedWal (new code). - db/db_impl/db_impl_secondary.cc, RecoverLogFiles: call at the top (modifies the upstream D15386512 `Status status;` line). - db/db_impl/db_impl_secondary.h, declaration (new code). - Tests: db/db_secondary_test.cc GC22RefusesMarkerlessIndexedWal (new). Assumptions: - Q1: refusing post_memtable_callback at N>1 is out, because the repro tests ASSERT_OK the commit. Sorted insert alone is not enough: a flush started between S's publication and the callback drops K@(S-1) (proved by the reservation-only neuter). So a reservation before publication is required. It lives in snapshots_ only, never in timestamped_snapshots_, so readers never get a snapshot above the published frontier. - Q1: the reservation is a write-conflict boundary, like the snapshot it stands for (conservative for compaction). Its unix time comes from the clock, so GetOldestSnapshotTime stays meaningful. - Q1: the "never fails because of cross-partition ordering" requirement is read as "timestamps that agree with the commit sequences never fail". Timestamps that disagree with the sequence order still get InvalidArgument, as they do at N=1 for writes in different groups. - Q2: a WAL whose head is empty or not yet readable is only "an indexed WAL" when another WAL in the round carries the index. The secondary has no other source: its own options need not match the primary's, and the MANIFEST does not record partitions. The repro's secondary runs with kNone options. - Q2: an N=1 primary with partition_wal_usage=kPartitionByColumnFamily whose newest WAL head is not yet on disk (manual_wal_flush keeps the marker buffered, or the creation-to-marker window) looks exactly like the repro's N=2 state (#24 indexed with data, #25 empty). Its secondary now gets a transient NotSupported until the marker is written, where before it replayed. This is fail-closed, following the doc's trigger list. kNone N=1 secondaries are unchanged. Without manual_wal_flush the marker is flushed when the WAL is created, so the window is tiny. - Q2: a WAL that cannot be opened during the pre-scan counts as giving no information (as ReadWALPartition's error was ignored before). For a new reader, MaybeInitLogReader still reports the open failure. - Q2: an existing reader counts as having seen its head once it has consumed bytes (LastRecordEnd() > 0) or the marker. This avoids re-reading every live WAL's head each round on kNone secondaries. - The repro tests still set the removed DBImpl::ValidateOptions: AllowWalPartitions sync-point callback (removed by GC18). The callback never fires and is harmless; tests left unmodified. Not done: - db_stress / crash test: not required (owner deferred, 2026-10-27). - No release-build run of the SyncPoint race tests: SyncPoint compiles out under NDEBUG. GC22TimestampedSnapshotReservedBeforePublish is the assert-free value check (its neuter fails on the value, not an assert). Test plan: All runs at the final tree (git diff sha256 4f87d66c...), TEST_TMPDIR under ~/pwal-3p/gc-22-claude-tmp, -j83 (half of 166 cores). The host is shared: load average was 13-18 during the suite run, and no failures were seen. 1. Base check: HEAD 5c602c3, clean, rev-list count 40 -- OK. 2. Repro tests at base (debug): ListStaysSorted FAIL `7 2`; SurvivesCompaction abort compaction_iterator.cc:223; FU14CatchUpRefusesBeforeApplyingPartitionZero FAIL (OK; p0_big0=1 p1_lower=0). Same symptoms as recorded. 3. Debug, gtest-parallel -w 83: transaction_test, write_prepared_transaction_test, db_secondary_test, db_write_test, db_basic_test, db_compaction_test -- 5458/5458 passed, 0 failed. 4. Neuters (7, listed above): each built and run, and each failed exactly the tests named. Tree restored afterwards (diff hash re-checked). 5. 100x repeats, debug: transaction_test *FU14*:*GC22* 400/400 (run twice); db_secondary_test *FU14*:*GC22* 200/200. 6. TSan (USE_CLANG=1 COMPILE_WITH_TSAN=1), 100x: transaction_test *FU14*:*GC22* 400/400, 0 TSan warnings; db_secondary_test *FU14*:*GC22* 200/200, 0 TSan warnings. 7. GC15 oracle, ROCKSDB_WAL_ORACLE_CYCLES=1000 ./db_wal_oracle_test (debug): 1000 cycles from seed 20261019 in 953 s; N=2 in 507, N=8 in 493; power loss in 528; 0 violations. All 4 tests pass (including the 3 oracle neuter tests). 8. N=1 byte identity (DEBUG_LEVEL=0 db_bench, fillseq --num=10000 --seed=20260928 --threads=1 --disable_auto_compactions=1), SHA-256 of 000004.log: - none: base 6d1351117a289a2784449a68d5421b1aa385ab0b383273c2c5918befa9181b09, commit identical. - partition_by_column_family: base 9a69a3fc66777fadce05e8a999479a5f57364aca27cd6d22aa00e4631adfc796, commit identical. 9. make check-format (clang-format 21.1.2): "Nothing needs to be reformatted!". make check-sources: clean. 10. db_stress / crash test: not run (not required; owner deferred). 11. ASan/UBSan: not run (not required by this doc).
JustinGaoF
force-pushed
the
pwal/gc22-claude
branch
from
October 28, 2026 20:35
23cf026 to
652ecdf
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] GC22 -- gap-close2 FU14 H2 and M-b, on pwal/gc22-base @ 5c602c3.
Reviewer question: At N>1, does the snapshot list stay in sequence order
when a commit creates a timestamped snapshot, and does a secondary instance
refuse a partitioned WAL set before applying anything?
Yes to both.
Q1 (FU14 H2). Does the snapshot list stay sorted when a commit creates a
timestamped snapshot at N>1?
Property. At N>1 snapshots_ stays sorted by sequence. Compaction and flush
keep every version the timestamped snapshot at S can see, including versions
written between S's publication and the callback. When the commit succeeds
and the timestamps agree with the sequences, the snapshot is created even if
callbacks on different partitions run out of sequence order. N=1 is
unchanged.
How:
the group inserts and publishes, insert a reserved SnapshotImpl at the
group's last sequence into snapshots_ under mutex_. The group's range is
registered and not yet applied, so the published frontier is below it. Any
snapshot taken, and any flush or compaction started, after the frontier
passes S sees S in the list. The completion-gate wrapper owns the
reservation through a shared_ptr whose deleter calls ReleaseSnapshot. It is
released when the write group is destroyed, which happens after the
callback (still run after the gate, as before) has created the real
timestamped snapshot at S. The reservation is also released when the gate
is skipped or fails. It is never exposed to users: timestamped_snapshots_
is only filled after the gate, so no reader can read at S before S is
published.
A GetSnapshot() taken while a reservation sits above the published
sequence would otherwise land after it. When the list is already sorted
(always the case at N=1) the loop runs zero iterations, so the list and its
order are unchanged.
has a higher sequence than the new one (another partition's callback ran
first), check against the latest one at or below the new sequence with the
existing rules. The next one above must then have a larger timestamp, or
the call returns InvalidArgument. New helper
TimestampedSnapshotList::GetLatestAtOrBelow. Before this change the debug
build failed
assert(latest_snap_seq <= snapshot_seq), and the releasebuild refused a consistent request with "snapshot exists with larger
timestamp".
Evidence:
snapshots_ list order: 7 2 (t1 snapshot 2, reader snapshot 7). Now: passes, unmodified.compaction_iterator.cc:223
snapshots_->at(i - 1) < snapshots_->at(i).Now: passes, unmodified.
check). T1 is held at its gate after publishing S, K@(S+1)="new" is
written, cf is flushed and compacted, then T1 is released. Snapshot S must
read "old". Without the reservation the flush drops K@(S-1) and S reads
NotFound.
T2 (ts 20) on the other partition creates its snapshot first. Both
snapshots must exist, ordered by ts and sequence. Then the inverted case:
T3 (ts 30) below T4 (ts 25) gets no snapshot, its commit still succeeds,
and snapshots_ stays sorted.
fail as at base. ReservedBeforePublish fails with NotFound / "" instead
of "old". OutOfSequenceOrder aborts at db_impl.cc
latest_snap_seq <= snapshot_seq.repro tests pass, because sorted insert alone fixes the order but not the
flush window.
7 2),SurvivesCompaction aborts at compaction_iterator.cc:223, and
OutOfSequenceOrder fails is_sorted.
latest_snap_seq <= snapshot_seq.Q2 (FU14 M-b). Does the secondary refuse a partitioned WAL set before
applying any record?
Property. In a catch-up round (and at OpenAsSecondary), the secondary
applies nothing and creates no reader if any WAL in the round may belong to a
partitioned set: a marker naming a partition other than 0, or, when some WAL
in the round carries the WAL index, a WAL whose head is empty or has nothing
readable yet, or whose records carry the WAL index without a marker. It
returns NotSupported, and a later round retries. kNone WALs never carry the
index, so non-partitioned secondaries take the old path.
How: new DBImplSecondary::CheckNoPartitionedWal runs at the top of
RecoverLogFiles, before MaybeInitLogReader or any replay. For each WAL it
uses the existing reader's state when that reader has consumed the head
(SawWALIndexMarker or LastRecordEnd > 0). Otherwise it reads the head
afresh: one ReadRecord on a fresh log::Reader, as ReadWALPartition does,
which it replaces. MaybeInitLogReader's per-reader ReadWALPartition check is
removed. The in-loop WALPartition() check stays as the backstop for a marker
that lands between the scan and the replay.
Evidence:
TryCatchUpWithPrimary -> OK,secondary sees p0_big0=1 p1_lower=0. Now: NotSupported ("WAL 25has no readable WAL index marker while other WALs carry one ..."),
p0_big0=0 p1_lower=0. Passes, unmodified.up across a WAL switch whose new marker is on disk (no false refusal).
After the head marker record of the current WAL is stripped,
OpenAsSecondary returns NotSupported.
as at base. GC22RefusesMarkerlessIndexedWal fails (open succeeds).
p1_lower=0).
fails.
Fold-back split (absorbing diffs per the map; tests go with their code):
has_post_memtable_callback block (reservation and capture). It modifies
D123551605 lines.
upstream lines (D35783919 / initial checkin), new code serving
D123551605.
code).
code in upstream D35783919 lines, beside D123551605's N>1 branch).
RunWithCommitHeldAtGate, GC22TimestampedSnapshotReservedBeforePublish
and GC22TimestampedSnapshotsOutOfSequenceOrder (new, appended after the
repro tests; they reuse the repro's FU14SnapshotRace Open/Close without
changing it).
ReadWALPartition check (D127093323 lines).
(modifies the upstream D15386512
Status status;line).Assumptions:
ASSERT_OK the commit. Sorted insert alone is not enough: a flush started
between S's publication and the callback drops K@(S-1) (proved by the
reservation-only neuter). So a reservation before publication is required.
It lives in snapshots_ only, never in timestamped_snapshots_, so readers
never get a snapshot above the published frontier.
stands for (conservative for compaction). Its unix time comes from the
clock, so GetOldestSnapshotTime stays meaningful.
read as "timestamps that agree with the commit sequences never fail".
Timestamps that disagree with the sequence order still get InvalidArgument,
as they do at N=1 for writes in different groups.
when another WAL in the round carries the index. The secondary has no
other source: its own options need not match the primary's, and the
MANIFEST does not record partitions. The repro's secondary runs with kNone
options.
newest WAL head is not yet on disk (manual_wal_flush keeps the marker
buffered, or the creation-to-marker window) looks exactly like the repro's
N=2 state ([Muse][GC] GC26: Resume, N-changes and rollback leave the DB openable; recovery modes follow D-10 #24 indexed with data, [GC] GC26: Resume, N changes and rollback leave the DB openable; recovery modes follow D-10 #25 empty). Its secondary now gets a
transient NotSupported until the marker is written, where before it
replayed. This is fail-closed, following the doc's trigger list.
kNone N=1 secondaries are unchanged. Without manual_wal_flush the marker
is flushed when the WAL is created, so the window is tiny.
information (as ReadWALPartition's error was ignored before). For a new
reader, MaybeInitLogReader still reports the open failure.
bytes (LastRecordEnd() > 0) or the marker. This avoids re-reading every
live WAL's head each round on kNone secondaries.
AllowWalPartitions sync-point callback (removed by GC18). The callback
never fires and is harmless; tests left unmodified.
Not done:
under NDEBUG. GC22TimestampedSnapshotReservedBeforePublish is the
assert-free value check (its neuter fails on the value, not an assert).
Test plan:
All runs at the final tree (git diff sha256 4f87d66c...), TEST_TMPDIR under
~/pwal-3p/gc-22-claude-tmp, -j83 (half of 166 cores). The host is shared:
load average was 13-18 during the suite run, and no failures were seen.
7 2;SurvivesCompaction abort compaction_iterator.cc:223;
FU14CatchUpRefusesBeforeApplyingPartitionZero FAIL (OK; p0_big0=1
p1_lower=0). Same symptoms as recorded.
write_prepared_transaction_test, db_secondary_test, db_write_test,
db_basic_test, db_compaction_test -- 5458/5458 passed, 0 failed.
the tests named. Tree restored afterwards (diff hash re-checked).
twice); db_secondary_test FU14:GC22 200/200.
FU14:GC22 400/400, 0 TSan warnings; db_secondary_test FU14:GC22
200/200, 0 TSan warnings.
(debug): 1000 cycles from seed 20261019 in 953 s; N=2 in 507, N=8 in
493; power loss in 528; 0 violations. All 4 tests pass (including the 3
oracle neuter tests).
--seed=20260928 --threads=1 --disable_auto_compactions=1), SHA-256 of
000004.log:
commit identical.
9a69a3fc66777fadce05e8a999479a5f57364aca27cd6d22aa00e4631adfc796,
commit identical.
reformatted!". make check-sources: clean.
(Candidate reconstructed byte-identically from the session trajectory; the original commit lives on the OnDemand host where the session ran.)