ruanwenjun commented on code in PR #18416:
URL:
https://github.com/apache/dolphinscheduler/pull/18416#discussion_r4011193948
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/server/JdbcRegistryServer.java:
##########
@@ -256,7 +257,12 @@ public void releaseJdbcRegistryLock(Long clientId, String
lockKey) {
@Override
public void close() {
- jdbcRegistryServerState = JdbcRegistryServerState.STOPPED;
+ synchronized (this) {
+ if (serverState.getAndSet(JdbcRegistryServerState.STOPPED) ==
JdbcRegistryServerState.STOPPED) {
Review Comment:
Nit, use `compareAndSet`.
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/server/JdbcRegistryServer.java:
##########
@@ -370,6 +384,33 @@ private void refreshClientsHeartbeat() {
}
}
+ private void transitionToStarted() {
+ if (SERVER_STATE_UPDATER.compareAndSet(
+ this, JdbcRegistryServerState.SUSPENDED,
JdbcRegistryServerState.STARTED)) {
+ doTriggerReconnectedListener();
+ }
+ }
+
+ private void transitionToSuspended() {
+ SERVER_STATE_UPDATER.compareAndSet(
+ this, JdbcRegistryServerState.STARTED,
JdbcRegistryServerState.SUSPENDED);
+ }
+
+ private void transitionToDisconnected() {
+ while (true) {
+ JdbcRegistryServerState currentState = jdbcRegistryServerState;
+ if (currentState != JdbcRegistryServerState.STARTED
+ && currentState != JdbcRegistryServerState.SUSPENDED) {
+ return;
+ }
+ if (SERVER_STATE_UPDATER.compareAndSet(
+ this, currentState, JdbcRegistryServerState.DISCONNECTED))
{
+ doTriggerOnDisConnectedListener();
+ return;
+ }
+ }
+ }
Review Comment:
All `compareAndSet` failed should be handled. Please don't reply to me with
an AI response, you should at least know what the reviewer means.
--
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]