diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkController.java b/solr/core/src/java/org/apache/solr/cloud/ZkController.java index 3ab82e68b1d..112b301b62c 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java @@ -2975,8 +2975,17 @@ public Collection publishNodeAsDown(String nodeName) { log.info("Publish node={} as DOWN", nodeName); ClusterState clusterState = getClusterState(); - Map> replicasPerCollectionOnNode = - clusterState.getReplicaNamesPerCollectionOnNode(nodeName); + Map> replicasPerCollectionOnNode = new HashMap<>(); + clusterState + .collectionStream() + .forEach( + col -> { + List replicas = col.getReplicasOnNode(nodeName); + if (!replicas.isEmpty()) { + replicasPerCollectionOnNode.put(col.getName(), replicas); + } + }); + if (distributedClusterStateUpdater.isDistributedStateUpdate()) { // Note that with the current implementation, when distributed cluster state updates are // enabled, we mark the node down synchronously from this thread, whereas the Overseer cluster diff --git a/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java b/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java index 5c7cd7442d3..c1021ba9508 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java @@ -27,6 +27,7 @@ import java.nio.file.Path; import java.time.Duration; import java.time.Instant; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; @@ -389,9 +390,17 @@ public List getCoreDescriptors() { zkController.getZkStateReader().forciblyRefreshAllClusterStateSlow(); ClusterState clusterState = zkController.getClusterState(); - Map> replicasOnNode = - clusterState.getReplicaNamesPerCollectionOnNode(nodeName); - assertNotNull("There should be replicas on the existing node", replicasOnNode); + Map> replicasOnNode = new HashMap<>(); + clusterState + .collectionStream() + .forEach( + col -> { + List replicasOfCollection = col.getReplicasOnNode(nodeName); + if (!replicasOfCollection.isEmpty()) { + replicasOnNode.put(col.getName(), replicasOfCollection); + } + }); + assertFalse("There should be replicas on the existing node", replicasOnNode.isEmpty()); List replicas = replicasOnNode.get(collectionName); assertNotNull("There should be replicas for the collection on the existing node", replicas); assertEquals( diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java index ba92c3a9011..28b9820b5e1 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java @@ -25,7 +25,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; -import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; @@ -167,22 +166,6 @@ public Set getLiveNodes() { return liveNodes; } - @Deprecated - public Map> getReplicaNamesPerCollectionOnNode(final String nodeName) { - Map> replicaNamesPerCollectionOnNode = new HashMap<>(); - collectionStates.values().stream() - .map(CollectionRef::get) - .filter(Objects::nonNull) - .forEach( - col -> { - List replicas = col.getReplicasOnNode(nodeName); - if (!replicas.isEmpty()) { - replicaNamesPerCollectionOnNode.put(col.getName(), replicas); - } - }); - return replicaNamesPerCollectionOnNode; - } - /** Check if node is alive. */ public boolean liveNodesContain(String name) { return liveNodes.contains(name); @@ -225,7 +208,7 @@ public static ClusterState createFromJson( return createFromCollectionMap(version, stateMap, liveNodes, creationTime, prsSupplier); } - @Deprecated + /** Still used by {@link #createFromJson}. */ public static ClusterState createFromCollectionMap( int version, Map stateMap,