Skip to content

Run lightweight UPDATE ON CLUSTER on one replica per shard - #122393

Merged
fm4v merged 3 commits into
ClickHouse:masterfrom
protomn:fix-update-on-cluster-replicas
Sep 30, 2026
Merged

fm4v merged 3 commits into
ClickHouse:masterfrom
protomn:fix-update-on-cluster-replicas

Conversation

@protomn

@protomn protomn commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #122285
Related: #115287

DDLWorker::taskShouldBeExecutedOnLeader sends ALTER, OPTIMIZE, TRUNCATE, index DDL and, since #115287, DELETE to one replica per shard, but not UPDATE. A lightweight UPDATE ... ON CLUSTER on a ReplicatedMergeTree table therefore ran on every replica of a shard. Each run reads the patch part written by the previous run and writes a new one, so an assignment that isn't idempotent, such as SET v = v + 1, was applied once per replica.

On a shard with two replicas, 100 became 102. A replica that was down when the entry was queued applied it again after it started. A plain UPDATE in a Replicated database with more than one shard goes through the same DDLWorker code and had the same problem.

This PR adds ASTUpdateQuery to that list. The existing supportsReplication check still makes the update run on every host for tables that don't replicate, such as plain MergeTree.

All supported release branches (26.3, 26.7, 26.8, 26.9) are affected. On those branches, DELETE ... ON CLUSTER with lightweight_delete_mode = 'lightweight_update' is rewritten into UPDATE ... ON CLUSTER, so the backport fixes that path too.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fixed lightweight UPDATE ... ON CLUSTER on ReplicatedMergeTree tables running on every replica of a shard instead of once per shard, which applied assignments such as SET v = v + 1 once per replica. A plain UPDATE in a Replicated database with more than one shard had the same problem.


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

Version info

  • Merged into: 26.10.1.1054-master (included in 26.10 and later)

@clickhouse-gh clickhouse-gh Bot added comp-ddl DDL command coordination and execution (ON CLUSTER, DDL queue). external Author is not a member of the ClickHouse organization labels Sep 26, 2026
@protomn

protomn commented Sep 28, 2026

Copy link
Copy Markdown
Contributor Author

cc @zlareb1 could this please be tagged can be tested?

@zlareb1 zlareb1 added the can be tested Allows running workflows for external contributors label Sep 28, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0a1347c]

Summary: ✅


AI Review

Summary

This PR fixes the UPDATE ... ON CLUSTER routing gap for lightweight UPDATE queries on replicated tables by sending ASTUpdateQuery through the same single-replica-per-shard path already used for replicated ALTER, DELETE, OPTIMIZE, and TRUNCATE. I did not find a remaining correctness gap in the current code: the direct ON CLUSTER path, the multi-shard Replicated database path, the non-replicated fallback, and the delayed-replica replay case are all covered by the implementation and by the new integration tests.

Final Verdict

✅ No findings.

LLVM Coverage Report

Measured on commit 0a1347c.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 79.50% 79.50% +0.00%

Changed lines: Changed C/C++ lines covered: 11/11 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 28, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 0a1347c15 with master e57232c33 (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

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

Job report

@protomn

protomn commented Sep 28, 2026

Copy link
Copy Markdown
Contributor Author

cc @zlareb1 i think this is good to be added to the merge queue

@fm4v
fm4v added this pull request to the merge queue Sep 30, 2026
pull Bot pushed a commit to Mu-L/ClickHouse that referenced this pull request Sep 30, 2026
All three fail the main pass of every `Stateless tests (*, s3 storage,
DBReplicated, sequential*)` run. On master this is hidden: the diagnostics
rerun drops `--replicated-database`, the rerun passes, and llvm_coverage jobs
report `flaky` as `OK` (340/340, 340/340 and 129/129 whitewashed rows in
7 days, 0 clean, 0 red). They are visible on the new lane of ClickHouse#122853:
https://github.com/ClickHouse/ClickHouse/actions/runs/36622581675/job/109632143373

05229 and 05230 edit one replica's ZooKeeper nodes by the table's literal
path. A Replicated database rewrites explicit engine arguments without
macros to `<path>/auto_{shard}` and `<replica>auto_{replica}`
(`_functional_tests_helper_database_replicated_replace_args_macros`), so the
`rm`/`ls`/`create` calls print `No node` and every assertion reads 0. Every
arm depends on that path, so both files get `no-replicated-database`, like
the other tests that edit a table's nodes by a literal path.

05260 filters `system.query_log` with `log_comment LIKE '05260\_%'`, which
also matches the test's default log comment. Under a Replicated database the
DDL worker replays `CREATE TABLE t_dist_pd` as a secondary query carrying
that comment, which adds one row. The filter now lists the three log comments
the test sets, as `05104_distributed_ast_push_down_under_not` does.

04741_cancel_skip_index_marks_remote_read fails on the same lane because a
lightweight `UPDATE` runs on every replica of a shard (ClickHouse#122285). ClickHouse#122393
fixes that, so the test is not touched here.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged via the queue into ClickHouse:master with commit 4063c6f Sep 30, 2026
176 checks passed
@protomn
protomn deleted the fix-update-on-cluster-replicas branch September 30, 2026 09:30
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 30, 2026
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-ddl DDL command coordination and execution (ON CLUSTER, DDL queue). external Author is not a member of the ClickHouse organization pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lightweight UPDATE ... ON CLUSTER executes on every replica of a shard, applying a non-idempotent assignment more than once

4 participants