Skip to content

3.x.x: stream the recovery-evidence export with FETCH_COUNT in the script, the runbooks and the rehearsal harness (#705) - #706

Merged
RobertClarke merged 2 commits into
3.x.xfrom
RobertClarke/705-evidence-fetch-count
Oct 6, 2026
Merged

RobertClarke merged 2 commits into
3.x.xfrom
RobertClarke/705-evidence-fetch-count

Conversation

@RobertClarke

@RobertClarke RobertClarke commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Fixes #705 (close by hand: the base is not the default branch).

Problem

Without FETCH_COUNT, psql buffers a whole result set before printing a row. On the restored production copy (65.9M shares), the documented recovery-evidence export reached 63 GB RSS and was OOM-killed twice on a 62 GB host. With -v FETCH_COUNT=10000 the same export ran at about 4 MB.

The cutover rehearsal harness (make prism-cutover-rehearsal, which #291's C1 runs) had the same problem twice over:

  • it ran psql without FETCH_COUNT;
  • it collected all of psql's stdout in memory before writing it to a file.

Change

  • scripts/prism-recovery-evidence.sql:
    • Sets FETCH_COUNT to 10000 when the caller left it unset (0), so every psql caller streams. A caller's -v FETCH_COUNT=<rows> is kept.
    • FETCH_COUNT counts rows, not bytes, so the audit_bodies and audit_snapshots exports, whose rows can be megabytes, fetch 16 rows at a time and then restore the caller's value.
    • SET LOCAL cursor_tuple_fraction = 1.0: psql 16 and older batch through a cursor, and this keeps the planner on whole-result plans instead of first-rows plans.
    • Comments warn that those psql versions batch only statements starting with SELECT or VALUES.
  • Runbooks: the five export commands in docs/prism-ledger-ops.md and docs/prism-rust-migration.md pass -v FETCH_COUNT=10000 and say why. The flag covers script copies from before this change, such as the rc.1 tag's.
  • Harness (tests/support/recovery.rs): psql's stdout streams straight into the temp file. tokio's output() always pipes stdout, so the harness spawns and waits instead. It runs the script's own default.
  • New check: the frozen 2.x backup and restore test exports one row per fetch and requires the same evidence, so every result crosses batch boundaries.

No server code changes. Batching changes how rows are delivered, not what they are.

Tests

On a private PostgreSQL 16.10, at the branch head:

  • cargo test -p qbit-prism-server --test migration_rollback: 10 passed, 2 ignored (operator and generator modes). This includes the mainnet-shaped cutover rehearsal and the new FETCH_COUNT=1 equality check.
  • cargo test -p qbit-prism-server --lib recovery_evidence: 2 passed. These tests parse the script.
  • cargo clippy -p qbit-prism-server --test migration_rollback --test live_regtest -- -D warnings and cargo fmt --check: clean.
  • psql spot checks:
    • a 25,001-row export inside the script's read-only transaction is byte-identical with and without FETCH_COUNT;
    • the default (10000), a caller's value (2), the wide-row value (16) and its restore all behave as intended.

/code-review high ran on the first commit; its findings are addressed in the second.

Merge timing: after the v3.0.0-rc.1 tag, per the rc.1 freeze, unless the coordinator folds it into #703. Until then, operators pass -v FETCH_COUNT=10000 by hand, and run make prism-cutover-rehearsal at production size from this branch.

🤖 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.

RobertClarke and others added 2 commits October 6, 2026 00:57
…ript, the runbooks and the rehearsal harness (#705)

Without FETCH_COUNT, psql buffers a whole result set before printing a row.
On the restored production copy (65.9M shares) the documented export reached
63 GB RSS and was OOM-killed twice on a 62 GB host. With FETCH_COUNT=10000 it
streams through a cursor at about 4 MB.

The script now sets FETCH_COUNT itself, so every psql caller streams, and the
five runbook commands pass it explicitly, with the reason. The cutover
rehearsal harness ran the same psql without it and also collected all of
psql's stdout in memory before writing it to a file; it now passes the flag
and streams stdout straight into the file. tokio's output() always pipes
stdout, so the harness spawns and waits instead.

No server code changes. A cursor fetch changes how rows are delivered, not
what they are, so the evidence output is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…time, and plan cursors for the whole result (#705)

Review follow-ups. The script now sets FETCH_COUNT only when the caller left
it unset, so -v FETCH_COUNT=<rows> can lower the batch size. FETCH_COUNT
counts rows, not bytes, so the audit_bodies and audit_snapshots exports,
whose rows can be megabytes, fetch 16 rows at a time and then restore the
caller's value. psql 16 and older batch through a cursor, which the planner
otherwise optimizes for its first 10% of rows; SET LOCAL
cursor_tuple_fraction = 1.0 keeps the ordinary whole-result plans. The
comments warn that those psql versions batch only statements starting with
SELECT or VALUES.

The rehearsal harness no longer passes its own FETCH_COUNT, so it runs the
script's default. A new check in the frozen 2.x backup and restore test
exports one row per fetch and requires the same evidence, so every result
crosses batch boundaries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 6, 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-06T05:07:02.078503Z 886c63f PR opened
ℹ️ 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.

@RobertClarke
RobertClarke merged commit 5cfb0a3 into 3.x.x Oct 6, 2026
40 checks passed
@RobertClarke
RobertClarke deleted the RobertClarke/705-evidence-fetch-count branch October 6, 2026 06:33
RobertClarke added a commit that referenced this pull request Oct 6, 2026
Set VERSION and [workspace.package].version to 3.0.0-rc.2: rc.1 plus
migration 025 (#708, #710) and the legacy-audit-body sidecar tool (#715).
Cargo.lock and the fuzz crate's lock move only their workspace-member
entries.

doc/release-notes-3.0.0-rc.2.md covers:
- the changes since rc.1: 025's per-program carry-forward rule, the
  canonical sidecars for escaped legacy range digests, FETCH_COUNT for
  the recovery evidence (#706), and the harness and CI fixes;
- upgrading from 2.0.x and from rc.1;
- the lean verification, since the only runtime change is 025;
- the known issues.

The development-line notes name 3.0.0-rc.2 as the tree's identity, and
they and the 3.0.0 notes link both candidates' notes. U3 wrote the
change lines.

Co-Authored-By: Claude Opus 5.5 <[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