From 0dfd92d0b34c8765859863c285df04a02aa1054d Mon Sep 17 00:00:00 2001 From: Benny Halevy Date: Fri, 29 Jul 2022 18:27:13 +0300 Subject: [PATCH] token_metadata: allow update_normal_token_owners to yield Given #11146, we see a 10ms stall when calculate_natural_endpoints calls get_all_endpoints that up until this patch performed a similar loop on the `_token_to_endpoint_map`, so to prevent such a stall with large number of tokens, turn update_normal_token_owners async, and allow yielding in the per-token tight loop. Signed-off-by: Benny Halevy --- locator/token_metadata.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/locator/token_metadata.cc b/locator/token_metadata.cc index 0b0eee558e..3275053a55 100644 --- a/locator/token_metadata.cc +++ b/locator/token_metadata.cc @@ -279,7 +279,7 @@ public: * Bootstrapping tokens are not taken into account. */ size_t count_normal_token_owners() const; private: - void update_normal_token_owners(); + future<> update_normal_token_owners(); public: // returns empty vector if keyspace_name not found. @@ -481,7 +481,7 @@ future<> token_metadata_impl::update_normal_tokens(const std::unordered_map token_metadata_impl::update_normal_token_owners() { std::unordered_set eps; for (auto [t, ep]: _token_to_endpoint_map) { eps.insert(ep); + co_await coroutine::maybe_yield(); } _normal_token_owners = std::move(eps); }