From a19b27bd7c53764b226da32f62a26758151581d4 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Thu, 22 Feb 2024 17:28:26 +0100 Subject: [PATCH] Revert extra changed lines That was the changes that looks OK for the initial patchset version, but not now, after all review comments. Signed-off-by: Azat Khuzhin --- src/Client/ConnectionEstablisher.cpp | 1 - src/Client/ConnectionPoolWithFailover.h | 7 +++---- src/Common/PoolWithFailoverBase.h | 14 ++++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Client/ConnectionEstablisher.cpp b/src/Client/ConnectionEstablisher.cpp index 853fea90f23..6b1b5aa968e 100644 --- a/src/Client/ConnectionEstablisher.cpp +++ b/src/Client/ConnectionEstablisher.cpp @@ -95,7 +95,6 @@ void ConnectionEstablisher::run(ConnectionEstablisher::TryResult & result, std:: LOG_TRACE(log, "Server {} has unacceptable replica delay for table {}.{}: {}", result.entry->getDescription(), table_to_check->database, table_to_check->table, delay); ProfileEvents::increment(ProfileEvents::DistributedConnectionStaleReplica); - return; } } catch (const Exception & e) diff --git a/src/Client/ConnectionPoolWithFailover.h b/src/Client/ConnectionPoolWithFailover.h index 0f47270e964..7bb4291e339 100644 --- a/src/Client/ConnectionPoolWithFailover.h +++ b/src/Client/ConnectionPoolWithFailover.h @@ -62,14 +62,13 @@ public: /// The same as getMany(), but return std::vector. std::vector getManyForTableFunction(const ConnectionTimeouts & timeouts, - const Settings & settings, - PoolMode pool_mode); + const Settings & settings, PoolMode pool_mode); using Base = PoolWithFailoverBase; using TryResult = Base::TryResult; - /// The same as getMany(), but check that: - /// - replication delay for table_to_check is acceptable (delay threshold is taken from settings) + /// The same as getMany(), but check that replication delay for table_to_check is acceptable. + /// Delay threshold is taken from settings. std::vector getManyChecked( const ConnectionTimeouts & timeouts, const Settings & settings, diff --git a/src/Common/PoolWithFailoverBase.h b/src/Common/PoolWithFailoverBase.h index ccb2354c312..46c414d34c1 100644 --- a/src/Common/PoolWithFailoverBase.h +++ b/src/Common/PoolWithFailoverBase.h @@ -293,12 +293,14 @@ PoolWithFailoverBase::getMany( std::erase_if(try_results, [](const TryResult & r) { return r.entry.isNull() || !r.is_usable; }); - auto comparator = [&](const TryResult & left, const TryResult & right) - { - return std::forward_as_tuple(!left.is_up_to_date, left.delay) - < std::forward_as_tuple(!right.is_up_to_date, right.delay); - }; - std::stable_sort(try_results.begin(), try_results.end(), comparator); + /// Sort so that preferred items are near the beginning. + std::stable_sort( + try_results.begin(), try_results.end(), + [](const TryResult & left, const TryResult & right) + { + return std::forward_as_tuple(!left.is_up_to_date, left.delay) + < std::forward_as_tuple(!right.is_up_to_date, right.delay); + }); if (fallback_to_stale_replicas) {