Repository: hive Updated Branches: refs/heads/branch-1 19620f7bb -> 718bf34f6
HIVE-12583: HS2 ShutdownHookManager holds extra of Driver instance (Daniel Dai, reviewed by Sergey Shelukhin) Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/718bf34f Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/718bf34f Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/718bf34f Branch: refs/heads/branch-1 Commit: 718bf34f6690080172d1332bcb25c1d637a4c7fe Parents: 19620f7 Author: Daniel Dai <da...@hortonworks.com> Authored: Sat Dec 5 17:44:30 2015 -0800 Committer: Daniel Dai <da...@hortonworks.com> Committed: Sat Dec 5 17:44:30 2015 -0800 ---------------------------------------------------------------------- .../java/org/apache/hadoop/hive/ql/Driver.java | 28 +++++++++++--------- 1 file changed, 16 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/718bf34f/ql/src/java/org/apache/hadoop/hive/ql/Driver.java ---------------------------------------------------------------------- diff --git a/ql/src/java/org/apache/hadoop/hive/ql/Driver.java b/ql/src/java/org/apache/hadoop/hive/ql/Driver.java index c134653..4b032cc 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/Driver.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/Driver.java @@ -127,6 +127,7 @@ public class Driver implements CommandProcessor { static final private Log LOG = LogFactory.getLog(CLASS_NAME); static final private LogHelper console = new LogHelper(LOG); static final int SHUTDOWN_HOOK_PRIORITY = 0; + private Runnable shutdownRunner = null; private static final Object compileMonitor = new Object(); @@ -391,18 +392,18 @@ public class Driver implements CommandProcessor { // Initialize the transaction manager. This must be done before analyze is called. final HiveTxnManager txnManager = SessionState.get().initTxnMgr(conf); // In case when user Ctrl-C twice to kill Hive CLI JVM, we want to release locks - ShutdownHookManager.addShutdownHook( - new Runnable() { - @Override - public void run() { - try { - releaseLocksAndCommitOrRollback(ctx.getHiveLocks(), false, txnManager); - } catch (LockException e) { - LOG.warn("Exception when releasing locks in ShutdownHook for Driver: " + - e.getMessage()); - } - } - }, SHUTDOWN_HOOK_PRIORITY); + shutdownRunner = new Runnable() { + @Override + public void run() { + try { + releaseLocksAndCommitOrRollback(ctx.getHiveLocks(), false, txnManager); + } catch (LockException e) { + LOG.warn("Exception when releasing locks in ShutdownHook for Driver: " + + e.getMessage()); + } + } + }; + ShutdownHookManager.addShutdownHook(shutdownRunner, SHUTDOWN_HOOK_PRIORITY); command = new VariableSubstitution().substitute(conf, command); ctx = new Context(conf); @@ -1891,6 +1892,9 @@ public class Driver implements CommandProcessor { LOG.warn("Exception when releasing locking in destroy: " + e.getMessage()); } + if (shutdownRunner != null) { + ShutdownHookManager.removeShutdownHook(shutdownRunner); + } } }