Return-Path: X-Original-To: apmail-drill-commits-archive@www.apache.org Delivered-To: apmail-drill-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 1E0D817CC8 for ; Thu, 26 Mar 2015 06:26:44 +0000 (UTC) Received: (qmail 66577 invoked by uid 500); 26 Mar 2015 06:26:41 -0000 Delivered-To: apmail-drill-commits-archive@drill.apache.org Received: (qmail 66504 invoked by uid 500); 26 Mar 2015 06:26:41 -0000 Mailing-List: contact commits-help@drill.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: commits@drill.apache.org Delivered-To: mailing list commits@drill.apache.org Received: (qmail 66378 invoked by uid 99); 26 Mar 2015 06:26:40 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Mar 2015 06:26:40 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A624DE2F04; Thu, 26 Mar 2015 06:26:40 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jacques@apache.org To: commits@drill.apache.org Date: Thu, 26 Mar 2015 06:26:47 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [08/10] drill git commit: DRILL-2547: Don't allow Drill to shut down while queries are still executing This will cause Drillbit.close() to block until all currently executing fragments have completed. DRILL-2547: Don't allow Drill to shut down while queries are still executing This will cause Drillbit.close() to block until all currently executing fragments have completed. WorkManager - added waitForExit() and indicateIfSafeToExit(), which use a latch to wait to shut down if there are active fragments - waitForExit() times out after 5 seconds Drillbit - call WorkManager.waitForExit() in close() Project: http://git-wip-us.apache.org/repos/asf/drill/repo Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/26463d38 Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/26463d38 Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/26463d38 Branch: refs/heads/0.8.0 Commit: 26463d38f356c138ba42b78144842950c33e1cef Parents: f89c59b Author: Chris Westin Authored: Tue Mar 24 16:21:33 2015 -0700 Committer: Jacques Nadeau Committed: Wed Mar 25 21:11:23 2015 -0700 ---------------------------------------------------------------------- .../org/apache/drill/exec/server/Drillbit.java | 3 ++ .../org/apache/drill/exec/work/WorkManager.java | 47 +++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/drill/blob/26463d38/exec/java-exec/src/main/java/org/apache/drill/exec/server/Drillbit.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/Drillbit.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/Drillbit.java index 0f531b8..958f2dc 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/Drillbit.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/Drillbit.java @@ -252,6 +252,9 @@ public class Drillbit implements AutoCloseable { return; } + // wait for anything that is running to complete + manager.waitToExit(); + if (coord != null && registrationHandle != null) { coord.unregister(registrationHandle); } http://git-wip-us.apache.org/repos/asf/drill/blob/26463d38/exec/java-exec/src/main/java/org/apache/drill/exec/work/WorkManager.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/work/WorkManager.java b/exec/java-exec/src/main/java/org/apache/drill/exec/work/WorkManager.java index 231e49a..e2bcec3 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/work/WorkManager.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/work/WorkManager.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; @@ -168,6 +169,46 @@ public class WorkManager implements AutoCloseable { return dContext; } + private CountDownLatch exitLatch = null; // used to wait to exit when things are still running + + /** + * Waits until it is safe to exit. Blocks until all currently running fragments have completed. + * + *

This is intended to be used by {@link org.apache.drill.exec.server.Drillbit#close()}.

+ */ + public void waitToExit() { + synchronized(this) { + if (queries.isEmpty() && runningFragments.isEmpty()) { + return; + } + + exitLatch = new CountDownLatch(1); + } + + while(true) { + try { + exitLatch.await(5, TimeUnit.SECONDS); + } catch(InterruptedException e) { + // keep waiting + } + break; + } + } + + /** + * If it is safe to exit, and the exitLatch is in use, signals it so that waitToExit() will + * unblock. + */ + private void indicateIfSafeToExit() { + synchronized(this) { + if (exitLatch != null) { + if (queries.isEmpty() && runningFragments.isEmpty()) { + exitLatch.countDown(); + } + } + } + } + /** * Narrowed interface to WorkManager that is made available to tasks it is managing. */ @@ -196,8 +237,11 @@ public class WorkManager implements AutoCloseable { final QueryId queryId = foreman.getQueryId(); final boolean wasRemoved = queries.remove(queryId, foreman); if (!wasRemoved) { - throw new IllegalStateException("Couldn't find retiring Foreman for query " + queryId); + logger.warn("Couldn't find retiring Foreman for query " + queryId); +// throw new IllegalStateException("Couldn't find retiring Foreman for query " + queryId); } + + indicateIfSafeToExit(); } public Foreman getForemanForQueryId(final QueryId queryId) { @@ -219,6 +263,7 @@ public class WorkManager implements AutoCloseable { @Override protected void cleanup() { runningFragments.remove(fragmentHandle); + indicateIfSafeToExit(); } }); }