Skip to content

Cherry pick #125801 to 26.9: Parallel replicas followers follow the initiator whatever their own automatic_parallel_replicas_mode - #129267

Merged
robot-clickhouse-ci-2 merged 5 commits into
backport/26.9/125801from
cherrypick/26.9/125801
Nov 11, 2026
Merged

robot-clickhouse-ci-2 merged 5 commits into
backport/26.9/125801from
cherrypick/26.9/125801

Conversation

@robot-clickhouse

Copy link
Copy Markdown
Member

Original pull-request #125801

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 4 commits October 14, 2026 12:34
…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 (#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 #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]>
…-automatic-mode

Parallel replicas followers follow the initiator whatever their own `automatic_parallel_replicas_mode`
@robot-clickhouse robot-clickhouse added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request labels Nov 4, 2026
@groeneai

groeneai commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

The conflict is in code that does not exist on 26.9: #125801 edits Context::isParallelReplicasEnabled, getAutomaticParallelReplicasMode and canUseTaskBasedParallelReplicasImpl, which came with #122306, and #122306 is not on 26.9. I applied the change to the 26.9 shape of the same two places instead: Context::canUseTaskBasedParallelReplicas no longer requires automatic_parallel_replicas_mode = 0 on a follower, and buildContext in InterpreterSelectQueryAnalyzer.cpp no longer switches enable_parallel_replicas off on a follower. On 26.9 that block turns parallel replicas off whenever the automatic mode is not zero, so the first change alone does not fix anything. The Context.h comment edits of #125801 describe #122306 code and are not taken. Against backport/26.9/125801 the merge changes only Context.cpp, InterpreterSelectQueryAnalyzer.cpp and one comment in InterpreterInsertQuery.cpp, and adds the test byte-identical to master.

On the 26.9 tree (clang-22, debug) test_parallel_replicas_feature_tier passes 10 of 10. Without the change it fails: the INSERT SELECT writes 300000 rows instead of 100000, and every group of the SELECT is counted 3 times. test_parallel_replicas_insert_select passes.

I cannot push to cherrypick/26.9/125801. The merge is on my fork and its first parent is this PR's head c0db9e824202, so applying it is a fast-forward:

git fetch https://github.com/groeneai/ClickHouse.git groeneai/resolve-26.9-cherrypick-125801
git push origin FETCH_HEAD:cherrypick/26.9/125801

@robot-clickhouse

Copy link
Copy Markdown
Member Author

Dear @nickitat, @groeneai, this cherry-pick PR has not been updated for 3d0h4m22s. Please resolve the conflicts to backport #125801, or close this PR if the backport is no longer needed. This PR will be automatically closed after 7 days of inactivity.

@nickitat

Copy link
Copy Markdown
Member

@copilot resolve the merge conflicts in this pull request

… into cherrypick/26.9/125801

# Conflicts:
#	src/Interpreters/Context.cpp
#	src/Interpreters/Context.h
#	src/Interpreters/InterpreterSelectQueryAnalyzer.cpp

Co-authored-by: nickitat <[email protected]>
@cla-assistant

cla-assistant Bot commented Nov 11, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ nickitat
✅ groeneai
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

@robot-clickhouse-ci-2
robot-clickhouse-ci-2 merged commit f447efc into backport/26.9/125801 Nov 11, 2026
1 of 2 checks passed
@robot-clickhouse-ci-2
robot-clickhouse-ci-2 deleted the cherrypick/26.9/125801 branch November 11, 2026 23:43

Copilot AI commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

🕵 Resolved the 26.9 conflicts in merge commit 6bf8f33d1f; the backport PR has merged.

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

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants