Skip to content

[GC] GC23: Fail closed on misplaced supersessions, keep skipped superseded holes safe, pin GC22's snapshot and secondary fixes - #18

Closed
JustinGaoF wants to merge 1 commit into
pwal/gc23-basefrom
pwal/gc23-claude
Closed

JustinGaoF wants to merge 1 commit into
pwal/gc23-basefrom
pwal/gc23-claude

Conversation

@JustinGaoF

Copy link
Copy Markdown
Owner

[GC] GC23 -- recovery and consumer carry-over after GC19 and GC22, on
pwal/gc23-base @ c1f219f.

Reviewer question: Can any recovery path now replay a superseded record,
skip a superseded-only hole, or accept a damaged unattested head, and are
GC22's snapshot and secondary fixes fully pinned?

Short answer:

  • No recovery path replays a superseded record. A supersession written
    after data now fails closed in every mode, naming the WAL.
  • A superseded-only hole is skipped only when that is safe. That includes
    a new case found this round: an open skips a trailing hole and later
    writes land above it.
  • A damaged head that no attestation bounds still fails closed. The
    history floor never reaches a member that is not first of history.
  • GC22's fixes are pinned: properties, the secondary's empty-head and
    retry cases, the N=1 transient refusal, and a value check that needs no
    SyncPoint.
  • One gap remains, the same at the base: a deleted current (untracked)
    WAL whose lost record sits below the survivors (Q2, Not done).

Tests ported from the losing candidates (Muse), with thanks:

  • From GC19 (Muse): GC19H6FloorUnsetHeadDamageStillFails,
    GC19H6FloorSetAbsoluteAndSkipOutcomes,
    LogMergeTest.SupersededOnlyHoleInsideLiveStreamStops,
    LogMergeTest.TrailingSupersededHoleWithoutLiveAboveSkips, and
    InterleavedMixedSetWithSupersessionsFailsClosed (reworked per Q5).
  • From GC22 (Muse): DBSecondaryTest.CatchUpEmptyUnindexedWalAppliesNothing
    and DBSecondaryTest.CatchUpRefusesIndexedRoundWithEmptyHead.

Q1. Does supersession detection find every declaration? (option (a))

  • Property: supersession records are written only into the head of a new
    WAL, ahead of its first data record, and the write site asserts it. A
    supersession met after a data or progress record is never honored. On
    either recovery path (sequential ProcessLogFile, or the merge) it fails
    the open in every mode with "WAL declares a WAL index supersession
    after a data record; recovery cannot honor it". No superseded record is
    applied, because the open fails before anything persists.
  • How:
    • log::Reader already reported a misplaced supersession as corruption
      and dropped it. Skip mode swallowed that report, and point-in-time
      had already replayed the earlier WAL by then. The reader now also
      records it (SawMisplacedWALIndexSupersession).
    • ProcessLogFile and ProcessLogFilesMerged turn that flag into the
      status above (MisplacedSupersessionStatus).
    • DBImpl::WriteWALIndexSupersessions asserts that its WAL has recorded
      no data record (last_wal_index_recorded() == 0).
    • Detection stays head-only: no WAL is re-read.
  • Evidence: new DBWALIndexTest.SupersessionAfterDataFailsClosed. A newer
    WAL gets a byte-exact supersession record (old WAL from key 3's index)
    appended after its data. Then the test opens with kNone (sequential) and
    with indexing (merge), in all four modes. At the base, kNone tolerate and
    absolute fail with the generic "WAL_Index supersession follows a data
    record or progress assertion", and point-in-time opens with superseded
    keys 3-5 present ("value3"/"value4"/"value5"). Now all 8 opens fail
    with the status above.
  • Neuters:
    • Drop the ProcessLogFile guard: the kNone point-in-time open succeeds
      with keys 3-5 present.
    • Drop the merged guard: the indexed point-in-time open does the same.

Q2. Is a deleted current indexed WAL caught after SyncWAL with an
unindexed prefix?

  • Rule, unchanged from the base:
    • The MANIFEST records a WAL's synced size only once the WAL is
      inactive (FinishWalPartitionSync, as upstream). SyncWAL on a current
      WAL records nothing.
    • So a current WAL is legitimately untracked. Neither WalSet::CheckWals
      nor the merge's expected set demands it, and with no successor
      nothing attests it.
    • Its loss is judged by the surviving files alone.
    • A MANIFEST-tracked indexed WAL that goes missing still fails every
      mode, naming it (GC19MissingIndexedWalAfterPrefixFails, unchanged).
  • Evidence: new GC23MissingCurrentIndexedWalAfterPrefix. GC19's setup,
    then SyncWAL, then delete partition 1's current WAL. The test asserts
    the WAL is absent from the MANIFEST's WAL set while the prefix WAL is
    tracked. It pins the outcome, identical at the base and here: every mode
    opens without the lost record.
    • Lost record above every survivor: a lost tail, which is the expected
      outcome.
    • Lost record below a survivor: the lost index sits under the lower
      bound the survivors set, so the open keeps the later write without the
      earlier one. That is a known gap, not weaker than the base; see Not
      done.
  • Neuter: GC19's (keep the replayed prefix in expected_wals). The test
    fails with "WAL named but not held".

Q3. Is HeadBounded's floor term limited to the case it exists for?
(proved and kept, no code change)

  • When the term holds: history_floor_ is set and no member attests.
    history_floor_ is set only for a partitioned set with LastSequence() == 0
    and MinWalNumberToKeep() == 0. These are exactly the conditions under
    which ComputeLowerBound lowers the bound to the floor.
  • Why both gates are correct under it:
    • With the bound at the floor (kWALIndexStartNumber), the first index
      ever allocated, no head can hide an index below the bound.
    • The lower-bound gate (damaged head with data after it) and the
      post-drive gate (data-less damaged head) therefore never need an
      attestation then. Any index a head lost is examined as a hole or a
      lost tail.
  • Scope: the floor never reaches a member that is not first of history.
    wal_partitions > 1 requires MANIFEST WAL tracking, and both ways a DB
    gets a second WAL generation record a MinWalNumberToKeep: a rotation,
    and a reopen (even one that recovered no sequence). So whenever the
    floor is set, every member was created by the DB's first open.
  • Evidence:
    • Ported GC19H6FloorSetAbsoluteAndSkipOutcomes and
      GC19H6FloorUnsetHeadDamageStillFails. In the second, the rotation
      turns the floor off; Muse's comment said "set yet ineffective", which
      is corrected.
    • New GC23FloorOffForLaterGenerationHeads: a brand-new N=2 DB with spans
      suppressed gets a second generation by rotation and by reopen. It
      asserts MinWalNumberToKeep != 0, then corrupts the second generation's
      first record (data survives behind it). Every mode fails with "WAL
      head damaged and unattested".
    • The brand-new case is unchanged (FU14H6,
      GC19TornFirstRecordInBrandNewNTwoDbModes).
  • Neuters (the GC19 term itself is not narrowed, so none restores it):
    • Drop the floor term: FU14H6, GC19TornFirstRecordInBrandNewNTwoDbModes
      and GC19H6FloorSetAbsoluteAndSkipOutcomes fail with "head damaged and
      unattested".
    • HeadBounded whenever no member attests: GC23FloorOff opens.
    • HeadBounded always: GC23FloorOff and GC19H6FloorUnset open.
    • Set the floor without the MinWalNumberToKeep condition: GC23FloorOff
      opens.

Q4. Is the Q2 void exception right at N>1? (premise asserted; one rule
added)

  • Premise: the declaring WAL is the lowest-numbered WAL the open creates.
    WriteWALIndexSupersessions now asserts that its WAL is cur_wal_number_.
    Open already asserts that every other partition's new WAL is numbered
    above it.
  • At N>1:
    • A void from before the cut, in a WAL numbered below the declarer,
      clears the pending index and the open ends clean.
    • A void burned after the cut, in the declarer or a later WAL, does not
      clear it: point-in-time stops at the pending index.
    • Within N>1 histories every cut sits at or above the seed, which is
      above every surviving void. So the pre-cut case comes from an N=1
      cut carried into an upgrade.
    • No write path burns an index after a cut while the reissue of a lower
      superseded index is absent (a burn stops the DB). So the post-cut
      layout is crafted from real files.
  • New finding, fixed:
    • GC19's pending rule turned a superseded-only hole that one open had
      skipped (nothing live above it) into a frontier at the next open,
      once that open's writes landed above it. It reproduces at the base,
      at N=1 with indexing and avoid_flush_during_recovery.
    • Steps: a filter stop cuts keys 2-4; one write reissues only index 3;
      the next open skips 4-5 and writes at 6; the open after that stops at
      4.
    • Fix: an open whose merge skipped such an index now flushes, so the
      WALs holding the superseded copies retire before any write can land
      above the hole. WALIndexMerger::SkippedUnexplainedDiscard reports
      this: one still pending at kCleanEnd, or one re-trusted under skip.
      Recovery sets flushed.
  • Evidence:
    • New GC23VoidAgainstPendingSupersededIndex at N in {2,8}.
      • Pre-cut, files as written: every mode opens with k0, k1, n* and p*.
      • Post-cut, the void moved into the declarer, or into the highest
        partition WAL the upgrade created: a point-in-time read-only open
        holds only k0 and k1.
      • Read-write point-in-time fails with "... a write would reissue it":
        the end-of-recovery check counts only this open's cuts (see
        Assumptions).
      • Tolerate and absolute fail with "unexplained hole"; skip re-trusts
        and opens.
    • New DBWALIndexTest.SkippedSupersededHoleSurvivesLaterWrites (four
      modes). At the base, the point-in-time leg fails with "WAL 4 holds
      live wal_index 5 at or above the next wal_index 4; a write would
      reissue it". A probe under tolerate gave "unexplained hole at
      wal_index 4". Now all four modes keep keys 0, 1, 20 and 21.
  • Neuters:
    • Clear the pending index on any void: GC23VoidAgainst fails (the
      post-cut opens hold n* and p*), as does
      LogMergeTest.DiscardedHoleWithLiveAboveIsAFrontier.
    • Never clear it: GC23VoidAgainst fails, because the upgrade open fails
      with "unexplained hole at wal_index 3".
    • Drop the flush: SkippedSupersededHole fails as at the base.

