This is an automated email from the ASF dual-hosted git repository.

kgyrtkirk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git


The following commit(s) were added to refs/heads/master by this push:
     new ffbbd84  HIVE-23727: Improve SQLOperation log handling when canceling 
background (#1272) (Zhihua Deng reviewed by Zoltan Haindrich)
ffbbd84 is described below

commit ffbbd84c2c6bd1d56989f2fd56608f75278ae546
Author: dengzh <dengzhhu...@gmail.com>
AuthorDate: Thu Jul 30 22:31:14 2020 +0800

    HIVE-23727: Improve SQLOperation log handling when canceling background 
(#1272) (Zhihua Deng reviewed by Zoltan Haindrich)
---
 .../hive/service/cli/operation/SQLOperation.java   | 28 ++++++++++++----------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git 
a/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java 
b/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java
index a76878a..0021828 100644
--- a/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java
+++ b/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java
@@ -172,10 +172,10 @@ public class SQLOperation extends 
ExecuteStatementOperation {
         timeoutExecutor.schedule(() -> {
           try {
             final String queryId = queryState.getQueryId();
-            log.info("Query timed out after: " + queryTimeout + " seconds. 
Cancelling the execution now: " + queryId);
+            log.info("Query timed out after: {} seconds. Cancelling the 
execution now: {}", queryTimeout, queryId);
             SQLOperation.this.cancel(OperationState.TIMEDOUT);
           } catch (HiveSQLException e) {
-            log.error("Error cancelling the query after timeout: " + 
queryTimeout + " seconds", e);
+            log.error("Error cancelling the query after timeout: {} seconds", 
queryTimeout, e);
           }
           return null;
         }, queryTimeout, TimeUnit.SECONDS);
@@ -206,6 +206,9 @@ public class SQLOperation extends ExecuteStatementOperation 
{
       throw toSQLException("Error while compiling statement", e);
     } catch (Throwable e) {
       setState(OperationState.ERROR);
+      if (e instanceof OutOfMemoryError) {
+        throw e;
+      }
       throw new HiveSQLException("Error running query", e);
     }
   }
@@ -229,11 +232,8 @@ public class SQLOperation extends 
ExecuteStatementOperation {
        * may return a non-zero response code. We will simply return if the 
operation state is
        * CANCELED, TIMEDOUT, CLOSED or FINISHED, otherwise throw an exception
        */
-      if ((getStatus().getState() == OperationState.CANCELED)
-          || (getStatus().getState() == OperationState.TIMEDOUT)
-          || (getStatus().getState() == OperationState.CLOSED)
-          || (getStatus().getState() == OperationState.FINISHED)) {
-        log.warn("Ignore exception in terminal state", e);
+      if (getStatus().getState().isTerminal()) {
+        log.warn("Ignore exception in terminal state: {}", 
getStatus().getState(), e);
         return;
       }
       setState(OperationState.ERROR);
@@ -241,6 +241,8 @@ public class SQLOperation extends ExecuteStatementOperation 
{
         throw toSQLException("Error while compiling statement", 
(CommandProcessorException)e);
       } else if (e instanceof HiveSQLException) {
         throw (HiveSQLException) e;
+      } else if (e instanceof OutOfMemoryError) {
+        throw (OutOfMemoryError) e;
       } else {
         throw new HiveSQLException("Error running query", e);
       }
@@ -341,7 +343,7 @@ public class SQLOperation extends ExecuteStatementOperation 
{
         currentUGI.doAs(doAsAction);
       } catch (Exception e) {
         setOperationException(new HiveSQLException(e));
-        log.error("Error running hive query as user : " + 
currentUGI.getShortUserName(), e);
+        log.error("Error running hive query as user : {}", 
currentUGI.getShortUserName(), e);
       } finally {
         /**
          * We'll cache the ThreadLocal RawStore object for this background 
thread for an orderly cleanup
@@ -383,9 +385,9 @@ public class SQLOperation extends ExecuteStatementOperation 
{
         boolean success = backgroundHandle.cancel(true);
         String queryId = queryState.getQueryId();
         if (success) {
-          log.info("The running operation has been successfully interrupted: " 
+ queryId);
-        } else if (state == OperationState.CANCELED) {
-          log.info("The running operation could not be cancelled, typically 
because it has already completed normally: " + queryId);
+          log.info("The running operation has been successfully interrupted: 
{}", queryId);
+        } else {
+          log.info("The running operation could not be cancelled, typically 
because it has already completed normally: {}", queryId);
         }
       }
     }
@@ -415,12 +417,12 @@ public class SQLOperation extends 
ExecuteStatementOperation {
     String queryId = null;
     if (stateAfterCancel == OperationState.CANCELED) {
       queryId = queryState.getQueryId();
-      log.info("Cancelling the query execution: " + queryId);
+      log.info("Cancelling the query execution: {}", queryId);
     }
     cleanup(stateAfterCancel);
     cleanupOperationLog(operationLogCleanupDelayMs);
     if (stateAfterCancel == OperationState.CANCELED) {
-      log.info("Successfully cancelled the query: " + queryId);
+      log.info("Successfully cancelled the query: {}", queryId);
     }
   }
 

Reply via email to