diff --git a/locator/abstract_replication_strategy.cc b/locator/abstract_replication_strategy.cc index d7e02f46e0..e8079cc0c8 100644 --- a/locator/abstract_replication_strategy.cc +++ b/locator/abstract_replication_strategy.cc @@ -174,11 +174,9 @@ abstract_replication_strategy::get_ranges(inet_address ep, token_metadata_ptr tm } auto prev_tok = sorted_tokens.back(); for (auto tok : sorted_tokens) { - for (inet_address a : co_await calculate_natural_endpoints(tok, tm)) { - if (a == ep) { + auto eps = co_await calculate_natural_endpoints(tok, tm); + if (eps.contains(ep)) { insert_token_range_to_sorted_container_while_unwrapping(prev_tok, tok, ret); - break; - } } prev_tok = tok; } @@ -245,20 +243,13 @@ abstract_replication_strategy::get_address_ranges(const token_metadata& tm, inet continue; } auto eps = co_await calculate_natural_endpoints(t, tm); - bool found = false; - for (auto ep : eps) { - if (ep != endpoint) { - continue; - } + if (eps.contains(endpoint)) { dht::token_range_vector r = tm.get_primary_ranges_for(t); rslogger.debug("token={} primary_range={} endpoint={}", t, r, endpoint); for (auto&& rng : r) { - ret.emplace(ep, rng); + ret.emplace(endpoint, rng); } - found = true; - break; - } - if (!found) { + } else { rslogger.debug("token={} natural_endpoints={}: endpoint={} not found", t, eps, endpoint); } } diff --git a/locator/token_metadata.cc b/locator/token_metadata.cc index eb3d8a86ae..5ae5d96001 100644 --- a/locator/token_metadata.cc +++ b/locator/token_metadata.cc @@ -816,13 +816,10 @@ void token_metadata_impl::calculate_pending_ranges_for_leaving( auto t = r.end() ? r.end()->value() : dht::maximum_token(); auto current_endpoints = strategy.calculate_natural_endpoints(t, metadata).get0(); auto new_endpoints = strategy.calculate_natural_endpoints(t, *all_left_metadata).get0(); - std::vector diff; - std::sort(current_endpoints.begin(), current_endpoints.end()); - std::sort(new_endpoints.begin(), new_endpoints.end()); - std::set_difference(new_endpoints.begin(), new_endpoints.end(), - current_endpoints.begin(), current_endpoints.end(), std::back_inserter(diff)); - for (auto& ep : diff) { + for (auto ep : new_endpoints) { + if (!current_endpoints.contains(ep)) { new_pending_ranges.emplace(r, ep); + } } seastar::thread::maybe_yield(); } diff --git a/repair/repair.cc b/repair/repair.cc index b167b0565b..ca44ddb1df 100644 --- a/repair/repair.cc +++ b/repair/repair.cc @@ -1585,7 +1585,7 @@ future<> repair_service::do_decommission_removenode_with_repair(locator::token_m auto end_token = r.end() ? r.end()->value() : dht::maximum_token(); const auto new_eps = ks.get_replication_strategy().calculate_natural_endpoints(end_token, temp).get0(); const auto& current_eps = current_replica_endpoints[r]; - std::unordered_set neighbors_set(new_eps.begin(), new_eps.end()); + std::unordered_set neighbors_set = new_eps.get_set(); bool skip_this_range = false; auto new_owner = neighbors_set; for (const auto& node : current_eps) { diff --git a/utils/sequenced_set.hh b/utils/sequenced_set.hh index 566db42cc1..aee5b9b3a7 100644 --- a/utils/sequenced_set.hh +++ b/utils/sequenced_set.hh @@ -125,6 +125,14 @@ public: return _vec; } + const auto& get_set() const noexcept { + return _set; + } + + bool contains(const T& t) const noexcept { + return _set.contains(t); + } + void reserve(size_type sz) { _set.reserve(sz); _vec.reserve(sz);