-
Notifications
You must be signed in to change notification settings - Fork 5k
[Fix-17758][Master] Add logic to handle tasks that fail during initialization. #17759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
8292ea0
f860406
e8ca640
399923b
8d8de57
a984bbe
fe92a05
560765a
abb3809
2944d4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event; | ||
|
|
||
| import org.apache.dolphinscheduler.server.master.engine.ILifecycleEventType; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.AbstractTaskLifecycleEvent; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.TaskLifecycleEventType; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable; | ||
|
|
||
| import java.util.Date; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
|
|
||
| @Data | ||
| @Builder | ||
| @AllArgsConstructor | ||
| public class TaskFatalLifecycleEvent extends AbstractTaskLifecycleEvent { | ||
|
|
||
| private final ITaskExecutionRunnable taskExecutionRunnable; | ||
|
||
|
|
||
| private final Date endTime; | ||
|
|
||
| @Override | ||
| public ILifecycleEventType getEventType() { | ||
| return TaskLifecycleEventType.FATAL; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "TaskFatalLifecycleEvent{" + | ||
| "task=" + taskExecutionRunnable.getName() + | ||
| ", endTime=" + endTime + | ||
| '}'; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.dolphinscheduler.server.master.engine.task.lifecycle.handler; | ||
|
|
||
| import org.apache.dolphinscheduler.server.master.engine.ILifecycleEventType; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.TaskLifecycleEventType; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event.TaskFatalLifecycleEvent; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.statemachine.ITaskStateAction; | ||
| import org.apache.dolphinscheduler.server.master.engine.workflow.runnable.IWorkflowExecutionRunnable; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| public class TaskFatalLifecycleEventHandler extends AbstractTaskLifecycleEventHandler<TaskFatalLifecycleEvent> { | ||
|
|
||
| @Override | ||
| public void handle(final ITaskStateAction taskStateAction, | ||
| final IWorkflowExecutionRunnable workflowExecutionRunnable, | ||
| final ITaskExecutionRunnable taskExecutionRunnable, | ||
| final TaskFatalLifecycleEvent taskFatalEvent) { | ||
| taskStateAction.onFatalEvent(workflowExecutionRunnable, taskExecutionRunnable, taskFatalEvent); | ||
| } | ||
|
|
||
| @Override | ||
| public ILifecycleEventType matchEventType() { | ||
| return TaskLifecycleEventType.FATAL; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ | |
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event.TaskDispatchLifecycleEvent; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event.TaskDispatchedLifecycleEvent; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event.TaskFailedLifecycleEvent; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event.TaskFatalLifecycleEvent; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event.TaskKilledLifecycleEvent; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event.TaskPausedLifecycleEvent; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event.TaskRetryLifecycleEvent; | ||
|
|
@@ -99,6 +100,29 @@ protected void releaseTaskInstanceResourcesIfNeeded(final ITaskExecutionRunnable | |
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void onFatalEvent(final IWorkflowExecutionRunnable workflowExecutionRunnable, | ||
| final ITaskExecutionRunnable taskExecutionRunnable, | ||
| final TaskFatalLifecycleEvent taskFatalEvent) { | ||
| releaseTaskInstanceResourcesIfNeeded(taskExecutionRunnable); | ||
|
|
||
| final TaskInstance taskInstance = taskExecutionRunnable.getTaskInstance(); | ||
| taskInstance.setState(TaskExecutionStatus.FAILURE); | ||
| taskInstance.setEndTime(taskFatalEvent.getEndTime()); | ||
| taskInstanceDao.updateById(taskInstance); | ||
|
Comment on lines
+109
to
+112
|
||
|
|
||
| // If all successors are condition tasks, then the task will not be marked as failure. | ||
| // And the DAG will continue to execute. | ||
| final IWorkflowExecutionGraph workflowExecutionGraph = taskExecutionRunnable.getWorkflowExecutionGraph(); | ||
| if (workflowExecutionGraph.isAllSuccessorsAreConditionTask(taskExecutionRunnable)) { | ||
| mergeTaskVarPoolToWorkflow(workflowExecutionRunnable, taskExecutionRunnable); | ||
| publishWorkflowInstanceTopologyLogicalTransitionEvent(taskExecutionRunnable); | ||
| return; | ||
| } | ||
| taskExecutionRunnable.getWorkflowExecutionGraph().markTaskExecutionRunnableChainFailure(taskExecutionRunnable); | ||
| publishWorkflowInstanceTopologyLogicalTransitionEvent(taskExecutionRunnable); | ||
| } | ||
|
|
||
| @Override | ||
| public void onDispatchedEvent(final IWorkflowExecutionRunnable workflowExecutionRunnable, | ||
| final ITaskExecutionRunnable taskExecutionRunnable, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event.TaskDispatchedLifecycleEvent; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event.TaskFailedLifecycleEvent; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event.TaskFailoverLifecycleEvent; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event.TaskFatalLifecycleEvent; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event.TaskKillLifecycleEvent; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event.TaskKilledLifecycleEvent; | ||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.event.TaskPauseLifecycleEvent; | ||
|
|
@@ -37,6 +38,7 @@ | |
| import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable; | ||
| import org.apache.dolphinscheduler.server.master.engine.workflow.runnable.IWorkflowExecutionRunnable; | ||
|
|
||
| import java.util.Date; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
@@ -109,7 +111,17 @@ public void onDispatchEvent(final IWorkflowExecutionRunnable workflowExecutionRu | |
| taskInstance.getDelayTime(), | ||
| remainTimeMills); | ||
| } | ||
| taskExecutionRunnable.initializeTaskExecutionContext(); | ||
| try { | ||
| taskExecutionRunnable.initializeTaskExecutionContext(); | ||
| } catch (Exception ex) { | ||
| log.error("Current taskInstance: {} initializeTaskExecutionContext error", taskInstance.getName(), ex); | ||
| final TaskFatalLifecycleEvent taskFatalEvent = TaskFatalLifecycleEvent.builder() | ||
| .taskExecutionRunnable(taskExecutionRunnable) | ||
| .endTime(new Date()) | ||
| .build(); | ||
| taskExecutionRunnable.getWorkflowEventBus().publish(taskFatalEvent); | ||
| return; | ||
| } | ||
|
Comment on lines
+114
to
+124
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to create a |
||
| workerGroupDispatcherCoordinator.dispatchTask(taskExecutionRunnable, remainTimeMills); | ||
| } | ||
|
|
||
|
|
||
Check notice
Code scanning / CodeQL
Missing Override annotation Note