[Bug] Using the subprocess node, after the sub-node ends, the task will not be executed backwards
Search before asking
- [X] I had searched in the issues and found no similar issues.
What happened
使用sub_process 节点,子节点结束后,任务不会向后执行
What you expected to happen
帮忙看看这个问题
How to reproduce
sub_process 按官方文档中的使用方法就可以复现
Anything else
No response
Version
3.2.x
Are you willing to submit PR?
- [ ] Yes I am willing to submit a PR!
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
Search before asking
- [X] I had searched in the issues and found no similar issues.
What happened
Using the sub_process node, after the sub-node ends, the task will not be executed backwards
What you expected to happen
Help with this issue
How to reproduce
sub_process can be reproduced according to the usage method in the official documentation.
Anything else
No response
Version
3.2.x
Are you willing to submit PR?
- [ ] Yes I am willing to submit a PR!
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
Keep only one master node
https://lqwang.net/40.html
https://lqwang.net/40.html
Hi, This fix is base on 3.1.1 and fixed at 3.1.9.
Now we are using 3.2.0, the code sturct is different, and still has this issue.
I am using version 3.2.0.
I found some abnormal logs in the logs.
[INFO] 2025-03-07 11:45:21.157 +0800 org.apache.dolphinscheduler.server.master.runner.WorkflowExecuteRunnable:[292] - [WorkflowInstance-182][TaskInstance-323] - Begin to handle state event, TaskStateEvent(processInstanceId=182, taskInstanceId=323, taskCode=0, status=null, type=TASK_STATE_CHANGE, key=183-0-182-323, channel=null, context=null)
[WARN] 2025-03-07 11:45:22.157 +0800 org.apache.dolphinscheduler.server.master.event.TaskStateEventHandler:[96] - [WorkflowInstance-182][TaskInstance-323] - The task event is broken..., taskEvent: TaskStateEvent(processInstanceId=182, taskInstanceId=323, taskCode=0, status=null, type=TASK_STATE_CHANGE, key=183-0-182-323, channel=null, context=null)
https://github.com/apache/dolphinscheduler/blob/3.2.0-release/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkflowExecuteRunnable.java#L292
https://github.com/apache/dolphinscheduler/blob/3.2.0-release/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/event/TaskStateEventHandler.java#L94
the processInstanceId 292 is the parent process instance id (this process job that include sub_process task), the taskInstance 323 is the sub_process task instance id.
This event is TASK_STATE_CHANGE event, and it required status can't be null.
But in this event, the status is null. can't handle this event, and this event won't be removed from the queue stateEvents. So from the server log we can see a lots of log about this event.
Could someone give me some guide about why this status is null?
I think this maybe related to this sub_process task can't finished issue.
I find the root cause. It due to the status update issue. Related to 2 classes
WorkflowExecuteThreadPool
When sub_process job finished (success or failed). it will call notifyProcessChanged method https://github.com/apache/dolphinscheduler/blob/3.2.0-release/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/runner/WorkflowExecuteThreadPool.java#L146
In this method, there are 2 issues:
crossWorkflowParameterPassingmethod will getNullPointException. But this won't have any impact, just print error log
private void crossWorkflowParameterPassing(ProcessInstance finishProcessInstance, TaskInstance taskInstance) {
try {
// when task finished, it will removed. so here get result will be null
MasterTaskExecuteRunnable masterTaskExecuteRunnable =
MasterTaskExecuteRunnableHolder.getMasterTaskExecuteRunnable(taskInstance.getId());
masterTaskExecuteRunnable.getILogicTask().getTaskParameters()
.setVarPool(finishProcessInstance.getVarPool());
log.info("Cross workflow parameter passing success, finishProcessInstanceId: {}, taskInstanceId: {}",
finishProcessInstance.getId(), taskInstance.getId());
} catch (Exception ex) {
log.error("Cross workflow parameter passing error, finishProcessInstanceId: {}, taskInstanceId: {}",
finishProcessInstance.getId(), taskInstance.getId(), ex);
}
}
notifyProcessandnotifyMyselfmethod
I am not sure why there have different process logical. I think there should only be notify address is different. but now there have different process logical.
And that why when use standalone or 1 master mode, it can't be repeat.
when call notifyProcess method, it will generate WorkflowStateEventChangeRequest message to other master node.
The generated message is
WorkflowStateEventChangeRequest workflowStateEventChangeRequest = new WorkflowStateEventChangeRequest(
finishProcessInstance.getId(), 0, finishProcessInstance.getState(), processInstance.getId(),
taskInstance.getId());
Please notice sourceTaskInstanceId is set to 0, destTaskInstanceId is set to sub_process task instance id.
StateEventProcessor
When send message to other master node, it will call StateEventProcessor.process() method
https://github.com/apache/dolphinscheduler/blob/3.2.0-release/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/processor/StateEventProcessor.java#L51
public void process(Channel channel, Message message) {
WorkflowStateEventChangeRequest workflowStateEventChangeRequest =
JSONUtils.parseObject(message.getBody(), WorkflowStateEventChangeRequest.class);
StateEvent stateEvent;
if (workflowStateEventChangeRequest.getDestTaskInstanceId() == 0) {
stateEvent = createWorkflowStateEvent(workflowStateEventChangeRequest);
} else {
stateEvent = createTaskStateEvent(workflowStateEventChangeRequest);
}
try (
final LogUtils.MDCAutoClosableContext mdcAutoClosableContext = LogUtils.setWorkflowAndTaskInstanceIDMDC(
stateEvent.getProcessInstanceId(), stateEvent.getTaskInstanceId())) {
log.info("Received state change command, event: {}", stateEvent);
stateEventResponseService.addStateChangeEvent(stateEvent);
}
}
when receiving the message sent above ( sourceTaskInstanceId = 0, getDestTaskInstanceId = sub_process_task_instance_id ). It will call createTaskStateEvent method. and send it to next step.
private TaskStateEvent createTaskStateEvent(WorkflowStateEventChangeRequest workflowStateEventChangeRequest) {
return TaskStateEvent.builder()
.processInstanceId(workflowStateEventChangeRequest.getDestProcessInstanceId())
.taskInstanceId(workflowStateEventChangeRequest.getDestTaskInstanceId())
.type(StateEventType.TASK_STATE_CHANGE)
.key(workflowStateEventChangeRequest.getKey())
.build();
}
In this method, will create a TaskStateEvent, this event is to describe sub_process task status. Event type is StateEventType.TASK_STATE_CHANGE, but not set status field.
So when StateEventResponseService receive this event and process it.
The code stack is
StateEventResponseService.addStateChangeEvent(stateEvent);
WorkflowExecuteThreadPool.submitStateEvent(stateEvent)
WorkflowExecuteThread.addStateEvent(stateEvent)
WorkflowExecuteRunnable.handleEvents()
Then it will go to TaskStateEventHandler.handleStateEvent() method
in this class, it has status field check
if (taskStateEvent == null || taskStateEvent.getStatus() == null) {
// the event is broken
log.warn("The task event is broken..., taskEvent: {}", taskStateEvent);
return;
}
So this event will never process. and never remove from the queue ( WorkflowExecuteRunnable.stateEvents )
How to fix
From the above, we can see the problem is on this method.
private TaskStateEvent createTaskStateEvent(WorkflowStateEventChangeRequest workflowStateEventChangeRequest) {
return TaskStateEvent.builder()
.processInstanceId(workflowStateEventChangeRequest.getDestProcessInstanceId())
.taskInstanceId(workflowStateEventChangeRequest.getDestTaskInstanceId())
.type(StateEventType.TASK_STATE_CHANGE)
.key(workflowStateEventChangeRequest.getKey())
.build();
}
In my fix, I set the status by workflow execution status (maybe not set all cases, but most cases it can work well)
private TaskStateEvent createTaskStateEvent(WorkflowStateEventChangeRequest workflowStateEventChangeRequest) {
return TaskStateEvent.builder()
.processInstanceId(workflowStateEventChangeRequest.getDestProcessInstanceId())
.taskInstanceId(workflowStateEventChangeRequest.getDestTaskInstanceId())
.type(StateEventType.TASK_STATE_CHANGE)
.status(workflowExecutionStatusToTaskExecutionStatus(workflowStateEventChangeRequest.getSourceStatus()))
.key(workflowStateEventChangeRequest.getKey())
.build();
}
private TaskExecutionStatus workflowExecutionStatusToTaskExecutionStatus(WorkflowExecutionStatus workflowExecutionStatus) {
switch (workflowExecutionStatus) {
case SUCCESS:
return TaskExecutionStatus.SUCCESS;
case FAILURE:
return TaskExecutionStatus.FAILURE;
case STOP:
return TaskExecutionStatus.STOP;
case RUNNING_EXECUTION:
return TaskExecutionStatus.RUNNING_EXECUTION;
default:
log.info("Received un-expected workflow execution status: {}", workflowExecutionStatus);
return TaskExecutionStatus.RUNNING_EXECUTION;
}
}
cc @SbloodyS @ruanwenjun PTAL
cc @SbloodyS @ruanwenjun PTAL
The whole logic has been refactored at 3.3.0, and there is no plan to maintain the 3.2.x 😢
cc @SbloodyS @ruanwenjun PTAL
The whole logic has been refactored at 3.3.0, and there is no plan to maintain the 3.2.x 😢
Looking forward 3.3.0 release. 👍
cc @SbloodyS @ruanwenjun PTAL
The whole logic has been refactored at 3.3.0, and there is no plan to maintain the 3.2.x 😢
Looking forward 3.3.0 release. 👍
3.3.0-alpha has been released, you can try.