ClickHouse cluster mode runs CREATE ... AS SELECT on every replica
Maintainer thường phản hồi trong vòng 4 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 67/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- clickhouse, python
- Lĩnh vực
- data-engineering, databases
Hướng nghiên cứu
Bắt đầu từ sqlmesh/core/engine_adapter/clickhouse.py, đọc ClickhouseEngineAdapter._create_table và hai Cloud-only gates được xác định trong issue. Kiểm tra các bài kiểm tra của bộ điều hợp ClickHouse để xem độ phủ của các chế độ thực thi Cloud và cluster, sau đó chạy các bài kiểm tra liên quan. Hoàn thành nghĩa là chế độ cluster sử dụng đường dẫn empty-CTAS và đường dẫn chèn nút đơn, trong khi hành vi Cloud hiện tại vẫn được bao phủ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 3.3k
- Fork
- 471
- Merge trung bình
- 6 ngày 7 giờ
- Pull request đã merge (30 ngày)
- 35
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của SQLMesh/sqlmesh
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 4 ngày
-
VSCode Extension: SQLMesh LSP crashes on startup: ImportError: cannot import name 'WorkspaceDiagnosticRefreshRequest' with lsprotocol 2025.xCó thể đã có người làm @boomesh11 đã nhận 15 ngày trước. Đang mởBug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 4 ngày
-
Improvement
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
SQLMesh/sqlmesh#5696 · 6 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Support pg_lakeĐang mởFeature Improvement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
SQLMesh/sqlmesh#5669 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
Tất cả issue của SQLMesh/sqlmesh
Issue tương tự
-
[BUG][Low–Medium] founder_numbers.py silently reads a SAFE discount or pool target given as a fraction (0.2) as 0.2%Có thể đã có người làm @sumitkhond111-del đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
bmad-code-org/BMAD-METHOD#3358 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
open-mmlab/mmcv#3352 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
OpenGithubs/weekly#263 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
comp/cli P3 type/feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
NousResearch/hermes-agent#162784 ·
Maintainer thường phản hồi trong vòng 1 ngày