Merge branch '1.5.2-SNAPSHOT' into 1.6.1-SNAPSHOT

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

Branch: refs/heads/master
Commit: 41b72b5b7ea6af31c6cb78dd522c6505229fc135
Parents: 985a699 d4d455f
Author: Sean Busbey <bus...@cloudera.com>
Authored: Tue Jul 1 12:45:43 2014 -0500
Committer: Sean Busbey <bus...@cloudera.com>
Committed: Tue Jul 1 12:45:43 2014 -0500

----------------------------------------------------------------------
 .../accumulo/fate/zookeeper/ZooSession.java     | 14 +++++++--
 .../accumulo/fate/zookeeper/ZooSessionTest.java | 32 ++++++++++++++++++++
 2 files changed, 43 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/41b72b5b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java
----------------------------------------------------------------------
diff --cc fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java
index c0140ef,a9f630e..33bd77b
--- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java
@@@ -66,11 -66,18 +66,18 @@@ public class ZooSession 
      
    }
    
+   /**
+    * @param host comma separated list of zk servers
+    * @param timeout in milliseconds
+    * @param scheme authentication type, e.g. 'digest', may be null
+    * @param auth authentication-scheme-specific token, may be null
+    * @param watcher ZK notifications, may be null
+    */
    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;
 +    long sleepTime = 100;
      ZooKeeper zooKeeper = null;
      
      long startTime = System.currentTimeMillis();
@@@ -108,18 -112,15 +112,22 @@@
              log.warn("interrupted", e);
            }
        }
+ 
+       if (System.currentTimeMillis() - startTime > 2 * timeout) {
+         throw new RuntimeException("Failed to connect to zookeeper (" + host 
+ ") within 2x zookeeper timeout period " + timeout);
+       }
        
        if (tryAgain) {
 +        if (startTime + 2 * timeout < System.currentTimeMillis() + sleepTime 
+ connectTimeWait)
 +          sleepTime = 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());
 +          sleepTime = sleepTime + (long)(sleepTime * Math.random());
        }
      }
      

Reply via email to