accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vi...@apache.org
Subject git commit: ACCUMULO-1410 - making the ZK connections a bit tolerant to user requests
Date Mon, 09 Sep 2013 18:55:16 GMT
Updated Branches:
  refs/heads/master 505009437 -> 5d7a4a727


ACCUMULO-1410 - making the ZK connections a bit tolerant to user requests


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/5d7a4a72
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/5d7a4a72
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/5d7a4a72

Branch: refs/heads/master
Commit: 5d7a4a727247d7d19ea29b1031bedcefb690b4a1
Parents: 5050094
Author: John Vines <jvines@gmail.com>
Authored: Mon Sep 9 14:54:29 2013 -0400
Committer: John Vines <jvines@gmail.com>
Committed: Mon Sep 9 14:54:29 2013 -0400

----------------------------------------------------------------------
 .../apache/accumulo/fate/zookeeper/ZooSession.java   | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/5d7a4a72/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java
----------------------------------------------------------------------
diff --git a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java
index 4854d49..b02fbd3 100644
--- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java
@@ -72,18 +72,18 @@ class ZooSession {
   
   public static ZooKeeper connect(String host, int timeout, String scheme, byte[] auth, Watcher
watcher) {
     final int TIME_BETWEEN_CONNECT_CHECKS_MS = 100;
-    final int TOTAL_CONNECT_TIME_WAIT_MS = 10 * 1000;
+    int connectTimeWait = Math.min(10 * 1000, timeout);
     boolean tryAgain = true;
     int sleepTime = 100;
     ZooKeeper zooKeeper = null;
     
     long startTime = System.currentTimeMillis();
-
+    
     while (tryAgain) {
       try {
         zooKeeper = new ZooKeeper(host, timeout, watcher);
         // it may take some time to get connected to zookeeper if some of the servers are
down
-        for (int i = 0; i < TOTAL_CONNECT_TIME_WAIT_MS / TIME_BETWEEN_CONNECT_CHECKS_MS
&& tryAgain; i++) {
+        for (int i = 0; i < connectTimeWait / TIME_BETWEEN_CONNECT_CHECKS_MS &&
tryAgain; i++) {
           if (zooKeeper.getState().equals(States.CONNECTED)) {
             if (auth != null)
               zooKeeper.addAuthInfo(scheme, auth);
@@ -94,7 +94,7 @@ class ZooSession {
         
         if (System.currentTimeMillis() - startTime > 2 * timeout)
           throw new RuntimeException("Failed to connect to zookeeper (" + host + ") within
2x zookeeper timeout period " + timeout);
-
+        
       } catch (UnknownHostException uhe) {
         // do not expect to recover from this
         log.warn(uhe.getClass().getName() + " : " + uhe.getMessage());
@@ -112,6 +112,13 @@ class ZooSession {
       }
       
       if (tryAgain) {
+        if (startTime + 2 * timeout < System.currentTimeMillis() + sleepTime + connectTimeWait)
+          sleepTime = (int) (startTime + 2 * timeout - System.currentTimeMillis() - connectTimeWait);
+        if (sleepTime < 0)
+        {
+          connectTimeWait -= sleepTime; 
+          sleepTime = 0;
+        }
         UtilWaitThread.sleep(sleepTime);
         if (sleepTime < 10000)
           sleepTime = (int) (sleepTime + sleepTime * Math.random());


Mime
View raw message