From 2af74679d0bf1bce54d74890d3fd6ea615d2ebcd Mon Sep 17 00:00:00 2001 From: Siyang Tang Date: Tue, 24 Dec 2024 19:30:37 +0800 Subject: [PATCH] [fix](meta-mgr) Real-time parsing meta service endpoint to avoid rpc failed after config muted --- be/src/cloud/cloud_meta_mgr.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/be/src/cloud/cloud_meta_mgr.cpp b/be/src/cloud/cloud_meta_mgr.cpp index 835e74ca7d5687..2cd6b58c57b5f6 100644 --- a/be/src/cloud/cloud_meta_mgr.cpp +++ b/be/src/cloud/cloud_meta_mgr.cpp @@ -143,6 +143,10 @@ class MetaServiceProxy { } private: + static bool is_meta_service_endpoint_list() { + return config::meta_service_endpoint.find(',') != std::string::npos; + } + static Status get_pooled_client(std::shared_ptr* stub) { static std::once_flag proxies_flag; static size_t num_proxies = 1; @@ -154,9 +158,6 @@ class MetaServiceProxy { if (config::meta_service_connection_pooled) { num_proxies = config::meta_service_connection_pool_size; } - if (config::meta_service_endpoint.find(',') != std::string::npos) { - is_meta_service_endpoint_list = true; - } proxies = std::make_unique(num_proxies); }); @@ -175,7 +176,7 @@ class MetaServiceProxy { const char* load_balancer_name = nullptr; std::string endpoint; - if (is_meta_service_endpoint_list) { + if (is_meta_service_endpoint_list()) { endpoint = fmt::format("list://{}", config::meta_service_endpoint); load_balancer_name = "random"; } else { @@ -215,7 +216,7 @@ class MetaServiceProxy { bool is_idle_timeout(long now) { auto idle_timeout_ms = config::meta_service_idle_connection_timeout_ms; // idle timeout only works without list endpoint. - return !is_meta_service_endpoint_list && idle_timeout_ms > 0 && + return !is_meta_service_endpoint_list() && idle_timeout_ms > 0 && _last_access_at_ms.load(std::memory_order_relaxed) + idle_timeout_ms < now; } @@ -243,7 +244,7 @@ class MetaServiceProxy { long deadline = now; // connection age only works without list endpoint. - if (!is_meta_service_endpoint_list && + if (!is_meta_service_endpoint_list() && config::meta_service_connection_age_base_seconds > 0) { std::default_random_engine rng(static_cast(now)); std::uniform_int_distribution<> uni( @@ -262,16 +263,12 @@ class MetaServiceProxy { return Status::OK(); } - static std::atomic_bool is_meta_service_endpoint_list; - std::shared_mutex _mutex; std::atomic _last_access_at_ms {0}; long _deadline_ms {0}; std::shared_ptr _stub; }; -std::atomic_bool MetaServiceProxy::is_meta_service_endpoint_list = false; - template struct is_any : std::disjunction...> {};