ClickHouse cluster mode runs CREATE ... AS SELECT on every replica
维护者通常 4 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 67/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 冷清
- 技术栈
- clickhouse, python
调研方向
从 sqlmesh/core/engine_adapter/clickhouse.py 开始,阅读 ClickhouseEngineAdapter._create_table 以及 issue 中确定的两个 Cloud-only 门控。检查 ClickHouse 适配器测试对 Cloud 和集群运行模式的覆盖情况,然后运行相关测试。完成意味着集群模式使用 empty-CTAS 和单节点插入路径,同时现有 Cloud 行为仍保持覆盖。
由索引模型根据 Issue 内容生成。
描述
Summary
In self-hosted ClickHouse cluster mode (cluster: set on the gateway, non-Cloud), SQLMesh materializes full-refresh / CTAS models with a single CREATE TABLE … AS SELECT … ON CLUSTER <cluster>. Because the statement is ON CLUSTER, every replica executes the whole statement — SELECT and INSERT included. On an N-replica cluster this causes:
- N× the source reads/compute for one result (each replica independently re-scans the same upstream source).
- Deadlock/failure under
insert_quorum > 0: the N concurrent quorum inserts never reach a clean quorum, so each blocks forinsert_quorum_timeout(default 600s) and then fails withCode 319 UNKNOWN_STATUS_OF_INSERT, rolling the new table back to 0 rows. - The long CTAS occupies the distributed-DDL queue for its whole duration, head-of-line-blocking every other
ON CLUSTERoperation cluster-wide.
ClickHouse Cloud mode already avoids this: it creates the table EMPTY (schema only) then runs a plain single-node INSERT … SELECT that ReplicatedMergeTree replicates. Self-hosted cluster mode should do the same.
Root cause
In sqlmesh/core/engine_adapter/clickhouse.py, ClickhouseEngineAdapter._create_table, both the empty-CTAS split and the follow-up single-node insert are gated on engine_run_mode.is_cloud:
empty_ctas=(self.engine_run_mode.is_cloud and expression is not None),
...
if (self.engine_run_mode.is_cloud and table_kind != "VIEW" and expression and not (<limit 0>)):
self._insert_append_query(table_name, expression, ...)
So cluster mode falls through to a full CREATE … AS SELECT ON CLUSTER.
Suggested fix
Broaden those two gates to is_cloud or is_cluster, so cluster mode also does empty-CREATE + single-node INSERT … SELECT and lets ReplicatedMergeTree replicate the parts. (A single writer is also fine under insert_quorum > 0 — it just waits for one peer to confirm, the normal path.)
Verified with a local monkeypatch broadening those gates: the build then did NewPart on one replica + DownloadPart on the others, produced the correct row count consistent across all replicas, read the source once, and no longer hit Code 319.
Possibly related: #5785.
Environment
- SQLMesh 0.236.1
- Self-hosted ClickHouse cluster, 1 shard × 4 replicas,
ReplicatedMergeTree - Gateway:
type: clickhousewithcluster:set - Server-side
insert_quorum = 2,insert_quorum_timeout = 600000
Reproduction
- Gateway in cluster mode (
cluster:set), models stored asReplicatedMergeTree, server-sideinsert_quorum >= 2. - Run a full-refresh model whose query reads from an external source.
- Observe via
clusterAllReplicas('…','system.processes'): the SELECT pipeline runs on all replicas; afterinsert_quorum_timeoutthe CREATE fails withUNKNOWN_STATUS_OF_INSERT(code 319) and the table is left empty.
- 主要语言
- Python
- 星标
- 3.3k
- 派生
- 471
- 平均合并
- 6 天 7 小时
- 30 天内合并 PR
- 35
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
SQLMesh/sqlmesh 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 86/100
维护者通常 4 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 4 天内回复
-
VSCode Extension: SQLMesh LSP crashes on startup: ImportError: cannot import name 'WorkspaceDiagnosticRefreshRequest' with lsprotocol 2025.x可能已有人在做 @boomesh11 于 15 天前认领。 未关闭Bug
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 4 天内回复
-
Improvement
难度 1/5 1 小时以内 新手友好度 85/100
SQLMesh/sqlmesh#5696 · 6 条评论 ·
维护者通常 4 天内回复
-
Support pg_lake未关闭Feature Improvement
难度 2/5 1-3 小时 新手友好度 70/100
SQLMesh/sqlmesh#5669 · 1 条评论 ·
维护者通常 4 天内回复
相似的 Issue
-
accepted
难度 2/5 1-3 小时 新手友好度 67/100
future-agi/future-agi#5274 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
GenericMappingTools/pygmt#5014 · 1 条评论 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 66/100
w3c/feedvalidator#204 ·
-
[BUG][Low–Medium] founder_numbers.py silently reads a SAFE discount or pool target given as a fraction (0.2) as 0.2%可能已有人在做 @sumitkhond111-del 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 72/100
bmad-code-org/BMAD-METHOD#3358 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 86/100
open-mmlab/mmcv#3352 ·