Skip to content

3.x.x: fail the database over, fill its WAL volume and restart over a candidate backlog under load, nightly and weekly on the real node (#554) - #635

Merged
djh58 merged 3 commits into
3.x.xfrom
djh58/prism-b554-faults-pr2
Oct 1, 2026
Merged

djh58 merged 3 commits into
3.x.xfrom
djh58/prism-b554-faults-pr2

Conversation

@djh58

@djh58 djh58 commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Refs #554 (#487 S16). This is the second of #554's two PRs: the faults #623 left open, as agreed in the design on #554. They are the primary lost with its async standby promoted (and the fenced switch), a found block mid-landing across a failover, a full WAL volume, and a restart over a candidate backlog. Each runs under load in qbit-prism-load's faults phase and is held to its criteria. No server code changes, and no server defect was found.

What

Five new faults in src/fault/. Each is injected while the sessions keep mining. Its criteria come on top of the run's own contract: every acknowledged share in PostgreSQL, no committed share unanswered mid-run, and one submitblock per block hash.

Fault What is injected Pass criteria
primary-kill A barrier first reads the primary's flush position and waits until the standby has flushed it. Replication is then cut, and the primary keeps acknowledging for cut s. The primary is stopped immediately, the async standby promoted, the writer endpoint moved to it, and a new standby built. The cut left WAL the standby never received. Every acknowledged share the new primary lacks is listed by id (session, frontend, time), and none was acknowledged before the barrier. Each lost share is absent from what the standby had received, and promotion kept all of that. Every frontend accepts a share on the new primary within 30 s, with the same process. The new standby streams.
primary-switch The fenced variant. The writer endpoint is fenced, and the standby replays through the old primary's flush position. The primary is then stopped and the standby promoted. Nothing acknowledged is lost, and the standby was 0 bytes behind. Frontends and standby as above.
block-failover The relay holds a found block's submitblock. As the call arrives, replication is cut and the primary stopped. The call then goes on to the node, and the standby is promoted. The reservation is on the promoted primary. #529's standby wait is on in these runs; the frontends get PRISM_OFFER_STANDBY_APPLICATION_NAME. The block reaches the node once and lands within 30 s of the promotion, with outcome unknown or accepted (#585). Blocks the relay forwarded around the failover are listed with their rows, so a gap-lost candidate is counted. Losses are checked as for primary-kill.
wal-disk-full The primary's pg_wal sits on a 1 GiB fuse2fs volume, #575's DiskFullInjector (included by #[path]). It uses 1 MiB segments with wal_recycle=off. The volume is filled and segment switches forced until PostgreSQL PANICs. PostgreSQL's crash recovery can find room again, because it deletes the segments it no longer needs; for hold s the volume is refilled whenever PostgreSQL accepts connections. The volume is then freed, and PostgreSQL started again if its postmaster exited. Nothing acknowledged is lost. Nothing is acknowledged inside the intervals PostgreSQL's own log (in UTC) shows it down: each PANIC to the next "ready to accept connections", with a 250 ms grace. Every frontend accepts shares again within 30 s, with the same process. Every frontend's /metrics showed #575's paging condition, qbit_prism_collector_available{collector="database"} == 0. If PostgreSQL cannot be brought back, the run fails with the primary's log rather than hanging.
candidate-backlog The relay answers every submitblock with qbitd's warmup error (−28). The server knows that call was never run (#526), so each row goes back to pending. It holds the answer until backlog found blocks are unfinished, then both frontends get SIGTERM and are relaunched while it still refuses. The relay then heals. Every exit is 0 within 35 s. Every backlog row reaches a terminal state after the heal, none reaches the node twice, and every row counted before is there after.

How the database is failed over. A plan with a failover asks the managed cluster for three things:

  • the async standby, streaming through a replication link (a TCP relay) that the fault can cut;
  • a writer endpoint in front of the primary, for every writer (the frontends through the delay proxy, and the harness's own side pool);
  • a read endpoint in front of the standby, for the public reader.

The promotion follows the operator procedure: the primary goes, pg_ctl promote waits, and only then do the endpoints move. Nothing is restarted, and every client reconnects to the same address. A new standby is then built from the new primary (pg_basebackup with a new slot), so later faults and the run's replication premise still have one. Only a run with such a fault gets this topology; every other run's cluster is unchanged.

What the run excuses. The run's durability finding (exit 4) excuses only the acknowledged shares a failover's verdict proves are in the replication gap: each was acknowledged after the barrier and was absent from the standby at promotion. Commits the server answered ledger-outcome-unknown while the primary was going are excused too. Each is listed in the fault's row. Any other missing share is still exit 4. The gate's reconciliation row now counts the gap separately, as "0 (and N in a failover's replication gap, each listed in its fault row)".

Three behaviours by design, handled in the harness rather than reported as defects:

  • The public API refuses on a lost replica. In replica mode it returns 503 while its standby cannot show it is current (the primary down, the link cut), or once the standby has been promoted. The read endpoint follows each rebuilt standby. The read tier leaves the wal-disk-full and failover windows out until the first 2xx, and each of those faults requires that 2xx within 30 s of its removal.
  • A backlog block can lose a tip race. On the real node, a backlog block at the same height as the one that landed is answered inconclusive. It stays in reconciliation until the winner has PRISM_CANDIDATE_ORPHAN_CONFIRMATIONS (6) confirmations (3.x.x: lost-race regression test and a terminal orphan disposition for reconciliation rows #415). The fault mints those six blocks, and the row then settles as orphaned.
  • PostgreSQL recovers on a full WAL volume. With wal_recycle=off, crash recovery deletes the segments it no longer needs, finds room and comes back. The fault refills the volume each time, and takes when PostgreSQL was down from its own log rather than from a probe.

#529's standby wait (PRISM_OFFER_STANDBY_APPLICATION_NAME) is set for the whole of a run that lists a failover, as a pool with a failover standby runs. Every found block's offer in faults-short-real-node therefore waits up to 250 ms for the standby's flush first. That is a change from earlier nights' landing timings.

Where it runs, and what it costs

Preset Lane Runner What Cost
(none) per PR No new gated test. Per the coordinator, #531/#585's per-PR failover drills already guard the path. 0 s per PR. The lib gains a few unit tests (milliseconds).
faults-short-real-node nightly 8 vCPU Gains candidate-backlog, primary-kill, primary-switch and block-failover (11 faults). About 11.5 minutes of run, up from about 9 (measured here in release, the way the nightly runs it): about $0.04 more a night.
faults-long-real-node (new) weekly, #588's Saturday weekly selection, its own runner beside the soak 16 vCPU, timeout 100 min All 12 faults, wal-disk-full first, with 2,000 sessions at 200 shares/s after a 45-minute warm-up with six external tips. The faults themselves take about 11 minutes. About 60 minutes, about $2 a week at $0.032 per 16 vCPU minute.
faults-failover-fake-node (new) dispatch 8 vCPU The five new faults on the fake node, with two frontends and 100 sessions. about 2 min

The workflow change is a separate commit. The run job installs fuse2fs and fuse3 only for a preset whose --faults lists wal-disk-full.

Tests and mutants

Checks run on the final tree:

  • cargo fmt --check and cargo clippy -p qbit-prism-load --all-targets -D warnings.
  • qbit-prism-load's lib (42 tests), harness (139), churn, soak_plan and realism.
  • The new unit tests cover:
    • the endpoint's fence and move;
    • the gap rule;
    • the PostgreSQL log's down intervals;
    • the public API's return;
    • process identity;
    • the plan's new keys and ordering rule;
    • the gate row that counts a failover's gap apart;
    • and in harness, classify_gaps excusing only what a fault proves.
  • The gated faults (33 s), load_smoke, real_node and quorum_replication tests, on PostgreSQL 16 with fsync on and PRISM_TEST_REQUIRE_INTEGRATION=1.
  • check_e2e_scenarios.py, actionlint, and the Python unittest suite. 853 tests pass; the 6 image-smoke tests fail here for want of a native server binary, which this change does not touch.

Runs:

  • faults-failover-fake-node on a debug build: exit 0, all five faults passing.
  • faults-short-real-node, run the way the nightly runs it (prism-load-run.sh, release builds, real node, a shared host): gate PASS and exit 0 in 678 s, all eleven faults passing.
    • primary-kill lost 151 of 632 acknowledged shares in its 3 s cut, each listed, all after the barrier. The gate reads "0 (and 152 in a failover's replication gap…)", the extra one from block-failover.
    • primary-switch lost 0 of 501; the standby was 120 bytes ahead after the fast stop's shutdown checkpoint.
    • block-failover landed 2.4 s after the promotion, outcome unknown, forwarded once.
    • The public API answered 2,863 of 2,863 with p99 40 ms.
  • faults-long-real-node with its warm-up cut to 4 minutes (release, real node, 2,000 sessions at 200 shares/s): exit 0, all twelve faults passing.
    • wal-disk-full refilled twice; PostgreSQL's log showed it down for 28.7 s, with 0 acknowledgements inside.
    • primary-kill lost 1,001 of 3,002 acknowledged shares in its 5 s cut, each listed, all after the barrier.
    • primary-switch lost 0 of 2,000.
    • block-failover landed 2.3 s after the promotion.
    • The faults phase took 10.6 minutes.

Mutants. Each was applied to the server, built, run against a one-fault copy of faults-failover-fake-node, and reverted.

Mutant Fault Result
MK: share appends commit with synchronous_commit = off (an ACK before its WAL is flushed) primary-kill exit 4. "no share acknowledged before the barrier was lost" failed: 2 lost shares were acknowledged before the barrier, and the durability finding names them.
MW: a share the ledger did not confirm is acknowledged anyway wal-disk-full exit 4. "no acknowledged share was lost" failed: 1 of 339 was missing, and the durability finding names it.
MF: a claim release the database did not answer is dropped, not retried (#529's deferred release undone) block-failover exit 9. "the block landed within 30 s of the promotion" failed: the row sat in offer_reserved for the 90 s watch, waiting for the 120 s lease.
MB: an offer the node never ran is released to pending but never retried candidate-backlog exit 9. "every backlog row reached a terminal state" failed: 3 rows were still pending.

Not covered here

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

… candidate backlog under load, nightly and weekly on the real node (#554)

The second half of #554's faults, in qbit-prism-load's `faults` phase. Each
is injected while the sessions keep mining and held to its criteria on top
of the run's own reconciliation. No server code changes.

- primary-kill: a barrier shows the standby flushed the primary's position,
  replication is cut, the primary keeps acknowledging for `cut` s and is
  stopped immediately, and the async standby is promoted. Every acknowledged
  share the new primary lacks is listed; none may predate the barrier, and
  each must be absent from what the standby had received.
- primary-switch: writers fenced, the standby replays through the old
  primary's flush position, then the switch. Nothing may be lost.
- block-failover: the relay holds a found block's submitblock while
  replication is cut and the primary stopped. With #529's standby wait on,
  the reservation must be on the promoted primary, and the block must reach
  the node once and land within 30 s of the promotion (#585).
- wal-disk-full: #575's DiskFullInjector fills the primary's pg_wal volume
  until PostgreSQL stops, then frees it. Nothing acknowledged may be lost or
  acknowledged while it is down. The frontends must serve again without a
  restart, and every /metrics must show #575's paging condition.
- candidate-backlog: the relay answers submitblock with qbitd's warmup error
  (#526) while found blocks pile up, every frontend is restarted, the relay
  heals. Every backlog row must reach a terminal state, and none may reach
  the node twice.

For these, the managed cluster streams its standby through a replication
link the harness can cut. Every writer (the frontends and the harness's side
pool) reaches the primary through a writer endpoint, and the public reader
reaches the standby through a read endpoint. A promotion moves the endpoints
and rebuilds the standby; nothing is restarted. The run excuses, from its
durability finding, only the acknowledged shares a failover's verdict proves
lie in the replication gap.

faults-short-real-node (nightly) gains every new fault but the full WAL
volume. faults-long-real-node (weekly, #588's Saturday selection, 16 vCPU)
runs all twelve with 2,000 sessions. faults-failover-fake-node runs the five
on dispatch. No per-PR test is added.

Refs #554

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@djh58
djh58 requested a review from kiwidream October 1, 2026 14:25
…e WAL volume (#554)

faults-long-real-node, on the Saturday `weekly` selection beside the soak,
and faults-failover-fake-node, on dispatch, run #554's wal-disk-full fault.
That fault mounts the primary's pg_wal on a small ext4 image with fuse2fs,
without root, as #575's disk-full scenario does. The run job now installs
fuse2fs and fuse3 when the preset's --faults lists wal-disk-full, and the
header and the dispatch input name the new weekly preset and its cost.

Refs #554

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and finish an abandoned failover (#554)

Review of #635 (/code-review medium, a quality review and an adversarial
review) found checks that could pass without proving their claim, a flake,
and a cleanup gap. No server code changes.

- candidate-backlog passed even if every backlog row was abandoned at the
  relaunch. It now requires one backlog block to land, offered once.
- block-failover took its barrier before waiting up to 30 s for the found
  block, so that whole window counted as the replication gap. The barrier
  is now taken after the held call arrives, just before the cut. The held
  call goes to the node within 800 ms of arriving, inside the frontend's
  1 s submitblock deadline, however long the stop takes.
- wal-disk-full now starts its down intervals and its outcome-unknown
  window at the fill's start, so a PANIC during the fill is counted. An
  acknowledgement inside a down interval fails the check only when its
  share is absent from PostgreSQL, since a late answer to an earlier
  commit is not a lie.
- An abandoned failover waits for its in-flight stop or promotion, promotes
  once, heals a cut link and moves the writer endpoint, so the run's end
  still finds a primary.
- The gap key's constant is renamed to match its value; the frozen set's
  lookback is named and leaves re-offers out; a unit test pins the backlog's
  unfinished states to the server's CandidateState::UNFINISHED_SQL.

Refs #554

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@djh58

djh58 commented Oct 1, 2026

Copy link
Copy Markdown
Member Author

Handover

@kiwidream now owns this PR. Head is 8af944e, the review fixes. CI is still running on the head commit. A review ledger will be posted here once CI is green. Any findings from that review will be listed in the ledger as open items with a proposed fix. No new commits will be pushed by the current owner. Left to do: green CI, the ledger, then owner review and merge. Its nightly and weekly workflow wiring takes effect only once main's workflow copy is synced (#633), which is blocked on #601.

@djh58

djh58 commented Oct 1, 2026

Copy link
Copy Markdown
Member Author

Review ledger: #635 (Refs #554)

Lanes run

  • /code-review high, before signing, on the uncommitted tree. It found 9 items; 8 were fixed in d1e3947 itself and 1 was rejected.

  • /deep-review on the PR:

    • /code-review medium (2 findings);
    • a code-quality review (8 findings, mostly structural);
    • an independent adversarial review (4 findings).

    The adversarial review looked at four questions: can a fault's verdict pass while an acknowledged share was lost or a block double-submitted; can the exit-4 excusal hide a loss it did not prove; is cleanup correct on every path; and is it flaky under a loaded runner. No bot or human review comments arrived on the PR.

Every finding was checked against the code. The fixes after review are in one follow-up commit, 8af944e.

Fixed before signing (in d1e3947)

# Finding Fix
1 A loss could be excused as the replication gap when the standby could not be read before promotion. Excusal and "promotion kept every share" now require a successful read of the standby.
2 The backlog counted every refused hash, including terminal rows and ones from an earlier backlog, and recorded nothing on its deadline path. It counts only this backlog's unfinished rows and records the last read on the deadline.
3 The fenced switch stopped the primary with an immediate stop, so WAL written after the catch-up read could show a gap. It uses a fast shutdown, which ships everything up to the shutdown checkpoint. The standby was 120 bytes ahead in the release nightly.
4 abandon() ignored the new faults, so the writer could stay fenced or the frontends stay down. Both the failover and the backlog are now cleaned up.
5 Refills could pile up concurrent pg_switch_wal loops. One loop runs at a time.
6 Outcome-unknown answers were excused from the replication cut on, while the primary was still healthy. They are excused from the kill (or the fence) on.
7 #529's standby wait is set for the whole of a failover run. Documented as run-wide in the README and the PR body.
8 A restart after a promotion would use the old primary's port and options. The promotion updates them.

Fixed after review (8af944e)

# Finding Fix
9 candidate-backlog passed if every backlog row was abandoned at the relaunch (adversarial). It now requires one backlog block to land, offered once.
10 block-failover took its barrier before waiting up to 30 s for the block, so the whole window counted as the gap (adversarial). The barrier is taken after the held call arrives, just before the cut.
11 wal-disk-full missed a PANIC during the fill itself (adversarial). The down intervals and the excusal window start at the fill's start.
12 The 250 ms grace could misread a late answer to an earlier commit (adversarial). An acknowledgement inside a down interval counts only if its share is absent from PostgreSQL.
13 The held submitblock could outlast the frontend's 1 s deadline (code-review medium). The relay carries every call in its own task, so it was never cancelled. The call is still released within 800 ms of arriving.
14 abandon() during an in-flight stop, cut or promotion (code-review medium; also the quality review's double promotion). It waits for the step, promotes once, heals a cut link and moves the writer.
15 The gap key's constant name did not match its value, and the frozen set's look-back was unexplained and included re-offers (quality review). Renamed; the look-back is a named constant that leaves re-offers out; a unit test pins the backlog's unfinished states to the server's CandidateState::UNFINISHED_SQL.

Deferred to #636

Structural, with no behaviour change. #636 has the detail.

  • One owner for the three endpoints.
  • One standby builder, and Endpoint moved out of fault/.
  • Per-mode fault state.
  • Reuse of the frontend helpers.
  • A FaultAction trait in place of match dispatch.
  • File splits.

Rejected

  • The fault plan is parsed three times. The parse is pure and deterministic, and validate() already parses it. Carrying it through RunContext would change no result.
  • In primary-kill, a share an ack-before-commit regression acknowledged inside the cut window would be excused (adversarial, finding 2's second half). Inside the cut, D3's policy permits exactly that loss, and a lost acknowledged share is indistinguishable from one that was never durable without reading the dead primary's WAL. MK, a server built with synchronous_commit = off on share appends, is still caught: it loses shares acknowledged before the barrier (exit 4).

Verification after the fixes (8af944e)

  • cargo fmt, and cargo clippy -p qbit-prism-load --all-targets -D warnings.
  • qbit-prism-load unit tests: the lib's 43 and harness 139.
  • The gated faults test, 33 s; check_e2e_scenarios.py.
  • faults-short-real-node, run the way the nightly runs it (release, real node): gate PASS and exit 0 in 668 s, all eleven faults passing.
    • primary-kill lost 151 acknowledged shares in its gap, each listed.
    • block-failover landed 2.2 s after the promotion, outcome unknown, once.
    • The public API answered 2,804 of 2,804 requests, p99 40 ms.
  • faults-long-real-node with its warm-up cut to 4 minutes (2,000 sessions, release, real node): exit 0, all twelve faults passing.
  • faults-failover-fake-node: exit 0, all five passing.
  • CI on 8af944e: green (22 checks passed; the run-load lanes are label-gated and skipped).

@djh58
djh58 merged commit 62cc625 into 3.x.x Oct 1, 2026
33 checks passed
djh58 added a commit that referenced this pull request Oct 1, 2026
…ts on #621, not #604

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
RobertClarke added a commit that referenced this pull request Oct 6, 2026
#551, #553, #554, #582)

The file is 3.x.x's copy byte for byte again, as of 3.x.x c95febb; the
last change to it there is bd1ddeb (#663). Since 1932cb3 (#597), five
3.x.x changes landed in it:

- #552 (#613): the `bridging` job runs the short plan on the fake and
  the real node on one runner, nightly, on the run-load label and on a
  dispatch with the new `bridging` input.
- #551 (#606): every preset job builds a trend row; on a schedule the
  `evidence` job (the one job with `contents: write`) appends the rows to
  the orphan `ci-evidence` branch, applies the report-only regression
  rule, promotes the soak's and flagged runs' bundles to the rolling
  `ci-evidence/YYYY-MM` pre-release, and keeps one
  `prism-load-regression` issue. PR and dispatch runs get the read-only
  `evidence-preview` instead.
- #553 (#618): the live nightly and weekly lists gain the chain-event
  scenarios under 2,000 sessions; the workflow's comments say so.
- #554 (#635): the run job installs fuse2fs and fuse3 for a preset whose
  faults fill the WAL volume (faults-long-real-node, Saturday).
- #582 (#663): comment only.

Without this, main's scheduled copy (#595) still has no qbitd install
step, so every `--node qbitd` preset fails with "--node qbitd needs
--qbitd-bin or QBITD_BIN" (scheduled runs 37188928798 and 37287515779).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Anatolie added a commit that referenced this pull request Oct 16, 2026
 (#590, #596, #588, #597, #552, #551, #553, #554) (#601)

* main: sync the PRISM load-harness nightly workflow from 3.x.x (#590, #596)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* main: sync the PRISM load-harness nightly workflow from 3.x.x (#590, #596, #588, #597)

Adds #588's Saturday 5.5 h soak schedule and its live-nightly step that runs every listed test binary, so qbit-prism-load::soak_smoke runs beside the live_regtest variants, and #597's L6 shipped-images lane on the Sunday schedule. Byte-identical to 3.x.x at 1932cb3.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* main: re-sync the PRISM load-harness nightly workflow from 3.x.x (#552, #551, #553, #554, #582)

The file is 3.x.x's copy byte for byte again, as of 3.x.x c95febb; the
last change to it there is bd1ddeb (#663). Since 1932cb3 (#597), five
3.x.x changes landed in it:

- #552 (#613): the `bridging` job runs the short plan on the fake and
  the real node on one runner, nightly, on the run-load label and on a
  dispatch with the new `bridging` input.
- #551 (#606): every preset job builds a trend row; on a schedule the
  `evidence` job (the one job with `contents: write`) appends the rows to
  the orphan `ci-evidence` branch, applies the report-only regression
  rule, promotes the soak's and flagged runs' bundles to the rolling
  `ci-evidence/YYYY-MM` pre-release, and keeps one
  `prism-load-regression` issue. PR and dispatch runs get the read-only
  `evidence-preview` instead.
- #553 (#618): the live nightly and weekly lists gain the chain-event
  scenarios under 2,000 sessions; the workflow's comments say so.
- #554 (#635): the run job installs fuse2fs and fuse3 for a preset whose
  faults fill the WAL volume (faults-long-real-node, Saturday).
- #582 (#663): comment only.

Without this, main's scheduled copy (#595) still has no qbitd install
step, so every `--node qbitd` preset fails with "--node qbitd needs
--qbitd-bin or QBITD_BIN" (scheduled runs 37188928798 and 37287515779).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Robert Clarke <[email protected]>
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