bowenliang123 commented on code in PR #5398:
URL: https://github.com/apache/kyuubi/pull/5398#discussion_r1363091698
##########
kyuubi-server/src/main/scala/org/apache/kyuubi/operation/ExecuteStatement.scala:
##########
@@ -169,4 +169,45 @@ class ExecuteStatement(
}
override protected def eventEnabled: Boolean = true
+
+ private def startTimeoutCheck(isTimedOut: AtomicBoolean, interval: Long):
Unit = {
+ val checkTimeout = new Runnable {
+ override def run(): Unit = {
+ if (queryTimeout > 0) {
+ val execTime = System.currentTimeMillis() - startTime
+ if (!isTerminalState(state) && !isTimedOut.get &&
+ startTime > 0 && execTime >= queryTimeout) {
+ isTimedOut.set(true)
+ setToTimeoutState()
+ }
+ if (!isTimedOut.get && !isTerminalState(state)) {
+ timeoutCheckPool.schedule(this, interval, TimeUnit.MILLISECONDS)
+ }
+ }
+ }
+ }
+ timeoutCheckPool.schedule(
+ checkTimeout,
+ Duration(queryTimeout, TimeUnit.SECONDS).toMillis,
+ TimeUnit.MILLISECONDS)
+ }
+
+ private def setToTimeoutState(): Unit = {
+ // Clients less than version 2.1 have no HIVE-4924 Patch,
+ // no queryTimeout parameter and no TIMEOUT status.
+ // When the server enables kyuubi.operation.query.timeout,
+ // this will cause the client of the lower version to get stuck.
+ // Check thrift protocol version <= HIVE_CLI_SERVICE_PROTOCOL_V8(Hive
2.1.0),
+ // convert TIMEDOUT_STATE to CANCELED.
+ if (getProtocolVersion.getValue <= HIVE_CLI_SERVICE_PROTOCOL_V8.getValue) {
+ setState(OperationState.CANCELED)
+ } else {
+ setState(OperationState.TIMEOUT)
+ }
+ }
+}
+
+object ExecuteStatement {
+ private[kyuubi] lazy val timeoutCheckPool: ScheduledExecutorService =
Review Comment:
Change to use the `addTimeoutMonitor` method, which starts as a
single-thread executor pool and seems never closed. It seems never be closed
and it's opened for each ExecuteStatement operation.
Does it cause the thread leaks? Or let's force the timeout check in a
dedicated global ForkJoinPool ?
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]