Skip to content

Commit 57fff8c

Browse files
authored
[Fix-13913][Master] syncMasterNodes does not make current slot correctly after zookeeper reconnect (#14014)
1 parent a626b4c commit 57fff8c

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

Diff for: dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/registry/MasterConnectionStateListener.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ public class MasterConnectionStateListener implements ConnectionListener {
3232

3333
private final String masterNodePath;
3434
private final RegistryClient registryClient;
35+
private final MasterHeartBeatTask masterHeartBeatTask;
3536

36-
public MasterConnectionStateListener(String masterNodePath, RegistryClient registryClient) {
37+
public MasterConnectionStateListener(String masterNodePath, RegistryClient registryClient, MasterHeartBeatTask masterHeartBeatTask) {
3738
this.masterNodePath = checkNotNull(masterNodePath);
3839
this.registryClient = checkNotNull(registryClient);
40+
this.masterHeartBeatTask = checkNotNull(masterHeartBeatTask);
3941
}
4042

4143
@Override
@@ -50,7 +52,7 @@ public void onUpdate(ConnectionState state) {
5052
case RECONNECTED:
5153
logger.debug("registry connection state is {}, clean the node info", state);
5254
registryClient.remove(masterNodePath);
53-
registryClient.persistEphemeral(masterNodePath, "");
55+
registryClient.persistEphemeral(masterNodePath, masterHeartBeatTask.getHeartBeatInfo());
5456
break;
5557
case DISCONNECTED:
5658
logger.warn("registry connection state is {}, ready to stop myself", state);

Diff for: dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/registry/MasterRegistryClient.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ public class MasterRegistryClient implements AutoCloseable {
7979
*/
8080
private ScheduledExecutorService heartBeatExecutor;
8181

82+
/**
83+
* master heartbeat task
84+
*/
85+
private MasterHeartBeatTask masterHeartBeatTask;
86+
8287
/**
8388
* master startup time, ms
8489
*/
@@ -96,7 +101,7 @@ public void start() {
96101
// master registry
97102
registry();
98103
registryClient.addConnectionStateListener(new MasterConnectionStateListener(getCurrentNodePath(),
99-
registryClient));
104+
registryClient, masterHeartBeatTask));
100105
registryClient.subscribe(REGISTRY_DOLPHINSCHEDULER_NODE, new MasterRegistryDataListener());
101106
} catch (Exception e) {
102107
throw new RegistryException("Master registry client start up error", e);
@@ -189,15 +194,15 @@ void registry() {
189194
logger.info("Master node : {} registering to registry center", masterAddress);
190195
String localNodePath = getCurrentNodePath();
191196
Duration masterHeartbeatInterval = masterConfig.getHeartbeatInterval();
192-
MasterHeartBeatTask heartBeatTask = new MasterHeartBeatTask(startupTime,
197+
masterHeartBeatTask = new MasterHeartBeatTask(startupTime,
193198
masterConfig.getMaxCpuLoadAvg(),
194199
masterConfig.getReservedMemory(),
195200
Sets.newHashSet(localNodePath),
196201
registryClient);
197202

198203
// remove before persist
199204
registryClient.remove(localNodePath);
200-
registryClient.persistEphemeral(localNodePath, heartBeatTask.getHeartBeatInfo());
205+
registryClient.persistEphemeral(localNodePath, masterHeartBeatTask.getHeartBeatInfo());
201206

202207
while (!registryClient.checkNodeExists(NetUtils.getHost(), NodeType.MASTER)) {
203208
logger.warn("The current master server node:{} cannot find in registry", NetUtils.getHost());
@@ -210,7 +215,7 @@ void registry() {
210215
// delete dead server
211216
registryClient.handleDeadServer(Collections.singleton(localNodePath), NodeType.MASTER, Constants.DELETE_OP);
212217

213-
this.heartBeatExecutor.scheduleAtFixedRate(heartBeatTask, 0L, masterHeartbeatInterval.getSeconds(), TimeUnit.SECONDS);
218+
this.heartBeatExecutor.scheduleAtFixedRate(masterHeartBeatTask, 0L, masterHeartbeatInterval.getSeconds(), TimeUnit.SECONDS);
214219
logger.info("Master node : {} registered to registry center successfully with heartBeatInterval : {}s", masterAddress, masterHeartbeatInterval);
215220

216221
}

0 commit comments

Comments
 (0)