|
@@ -129,8 +129,7 @@ public class ServerNodeManager implements InitializingBean {
|
|
|
|
|
|
// load nodes from zookeeper
|
|
// load nodes from zookeeper
|
|
updateMasterNodes();
|
|
updateMasterNodes();
|
|
- updateWorkerNodes();
|
|
|
|
- updateWorkerGroupMappings();
|
|
|
|
|
|
+ refreshWorkerNodesAndGroupMappings();
|
|
|
|
|
|
// init executor service
|
|
// init executor service
|
|
executorService =
|
|
executorService =
|
|
@@ -153,27 +152,21 @@ public class ServerNodeManager implements InitializingBean {
|
|
@Override
|
|
@Override
|
|
public void run() {
|
|
public void run() {
|
|
try {
|
|
try {
|
|
-
|
|
|
|
// sync worker node info
|
|
// sync worker node info
|
|
- updateWorkerNodes();
|
|
|
|
- updateWorkerGroupMappings();
|
|
|
|
- notifyWorkerInfoChangeListeners();
|
|
|
|
|
|
+ refreshWorkerNodesAndGroupMappings();
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
logger.error("WorkerNodeInfoAndGroupDbSyncTask error:", e);
|
|
logger.error("WorkerNodeInfoAndGroupDbSyncTask error:", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- protected Set<String> getWorkerAddressByWorkerGroup(Map<String, String> newWorkerNodeInfo,
|
|
|
|
- WorkerGroup wg) {
|
|
|
|
- Set<String> nodes = new HashSet<>();
|
|
|
|
- String[] addrs = wg.getAddrList().split(Constants.COMMA);
|
|
|
|
- for (String addr : addrs) {
|
|
|
|
- if (newWorkerNodeInfo.containsKey(addr)) {
|
|
|
|
- nodes.add(addr);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return nodes;
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Refresh worker nodes and worker group mapping information
|
|
|
|
+ */
|
|
|
|
+ private void refreshWorkerNodesAndGroupMappings() {
|
|
|
|
+ updateWorkerNodes();
|
|
|
|
+ updateWorkerGroupMappings();
|
|
|
|
+ notifyWorkerInfoChangeListeners();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -204,7 +197,15 @@ public class ServerNodeManager implements InitializingBean {
|
|
} catch (Exception ex) {
|
|
} catch (Exception ex) {
|
|
logger.error("WorkerGroupListener capture data change and get data failed", ex);
|
|
logger.error("WorkerGroupListener capture data change and get data failed", ex);
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ private void syncSingleWorkerNodeInfo(String workerAddress, WorkerHeartBeat info) {
|
|
|
|
+ workerNodeInfoWriteLock.lock();
|
|
|
|
+ try {
|
|
|
|
+ workerNodeInfo.put(workerAddress, info);
|
|
|
|
+ } finally {
|
|
|
|
+ workerNodeInfoWriteLock.unlock();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -241,8 +242,8 @@ public class ServerNodeManager implements InitializingBean {
|
|
try {
|
|
try {
|
|
registryClient.getLock(nodeLock);
|
|
registryClient.getLock(nodeLock);
|
|
Collection<String> currentNodes = registryClient.getMasterNodesDirectly();
|
|
Collection<String> currentNodes = registryClient.getMasterNodesDirectly();
|
|
- List<Server> masterNodes = registryClient.getServerList(NodeType.MASTER);
|
|
|
|
- syncMasterNodes(currentNodes, masterNodes);
|
|
|
|
|
|
+ List<Server> masterNodeList = registryClient.getServerList(NodeType.MASTER);
|
|
|
|
+ syncMasterNodes(currentNodes, masterNodeList);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
logger.error("update master nodes error", e);
|
|
logger.error("update master nodes error", e);
|
|
} finally {
|
|
} finally {
|
|
@@ -289,7 +290,6 @@ public class ServerNodeManager implements InitializingBean {
|
|
try {
|
|
try {
|
|
workerGroupNodes.clear();
|
|
workerGroupNodes.clear();
|
|
workerGroupNodes.putAll(tmpWorkerGroupMappings);
|
|
workerGroupNodes.putAll(tmpWorkerGroupMappings);
|
|
- notifyWorkerInfoChangeListeners();
|
|
|
|
} finally {
|
|
} finally {
|
|
workerGroupWriteLock.unlock();
|
|
workerGroupWriteLock.unlock();
|
|
}
|
|
}
|
|
@@ -363,15 +363,6 @@ public class ServerNodeManager implements InitializingBean {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void syncSingleWorkerNodeInfo(String workerAddress, WorkerHeartBeat info) {
|
|
|
|
- workerNodeInfoWriteLock.lock();
|
|
|
|
- try {
|
|
|
|
- workerNodeInfo.put(workerAddress, info);
|
|
|
|
- } finally {
|
|
|
|
- workerNodeInfoWriteLock.unlock();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Add the resource change listener, when the resource changed, the listener will be notified.
|
|
* Add the resource change listener, when the resource changed, the listener will be notified.
|
|
*
|
|
*
|
|
@@ -382,10 +373,10 @@ public class ServerNodeManager implements InitializingBean {
|
|
}
|
|
}
|
|
|
|
|
|
private void notifyWorkerInfoChangeListeners() {
|
|
private void notifyWorkerInfoChangeListeners() {
|
|
- Map<String, Set<String>> workerGroupNodes = getWorkerGroupNodes();
|
|
|
|
- Map<String, WorkerHeartBeat> workerNodeInfo = getWorkerNodeInfo();
|
|
|
|
|
|
+ Map<String, Set<String>> workerGroupNodeMap = getWorkerGroupNodes();
|
|
|
|
+ Map<String, WorkerHeartBeat> workerNodeInfoMap = getWorkerNodeInfo();
|
|
for (WorkerInfoChangeListener listener : workerInfoChangeListeners) {
|
|
for (WorkerInfoChangeListener listener : workerInfoChangeListeners) {
|
|
- listener.notify(workerGroupNodes, workerNodeInfo);
|
|
|
|
|
|
+ listener.notify(workerGroupNodeMap, workerNodeInfoMap);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|