Repository navigation
3.x.x: peer sync's apply_prepared takes the blob-GC fence, in bounded chunks, so a pulled job keeps its blobs (#785) - #799
Conversation
…d job keeps the blobs it reuses (#785) apply_prepared inserted a pulled batch's template and balance blobs with ON CONFLICT DO NOTHING and never touched the cluster row. When this node already held a blob that no job named any more, the insert locked nothing. prune_unreferenced_blobs (cluster row FOR UPDATE, then a DELETE whose NOT EXISTS cannot see the uncommitted job) could then delete it before the apply committed. The job, and on a peer pull the advanced cursor, committed without its blob (D-19), so adoption (S8) could not read that record. The change: - apply_prepared takes `qbit_prism_cluster ... FOR KEY SHARE` right after BEGIN, as save_compact_prepared does, whenever the batch holds a job or a blob, and holds it through the commit. The collector then either commits first, and the apply's inserts put the blobs back, or scans after the job is visible. - Lock order: the collector takes SETTLEMENT, ORDER, then the cluster row, and authority writers take advisory and table locks before it. apply_prepared takes no advisory lock after the fence: its job insert names sync_seq, so the barrier-taking default never runs, and record_conflict and advance_cursor take none. No writer that holds a row apply_prepared writes waits for the cluster row. - An empty batch takes no fence, so an idle pull never waits behind an authority writer. Tests (dual_writer_sync, PostgreSQL-gated): - a_pulled_prepared_job_keeps_the_held_blobs_it_names_from_the_collector: the apply waits at its cursor advance. The collector must wait for it at the cluster row and delete nothing. Applying the batch again changes nothing. - a_pulled_prepared_job_puts_back_the_blobs_the_collector_took_first: the collector waits in its DELETE holding the cluster row, and the apply waits for it and re-inserts both blobs. A fence wait that fails (cancelled behind an authority writer) applies nothing, keeps the cursor, and applies whole on retry. Both fail on the base with "B holds the pulled job without its blobs". Co-Authored-By: Claude Opus 5.5 <[email protected]>
…issing (#785) Review of 128d1ac measured the blob-GC fence held for a whole pulled batch: 0.7-2.1 s for 5000 prepared jobs, about 48 ms a MB of blob JSON. The tip observation waits for it holding SETTLEMENT, and the collector holding SETTLEMENT and ORDER, so landings, candidate writers and share appends queue behind them. Own-log recovery also re-applied, and so fenced, every batch of own jobs even when none was missing. The change: - apply_prepared applies a batch in chunks of at most 1000 jobs and 2 MiB of job and blob JSON (PREPARED_CHUNK_ROWS, PREPARED_CHUNK_BYTES). At the measured rates that is about 140 ms plus 100 ms, so one hold stays near 250 ms. A job whose blobs alone are larger goes alone: it cannot be split from them (D-19). - Each chunk is its own transaction: the fence, the blobs its jobs name (a shared blob in every chunk that names it), its jobs, the cursor through its last job, commit. A failure leaves the earlier chunks and the cursor past them, the next read resumes there, and re-applying is a no-op. - A conflict refuses its chunk through the chunk's last job, not the batch's. The rows above it are held, which is what offer_wait's `need > refused` assumes. A blob conflict that several chunks name is recorded and counted once per batch, and refuses each of them. - Own-log recovery first asks prepared_held_alike: is every job and blob held as the peer has them, a job's expiry aside? If so it applies nothing and takes no fence. A batch missing a row, or holding one otherwise, is applied as before, so a diverged own job still stops recovery (D-17). - The fence comment says why no peer-sync apply calls writable(). Tests: - a_pulled_prepared_job_keeps_the_held_blobs_it_names_from_the_collector: a share append now completes within 2 s while a pull holds the fence. With FOR SHARE it times out. - a_large_pull_applies_in_fenced_chunks_and_resumes_after_a_failed_one (2.5 chunks): the first chunk is committed while the second waits. The second, cancelled with its rows written, applies nothing, and so does a cancelled fence wait. Resumed from the cursor, the pull applies whole. One blob conflict over two chunks is recorded once and refuses both. It fails with chunking disabled and without the dedupe. - recovery_applies_only_own_prepared_jobs_missing_or_held_otherwise: fails when recovery always applies. - prepared_chunks_keep_their_bounds_and_carry_every_blob_their_jobs_name (unit): the row and byte bounds, an oversized job alone, the blobs of each chunk, an empty batch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5f436b6e62
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| applied.merge( | ||
| self.apply_prepared_chunk(&chunk, origin, stream, &mut recorded) | ||
| .await?, |
There was a problem hiding this comment.
Preserve committed chunk counts when a later chunk fails
If an earlier chunk commits and a later chunk fails (for example, through the cancellation exercised by the new test), this ? discards the accumulated Applied even though the earlier rows, conflicts, and cursor advancement remain committed. In PeerSync::pull_peer, the error branch only calls stream_failed, so those committed changes never reach report.applied or record_peer_sync_applied. Subsequent pulls start after the committed cursor and cannot recover those counts, permanently underreporting both inserted rows and any conflicts confined to the earlier chunks. Preserve the committed chunks' accounting alongside the error and merge it into the pass report.
Useful? React with 👍 / 👎.
…the chunked fence's last gaps (#785) Re-check and pre-push review of 5f436b6. Partial success keeps its accounting: - apply_prepared returns PreparedApplyError when a chunk fails. It carries the Applied of the chunks committed before it and the jobs still pending. - The pull merges that Applied into its report, so qbit_prism_peer_sync_rows_total and _conflicts_total count those chunks; the retry resumes past them and would never count them. The stream's lag is the pending jobs, not the whole batch. - Own-log recovery merges it before ensure_progress. A conflict a committed chunk recorded stops recovery as a divergence (D-17), even when a later chunk fails. - stream_failed's doc and docs/prism-ledger-ops.md now say that the cursor stops before the failed unit, and what was committed before it stays and is counted. The chunk bound's doc: the hold scales with JSON at about 64 ms a MiB. A job whose blobs alone pass 2 MiB goes alone (D-19): a 4 MiB template held the fence about 509 ms, an 8 MiB one about 1,049 ms. Less work under the fence: the carried columns of the three tables are read once a batch, on a plain acquire, before the first fence. carried_columns_in takes a connection, so transactions still pass. Cleanups: - json_len counts bytes through an io::Write instead of building the string. - The pass that put blobs no job names into the last chunk is gone. It was unreachable from a pull and skipped the byte bound; such a blob is not applied. - prepared_held replaces missing_prepared and prepared_held_alike: one query on a plain acquire, with no BEGIN. Tests (dual_writer_sync, PostgreSQL-gated): - a_pull_that_fails_partway_counts_and_keeps_the_chunks_before_it: the first chunk refused, the second clean, the third failing. The pass counts both chunks' rows and the conflict in its report and metrics, lags by the third chunk alone, and its cursor stands past the second, refused through the first only. It fails without the accounting ("Applied { inserted: {}, conflicts: {} }") and with refusal sticky across chunks (cursor ingested through 2000, not 1000). - recovery_stopped_partway_still_meets_a_conflict_it_committed: fails, reporting the later error, when recovery drops the committed chunk's conflict. - recovery_applies_only_own_prepared_jobs_missing_or_held_otherwise now also checks that a lost own template is put back, and that own balances held with other bytes diverge. It fails when prepared_held ignores blobs ("recovery left a lost own blob lost"). - The chunk unit test: no unnamed blob in any chunk, and json_len matches the serialized length. Co-Authored-By: Claude Opus 5.5 <[email protected]>
#814) (#819) - 3.1.1 notes: the L3 runs the tag can promote, and the first l3-full runs on a tree with #788 (#810, #811), in Verification and #779; a 3.1.0 frontend's peer sync still lacks #799's blob-GC fence on its node's database; "no released migration's SQL changed" instead of sqlx checksums the native runner doesn't keep; CI on the promoted main commit rather than a tag dispatch. - docs/releasing.md: rewrite the notes' relative links for the release body. - prism-rust-migration.md, prism-ledger-ops.md: from 3.1.1 the #709 and #731 sidecar procedures aren't needed, and the #731 checker's re-check exits 3 for rows 3.1.1 imports; 032 in the migration transaction. Co-authored-by: Claude Opus 5.5 <[email protected]>
## Problem #814: after 3.1.1, several operator docs and the #731 parts-digest checker still described pre-3.1.1 behaviour. #819 shipped part of the fix; this PR does the rest. - The docs said every share append updates the cluster row, which stopped being true in #801. They gave that as the reason for the long-snapshot guidance and the backfill's 5 s cap. - The docs called the peer-sync prepared apply one transaction. Since #799 it runs in chunks. - The docs priced the share path at "ten statements and a ping", which #802 changed. - On 3.1.1, the checker reported `import_refuses` and exited 3 for 2.x v2 bodies that the import accepts. - Some references were already wrong in 3.1.0. ## The change **Cluster row (#801).** Each passage is now scoped to "while a frontend before 3.1.1 serves the database": - the files: prism-rust-migration.md, prism-ledger-ops.md (including the line next to the `/audit` routes) and the admission-gate comment; - the backfill's 5 s cap stays, explicitly as a conservative choice. The backfill can't tell which releases are serving, and a rolling upgrade mixes them; - MultiXact estimate: the clock `UPDATE`s left are the snapshot anchor's and the own-log floor's. A fenced append still locks the row `FOR SHARE` (032), so the MultiXact rate still grows with the share rate. **Prepared apply (#785/#799).** It is now described as chunks of at most 1,000 jobs and 2 MiB; a job whose blobs alone are larger goes in a chunk by itself. Each chunk is its own transaction under the cluster row's `FOR KEY SHARE`. - Files: prism-ledger-ops.md, prism-configuration.md, and the `config/dual_writer.rs` doc comment (comment only). - New peer-sync rows in the lock matrix and the lock-order table: prepared apply, and the own-log floor (SETTLEMENT → ORDER → cluster `NO KEY UPDATE`). **Share path (#802).** A share without a block takes three round trips and four statements: `BEGIN; SET LOCAL`, one call, `COMMIT`. A share that carries a block keeps the ten. **#731 checker.** `scripts/prism_legacy_parts_digest_check.py` gets an opt-in `--with-731-fix` mode, which models 3.1.1's import: - what it recomputes: 2.x's parts digest over the parts as 3.x parses them. That means known fields in declaration order with `kind` first, and inline shares in `AcceptedShare` form, using the sidecar tool's model. Non-ASCII is escaped; - statuses: `ok-in-3x` or `matches-neither`; - if `prism_legacy_range_sidecars.py` is not beside the checker, the mode refuses up front; - the default mode is byte-identical to before, with the same statuses, output and exit codes; - the docstring's "3.x refuses every 2.x v2 body" is corrected; - the #731 runbook gets a 3.1.1 command variant. **References.** - `/audit/latest-evidence` → `/audit/latest`. - Migration 17's refusals are no longer quoted as "migration 16". - The truncated native-collision quote is completed. - prism-alert-migration.md now says eight native rules page, with `critical` and `page: "true"`. - tests/perf/window_paging_allocation.md's re-run recipe starts from a worktree of #241's commit, which holds the harness that today's tree lacks. The image is built from 527b3ac's tree by path, since today's Dockerfile builds a different image. **#820 follow-up.** The `PrismAcceptedRevisionWorkTrackingUnknown` description now says an idle backup's unknown wait also ends when the block matures, if no authorized miner was connected since its acceptance. The text was changed at its source in `scripts/generate_prism_alerts.py`. The rule JSON, the migration doc tables and the qbit-tools patch were regenerated with `--snapshot` from the pinned qbit-tools a007a142 templates. ## Tests run (minidev-alex1) - `PRISM_AUDIT_CANONICALIZE_BIN=target/debug/qbit-prism-audit-canonicalize python3 -m unittest tests.test_prism_legacy_range_sidecars tests.test_prism_legacy_parts_digest_check tests.test_docs_lab_prism_references tests.test_prism_legacy_import_admission_gate`: OK (1 skipped). The canonicalizer was built with `cargo build --locked -p qbit-prism --bin qbit-prism-audit-canonicalize --bin qbit-prism-build-audit-bundle`. - New tests cover the fixed mode on both 2.x fixtures and on sorted-key and other digests. - They cover unknown keys, null bounds and escaping. - Inline-share variants are checked against the real canonicalizer: null `credit_policy`, an unknown key, reordered keys. - They check that the other statuses are unchanged, that `--jobs 3` parity holds, and that the checker runs when copied alone. - `python3 scripts/generate_prism_alerts.py --check`, `generate_prism_metrics.py --check`, `check_prism_settings.py`, `check_prism_alert_uids.py`, `check_gate_env_reads.py`: pass. - `python3 scripts/test_prism_alert_deployment.py --snapshot <qbit-tools a007a142 templates>`: patch applies, 10 Jinja gate combinations pass. - `cargo fmt --all -- --check`: pass. `cargo clippy --locked -p qbit-prism-server --all-targets -- -D warnings`: pass (only the 3 known vendored sqlx-core warnings). - `bash -n scripts/prism_legacy_import_admission_gate.sh`: pass. ## What CI must cover - the Python test shards; - `make test-prism-legacy-range-sidecars`, which uses the real canonicalizer; - the alert PromQL check with promtool, not run here (only a description changed); - the full Rust suites. No Rust code changed, only one doc comment. Refs #814 🤖 Generated with [Claude Code](https://claude.com/claude-code) Squashed commits: 27d51e6 3.x.x: operator docs and the #731 checker catch up with 3.1.1 (#814) f84b602 3.x.x: --with-731-fix parses inline shares as 3.x does; review fixes (#814) 88f3ee3 3.x.x: the 3.1.1 #731 runbook still proves listed rows; checker loads its share model lazily (#814) 36f0c92 3.x.x: --with-731-fix refuses up front without its share model; wording fixes (#814) 99ada68 Merge remote-tracking branch 'origin/3.x.x' into orca/814-docs-catch-up da36f25 3.x.x: the window-paging re-run starts from #241's commit, which holds the harness (#814) Co-Authored-By: Claude Opus 5.5 <[email protected]>
## Problem #814: after 3.1.1, several operator docs and the #731 parts-digest checker still described pre-3.1.1 behaviour. #819 shipped part of the fix; this PR does the rest. - The docs said every share append updates the cluster row, which stopped being true in #801. They gave that as the reason for the long-snapshot guidance and the backfill's 5 s cap. - The docs called the peer-sync prepared apply one transaction. Since #799 it runs in chunks. - The docs priced the share path at "ten statements and a ping", which #802 changed. - On 3.1.1, the checker reported `import_refuses` and exited 3 for 2.x v2 bodies that the import accepts. - Some references were already wrong in 3.1.0. ## The change **Cluster row (#801).** Each passage is now scoped to "while a frontend before 3.1.1 serves the database": - the files: prism-rust-migration.md, prism-ledger-ops.md (including the line next to the `/audit` routes) and the admission-gate comment; - the backfill's 5 s cap stays, explicitly as a conservative choice. The backfill can't tell which releases are serving, and a rolling upgrade mixes them; - MultiXact estimate: the clock `UPDATE`s left are the snapshot anchor's and the own-log floor's. A fenced append still locks the row `FOR SHARE` (032), so the MultiXact rate still grows with the share rate. **Prepared apply (#785/#799).** It is now described as chunks of at most 1,000 jobs and 2 MiB; a job whose blobs alone are larger goes in a chunk by itself. Each chunk is its own transaction under the cluster row's `FOR KEY SHARE`. - Files: prism-ledger-ops.md, prism-configuration.md, and the `config/dual_writer.rs` doc comment (comment only). - New peer-sync rows in the lock matrix and the lock-order table: prepared apply, and the own-log floor (SETTLEMENT → ORDER → cluster `NO KEY UPDATE`). **Share path (#802).** A share without a block takes three round trips and four statements: `BEGIN; SET LOCAL`, one call, `COMMIT`. A share that carries a block keeps the ten. **#731 checker.** `scripts/prism_legacy_parts_digest_check.py` gets an opt-in `--with-731-fix` mode, which models 3.1.1's import: - what it recomputes: 2.x's parts digest over the parts as 3.x parses them. That means known fields in declaration order with `kind` first, and inline shares in `AcceptedShare` form, using the sidecar tool's model. Non-ASCII is escaped; - statuses: `ok-in-3x` or `matches-neither`; - if `prism_legacy_range_sidecars.py` is not beside the checker, the mode refuses up front; - the default mode is byte-identical to before, with the same statuses, output and exit codes; - the docstring's "3.x refuses every 2.x v2 body" is corrected; - the #731 runbook gets a 3.1.1 command variant. **References.** - `/audit/latest-evidence` → `/audit/latest`. - Migration 17's refusals are no longer quoted as "migration 16". - The truncated native-collision quote is completed. - prism-alert-migration.md now says eight native rules page, with `critical` and `page: "true"`. - tests/perf/window_paging_allocation.md's re-run recipe starts from a worktree of #241's commit, which holds the harness that today's tree lacks. The image is built from 527b3ac's tree by path, since today's Dockerfile builds a different image. **#820 follow-up.** The `PrismAcceptedRevisionWorkTrackingUnknown` description now says an idle backup's unknown wait also ends when the block matures, if no authorized miner was connected since its acceptance. The text was changed at its source in `scripts/generate_prism_alerts.py`. The rule JSON, the migration doc tables and the qbit-tools patch were regenerated with `--snapshot` from the pinned qbit-tools a007a142 templates. ## Tests run (minidev-alex1) - `PRISM_AUDIT_CANONICALIZE_BIN=target/debug/qbit-prism-audit-canonicalize python3 -m unittest tests.test_prism_legacy_range_sidecars tests.test_prism_legacy_parts_digest_check tests.test_docs_lab_prism_references tests.test_prism_legacy_import_admission_gate`: OK (1 skipped). The canonicalizer was built with `cargo build --locked -p qbit-prism --bin qbit-prism-audit-canonicalize --bin qbit-prism-build-audit-bundle`. - New tests cover the fixed mode on both 2.x fixtures and on sorted-key and other digests. - They cover unknown keys, null bounds and escaping. - Inline-share variants are checked against the real canonicalizer: null `credit_policy`, an unknown key, reordered keys. - They check that the other statuses are unchanged, that `--jobs 3` parity holds, and that the checker runs when copied alone. - `python3 scripts/generate_prism_alerts.py --check`, `generate_prism_metrics.py --check`, `check_prism_settings.py`, `check_prism_alert_uids.py`, `check_gate_env_reads.py`: pass. - `python3 scripts/test_prism_alert_deployment.py --snapshot <qbit-tools a007a142 templates>`: patch applies, 10 Jinja gate combinations pass. - `cargo fmt --all -- --check`: pass. `cargo clippy --locked -p qbit-prism-server --all-targets -- -D warnings`: pass (only the 3 known vendored sqlx-core warnings). - `bash -n scripts/prism_legacy_import_admission_gate.sh`: pass. ## What CI must cover - the Python test shards; - `make test-prism-legacy-range-sidecars`, which uses the real canonicalizer; - the alert PromQL check with promtool, not run here (only a description changed); - the full Rust suites. No Rust code changed, only one doc comment. Refs #814 🤖 Generated with [Claude Code](https://claude.com/claude-code) Squashed commits: dea2d9a 3.x.x: operator docs and the #731 checker catch up with 3.1.1 (#814) 27bec61 Merge 3.x.x (3d48a8f) into the #814 branch: the backfill passage keeps #801's note and #824's SQLSTATE rule 1fe7fba Merge 3.x.x (582849b) into the #814 branch: the deployment patch is regenerated beside #843's listener rule Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fixes #785. Peer sync's
apply_preparedreused existing template and balance blobs without the cluster fence. The collector, which takes the cluster rowFOR UPDATEand deletes unreferenced blobs, could delete a blob between that reuse and the commit. The pulled job then committed without it (breaking D-19): a block the peer found on that job couldn't be adopted from this node. This affects dual writer only.What changes
apply_preparedtakesqbit_prism_cluster ... FOR KEY SHARE(the fencesave_compact_prepareduses) before it inserts or reuses blobs, and holds it to the commit. The lock order is unchanged: fence first, no advisory lock after it.Tests
dual_writer_sync28/28. It includes the collector interleavings, which fail on the base, a held pull not blocking a share append, the chunked apply resuming after a failed chunk, and the recovery skip.compact_issued_repair,compact_runtime_e2e, the dual-writer suites andledger_postgres253/253 all pass.Follow-up round (0cb0208)
apply_preparedreturnsResult<Applied, PreparedApplyError>, and the error carries the committed chunks'Appliedand the pending count. Recovery runsensure_progressbefore propagating, so a committed conflict surfaces as divergence (D-17), and lag counts only what is pending.🤖 Generated with Claude Code