EnricoMi opened a new issue, #1433: URL: https://github.com/apache/incubator-uniffle/issues/1433
### 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/incubator-uniffle/issues?q=is%3Aissue) and found no similar issues. ### Describe the bug The ShuffleServer state transitions are subject to race conditions. In unlikely but possible situations, states can transition undesirably, e.g. - `DECOMMISSIONING` -> `UNHEALTHY` -> `ACTIVE` (though still unhealthy) - `DECOMMISSIONING` -> `UNHEALTHY` (decommissioning stopped) - `ACTIVE` -> any non-`ACTIVE` -> `DECOMMISSIONING` (not allowed by code) Example: ```Java if (!ServerStatus.ACTIVE.equals(serverStatus.get())) { throw new InvalidRequestException( "Shuffle Server is processing other procedures, current status:" + serverStatus); } serverStatus.set(ServerStatus.DECOMMISSIONING); ``` Just before line `serverStatus.set(ServerStatus.DECOMMISSIONING);`, the state could change, so it is not guaranteed that `ACTIVE` state turns into `DECOMMISSIONING`. Having an `AtomicReference<ServerStatus>`, this should look like: ```Java boolean wasActive = serverStatus.compareAndSet(ServerStatus.ACTIVE, ServerStatus.DECOMMISSIONING); if (!wasActive) { throw new InvalidRequestException( "Shuffle Server is processing other procedures, current status:" + serverStatus); } ``` Ideally, you would use `compareAndExchange`, so that the state in the exception is accurate (that could change in the meantime as well), but I get such a warning for that: `Usage of API documented as @since 1.9+`: ```Java ServerStatus before = serverStatus.compareAndExchange(ServerStatus.ACTIVE, ServerStatus.DECOMMISSIONING); if (!ServerStatus.ACTIVE.equals(before)) { throw new InvalidRequestException( "Shuffle Server is processing other procedures, current status:" + before); } ``` ### Affects Version(s) master ### Uniffle Server Log Output _No response_ ### Uniffle Engine Log Output _No response_ ### Uniffle Server Configurations _No response_ ### Uniffle Engine Configurations _No response_ ### Additional context _No response_ ### Are you willing to submit PR? - [X] Yes I am willing to submit a PR! -- 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]
