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


##########
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:
   Use `AtomicReference`, don't write field name `jdbcRegistryServerState` here.



##########
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:
   Need to handle the status set failed case.



##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/server/JdbcRegistryServer.java:
##########
@@ -341,27 +346,27 @@ private void refreshClientsHeartbeat() {
                 }
                 JdbcRegistryClientHeartbeatDTO clone = 
jdbcRegistryClientHeartbeatDTO.clone();
                 clone.setLastHeartbeatTime(now);
-                
jdbcRegistryClientRepository.updateById(jdbcRegistryClientHeartbeatDTO);
+                if (!jdbcRegistryClientRepository.updateById(clone)) {
+                    log.error("The client heartbeat has expired: {}", 
jdbcRegistryClientHeartbeatDTO.getId());
+                    transitionToDisconnected();
+                    return;

Review Comment:
   Only a session timeout can cause the status to change to "disconnected".



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