accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject [1/3] git commit: ACCUMULO-3233 retry to start the minicluster when ZK fails to start
Date Wed, 15 Oct 2014 01:03:52 GMT
Repository: accumulo
Updated Branches:
  refs/heads/1.6 ecd9f7b10 -> 0348e3ea3
  refs/heads/master 1f9630d4c -> a21d2d3cf


ACCUMULO-3233 retry to start the minicluster when ZK fails to start

There's a race condition between choosing a random port and when
zookeeper actually binds to that port in which another process
could bind to the port first. This results in accumulo initialization
to fail because ZK died.

This is a very infrequent occurrence, so we can just retry a few times
and that should reduce the frequency in which we see it happen.


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

Branch: refs/heads/1.6
Commit: 0348e3ea36e21edf524c3f6085914a5680d93b01
Parents: ecd9f7b
Author: Josh Elser <elserj@apache.org>
Authored: Tue Oct 14 20:39:54 2014 -0400
Committer: Josh Elser <elserj@apache.org>
Committed: Tue Oct 14 20:39:54 2014 -0400

----------------------------------------------------------------------
 .../impl/MiniAccumuloClusterImpl.java           | 13 +++---
 .../impl/ZooKeeperBindException.java            | 41 ++++++++++++++++++
 .../test/functional/ConfigurableMacIT.java      | 23 ++++++++--
 .../accumulo/test/functional/SimpleMacIT.java   | 44 ++++++++++++++------
 4 files changed, 100 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/0348e3ea/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniAccumuloClusterImpl.java
----------------------------------------------------------------------
diff --git a/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniAccumuloClusterImpl.java
b/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniAccumuloClusterImpl.java
index 07c5742..5d8501e 100644
--- a/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniAccumuloClusterImpl.java
+++ b/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniAccumuloClusterImpl.java
@@ -60,8 +60,8 @@ import org.apache.accumulo.core.client.impl.MasterClient;
 import org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException;
 import org.apache.accumulo.core.client.security.tokens.PasswordToken;
 import org.apache.accumulo.core.conf.Property;
-import org.apache.accumulo.core.master.thrift.MasterGoalState;
 import org.apache.accumulo.core.master.thrift.MasterClientService;
+import org.apache.accumulo.core.master.thrift.MasterGoalState;
 import org.apache.accumulo.core.master.thrift.MasterMonitorInfo;
 import org.apache.accumulo.core.util.Daemon;
 import org.apache.accumulo.core.util.Pair;
