From 0cc9dbd35bee66fec6d7b880e9b758e0872e849d Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Wed, 22 Apr 2020 01:41:40 +0300 Subject: [PATCH 1/2] Prefer fallback_to_stale_replicas over skip_unavailable_shards Patch from: @alex-zaitsev --- src/Common/PoolWithFailoverBase.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Common/PoolWithFailoverBase.h b/src/Common/PoolWithFailoverBase.h index a923088db3d..e0f251e9ed5 100644 --- a/src/Common/PoolWithFailoverBase.h +++ b/src/Common/PoolWithFailoverBase.h @@ -274,12 +274,7 @@ PoolWithFailoverBase::getMany( < std::forward_as_tuple(!right.is_up_to_date, right.staleness); }); - if (up_to_date_count >= min_entries) - { - /// There is enough up-to-date entries. - try_results.resize(up_to_date_count); - } - else if (fallback_to_stale_replicas) + if (fallback_to_stale_replicas) { /// There is not enough up-to-date entries but we are allowed to return stale entries. /// Gather all up-to-date ones and least-bad stale ones. @@ -287,6 +282,11 @@ PoolWithFailoverBase::getMany( size_t size = std::min(try_results.size(), max_entries); try_results.resize(size); } + else if (up_to_date_count >= min_entries) + { + /// There is enough up-to-date entries. + try_results.resize(up_to_date_count); + } else throw DB::Exception( "Could not find enough connections to up-to-date replicas. Got: " + std::to_string(up_to_date_count) From e0f58b1ca118f30ec70415e4c124b7a3d2ee1556 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Wed, 22 Apr 2020 01:45:51 +0300 Subject: [PATCH 2/2] Cover fallback_to_stale_replicas in conjunction with skip_unavailable_shards --- tests/integration/test_delayed_replica_failover/test.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/integration/test_delayed_replica_failover/test.py b/tests/integration/test_delayed_replica_failover/test.py index 58734b2c39b..66a3a9e1a34 100644 --- a/tests/integration/test_delayed_replica_failover/test.py +++ b/tests/integration/test_delayed_replica_failover/test.py @@ -81,6 +81,14 @@ SELECT sum(x) FROM distributed SETTINGS max_replica_delay_for_distributed_queries=1 ''').strip() == '3' + # Regression for skip_unavailable_shards in conjunction with skip_unavailable_shards + assert instance_with_dist_table.query(''' +SELECT sum(x) FROM distributed SETTINGS + load_balancing='in_order', + skip_unavailable_shards=1, + max_replica_delay_for_distributed_queries=1 +''').strip() == '3' + # If we forbid stale replicas, the query must fail. with pytest.raises(Exception): print instance_with_dist_table.query('''