Repository navigation
3.x.x: bound the pool hashrate series' ledger reads at both ends, so no plan walks the ledger - #754
Merged
Conversation
…t at both ends, so it reads only their shares The rollup series re-reads the current bucket and the leading partial bucket from the ledger. Its filter wrote them as an OR, with a NULL guard on the range start, and neither bounds an index range. With the rollups current, the planner walks every share at or below the watermark and filters on accepted_at. On a production-sized ledger (66M shares) that is 19 s, past the public API's read deadline, so every pool hashrate-series request answered 504. 2.x built the same read with bounded predicates, so this is a 3.x regression. The boundary is now two disjoint slices, each bounded at both ends: the current bucket, and the leading partial bucket when the range has a start. Each is a range scan on qbit_share_ledger_accepted_recent_idx. On a 6M-share copy of a 2.x ledger migrated to the native schema, the default request takes 8 ms instead of 1,957 ms (generic plan) and 4 ms instead of 346 ms (custom plan). Its output was byte-identical to the old query's in 312 cases: every allowed range and bucket, pool and miner subjects, with and without smoothing context and an anchor, with the watermark current, lagging and missing. Two tests: - the rollup series must equal the raw ledger series in each of those cases, before the rollups run, at a current watermark and with shares past it; - under both plan modes, the pool chart may read at most 1,000 of 20,000 ledger shares. The old filter reads all 20,000. 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. |
…and check three request shapes in its plan test (review on #754) Review on #754. The first boundary slice kept an IS NULL test on the range start, the shape its own comment warned against. It still bounded an index range on the current bucket, but read as if it didn't. The second slice repeated bounds that the others already imply. Each slice now has one lower and one upper accepted_at bound. GREATEST and LEAST skip a NULL range start or first full bucket, and without a range start the second slice matches no row. The set of shares is unchanged. On the 6M-share copy, the output again matched rc.5's in the 312 cases, with the same plans: an accepted_recent_idx range per slice, 7.7 ms generic and 2.9 ms custom. The plan test now checks three request shapes under both plan modes: - the default pool request; - a 5-minute one, whose smoothing context widens the range and binds the anchor; - a miner's default request. It reads row counts as floats, since PostgreSQL 18 prints per-loop averages with decimals. It runs on a detached connection, so the prepared statement and the plan mode can't return to the pool. The identity test's share past the watermark now sits in a rolled bucket six days back, so the 7-day ranges keep it on a slow runner. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ence, so no plan walks the ledger for it (real-data test on #754) The tail re-reads the shares past the rollup watermark. Its only index-usable bound was share_seq > watermark. Its accepted_at range had the IS NULL test on the range start, and its miner test was an OR. On a production-sized ledger, under the generic plan, the planner walked p0's accepted_recent_idx by accepted_at <= ended_at alone, with share_seq as a filter: 66M index entries and 5.9M heap fetches for no row, 17 to 27 s. Under a custom plan with a miner it walked the miner's whole history through accepted_miner_history_idx. The tail's shares now come from a subquery that bounds share_seq on both sides, by the watermark and by the ledger's max(share_seq), which is one backward probe per partition. OFFSET 0 keeps the subquery's plan to that range. The time and miner tests then filter the stream, so the tail reads only the shares past the watermark. That's none when the rollups are current, and the lag while they catch up. On the 6M-share copy, with a 600k-share miner added, every request now runs in 1 to 17 ms under each condition tried: - generic, custom and auto plans (auto after 7 executions); - random_page_cost 4 and 1.1; - pool, small-miner and big-miner subjects, anchored or not. Before, at random_page_cost 1.1, the generic pool request took 381 ms and the big miner 161 to 176 ms. Output matched rc.5's in the 312 cases. The only differences were in unanchored cases, where the range start slid while the slower old query ran, and only in its leading bucket. The 20,000-share plan test missed this. Its planner, at PostgreSQL's default cost settings, happened to choose plans that read nothing. The production planner, with an SSD's random_page_cost, chose the walk. The test now covers: - a miner holding half the shares; - unanchored 7- and 30-day requests; - both random_page_cost values. It also checks plan shape as well as rows read: every ledger index scan outside a Limit probe must bound one column from both sides, and no sequential scan may read ledger rows. Against the previous commit it reports the one-sided tail in every plan mode, and the miner history walks. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…atermark too, and count recheck rows (review on #754) Review on #754. The plan test ran only with the rollups current, so the tail it checked was always empty. It now runs every plan again after 300 shares land past the watermark, half of them the big miner's. Each request may then read the lag as well as the partial buckets, and nothing more. The tail's cost follows the rollup lag, and the test pins that. Rows a lossy bitmap scan drops on its recheck now count as read, as they do in the fanout lane's plan test. The comment on the test's connection now says what ends it: the fixture's DROP DATABASE ... WITH (FORCE). The query is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…must see executed CI's "Prove every Rust PRISM gated test executed" failed. Two new api_2x tests ran but are missing from test/prism-gated-tests.txt: chart_rollups_match_raw_for_every_range_bucket_and_watermark and chart_rollups_read_only_the_partial_buckets_under_any_plan. Both are now listed, in order. Co-Authored-By: Claude Opus 5.5 <[email protected]>
RobertClarke
added a commit
that referenced
this pull request
Oct 8, 2026
Set VERSION and [workspace.package].version to 3.0.0-rc.6: rc.5 plus #754 (the pool hashrate series bounds both of its ledger reads, the boundary buckets and the tail past the rollup watermark, at both ends, fixing a 3.x regression that timed it out on large ledgers), #750 (#748: a failed record of 2 is re-checked on a fresh connection when its own one was lost, and each attempt is bounded on the client's side), and #753, a test-only fix for #724. Both Cargo.lock files move only their workspace-member entries. doc/release-notes-3.0.0-rc.6.md covers: - the changes, with #754's figures from its pull request (19 to 40 s and a 504 on a 66M-share ledger before, and 17 to 27 s with only the boundary fixed; 1 to 17 ms on a 6M-share copy after, under every plan mode and random_page_cost tried, with its output matching rc.5's; and on a production-sized ledger, 9 to 23 ms for the pool and 2 to 15 ms for miners in 20 of 20 runs, against rc.5's 15.8 to 25.2 s, with identical output), #750's lost connections, fresh read, client-side deadlines and two new stops, and #753's wait for current work; - upgrading: rc.6 adds no migration, capability, setting or script, so an upgrade from rc.5 and a rollback to it replace the binary only, at fence 2 too, and a database that rc.5's migrate migrated is served by rc.6 unchanged, which a cutover that pinned rc.5 can rely on. An upgrade from rc.4 or earlier is as in rc.5's notes, which the section links: migrate for 026, fence 2 and the deferred backfill, #738's snapshot rule and fatal-state clear --timeout-seconds; - the same evidence set as rc.5's, with the pair's serving evidence carried; - the known issues: rc.5's, with #748 fixed and #724's drill race and new-tip shares fixed on the test side (#747, #753), plus #752 after the cutover, #738's fix now planned after the cutover, and #739 not in this candidate. The development-line notes name 3.0.0-rc.6, and they and the 3.0.0 notes link all six candidates' notes. docs/prism-rust-migration.md names rc.5 where it said "this release" of serving at fence 2 and finishing the backfill. That is in three places: that every build before rc.5 refuses fence 2, that the starts of rc.5 and later accept it, and that only rc.5 and later finish a pending backfill. In this candidate's tree "this release" would have excluded rc.5, which does both. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's wrong
/public/v1/hashrate-seriesreads most buckets from the rollup tables. It re-reads two kinds of rows from the ledger:Neither read gave the planner an index range it could use:
accepted_atwith an OR,(accepted_at >= current_bucket OR accepted_at < first_full_bucket), plus a NULL guard on the range start,(started_at IS NULL OR accepted_at >= started_at).share_seqonly from below, by the watermark. It had the same NULL guard on time, and an OR on the miner.On a production-sized ledger (66M shares, rollup lag 0), the planner walked whole indexes:
range=1m,bucket=1h): 19–40 s. The boundary did an index-only scan ofqbit_share_ledger_p0_accepted_seq_walk_idxwithIndex Cond: (share_seq <= $8), removing 66,090,385 rows by filter to return 2,390.qbit_share_ledger_p0_accepted_recent_idxbyaccepted_at <= ended_atalone, filteringshare_seq > $12. That's 66M entries for 0 rows, 17–27 s.accepted_miner_history_idx.So pool hashrate-series requests ran past the public API's read deadline. PRISM answers those 503
read_timeout, and the proxy in front answered 504. Big miners' charts were slow too.This is a 3.x regression. 2.x builds the same read with bounded predicates (
lab/prism/share_ledger.pyon 2.x.x, e.g.accepted_at >= (SELECT range_started_at FROM range_buckets)).The fix
The changes are confined to
dashboard_hashrate_rollups.sql. It's read-only SQL in the public read path: no migration, no schema change, no write path.The boundary becomes a
UNION ALLof two disjoint slices. Each is bounded byaccepted_atat both ends, so each is a range scan onqbit_share_ledger_accepted_recent_idx, or on the miner index for a miner:[GREATEST(current_bucket, started_at), ended_at];[started_at, LEAST(first_full_bucket, current_bucket)), which is empty without a range start.GREATESTandLEASTskip a NULL range start or first full bucket.The tail takes its shares from a subquery bounded by
share_seqon both sides:share_seq > watermark AND share_seq <= max(share_seq), where the max is one backward probe per partition. The subquery is fenced byOFFSET 0, so the time and miner tests only filter its stream. It reads only the shares past the watermark: none while the rollups are current, the lag while they catch up.Measured
The test copy is a 2.x ledger migrated to the native schema, with 6M shares plus one 600k-share miner. Every request runs in 1–17 ms under all of these conditions:
random_page_cost4 and 1.1;Before the fix, at
random_page_cost1.1:The fixed query's output matched rc.5's in 104 cases per watermark state, 312 in all:
The only differences were in unanchored cases, where the range start slid during the slower old query. They fell only in the leading bucket, by one share.
By design, the tail's cost follows the rollup lag. With no progress row, which means the rollups have never run, it reads every share, as rc.5 did. The rollup lag metric is the thing to alarm on.
Not changed: the raw fallback,
dashboard_hashrate_series.sql, used only when the rollup tables are absent, still has an unbounded range start. Both the 2.x and the 3.x schemas have the rollup tables.Tests
chart_rollups_match_raw_for_every_range_bucket_and_watermarkchart_rollups_read_only_the_partial_buckets_under_any_planforce_custom_planandforce_generic_plan, atrandom_page_cost4 and 1.1. Every plan runs twice: once with the rollups current, then again after 300 shares land past the watermark.read 20000 of 20000 ledger shares). Against the boundary-only version it fails, flagging the tail'sIndex Cond: (share_seq > $12)in every mode and the big miner's history walk.Run locally against PostgreSQL 16:
api_2x(7),api_contract(6) andapi_database(2) all pass.cargo fmt --checkandclippy --all-targets -D warningsare clean.🤖 Generated with Claude Code