bookkeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From si...@apache.org
Subject bookkeeper git commit: BOOKKEEPER-970: Bump the zookeeper version to 3.5
Date Thu, 23 Mar 2017 14:59:07 GMT
Repository: bookkeeper
Updated Branches:
  refs/heads/master 986110c4d -> 1e4ccaf16


BOOKKEEPER-970: Bump the zookeeper version to 3.5

in DL, we need to leverage the asynchronous version of 'multi' in zookeeper. so this jira
is to bump the zookeeper version to 3.5 to support async multi.

Author: Sijie Guo <sijie@apache.org>

Reviewers: Enrico Olivelli <eolivelli@gmail.com>

Closes #79 from sijie/sijie/bump_zookeeper_version


Project: http://git-wip-us.apache.org/repos/asf/bookkeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/bookkeeper/commit/1e4ccaf1
Tree: http://git-wip-us.apache.org/repos/asf/bookkeeper/tree/1e4ccaf1
Diff: http://git-wip-us.apache.org/repos/asf/bookkeeper/diff/1e4ccaf1

Branch: refs/heads/master
Commit: 1e4ccaf167936fb4ad0de8c29ecf840bed3e89ed
Parents: 986110c
Author: Sijie Guo <sijie@apache.org>
Authored: Thu Mar 23 10:59:01 2017 -0400
Committer: Sijie Guo <sijie@apache.org>
Committed: Thu Mar 23 10:59:01 2017 -0400

----------------------------------------------------------------------
 bookkeeper-benchmark/pom.xml                    |   6 +
 bookkeeper-server/pom.xml                       |   6 +
 .../bookkeeper/zookeeper/ZooKeeperClient.java   | 235 ++++++++++++++++---
 .../bookkeeper/zookeeper/TestRetryPolicy.java   |  54 +++++
 .../zookeeper/TestZooKeeperClient.java          |  29 ++-
 pom.xml                                         |   2 +-
 6 files changed, 299 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/1e4ccaf1/bookkeeper-benchmark/pom.xml
----------------------------------------------------------------------
diff --git a/bookkeeper-benchmark/pom.xml b/bookkeeper-benchmark/pom.xml
index c866fbe..dac28b0 100644
--- a/bookkeeper-benchmark/pom.xml
+++ b/bookkeeper-benchmark/pom.xml
@@ -74,6 +74,12 @@
       <version>${zookeeper.version}</version>
       <type>jar</type>
       <scope>compile</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>net.java.dev.javacc</groupId>
+          <artifactId>javacc</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>org.apache.zookeeper</groupId>

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/1e4ccaf1/bookkeeper-server/pom.xml
----------------------------------------------------------------------
diff --git a/bookkeeper-server/pom.xml b/bookkeeper-server/pom.xml
index 25de77a..cc13e59 100644
--- a/bookkeeper-server/pom.xml
+++ b/bookkeeper-server/pom.xml
@@ -69,6 +69,12 @@
       <artifactId>zookeeper</artifactId>
       <version>${zookeeper.version}</version>
       <scope>compile</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>net.java.dev.javacc</groupId>
+          <artifactId>javacc</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>org.apache.zookeeper</groupId>

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/1e4ccaf1/bookkeeper-server/src/main/java/org/apache/bookkeeper/zookeeper/ZooKeeperClient.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/zookeeper/ZooKeeperClient.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/zookeeper/ZooKeeperClient.java
index 80a853b..94df8da 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/zookeeper/ZooKeeperClient.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/zookeeper/ZooKeeperClient.java
@@ -29,6 +29,7 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.RejectedExecutionException;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
 
 import com.google.common.annotations.VisibleForTesting;
@@ -41,9 +42,11 @@ import org.apache.bookkeeper.stats.OpStatsLogger;
 import org.apache.bookkeeper.stats.StatsLogger;
 import org.apache.bookkeeper.zookeeper.ZooWorker.ZooCallable;
 import org.apache.zookeeper.AsyncCallback.ACLCallback;
