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 3fb4ca4..220f13e 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/Driver.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/Driver.java @@ -129,6 +129,7 @@ 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(); @@ -395,18 +396,18 @@ public int compile(String command, boolean resetTaskIds) { // 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); // we set the hadoop caller context to the query id as soon as we have one. // initially, the caller context is the session id (when creating temp directories) @@ -1835,6 +1836,9 @@ public void destroy() { LOG.warn("Exception when releasing locking in destroy: " + e.getMessage()); } + if (shutdownRunner != null) { + ShutdownHookManager.removeShutdownHook(shutdownRunner); + } } }