Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Storages/IStorageCluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <Analyzer/JoinNode.h>
#include <Analyzer/InDepthQueryTreeVisitor.h>
#include <Analyzer/Utils.h>
#include <Poco/URI.h>

#include <algorithm>
#include <memory>
Expand Down Expand Up @@ -405,7 +406,8 @@ IStorageCluster::RemoteCallVariables IStorageCluster::convertToRemote(
/// After getClusterImpl each shard must have exactly 1 replica
if (shard_addresses.size() != 1)
throw Exception(ErrorCodes::LOGICAL_ERROR, "Size of shard {} in cluster {} is not equal 1", shard_num, cluster_name_from_settings);
auto host_name = shard_addresses[0].toString();
std::string host_name;
Poco::URI::decode(shard_addresses[0].toString(), host_name);

LOG_INFO(log, "Choose remote initiator '{}'", host_name);

Expand Down
52 changes: 52 additions & 0 deletions tests/integration/test_s3_cluster/configs/cluster.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@
</shard>
</cluster_simple>

<!-- Cluster without s0_0_0-->
<cluster_remote>
<shard>
<replica>
<host>s0_0_1</host>
<port>9000</port>
</replica>
<replica>
<host>s0_1_0</host>
<port>9000</port>
</replica>
</shard>
</cluster_remote>

<!-- A part of the cluster above, represents only one shard-->
<first_shard>
<shard>
Expand Down Expand Up @@ -49,6 +63,44 @@
</shard>
</cluster_non_existent_port>

<cluster_with_dots>
<shard>
<replica>
<host>c2.s0_0_0</host>
<port>9000</port>
</replica>
<replica>
<host>c2.s0_0_1</host>
<port>9000</port>
</replica>
</shard>
</cluster_with_dots>

<cluster_all>
<shard>
<replica>
<host>s0_0_0</host>
<port>9000</port>
</replica>
<replica>
<host>s0_0_1</host>
<port>9000</port>
</replica>
<replica>
<host>s0_1_0</host>
<port>9000</port>
</replica>
<replica>
<host>c2.s0_0_0</host>
<port>9000</port>
</replica>
<replica>
<host>c2.s0_0_1</host>
<port>9000</port>
</replica>
</shard>
</cluster_all>

</remote_servers>
<macros>
<default_cluster_macro>cluster_simple</default_cluster_macro>
Expand Down
74 changes: 74 additions & 0 deletions tests/integration/test_s3_cluster/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,22 @@ def started_cluster():
with_zookeeper=True,
stay_alive=True,
)
cluster.add_instance(
"c2.s0_0_0",
main_configs=["configs/cluster.xml", "configs/named_collections.xml"],
user_configs=["configs/users.xml"],
macros={"replica": "replica1", "shard": "shard1"},
with_zookeeper=True,
stay_alive=True,
)
cluster.add_instance(
"c2.s0_0_1",
main_configs=["configs/cluster.xml", "configs/named_collections.xml"],
user_configs=["configs/users.xml"],
macros={"replica": "replica2", "shard": "shard1"},
with_zookeeper=True,
stay_alive=True,
)

logging.info("Starting cluster...")
cluster.start()
Expand Down Expand Up @@ -1197,3 +1213,61 @@ def test_joins(started_cluster):
)
res = list(map(str.split, result8.splitlines()))
assert len(res) == 25


def test_object_storage_remote_initiator(started_cluster):
node = started_cluster.instances["s0_0_0"]

query_id = uuid.uuid4().hex
result = node.query(
f"""
SELECT * from s3Cluster(
'cluster_remote',
'http://minio1:9001/root/data/{{clickhouse,database}}/*', 'minio', '{minio_secret_key}', 'CSV',
'name String, value UInt32, polygon Array(Array(Tuple(Float64, Float64)))') ORDER BY (name, value, polygon)
SETTINGS object_storage_remote_initiator=1
""",
query_id = query_id,
)

assert result is not None

node.query("SYSTEM FLUSH LOGS ON CLUSTER 'cluster_all'")
queries = node.query(
f"""
SELECT count()
FROM clusterAllReplicas('cluster_all', system.query_log)
WHERE type='QueryFinish' AND initial_query_id='{query_id}'
FORMAT TSV
"""
).splitlines()

# initial node + describe table + remote initiator + 2 subqueries on replicas
assert queries == ["5"]

query_id = uuid.uuid4().hex
result = node.query(
f"""
SELECT * from s3Cluster(
'cluster_with_dots',
'http://minio1:9001/root/data/{{clickhouse,database}}/*', 'minio', '{minio_secret_key}', 'CSV',
'name String, value UInt32, polygon Array(Array(Tuple(Float64, Float64)))') ORDER BY (name, value, polygon)
SETTINGS object_storage_remote_initiator=1
""",
query_id = query_id,
)

assert result is not None

node.query("SYSTEM FLUSH LOGS ON CLUSTER 'cluster_all'")
queries = node.query(
f"""
SELECT count()
FROM clusterAllReplicas('cluster_all', system.query_log)
WHERE type='QueryFinish' AND initial_query_id='{query_id}'
FORMAT TSV
"""
).splitlines()

# initial node + describe table + remote initiator + 2 subqueries on replicas
assert queries == ["5"]
Loading