ruanwenjun commented on code in PR #18416:
URL:
https://github.com/apache/dolphinscheduler/pull/18416#discussion_r4011219323
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/server/JdbcRegistryServer.java:
##########
@@ -341,27 +350,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());
+ throw new IllegalStateException(
+ "The client heartbeat record no longer exists: " +
jdbcRegistryClientHeartbeatDTO.getId());
+ }
jdbcRegistryClientHeartbeatDTO.setLastHeartbeatTime(clone.getLastHeartbeatTime());
}
- if (jdbcRegistryServerState == JdbcRegistryServerState.SUSPENDED) {
- jdbcRegistryServerState = JdbcRegistryServerState.STARTED;
- doTriggerReconnectedListener();
- }
+ transitionToStarted();
Review Comment:
Don't add such method, looks so strange, this only transite from `SUSPENDED`
to `STARTED.`
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/main/java/org/apache/dolphinscheduler/plugin/registry/jdbc/server/JdbcRegistryServer.java:
##########
@@ -370,6 +379,33 @@ private void refreshClientsHeartbeat() {
}
}
+ private void transitionToStarted() {
+ if (serverState.compareAndSet(JdbcRegistryServerState.SUSPENDED,
JdbcRegistryServerState.STARTED)) {
+ doTriggerReconnectedListener();
+ }
+ }
+
+ private void transitionToSuspended() {
+ if (!serverState.compareAndSet(JdbcRegistryServerState.STARTED,
JdbcRegistryServerState.SUSPENDED)) {
+ log.debug("Failed to transition JdbcRegistryServer to SUSPENDED;
current state is {}", serverState.get());
+ }
+ }
Review Comment:
Please remove this kind of method.
--
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]