Skip to content

[Bug] Wrong parameter binding order in JDBCMetadataStore#transformMetadataState #7389

@wangzhigang1999

Description

@wangzhigang1999

Code of Conduct

Search before asking

  • I have searched in the issues and found no similar issues.

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:

  1. SET clause: Sets state to fromState (the old state) instead of targetState.
  2. 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

  1. Insert a metadata record with state = "INITIALIZED".
  2. Call transformMetadataState(id, "INITIALIZED", "CANCELED").
  3. Observe that the method returns false.
  4. 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?

  • Yes. I would be willing to submit a PR with guidance from the Kyuubi community to fix.
  • No. I cannot submit a PR at this time.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions