Bläddra i källkod

fix bug:master fault tolerance error (#2350) (#2375)

fix bug: Visit the worker page of the monitoring center, a null pointer occur(#2349)

Co-authored-by: baoliang <baoliang@analysys.com.cn>
bao liang 5 år sedan
förälder
incheckning
785c34bc66

+ 2 - 1
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/zk/ZKMasterClient.java

@@ -24,6 +24,7 @@ import org.apache.dolphinscheduler.common.Constants;
 import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
 import org.apache.dolphinscheduler.common.enums.ZKNodeType;
 import org.apache.dolphinscheduler.common.model.Server;
+import org.apache.dolphinscheduler.common.utils.OSUtils;
 import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
 import org.apache.dolphinscheduler.dao.entity.TaskInstance;
 import org.apache.dolphinscheduler.server.builder.TaskExecutionContextBuilder;
@@ -72,7 +73,7 @@ public class ZKMasterClient extends AbstractZKClient {
 			this.initSystemZNode();
 
 			// check if fault tolerance is required?failure and tolerance
-			if (getActiveMasterNum() == 1) {
+			if (getActiveMasterNum() == 1 && checkZKNodeExists(OSUtils.getHost(), ZKNodeType.MASTER)) {
 				failoverWorker(null, true);
 				failoverMaster(null);
 			}

+ 11 - 1
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/zk/AbstractZKClient.java

@@ -145,8 +145,18 @@ public abstract class AbstractZKClient extends ZookeeperCachedOperator {
 		try {
 			String path =  getZNodeParentPath(zkNodeType);
 			List<String> serverList  = super.getChildrenKeys(path);
+			if(zkNodeType == ZKNodeType.WORKER){
+			    List<String> workerList = new ArrayList<>();
+			    for(String group : serverList){
+			    	List<String> groupServers = super.getChildrenKeys(path + Constants.SLASH + group);
+			    	for(String groupServer : groupServers){
+			    		workerList.add(group + Constants.SLASH + groupServer);
+					}
+				}
+				serverList = workerList;
+			}
 			for(String server : serverList){
-				masterMap.putIfAbsent(server, super.get(path + "/" + server));
+				masterMap.putIfAbsent(server, super.get(path + Constants.SLASH + server));
 			}
 		} catch (Exception e) {
 			logger.error("get server list failed", e);