From 3db018b95f717614231fb6357d7bc7685647243d Mon Sep 17 00:00:00 2001 From: "markrmiller@gmail.com" Date: Wed, 15 Jul 2020 13:35:46 -0500 Subject: [PATCH] #179 - Close the Overseer on ZK disconnect. --- .../org/apache/solr/cloud/ZkController.java | 8 ++++++- .../solr/common/cloud/ConnectionManager.java | 21 ++++++++++++++++++- .../solr/common/cloud/SolrZkClient.java | 5 +++++ .../solr/common/cloud/ZkCmdExecutor.java | 2 +- 4 files changed, 33 insertions(+), 3 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 1e6bcc877a35..91c30bcdcbc6 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java @@ -528,7 +528,13 @@ public void command() throws SessionExpiredException { public boolean isClosed() { return cc.isShutDown(); }}); - + zkClient.setDisconnectListener(() -> { + try { + ZkController.this.overseer.close(); + } catch (NullPointerException e) { + // okay + } + }); init(); this.overseerRunningMap = Overseer.getRunningMap(zkClient); diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.java index 86ad08c5ee17..726164f8c55f 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.java @@ -58,6 +58,7 @@ public class ConnectionManager implements Watcher, Closeable { private CountDownLatch connectedLatch = new CountDownLatch(1); private CountDownLatch disconnectedLatch = new CountDownLatch(1); + private volatile DisconnectListener disconnectListener; public void setOnReconnect(OnReconnect onReconnect) { this.onReconnect = onReconnect; @@ -123,8 +124,16 @@ private void disconnected() { if (!likelyExpiredState.isLikelyExpired(0)) { likelyExpiredState = new LikelyExpiredState(LikelyExpiredState.StateType.TRACKING_TIME, System.nanoTime()); } - disconnectedLatch.countDown();; + disconnectedLatch.countDown(); connectedLatch = new CountDownLatch(1); + + try { + disconnectListener.disconnected(); + } catch (NullPointerException e) { + // okay + } catch (Exception e) { + log.warn("Exception firing disonnectListener"); + } } @Override @@ -293,7 +302,17 @@ public void waitForDisconnected(long waitForDisconnected) } + public interface DisconnectListener { + void disconnected(); + } + + public void setDisconnectListener(DisconnectListener dl) { + this.disconnectListener = dl; + + } + private void closeKeeper(SolrZooKeeper keeper) { keeper.close(); } + } diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java index 5ec8c238aa0b..19e54ac05596 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java @@ -1100,6 +1100,11 @@ public void setIsClosed(IsClosed isClosed) { this.higherLevelIsClosed = isClosed; } + public void setDisconnectListener(ConnectionManager.DisconnectListener dl) { + this.connManager.setDisconnectListener(dl); + + } + /** * Watcher wrapper that ensures that heavy implementations of process do not interfere with our ability * to react to other watches, but also ensures that two wrappers containing equal watches are considered diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java index 418c78b79183..084db7d75cae 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java @@ -35,7 +35,7 @@ public class ZkCmdExecutor { private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private long retryDelay = 500L; // 1 second would match timeout, so 500 ms over for padding + private long retryDelay = 50L; private int retryCount; private long timeoutms; private IsClosed isClosed;