-
Notifications
You must be signed in to change notification settings - Fork 8.3k
is_local = 0 in system.clusters when default_database is used #46277
Copy link
Copy link
Open
Labels
unexpected behaviourResult is unexpected, but not entirely wrong at the same time.Result is unexpected, but not entirely wrong at the same time.
Description
In table system.clusters, column is_local is always 0 when default_database is specified, even if the host resolves to a local address.
This is due to how this function is implemented:
ClickHouse/src/Interpreters/Cluster.cpp
Lines 40 to 53 in 27bc317
| inline bool isLocalImpl(const Cluster::Address & address, const Poco::Net::SocketAddress & resolved_address, UInt16 clickhouse_port) | |
| { | |
| /// If there is replica, for which: | |
| /// - its port is the same that the server is listening; | |
| /// - its host is resolved to set of addresses, one of which is the same as one of addresses of network interfaces of the server machine*; | |
| /// then we must go to this shard without any inter-process communication. | |
| /// | |
| /// * - this criteria is somewhat approximate. | |
| /// | |
| /// Also, replica is considered non-local, if it has default database set | |
| /// (only reason is to avoid query rewrite). | |
| return address.default_database.empty() && isLocalAddress(resolved_address, clickhouse_port); | |
| } |
I was wondering if this is intended and the reason is still relevant today? "only reason is to avoid query rewrite".
How to reproduce
Create a cluster definition in <remote_servers> in config.xml with default_database. I use this to implement circular replication:
<remote_servers>
<ch_cluster>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>ch-0.clickhouse</host>
<port>9000</port>
<default_database>stats_0</default_database>
</replica>
<replica>
<host>ch-1.clickhouse</host>
<port>9000</port>
<default_database>stats_1</default_database>
</replica>
</shard>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>ch-1.clickhouse</host>
<port>9000</port>
<default_database>stats_0</default_database>
</replica>
<replica>
<host>ch-2.clickhouse</host>
<port>9000</port>
<default_database>stats_1</default_database>
</replica>
</shard>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>ch-2.clickhouse</host>
<port>9000</port>
<default_database>stats_0</default_database>
</replica>
<replica>
<host>ch-0.clickhouse</host>
<port>9000</port>
<default_database>stats_1</default_database>
</replica>
</shard>
</ch_cluster>
</remote_servers>Contents of system.clusters:
select host_address, is_local, default_database from system.clusters where cluster = 'ch_cluster'
┌─host_address─┬─is_local─┬─default_database─┐
│ 10.3.99.160 │ 0 │ stats_0 │
│ 10.3.61.198 │ 0 │ stats_1 │
│ 10.3.61.198 │ 0 │ stats_0 │
│ 10.3.69.69 │ 0 │ stats_1 │
│ 10.3.69.69 │ 0 │ stats_0 │
│ 10.3.99.160 │ 0 │ stats_1 │
└──────────────┴──────────┴──────────────────┘
I would expect that the entries for the host that I'm connected to have is_local = 1:
┌─host_address─┬─is_local─┬─default_database─┐
│ 10.3.99.160 │ 1 │ stats_0 │
│ 10.3.61.198 │ 0 │ stats_1 │
│ 10.3.61.198 │ 0 │ stats_0 │
│ 10.3.69.69 │ 0 │ stats_1 │
│ 10.3.69.69 │ 0 │ stats_0 │
│ 10.3.99.160 │ 1 │ stats_1 │
└──────────────┴──────────┴──────────────────┘
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
unexpected behaviourResult is unexpected, but not entirely wrong at the same time.Result is unexpected, but not entirely wrong at the same time.