From b2fb650098aa3add6b239c2bec246eb8bb0f4a2c Mon Sep 17 00:00:00 2001 From: Petr Gusev Date: Wed, 6 Dec 2023 12:13:29 +0400 Subject: [PATCH] calculate_natural_endpoints: fix indentation --- locator/everywhere_replication_strategy.cc | 12 +++--- locator/local_strategy.cc | 2 +- locator/network_topology_strategy.cc | 16 ++++---- locator/simple_strategy.cc | 44 +++++++++++----------- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/locator/everywhere_replication_strategy.cc b/locator/everywhere_replication_strategy.cc index d946bb9d48..48a757b6da 100644 --- a/locator/everywhere_replication_strategy.cc +++ b/locator/everywhere_replication_strategy.cc @@ -21,12 +21,12 @@ everywhere_replication_strategy::everywhere_replication_strategy(const replicati } future everywhere_replication_strategy::calculate_natural_endpoints(const token& search_token, const token_metadata2& tm) const { - if (tm.sorted_tokens().empty()) { - host_id_set result{host_id_vector_replica_set({host_id{}})}; - return make_ready_future(std::move(result)); - } - const auto& all_endpoints = tm.get_all_endpoints(); - return make_ready_future(host_id_set(all_endpoints.begin(), all_endpoints.end())); + if (tm.sorted_tokens().empty()) { + host_id_set result{host_id_vector_replica_set({host_id{}})}; + return make_ready_future(std::move(result)); + } + const auto& all_endpoints = tm.get_all_endpoints(); + return make_ready_future(host_id_set(all_endpoints.begin(), all_endpoints.end())); } size_t everywhere_replication_strategy::get_replication_factor(const token_metadata& tm) const { diff --git a/locator/local_strategy.cc b/locator/local_strategy.cc index 71bba87e73..d5dcbae3a1 100644 --- a/locator/local_strategy.cc +++ b/locator/local_strategy.cc @@ -19,7 +19,7 @@ local_strategy::local_strategy(const replication_strategy_config_options& config } future local_strategy::calculate_natural_endpoints(const token& t, const token_metadata2& tm) const { - return make_ready_future(host_id_set{host_id{}}); + return make_ready_future(host_id_set{host_id{}}); } void local_strategy::validate_options(const gms::feature_service&) const { diff --git a/locator/network_topology_strategy.cc b/locator/network_topology_strategy.cc index 67d06b3100..ca25ff2acd 100644 --- a/locator/network_topology_strategy.cc +++ b/locator/network_topology_strategy.cc @@ -241,18 +241,18 @@ future network_topology_strategy::calculate_natural_endpoints( const token& search_token, const token_metadata2& tm) const { - natural_endpoints_tracker tracker(tm, _dc_rep_factor); + natural_endpoints_tracker tracker(tm, _dc_rep_factor); - for (auto& next : tm.ring_range(search_token)) { - co_await coroutine::maybe_yield(); + for (auto& next : tm.ring_range(search_token)) { + co_await coroutine::maybe_yield(); - host_id ep = *tm.get_endpoint(next); - if (tracker.add_endpoint_and_check_if_done(ep)) { - break; - } + host_id ep = *tm.get_endpoint(next); + if (tracker.add_endpoint_and_check_if_done(ep)) { + break; } + } - co_return std::move(tracker.replicas()); + co_return std::move(tracker.replicas()); } void network_topology_strategy::validate_options(const gms::feature_service& fs) const { diff --git a/locator/simple_strategy.cc b/locator/simple_strategy.cc index 6ba63db0cb..1cde3d6014 100644 --- a/locator/simple_strategy.cc +++ b/locator/simple_strategy.cc @@ -34,33 +34,33 @@ simple_strategy::simple_strategy(const replication_strategy_config_options& conf } future simple_strategy::calculate_natural_endpoints(const token& t, const token_metadata2& tm) const { - const std::vector& tokens = tm.sorted_tokens(); + const std::vector& tokens = tm.sorted_tokens(); - if (tokens.empty()) { - co_return host_id_set{}; + if (tokens.empty()) { + co_return host_id_set{}; + } + + size_t replicas = _replication_factor; + host_id_set endpoints; + endpoints.reserve(replicas); + + for (auto& token : tm.ring_range(t)) { + // If the number of nodes in the cluster is smaller than the desired + // replication factor we should return the loop when endpoints already + // contains all the nodes in the cluster because no more nodes could be + // added to endpoints lists. + if (endpoints.size() == replicas || endpoints.size() == tm.count_normal_token_owners()) { + break; } - size_t replicas = _replication_factor; - host_id_set endpoints; - endpoints.reserve(replicas); + auto ep = tm.get_endpoint(token); + assert(ep); - for (auto& token : tm.ring_range(t)) { - // If the number of nodes in the cluster is smaller than the desired - // replication factor we should return the loop when endpoints already - // contains all the nodes in the cluster because no more nodes could be - // added to endpoints lists. - if (endpoints.size() == replicas || endpoints.size() == tm.count_normal_token_owners()) { - break; - } + endpoints.push_back(*ep); + co_await coroutine::maybe_yield(); + } - auto ep = tm.get_endpoint(token); - assert(ep); - - endpoints.push_back(*ep); - co_await coroutine::maybe_yield(); - } - - co_return endpoints; + co_return endpoints; } size_t simple_strategy::get_replication_factor(const token_metadata&) const {