ruanwenjun commented on code in PR #17759:
URL:
https://github.com/apache/dolphinscheduler/pull/17759#discussion_r2608866047
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/task/statemachine/AbstractTaskStateAction.java:
##########
@@ -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);
Review Comment:
```suggestion
persistentTaskInstanceFatalEventToDB(taskExecutionRunnable,
taskFatalEvent)
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/task/statemachine/TaskSubmittedStateAction.java:
##########
@@ -109,7 +110,12 @@ public void onDispatchEvent(final
IWorkflowExecutionRunnable workflowExecutionRu
taskInstance.getDelayTime(),
remainTimeMills);
}
- taskExecutionRunnable.initializeTaskExecutionContext();
+ try {
+ taskExecutionRunnable.initializeTaskExecutionContext();
+ } catch (Exception ex) {
+ log.error("Current taskInstance: {} initializeTaskExecutionContext
fail", taskInstance.getName(), ex);
+ throw new TaskFatalException(taskInstance.getName() + "
initializeTaskExecutionContext fail");
+ }
Review Comment:
```suggestion
taskExecutionRunnable.initializeTaskExecutionContext();
```
It's better to throw `TaskFatalException` in
`TaskExecutionContextFactory#createTaskExecutionContext` method. Not all
exception should be transformed to `TaskFatalException`.
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/task/lifecycle/TaskLifecycleEventType.java:
##########
@@ -29,6 +29,10 @@ public enum TaskLifecycleEventType implements
ILifecycleEventType {
* Dispatch the task instance to target.
*/
DISPATCH,
+ /**
+ * Severe and unrecoverable errors, such as initialization failure.
Review Comment:
```suggestion
* Task instance encounters catastrophic failure, it will enter a failed
state.
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/WorkflowEventBusFireWorker.java:
##########
@@ -128,6 +132,19 @@ private void doFireSingleWorkflowEventBus(final
IWorkflowExecutionRunnable workf
ThreadUtils.sleep(5_000);
return;
}
+ // the task encounters an unrecoverable error (e.g.,
initialization failure).
+ if (ExceptionUtils.isTaskFatalException(ex)) {
+ log.warn("Task fatal exception occurred during event
handling: {}", lifecycleEvent, ex);
+ if (lifecycleEvent instanceof TaskDispatchLifecycleEvent) {
Review Comment:
```suggestion
if (lifecycleEvent instanceof
AbstractTaskLifecycleEvent) {
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/task/statemachine/ITaskStateAction.java:
##########
@@ -89,7 +91,15 @@ void onRetryEvent(final IWorkflowExecutionRunnable
workflowExecutionRunnable,
*/
void onDispatchEvent(final IWorkflowExecutionRunnable
workflowExecutionRunnable,
final ITaskExecutionRunnable taskExecutionRunnable,
- final TaskDispatchLifecycleEvent taskDispatchEvent);
+ final TaskDispatchLifecycleEvent taskDispatchEvent)
throws TaskFatalException;
+
+ /**
+ * Perform the necessary actions when the task in a certain state receive
a {@link TaskFatalLifecycleEvent}.
+ * <p> This method is called when the task encounters an unrecoverable
error (e.g., initialization failure).
Review Comment:
```suggestion
* <p> This method is called when the task encounters catastrophic
failure (e.g., initialization failure).
```
We will still retry the task instance if config retry policy.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]