首页 > 解决方案 > clickhouse 集群:数据未复制

问题描述

我有一个包含 2 个节点的集群进行测试。1 个分片和 2 个副本。zookeeper集群中的3个节点

<remote_servers>
  <ch_cluster>
    <shard>
      <internal_replication>true</internal_replication>
      <replica>
        <host>ch1</host>
        <port>9000</port>
      </replica>
      <replica>
        <host>ch2</host>
        <port>9000</port>
      </replica>
    </shard>
  </ch_cluster>
</remote_servers>

ch1 中的宏:

  <macros>
        <shard>shard_01</shard>
        <replica>replica-01</replica>
    </macros>

ch2 中的宏:

   <macros>
        <shard>shard_01</shard>
        <replica>replica-02</replica>
    </macros>

动物园管理员配置:

   <zookeeper>
        <node>
            <host>zoo1</host>
            <port>2181</port>
        </node>
        <node>
            <host>zoo2</host>
            <port>2181</port>
        </node>
        <node>
            <host>zoo3</host>
            <port>2181</port>
        </node>
    </zookeeper>

我创建了第一个表

CREATE TABLE IF NOT EXISTS test.hits_local ON CLUSTER ch_cluster
(
  `date` Datetime,
  `user_id` String,
  `pageviews` Int32
)
ENGINE = ReplicatedMergeTree('/clickhouse/ch_cluster/tables/{shard}/hits_local', '{replica}')
PARTITION BY toStartOfHour(date)
ORDER BY (date)

然后我创建一个分布式表:

CREATE TABLE IF NOT EXISTS test.hits ON CLUSTER 'ch_cluster'
AS test.hits_local 
 (
      `date` Datetime,
      `user_id` String,
      `pageviews` Int32
    )
ENGINE = Distributed('ch_cluster', 'test', 'hits_local')

然后当从ch2中的test.hits_local中 选择数据时,我在ch1的test.hits_local表中插入数据,没有数据

然后我尝试从ch2中的test.hits分布式表中选择数据在5-6 分钟后出现,但在ch2中的test.hits_local中 没有数据

我的问题是何时将数据复制到ch2?谁负责将数据复制到另一个节点?它是动物园管理员还是应该将数据插入到 ch1 和 ch2 的表中?我应该将 < internal_replication > true </ internal_replication > 更改为false吗?

是否有必要将数据复制到ch2中的 test.hits_local ?

谢谢你。

标签: replicationdatabase-replicationclickhouse

解决方案


我应该将 <internal_replication>true</internal_replication> 更改为 false 吗?

不,你不应该。如果你使用 ReplicatedMergeTree internal_replication必须是 true

复制由 ReplicatedMergeTree 表引擎在内部完成。

副本使用它们的主机名和端口 = 9009 进行通信。检查 system.replication_queue 表是否有错误。

很可能节点“ch1”在 Zookeeper 中宣布了自己的主机名,即“localhost”。所以第二个节点“ch2”无法访问 localhost:9009 什么的。您可以在 clickhouse-server.log 或 system.replication_queue 中找到此类问题(它有一个包含错误的列)。

即使在非常高负载的设置中,复制延迟通常也小于 2 秒。


推荐阅读