Q5. Are Muse's GC19 tests ported, and does every GC19 test discriminate?
(test-only)

  • SupersededOnlyHoleInsideLiveStreamStops. Neuter: GC19's Q2 (skip
    superseded-only indices unconditionally); it fails on all 4 params.
  • TrailingSupersededHoleWithoutLiveAboveSkips. Neuter: stop at every
    superseded-only index without deferring; it fails on all 4 params.
  • InterleavedMixedSetWithSupersessionsFailsClosed, reworked. After each
    kNone open it accepts either OK with keys 6 and 7 NOT_FOUND, or
    Corruption naming the supersession. It passes at the base, where both
    opens are OK. Neuter: GC19's Q5 (ignore superseding in the kNone
    routing); the first open fails with "Sequence number is being set
    backwards", which is neither outcome.
  • The higher-numbered case of GC19ReportedTailGapStopsPITEitherPartition
    now discriminates a named neuter: drop the point-in-time stop in
    map_tail_gap's pending-report branch. That case then recovers i4 above
    the gap ("i4 recovered above the prefix end OK"). Only the test comment
    changed to name it.

Q6. Is the secondary's behaviour pinned for non-partitioned and retry
cases? (test-only)

  • CatchUpEmptyUnindexedWalAppliesNothing: a kNone N=1 secondary with an
    empty newest WAL catches up OK and applies nothing. After FlushWAL it
    sees the key.
  • CatchUpRefusesIndexedRoundWithEmptyHead: refused (NotSupported) and
    nothing applied. After FlushWAL the next round succeeds and sees both
    b_key and the flushed a_key.
  • Neuter: refuse any empty head whatever the round's indexing.
    CatchUpEmptyUnindexed fails: OpenAsSecondary already returns
    NotSupported ("WAL 8 has no readable WAL index marker ...").

