Repository navigation
Keep the population of a Replicated database DDL entry on the replica that executes it - #124477
Conversation
… that executes it Every replica of a `Replicated` database executes a `CREATE` entry and fills its own copy of the table, and such a `CREATE` always takes the non-atomic population (`shouldPopulateMaterializedViewAtomically` refuses the atomic path under a ZooKeeper metadata transaction). `fillTableIfNeeded` built that `INSERT ... SELECT` with the entry's own context, i.e. with the user's parallel-replicas settings, so `InterpreterInsertQuery` sent `INSERT INTO <table> SELECT ...` to every replica of `cluster_for_parallel_replicas` (`parallel_distributed_insert_select` defaults to 2) and the `SELECT` read through parallel replicas. A replica's rows landed in other replicas' tables (duplicated there, missing locally), or the remote INSERT failed with `UNKNOWN_TABLE` where the table did not exist yet; for `CREATE TABLE ... AS SELECT` the other replicas' DDL workers failed on the already renamed `_tmp_replace_*` table until they were recovered as lost replicas with an empty table. Under a ZooKeeper metadata transaction the population now uses a context copy with `parallel_distributed_insert_select = 0` and `enable_parallel_replicas = 0`, and both settings (plus the `allow_experimental_parallel_reading_from_replicas` alias) are removed from the copied `SELECT`, because its own `SETTINGS` are reapplied on top of the context; `removeSettingsFromQuery` also drops the `name = DEFAULT` form, which would restore the default 2. This is what the atomic `POPULATE` path already does. The single site covers `POPULATE`, `CREATE OR REPLACE ... POPULATE` and `CREATE TABLE ... AS SELECT`; the view's stored definition is unchanged, as only the clone is scrubbed. Reported by @ fm4v from 04494_atomic_populate_materialized_view_parallel_replicas in the DBReplicated lane, where every replica of the CI cluster points at the primary server. Test: 4 cases in `test_parallel_replicas_insert_select` (secondaries populating through the only live replica, the initiator populating before the other replicas created the view, CTAS into `Memory`, and the read side with different data per replica, with parallel replicas also enabled by the view's own `SETTINGS`), all failing on master and on 26.8.18.2. Closes ClickHouse#124446 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; round 1: 2 findings, round 2: 0 findings) plus my own review in both rounds.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261007-190500 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261007-183004 |
|
Workflow [PR], commit [8ad579d] Summary: ✅
AI ReviewSummaryThis PR keeps Final Verdict
LLVM Coverage ReportMeasured on commit 8ad579d.
Changed lines: Changed C/C++ lines covered: 17/17 (100.00%) · Uncovered code |
|
📊 Cloud Performance Report ✅ AI verdict: This PR only changes InterpreterCreateQuery::fillTableIfNeeded, the code that fills a table after CREATE ... AS SELECT or POPULATE. When that runs in a Replicated database, it now turns off parallel replicas and parallel_distributed_insert_select. None of the read-only SELECTs in clickbench or tpch_adapted_1_official run this code. The only flagged query, clickbench Q31 (-10.4%, 297 ms to 266 ms), was correctly kept as no change: it falls inside master's current range of run times and CPU time barely moved. Nothing in this run suggests a performance effect from the PR. clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
2e77cbc
Backport #124477 to 26.9: Keep the population of a Replicated database DDL entry on the replica that executes it
Resolve the cherry-pick of #124477 onto 26.8. The only conflict is context: on master the new settings list sits above fillTableIfNeeded, whose signature #117967 changed (published_table_name); 26.8 keeps its own signature (skip_target_insert_access_check), so the resolution adds only the lines #124477 adds and does not bring #117967 along. The test files merged cleanly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry pick #124477 to 26.8: Keep the population of a Replicated database DDL entry on the replica that executes it
…e DDL entry on the replica that executes it
Backport #124477 to 26.8: Keep the population of a Replicated database DDL entry on the replica that executes it
The bugs behind their `no-parallel-replicas` / `no-replicated-database` tags are fixed on master: - `01660_join_or_any`: ClickHouse#123683 - `04653_bloom_filter_fixed_string_constant_scalar`: ClickHouse#118988 - `04819_dynamic_aggregate_function_state_version`: ClickHouse#123649 - `04825_quantile_deterministic_alter_add_modify_column`: ClickHouse#115393, ClickHouse#123070 - `04494_atomic_populate_materialized_view_parallel_replicas`: ClickHouse#124477 - `04266_text_index_tokens_cardinality_order`: ClickHouse#124500 already disables parallel replicas for the log-checked query Related: ClickHouse#124015
…e DDL entry on the replica that executes it
Closes: #124446
Related: #123790
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
CREATE MATERIALIZED VIEW ... POPULATEandCREATE TABLE ... AS SELECTin aReplicateddatabase with parallel replicas enabled: each replica sent its population to other replicas, so its rows landed in other replicas' tables (duplicated there, missing on the replica itself), or the query failed withUNKNOWN_TABLE. The population now ignores the query's parallel replicas andparallel_distributed_insert_selectsettings, so each replica fills only its own table. Closes #124446.Description
On 26.8.18.2,
CREATE MATERIALIZED VIEW ... POPULATEin a 3-replicaReplicateddatabase withenable_parallel_replicas = 1and acluster_for_parallel_replicasthat reaches one replica (the shape of the CI failure in #124446) leaves every source row three times in that replica's view and no rows in the other two. With the database's own cluster, theCREATEcan fail withUNKNOWN_TABLE.Every replica of a
Replicateddatabase executes theCREATEentry and fills its own copy of the table with the non-atomic population (fillTableIfNeeded). ThatINSERT ... SELECTran with the entry's settings, so it was sent asINSERT INTO <table> SELECT ...to the replicas ofcluster_for_parallel_replicas(parallel_distributed_insert_select = 2is the default) and read through parallel replicas.The fix: for a
CREATEexecuted as aReplicateddatabase entry, the population runs withparallel_distributed_insert_select = 0andenable_parallel_replicas = 0, and these settings (with the alias) are removed from the copiedSELECT'sSETTINGS, as the atomicPOPULATEpath already does.4 new cases in
test_parallel_replicas_insert_selectfail on master and on 26.8.18.2, and pass with the fix.04494_atomic_populate_materialized_view_parallel_replicasis unchanged: itsno-replicated-databasetag comes from #123790, not merged yet. #120775 (open) keeps anINSERT ... SELECTon the initiator when the target does not replicate; it does not cover the read side.Workflow [PR]
Sync PR [sync-upstream/pr/124477]
Version info
26.10.1.2002-master(included in26.10and later)26.9.15.8