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_r319933080
##########
File path:
sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/HiveThriftServer2.scala
##########
@@ -239,6 +239,15 @@ object HiveThriftServer2 extends Logging {
executionList(id).state = ExecutionState.COMPILED
}
+ def onStatementCanceled(id: String): Unit = {
+ synchronized {
+ executionList(id).finishTimestamp = System.currentTimeMillis
+ executionList(id).state = ExecutionState.CANCELED
+ totalRunning -= 1
Review comment:
@AngersZhuuuu I think it's easy to get something wrong with the
`totalRunning` counter. Even if we covered all the cases now, it's hard to
reason about all the possible paths, and easy to break. I would suggest to
count it on the fly based on status, like I proposed before.
```
def getOnlineSessionNum: Int = synchronized {
sessionList.count(_._2.finishTimestamp == 0)
}
def isExecutionActive(execInfo: ExecutionInfo): Boolean = {
!(execInfo.state == ExecutionState.FAILED ||
execInfo.state == ExecutionState.CANCELED ||
execInfo.closeTimestamp != 0)
}
/**
* When an error or a cancellation occurs, we set the finishTimestamp of
the statement.
* Therefore, when we count the number of running statements, we need to
exclude errors and
* cancellations and count all statements that have not been closed so
far.
*/
def getTotalRunning: Int = synchronized {
executionList.count {
case (_, v) => isExecutionActive(v)
}
}
```
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]