Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions solr/core/src/java/org/apache/solr/cloud/ZkController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2975,8 +2975,17 @@ public Collection<String> publishNodeAsDown(String nodeName) {
log.info("Publish node={} as DOWN", nodeName);

ClusterState clusterState = getClusterState();
Map<String, List<Replica>> replicasPerCollectionOnNode =
clusterState.getReplicaNamesPerCollectionOnNode(nodeName);
Map<String, List<Replica>> replicasPerCollectionOnNode = new HashMap<>();
clusterState
.collectionStream()
.forEach(
col -> {
List<Replica> 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
Expand Down
15 changes: 12 additions & 3 deletions solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at this, it's apparent the logic should be simplified to only get the list of replicas on this node for the collection the test cares about. No need for a Map; only a List. Could build in a single Stream.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already resolved -- main picked this up via #4760 (unrelated SOLR-18382 cleanup), and I just merged main into this branch. Current code is exactly what you described: no Map, just clusterState.getCollection(collectionName).getReplicasOnNode(nodeName).

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -389,9 +390,17 @@ public List<CoreDescriptor> getCoreDescriptors() {
zkController.getZkStateReader().forciblyRefreshAllClusterStateSlow();
ClusterState clusterState = zkController.getClusterState();

Map<String, List<Replica>> replicasOnNode =
clusterState.getReplicaNamesPerCollectionOnNode(nodeName);
assertNotNull("There should be replicas on the existing node", replicasOnNode);
Map<String, List<Replica>> replicasOnNode = new HashMap<>();
clusterState
.collectionStream()
.forEach(
col -> {
List<Replica> replicasOfCollection = col.getReplicasOnNode(nodeName);
if (!replicasOfCollection.isEmpty()) {
replicasOnNode.put(col.getName(), replicasOfCollection);
}
});
assertFalse("There should be replicas on the existing node", replicasOnNode.isEmpty());
List<Replica> replicas = replicasOnNode.get(collectionName);
assertNotNull("There should be replicas for the collection on the existing node", replicas);
assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -167,22 +166,6 @@ public Set<String> getLiveNodes() {
return liveNodes;
}

@Deprecated
public Map<String, List<Replica>> getReplicaNamesPerCollectionOnNode(final String nodeName) {
Map<String, List<Replica>> replicaNamesPerCollectionOnNode = new HashMap<>();
collectionStates.values().stream()
.map(CollectionRef::get)
.filter(Objects::nonNull)
.forEach(
col -> {
List<Replica> 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);
Expand Down Expand Up @@ -225,7 +208,7 @@ public static ClusterState createFromJson(
return createFromCollectionMap(version, stateMap, liveNodes, creationTime, prsSupplier);
}

@Deprecated
/** Still used by {@link #createFromJson}. */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createFromJson has been removed. We can remove this one. Ideally should have folded both together into the same change to tackle ClusterState API IMO.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked — it has its own independent callers (BackupManager, DistributedClusterStateUpdater, ZkStateReader in production, plus 4 test files), unrelated to createFromJson. Can't remove it; createFromJson was just a thin wrapper over it.

public static ClusterState createFromCollectionMap(
int version,
Map<String, Object> stateMap,
Expand Down