zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [zookeeper] enixon commented on a change in pull request #730: Zookeeper-3188: Improve resilience to network
Date Thu, 14 Mar 2019 23:11:57 GMT
enixon commented on a change in pull request #730: Zookeeper-3188: Improve resilience to network
URL: https://github.com/apache/zookeeper/pull/730#discussion_r265799598
 
 

 ##########
 File path: zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/Learner.java
 ##########
 @@ -306,6 +280,81 @@ protected void connectToLeader(InetSocketAddress addr, String hostname)
         leaderOs = BinaryOutputArchive.getArchive(bufferedOutput);
     }
 
+    class LeaderConnector implements Runnable {
+
+        private AtomicReference<Socket> socket;
+        private InetSocketAddress address;
+        private CountDownLatch latch;
+
+        LeaderConnector(InetSocketAddress address, AtomicReference<Socket> socket,
CountDownLatch latch) {
+            this.address = address;
+            this.socket = socket;
+            this.latch = latch;
+        }
+
+        @Override
+        public void run() {
+            try {
+                Thread.currentThread().setName("LeaderConnector-" + address);
+                Socket sock = connectToLeader();
+
+                if (sock != null && sock.isConnected() && !socket.compareAndSet(null,
sock)) {
+                    LOG.info("Connection to the leader is already established, close the
redundant connection");
+                    sock.close();
+                }
+
+            } catch (Exception e) {
+                LOG.error("Failed connect to {}", address, e);
+            } finally {
+                latch.countDown();
+            }
+        }
+
+        private Socket connectToLeader() throws IOException, X509Exception, InterruptedException
{
+            Socket sock = createSocket();
+
+            int initLimitTime = self.tickTime * self.initLimit;
+            int remainingInitLimitTime;
+            long startNanoTime = nanoTime();
+
+            for (int tries = 0; tries < 5 && socket.get() == null; tries++) {
 
 Review comment:
   Does it make sense to change the retry logic as well so as to not spend more time trying
to talk to a single LearnerMaster?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message