Return-Path: X-Original-To: apmail-accumulo-commits-archive@www.apache.org Delivered-To: apmail-accumulo-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0023311E22 for ; Fri, 16 May 2014 22:18:46 +0000 (UTC) Received: (qmail 30873 invoked by uid 500); 16 May 2014 10:17:14 -0000 Delivered-To: apmail-accumulo-commits-archive@accumulo.apache.org Received: (qmail 23853 invoked by uid 500); 16 May 2014 10:16:45 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 14047 invoked by uid 99); 16 May 2014 10:16:09 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 May 2014 10:16:09 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 5210D91E932; Thu, 15 May 2014 18:34:38 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: elserj@apache.org To: commits@accumulo.apache.org Date: Thu, 15 May 2014 18:34:40 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [03/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/master Commit: 57f27635b0414ae3198995f932ccac2501eb73cd Parents: 72fd01f Author: Josh Elser Authored: Thu May 15 12:35:03 2014 -0400 Committer: Josh Elser 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 future = new FutureTask(new Callable() { + @Override + public Integer call() throws InterruptedException { + proc.destroy(); + return proc.waitFor(); + } + }); + + executor.execute(future); + + return future.get(timeout, unit); + } }