You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by el...@apache.org on 2014/05/15 20:34:39 UTC

[02/10] git commit: ACCUMULO-2764 Wrap the MAC process termination in a Callable to get timeout semantics

ACCUMULO-2764 Wrap the MAC process termination in a Callable to get timeout semantics


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

Branch: refs/heads/1.6.1-SNAPSHOT
Commit: 57f27635b0414ae3198995f932ccac2501eb73cd
Parents: 72fd01f
Author: Josh Elser <el...@apache.org>
Authored: Thu May 15 12:35:03 2014 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Thu May 15 12:56:09 2014 -0400

----------------------------------------------------------------------
 .../minicluster/MiniAccumuloCluster.java        | 61 +++++++++++++++++---
 1 file changed, 53 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/57f27635/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java
----------------------------------------------------------------------
diff --git a/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java b/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java
index e2b2f83..9b0e196 100644
--- a/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java
+++ b/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java
@@ -32,6 +32,13 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Properties;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.FutureTask;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 
 import org.apache.accumulo.core.Constants;
 import org.apache.accumulo.core.conf.Property;
@@ -43,6 +50,7 @@ import org.apache.accumulo.server.util.Initialize;
 import org.apache.accumulo.server.util.PortUtils;
 import org.apache.accumulo.server.util.time.SimpleTimer;
 import org.apache.accumulo.start.Main;
+import org.apache.log4j.Logger;
 import org.apache.zookeeper.server.ZooKeeperServerMain;
 
 /**
@@ -52,6 +60,7 @@ import org.apache.zookeeper.server.ZooKeeperServerMain;
  * @since 1.5.0
  */
 public class MiniAccumuloCluster {
+  private static final Logger log = Logger.getLogger(MiniAccumuloCluster.class);
   
   private static final String INSTANCE_SECRET = "DONTTELL";
   private static final String INSTANCE_NAME = "miniInstance";
@@ -357,17 +366,32 @@ public class MiniAccumuloCluster {
   
   public void stop() throws IOException, InterruptedException {
     if (zooKeeperProcess != null) {
-      zooKeeperProcess.destroy();
-      zooKeeperProcess.waitFor();
+      try {
+        stopProcessWithTimeout(zooKeeperProcess, 30, TimeUnit.SECONDS);
+      } catch (ExecutionException e) {
+        log.warn("ZooKeeper did not fully stop after 30 seconds", e);
+      } catch (TimeoutException e) {
+        log.warn("ZooKeeper did not fully stop after 30 seconds", e);
+      }
     }
     if (masterProcess != null) {
-      masterProcess.destroy();
-      masterProcess.waitFor();
+      try {
+        stopProcessWithTimeout(masterProcess, 30, TimeUnit.SECONDS);
+      } catch (ExecutionException e) {
+        log.warn("Master did not fully stop after 30 seconds", e);
+      } catch (TimeoutException e) {
+        log.warn("Master did not fully stop after 30 seconds", e);
+      }
     }
     if (tabletServerProcesses != null) {
       for (Process tserver : tabletServerProcesses) {
-        tserver.destroy();
-        tserver.waitFor();
+        try {
+          stopProcessWithTimeout(tserver, 30, TimeUnit.SECONDS);
+        } catch (ExecutionException e) {
+          log.warn("TabletServer did not fully stop after 30 seconds", e);
+        } catch (TimeoutException e) {
+          log.warn("TabletServer did not fully stop after 30 seconds", e);
+        }
       }
     }
     
@@ -375,8 +399,29 @@ public class MiniAccumuloCluster {
       lw.flush();
 
     if (gcProcess != null) {
-      gcProcess.destroy();
-      gcProcess.waitFor();
+      try {
+        stopProcessWithTimeout(gcProcess, 30, TimeUnit.SECONDS);
+      } catch (ExecutionException e) {
+        log.warn("GarbageCollector did not fully stop after 30 seconds", e);
+      } catch (TimeoutException e) {
+        log.warn("GarbageCollector did not fully stop after 30 seconds", e);
+      }
     }
   }
+
+  private final ExecutorService executor = Executors.newSingleThreadExecutor();
+
+  private int stopProcessWithTimeout(final Process proc, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
+    FutureTask<Integer> future = new FutureTask<Integer>(new Callable<Integer>() {
+        @Override
+        public Integer call() throws InterruptedException {
+          proc.destroy();
+          return proc.waitFor();
+        }
+    });
+
+    executor.execute(future);
+
+    return future.get(timeout, unit);
+  }
 }