You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by is...@apache.org on 2023/01/17 11:26:23 UTC

[solr] 01/01: SOLR-16414: simplified code

This is an automated email from the ASF dual-hosted git repository.

ishan pushed a commit to branch jira/solr-16414-9_1_backport
in repository https://gitbox.apache.org/repos/asf/solr.git

commit 61922ec170d1f88081902e494eb754715a9239e2
Author: Noble Paul <no...@gmail.com>
AuthorDate: Tue Nov 8 17:22:08 2022 +1100

    SOLR-16414: simplified code
---
 .../java/org/apache/solr/cloud/ZkController.java   | 50 ++++++++--------------
 1 file changed, 19 insertions(+), 31 deletions(-)

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 6d20f57a42a..696ea7c900e 100644
--- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java
+++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java
@@ -2937,40 +2937,28 @@ public class ZkController implements Closeable {
     } else {
       try {
         // Create a concurrently accessible set to avoid repeating collections
-        Set<String> collectionsInThisNode = new HashSet<>();
+        Set<String> processedCollections = new HashSet<>();
         for (CoreDescriptor cd : cc.getCoreDescriptors()) {
-          if (cd.getCloudDescriptor() != null
-              && cd.getCloudDescriptor().getCollectionName() != null) {
-            collectionsInThisNode.add(cd.getCloudDescriptor().getCollectionName());
+          String collName = cd.getCollectionName();
+          DocCollection coll;
+          if (collName != null
+              && processedCollections.add(collName)
+              && (coll = zkStateReader.getCollection(collName)) != null
+              && coll.isPerReplicaState()) {
+            final List<String> replicasToDown = new ArrayList<>();
+            coll.forEachReplica(
+                (s, replica) -> {
+                  if (replica.getNodeName().equals(nodeName)) {
+                    replicasToDown.add(replica.getName());
+                  }
+                });
+            PerReplicaStatesOps.downReplicas(
+                    replicasToDown,
+                    PerReplicaStatesFetcher.fetch(
+                        coll.getZNode(), zkClient, coll.getPerReplicaStates()))
+                .persist(coll.getZNode(), zkClient);
           }
         }
-        collectionsInThisNode.forEach(
-            c -> {
-              final List<String> replicasToDown = new ArrayList<>();
-              DocCollection coll = zkStateReader.getCollection(c);
-              if (coll == null) {
-                // may be the collection no more exists
-                return;
-              }
-              coll.forEachReplica(
-                  (s, r) -> {
-                    if (r.getNodeName().equals(nodeName)) {
-                      replicasToDown.add(r.getName());
-                    }
-                  });
-
-              if (!replicasToDown.isEmpty()) {
-                try {
-                  PerReplicaStatesOps.downReplicas(
-                          replicasToDown,
-                          PerReplicaStatesFetcher.fetch(
-                              coll.getZNode(), zkClient, coll.getPerReplicaStates()))
-                      .persist(coll.getZNode(), zkClient);
-                } catch (KeeperException | InterruptedException e) {
-                  throw new RuntimeException(e);
-                }
-              }
-            });
 
         // We always send a down node event to overseer to be safe, but overseer will not need to do
         // anything for PRS collections