Q7. Does the pre-publish snapshot reservation stay invisible to snapshot
properties and APIs? (documented and pinned)

  • Property:
    • At N>1, until CommitAndTryCreateSnapshot returns, its reservation
      counts as one unreleased snapshot in rocksdb.num-snapshots,
      oldest-snapshot-time and oldest-snapshot-sequence.
    • No API returns it. The timestamped-snapshot APIs list nothing.
    • GC22's compaction guarantee is unchanged (its tests pass).
  • How: documented at Transaction::CommitAndTryCreateSnapshot. No code
    change, so SnapshotList, which the snapshot paths share, stays as it
    is.
  • Evidence: new GC23SnapshotReservationInProperties, using
    RunWithCommitHeldAtGate.
    • While T1 is held: num-snapshots 1, oldest-snapshot-sequence ==
      T1's S, oldest-snapshot-time != 0; GetAllTimestampedSnapshots empty;
      GetLatestTimestampedSnapshot null.
    • After the call returns: 1 snapshot at S.
    • After release: 0 snapshots.
  • Neuter: drop the reservation (the excluded behaviour). The held counts
    read 0, and GC22TimestampedSnapshotReservedBeforePublish also fails.

Q8. Is the N=1-indexed transient refusal decided and pinned? (D-GC23a
option (i))

  • The refusal is documented at DBOptions::wal_partitions.
  • CatchUpRefusesIndexedRoundWithEmptyHead pins both the refusal and the
    retry.
  • Neuter: option (ii), treating the empty head as unpartitioned (drop
    GC22's empty-head rule). The first catch-up succeeds and the test
    fails; FU14CatchUpRefusesBeforeApplyingPartitionZero also fails.

Q9. Is GC22's compaction guarantee checked without SyncPoint? (test-only)

  • New GC23TimestampedSnapshotsSurviveFlushStress at N in {2,8}. Eight
    synced committers on every partition but 1 call
    CommitAndTryCreateSnapshot, while a writer overwrites "k" on partition 1
    and a flusher flushes and compacts it.
    • Synced commits re-sync in their gate when predecessors land late,
      which widens the window between publish and snapshot.
    • Every created snapshot must find "k". Its read right after creation
      must equal its read after a final flush and compaction. Ordered by
      sequence, the values never go backwards.
  • It uses no SyncPoint. transaction_test as a whole does not build with
    NDEBUG (73 unguarded SyncPoint uses), so the test ran in the debug build
    (DEBUG_LEVEL=1) and under TSan.
  • Neuter: drop the reservation. 10/10 runs fail, each with 109-171
    failures: snapshot reads change after the compaction.

Fold-back split (blame at the base; the GC19 and GC22 winners' lines
count as the diffs their own splits send them to):

  • Q1:
    • db/log_reader.h:
      • SawMisplacedWALIndexSupersession: new code next to D120408456's
        supersession accessors.
      • saw_misplaced_supersession_: new member next to
        D121636079/D123928339 members.
      • Absorbing: D121636079.
    • db/log_reader.cc: one line in DecodeWALIndexSupersessionRecord's
      head-position branch. Modifies D120621828 lines. Absorbing:
      D121636079.
    • db/db_impl/db_impl_open.cc:
      • MisplacedSupersessionStatus: new code beside D120649665's
        MergedSequenceOf.
      • The guard loop ahead of the post-drive head check: new code between
        D120649665 and D123928339 lines.
      • The guard after ProcessLogFile's read loop: new code in D120415420
        lines.
      • Absorbing: D121636079.
    • db/db_impl/db_impl_open.cc, WriteWALIndexSupersessions: the
      no-data-yet assert. Modifies D120415420 lines. Absorbing: D120415420
      (writer-side assertion).
  • Q2: test only. GC23MissingCurrentIndexedWalAfterPrefix in
    db/db_write_test.cc goes to D120649665 (the DBWalPartitionCoverageTest
    fixture is D127093323's).
  • Q3: tests only. GC19H6FloorSetAbsoluteAndSkipOutcomes,
    GC19H6FloorUnsetHeadDamageStillFails, GC23FloorOffForLaterGenerationHeads
    and the fixture helpers CreateBrandNewPartitionedDb / CorruptImageRecord
    (new code in D127093323's fixture) go to D120624825.
  • Q4:
    • db/db_impl/db_impl_open.cc, WriteWALIndexSupersessions: the
      declarer-premise assert. Modifies D120415420 lines. Absorbing:
      D120415420.
    • db/db_impl/db_impl_open.cc: the flush in ProcessLogFilesMerged's
      kCleanEnd branch. Modifies D120649665 lines. Absorbing: D120649665.
    • db/log_merge.h: SkippedUnexplainedDiscard (new code next to
      D120624825/D120649665 accessors) and skipped_discard_ (new member next
      to a D120624825 member). Absorbing: D120649665.
    • db/log_merge.cc: one line in the skip branch of WALIndexMerger::Next.
      Modifies D120649665 lines. Absorbing: D120649665.
    • Tests:
      • GC23VoidAgainstPendingSupersededIndex and FirstBlockRecords
        (db/db_write_test.cc; N>1 tests compile at or above D123079329) go
        to D120649665.
      • SkippedSupersededHoleSurvivesLaterWrites (db/db_wal_test.cc,
        DBWALIndexTest fixture from D120415420) goes to D120649665.
  • Q5: tests only.
    • log_merge_test.cc ports go to D120649665.
    • InterleavedMixedSetWithSupersessionsFailsClosed (db_wal_test.cc) goes
      to D120415420.
    • The GC19ReportedTailGapStopsPITEitherPartition comment
      (db_write_test.cc) goes to D127093323 per the map. The test is GC19's
      Q1 test, sent to D120649665 by GC19's split.
  • Q6 and Q8:
    • include/rocksdb/options.h: the wal_partitions doc sentence. Modifies
      lines GC18's winner added (29df5aa, folded per GC18's split).
      Absorbing: D127093323.
    • db/db_secondary_test.cc: the two ports go to D127093323.
  • Q7:
    • include/rocksdb/utilities/transaction.h: the CommitAndTryCreateSnapshot
      doc. Modifies upstream lines (1777e5f). Absorbing: D123551605.
    • GC23SnapshotReservationInProperties (transaction_test.cc, beside
      GC22's tests) goes to D123551605.
  • Q9: GC23TimestampedSnapshotsSurviveFlushStress (transaction_test.cc)
    goes to D127275775.

Assumptions:

  1. D-GC23a was blank: option (i), fail closed, documented and pinned.
  2. Q1 is option (a). The writer guarantee is a debug assert at the DB
    write site (WriteWALIndexSupersessions), not in log::Writer: existing
    log_test cases use log::Writer to write misplaced supersessions on
    purpose, to test the reader. The recovery guard covers both paths,
    not only the sequential one, so that no path replays a superseded
    record.
  3. Q1's test crafts the misplaced record byte for byte (a test hook, as
    the doc allows). A naturally reissued layout already fails at the base
    with "Sequence number is being set backwards", so only a layout whose
    later data does not reissue sequences shows silent replay.
  4. Q2: the current WAL is legitimately untracked (an upstream rule this
    round does not change), so the test pins the base outcome rather than
    a failure.
  5. Q3: proved and kept rather than narrowed. Narrowing would change no
    reachable outcome: the floor implies every member is first of history.
  6. Q4: the post-cut void layout is crafted (see Q4). Read-write
    point-in-time at such a frontier fails closed with "... a write would
    reissue it": ProcessLogFilesMerged's end-of-recovery check counts only
    this open's cuts, not a supersession already declared by an earlier
    open. That predates this round and fails closed, so it is pinned, not
    changed. The read-only open shows the stop.
  7. Q4's flush fix goes beyond the doc's literal asks. It is in the
    pending-hole handling Q4 owns, it restores openability that GC19's
    rule broke, and it affects only opens that skipped an unexplained
    superseded-only index (N=1 kNone never has one). It overrides
    avoid_flush_during_recovery in that case only, as the kNone opener's
    merge already does.
  8. Q7: document rather than exclude. That needs the least code and leaves
    SnapshotList untouched.
  9. Q9 runs in the debug build (see Q9).

Not done:

  • Q2 gap, the same at the base: a deleted current (untracked) partition WAL
    whose lost record lies below a surviving record of another partition is
    absorbed under the survivors' lower bound, so the open keeps a later
    write without an earlier one. Detecting it needs the MANIFEST to track
    current WALs (a MANIFEST write per sync at N>1) or an index-epoch floor.
    Pinned by GC23MissingCurrentIndexedWalAfterPrefix ("lost record below"
    case) so a fix flips it.
  • The release (NDEBUG) run of Q9: the harness does not build in opt (see
    Q9).
  • db_stress / crash test: not required (owner deferred, 2026-10-27).

Test plan (host: 166 cores, J=83; TEST_TMPDIR under
~/pwal-3p/gc-23-claude-tmp; logs in its logs/ and neuter/; final tree
diff sha256 4502a7e9f10a7d3b):

  1. Base checks: HEAD c1f219f, clean, rev-list count 43 -- OK.
  2. New tests against the base library (test files only, in
    ~/pwal-3p/gc-23-claude-base, debug):
    • Fail at the base: SupersessionAfterDataFailsClosed and
      SkippedSupersededHoleSurvivesLaterWrites (symptoms under Q1 and Q4).
    • Pass at the base, as the pins they are: the Q2/Q3/Q5/Q6/Q7/Q8/Q9
      tests and the Q4 void test.
    • The GC19/GC22 repro tests (FU14*) already pass at the base and pass
      here unmodified. This round has no repro commit.
  3. Required suites (debug), one gtest-parallel -w 83 run of db_write_test,
    db_wal_test, log_merge_test, log_test, db_secondary_test,
    transaction_test and db_basic_test: 6938/6938 passed. The Q9 test took
    94 s there under the 83-way load, so its budget was then cut from 300
    to 100 commits per thread: 3-11 s alone, neuter still 10/10. The rare
    SyncClosedWalsEmptiedByWaitLeavesLaterMark hang was not seen.
  4. db_wal_oracle_test, ROCKSDB_WAL_ORACLE_CYCLES=1000 (debug): 4/4 pass.
    1000 cycles from seed 20261019 in 729 s; N=2 in 507, N=8 in 493;
    power loss in 528; 122 recoveries stopped at a cross-partition hole;
    0 violations. The three self-tests still catch their injected bugs.
  5. Neuters: 17 patches, the reservation drop serving Q7 and Q9. Each was
    applied by script with the file's sha256 checked before and after,
    rebuilt, run, and restored (hash re-checked). Every named test failed
    as listed under its question. Logs: neuter/log_*.txt.
  6. 100x repeats (debug):
    • db_wal_test Q1/Q4/Q5 tests: 300/300.
    • db_write_test GC23* + GC19H6Floor* + GC19ReportedTailGap*: 600/600.
    • log_merge_test ports: 800/800.
    • db_secondary_test CatchUp*: 300/300.
    • transaction_test GC23SnapshotReservation + GC22* + FU14*: 500/500.
    • Q9 stress: 10/10.
  7. TSan (USE_CLANG=1 COMPILE_WITH_TSAN=1), 0 ThreadSanitizer warnings:
    • db_wal_test Q1/Q4/Q5: 9/9 (x3).
    • db_write_test GC23*/GC19H6Floor*/GC19ReportedTailGap*: 18/18 (x3).
    • log_merge_test ports: 24/24 (x3).
    • db_secondary_test CatchUp*: 9/9 (x3).
    • transaction_test GC23SnapshotReservation + GC22* + FU14*: 500/500
      (x100, the SyncPoint-driven ones).
    • Q9 stress: 3/3.
  8. N=1 byte identity (DEBUG_LEVEL=0 db_bench fillseq --threads=1
    --num=10000 --seed=20260928 --disable_auto_compactions=1), SHA-256 of
    000004.log, base (~/pwal-3p/gc-23-claude-base) == commit:
    • none: 6d1351117a289a2784449a68d5421b1aa385ab0b383273c2c5918befa9181b09
    • partition_by_column_family:
      9a69a3fc66777fadce05e8a999479a5f57364aca27cd6d22aa00e4631adfc796
  9. make check-format: "Nothing needs to be reformatted!" (clang-format
    21.1.2; only changed lines formatted). make check-sources: exit 0.
  10. db_stress / crash test: not run (not required). ASan/UBSan: not run
    (not required).
  11. Host load: the load average reached about 169 while the neuter batch
    and a release build ran together. Neuter outcomes are deterministic.
    The suites, repeats and oracle ran at a load average of about 30-45.

…seded holes safe, pin GC22's snapshot and secondary fixes

[GC] GC23 -- recovery and consumer carry-over after GC19 and GC22, on
pwal/gc23-base @ c1f219f.

Reviewer question: Can any recovery path now replay a superseded record,
skip a superseded-only hole, or accept a damaged unattested head, and are
GC22's snapshot and secondary fixes fully pinned?

Short answer:
- No recovery path replays a superseded record. A supersession written
  after data now fails closed in every mode, naming the WAL.
- A superseded-only hole is skipped only when that is safe. That includes
  a new case found this round: an open skips a trailing hole and later
  writes land above it.
- A damaged head that no attestation bounds still fails closed. The
  history floor never reaches a member that is not first of history.
- GC22's fixes are pinned: properties, the secondary's empty-head and
  retry cases, the N=1 transient refusal, and a value check that needs no
  SyncPoint.
- One gap remains, the same at the base: a deleted *current* (untracked)
  WAL whose lost record sits below the survivors (Q2, Not done).

Tests ported from the losing candidates (Muse), with thanks:
- From GC19 (Muse): GC19H6FloorUnsetHeadDamageStillFails,
  GC19H6FloorSetAbsoluteAndSkipOutcomes,
  LogMergeTest.SupersededOnlyHoleInsideLiveStreamStops,
  LogMergeTest.TrailingSupersededHoleWithoutLiveAboveSkips, and
  InterleavedMixedSetWithSupersessionsFailsClosed (reworked per Q5).
- From GC22 (Muse): DBSecondaryTest.CatchUpEmptyUnindexedWalAppliesNothing
  and DBSecondaryTest.CatchUpRefusesIndexedRoundWithEmptyHead.

Q1. Does supersession detection find every declaration? (option (a))
- Property: supersession records are written only into the head of a new
  WAL, ahead of its first data record, and the write site asserts it. A
  supersession met after a data or progress record is never honored. On
  either recovery path (sequential ProcessLogFile, or the merge) it fails
  the open in every mode with "WAL <n> declares a WAL index supersession
  after a data record; recovery cannot honor it". No superseded record is
  applied, because the open fails before anything persists.
- How:
  - log::Reader already reported a misplaced supersession as corruption
    and dropped it. Skip mode swallowed that report, and point-in-time
    had already replayed the earlier WAL by then. The reader now also
    records it (SawMisplacedWALIndexSupersession).
  - ProcessLogFile and ProcessLogFilesMerged turn that flag into the
    status above (MisplacedSupersessionStatus).
  - DBImpl::WriteWALIndexSupersessions asserts that its WAL has recorded
    no data record (last_wal_index_recorded() == 0).
  - Detection stays head-only: no WAL is re-read.
- Evidence: new DBWALIndexTest.SupersessionAfterDataFailsClosed. A newer
  WAL gets a byte-exact supersession record (old WAL from key 3's index)
  appended after its data. Then the test opens with kNone (sequential) and
  with indexing (merge), in all four modes. At the base, kNone tolerate and
  absolute fail with the generic "WAL_Index supersession follows a data
  record or progress assertion", and point-in-time opens with superseded
  keys 3-5 present ("value3"/"value4"/"value5"). Now all 8 opens fail
  with the status above.
- Neuters:
  - Drop the ProcessLogFile guard: the kNone point-in-time open succeeds
    with keys 3-5 present.
  - Drop the merged guard: the indexed point-in-time open does the same.

Q2. Is a deleted current indexed WAL caught after SyncWAL with an
unindexed prefix?
- Rule, unchanged from the base:
  - The MANIFEST records a WAL's synced size only once the WAL is
    inactive (FinishWalPartitionSync, as upstream). SyncWAL on a current
    WAL records nothing.
  - So a current WAL is legitimately untracked. Neither WalSet::CheckWals
    nor the merge's expected set demands it, and with no successor
    nothing attests it.
  - Its loss is judged by the surviving files alone.
  - A MANIFEST-tracked indexed WAL that goes missing still fails every
    mode, naming it (GC19MissingIndexedWalAfterPrefixFails, unchanged).
- Evidence: new GC23MissingCurrentIndexedWalAfterPrefix. GC19's setup,
  then SyncWAL, then delete partition 1's current WAL. The test asserts
  the WAL is absent from the MANIFEST's WAL set while the prefix WAL is
  tracked. It pins the outcome, identical at the base and here: every mode
  opens without the lost record.
  - Lost record above every survivor: a lost tail, which is the expected
    outcome.
  - Lost record below a survivor: the lost index sits under the lower
    bound the survivors set, so the open keeps the later write without the
    earlier one. That is a known gap, not weaker than the base; see Not
    done.
- Neuter: GC19's (keep the replayed prefix in expected_wals). The test
  fails with "WAL <prefix> named but not held".

Q3. Is HeadBounded's floor term limited to the case it exists for?
(proved and kept, no code change)
- When the term holds: history_floor_ is set and no member attests.
  history_floor_ is set only for a partitioned set with LastSequence() == 0
  and MinWalNumberToKeep() == 0. These are exactly the conditions under
  which ComputeLowerBound lowers the bound to the floor.
- Why both gates are correct under it:
  - With the bound at the floor (kWALIndexStartNumber), the first index
    ever allocated, no head can hide an index below the bound.
  - The lower-bound gate (damaged head with data after it) and the
    post-drive gate (data-less damaged head) therefore never need an
    attestation then. Any index a head lost is examined as a hole or a
    lost tail.
- Scope: the floor never reaches a member that is not first of history.
  wal_partitions > 1 requires MANIFEST WAL tracking, and both ways a DB
  gets a second WAL generation record a MinWalNumberToKeep: a rotation,
  and a reopen (even one that recovered no sequence). So whenever the
  floor is set, every member was created by the DB's first open.
- Evidence:
  - Ported GC19H6FloorSetAbsoluteAndSkipOutcomes and
    GC19H6FloorUnsetHeadDamageStillFails. In the second, the rotation
    turns the floor off; Muse's comment said "set yet ineffective", which
    is corrected.
  - New GC23FloorOffForLaterGenerationHeads: a brand-new N=2 DB with spans
    suppressed gets a second generation by rotation and by reopen. It
    asserts MinWalNumberToKeep != 0, then corrupts the second generation's
    first record (data survives behind it). Every mode fails with "WAL <n>
    head damaged and unattested".
  - The brand-new case is unchanged (FU14H6,
    GC19TornFirstRecordInBrandNewNTwoDbModes).
- Neuters (the GC19 term itself is not narrowed, so none restores it):
  - Drop the floor term: FU14H6, GC19TornFirstRecordInBrandNewNTwoDbModes
    and GC19H6FloorSetAbsoluteAndSkipOutcomes fail with "head damaged and
    unattested".
  - HeadBounded whenever no member attests: GC23FloorOff opens.
  - HeadBounded always: GC23FloorOff and GC19H6FloorUnset open.
  - Set the floor without the MinWalNumberToKeep condition: GC23FloorOff
    opens.

Q4. Is the Q2 void exception right at N>1? (premise asserted; one rule
added)
- Premise: the declaring WAL is the lowest-numbered WAL the open creates.
  WriteWALIndexSupersessions now asserts that its WAL is cur_wal_number_.
  Open already asserts that every other partition's new WAL is numbered
  above it.
- At N>1:
  - A void from before the cut, in a WAL numbered below the declarer,
    clears the pending index and the open ends clean.
  - A void burned after the cut, in the declarer or a later WAL, does not
    clear it: point-in-time stops at the pending index.
  - Within N>1 histories every cut sits at or above the seed, which is
    above every surviving void. So the pre-cut case comes from an N=1
    cut carried into an upgrade.
  - No write path burns an index after a cut while the reissue of a lower
    superseded index is absent (a burn stops the DB). So the post-cut
    layout is crafted from real files.
- New finding, fixed:
  - GC19's pending rule turned a superseded-only hole that one open had
    skipped (nothing live above it) into a frontier at the next open,
    once that open's writes landed above it. It reproduces at the base,
    at N=1 with indexing and avoid_flush_during_recovery.
  - Steps: a filter stop cuts keys 2-4; one write reissues only index 3;
    the next open skips 4-5 and writes at 6; the open after that stops at
    4.
  - Fix: an open whose merge skipped such an index now flushes, so the
    WALs holding the superseded copies retire before any write can land
    above the hole. WALIndexMerger::SkippedUnexplainedDiscard reports
    this: one still pending at kCleanEnd, or one re-trusted under skip.
    Recovery sets `flushed`.
- Evidence:
  - New GC23VoidAgainstPendingSupersededIndex at N in {2,8}.
    - Pre-cut, files as written: every mode opens with k0, k1, n* and p*.
    - Post-cut, the void moved into the declarer, or into the highest
      partition WAL the upgrade created: a point-in-time read-only open
      holds only k0 and k1.
    - Read-write point-in-time fails with "... a write would reissue it":
      the end-of-recovery check counts only this open's cuts (see
      Assumptions).
    - Tolerate and absolute fail with "unexplained hole"; skip re-trusts
      and opens.
  - New DBWALIndexTest.SkippedSupersededHoleSurvivesLaterWrites (four
    modes). At the base, the point-in-time leg fails with "WAL 4 holds
    live wal_index 5 at or above the next wal_index 4; a write would
    reissue it". A probe under tolerate gave "unexplained hole at
    wal_index 4". Now all four modes keep keys 0, 1, 20 and 21.
- Neuters:
  - Clear the pending index on any void: GC23VoidAgainst fails (the
    post-cut opens hold n* and p*), as does
    LogMergeTest.DiscardedHoleWithLiveAboveIsAFrontier.
  - Never clear it: GC23VoidAgainst fails, because the upgrade open fails
    with "unexplained hole at wal_index 3".
  - Drop the flush: SkippedSupersededHole fails as at the base.

Q5. Are Muse's GC19 tests ported, and does every GC19 test discriminate?
(test-only)
- SupersededOnlyHoleInsideLiveStreamStops. Neuter: GC19's Q2 (skip
  superseded-only indices unconditionally); it fails on all 4 params.
- TrailingSupersededHoleWithoutLiveAboveSkips. Neuter: stop at every
  superseded-only index without deferring; it fails on all 4 params.
- InterleavedMixedSetWithSupersessionsFailsClosed, reworked. After each
  kNone open it accepts either OK with keys 6 and 7 NOT_FOUND, or
  Corruption naming the supersession. It passes at the base, where both
  opens are OK. Neuter: GC19's Q5 (ignore superseding in the kNone
  routing); the first open fails with "Sequence number is being set
  backwards", which is neither outcome.
