Skip to content

Commit

Permalink
calculate_natural_endpoints: fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Gusev committed Oct 31, 2023
1 parent 60248a2 commit e4efe83
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
10 changes: 5 additions & 5 deletions locator/everywhere_replication_strategy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ everywhere_replication_strategy::everywhere_replication_strategy(const replicati

future<natural_ep_type> everywhere_replication_strategy::calculate_natural_endpoints(const token& search_token, const token_metadata& tm, bool host_id) const {
return select_tm([this]<typename NodeId>(const generic_token_metadata<NodeId>& tm) -> future<natural_ep_type> {
if (tm.sorted_tokens().empty()) {
if (tm.sorted_tokens().empty()) {
set_type<NodeId> result{vector_type<NodeId>({this->get_self_id<NodeId>()})};
return make_ready_future<natural_ep_type>(std::move(result));
}
const auto& all_endpoints = tm.get_all_endpoints();
return make_ready_future<natural_ep_type>(set_type<NodeId>(all_endpoints.begin(), all_endpoints.end()));
return make_ready_future<natural_ep_type>(std::move(result));
}
const auto& all_endpoints = tm.get_all_endpoints();
return make_ready_future<natural_ep_type>(set_type<NodeId>(all_endpoints.begin(), all_endpoints.end()));
}, tm, host_id);
}

Expand Down
16 changes: 8 additions & 8 deletions locator/network_topology_strategy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,18 +244,18 @@ network_topology_strategy::calculate_natural_endpoints(
const token& search_token, const token_metadata& tm, bool host_id) const {

return select_tm([&]<typename NodeId>(const generic_token_metadata<NodeId>& tm) -> future<natural_ep_type> {
natural_endpoints_tracker<NodeId> tracker(tm, _dc_rep_factor);
natural_endpoints_tracker<NodeId> 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();

NodeId ep = *tm.get_endpoint(next);
if (tracker.add_endpoint_and_check_if_done(ep)) {
break;
NodeId 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());
}, tm, host_id);
}

Expand Down
44 changes: 22 additions & 22 deletions locator/simple_strategy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,33 @@ simple_strategy::simple_strategy(const replication_strategy_config_options& conf

future<natural_ep_type> simple_strategy::calculate_natural_endpoints(const token& t, const token_metadata& tm, bool host_id) const {
return select_tm([&]<typename NodeId>(const generic_token_metadata<NodeId>& tm) -> future<natural_ep_type> {
const std::vector<token>& tokens = tm.sorted_tokens();
const std::vector<token>& tokens = tm.sorted_tokens();

if (tokens.empty()) {
co_return set_type<NodeId>{};
}

size_t replicas = _replication_factor;
set_type<NodeId> 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;
if (tokens.empty()) {
co_return set_type<NodeId>{};
}

auto ep = tm.get_endpoint(token);
assert(ep);
size_t replicas = _replication_factor;
set_type<NodeId> endpoints;
endpoints.reserve(replicas);

endpoints.push_back(*ep);
co_await coroutine::maybe_yield();
}
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;
}

auto ep = tm.get_endpoint(token);
assert(ep);

endpoints.push_back(*ep);
co_await coroutine::maybe_yield();
}

co_return endpoints;
co_return endpoints;
}, tm, host_id);
}

Expand Down

0 comments on commit e4efe83

Please sign in to comment.