juliuszsompolski commented on a change in pull request #25611: 
[SPARK-28901][SQL] SparkThriftServer's Cancel SQL Operation show it in JDBC Tab 
UI
URL: https://github.com/apache/spark/pull/25611#discussion_r319481056
 
 

 ##########
 File path: 
sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/SparkExecuteStatementOperation.scala
 ##########
 @@ -249,32 +257,43 @@ private[hive] class SparkExecuteStatementOperation(
       }
       dataTypes = result.queryExecution.analyzed.output.map(_.dataType).toArray
     } catch {
-      case e: HiveSQLException =>
-        if (getStatus().getState() == OperationState.CANCELED) {
+      // Actually do need to catch Throwable as some failures don't inherit 
from Exception and
+      // HiveServer will silently swallow them.
+      case e: Throwable =>
+        val currentState = getStatus().getState()
+        if (currentState == OperationState.CANCELED ||
+          currentState == OperationState.CLOSED ||
+          currentState == OperationState.FINISHED) {
+          // This may happen if the execution was cancelled, and then closed 
from another thread.
+          logWarning(s"Ignore exception in terminal state with $statementId: 
$e")
           return
         } else {
+          logError(s"Error executing query, currentState $currentState, ", e)
           setState(OperationState.ERROR)
           HiveThriftServer2.listener.onStatementError(
             statementId, e.getMessage, SparkUtils.exceptionString(e))
-          throw e
+          if (e.isInstanceOf[HiveSQLException]) {
+            throw e.asInstanceOf[HiveSQLException]
+          } else {
+            throw new HiveSQLException("Error running query: " + e.toString, e)
+          }
         }
-      // Actually do need to catch Throwable as some failures don't inherit 
from Exception and
-      // HiveServer will silently swallow them.
-      case e: Throwable =>
-        val currentState = getStatus().getState()
-        logError(s"Error executing query, currentState $currentState, ", e)
-        setState(OperationState.ERROR)
-        HiveThriftServer2.listener.onStatementError(
-          statementId, e.getMessage, SparkUtils.exceptionString(e))
-        throw new HiveSQLException(e.toString)
     }
-    setState(OperationState.FINISHED)
-    HiveThriftServer2.listener.onStatementFinish(statementId)
+    synchronized {
+      if (!getStatus.getState.isTerminal) {
+        setState(OperationState.FINISHED)
+        HiveThriftServer2.listener.onStatementFinish(statementId)
+      }
+    }
   }
 
   override def cancel(): Unit = {
-    logInfo(s"Cancel '$statement' with $statementId")
-    cleanup(OperationState.CANCELED)
+    synchronized {
+      if (!getStatus.getState.isTerminal) {
+        setState(OperationState.FINISHED)
+        HiveThriftServer2.listener.onStatementFinish(statementId)
 
 Review comment:
   Cancel needs to set state CANCELED and call `cleanup()` for the execution 
thread to get notified (through backgroundHandle.cancel).

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to