@@ -97,7 +97,7 @@ import com.google.common.collect.Maps;
 /**
  * A utility class that will create Zookeeper and Accumulo processes that write all of their
data to a single local directory. This class makes it easy to test
  * code against a real Accumulo instance. Its much more accurate for testing than {@link
org.apache.accumulo.core.client.mock.MockAccumulo}, but much slower.
- * 
+ *
  * @since 1.6.0
  */
 public class MiniAccumuloClusterImpl implements AccumuloCluster {
@@ -318,7 +318,7 @@ public class MiniAccumuloClusterImpl implements AccumuloCluster {
   }
 
   /**
-   * 
+   *
    * @param dir
    *          An empty or nonexistant temp directoy that Accumulo and Zookeeper can store
data in. Creating the directory is left to the user. Java 7, Guava,
    *          and Junit provide methods for creating temporary directories.
@@ -439,7 +439,7 @@ public class MiniAccumuloClusterImpl implements AccumuloCluster {
 
   /**
    * Starts Accumulo and Zookeeper processes. Can only be called once.
-   * 
+   *
    * @throws IllegalStateException
    *           if already started
    */
@@ -481,7 +481,8 @@ public class MiniAccumuloClusterImpl implements AccumuloCluster {
             break;
         } catch (Exception e) {
           if (System.currentTimeMillis() - startTime >= config.getZooKeeperStartupTime())
{
-            throw new RuntimeException("Zookeeper did not start within " + (config.getZooKeeperStartupTime()/1000)
+ " seconds. Check the logs in " + config.getLogDir() + " for errors.  Last exception: " +
e);
+            throw new ZooKeeperBindException("Zookeeper did not start within " + (config.getZooKeeperStartupTime()
/ 1000) + " seconds. Check the logs in "
+                + config.getLogDir() + " for errors.  Last exception: " + e);
           }
           UtilWaitThread.sleep(250);
         } finally {
@@ -708,7 +709,7 @@ public class MiniAccumuloClusterImpl implements AccumuloCluster {
 
   /**
    * Utility method to get a connector to the MAC.
-   * 
+   *
    * @since 1.6.0
    */
   @Override

http://git-wip-us.apache.org/repos/asf/accumulo/blob/0348e3ea/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/ZooKeeperBindException.java
----------------------------------------------------------------------
diff --git a/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/ZooKeeperBindException.java
b/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/ZooKeeperBindException.java
new file mode 100644
index 0000000..21bc972
--- /dev/null
+++ b/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/ZooKeeperBindException.java
@@ -0,0 +1,41 @@
+/*
+ * 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.accumulo.minicluster.impl;
+
+/**
+ * Thrown when we fail to connect to ZooKeeper (assuming the root cause is that ZooKeeper
failed to bind to its port)
+ */
+public class ZooKeeperBindException extends RuntimeException {
+
+  private static final long serialVersionUID = 1L;
+
+  public ZooKeeperBindException() {
+  }
+
+  public ZooKeeperBindException(String message) {
+    super(message);
+  }
+
+  public ZooKeeperBindException(Throwable cause) {
+    super(cause);
+  }
+
+  public ZooKeeperBindException(String message, Throwable cause) {
+    super(message, cause);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/0348e3ea/test/src/test/java/org/apache/accumulo/test/functional/ConfigurableMacIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/ConfigurableMacIT.java
b/test/src/test/java/org/apache/accumulo/test/functional/ConfigurableMacIT.java
index 59b0977..0d0e047 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/ConfigurableMacIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/ConfigurableMacIT.java
@@ -31,6 +31,7 @@ import org.apache.accumulo.core.conf.Property;
 import org.apache.accumulo.core.util.MonitorUtil;
 import org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl;
 import org.apache.accumulo.minicluster.impl.MiniAccumuloConfigImpl;
+import org.apache.accumulo.minicluster.impl.ZooKeeperBindException;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.KeeperException;
@@ -48,8 +49,25 @@ public class ConfigurableMacIT extends AbstractMacIT {
 
   @Before
   public void setUp() throws Exception {
-    MiniAccumuloConfigImpl cfg = new MiniAccumuloConfigImpl(
-        createTestDir(this.getClass().getName() + "_" + this.testName.getMethodName()), ROOT_PASSWORD);
+    createMiniAccumulo();
+    Exception lastException = null;
+    for (int i = 0; i < 3; i++) {
+      try {
+        cluster.start();
+        return;
+      } catch (ZooKeeperBindException e) {
+        lastException = e;
+        log.warn("Failed to start MiniAccumuloCluster, assumably due to ZooKeeper issues",
lastException);
+        Thread.sleep(3000);
+        createMiniAccumulo();
+      }
+    }
+    throw new RuntimeException("Failed to start MiniAccumuloCluster after three attempts",
lastException);
+  }
+
+  private void createMiniAccumulo() throws Exception {
+    // createTestDir will give us a empty directory, we don't need to clean it up ourselves
+    MiniAccumuloConfigImpl cfg = new MiniAccumuloConfigImpl(createTestDir(this.getClass().getName()
+ "_" + this.testName.getMethodName()), ROOT_PASSWORD);
     cfg.setNativeLibPaths(NativeMapIT.nativeMapLocation().getAbsolutePath());
     Configuration coreSite = new Configuration(false);
     configure(cfg, coreSite);
@@ -66,7 +84,6 @@ public class ConfigurableMacIT extends AbstractMacIT {
       out.close();
     }
     beforeClusterStart(cfg);
-    cluster.start();
   }
 
   @After

http://git-wip-us.apache.org/repos/asf/accumulo/blob/0348e3ea/test/src/test/java/org/apache/accumulo/test/functional/SimpleMacIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/SimpleMacIT.java b/test/src/test/java/org/apache/accumulo/test/functional/SimpleMacIT.java
index b166ffd..1dd9562 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/SimpleMacIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/SimpleMacIT.java
@@ -27,6 +27,7 @@ import org.apache.accumulo.minicluster.MiniAccumuloCluster;
 import org.apache.accumulo.minicluster.MiniAccumuloInstance;
 import org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl;
 import org.apache.accumulo.minicluster.impl.MiniAccumuloConfigImpl;
+import org.apache.accumulo.minicluster.impl.ZooKeeperBindException;
 import org.apache.log4j.Logger;
 import org.junit.After;
 import org.junit.AfterClass;
@@ -51,22 +52,41 @@ public class SimpleMacIT extends AbstractMacIT {
   public static synchronized void setUp() throws Exception {
     if (getInstanceOneConnector() == null && cluster == null) {
       log.info("No shared instance available, falling back to creating MAC");
-      folder = createSharedTestDir(SimpleMacIT.class.getName());
-      MiniAccumuloConfigImpl cfg = new MiniAccumuloConfigImpl(folder, ROOT_PASSWORD);
-      cfg.setNativeLibPaths(NativeMapIT.nativeMapLocation().getAbsolutePath());
-      cfg.setProperty(Property.TSERV_NATIVEMAP_ENABLED, Boolean.TRUE.toString());
-      configureForEnvironment(cfg, SimpleMacIT.class, createSharedTestDir(SimpleMacIT.class.getName()
+ "-ssl"));
-      cluster = new MiniAccumuloClusterImpl(cfg);
-      cluster.start();
-      Runtime.getRuntime().addShutdownHook(new Thread() {
-        @Override
-        public void run() {
-          cleanUp(cluster);
+      createMiniAccumulo();
+      Exception lastException = null;
+      for (int i = 0; i < 3; i++) {
+        try {
+          cluster.start();
+
+          Runtime.getRuntime().addShutdownHook(new Thread() {
+            @Override
+            public void run() {
+              cleanUp(cluster);
+            }
+          });
+
+          return;
+        } catch (ZooKeeperBindException e) {
+          lastException = e;
+          log.warn("Failed to start MiniAccumuloCluster, assumably due to ZooKeeper issues",
lastException);
+          Thread.sleep(3000);
+          createMiniAccumulo();
         }
-      });
+      }
+
+      throw new RuntimeException("Failed to start MiniAccumuloCluster after three attempts",
lastException);
     }
   }
 
+  private static void createMiniAccumulo() throws Exception {
+    folder = createSharedTestDir(SimpleMacIT.class.getName());
+    MiniAccumuloConfigImpl cfg = new MiniAccumuloConfigImpl(folder, ROOT_PASSWORD);
+    cfg.setNativeLibPaths(NativeMapIT.nativeMapLocation().getAbsolutePath());
+    cfg.setProperty(Property.TSERV_NATIVEMAP_ENABLED, Boolean.TRUE.toString());
+    configureForEnvironment(cfg, SimpleMacIT.class, createSharedTestDir(SimpleMacIT.class.getName()
+ "-ssl"));
+    cluster = new MiniAccumuloClusterImpl(cfg);
+  }
+
   @Before
   public void logTestInfo() {
     if (cluster != null)


Mime
View raw message