Skip to content

Commit e3142a5

Browse files
[KYUUBI] Fix wrong parameter binding order in JDBCMetadataStore#transformMetadataState
The SQL placeholders expect (targetState, identifier, fromState) but the code passed (fromState, identifier, targetState), causing the UPDATE to set state back to fromState and match on targetState instead. This made cancelUnscheduledBatch silently fail.
1 parent c237522 commit e3142a5

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

kyuubi-server/src/main/scala/org/apache/kyuubi/server/metadata/jdbc/JDBCMetadataStore.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ class JDBCMetadataStore(conf: KyuubiConf) extends MetadataStore with Logging {
235235
targetState: String): Boolean = {
236236
val query = s"UPDATE $METADATA_TABLE SET state = ? WHERE identifier = ? AND state = ?"
237237
JdbcUtils.withConnection { connection =>
238-
withUpdateCount(connection, query, fromState, identifier, targetState) { updateCount =>
238+
withUpdateCount(connection, query, targetState, identifier, fromState) { updateCount =>
239239
updateCount == 1
240240
}
241241
}

kyuubi-server/src/test/scala/org/apache/kyuubi/server/metadata/jdbc/JDBCMetadataStoreSuite.scala

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,32 @@ class JDBCMetadataStoreSuite extends KyuubiFunSuite {
248248
}
249249
}
250250

251+
test("transformMetadataState should transition state correctly") {
252+
val batchId = UUID.randomUUID().toString
253+
val batchMetadata = Metadata(
254+
identifier = batchId,
255+
sessionType = SessionType.BATCH,
256+
realUser = "kyuubi",
257+
username = "kyuubi",
258+
ipAddress = "127.0.0.1",
259+
state = "INITIALIZED",
260+
resource = "intern",
261+
className = "org.apache.kyuubi.SparkWC",
262+
requestName = "test_transform",
263+
createTime = System.currentTimeMillis(),
264+
engineType = "SPARK")
265+
266+
jdbcMetadataStore.insertMetadata(batchMetadata)
267+
268+
val result = jdbcMetadataStore.transformMetadataState(batchId, "INITIALIZED", "CANCELED")
269+
assert(result, "should successfully transition from INITIALIZED to CANCELED")
270+
271+
val metadata = jdbcMetadataStore.getMetadata(batchId)
272+
assert(metadata.state == "CANCELED", s"state should be CANCELED but was ${metadata.state}")
273+
274+
jdbcMetadataStore.cleanupMetadataByIdentifier(batchId)
275+
}
276+
251277
test("throw exception if update count is 0") {
252278
val metadata = Metadata(identifier = UUID.randomUUID().toString, state = "RUNNING")
253279
intercept[KyuubiException] {

0 commit comments

Comments
 (0)