From 9a8a80527bc78f5063395af7d0bd88b36b676d2a Mon Sep 17 00:00:00 2001 From: Asias He Date: Wed, 22 Jun 2022 09:56:38 +0800 Subject: [PATCH] locator: Speed up simple_strategy::calculate_natural_endpoint 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 Refs #10337 Refs #10817 Refs #10836 Refs #10837 --- locator/simple_strategy.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/locator/simple_strategy.cc b/locator/simple_strategy.cc index 7da522b467..8de32e8091 100644 --- a/locator/simple_strategy.cc +++ b/locator/simple_strategy.cc @@ -45,7 +45,11 @@ future simple_strategy::calculate_natural_endpo endpoints.reserve(replicas); for (auto& token : tm.ring_range(t)) { - if (endpoints.size() == replicas) { + // 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; }