You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by zh...@apache.org on 2023/09/01 07:22:06 UTC
[dolphinscheduler] 03/03: [Fix-14149][master] task finished so not dispatch (#14161)
This is an automated email from the ASF dual-hosted git repository.
zhongjiajie pushed a commit to branch 3.2.0-release
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
commit ab306cedd535d14cfee0401800f15239cc7841c2
Author: eye-gu <73...@qq.com>
AuthorDate: Thu Aug 31 20:08:09 2023 +0800
[Fix-14149][master] task finished so not dispatch (#14161)
(cherry picked from commit 7ae4fb378779077c75cd6411ef8e3b68f232bd84)
---
.../master/runner/WorkflowExecuteRunnable.java | 33 +++++++++++++++++++++-
.../master/runner/WorkflowExecuteRunnableTest.java | 18 ++++++++++++
2 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkflowExecuteRunnable.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkflowExecuteRunnable.java
index 779180aa89..b07256c11f 100644
--- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkflowExecuteRunnable.java
+++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkflowExecuteRunnable.java
@@ -84,6 +84,7 @@ import org.apache.dolphinscheduler.server.master.metrics.TaskMetrics;
import org.apache.dolphinscheduler.server.master.rpc.MasterRpcClient;
import org.apache.dolphinscheduler.server.master.runner.execute.DefaultTaskExecuteRunnable;
import org.apache.dolphinscheduler.server.master.runner.execute.DefaultTaskExecuteRunnableFactory;
+import org.apache.dolphinscheduler.server.master.runner.execute.TaskExecuteRunnable;
import org.apache.dolphinscheduler.server.master.utils.TaskUtils;
import org.apache.dolphinscheduler.server.master.utils.WorkflowInstanceUtils;
import org.apache.dolphinscheduler.service.alert.ProcessAlertManager;
@@ -124,6 +125,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
@@ -988,7 +990,7 @@ public class WorkflowExecuteRunnable implements IWorkflowExecuteRunnable {
}
}
// 4. submit to dispatch queue
- taskExecuteRunnable.dispatch();
+ tryToDispatchTaskInstance(taskInstance, taskExecuteRunnable);
stateWheelExecuteThread.addTask4TimeoutCheck(workflowInstance, taskInstance);
return true;
@@ -999,6 +1001,35 @@ public class WorkflowExecuteRunnable implements IWorkflowExecuteRunnable {
}
}
+ /**
+ * Sometimes (such as pause), if the task instance status has already been finished,
+ * there is no need to dispatch it
+ */
+ @VisibleForTesting
+ void tryToDispatchTaskInstance(TaskInstance taskInstance, TaskExecuteRunnable taskExecuteRunnable) {
+ if (!taskInstance.getState().isFinished()) {
+ taskExecuteRunnable.dispatch();
+ } else {
+ if (workflowExecuteContext.getWorkflowInstance().isBlocked()) {
+ TaskStateEvent processBlockEvent = TaskStateEvent.builder()
+ .processInstanceId(workflowExecuteContext.getWorkflowInstance().getId())
+ .taskInstanceId(taskInstance.getId())
+ .status(taskInstance.getState())
+ .type(StateEventType.PROCESS_BLOCKED)
+ .build();
+ this.stateEvents.add(processBlockEvent);
+ }
+
+ TaskStateEvent taskStateChangeEvent = TaskStateEvent.builder()
+ .processInstanceId(workflowExecuteContext.getWorkflowInstance().getId())
+ .taskInstanceId(taskInstance.getId())
+ .status(taskInstance.getState())
+ .type(StateEventType.TASK_STATE_CHANGE)
+ .build();
+ this.stateEvents.add(taskStateChangeEvent);
+ }
+ }
+
/**
* find task instance in db.
* in case submit more than one same name task in the same time.
diff --git a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/runner/WorkflowExecuteRunnableTest.java b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/runner/WorkflowExecuteRunnableTest.java
index 3aff6d65e8..2306fbc428 100644
--- a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/runner/WorkflowExecuteRunnableTest.java
+++ b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/runner/WorkflowExecuteRunnableTest.java
@@ -35,10 +35,12 @@ import org.apache.dolphinscheduler.dao.entity.TaskInstance;
import org.apache.dolphinscheduler.dao.repository.ProcessInstanceDao;
import org.apache.dolphinscheduler.dao.repository.TaskDefinitionLogDao;
import org.apache.dolphinscheduler.dao.repository.TaskInstanceDao;
+import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
import org.apache.dolphinscheduler.server.master.config.MasterConfig;
import org.apache.dolphinscheduler.server.master.graph.IWorkflowGraph;
import org.apache.dolphinscheduler.server.master.rpc.MasterRpcClient;
import org.apache.dolphinscheduler.server.master.runner.execute.DefaultTaskExecuteRunnableFactory;
+import org.apache.dolphinscheduler.server.master.runner.execute.TaskExecuteRunnable;
import org.apache.dolphinscheduler.service.alert.ProcessAlertManager;
import org.apache.dolphinscheduler.service.bean.SpringApplicationContext;
import org.apache.dolphinscheduler.service.command.CommandService;
@@ -374,4 +376,20 @@ public class WorkflowExecuteRunnableTest {
return schedulerList;
}
+ @Test
+ void testTryToDispatchTaskInstance() {
+ // task instance already finished, not dispatch
+ TaskInstance taskInstance = new TaskInstance();
+ taskInstance.setState(TaskExecutionStatus.PAUSE);
+ Mockito.when(processInstance.isBlocked()).thenReturn(true);
+ TaskExecuteRunnable taskExecuteRunnable = Mockito.mock(TaskExecuteRunnable.class);
+ workflowExecuteThread.tryToDispatchTaskInstance(taskInstance, taskExecuteRunnable);
+ Mockito.verify(taskExecuteRunnable, Mockito.never()).dispatch();
+
+ // submit success should dispatch
+ taskInstance = new TaskInstance();
+ taskInstance.setState(TaskExecutionStatus.SUBMITTED_SUCCESS);
+ workflowExecuteThread.tryToDispatchTaskInstance(taskInstance, taskExecuteRunnable);
+ Mockito.verify(taskExecuteRunnable).dispatch();
+ }
}