You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by md...@apache.org on 2022/05/03 19:59:21 UTC

[solr] branch main updated: SOLR-16154 Submit ZK Event Listener to CC Executor (#805)

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

mdrob pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new c850a79ea9d SOLR-16154 Submit ZK Event Listener to CC Executor (#805)
c850a79ea9d is described below

commit c850a79ea9d75c53c4929af1806c2348c7a3e180
Author: Mike Drob <md...@apache.org>
AuthorDate: Tue May 3 14:59:15 2022 -0500

    SOLR-16154 Submit ZK Event Listener to CC Executor (#805)
---
 solr/CHANGES.txt                                   |  2 +
 .../java/org/apache/solr/cloud/ZkController.java   | 43 ++++++++++------------
 2 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 41d30f6c8d0..f6c30761c99 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -783,6 +783,8 @@ Bug Fixes
 
 * SOLR-16164: ConfigSet API returns error if untrusted user creates from _default configset (Eric Pugh, Kevin Risden)
 
+* SOLR-16154: Event listeners submit through core container executor service instead of separate thread (Mike Drob, Kevin Risden)
+
 ==================  8.11.2 ==================
 
 Bug Fixes
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 1a1d050941b..d026e855c91 100644
--- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java
+++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java
@@ -220,8 +220,7 @@ public class ZkController implements Closeable {
 
   @Deprecated
   // keeps track of replicas that have been asked to recover by leaders running on this node
-  private final Map<String, String> replicasInLeaderInitiatedRecovery =
-      new HashMap<String, String>();
+  private final Map<String, String> replicasInLeaderInitiatedRecovery = new HashMap<>();
 
   // This is an expert and unsupported development mode that does not create
   // an Overseer or register a /live node. This let's you monitor the cluster
@@ -232,7 +231,7 @@ public class ZkController implements Closeable {
   // keeps track of a list of objects that need to know a new ZooKeeper session was created after
   // expiration occurred ref is held as a HashSet since we clone the set before notifying to avoid
   // synchronizing too long
-  private HashSet<OnReconnect> reconnectListeners = new HashSet<OnReconnect>();
+  private HashSet<OnReconnect> reconnectListeners = new HashSet<>();
 
   private class RegisterCoreAsync implements Callable<Object> {
 
@@ -614,7 +613,9 @@ public class ZkController implements Closeable {
         try {
           log.debug(
               "calling waitForLeaderToSeeDownState for coreZkNodeName={} collection={} shard={}",
-              new Object[] {coreZkNodeName, collection, slice});
+              coreZkNodeName,
+              collection,
+              slice);
           waitForLeaderToSeeDownState(descriptor, coreZkNodeName);
         } catch (Exception e) {
           log.warn(
@@ -1468,8 +1469,8 @@ public class ZkController implements Closeable {
       // zk, we are willing to wait a while to find it in state
       String clusterStateLeaderUrl = zkStateReader.getLeaderUrl(collection, shardId, timeoutms * 2);
       int tries = 0;
-      final long msInSec = 1000L;
-      int maxTries = (int) Math.floor(leaderConflictResolveWait / msInSec);
+      final int msInSec = 1000;
+      int maxTries = leaderConflictResolveWait / msInSec;
       while (!leaderUrl.equals(clusterStateLeaderUrl)) {
         if (cc.isShutDown()) throw new AlreadyClosedException();
         if (tries > maxTries) {
@@ -2596,10 +2597,8 @@ public class ZkController implements Closeable {
       }
 
     } catch (KeeperException.BadVersionException bve) {
-      int v = -1;
       try {
-        Stat stat = zkClient.exists(resourceLocation, null, true);
-        v = stat.getVersion();
+        zkClient.exists(resourceLocation, null, true);
       } catch (Exception e) {
         log.error("Exception during ZooKeeper node checking ", e);
       }
@@ -2754,19 +2753,18 @@ public class ZkController implements Closeable {
       if (listeners != null && !listeners.isEmpty()) {
         final Set<Runnable> listenersCopy = new HashSet<>(listeners);
         // run these in a separate thread because this can be long running
-        new Thread(
-                () -> {
-                  log.debug("Running listeners for {}", zkDir);
-                  for (final Runnable listener : listenersCopy) {
-                    try {
-                      listener.run();
-                    } catch (Exception e) {
-                      log.warn("listener throws error", e);
-                    }
-                  }
-                },
-                "ZKEventListenerThread")
-            .start();
+        Runnable work =
+            () -> {
+              log.debug("Running listeners for {}", zkDir);
+              for (final Runnable listener : listenersCopy) {
+                try {
+                  listener.run();
+                } catch (RuntimeException e) {
+                  log.warn("listener throws error", e);
+                }
+              }
+            };
+        cc.getCoreZkRegisterExecutorService().submit(work);
       }
     }
     return true;
@@ -2866,7 +2864,6 @@ public class ZkController implements Closeable {
       Collection<Slice> slices = collection.getSlices();
 
       for (Slice slice : slices) {
-        Collection<Replica> replicas = slice.getReplicas();
         Replica r = slice.getReplica(dcore.getCloudDescriptor().getCoreNodeName());
         if (r != null) {
           return true;