[KYUUBI #7645][SERVER] Fix operation state metrics transition - #7642
Open
HanShuhang wants to merge 1 commit into
Open
[KYUUBI #7645][SERVER] Fix operation state metrics transition#7642HanShuhang wants to merge 1 commit into
HanShuhang wants to merge 1 commit into
Conversation
yikf
reviewed
Aug 21, 2026
| } | ||
| } | ||
|
|
||
| private class TestKyuubiOperation(session: Session) extends KyuubiOperation(session) { |
Contributor
There was a problem hiding this comment.
Hi @HanShuhang , thanks for working on this, left two minor points, let me know what you think.
-
Please file/link an issue and add '[KYUUBI #NNNN]' to the title.
-
TestKyuubiOperationis over-implemented —KyuubiOperationalready implements everything exceptrunInternal. Trim to:
Suggested change
| private class TestKyuubiOperation(session: Session) extends KyuubiOperation(session) { | |
| private class TestKyuubiOperation(session: Session) extends KyuubiOperation(session) { | |
| def transitState(newState: OperationState): Unit = setState(newState) | |
| override protected def runInternal(): Unit = {} | |
| } |
Contributor
Author
There was a problem hiding this comment.
Thanks! I agree with your suggestions and have updated the PR accordingly.
HanShuhang
force-pushed
the
hsh/fix-state
branch
from
August 21, 2026 09:56
37b7a05 to
543cb2e
Compare
HanShuhang
force-pushed
the
hsh/fix-state
branch
from
August 24, 2026 03:49
543cb2e to
063f24c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why are the changes needed?
KyuubiOperation#setStateupdated operation state metrics before delegating toAbstractOperation#setState, where the state transition is validated and the actual operation state is changed. It also did not protect the whole transition-and-metrics-update sequence with the operation lock.This can cause inaccurate operation state metrics in two cases:
A stale or invalid state transition may update metrics before being rejected.
For example, an operation may have already moved from
RUNNINGtoFINISHED, while a delayed cancel/close path still tries to update it to another terminal state such asCANCELED. In the old implementation, the target state metric was updated beforeOperationState#validateTransitionrejected the transition, so the operation remained in the original state but the metrics had already been changed.Concurrent state transitions for the same operation may update metrics based on the same stale old state.
For example, one thread may observe the remote query as finished and call
KyuubiOperation#setState(FINISHED), while another thread concurrently handles cancel/close/timeout/error and callsKyuubiOperation#setState(CANCELED)or another terminal state. Since the old implementation readstateand updated metrics outside a common operation lock, both paths could observe the old state asRUNNINGand both update theRUNNINGmetric, makingkyuubi.operation.state.ExecuteStatement.runninginaccurate.This patch makes
KyuubiOperation#setStateexecute under the operation lock, captures the old state once, delegates toAbstractOperation#setStatefirst, and updates operation state metrics only after the state transition succeeds.How was this patch tested?
Added a unit test in
KyuubiOperationSuiteto verify that a stale terminal transition does not update operation state metrics.Was this patch authored or co-authored using generative AI tooling?
Assisted-by: TraeCode with GPT-5