- The higher-numbered case of GC19ReportedTailGapStopsPITEitherPartition
  now discriminates a named neuter: drop the point-in-time stop in
  map_tail_gap's pending-report branch. That case then recovers i4 above
  the gap ("i4 recovered above the prefix end OK"). Only the test comment
  changed to name it.

Q6. Is the secondary's behaviour pinned for non-partitioned and retry
cases? (test-only)
- CatchUpEmptyUnindexedWalAppliesNothing: a kNone N=1 secondary with an
  empty newest WAL catches up OK and applies nothing. After FlushWAL it
  sees the key.
- CatchUpRefusesIndexedRoundWithEmptyHead: refused (NotSupported) and
  nothing applied. After FlushWAL the next round succeeds and sees both
  b_key and the flushed a_key.
- Neuter: refuse any empty head whatever the round's indexing.
  CatchUpEmptyUnindexed fails: OpenAsSecondary already returns
  NotSupported ("WAL 8 has no readable WAL index marker ...").

Q7. Does the pre-publish snapshot reservation stay invisible to snapshot
properties and APIs? (documented and pinned)
- Property:
  - At N>1, until CommitAndTryCreateSnapshot returns, its reservation
    counts as one unreleased snapshot in rocksdb.num-snapshots,
    oldest-snapshot-time and oldest-snapshot-sequence.
  - No API returns it. The timestamped-snapshot APIs list nothing.
  - GC22's compaction guarantee is unchanged (its tests pass).
