From 5657cb9aecfd2ce6b87fb5340439cdf4c1c2bb9a Mon Sep 17 00:00:00 2001 From: caishunfeng Date: Sun, 24 Apr 2022 20:34:21 +0800 Subject: [PATCH] [Bug-9719][Master] fix failover fail because task plugins has not been loaded (#9720) --- .../dolphinscheduler/server/master/MasterServer.java | 7 +++++++ .../server/master/runner/FailoverExecuteThread.java | 3 +++ .../server/master/runner/MasterSchedulerService.java | 4 ---- .../dolphinscheduler/service/task/TaskPluginManager.java | 5 +---- .../dolphinscheduler/server/worker/WorkerServer.java | 3 +++ 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/MasterServer.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/MasterServer.java index af050aef7d..6ab0d4e51a 100644 --- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/MasterServer.java +++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/MasterServer.java @@ -36,6 +36,7 @@ import org.apache.dolphinscheduler.server.master.runner.EventExecuteService; import org.apache.dolphinscheduler.server.master.runner.FailoverExecuteThread; import org.apache.dolphinscheduler.server.master.runner.MasterSchedulerService; import org.apache.dolphinscheduler.service.bean.SpringApplicationContext; +import org.apache.dolphinscheduler.service.task.TaskPluginManager; import javax.annotation.PostConstruct; @@ -68,6 +69,9 @@ public class MasterServer implements IStoppable { @Autowired private MasterRegistryClient masterRegistryClient; + @Autowired + private TaskPluginManager taskPluginManager; + @Autowired private MasterSchedulerService masterSchedulerService; @@ -131,6 +135,9 @@ public class MasterServer implements IStoppable { this.nettyRemotingServer.start(); + // install task plugin + this.taskPluginManager.installPlugin(); + // self tolerant this.masterRegistryClient.init(); this.masterRegistryClient.start(); diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/FailoverExecuteThread.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/FailoverExecuteThread.java index c717ab04a2..aa894f8b3b 100644 --- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/FailoverExecuteThread.java +++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/FailoverExecuteThread.java @@ -50,6 +50,9 @@ public class FailoverExecuteThread extends Thread { @Override public void run() { + // when startup, wait 10s for ready + ThreadUtils.sleep((long) Constants.SLEEP_TIME_MILLIS * 10); + logger.info("failover execute thread started"); while (Stopper.isRunning()) { try { diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterSchedulerService.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterSchedulerService.java index f448f0fa7c..eb0be167d9 100644 --- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterSchedulerService.java +++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterSchedulerService.java @@ -33,7 +33,6 @@ import org.apache.dolphinscheduler.server.master.dispatch.executor.NettyExecutor import org.apache.dolphinscheduler.server.master.registry.ServerNodeManager; import org.apache.dolphinscheduler.service.alert.ProcessAlertManager; import org.apache.dolphinscheduler.service.process.ProcessService; -import org.apache.dolphinscheduler.service.task.TaskPluginManager; import org.apache.commons.collections4.CollectionUtils; @@ -102,9 +101,6 @@ public class MasterSchedulerService extends Thread { @Autowired private StateWheelExecuteThread stateWheelExecuteThread; - @Autowired - private TaskPluginManager taskPluginManager; - /** * constructor of MasterSchedulerService */ diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/task/TaskPluginManager.java b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/task/TaskPluginManager.java index 72f3454dcb..7dffe9c204 100644 --- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/task/TaskPluginManager.java +++ b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/task/TaskPluginManager.java @@ -40,8 +40,6 @@ import java.util.concurrent.ConcurrentHashMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; @Component @@ -86,8 +84,7 @@ public class TaskPluginManager { return taskChannel.parseParameters(parametersNode); } - @EventListener - public void installPlugin(ApplicationReadyEvent readyEvent) { + public void installPlugin() { final Set names = new HashSet<>(); ServiceLoader.load(TaskChannelFactory.class).forEach(factory -> { diff --git a/dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/WorkerServer.java b/dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/WorkerServer.java index 45401b62b0..8ac528dee4 100644 --- a/dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/WorkerServer.java +++ b/dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/WorkerServer.java @@ -155,6 +155,9 @@ public class WorkerServer implements IStoppable { this.nettyRemotingServer.start(); + // install task plugin + this.taskPluginManager.installPlugin(); + // worker registry try { this.workerRegistryClient.registry();