+import org.apache.zookeeper.AsyncCallback.Create2Callback;
 import org.apache.zookeeper.AsyncCallback.Children2Callback;
 import org.apache.zookeeper.AsyncCallback.ChildrenCallback;
 import org.apache.zookeeper.AsyncCallback.DataCallback;
+import org.apache.zookeeper.AsyncCallback.MultiCallback;
 import org.apache.zookeeper.AsyncCallback.StatCallback;
 import org.apache.zookeeper.AsyncCallback.StringCallback;
 import org.apache.zookeeper.AsyncCallback.VoidCallback;
@@ -77,6 +80,7 @@ public class ZooKeeperClient extends ZooKeeper implements Watcher {
 
     // state for the zookeeper client
     private final AtomicReference<ZooKeeper> zk = new AtomicReference<ZooKeeper>();
+    private final AtomicBoolean closed = new AtomicBoolean(false);
     private final ZooKeeperWatcherBase watcherManager;
 
     private final ScheduledExecutorService retryExecutor;
@@ -297,6 +301,7 @@ public class ZooKeeperClient extends ZooKeeper implements Watcher {
 
     @Override
     public void close() throws InterruptedException {
+        closed.set(true);
         connectExecutor.shutdown();
         retryExecutor.shutdown();
         closeZkHandle();
@@ -328,12 +333,19 @@ public class ZooKeeperClient extends ZooKeeper implements Watcher {
     }
 
     private void onExpired() {
+        if (closed.get()) {
+            // we don't schedule any tries if the client is closed.
+            return;
+        }
+
         logger.info("ZooKeeper session {} is expired from {}.",
                 Long.toHexString(getSessionId()), connectString);
         try {
             connectExecutor.submit(clientCreator);
         } catch (RejectedExecutionException ree) {
-            logger.error("ZooKeeper reconnect task is rejected : ", ree);
+            if (!closed.get()) {
+                logger.error("ZooKeeper reconnect task is rejected : ", ree);
+            }
         } catch (Exception t) {
             logger.error("Failed to submit zookeeper reconnect task due to runtime exception
: ", t);
         }
@@ -403,6 +415,20 @@ public class ZooKeeperClient extends ZooKeeper implements Watcher {
         zkHandle.addAuthInfo(scheme, auth);
     }
 
+    private void backOffAndRetry(Runnable r, long nextRetryWaitTimeMs) {
+        try {
+            retryExecutor.schedule(r, nextRetryWaitTimeMs, TimeUnit.MILLISECONDS);
+        } catch (RejectedExecutionException ree) {
+            if (!closed.get()) {
+                logger.error("ZooKeeper Operation {} is rejected : ", r, ree);
+            }
+        }
+    }
+
+    private boolean allowRetry(ZooWorker worker, int rc) {
+        return worker.allowRetry(rc) && !closed.get();
+    }
+
     @Override
     public synchronized void register(Watcher watcher) {
         watcherManager.addChildWatcher(watcher);
@@ -430,6 +456,46 @@ public class ZooKeeperClient extends ZooKeeper implements Watcher {
     }
 
     @Override
+    public void multi(final Iterable<Op> ops,
+                      final MultiCallback cb,
+                      final Object context) {
+        final Runnable proc = new ZkRetryRunnable(operationRetryPolicy, rateLimiter, createStats)
{
+
+            final MultiCallback multiCb = new MultiCallback() {
+
+                @Override
+                public void processResult(int rc, String path, Object ctx, List<OpResult>
results) {
+                    ZooWorker worker = (ZooWorker)ctx;
+                    if (allowRetry(worker, rc)) {
+                        backOffAndRetry(that, worker.nextRetryWaitTime());
+                    } else {
+                        cb.processResult(rc, path, context, results);
+                    }
+                }
+
+            };
+
+            @Override
+            void zkRun() {
+                ZooKeeper zkHandle = zk.get();
+                if (null == zkHandle) {
+                    ZooKeeperClient.super.multi(ops, multiCb, worker);
+                } else {
+                    zkHandle.multi(ops, multiCb, worker);
+                }
+            }
+
+            @Override
+            public String toString() {
+                return "multi";
+            }
+        };
+        // execute it immediately
+        proc.run();
+    }
+
+    @Override
+    @Deprecated
     public Transaction transaction() {
         // since there is no reference about which client that the transaction could use
         // so just use ZooKeeper instance directly.
@@ -471,8 +537,8 @@ public class ZooKeeperClient extends ZooKeeper implements Watcher {
                 @Override
                 public void processResult(int rc, String path, Object ctx, List<ACL>
acl, Stat stat) {
                     ZooWorker worker = (ZooWorker)ctx;
-                    if (worker.allowRetry(rc)) {
-                        retryExecutor.schedule(that, worker.nextRetryWaitTime(), TimeUnit.MILLISECONDS);
+                    if (allowRetry(worker, rc)) {
+                        backOffAndRetry(that, worker.nextRetryWaitTime());
                     } else {
                         cb.processResult(rc, path, context, acl, stat);
                     }
@@ -531,8 +597,8 @@ public class ZooKeeperClient extends ZooKeeper implements Watcher {
                 @Override
                 public void processResult(int rc, String path, Object ctx, Stat stat) {
                     ZooWorker worker = (ZooWorker)ctx;
-                    if (worker.allowRetry(rc)) {
-                        retryExecutor.schedule(that, worker.nextRetryWaitTime(), TimeUnit.MILLISECONDS);
+                    if (allowRetry(worker, rc)) {
+                        backOffAndRetry(that, worker.nextRetryWaitTime());
                     } else {
                         cb.processResult(rc, path, context, stat);
                     }
@@ -568,8 +634,8 @@ public class ZooKeeperClient extends ZooKeeper implements Watcher {
                 @Override
                 public void processResult(int rc, String path, Object ctx) {
                     ZooWorker worker = (ZooWorker)ctx;
-                    if (worker.allowRetry(rc)) {
-                        retryExecutor.schedule(that, worker.nextRetryWaitTime(), TimeUnit.MILLISECONDS);
+                    if (allowRetry(worker, rc)) {
+                        backOffAndRetry(that, worker.nextRetryWaitTime());
                     } else {
                         cb.processResult(rc, path, context);
                     }
@@ -649,8 +715,8 @@ public class ZooKeeperClient extends ZooKeeper implements Watcher {
                 @Override
                 public void processResult(int rc, String path, Object ctx, String name) {
                     ZooWorker worker = (ZooWorker)ctx;
-                    if (worker.allowRetry(rc)) {
-                        retryExecutor.schedule(that, worker.nextRetryWaitTime(), TimeUnit.MILLISECONDS);
+                    if (allowRetry(worker, rc)) {
+                        backOffAndRetry(that, worker.nextRetryWaitTime());
                     } else {
                         cb.processResult(rc, path, context, name);
                     }
@@ -678,6 +744,74 @@ public class ZooKeeperClient extends ZooKeeper implements Watcher {
     }
 
     @Override
+    public String create(final String path,
+                         final byte[] data,
+                         final List<ACL> acl,
+                         final CreateMode createMode,
+                         final Stat stat)
+            throws KeeperException, InterruptedException {
+        return ZooWorker.syncCallWithRetries(this, new ZooCallable<String>() {
+
+            @Override
+            public String call() throws KeeperException, InterruptedException {
+                ZooKeeper zkHandle = zk.get();
+                if (null == zkHandle) {
+                    return ZooKeeperClient.super.create(path, data, acl, createMode);
+                }
+                return zkHandle.create(path, data, acl, createMode);
+            }
+
+            @Override
+            public String toString() {
+                return String.format("create (%s, acl = %s, mode = %s)", path, acl, createMode);
+            }
+
+        }, operationRetryPolicy, rateLimiter, createStats);
+    }
+
+    @Override
+    public void create(final String path,
+                       final byte[] data,
+                       final List<ACL> acl,
+                       final CreateMode createMode,
+                       final Create2Callback cb,
+                       final Object context) {
+        final Runnable proc = new ZkRetryRunnable(operationRetryPolicy, rateLimiter, createStats)
{
+
+            final Create2Callback createCb = new Create2Callback() {
+
+                @Override
+                public void processResult(int rc, String path, Object ctx, String name, Stat
stat) {
+                    ZooWorker worker = (ZooWorker)ctx;
+                    if (allowRetry(worker, rc)) {
+                        backOffAndRetry(that, worker.nextRetryWaitTime());
+                    } else {
+                        cb.processResult(rc, path, context, name, stat);
+                    }
+                }
+
+            };
+
+            @Override
+            void zkRun() {
+                ZooKeeper zkHandle = zk.get();
+                if (null == zkHandle) {
+                    ZooKeeperClient.super.create(path, data, acl, createMode, createCb, worker);
+                } else {
+                    zkHandle.create(path, data, acl, createMode, createCb, worker);
+                }
+            }
+
+            @Override
+            public String toString() {
+                return String.format("create (%s, acl = %s, mode = %s)", path, acl, createMode);
+            }
+        };
+        // execute it immediately
+        proc.run();
+    }
+
+    @Override
     public void delete(final String path, final int version) throws KeeperException, InterruptedException
{
         ZooWorker.syncCallWithRetries(this, new ZooCallable<Void>() {
 
@@ -709,8 +843,8 @@ public class ZooKeeperClient extends ZooKeeper implements Watcher {
                 @Override
                 public void processResult(int rc, String path, Object ctx) {
                     ZooWorker worker = (ZooWorker)ctx;
-                    if (worker.allowRetry(rc)) {
-                        retryExecutor.schedule(that, worker.nextRetryWaitTime(), TimeUnit.MILLISECONDS);
+                    if (allowRetry(worker, rc)) {
+                        backOffAndRetry(that, worker.nextRetryWaitTime());
                     } else {
                         cb.processResult(rc, path, context);
                     }
@@ -788,8 +922,8 @@ public class ZooKeeperClient extends ZooKeeper implements Watcher {
                 @Override
                 public void processResult(int rc, String path, Object ctx, Stat stat) {
                     ZooWorker worker = (ZooWorker)ctx;
-                    if (worker.allowRetry(rc)) {
-                        retryExecutor.schedule(that, worker.nextRetryWaitTime(), TimeUnit.MILLISECONDS);
+                    if (allowRetry(worker, rc)) {
+                        backOffAndRetry(that, worker.nextRetryWaitTime());
                     } else {
                         cb.processResult(rc, path, context, stat);
                     }
@@ -825,8 +959,8 @@ public class ZooKeeperClient extends ZooKeeper implements Watcher {
                 @Override
                 public void processResult(int rc, String path, Object ctx, Stat stat) {
                     ZooWorker worker = (ZooWorker)ctx;
-                    if (worker.allowRetry(rc)) {
-                        retryExecutor.schedule(that, worker.nextRetryWaitTime(), TimeUnit.MILLISECONDS);
+                    if (allowRetry(worker, rc)) {
+                        backOffAndRetry(that, worker.nextRetryWaitTime());
                     } else {
                         cb.processResult(rc, path, context, stat);
                     }
@@ -906,8 +1040,8 @@ public class ZooKeeperClient extends ZooKeeper implements Watcher {
                 @Override
                 public void processResult(int rc, String path, Object ctx, byte[] data, Stat
stat) {
                     ZooWorker worker = (ZooWorker)ctx;
-                    if (worker.allowRetry(rc)) {
-                        retryExecutor.schedule(that, worker.nextRetryWaitTime(), TimeUnit.MILLISECONDS);
+                    if (allowRetry(worker, rc)) {
+                        backOffAndRetry(that, worker.nextRetryWaitTime());
                     } else {
                         cb.processResult(rc, path, context, data, stat);
                     }
@@ -943,8 +1077,8 @@ public class ZooKeeperClient extends ZooKeeper implements Watcher {
                 @Override
                 public void processResult(int rc, String path, Object ctx, byte[] data, Stat
stat) {
                     ZooWorker worker = (ZooWorker)ctx;
-                    if (worker.allowRetry(rc)) {
-                        retryExecutor.schedule(that, worker.nextRetryWaitTime(), TimeUnit.MILLISECONDS);
+                    if (allowRetry(worker, rc)) {
+                        backOffAndRetry(that, worker.nextRetryWaitTime());
                     } else {
                         cb.processResult(rc, path, context, data, stat);
                     }
@@ -1003,8 +1137,8 @@ public class ZooKeeperClient extends ZooKeeper implements Watcher {
                 @Override
                 public void processResult(int rc, String path, Object ctx, Stat stat) {
                     ZooWorker worker = (ZooWorker)ctx;
-                    if (worker.allowRetry(rc)) {
-                        retryExecutor.schedule(that, worker.nextRetryWaitTime(), TimeUnit.MILLISECONDS);
+                    if (allowRetry(worker, rc)) {
+                        backOffAndRetry(that, worker.nextRetryWaitTime());
                     } else {
                         cb.processResult(rc, path, context, stat);
                     }
@@ -1086,8 +1220,8 @@ public class ZooKeeperClient extends ZooKeeper implements Watcher {
                 public void processResult(int rc, String path, Object ctx,
                         List<String> children, Stat stat) {
                     ZooWorker worker = (ZooWorker)ctx;
-                    if (worker.allowRetry(rc)) {
-                        retryExecutor.schedule(that, worker.nextRetryWaitTime(), TimeUnit.MILLISECONDS);
+                    if (allowRetry(worker, rc)) {
+                        backOffAndRetry(that, worker.nextRetryWaitTime());
                     } else {
                         cb.processResult(rc, path, context, children, stat);
                     }
@@ -1125,8 +1259,8 @@ public class ZooKeeperClient extends ZooKeeper implements Watcher {
                 public void processResult(int rc, String path, Object ctx,
                         List<String> children, Stat stat) {
                     ZooWorker worker = (ZooWorker)ctx;
-                    if (worker.allowRetry(rc)) {
-                        retryExecutor.schedule(that, worker.nextRetryWaitTime(), TimeUnit.MILLISECONDS);
+                    if (allowRetry(worker, rc)) {
+                        backOffAndRetry(that, worker.nextRetryWaitTime());
                     } else {
                         cb.processResult(rc, path, context, children, stat);
                     }
@@ -1209,8 +1343,8 @@ public class ZooKeeperClient extends ZooKeeper implements Watcher {
                 public void processResult(int rc, String path, Object ctx,
                         List<String> children) {
                     ZooWorker worker = (ZooWorker)ctx;
-                    if (worker.allowRetry(rc)) {
-                        retryExecutor.schedule(that, worker.nextRetryWaitTime(), TimeUnit.MILLISECONDS);
+                    if (allowRetry(worker, rc)) {
+                        backOffAndRetry(that, worker.nextRetryWaitTime());
                     } else {
                         cb.processResult(rc, path, context, children);
                     }
@@ -1248,8 +1382,8 @@ public class ZooKeeperClient extends ZooKeeper implements Watcher {
                 public void processResult(int rc, String path, Object ctx,
                         List<String> children) {
                     ZooWorker worker = (ZooWorker)ctx;
-                    if (worker.allowRetry(rc)) {
-                        retryExecutor.schedule(that, worker.nextRetryWaitTime(), TimeUnit.MILLISECONDS);
+                    if (allowRetry(worker, rc)) {
+                        backOffAndRetry(that, worker.nextRetryWaitTime());
                     } else {
                         cb.processResult(rc, path, context, children);
                     }
@@ -1276,4 +1410,47 @@ public class ZooKeeperClient extends ZooKeeper implements Watcher {
         proc.run();
     }
 
+    @Override
+    public void removeWatches(String path, Watcher watcher, WatcherType watcherType, boolean
local)
+            throws InterruptedException, KeeperException {
+        ZooKeeper zkHandle = zk.get();
+        if (null == zkHandle) {
+            ZooKeeperClient.super.removeWatches(path, watcher, watcherType, local);
+        } else {
+            zkHandle.removeWatches(path, watcher, watcherType, local);
+        }
+    }
+
+    @Override
+    public void removeWatches(String path, Watcher watcher, WatcherType watcherType, boolean
local, VoidCallback cb, Object ctx) {
+        ZooKeeper zkHandle = zk.get();
+        if (null == zkHandle) {
+            ZooKeeperClient.super.removeWatches(path, watcher, watcherType, local, cb, ctx);
+        } else {
+            zkHandle.removeWatches(path, watcher, watcherType, local, cb, ctx);
+        }
+    }
+
+    @Override
+    public void removeAllWatches(String path, WatcherType watcherType, boolean local)
+            throws InterruptedException, KeeperException {
+        ZooKeeper zkHandle = zk.get();
+        if (null == zkHandle) {
+            ZooKeeperClient.super.removeAllWatches(path, watcherType, local);
+        } else {
+            zkHandle.removeAllWatches(path, watcherType, local);
+        }
+    }
+
+    @Override
+    public void removeAllWatches(String path, WatcherType watcherType, boolean local, VoidCallback
cb, Object ctx) {
+        ZooKeeper zkHandle = zk.get();
+        if (null == zkHandle) {
+            ZooKeeperClient.super.removeAllWatches(path, watcherType, local, cb, ctx);
+        } else {
+            zkHandle.removeAllWatches(path, watcherType, local, cb, ctx);
+        }
+    }
+
+
 }

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/1e4ccaf1/bookkeeper-server/src/test/java/org/apache/bookkeeper/zookeeper/TestRetryPolicy.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/zookeeper/TestRetryPolicy.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/zookeeper/TestRetryPolicy.java
new file mode 100644
index 0000000..7b36ed1
--- /dev/null
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/zookeeper/TestRetryPolicy.java
@@ -0,0 +1,54 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.bookkeeper.zookeeper;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class TestRetryPolicy {
+
+    private static void assertTimeRange(long waitTime, long minTime, long maxTime) {
+        assertTrue(waitTime >= minTime);
+        assertTrue(waitTime <= maxTime);
+    }
+
+    @Test(timeout = 60000)
+    public void testExponentialBackoffRetryPolicy() throws Exception {
+        RetryPolicy policy = new ExponentialBackoffRetryPolicy(1000, Integer.MAX_VALUE);
+        assertTimeRange(policy.nextRetryWaitTime(30, 2000), 1000L, (long) (1000 * Math.pow(2,
31)));
+        assertTimeRange(policy.nextRetryWaitTime(31, 2000), 1000L, (long) (1000 * Math.pow(2,
32)));
+        assertTimeRange(policy.nextRetryWaitTime(32, 2000), 1000L, (long) (1000 * Math.pow(2,
33)));
+        assertTimeRange(policy.nextRetryWaitTime(127, 2000), 1000L, 1000L);
+        assertTimeRange(policy.nextRetryWaitTime(128, 2000), 1000L, 2000L);
+        assertTimeRange(policy.nextRetryWaitTime(129, 2000), 1000L, 4000L);
+    }
+
+    @Test(timeout = 60000)
+    public void testBoundExponentialBackoffRetryPolicy() throws Exception {
+        RetryPolicy policy = new BoundExponentialBackoffRetryPolicy(1000, 2000, Integer.MAX_VALUE);
+        assertTimeRange(policy.nextRetryWaitTime(30, 2000), 1000L, 2000L);
+        assertTimeRange(policy.nextRetryWaitTime(31, 2000), 1000L, 2000L);
+        assertTimeRange(policy.nextRetryWaitTime(32, 2000), 1000L, 2000L);
+        assertTimeRange(policy.nextRetryWaitTime(127, 2000), 1000L, 1000L);
+        assertTimeRange(policy.nextRetryWaitTime(128, 2000), 1000L, 2000L);
+        assertTimeRange(policy.nextRetryWaitTime(129, 2000), 1000L, 2000L);
+    }
+}

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/1e4ccaf1/bookkeeper-server/src/test/java/org/apache/bookkeeper/zookeeper/TestZooKeeperClient.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/zookeeper/TestZooKeeperClient.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/zookeeper/TestZooKeeperClient.java
index d829db5..fae5888 100644
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/zookeeper/TestZooKeeperClient.java
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/zookeeper/TestZooKeeperClient.java
@@ -30,6 +30,7 @@ import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.bookkeeper.stats.NullStatsLogger;
 import org.apache.bookkeeper.test.ZooKeeperUtil;
+import org.apache.zookeeper.AsyncCallback.Create2Callback;
 import org.apache.zookeeper.AsyncCallback.Children2Callback;
 import org.apache.zookeeper.AsyncCallback.DataCallback;
 import org.apache.zookeeper.AsyncCallback.StatCallback;
@@ -164,7 +165,7 @@ public class TestZooKeeperClient extends TestCase {
 
         Assert.assertFalse("Client doesn't receive expire event from ZooKeeper.",
                 client.getState().isConnected());
-        
+
         try {
             client.exists("/tmp", false);
             Assert.fail("Should fail due to connection loss.");
@@ -223,9 +224,14 @@ public class TestZooKeeperClient extends TestCase {
         client.create(path + "/children", data, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
 
         expireZooKeeperSession(client, timeout);
+        logger.info("Create children under znode " + path);
+        client.create(path + "/children2", data, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT,
new Stat());
+
+        expireZooKeeperSession(client, timeout);
         List<String> children = client.getChildren(path, false, newStat);
-        Assert.assertEquals(1, children.size());
-        Assert.assertEquals("children", children.get(0));
+        Assert.assertEquals(2, children.size());
+        Assert.assertTrue(children.contains("children"));
+        Assert.assertTrue(children.contains("children2"));
         logger.info("Get children under znode " + path);
 
         expireZooKeeperSession(client, timeout);
@@ -287,6 +293,23 @@ public class TestZooKeeperClient extends TestCase {
         logger.info("Created znode " + path);
 
         expireZooKeeperSession(client, timeout);
+        logger.info("Create znode " + path);
+        final CountDownLatch create2Latch = new CountDownLatch(1);
+        client.create(path, data, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT,
+                new Create2Callback() {
+
+            @Override
+            public void processResult(int rc, String path, Object ctx, String name, Stat
stat) {
+                if (KeeperException.Code.NODEEXISTS.intValue() == rc) {
+                    create2Latch.countDown();
+                }
+            }
+
+        }, null);
+        create2Latch.await();
+        logger.info("Created znode " + path);
+
+        expireZooKeeperSession(client, timeout);
         logger.info("Exists znode " + path);
         final CountDownLatch existsLatch = new CountDownLatch(1);
         client.exists(path, false, new StatCallback() {

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/1e4ccaf1/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 298520b..10e0f67 100644
--- a/pom.xml
+++ b/pom.xml
@@ -44,7 +44,7 @@
     <protobuf.version>2.6.1</protobuf.version>
     <guava.version>13.0.1</guava.version>
     <netty.version>3.9.4.Final</netty.version>
-    <zookeeper.version>3.4.6</zookeeper.version>
+    <zookeeper.version>3.5.1-alpha</zookeeper.version>
   </properties>
   <url>http://zookeeper.apache.org/bookkeeper</url>
   <build>


Mime
View raw message