- How: documented at Transaction::CommitAndTryCreateSnapshot. No code
  change, so SnapshotList, which the snapshot paths share, stays as it
  is.
- Evidence: new GC23SnapshotReservationInProperties, using
  RunWithCommitHeldAtGate.
  - While T1 is held: num-snapshots 1, oldest-snapshot-sequence ==
    T1's S, oldest-snapshot-time != 0; GetAllTimestampedSnapshots empty;
    GetLatestTimestampedSnapshot null.
  - After the call returns: 1 snapshot at S.
  - After release: 0 snapshots.
- Neuter: drop the reservation (the excluded behaviour). The held counts
  read 0, and GC22TimestampedSnapshotReservedBeforePublish also fails.

Q8. Is the N=1-indexed transient refusal decided and pinned? (D-GC23a
option (i))
- The refusal is documented at DBOptions::wal_partitions.
- CatchUpRefusesIndexedRoundWithEmptyHead pins both the refusal and the
  retry.
- Neuter: option (ii), treating the empty head as unpartitioned (drop
  GC22's empty-head rule). The first catch-up succeeds and the test
  fails; FU14CatchUpRefusesBeforeApplyingPartitionZero also fails.

Q9. Is GC22's compaction guarantee checked without SyncPoint? (test-only)
- New GC23TimestampedSnapshotsSurviveFlushStress at N in {2,8}. Eight
  synced committers on every partition but 1 call
  CommitAndTryCreateSnapshot, while a writer overwrites "k" on partition 1
  and a flusher flushes and compacts it.
  - Synced commits re-sync in their gate when predecessors land late,
    which widens the window between publish and snapshot.
  - Every created snapshot must find "k". Its read right after creation
    must equal its read after a final flush and compaction. Ordered by
    sequence, the values never go backwards.
- It uses no SyncPoint. transaction_test as a whole does not build with
  NDEBUG (73 unguarded SyncPoint uses), so the test ran in the debug build
  (DEBUG_LEVEL=1) and under TSan.
- Neuter: drop the reservation. 10/10 runs fail, each with 109-171
  failures: snapshot reads change after the compaction.

Fold-back split (blame at the base; the GC19 and GC22 winners' lines
count as the diffs their own splits send them to):
- Q1:
  - db/log_reader.h:
    - SawMisplacedWALIndexSupersession: new code next to D120408456's
      supersession accessors.
    - saw_misplaced_supersession_: new member next to
      D121636079/D123928339 members.
    - Absorbing: D121636079.
  - db/log_reader.cc: one line in DecodeWALIndexSupersessionRecord's
    head-position branch. Modifies D120621828 lines. Absorbing:
    D121636079.
  - db/db_impl/db_impl_open.cc:
    - MisplacedSupersessionStatus: new code beside D120649665's
      MergedSequenceOf.
    - The guard loop ahead of the post-drive head check: new code between
      D120649665 and D123928339 lines.
    - The guard after ProcessLogFile's read loop: new code in D120415420
      lines.
    - Absorbing: D121636079.
  - db/db_impl/db_impl_open.cc, WriteWALIndexSupersessions: the
    no-data-yet assert. Modifies D120415420 lines. Absorbing: D120415420
    (writer-side assertion).
- Q2: test only. GC23MissingCurrentIndexedWalAfterPrefix in
  db/db_write_test.cc goes to D120649665 (the DBWalPartitionCoverageTest
  fixture is D127093323's).
- Q3: tests only. GC19H6FloorSetAbsoluteAndSkipOutcomes,
  GC19H6FloorUnsetHeadDamageStillFails, GC23FloorOffForLaterGenerationHeads
  and the fixture helpers CreateBrandNewPartitionedDb / CorruptImageRecord
  (new code in D127093323's fixture) go to D120624825.
- Q4:
  - db/db_impl/db_impl_open.cc, WriteWALIndexSupersessions: the
    declarer-premise assert. Modifies D120415420 lines. Absorbing:
    D120415420.
  - db/db_impl/db_impl_open.cc: the flush in ProcessLogFilesMerged's
    kCleanEnd branch. Modifies D120649665 lines. Absorbing: D120649665.
  - db/log_merge.h: SkippedUnexplainedDiscard (new code next to
    D120624825/D120649665 accessors) and skipped_discard_ (new member next
    to a D120624825 member). Absorbing: D120649665.
  - db/log_merge.cc: one line in the skip branch of WALIndexMerger::Next.
    Modifies D120649665 lines. Absorbing: D120649665.
  - Tests:
    - GC23VoidAgainstPendingSupersededIndex and FirstBlockRecords
      (db/db_write_test.cc; N>1 tests compile at or above D123079329) go
      to D120649665.
    - SkippedSupersededHoleSurvivesLaterWrites (db/db_wal_test.cc,
      DBWALIndexTest fixture from D120415420) goes to D120649665.
- Q5: tests only.
  - log_merge_test.cc ports go to D120649665.
  - InterleavedMixedSetWithSupersessionsFailsClosed (db_wal_test.cc) goes
    to D120415420.
  - The GC19ReportedTailGapStopsPITEitherPartition comment
    (db_write_test.cc) goes to D127093323 per the map. The test is GC19's
    Q1 test, sent to D120649665 by GC19's split.
- Q6 and Q8:
  - include/rocksdb/options.h: the wal_partitions doc sentence. Modifies
    lines GC18's winner added (29df5aa, folded per GC18's split).
    Absorbing: D127093323.
  - db/db_secondary_test.cc: the two ports go to D127093323.
- Q7:
  - include/rocksdb/utilities/transaction.h: the CommitAndTryCreateSnapshot
    doc. Modifies upstream lines (1777e5f). Absorbing: D123551605.
  - GC23SnapshotReservationInProperties (transaction_test.cc, beside
    GC22's tests) goes to D123551605.
- Q9: GC23TimestampedSnapshotsSurviveFlushStress (transaction_test.cc)
  goes to D127275775.

Assumptions:
1. D-GC23a was blank: option (i), fail closed, documented and pinned.
2. Q1 is option (a). The writer guarantee is a debug assert at the DB
   write site (WriteWALIndexSupersessions), not in log::Writer: existing
   log_test cases use log::Writer to write misplaced supersessions on
   purpose, to test the reader. The recovery guard covers both paths,
   not only the sequential one, so that no path replays a superseded
   record.
3. Q1's test crafts the misplaced record byte for byte (a test hook, as
   the doc allows). A naturally reissued layout already fails at the base
   with "Sequence number is being set backwards", so only a layout whose
   later data does not reissue sequences shows silent replay.
4. Q2: the current WAL is legitimately untracked (an upstream rule this
   round does not change), so the test pins the base outcome rather than
   a failure.
5. Q3: proved and kept rather than narrowed. Narrowing would change no
   reachable outcome: the floor implies every member is first of history.
6. Q4: the post-cut void layout is crafted (see Q4). Read-write
   point-in-time at such a frontier fails closed with "... a write would
   reissue it": ProcessLogFilesMerged's end-of-recovery check counts only
   this open's cuts, not a supersession already declared by an earlier
   open. That predates this round and fails closed, so it is pinned, not
   changed. The read-only open shows the stop.
7. Q4's flush fix goes beyond the doc's literal asks. It is in the
   pending-hole handling Q4 owns, it restores openability that GC19's
   rule broke, and it affects only opens that skipped an unexplained
   superseded-only index (N=1 kNone never has one). It overrides
   avoid_flush_during_recovery in that case only, as the kNone opener's
   merge already does.
8. Q7: document rather than exclude. That needs the least code and leaves
   SnapshotList untouched.
9. Q9 runs in the debug build (see Q9).

Not done:
- Q2 gap, the same at the base: a deleted current (untracked) partition WAL
  whose lost record lies below a surviving record of another partition is
  absorbed under the survivors' lower bound, so the open keeps a later
  write without an earlier one. Detecting it needs the MANIFEST to track
  current WALs (a MANIFEST write per sync at N>1) or an index-epoch floor.
  Pinned by GC23MissingCurrentIndexedWalAfterPrefix ("lost record below"
  case) so a fix flips it.
- The release (NDEBUG) run of Q9: the harness does not build in opt (see
  Q9).
- db_stress / crash test: not required (owner deferred, 2026-10-27).

Test plan (host: 166 cores, J=83; TEST_TMPDIR under
~/pwal-3p/gc-23-claude-tmp; logs in its logs/ and neuter/; final tree
diff sha256 4502a7e9f10a7d3b):
1. Base checks: HEAD c1f219f, clean, rev-list count 43 -- OK.
2. New tests against the base library (test files only, in
   ~/pwal-3p/gc-23-claude-base, debug):
   - Fail at the base: SupersessionAfterDataFailsClosed and
     SkippedSupersededHoleSurvivesLaterWrites (symptoms under Q1 and Q4).
   - Pass at the base, as the pins they are: the Q2/Q3/Q5/Q6/Q7/Q8/Q9
     tests and the Q4 void test.
   - The GC19/GC22 repro tests (FU14*) already pass at the base and pass
     here unmodified. This round has no repro commit.
3. Required suites (debug), one gtest-parallel -w 83 run of db_write_test,
   db_wal_test, log_merge_test, log_test, db_secondary_test,
   transaction_test and db_basic_test: 6938/6938 passed. The Q9 test took
   94 s there under the 83-way load, so its budget was then cut from 300
   to 100 commits per thread: 3-11 s alone, neuter still 10/10. The rare
   SyncClosedWalsEmptiedByWaitLeavesLaterMark hang was not seen.
4. db_wal_oracle_test, ROCKSDB_WAL_ORACLE_CYCLES=1000 (debug): 4/4 pass.
   1000 cycles from seed 20261019 in 729 s; N=2 in 507, N=8 in 493;
   power loss in 528; 122 recoveries stopped at a cross-partition hole;
   0 violations. The three self-tests still catch their injected bugs.
5. Neuters: 17 patches, the reservation drop serving Q7 and Q9. Each was
   applied by script with the file's sha256 checked before and after,
   rebuilt, run, and restored (hash re-checked). Every named test failed
   as listed under its question. Logs: neuter/log_*.txt.
6. 100x repeats (debug):
   - db_wal_test Q1/Q4/Q5 tests: 300/300.
   - db_write_test GC23* + GC19H6Floor* + GC19ReportedTailGap*: 600/600.
   - log_merge_test ports: 800/800.
   - db_secondary_test CatchUp*: 300/300.
   - transaction_test GC23SnapshotReservation + GC22* + FU14*: 500/500.
   - Q9 stress: 10/10.
7. TSan (USE_CLANG=1 COMPILE_WITH_TSAN=1), 0 ThreadSanitizer warnings:
   - db_wal_test Q1/Q4/Q5: 9/9 (x3).
   - db_write_test GC23*/GC19H6Floor*/GC19ReportedTailGap*: 18/18 (x3).
   - log_merge_test ports: 24/24 (x3).
   - db_secondary_test CatchUp*: 9/9 (x3).
   - transaction_test GC23SnapshotReservation + GC22* + FU14*: 500/500
     (x100, the SyncPoint-driven ones).
   - Q9 stress: 3/3.
8. N=1 byte identity (DEBUG_LEVEL=0 db_bench fillseq --threads=1
   --num=10000 --seed=20260928 --disable_auto_compactions=1), SHA-256 of
   000004.log, base (~/pwal-3p/gc-23-claude-base) == commit:
   - none: 6d1351117a289a2784449a68d5421b1aa385ab0b383273c2c5918befa9181b09
   - partition_by_column_family:
     9a69a3fc66777fadce05e8a999479a5f57364aca27cd6d22aa00e4631adfc796
9. make check-format: "Nothing needs to be reformatted!" (clang-format
   21.1.2; only changed lines formatted). make check-sources: exit 0.
10. db_stress / crash test: not run (not required). ASan/UBSan: not run
    (not required).
11. Host load: the load average reached about 169 while the neuter batch
    and a release build ran together. Neuter outcomes are deterministic.
    The suites, repeats and oracle ran at a load average of about 30-45.
@JustinGaoF JustinGaoF changed the title [claude][GC] GC23: Fail closed on misplaced supersessions, keep skipped superseded holes safe, pin GC22's snapshot and secondary fixes [GC] GC23: Fail closed on misplaced supersessions, keep skipped superseded holes safe, pin GC22's snapshot and secondary fixes Oct 29, 2026
@JustinGaoF

Copy link
Copy Markdown
Owner Author

Folded at M4 into pwal/m4 @ 7a31be3 (commit D120415420, D120649665, D121636079, D123551605, D127093323, D127275775, NEW-GC14a, FLIP); see the M4 PR #26.

@JustinGaoF JustinGaoF closed this Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant