Code of Conduct
Search before asking
Describe the bug
Description
In JDBCMetadataStore#transformMetadataState, the SQL parameter binding order is swapped, causing the method to silently fail during state transitions.
Root Cause
The SQL query is defined as:
UPDATE metadata SET state = ? WHERE identifier = ? AND state = ?
The placeholders expect parameters in the order: (targetState, identifier, fromState).
However, the code currently passes them as:
withUpdateCount(connection, query, fromState, identifier, targetState) { ... }
This results in the following incorrect behavior:
- SET clause: Sets
state to fromState (the old state) instead of targetState.
- WHERE clause: Checks if
state equals targetState (the new state) instead of fromState.
This effectively reverses the intended Compare-And-Swap (CAS) logic.
Impact
For example, when MetadataManager#cancelUnscheduledBatch calls:
transformMetadataState(batchId, "INITIALIZED", "CANCELED")
The executed SQL becomes:
UPDATE metadata
SET state = 'INITIALIZED'
WHERE identifier = ? AND state = 'CANCELED'
Since the record is currently in the INITIALIZED state, the WHERE state = 'CANCELED' condition matches 0 rows. Consequently:
- The update does not happen.
- The method returns
false.
- The cancel request fails silently without any exception or error log.
Steps to Reproduce
- Insert a metadata record with
state = "INITIALIZED".
- Call
transformMetadataState(id, "INITIALIZED", "CANCELED").
- Observe that the method returns
false.
- Query the database record: the state remains
"INITIALIZED".
Expected Behavior
The parameters should be bound as (targetState, identifier, fromState). The SQL should execute as:
UPDATE metadata
SET state = 'CANCELED'
WHERE identifier = ? AND state = 'INITIALIZED'
This should successfully update the state and return true (or a positive update count).
Proposed Fix
Swap the first and last arguments in the withUpdateCount call within transformMetadataState:
// Current (Incorrect)
withUpdateCount(connection, query, fromState, identifier, targetState)
// Fixed
withUpdateCount(connection, query, targetState, identifier, fromState)
Affects Version(s)
1.8.0
Kyuubi Server Log Output
Kyuubi Engine Log Output
Kyuubi Server Configurations
Kyuubi Engine Configurations
Additional context
No response
Are you willing to submit PR?
Code of Conduct
Search before asking
Describe the bug
Description
In
JDBCMetadataStore#transformMetadataState, the SQL parameter binding order is swapped, causing the method to silently fail during state transitions.Root Cause
The SQL query is defined as:
The placeholders expect parameters in the order:
(targetState, identifier, fromState).However, the code currently passes them as:
This results in the following incorrect behavior:
statetofromState(the old state) instead oftargetState.stateequalstargetState(the new state) instead offromState.This effectively reverses the intended Compare-And-Swap (CAS) logic.
Impact
For example, when
MetadataManager#cancelUnscheduledBatchcalls:The executed SQL becomes:
Since the record is currently in the
INITIALIZEDstate, theWHERE state = 'CANCELED'condition matches 0 rows. Consequently:false.Steps to Reproduce
state = "INITIALIZED".transformMetadataState(id, "INITIALIZED", "CANCELED").false."INITIALIZED".Expected Behavior
The parameters should be bound as
(targetState, identifier, fromState). The SQL should execute as:This should successfully update the state and return
true(or a positive update count).Proposed Fix
Swap the first and last arguments in the
withUpdateCountcall withintransformMetadataState:Affects Version(s)
1.8.0
Kyuubi Server Log Output
Kyuubi Engine Log Output
Kyuubi Server Configurations
Kyuubi Engine Configurations
Additional context
No response
Are you willing to submit PR?