From a185e833924b15c93c82be13d6d27f7ab5fda47b Mon Sep 17 00:00:00 2001 From: robot-clickhouse Date: Thu, 14 Nov 2024 16:07:56 +0000 Subject: [PATCH] Backport #71863 to 24.9: update host resolver a little bit often --- src/Common/HostResolvePool.cpp | 19 +++++++++++-------- src/Common/HostResolvePool.h | 4 ++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Common/HostResolvePool.cpp b/src/Common/HostResolvePool.cpp index e8a05a269bc..2c5bf039fe5 100644 --- a/src/Common/HostResolvePool.cpp +++ b/src/Common/HostResolvePool.cpp @@ -9,6 +9,7 @@ #include #include +#include namespace ProfileEvents @@ -49,16 +50,18 @@ HostResolver::WeakPtr HostResolver::getWeakFromThis() } HostResolver::HostResolver(String host_, Poco::Timespan history_) - : host(std::move(host_)) - , history(history_) - , resolve_function([](const String & host_to_resolve) { return DNSResolver::instance().resolveHostAllInOriginOrder(host_to_resolve); }) -{ - update(); -} + : HostResolver( + [](const String & host_to_resolve) { return DNSResolver::instance().resolveHostAllInOriginOrder(host_to_resolve); }, + host_, + history_) +{} HostResolver::HostResolver( ResolveFunction && resolve_function_, String host_, Poco::Timespan history_) - : host(std::move(host_)), history(history_), resolve_function(std::move(resolve_function_)) + : host(std::move(host_)) + , history(history_) + , resolve_interval(history_.totalMicroseconds() / 3) + , resolve_function(std::move(resolve_function_)) { update(); } @@ -203,7 +206,7 @@ bool HostResolver::isUpdateNeeded() Poco::Timestamp now; std::lock_guard lock(mutex); - return last_resolve_time + history < now || records.empty(); + return last_resolve_time + resolve_interval < now || records.empty(); } void HostResolver::updateImpl(Poco::Timestamp now, std::vector & next_gen) diff --git a/src/Common/HostResolvePool.h b/src/Common/HostResolvePool.h index d148e909ca9..b979da3d142 100644 --- a/src/Common/HostResolvePool.h +++ b/src/Common/HostResolvePool.h @@ -26,7 +26,7 @@ // a) it still occurs in resolve set after `history_` time or b) all other addresses are pessimized as well. // - resolve schedule // Addresses are resolved through `DB::DNSResolver::instance()`. -// Usually it does not happen more often than once in `history_` time. +// Usually it does not happen more often than 3 times in `history_` period. // But also new resolve performed each `setFail()` call. namespace DB @@ -212,6 +212,7 @@ protected: const String host; const Poco::Timespan history; + const Poco::Timespan resolve_interval; const HostResolverMetrics metrics = getMetrics(); // for tests purpose @@ -245,4 +246,3 @@ private: }; } -