Skip to content

3.x.x: learn the restart test's background statements after a landing, and keep its claim transaction whole (#729) - #792

Merged
kiwidream merged 1 commit into
3.x.xfrom
kiwidream/729-recovery-background-set
Oct 27, 2026
Merged

kiwidream merged 1 commit into
3.x.xfrom
kiwidream/729-recovery-background-set

Conversation

@kiwidream

@kiwidream kiwidream commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Fixes the flaky candidate_storm_restart::a_relaunched_frontend_recovers_one_row_at_the_same_statement_cost_at_both_cardinalities (#729). The change is test-only. The test failed in three ways, and all three were faults in how it measured, not in the server.

The three failures

72 vs 65. PostgreSQL shard 2 failed this way in 5 of 23 completed CI runs since Oct 22, #788 twice in a row among them.

  • The test learns the relaunched child's background statements in idle windows, then counts everything else inside the recovered row's span. Those windows ran before the child had accepted any block.
  • The metrics collector looks up orphan evidence only for blocks the process has registered as accepted. The recovered row's own active observation (Metrics::accepted_block) registers one inside the measured span.
  • No miner connects to close it, so from then on every 10 s collector tick runs that lookup. Its text had never been seen while idle, so a tick inside the span was counted as 7 statements of recovery work.

61 vs 65. This is the Oct 6 failure #729 was filed for. It was not an extra background transaction, as the issue first said: the 99-row run lost four statements of the recovered row's own claim transaction.

Three bare ROLLBACKs. This happened once, on this branch, during review.

The change

  • A warm-up landing. The relaunched child now lands one sibling after a first idle window and before the window the background set settles in. The first window, together with the launch, covers the child's startup.
  • What counts as background: everything the child ran outside that landing. Every background statement that only an accepted or landed block switches on is then seen while idle, whichever loop runs it, without the test naming any of them.
  • A check on the landing: the node must have been offered that sibling once and the recovered block no more than before.
  • Where counting starts: the measured executions now start at the verification window instead of the release. A transaction that reaches the recovered row's span is rebuilt from its BEGIN, and the span alone still decides what counts.
  • Transaction control is neutral: BEGIN, COMMIT, ROLLBACK, SAVEPOINT and RELEASE no longer make a run foreground on their own. They are read from the server's completion tags, or from a single-statement text when the proxy couldn't pair them.
    • This can't hide recovery work. BEGIN and COMMIT are in every background set, so each recovery transaction was already selected through a statement of its own.
    • The pinned sequence has no ROLLBACK, and a taken run still counts every statement it has.
  • Unchanged: the pinned 65, the equality across cardinalities, the empty selection on the verification window, the unfinished-count difference (now 22 vs 98), and 3.x.x: Offer the block to the node before rebuild, verification and landing #266's no-second-offer check.
  • Doc comments: they now say the row is taken over ahead of every sibling, not claimed by the oldest-due lane behind them.

Tests

The fix was proven with two experiments. Each was run on the base and on the change, using the execution proxy's own pauses. Neither is committed.

  • Collector tick in the span. Holding the recovered row's landing COMMIT for 12 s (pause_after_commit) puts one collector tick inside its span.
    • Base: "72 statements with 23 rows behind it and 65 with 99"; the extra 7 are exactly the collector's transaction.
    • With this change: one orphan lookup ran inside the span, it was in the background set, and both counts were 65.
  • Claim transaction across the mark. Holding the claim poll's fence reply across the mark and the release (pause_statement), at 100 rows.
    • Base: "65 with 23 and 61 with 99", missing BEGIN, the fence, the survey and COMMIT.
    • With this change: the takeover's transaction began before the mark, and the count was 65.
  • Pruner rollback. Holding the pruner's COMMIT reply for 6 s, past its budget, needs a statement-level marker trigger plus pause_after_commit.
  • Why the startup window is needed. Without it, an experiment counted 71. Share-partition maintenance ticks at startup and then every 60 s, and the session settings of new pool connections go unlearned.

Local runs on minidev-alex1, private PostgreSQL 16:

  • test/prism-native-tests.sh cargo-args --locked -p qbit-prism-server --test candidate_storm_restart -- --test-threads=4 --nocapture passed 21 of 21 three times on f58fe24d, and three times with the ROLLBACK fix on 3dbe288a. Every run recorded restart_recovery_statements at 65 and 65.
  • Run the clusters with TMPDIR on disk at a short path: the host's /tmp quota kills PostgreSQL ("Disk quota exceeded"), and a long path breaks its socket limit.
  • cargo fmt --all -- --check and cargo clippy --locked --workspace --all-targets -- -D warnings: clean.
  • No gated test was added or renamed.

A review pointed out that learning background statements from idle windows still depends on reaching the right state first. A background statement that only some later state switches on (a reconciliation row, a parked row) would need its own warm-up. A design that attributes executions by origin, for example a per-loop application_name recorded by the proxy, would remove that class entirely, but it needs a server change, so it is out of scope here.

Fixes #729.

🤖 Generated with Claude Code


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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T19:25:23.502292Z 06a7832 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@qbit-reviewer qbit-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No findings.

…, and keep its claim transaction whole (#729)

a_relaunched_frontend_recovers_one_row_at_the_same_statement_cost_at_both_cardinalities
failed three ways. All three are faults in the measurement, not in the
server.

72 vs 65 (PostgreSQL shard 2, in five CI runs since Oct 22).
- The idle windows that learn the relaunched child's background
  statements ran before it had accepted any block.
- The metrics collector looks up orphan evidence only for blocks this
  process registered as accepted. The recovered row's own active
  observation (Metrics::accepted_block) registers one inside the
  measured span.
- No miner connects to close it, so every ten-second tick after that
  runs the lookup. Its text was never seen idle, so a tick inside the
  span was counted as a 7-statement foreground transaction.

61 vs 65 (Oct 6). The 99-row run lost four statements of the recovered
row's own claim transaction: BEGIN, the writer fence, the claim survey
and COMMIT.
- Since #581, the first claim poll after the release takes the row
  over, ahead of every sibling.
- That poll sent BEGIN and the fence before the measured window's mark,
  and the survey after the release committed.
- So runs() over the executions since the mark split the transaction
  into runs of one, and kept only the takeover.

Three bare ROLLBACKs (once, on the rebased branch).
- The job/blob pruner runs a write transaction every two seconds, inside
  a five-second timeout_at that covers its COMMIT. That COMMIT waits for
  a WAL flush.
- When a stalled flush holds the COMMIT past the budget, the future is
  dropped mid-COMMIT. SQLx then sends a ROLLBACK behind the COMMIT,
  which the server completes anyway.
- The result is a ROLLBACK outside any transaction, a run of one that no
  idle window need ever see. It depends on the host's disk, not on the
  scenario's state.

The change:
- The relaunched child now lands one sibling after a first idle window,
  which together with the launch covers its startup, and before the
  window the background set settles in.
- The background set is everything the child ran outside that landing.
  So every background statement that only an accepted or landed block
  switches on is seen while idle, whichever loop runs it, without the
  test naming any of them.
- The node must have been offered that sibling once, and the recovered
  block no more than before.
- The measured executions now start at the verification window instead
  of the release, so a run that reaches the recovered row's span is
  rebuilt from its BEGIN. The span alone still decides what counts.
- Transaction control (BEGIN, COMMIT, ROLLBACK, SAVEPOINT, RELEASE) no
  longer makes a run foreground on its own. It is read from the server's
  completion tags, or from a single-statement text when the proxy could
  not pair them.
- Why that can't hide recovery work: BEGIN and COMMIT are in every
  background set, so each recovery transaction was already selected
  through a statement of its own. The pinned sequence has no ROLLBACK or
  savepoint, and a taken run still counts every statement it has.
- Unchanged: the pinned 65, the equality across cardinalities, the empty
  selection on the verification window, the unfinished-count difference
  and #266's no-second-offer check.

The doc comments now say the row is taken over ahead of every sibling,
not claimed by the oldest-due lane behind them. They also say a
per-sibling loop in the due-work probe or the claim lanes costs the
siblings' claims, which this test does not measure; a per-sibling loop
in the claim survey a takeover shares is still caught.

Tests: uncommitted experiments forced each interleaving with the
execution proxy's own pauses.
- Holding the recovered row's landing COMMIT for 12 s, past one
  collector tick, failed the base test with "72 statements with 23 rows
  behind it and 65 with 99". With this change, the lookup inside the
  span was background, and both counts were 65.
- Holding the claim poll's fence reply across the mark and the release
  failed the base test with "65 with 23 and 61 with 99". With this
  change, the transaction was rebuilt whole and counted 65.
- Holding the pruner's COMMIT reply for 6 s, past its budget, reproduced
  CI's three bare ROLLBACKs in the verification window, and "66 with 22
  and 65 with 98" inside the span. It did so with and without #788.
  With this change, both passed at 65 and 65.
- The full candidate_storm_restart binary passed 21 of 21 in six runs on
  private PostgreSQL 16 clusters. Each run recorded
  restart_recovery_statements at 65 and 65.

Refs #729.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kiwidream
kiwidream force-pushed the kiwidream/729-recovery-background-set branch from 6555ff4 to 06a7832 Compare October 27, 2026 19:24

@qbit-reviewer qbit-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No findings.

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