Skip to content

Commit 1317e83

Browse files
ruanwenjunSbloodyS
andauthored
[Bug] Refresh restart time when failover a workflow instance (#17344)
Co-authored-by: xiangzihao <460888207@qq.com>
1 parent e8f8a8c commit 1317e83

5 files changed

Lines changed: 10 additions & 7 deletions

File tree

dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/MasterServer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ public static void main(String[] args) {
117117
@PostConstruct
118118
public void initialized() {
119119
ServerLifeCycleManager.toRunning();
120-
final long startupTime = System.currentTimeMillis();
121120

122121
// init rpc server
123122
this.masterRPCServer.start();
@@ -140,7 +139,8 @@ public void initialized() {
140139

141140
this.schedulerApi.start();
142141

143-
this.systemEventBus.publish(GlobalMasterFailoverEvent.of(new Date(startupTime)));
142+
this.systemEventBus
143+
.publish(GlobalMasterFailoverEvent.of(new Date(ServerLifeCycleManager.getServerStartupTime())));
144144
this.systemEventBusFireWorker.start();
145145

146146
MasterServerMetrics.registerMasterCpuUsageGauge(() -> {
@@ -161,7 +161,8 @@ public void initialized() {
161161
close("MasterServer shutdownHook");
162162
}
163163
}));
164-
log.info("MasterServer initialized successfully in {} ms", System.currentTimeMillis() - startupTime);
164+
log.info("MasterServer initialized successfully in {} ms",
165+
System.currentTimeMillis() - ServerLifeCycleManager.getServerStartupTime());
165166
}
166167

167168
@PreDestroy

dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/command/handler/WorkflowFailoverCommandHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.dolphinscheduler.server.master.engine.task.runnable.TaskExecutionRunnableBuilder;
3434
import org.apache.dolphinscheduler.server.master.runner.WorkflowExecuteContext.WorkflowExecuteContextBuilder;
3535

36+
import java.util.Date;
3637
import java.util.Map;
3738
import java.util.Set;
3839
import java.util.function.BiConsumer;
@@ -89,6 +90,7 @@ protected void assembleWorkflowInstance(
8990
throw new IllegalArgumentException(
9091
"The WorkflowFailoverCommandParam: " + command.getCommandParam() + " is invalid");
9192
}
93+
workflowInstance.setRestartTime(new Date());
9294
workflowInstance.setState(workflowFailoverCommandParam.getWorkflowExecutionStatus());
9395
workflowInstance.setHost(masterConfig.getMasterAddress());
9496
workflowInstanceDao.updateById(workflowInstance);

dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/failover/FailoverCoordinator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ public void globalMasterFailover(final GlobalMasterFailoverEvent globalMasterFai
8383
doMasterFailover(
8484
masterAddress,
8585
aliveMasterServerMetadata.getServerStartupTime(),
86-
RegistryUtils.getFailoveredNodePathWhichStartupTimeIsUnknown(
86+
RegistryUtils.getGlobalMasterFailoverNodePath(
8787
masterAddress));
8888
} else {
8989
// If the master is not alive, then we use the event time as the failover deadline.
9090
log.info("The master[{}] is not alive, do global master failover on it", masterAddress);
9191
doMasterFailover(
9292
masterAddress,
9393
globalMasterFailoverEvent.getEventTime().getTime(),
94-
RegistryUtils.getFailoveredNodePathWhichStartupTimeIsUnknown(masterAddress));
94+
RegistryUtils.getGlobalMasterFailoverNodePath(masterAddress));
9595
}
9696
}
9797

dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/integration/cases/WorkflowInstanceFailoverTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ public void testGlobalFailover_runningWorkflow_fromAnotherMaster() {
568568

569569
systemEventBus.publish(GlobalMasterFailoverEvent.of(new Date()));
570570

571-
final String masterFailoverNodePath = RegistryUtils.getFailoveredNodePathWhichStartupTimeIsUnknown(
571+
final String masterFailoverNodePath = RegistryUtils.getGlobalMasterFailoverNodePath(
572572
"127.0.0.1:15678");
573573
// wait failover process
574574
await()

dolphinscheduler-registry/dolphinscheduler-registry-api/src/main/java/org/apache/dolphinscheduler/registry/api/utils/RegistryUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static String getMasterFailoverLockPath(final String masterAddress) {
2929
return RegistryNodeType.MASTER_FAILOVER_LOCK.getRegistryPath() + "/" + masterAddress;
3030
}
3131

32-
public static String getFailoveredNodePathWhichStartupTimeIsUnknown(final String serverAddress) {
32+
public static String getGlobalMasterFailoverNodePath(final String serverAddress) {
3333
return RegistryNodeType.FAILOVER_FINISH_NODES.getRegistryPath() + "/" + serverAddress + "-" + "unknown" + "-"
3434
+ "unknown";
3535
}

0 commit comments

Comments
 (0)