From 701d67c831227ae71d0ce903fe814f37548319c9 Mon Sep 17 00:00:00 2001 From: fuchanghai <33984497+fuchanghai@users.noreply.github.com> Date: Mon, 20 Feb 2023 14:10:59 +0800 Subject: [PATCH] [improve-#13045] after a submit failure, stop the processInstance to avoid an endless loop (#13051) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [improve-#13045] add max submit number of workflow * [fix-13405] remove max times * Update dolphinscheduler-master/src/main/resources/application.yaml Co-authored-by: Wenjun Ruan --------- Co-authored-by: fuchanghai <‘2875334588@qq.com’> Co-authored-by: Wenjun Ruan --- .../common/enums/StateEventType.java | 3 ++- .../master/event/WorkflowStartEventHandler.java | 15 +++++++++++---- .../master/event/WorkflowStateEventHandler.java | 3 +++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/StateEventType.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/StateEventType.java index 5afadaaf06..6e25d2ed4b 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/StateEventType.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/StateEventType.java @@ -27,7 +27,8 @@ public enum StateEventType { TASK_TIMEOUT(3, "task timeout"), WAKE_UP_TASK_GROUP(4, "wait task group"), TASK_RETRY(5, "task retry"), - PROCESS_BLOCKED(6, "process blocked"); + PROCESS_BLOCKED(6, "process blocked"), + PROCESS_SUBMIT_FAILED(7, "process submit failed"); StateEventType(int code, String descp) { this.code = code; diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/event/WorkflowStartEventHandler.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/event/WorkflowStartEventHandler.java index e6e9113d48..83af487bfe 100644 --- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/event/WorkflowStartEventHandler.java +++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/event/WorkflowStartEventHandler.java @@ -17,6 +17,8 @@ package org.apache.dolphinscheduler.server.master.event; +import org.apache.dolphinscheduler.common.enums.StateEventType; +import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus; import org.apache.dolphinscheduler.dao.entity.ProcessInstance; import org.apache.dolphinscheduler.server.master.cache.ProcessInstanceExecCacheManager; import org.apache.dolphinscheduler.server.master.metrics.ProcessInstanceMetrics; @@ -66,11 +68,16 @@ public class WorkflowStartEventHandler implements WorkflowEventHandler { if (processInstance.getTimeout() > 0) { stateWheelExecuteThread.addProcess4TimeoutCheck(processInstance); } - } else { - // submit failed will resend the event to workflow event queue - log.error("Failed to submit the workflow instance, will resend the workflow start event: {}", + } else if (WorkflowSubmitStatue.FAILED == workflowSubmitStatue) { + log.error( + "Failed to submit the workflow instance, will resend the workflow start event: {}", workflowEvent); - workflowEventQueue.addEvent(workflowEvent); + WorkflowStateEvent stateEvent = WorkflowStateEvent.builder() + .processInstanceId(processInstance.getId()) + .type(StateEventType.PROCESS_SUBMIT_FAILED) + .status(WorkflowExecutionStatus.FAILURE) + .build(); + workflowExecuteRunnable.addStateEvent(stateEvent); } }); } diff --git a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/event/WorkflowStateEventHandler.java b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/event/WorkflowStateEventHandler.java index 73b444a559..ba92d5b33a 100644 --- a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/event/WorkflowStateEventHandler.java +++ b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/event/WorkflowStateEventHandler.java @@ -57,6 +57,9 @@ public class WorkflowStateEventHandler implements StateEventHandler { return true; } if (workflowStateEvent.getStatus().isFinished()) { + if (workflowStateEvent.getType().equals(StateEventType.PROCESS_SUBMIT_FAILED)) { + workflowExecuteRunnable.updateProcessInstanceState(workflowStateEvent); + } workflowExecuteRunnable.endProcess(); } if (processInstance.getState().isReadyStop()) {