CalvinKirs commented on a change in pull request #2934:
URL: 
https://github.com/apache/incubator-dolphinscheduler/pull/2934#discussion_r446805121



##########
File path: 
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/registry/WorkerRegistry.java
##########
@@ -86,34 +90,39 @@ public void init(){
      */
     public void registry() {
         String address = OSUtils.getHost();
-        String localNodePath = getWorkerPath();
-        
zookeeperRegistryCenter.getZookeeperCachedOperator().persistEphemeral(localNodePath,
 "");
-        
zookeeperRegistryCenter.getZookeeperCachedOperator().getZkClient().getConnectionStateListenable().addListener(new
 ConnectionStateListener() {
-            @Override
-            public void stateChanged(CuratorFramework client, ConnectionState 
newState) {
-                if(newState == ConnectionState.LOST){
-                    logger.error("worker : {} connection lost from zookeeper", 
address);
-                } else if(newState == ConnectionState.RECONNECTED){
-                    logger.info("worker : {} reconnected to zookeeper", 
address);
-                    
zookeeperRegistryCenter.getZookeeperCachedOperator().persistEphemeral(localNodePath,
 "");
-                } else if(newState == ConnectionState.SUSPENDED){
-                    logger.warn("worker : {} connection SUSPENDED ", address);
-                }
-            }
-        });
+        Set<String> workerZkPaths = getWorkerZkPaths();
         int workerHeartbeatInterval = 
workerConfig.getWorkerHeartbeatInterval();
-        this.heartBeatExecutor.scheduleAtFixedRate(new HeartBeatTask(), 
workerHeartbeatInterval, workerHeartbeatInterval, TimeUnit.SECONDS);
-        logger.info("worker node : {} registry to ZK successfully with 
heartBeatInterval : {}s", address, workerHeartbeatInterval);
 
+        for (String workerZKPath : workerZkPaths) {
+            
zookeeperRegistryCenter.getZookeeperCachedOperator().persistEphemeral(workerZKPath,
 "");
+            
zookeeperRegistryCenter.getZookeeperCachedOperator().getZkClient().getConnectionStateListenable().addListener(new
 ConnectionStateListener() {
+                @Override
+                public void stateChanged(CuratorFramework client, 
ConnectionState newState) {
+                    if (newState == ConnectionState.LOST) {

Review comment:
       Hello, is it possible to return directly here without continuing to 
judge? In addition, it is not very intuitive to flood with too many if else
   




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to