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 <bhalevy@scylladb.com>
This commit is contained in:
Benny Halevy
2022-07-29 18:27:13 +03:00
parent 4f8ccef2c1
commit 0dfd92d0b3

View File

@@ -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<inet
}
}
}
update_normal_token_owners();
co_await update_normal_token_owners();
// New tokens were added to _token_to_endpoint_map
// so re-sort all tokens.
@@ -915,10 +915,11 @@ size_t token_metadata_impl::count_normal_token_owners() const {
return _normal_token_owners.size();
}
void token_metadata_impl::update_normal_token_owners() {
future<> token_metadata_impl::update_normal_token_owners() {
std::unordered_set<inet_address> eps;
for (auto [t, ep]: _token_to_endpoint_map) {
eps.insert(ep);
co_await coroutine::maybe_yield();
}
_normal_token_owners = std::move(eps);
}