From 0fa864aa7150ca55919c7323aa1d495afed394ac Mon Sep 17 00:00:00 2001 From: Julian Maicher Date: Fri, 29 Aug 2025 16:15:58 +0200 Subject: [PATCH] Fail when all replicas are unavailable for *cluster functions --- src/Storages/IStorageCluster.cpp | 11 ++++++++--- tests/config/config.d/clusters.xml | 14 ++++++++++++++ ...ding_s3_cluster_all_nodes_unavailable.reference | 0 ...03_reading_s3_cluster_all_nodes_unavailable.sql | 4 ++++ 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 tests/queries/0_stateless/03603_reading_s3_cluster_all_nodes_unavailable.reference create mode 100644 tests/queries/0_stateless/03603_reading_s3_cluster_all_nodes_unavailable.sql diff --git a/src/Storages/IStorageCluster.cpp b/src/Storages/IStorageCluster.cpp index 7c8d410cee53..0789c2993e74 100644 --- a/src/Storages/IStorageCluster.cpp +++ b/src/Storages/IStorageCluster.cpp @@ -42,6 +42,11 @@ namespace Setting extern const SettingsNonZeroUInt64 max_parallel_replicas; } +namespace ErrorCodes +{ + extern const int ALL_CONNECTION_TRIES_FAILED; +} + IStorageCluster::IStorageCluster( const String & cluster_name_, const StorageID & table_id_, @@ -239,10 +244,10 @@ void ReadFromCluster::initializePipeline(QueryPipelineBuilder & pipeline, const pipes.emplace_back(std::move(pipe)); } - auto pipe = Pipe::unitePipes(std::move(pipes)); - if (pipe.empty()) - pipe = Pipe(std::make_shared(getOutputHeader())); + if (pipes.empty()) + throw Exception(ErrorCodes::ALL_CONNECTION_TRIES_FAILED, "Cannot connect to any replica for query execution"); + auto pipe = Pipe::unitePipes(std::move(pipes)); for (const auto & processor : pipe.getProcessors()) processors.emplace_back(processor); diff --git a/tests/config/config.d/clusters.xml b/tests/config/config.d/clusters.xml index 0ee6ce774e43..1a507a76fd85 100644 --- a/tests/config/config.d/clusters.xml +++ b/tests/config/config.d/clusters.xml @@ -325,5 +325,19 @@ + + + 127.0.0.1 + 1234 + + + 127.0.0.2 + 1234 + + + 127.0.0.3 + 1234 + + diff --git a/tests/queries/0_stateless/03603_reading_s3_cluster_all_nodes_unavailable.reference b/tests/queries/0_stateless/03603_reading_s3_cluster_all_nodes_unavailable.reference new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tests/queries/0_stateless/03603_reading_s3_cluster_all_nodes_unavailable.sql b/tests/queries/0_stateless/03603_reading_s3_cluster_all_nodes_unavailable.sql new file mode 100644 index 000000000000..80da21ffacf8 --- /dev/null +++ b/tests/queries/0_stateless/03603_reading_s3_cluster_all_nodes_unavailable.sql @@ -0,0 +1,4 @@ +-- Tags: no-fasttest +-- s3Cluster is not used in fast tests + +SELECT * FROM s3Cluster('test_cluster_multiple_nodes_all_unavailable', 'http://localhost:11111/test/a.tsv'); -- { serverError ALL_CONNECTION_TRIES_FAILED }