Skip to content

Always report total rows to read for parallel replicas without a local plan - #128036

Open
groeneai wants to merge 3 commits into
ClickHouse:masterfrom
groeneai:fix-05325-pr-progress-total-rows
Open

groeneai wants to merge 3 commits into
ClickHouse:masterfrom
groeneai:fix-05325-pr-progress-total-rows

Conversation

@groeneai

@groeneai groeneai commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #127673
Related: #123928

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

With parallel replicas and parallel_replicas_local_plan = 0, query progress (for example X-ClickHouse-Summary) now always contains the total number of rows to read, also when some replicas are unavailable or receive no work.

Description

05325_parallel_replicas_progress_total_rows printed "read_rows":"1000000" "total_rows_to_read":"0" for its parallel_replicas_local_plan=0 arm in Stateless tests (amd_debug, parallel) on #127673 (requested there).

Without a local plan, the total comes only from the coordinator, which reported it through one stored progress callback. Every RemoteSource overwrote that callback, so it was always the last replica's, whichever replica announced. The total was buffered in that source and was lost when the source never ran again: in the CI log one replica took all marks and the other two were cancelled as unused right after Total rows to read: 1000000. With an unavailable last replica it is lost on every query.

The coordinator no longer stores a callback. RemoteQueryExecutor passes its own callback into handleInitialAllRangesAnnouncement, so the total is reported through the replica that announced, whose source is running and whose progress is collected right after. The initiator's local read passes none, as before.

The test gets an arm on test_cluster_1_shard_3_replicas_1_unavailable (no existing line changed).

Validation (debug build): with the unavailable replica, master reports 0 on 100/100 queries for both the count and the read-in-order arm, the fix 1000000 on 100/100. The extended test fails 50/50 on master and passes 50/50 with the fix (also with -j 8). In the CI shape (3 local replicas, 16 concurrent queries) master lost the total 3/3200, the fix 0/3200. The parallel-replicas, progress and read-limit tests show no failure with the fix that does not also occur on master in the same local setup.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/128036]

groeneai and others added 2 commits October 28, 2026 07:58
…ze sweep

Attempt of fix-plan r1: PipelineExecutor::finalizeExecution now calls
onProgress when a processor has only pending totals. It delivers the total
the parallel replicas coordinator buffered in a source that never runs
again (05325_parallel_replicas_progress_total_rows, local_plan=0), but it
also delivers the estimates of read-in-order FINAL layer sources that never
ran because LIMIT was satisfied, so 05325_read_in_order_final_virtual_row
fails with TOO_MANY_ROWS (max_rows_to_read = 3200). Kept only so PLAN can
choose the disposition; the test extension is independent of the mechanism.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ouncing replica

With `parallel_replicas_local_plan = 0` the coordinator is the only source
of the total rows to read. It reported the total through one stored
progress callback that every `RemoteSource` overwrote, so the total was
buffered in the source of the last replica, whichever replica announced.
If that source never ran again (the replica was unavailable, or it was
cancelled as unused because another replica took all marks), only the
executor's finalize sweep saw the buffered total, and the sweep does not
deliver totals-only progress, so the query reported no total
(`05325_parallel_replicas_progress_total_rows`, "total_rows_to_read":"0").

The coordinator no longer stores a callback. `RemoteQueryExecutor` passes
its own callback into `handleInitialAllRangesAnnouncement`, and the stream
coordinators report the total through it. The announcing replica's source
is running and its progress is collected after the current `work()`, so
the total is always delivered. The initiator's local read passes none and
keeps setting the total itself.

This also reverts the previous commit's change to the executor's finalize
sweep: delivering pending totals there also delivered the estimates of
sources that never ran because a LIMIT was reached early, which made
`05325_read_in_order_final_virtual_row` fail with TOO_MANY_ROWS.

The test gets an arm with an unavailable replica, where the total was
lost on every query.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 finding; plus my own review: 2 nits).

# Sev Finding Verdict Evidence / action
1 ⚠️ New arm uses enable_parallel_replicas=1, so it could pass after a silent fallback (05325_parallel_replicas_progress_total_rows.sh:35) DISAGREE No fallback applies (the >= 2 checks in Planner.cpp do not match these queries); master reports total 0 on 100/100 runs, impossible for an ordinary read.
2 💡 The first commit is a superseded attempt that the second one reverts DISAGREE In-tree rules forbid amend/rebase; the net diff does not touch PipelineExecutor.cpp.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-9:20261028-085900

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. parallel_replicas_local_plan = 0 on test_cluster_1_shard_3_replicas_1_unavailable: master reports total_rows_to_read 0 on 100/100 queries for the count and the read-in-order query.
b Root cause explained? The coordinator reported the total through one stored callback that every RemoteSource overwrote, so it was buffered in the last replica's source. When that source never ran again (unavailable, or cancelled as unused), the total was lost.
c Fix matches root cause? Yes. The total is reported through the callback of the replica that announced, whose source is running. The executor is unchanged.
d Test intent preserved / new tests added? Existing arms unchanged; new arm with an unavailable replica fails 50/50 on master, passes 50/50 with the fix.
e Both directions demonstrated? Yes: 100/100 zeros on master vs 100/100 1000000 with the fix; CI shape (3 local replicas, 16 concurrent queries) 3/3200 vs 0/3200.
f Fix is general across code paths? Both coordinator publishers (default and in-order modes) use the passed callback; the only remote caller passes its own, the local-plan callers pass none as before.
g Fix generalizes across inputs (params/datatypes/wrappers)? Measured for both coordination modes and for an unavailable replica and unused replicas. Not type-dependent.
h Backward compatible? (maintainer-approved exception only) Yes. No setting, protocol or format change; the coordinator lives on the initiator only.
i Invariants and contracts preserved? The same total is reported once per stream; the callback is still invoked under the coordinator mutex, now on the announcer's own thread into its own source.

Session id: cron:clickhouse-impl-slot-6:20261028-082300

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @nickitat @devcrafter, could you review this and add the can be tested label so CI runs? Without a local plan, the coordinator reported the total rows to read through one shared progress callback that each RemoteSource overwrote, so the total could be buffered in a replica source that never runs again; now RemoteQueryExecutor passes its own callback with the announcement.

@clickhouse-gh

clickhouse-gh Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [24d1674]

Summary: ✅


AI Review

Summary

Reviewed PR #128036 at 24d167499b67ba3a8e11726dde6711299c080e36. The change reports coordinator totals through the announcing replica's progress callback and extends coverage to an unavailable replica for both unordered and ordered reads. No actionable findings. The extended regression test passed 50/50 in pre-merge debug CI. Current-head CI is still running; no local build or tests were run during this review.

Final Verdict

Status: ✅ Approve. No changes requested.

@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements comp-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). labels Oct 28, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 28, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 407e49c

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Build profile diff infra, not from this PR: the CI logs cluster never passed the readiness probe, so the job ended with LogClusterNotReady: the endpoint never became ready before comparing anything #126200 (mine, open)
PR praktika rollup of the row above #126200 (the owner of the row above)

All five stateless flaky check builds passed with the extended 05325_parallel_replicas_progress_total_rows, and CH Inc sync is green. The earlier Config Workflow failures were the attempts before the can be tested label.

Session id: cron:our-pr-ci-monitor:20261028-183003

…ss-total-rows

# Conflicts:
#	src/Storages/MergeTree/ParallelReplicasReadingCoordinator.h
@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 24d167499 with master f30d7ec4f (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

130 translation units recompiled, 2094 s compile time in total, 130 of them have a recent master baseline.

Job report

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants