qiuyanjun888 commented on code in PR #18416:
URL: 
https://github.com/apache/dolphinscheduler/pull/18416#discussion_r4002228742


##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/server/JdbcRegistryServer.java:
##########
@@ -60,6 +61,10 @@
 @Slf4j
 public class JdbcRegistryServer implements IJdbcRegistryServer {
 
+    private static final AtomicReferenceFieldUpdater<JdbcRegistryServer, 
JdbcRegistryServerState> SERVER_STATE_UPDATER =

Review Comment:
   Addressed in 71e8a14eb2. Server state is now stored in an AtomicReference, 
so reads and compare-and-set transitions no longer depend on 
AtomicReferenceFieldUpdater or a field-name string.



##########
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:
   Addressed in 71e8a14eb2. CAS failures are now handled explicitly: the 
SUSPENDED transition records the current state, and the DISCONNECTED transition 
logs the failed attempt and retries after re-reading the state. The listener 
runs only after a successful state change.



-- 
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]

Reply via email to