You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2020/07/27 17:42:47 UTC

[lucene-solr] branch reference_impl updated: @394 Improve Zk waitForConnected.

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

markrmiller pushed a commit to branch reference_impl
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/reference_impl by this push:
     new e0754f4  @394 Improve Zk waitForConnected.
e0754f4 is described below

commit e0754f47982918bfe8148b4f2df8611e67ec16f7
Author: markrmiller@gmail.com <ma...@gmail.com>
AuthorDate: Mon Jul 27 12:42:31 2020 -0500

    @394 Improve Zk waitForConnected.
---
 .../org/apache/solr/common/cloud/ConnectionManager.java  | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

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 fb5905d..1401ce9 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
@@ -337,12 +337,16 @@ public class ConnectionManager implements Watcher, Closeable {
   public void waitForConnected(long waitForConnection)
           throws TimeoutException, InterruptedException {
     log.info("Waiting for client to connect to ZooKeeper");
-
-    if (client.isConnected()) return;
-    boolean success = connectedLatch.await(waitForConnection, TimeUnit.MILLISECONDS);
-    if (client.isConnected()) return;
-    if (!success) {
-      throw new TimeoutException("Timeout waiting to connect to ZooKeeper " + zkServerAddress + " " + waitForConnection + "ms");
+    TimeOut timeout = new TimeOut(waitForConnection, TimeUnit.MILLISECONDS, TimeSource.NANO_TIME);
+    while (!timeout.hasTimedOut()) {
+      if (client.isConnected()) return;
+      boolean success = connectedLatch.await(50, TimeUnit.MILLISECONDS);
+      if (success) return;
+      if (client.isConnected()) return;
+    }
+    if (timeout.hasTimedOut()) {
+      throw new TimeoutException("Timeout waiting to connect to ZooKeeper "
+              + zkServerAddress + " " + waitForConnection + "ms");
     }
 
     log.info("Client is connected to ZooKeeper");