问题描述
尝试在 k8s 上部署 clickhouse 以用作石墨后端。 Clickhouse 的新手我已经浏览了具有相同问题的链接,但没有一个对我有帮助。尝试创建两台 clickhouse 服务器,计划在未来再添加一台。clickhouse 服务器部署为 k8 statefulset。
clickhouse1-0.clickhouse1-hs.ns-vaggarwal.svc.cluster.local :) select * from graphite
SELECT *
FROM graphite
Query id: 7ba316b8-bc88-4ab2-83d2-269a990f93b7
Received exception from server (version 20.12.4):
Code: 306. DB::Exception: Received from localhost:9000. DB::Exception: Stack size too large. Stack address: 0x7fd2d75fe000,frame address: 0x7fd2d79fd3f0,stack size: 4197392,maximum stack size: 8388608.
0 rows in set. Elapsed: 0.044 sec.
clickhouse1-0.clickhouse1-hs.ns-vaggarwal.svc.cluster.local :) exit
我正在使用的示例 init.sql。
CREATE TABLE IF NOT EXISTS default.graphite_index
(
Date Date,Level UInt32,Path String,Version UInt32,updated DateTime DEFAULT Now(),status Enum8('SIMPLE' = 0,'BAN' = 1,'APPROVED' = 2,'HIDDEN' = 3,'AUTO_HIDDEN' = 4)
)
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/single/default.graphite_index','{replica}',updated)
PARTITION BY toYYYYMM(Date)
ORDER BY (Path)
SETTINGS index_granularity = 1024;
CREATE TABLE IF NOT EXISTS default.graphite (
Path String CODEC(ZSTD(2)),Value Float64 CODEC(Delta,ZSTD(2)),Time UInt32 CODEC(Delta,Date Date CODEC(Delta,Timestamp UInt32 CODEC(Delta,ZSTD(2))
) ENGINE = distributed('graphite','',graphite,xxHash64(Path));
CREATE DATABASE IF NOT EXISTS shard_01;
CREATE TABLE IF NOT EXISTS shard_01.graphite
AS default.graphite
ENGINE = ReplicatedGraphiteMergeTree('/clickhouse/tables/01/graphite','clickhouse1-0','graphite_rollup')
PARTITION BY toYYYYMM(Date)
ORDER BY (Path,Time);
CREATE DATABASE IF NOT EXISTS shard_02;
CREATE TABLE IF NOT EXISTS shard_02.graphite
AS default.graphite
ENGINE = ReplicatedGraphiteMergeTree('/clickhouse/tables/02/graphite',Time);
config.xml 中的相关部分
<remote_servers>
<graphite>
<!-- Shard 01 -->
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>clickhouse1-0</host>
<port>9000</port>
</replica>
<replica>
<host>clickhouse2-0</host>
<port>9000</port>
</replica>
</shard>
<!-- Shard 02 -->
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>clickhouse1-0</host>
<port>9000</port>
</replica>
<replica>
<host>clickhouse2-0</host>
<port>9000</port>
</replica>
</shard>
</graphite>
</remote_servers>
度量路径已编入索引。
clickhouse1-0.clickhouse1-hs.ns-vaggarwal.svc.cluster.local :) show tables
SHOW TABLES
Query id: 8cc91a1f-0be1-4ae8-98ed-411b06624968
┌─name───────────┐
│ graphite │
│ graphite_index │
└────────────────┘
2 rows in set. Elapsed: 0.002 sec.
clickhouse1-0.clickhouse1-hs.ns-vaggarwal.svc.cluster.local :) select * from graphite_index LIMIT 5;
SELECT *
FROM graphite_index
LIMIT 5
Query id: ced975d1-cd06-49b7-a18f-96e0e62504fd
┌───────Date─┬─Level─┬─Path────────────────────────────────────────────────────────────┬────Version─┬─────────────updated─┬─status─┐
│ 1970-02-12 │ 30005 │ active.pickle.carbon-clickhouse1-6489b8f7c8-mbzpr.agents.carbon │ 1612267498 │ 2021-02-02 12:04:58 │ SIMPLE │
│ 1970-02-12 │ 30005 │ active.pickle.carbon-clickhouse1-6489b8f7c8-ts6kk.agents.carbon │ 1612267558 │ 2021-02-02 12:05:58 │ SIMPLE │
│ 1970-02-12 │ 30005 │ active.pickle.carbon-clickhouse2-7898cd697d-jndms.agents.carbon │ 1612271795 │ 2021-02-02 13:16:35 │ SIMPLE │
│ 1970-02-12 │ 30005 │ active.pickle.carbon-clickhouse2-7898cd697d-pbns7.agents.carbon │ 1612271786 │ 2021-02-02 13:16:26 │ SIMPLE │
│ 1970-02-12 │ 30005 │ active.tcp.carbon-clickhouse1-6489b8f7c8-mbzpr.agents.carbon │ 1612267498 │ 2021-02-02 12:04:58 │ SIMPLE │
└────────────┴───────┴─────────────────────────────────────────────────────────────────┴────────────┴─────────────────────┴────────┘
5 rows in set. Elapsed: 0.002 sec. Processed 1.12 thousand rows,110.75 KB (613.49 thousand rows/s.,60.45 MB/s.)
解决方法
您进行了无限循环:
CREATE TABLE IF NOT EXISTS default.graphite (
) ENGINE = Distributed('graphite','',graphite,xxHash64(Path));
分布式表指向自身。
必须是分布式的('graphite','SOMEDATABASE'
或者应该使用 remote_servers 中的默认数据库
<replica>
<default_database>
!!!!!! 永远不要使用循环复制
!!!!!! 永远不要使用循环复制
!!!!!! 永远不要使用循环复制
!!!!!! 永远不要使用循环复制
这篇文章必须删除。 https://altinity.com/blog/2018/5/10/circular-replication-cluster-topology-in-clickhouse 这份文件对 ClickHouse 造成了很大的伤害。