You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by ch...@apache.org on 2026/10/28 13:53:51 UTC
(kyuubi) branch master updated: [KYUUBI #7811] JDBC engine should cancel the statement on query timeout
This is an automated email from the ASF dual-hosted git repository.
pan3793 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi.git
The following commit(s) were added to refs/heads/master by this push:
new 84e7ee16fc [KYUUBI #7811] JDBC engine should cancel the statement on query timeout
84e7ee16fc is described below
commit 84e7ee16fcb8f038e21c54f1140b7fc941b16bc2
Author: cxzl25 <sy...@ctrip.com>
AuthorDate: Wed Oct 28 21:53:42 2026 +0800
[KYUUBI #7811] JDBC engine should cancel the statement on query timeout
### Why are the changes needed?
When a query timeout is set (via client `queryTimeout` or `kyuubi.operation.query.timeout`), the JDBC engine's timeout monitor calls `ExecuteStatement.cleanup(TIMEOUT)`, which only calls `Statement.close()` on the running JDBC statement. #7248 only cancels the statement on `CANCELED`.
### How was this patch tested?
Added UT `JDBC ExecuteStatement timeout should kill SQL statement` for MySQL and StarRocks: execute `SELECT sleep(120)` with `queryTimeout=3`, wait for `TIMEDOUT_STATE`, then `CloseOperation` should succeed within 20 seconds.
### Was this patch assisted by generative AI tooling?
Assisted-by: Claude:claude-opus-5-5
Closes #7811 from cxzl25/jdbc-engine-kill-on-timeout-close.
Closes #7811
1838af06f [sychen] JDBC engine should cancel the statement on query timeout
Authored-by: cxzl25 <sy...@ctrip.com>
Signed-off-by: Cheng Pan <ch...@apache.org>
---
.../engine/jdbc/operation/ExecuteStatement.scala | 2 +-
.../jdbc/mysql/OperationWithEngineSuite.scala | 24 +++++++++++++++++++++-
.../StarRocksOperationWithEngineSuite.scala | 24 +++++++++++++++++++++-
3 files changed, 47 insertions(+), 3 deletions(-)
diff --git a/externals/kyuubi-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/operation/ExecuteStatement.scala b/externals/kyuubi-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/operation/ExecuteStatement.scala
index 3d611448f2..34d84aefb8 100644
--- a/externals/kyuubi-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/operation/ExecuteStatement.scala
+++ b/externals/kyuubi-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/operation/ExecuteStatement.scala
@@ -140,7 +140,7 @@ class ExecuteStatement(
super.cleanup(targetState)
} finally {
if (jdbcStatement != null) {
- if (targetState == OperationState.CANCELED) {
+ if (targetState == OperationState.CANCELED || targetState == OperationState.TIMEOUT) {
dialect.cancelStatement(jdbcStatement)
} else {
dialect.closeStatement(jdbcStatement)
diff --git a/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/mysql/OperationWithEngineSuite.scala b/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/mysql/OperationWithEngineSuite.scala
index 0b89848305..50cf3aaf30 100644
--- a/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/mysql/OperationWithEngineSuite.scala
+++ b/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/mysql/OperationWithEngineSuite.scala
@@ -23,7 +23,7 @@ import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.engine.jdbc.connection.ConnectionProvider
import org.apache.kyuubi.operation.HiveJDBCTestHelper
import org.apache.kyuubi.shaded.hive.service.rpc.thrift._
-import org.apache.kyuubi.shaded.hive.service.rpc.thrift.TOperationState.{CANCELED_STATE, RUNNING_STATE}
+import org.apache.kyuubi.shaded.hive.service.rpc.thrift.TOperationState.{CANCELED_STATE, RUNNING_STATE, TIMEDOUT_STATE}
class OperationWithEngineSuite extends MySQLOperationSuite with HiveJDBCTestHelper {
@@ -100,4 +100,26 @@ class OperationWithEngineSuite extends MySQLOperationSuite with HiveJDBCTestHelp
}
}
}
+
+ test("MySQL - JDBC ExecuteStatement timeout should kill SQL statement") {
+ failAfter(20.seconds) {
+ withSessionHandle { (client, handle) =>
+ val executeReq = new TExecuteStatementReq()
+ executeReq.setSessionHandle(handle)
+ // The SQL will sleep 120s
+ executeReq.setStatement("SELECT sleep(120)")
+ executeReq.setRunAsync(true)
+ executeReq.setQueryTimeout(3)
+ val executeResp = client.ExecuteStatement(executeReq)
+ assert(executeResp.getStatus.getStatusCode === TStatusCode.SUCCESS_STATUS)
+
+ val operationHandle = executeResp.getOperationHandle
+ waitForOperationStatusIn(client, operationHandle, Set(TIMEDOUT_STATE))
+
+ // Should not be blocked until the SQL finishes
+ val closeResp = client.CloseOperation(new TCloseOperationReq(operationHandle))
+ assert(closeResp.getStatus.getStatusCode === TStatusCode.SUCCESS_STATUS)
+ }
+ }
+ }
}
diff --git a/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/starrocks/StarRocksOperationWithEngineSuite.scala b/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/starrocks/StarRocksOperationWithEngineSuite.scala
index 49cc52b41a..1beaa5b961 100644
--- a/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/starrocks/StarRocksOperationWithEngineSuite.scala
+++ b/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/starrocks/StarRocksOperationWithEngineSuite.scala
@@ -24,7 +24,7 @@ import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.engine.jdbc.connection.ConnectionProvider
import org.apache.kyuubi.operation.HiveJDBCTestHelper
import org.apache.kyuubi.shaded.hive.service.rpc.thrift._
-import org.apache.kyuubi.shaded.hive.service.rpc.thrift.TOperationState.{CANCELED_STATE, RUNNING_STATE}
+import org.apache.kyuubi.shaded.hive.service.rpc.thrift.TOperationState.{CANCELED_STATE, RUNNING_STATE, TIMEDOUT_STATE}
class StarRocksOperationWithEngineSuite extends StarRocksOperationSuite with HiveJDBCTestHelper {
@@ -101,4 +101,26 @@ class StarRocksOperationWithEngineSuite extends StarRocksOperationSuite with Hiv
}
}
}
+
+ test("StarRocks - JDBC ExecuteStatement timeout should kill SQL statement") {
+ failAfter(20.seconds) {
+ withSessionHandle { (client, handle) =>
+ val executeReq = new TExecuteStatementReq()
+ executeReq.setSessionHandle(handle)
+ // The SQL will sleep 120s
+ executeReq.setStatement("SELECT sleep(120)")
+ executeReq.setRunAsync(true)
+ executeReq.setQueryTimeout(3)
+ val executeResp = client.ExecuteStatement(executeReq)
+ assert(executeResp.getStatus.getStatusCode === TStatusCode.SUCCESS_STATUS)
+
+ val operationHandle = executeResp.getOperationHandle
+ waitForOperationStatusIn(client, operationHandle, Set(TIMEDOUT_STATE))
+
+ // Should not be blocked until the SQL finishes
+ val closeResp = client.CloseOperation(new TCloseOperationReq(operationHandle))
+ assert(closeResp.getStatus.getStatusCode === TStatusCode.SUCCESS_STATUS)
+ }
+ }
+ }
}