HanShuhang opened a new issue, #7645: URL: https://github.com/apache/kyuubi/issues/7645
### Code of Conduct - [x] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) ### Search before asking - [x] I have searched in the [issues](https://github.com/apache/kyuubi/issues?q=is%3Aissue) and found no similar issues. ### Describe the bug `KyuubiOperation#setState` updates operation state metrics before the actual state transition is validated and applied by `AbstractOperation#setState`. Current flow: ```scala override def setState(newState: OperationState): Unit = { MetricsSystem.tracing { ms => if (!OperationState.isTerminal(state)) { ms.markMeter(MetricRegistry.name(OPERATION_STATE, opType, state.toString.toLowerCase), -1) } ms.markMeter(MetricRegistry.name(OPERATION_STATE, opType, newState.toString.toLowerCase)) ms.markMeter(MetricRegistry.name(OPERATION_STATE, newState.toString.toLowerCase)) } super.setState(newState) } This can make operation state metrics inconsistent with the real operation state. There are two related problems: 1. If AbstractOperation#setState rejects a stale or invalid transition, metrics may already have been updated. 2. Concurrent state transitions for the same operation are not protected as one atomic transition-and-metrics-update sequence, so multiple threads may update metrics based on the same stale old state. ### Affects Version(s) master ### Kyuubi Server Log Output ```logtalk ``` ### Kyuubi Engine Log Output ```logtalk ``` ### Kyuubi Server Configurations ```yaml ``` ### Kyuubi Engine Configurations ```yaml ``` ### Additional context _No response_ ### Are you willing to submit PR? - [x] 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. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
