Repository navigation
Parallel replicas followers follow the initiator whatever their own automatic_parallel_replicas_mode - #125801
Conversation
…utomatic_parallel_replicas_mode `Context::canUseTaskBasedParallelReplicas` requires `automatic_parallel_replicas_mode == 0`, and `canUseParallelReplicasOnFollower` is that predicate plus `collaborate_with_initiator`. The initiator ships `automatic_parallel_replicas_mode = 0` to its followers, but the value does not always arrive: - under `allow_feature_tier = 1`, `TCPHandler::receiveQuery` applies a secondary query's settings through `clampToSettingsConstraints`, which silently drops the change of this EXPERIMENTAL setting, so the follower keeps the mode from its profile; - the INSERT's own `SETTINGS automatic_parallel_replicas_mode = 2` is part of the shipped query text and is re-applied on the follower (ClickHouse#121734). Such a follower refused to collaborate and read its whole table. A SELECT is saved by the coordinator cancelling unused replicas once every range is assigned, at the cost of N times the work; a distributed INSERT SELECT has no such cancel, so every follower inserted its whole source table again (3x rows on a 3-replica cluster). The automatic mode is a decision of the initiator. On a follower `canUseTaskBasedParallelReplicas` now ignores it (the private impl's flag already exists for cluster engines), and so does `isParallelReplicasEnabled`, so every follower-side answer equals the answer for mode 0, i.e. what it already was when the shipped value arrived. Changing the base predicate, not only `canUseParallelReplicasOnFollower`, keeps the follower-side direct callers (planner checks, view metadata propagation) consistent within one query. Initiator contexts are unchanged. New integration test `test_parallel_replicas_feature_tier`: a distributed INSERT SELECT (300000 rows instead of 100000 before the change) and the heuristic SELECT with unused replicas kept alive by `parallel_replicas_wait_for_unused_replicas` (every group counted 3 times before the change). Closes ClickHouse#125757 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ture_tier The row count alone is also satisfied when the INSERT SELECT falls back to the local pipeline (`buildInsertSelectPipelineParallelReplicas` returning nothing), so the test would keep passing without any follower having run. Count the non-initial `Insert` queries of the INSERT in `system.query_log` on all replicas: node1 runs its share in the local plan, node2 and node3 run the shipped INSERT. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Condense the follower comment in Context::canUseTaskBasedParallelReplicas to one line. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 rounds, 2 findings) plus my own cold review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261014-131600 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261014-111300 |
|
Workflow [PR], commit [2be9c18] Summary: ✅
AI ReviewSummaryPR #125801, reviewed at Missing context / blind spots
Final Verdict✅ Approve. No code changes requested; CI validation remains pending. |
|
cc @nickitat @devcrafter, could you review this? A follower whose own |
|
@groeneai, would this change be necessary when we promote automatic_parallel_replicas_mode to the production tier? |
|
Only partly. The promotion removes the
A narrower alternative after the promotion is to strip |
c0db9e8
Backport #125801 to 26.10: Parallel replicas followers follow the initiator whatever their own `automatic_parallel_replicas_mode`
…LECT The parser copies the SELECT's trailing `SETTINGS` into the INSERT's own `settings_ast`, and `executeInsertSelectWithParallelReplicas` shipped that copy unchanged. Stripping only `query.select` left `automatic_parallel_replicas_mode = 2` in the query text every follower receives. A follower that predates #125801 re-applies it over the shipped 0, reads the whole source table instead of its share, and inserts every row again, so in a mixed-version cluster the previous commit would turn a local but correct insert into row duplication. Remove `automatic_parallel_replicas_mode` and `parallel_replicas_plan_based` from the top-level `SETTINGS` carriers of the cloned query before formatting it. The clone is deep, so the user's INSERT is not changed. This also covers the setting written in the INSERT's own `SETTINGS` clause. The test now checks that no follower receives the setting in its query text. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… SELECT settings `buildInsertSelectPipelineParallelReplicas` pins `automatic_parallel_replicas_mode = 0` on its context so that a distributed INSERT SELECT uses parallel replicas regardless of the automatic mode. The suitability probe (`isSuitableForInsertSelectWithParallelReplicas`) builds the SELECT with `InterpreterSelectQueryAnalyzer`, which re-applies the SELECT's own `SETTINGS` clause on top of that context, so `INSERT INTO t SELECT ... SETTINGS automatic_parallel_replicas_mode = 2` brought the mode back, the probe found no parallel replicas read and the insert silently ran on the initiator alone. Strip the setting from the SELECT's top-level `SETTINGS` together with `parallel_replicas_plan_based`, which had the same problem and was fixed the same way. `execute` restores `query.select` afterwards. The new test also covers the setting in the INSERT's own `SETTINGS` clause, which made every replica insert the whole source table until ClickHouse#125801. Closes: ClickHouse#121734 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n followers too A `*Cluster` worker executing a forwarded INSERT SELECT has `collaborate_with_initiator` set, so after ClickHouse#125801 `canUseParallelReplicasOnFollower` is true even when the initiator runs with `automatic_parallel_replicas_mode = 1`. The insert part kept parallel replicas on because it was disabled only under `canUseParallelReplicasOnInitiator`, so a materialized view that joins a MergeTree table started a coordinated read, and the initiator threw `Coordinator for parallel reading from replicas is not initialized`. With mode 0 the same query failed before ClickHouse#125801 as well. Gate on `canUseTaskBasedParallelReplicas` in `addInsertToSelectPipeline` and `buildInsertPipeline`, so the insert part never uses parallel replicas, wherever it runs. ClickHouse#126127 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry pick #125801 to 26.9: Parallel replicas followers follow the initiator whatever their own `automatic_parallel_replicas_mode`
…iator whatever their own `automatic_parallel_replicas_mode`
Backport #125801 to 26.9: Parallel replicas followers follow the initiator whatever their own `automatic_parallel_replicas_mode`
…iator whatever their own `automatic_parallel_replicas_mode`
Closes: #125757
Related: #121734
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A replica that takes part in a parallel replicas read now follows the initiator even when its own
automatic_parallel_replicas_modeis not 0, for example whenallow_feature_tierdrops the value the initiator sends, or whenINSERT ... SETTINGS automatic_parallel_replicas_mode = 2 SELECTre-applies it on the replica. Previously such a replica read its whole table on its own, so a query could count rows more than once and a distributedINSERT SELECTwrote them once per replica.Description
With
allow_feature_tier = 1andautomatic_parallel_replicas_mode = 1in the users profile, a query switched to parallel replicas was read in full by every replica: only the initiator registered at the coordinator, and each follower ran the shipped query uncoordinated over its whole table. Its result was merged into the answer whenever it arrived before the initiator cancelled it, and a distributedINSERT SELECThas no such cancel, so every follower inserted the whole source again.The initiator ships
automatic_parallel_replicas_mode = 0to its followers, but underallow_feature_tier = 1a replica drops the shipped change of thisEXPERIMENTALsetting (clampToSettingsConstraintson a secondary query), and #121734'sINSERT ... SETTINGSclause re-applies a non-zero value on the follower.Context::canUseTaskBasedParallelReplicasrequires the mode to be 0, so the follower refused to collaborate.The automatic mode is a decision of the initiator. On a follower (
collaborate_with_initiator)canUseTaskBasedParallelReplicasandisParallelReplicasEnablednow ignore it, so the follower answers exactly as it does when the shipped 0 arrives. Initiators are unchanged; no setting or protocol change.Validation on a 3-node cluster (20M rows): base read 50.6M rows on the initiator with followers
ParallelReplicasReadMarks = 0; with the fix 20M rows, 3 replicas used.INSERT SELECTof 1M rows wrote 3M on base and 1M with the fix, for both the tier vector and #121734's vector. The new integration test fails on base and passes 10/10 with the fix. #121734's second shape (the probe declining for the setting in the SELECT's trailingSETTINGS) is not touched here.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/125801]
Version info
26.10.1.2509-master(included in26.10and later)26.10.2.3