Repository navigation
3.x.x: retry a failed candidate attempt's claim release until the database answers, finish an offer in flight at shutdown, and record a recovered reservation's outcome as unknown (#529, #578) - #585
Conversation
…abase answers, finish an offer in flight at shutdown, and record a recovered reservation's outcome as unknown (#529, #578) A PostgreSQL failover while a found block is mid-landing delayed the landing by up to the 120 s candidate lease (#529 item b). The offering frontend's attempt failed on the old primary's dead connections, its claim release failed on the same connections, and no frontend could take the row until the lease expired. The submit loop now keeps a failed attempt whose release did not reach the database, and retries the same token- and lease-fenced release (the one retry_candidate runs, split out as release_candidate_claim) about once a second until the database answers or the lease's local end passes. At shutdown it tries each once more through release_recovery_claim. - Structural, not by convention: claim_release::Attempt owns the claim, the future of Attempt::run borrows it, and the only ways to release it (Attempt::failed, and at shutdown Attempt::hand_back_at_shutdown, which is #573's hand-back moved there unchanged: same release, reason, bound and logs) consume it, so the borrow checker drops the work first. Nothing this process started under the claim, submitblock included, can still run once the row is released. - The release is fenced on the token and the live lease, so it changes nothing once another frontend has taken the row or the lease expired. Offer-state rows are never offered again by the recovery, as before. - Retries keep their schedule while the loop processes other rows; before each claim the loop waits for at most one bounded retry (the lease's 5 s bound, never past the lease's local end). - The lease's local end comes from the heartbeat itself (the start of the last successful renewal plus the lease), never later than the database's own expiry. - WARN logs when a release is deferred and when it succeeds or expires. - A holder that died with the old primary still leaves its claim to the lease. A takeover keyed on the promotion (a timeline-stamped claim) would cover it, but needs a migration and preempts every healthy holder after a promotion; it stays a documented option in #529. A graceful shutdown between the offer reservation's commit and submitblock dropped the attempt, leaving an offer_reserved row that was never sent and that recovery never offers again, so a restart could lose a found block; #570's standby wait sits inside that window (#578). The offer path now holds an offer section from just before the reservation until the node's answer is recorded or the unsent reservation is returned to pending. A shutdown that finds one open keeps driving the attempt until it closes, within the send's deadline, the standby wait's bound and the lease's bound for the reservation and the recording, logs that it waits, and only then stops; the landing after it is left to the next claim, which lands the offered row without another offer. Pre-dispatch failures still return the reservation through release_unsent_offer. A crash in the window is unchanged: recovery reconciles the reservation as delivery unknown. A recovered offer_reserved row whose call's answer was never recorded landed submitted with offer_outcome NULL (#529 item a). finish_candidate now records unknown for an offer-state row without an outcome, as the reconciliation and orphan dispositions already do; pending rows keep none. Tests (gated, listed in test/prism-gated-tests.txt): - claim_release_tests, a third frontend reaching PostgreSQL through a TCP relay the test cuts and heals, with a 30 s lease: the claim is released 0.3 s after the database answers and only after the attempt's work was dropped, then another frontend recovers the reservation and lands it with outcome unknown and no submitblock; a deferred release leaves a claim another frontend took after expiry untouched; shutdown releases a deferred claim. - offer_shutdown_tests: a shutdown with the attempt parked right after the reservation (before the standby wait) or right before the send waits for the offer; the block is sent once, recorded accepted, and landed once. - The live async failover drill now asserts landing within 30 s of the promotion (2.3 s here; 119.8 s with the retry removed) and the unknown outcome. Docs: the ledger operations guide describes the deferred release, the shutdown mid-offer and the recorded outcome, and the HA reference's promotion step 5 says when a mid-landing block lands. Closes #529. Closes #578. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This comment has been minimized.
This comment has been minimized.
…offer section the renewal's allowance, and classify the moved pool checkouts (#529, #578) Review of #585 found two ways the shutdown path could run out of time. - The offer-section bound allowed the lease's bound twice, for the reservation and the recording, but a section has three database steps: the strictly-live renewal before submitblock is the third. A slow but live database could end the wait during the send and drop a reserved block, the loss #578 prevents. It now allows the lease's bound three times. - After the shutdown signal the loop could spend the section wait, the claim hand-back and one bounded attempt per deferred release in series, past the server's 30 s join of its tasks, which then aborts the loop and leaves its claims to the lease. Everything after the signal now shares one 20 s budget (SHUTDOWN_BUDGET), leaving room for one bounded retry already running when the signal came, and a signal that arrives during the pre-claim retry claims no new row. scripts/prism_pool_acquires.json follows the moves: the heartbeat's checkout is now in with_tracked_heartbeat, retry_candidate's BEGIN in release_candidate_claim, and Attempt::run is classified non-database (a name collision, like the server's runtime run), which the Python shard's pool-acquire check requires. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review ledger (deep-review)Stakes: high. The change is on the found-block offer, claim and landing path ( Battery.
Shutdown budget. Everything the submit loop does after a shutdown signal (waiting for an offer in flight, #578; handing back its claim, #573; the deferred releases, #529) shares one 20 s budget, inside the server's 30 s join of its tasks. That leaves room for one bounded (5 s) retry already running when the signal came, and no new row is claimed once the signal is seen. The offer wait is the smaller of that budget and the send's deadline + the standby wait's bound + three lease bounds (about 16 s with the defaults). A block still in its offer section when the budget runs out. The loop logs Also verified. The recovered outcome change (a) is exact against the 015 offer rule (only offer-state rows get CI on 91070c5. Everything is green except Python shard 1 (item 4, #584) and the aggregate job that depends on it. |
… candidate backlog under load, nightly and weekly on the real node (#554) (#635) * 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) 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]> * 3.x.x: install fuse2fs in the load-run job for a preset that fills the 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]> * 3.x.x: close the #554 fault checks review found could pass or flake, 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]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Closes #529 (items a and b; item c was fixed by #570). Closes #578.
Why
In the #531 async failover drill, a found block that was mid-landing when the primary failed landed about 120 s after the promotion: the
CANDIDATE_LEASE. The offering frontend's attempt failed on the old primary's dead connections, and so did its claim release (retry_candidate), so no frontend could take theoffer_reservedrow until the lease expired (item b). The recovered row then landedsubmittedwithoffer_outcomeNULL, while the reconciliation and orphan paths recordunknown(item a).What
(b) The holder retries its own claim release. Design options and the safety argument were agreed before implementation (holder-side deferred release, no schema change):
retry_candidateruns (split out asLedger::release_candidate_claim, which reportsfalseinstead of failing when the claim no longer holds the row), about once a second, until the database answers or the lease's local end passes. At shutdown it tries each once more throughLedger::release_recovery_claim, the path the submit loop's own shutdown release uses.claim_release::Attemptowns the claim and the future ofAttempt::runborrows it; the only ways to release the claim consume the attempt:Attempt::failed(theFailedAttempta release takes) and, at shutdown,Attempt::hand_back_at_shutdown. The borrow checker therefore drops the work first, and nothing this process started under the claim,submitblockincluded, can still run once the row is released.offer_reservedrow is never offered again, as before, so no newsubmitblockpath exists.candidate claim release deferredwhen it starts, anddeferred candidate claim release succeeded/... expired with its leasewhen it stops.#578: a graceful shutdown finishes an offer in flight. Once a reservation commits, no frontend offers the block again, so a shutdown that dropped the attempt between that commit and
submitblocklost the block on an ordinary restart; #570's standby wait sits inside that window.coordinator/offer_shutdown.rs) from just before the reservation until the node's answer is recorded, or the unsent reservation is returned topending(RpcNotSentError/release_unsent_offer, unchanged). It closes on every path when dropped, so a lost lease still ends it.offeredrow without another offer. The wait is bounded by the send's deadline + the standby wait's bound + the lease's bound for each of the reservation, the renewal before the send and the recording (about 16 s with the defaults), logsshutdown waits for a found block's offer in flight, and on the bound logs an ALERT and stops. Everything the loop does after the shutdown signal (this wait, the 3.x.x: fanout claim/attempt bookkeeping edge cases (follow-up to #569) #573 hand-back, the deferred releases) shares one 20 s budget inside the server's 30 s join, and a signal that arrives during the pre-claim retry claims no new row.(a) The recovered outcome.
finish_candidaterecordsoffer_outcome = unknownfor an offer-state row that has none, matching reconciliation and the orphan disposition. A pending row keeps none (the 015 offer rule). Rows that already landed with NULL are not rewritten.Docs. The ledger operations guide describes the deferred release, the shutdown mid-offer and the recorded outcome; the HA reference's promotion step 5 says when a mid-landing block lands.
Tests
All gated and listed, sorted, in
test/prism-gated-tests.txt.coordinator::candidate_lease_tests::claim_release_tests::a_failed_release_is_retried_after_the_attempt_stops_and_frees_the_row_before_its_leasesubmittedwith outcomeunknown, no call time, and nosubmitblock...::a_deferred_release_never_frees_a_row_another_frontend_took...::shutdown_attempts_each_deferred_release_oncecoordinator::candidate_lease_tests::offer_shutdown_tests::shutdown_after_the_offer_reservation_sends_and_records_the_block_onceacceptedbefore the loop exits, and it lands once with no second offerlive_regtest::pg_failover_tests::real_async_failover_mid_landing_loses_only_the_replication_gap(extended)unknown. The fenced drill is unchanged (0.3 s,accepted)Mutants (each fails at least one test)
the row waits for the 30 s lease), shutdown test, and the live async drill (landed 119.8 s after the promotion, beyond 30 s)changed another frontend's claim)released while the attempt's work was still running), and the other twolanded as submitted with outcome None)shutdown dropped the offer after its reservation committed)Verification
On the final tree (rebased onto #576; the fmt, clippy, full
--libandpg_failover_testsruns were repeated on the latest 3.x.x,2f907447, with the same results):cargo fmt --all --checkandcargo clippy --locked -p qbit-prism-server --all-targets -- -D warningsare clean.PRISM_TEST_REQUIRE_INTEGRATION=1:--libbinary: 590 passed, 0 failed (2 ignored); the four new tests passed 3/3 more back to back (about 14 s per run), and every mutant above was re-run against this tree;offer_lifecycle,rpc_not_sent,candidate_storm_restart,candidate_storm,offer_latency,landing_metrics,ledger_postgres(incl.candidates list/recover),refresh_liveness: 330 passed, 0 failed;live_regtest pg_failover_tests(both 3.x.x: live PostgreSQL primary failover with a found block mid-landing (#521 scenario 3) #531 drills and the 3.x.x: wait, within a bound, for the failover standby to flush a found block's reservation before submitblock (#529) #570 standby drill) 3/3 back to back on a loaded shared host (1-minute load 9 to 10): the async drill landed 2.3 s after the promotion with outcomeunknown, the fenced drill 0.3 s withaccepted;live_regtest node_outage_tests(the 3.x.x: a block found while qbitd refuses the connection is never offered again and is lost #522/3.x.x: live regtest: a qbitd stop or crash around submitblock offers each block once and lands or reconciles it (#521 scenario 4) #523/3.x.x: a submitblock answered with RPC_IN_WARMUP (-28) after a qbitd restart is recorded unknown and the block is lost #526 offer drills): 5 passed, 1 pre-existing ignored.readiness_rpc,lost_race_pin,b478_stale_revision_block,b478_payout_integrity,candidate_window_qualification,candidate_dispatch_probeandledger_single_executionalso passed.Coordination
release_recovery_claim, reasonclaim released at shutdown, 5 s bound and logs) intoAttempt::hand_back_at_shutdown, which runs after the attempt's future is dropped and, with 3.x.x: a graceful shutdown between offer reservation and submitblock can drop a found block #578, after an offer in flight has been recorded. 3.x.x: hand fanout and candidate claims back at shutdown, keep a lost failure's backoff, count refused sends and requeue refused fanouts behind due rows (#573) #576'ssubmit_loop_shutdown_hands_the_claim_back_for_an_immediate_takeoverpasses.🤖 Generated with Claude Code