Apache Solr open-source search software
SOLR-17257: Avoid instantiating NodeStateProvider several times when computing replica placement (#2420)
Yohann Calleab7d4ef867a46
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 01c7e6efab8..c2104977d57 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -108,7 +108,8 @@ ImprovementsOptimizations----------------------(No changes)+* SOLR-17257: Both Minimize Cores and the Affinity replica placement strategies would over-gather+ cluster metrics. AttributeFetcherImpl was improved accordingly. (Yohann Callea)Bug Fixes---------------------diff --git a/solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeFetcherImpl.java b/solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeFetcherImpl.javaindex 251dd49759d..8ac3f9ab0c6 100644--- a/solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeFetcherImpl.java+++ b/solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeFetcherImpl.java@@ -26,6 +26,7 @@ import java.util.Map;import java.util.Set;import java.util.function.BiConsumer;import java.util.stream.Collectors;+import org.apache.solr.client.solrj.cloud.NodeStateProvider;import org.apache.solr.client.solrj.cloud.SolrCloudManager;import org.apache.solr.client.solrj.impl.NodeValueFetcher;import org.apache.solr.cluster.Node;@@ -138,14 +139,14 @@ public class AttributeFetcherImpl implements AttributeFetcher {}));});+ final NodeStateProvider nodeStateProvider = cloudManager.getNodeStateProvider();+// Now that we know everything we need to fetch (and where to put it), just do it.// TODO: we could probably fetch this in parallel - for large clusters this could// significantly shorten the execution timefor (Node node : nodes) {Map<String, Object> tagValues =- cloudManager- .getNodeStateProvider()- .getNodeValues(node.getName(), allSnitchTagsToInsertion.keySet());+ nodeStateProvider.getNodeValues(node.getName(), allSnitchTagsToInsertion.keySet());for (Map.Entry<String, Object> e : tagValues.entrySet()) {String tag = e.getKey();Object value = e.getValue(); // returned value from the node@@ -163,7 +164,7 @@ public class AttributeFetcherImpl implements AttributeFetcher {for (Node node : nodeToReplicaInternalTags.keySet()) {Set<String> tags = nodeToReplicaInternalTags.get(node);Map<String, Map<String, List<Replica>>> infos =- cloudManager.getNodeStateProvider().getReplicaInfo(node.getName(), tags);+ nodeStateProvider.getReplicaInfo(node.getName(), tags);infos.entrySet().stream().filter(entry -> requestedCollectionNamesMetrics.containsKey(entry.getKey())).forEach(