From aa62dc354f1cdba7f183b9554710973ba599aebc Mon Sep 17 00:00:00 2001 From: Alexey Zatelepin Date: Tue, 18 Apr 2017 16:37:00 +0300 Subject: [PATCH] ensure that empty entries are not returned from PoolWithFailoverBase [#CLICKHOUSE-2141] --- dbms/src/Client/ConnectionPoolWithFailover.cpp | 5 ++++- dbms/src/Common/PoolWithFailoverBase.h | 15 ++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/dbms/src/Client/ConnectionPoolWithFailover.cpp b/dbms/src/Client/ConnectionPoolWithFailover.cpp index 1bf415c41d7..fd76b633866 100644 --- a/dbms/src/Client/ConnectionPoolWithFailover.cpp +++ b/dbms/src/Client/ConnectionPoolWithFailover.cpp @@ -139,6 +139,7 @@ ConnectionPoolWithFailover::tryGetEntry( if (!table_to_check || !max_allowed_delay || server_revision < DBMS_MIN_REVISION_WITH_TABLES_STATUS) { result.entry->forceConnected(); + result.is_up_to_date = true; return result; } @@ -162,7 +163,9 @@ ConnectionPoolWithFailover::tryGetEntry( max_delay = std::max(max_delay, status.absolute_delay); } - if (max_delay >= max_allowed_delay) + if (max_delay < max_allowed_delay) + result.is_up_to_date = true; + else { result.is_up_to_date = false; result.staleness = max_delay; diff --git a/dbms/src/Common/PoolWithFailoverBase.h b/dbms/src/Common/PoolWithFailoverBase.h index 468a002d1e8..f3ce6cbbb44 100644 --- a/dbms/src/Common/PoolWithFailoverBase.h +++ b/dbms/src/Common/PoolWithFailoverBase.h @@ -68,10 +68,10 @@ public: struct TryResult { TryResult() = default; - explicit TryResult(Entry entry_) : entry(std::move(entry)) {} + explicit TryResult(Entry entry_) : entry(std::move(entry)), is_up_to_date(true) {} Entry entry; - bool is_up_to_date = true; /// If true, the entry is a connection to up-to-date replica. + bool is_up_to_date = false; /// If true, the entry is a connection to up-to-date replica. double staleness = 0.0; /// Helps choosing the "least stale" option when all replicas are stale. }; @@ -224,6 +224,12 @@ PoolWithFailoverBase::getMany( "All connection tries failed. Log: \n\n" + fail_messages + "\n", DB::ErrorCodes::ALL_CONNECTION_TRIES_FAILED); + try_results.erase( + std::remove_if( + try_results.begin(), try_results.end(), + [](const TryResult & r) { return r.entry.isNull(); }), + try_results.end()); + std::vector entries; if (up_to_date_count >= min_entries) @@ -237,11 +243,6 @@ PoolWithFailoverBase::getMany( } else if (fallback_to_stale_replicas) { - try_results.erase( - std::remove_if( - try_results.begin(), try_results.end(), - [](const TryResult & r) { return r.entry.isNull(); }), - try_results.end()); std::stable_sort( try_results.begin(), try_results.end(), [](const TryResult & left, const TryResult & right)