diff --git ql/src/java/org/apache/hadoop/hive/ql/Driver.java ql/src/java/org/apache/hadoop/hive/ql/Driver.java index a800046..a2ce71d 100644 --- ql/src/java/org/apache/hadoop/hive/ql/Driver.java +++ ql/src/java/org/apache/hadoop/hive/ql/Driver.java @@ -645,9 +645,21 @@ public void run() { private int handleInterruption(String msg) { + return handleInterruptionWithHook(msg, null, null); + } + + private int handleInterruptionWithHook(String msg, HookContext hookContext, + PerfLogger perfLogger) { SQLState = "HY008"; //SQLState for cancel operation errorMessage = "FAILED: command has been interrupted: " + msg; console.printError(errorMessage); + if (hookContext != null) { + try { + invokeFailureHooks(perfLogger, hookContext, errorMessage, null); + } catch (Exception e) { + LOG.warn("Caught exception attempting to invoke Failure Hooks", e); + } + } return 1000; } @@ -1798,7 +1810,7 @@ public int execute(boolean deferClose) throws CommandNeedRetryException { // The main thread polls the TaskRunners to check if they have finished. if (isInterrupted()) { - return handleInterruption("before running tasks."); + return handleInterruptionWithHook("before running tasks.", hookContext, perfLogger); } DriverContext driverCxt = new DriverContext(ctx); driverCxt.prepare(plan); @@ -1848,7 +1860,7 @@ public int execute(boolean deferClose) throws CommandNeedRetryException { int exitVal = result.getExitVal(); if (isInterrupted()) { - return handleInterruption("when checking the execution result."); + return handleInterruptionWithHook("when checking the execution result.", hookContext, perfLogger); } if (exitVal != 0) { if (tsk.ifRetryCmdWhenFail()) { @@ -1873,6 +1885,9 @@ public int execute(boolean deferClose) throws CommandNeedRetryException { } else { setErrorMsgAndDetail(exitVal, result.getTaskError(), tsk); + if (driverCxt.isShutdown()) { + errorMessage = "FAILED: Operation cancelled. " + errorMessage; + } invokeFailureHooks(perfLogger, hookContext, errorMessage + Strings.nullToEmpty(tsk.getDiagnosticsMessage()), result.getTaskError()); SQLState = "08S01"; @@ -1961,7 +1976,7 @@ public int execute(boolean deferClose) throws CommandNeedRetryException { } catch (Throwable e) { executionError = true; if (isInterrupted()) { - return handleInterruption("during query execution: \n" + e.getMessage()); + return handleInterruptionWithHook("during query execution: \n" + e.getMessage(), hookContext, perfLogger); } ctx.restoreOriginalTracker();