From 746053e7e02861108e00449e4ab731e44c09aa5f Mon Sep 17 00:00:00 2001 From: Sema Checherinda Date: Wed, 13 Nov 2024 13:46:05 +0100 Subject: [PATCH 1/4] update host resolver a little bit often --- src/Common/HostResolvePool.cpp | 5 ++++- src/Common/HostResolvePool.h | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Common/HostResolvePool.cpp b/src/Common/HostResolvePool.cpp index e8a05a269bc..26b21d996cc 100644 --- a/src/Common/HostResolvePool.cpp +++ b/src/Common/HostResolvePool.cpp @@ -9,6 +9,7 @@ #include #include +#include namespace ProfileEvents @@ -202,8 +203,10 @@ bool HostResolver::isUpdateNeeded() { Poco::Timestamp now; + auto piece_history = Poco::Timespan(history.totalMicroseconds() / 3); + std::lock_guard lock(mutex); - return last_resolve_time + history < now || records.empty(); + return last_resolve_time + piece_history < 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..e1502050bca 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 @@ -245,4 +245,3 @@ private: }; } - From 8e9dfdae00cd9f757d377305938c45f50ff938a0 Mon Sep 17 00:00:00 2001 From: Sema Checherinda Date: Wed, 13 Nov 2024 15:12:45 +0100 Subject: [PATCH 2/4] rename var --- src/Common/HostResolvePool.cpp | 5 ++--- src/Common/HostResolvePool.h | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Common/HostResolvePool.cpp b/src/Common/HostResolvePool.cpp index 26b21d996cc..03e6a0fa8dc 100644 --- a/src/Common/HostResolvePool.cpp +++ b/src/Common/HostResolvePool.cpp @@ -52,6 +52,7 @@ HostResolver::WeakPtr HostResolver::getWeakFromThis() HostResolver::HostResolver(String host_, Poco::Timespan history_) : host(std::move(host_)) , history(history_) + , resolve_interval(history_.totalMicroseconds() / 3) , resolve_function([](const String & host_to_resolve) { return DNSResolver::instance().resolveHostAllInOriginOrder(host_to_resolve); }) { update(); @@ -203,10 +204,8 @@ bool HostResolver::isUpdateNeeded() { Poco::Timestamp now; - auto piece_history = Poco::Timespan(history.totalMicroseconds() / 3); - std::lock_guard lock(mutex); - return last_resolve_time + piece_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 e1502050bca..b979da3d142 100644 --- a/src/Common/HostResolvePool.h +++ b/src/Common/HostResolvePool.h @@ -212,6 +212,7 @@ protected: const String host; const Poco::Timespan history; + const Poco::Timespan resolve_interval; const HostResolverMetrics metrics = getMetrics(); // for tests purpose From 3ba6c18037d9cb7167595dc69f9ee3e0c3db4fcc Mon Sep 17 00:00:00 2001 From: Sema Checherinda Date: Wed, 13 Nov 2024 15:17:21 +0100 Subject: [PATCH 3/4] fix c-tor --- src/Common/HostResolvePool.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Common/HostResolvePool.cpp b/src/Common/HostResolvePool.cpp index 03e6a0fa8dc..aab92aadd7a 100644 --- a/src/Common/HostResolvePool.cpp +++ b/src/Common/HostResolvePool.cpp @@ -50,17 +50,15 @@ HostResolver::WeakPtr HostResolver::getWeakFromThis() } HostResolver::HostResolver(String host_, Poco::Timespan history_) - : host(std::move(host_)) - , history(history_) - , resolve_interval(history_.totalMicroseconds() / 3) - , 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(); } From e5e95b88996138c1f0b9ae951f655175948293b8 Mon Sep 17 00:00:00 2001 From: Sema Checherinda Date: Wed, 13 Nov 2024 15:18:26 +0100 Subject: [PATCH 4/4] style c-tor --- src/Common/HostResolvePool.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Common/HostResolvePool.cpp b/src/Common/HostResolvePool.cpp index aab92aadd7a..2c5bf039fe5 100644 --- a/src/Common/HostResolvePool.cpp +++ b/src/Common/HostResolvePool.cpp @@ -50,7 +50,10 @@ HostResolver::WeakPtr HostResolver::getWeakFromThis() } HostResolver::HostResolver(String host_, Poco::Timespan history_) - : HostResolver([](const String & host_to_resolve) { return DNSResolver::instance().resolveHostAllInOriginOrder(host_to_resolve); }, host_, history_) + : HostResolver( + [](const String & host_to_resolve) { return DNSResolver::instance().resolveHostAllInOriginOrder(host_to_resolve); }, + host_, + history_) {} HostResolver::HostResolver(