Cluster Discovery
Overview
ClickHouse's Cluster Discovery feature simplifies cluster configuration by allowing nodes to automatically discover and register themselves without the need for explicit definition in the configuration files. This is especially beneficial in cases where the manual definition of each node becomes cumbersome.
Cluster Discovery is an experimental feature and can be changed or removed in future versions.
To enable it include the allow_experimental_cluster_discovery
setting in your configuration file:
Remote Servers Configuration
Traditional Manual Configuration
Traditionally, in ClickHouse, each shard and replica in the cluster needed to be manually specified in the configuration:
Using Cluster Discovery
With Cluster Discovery, rather than defining each node explicitly, you simply specify a path in ZooKeeper. All nodes that register under this path in ZooKeeper will be automatically discovered and added to the cluster.
If you want to specify a shard number for a particular node, you can include the <shard>
tag within the <discovery>
section:
for node1
and node2
:
for node3
and node4
:
Observer mode
Nodes configured in observer mode will not register themselves as replicas.
They will solely observe and discover other active replicas in the cluster without actively participating.
To enable observer mode, include the <observer/>
tag within the <discovery>
section:
Discovery of clusters
Sometimes you may need to add and remove not only hosts in clusters, but clusters themselves. You can use the <multicluster_root_path>
node with root path for several clusters:
In this case, when some other host registers itself with the path /clickhouse/discovery/some_new_cluster
, a cluster with name some_new_cluster
will be added.
You can use both features simultaneously, the host can register itself in cluster my_cluster
and discovery any other clusters:
Limitations:
- You can't use both
<path>
and<multicluster_root_path>
in the sameremote_servers
subtree. <multicluster_root_path>
can only be with<observer/>
.- The last part of path from Keeper is used as the cluster name, while during registration the name is taken from the XML tag.
Use-Cases and Limitations
As nodes are added or removed from the specified ZooKeeper path, they are automatically discovered or removed from the cluster without the need for configuration changes or server restarts.
However, changes affect only cluster configuration, not the data or existing databases and tables.
Consider the following example with a cluster of 3 nodes:
Then, we add a new node to the cluster, starting a new node with the same entry in the remote_servers
section in a configuration file:
The fourth node is participating in the cluster, but table event_table
still exists only on the first three nodes:
If you need to have tables replicated on all the nodes, you may use the Replicated database engine in alternative to cluster discovery.