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



##########
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) {
+                        logger.error("worker : {} connection lost from 
zookeeper", address);
+                    } else if (newState == ConnectionState.RECONNECTED) {
+                        logger.info("worker : {} reconnected to zookeeper", 
address);
+                        
zookeeperRegistryCenter.getZookeeperCachedOperator().persistEphemeral(workerZKPath,
 "");
+                    } else if (newState == ConnectionState.SUSPENDED) {
+                        logger.warn("worker : {} connection SUSPENDED ", 
address);
+                    }

Review comment:
       > This is my suggestion, what do you think,
   
   Thx a lot for your review.
   I got your point, and can you describe your opinion about what is the 
benefits of using
    `if (a) { xxx; return;}  if (b) { xxx; return; }` but not `if (a) { xxx; } 
else if (b) {xxx;}` ?




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to