github-actions[bot] commented on issue #18247:
URL: 
https://github.com/apache/dolphinscheduler/issues/18247#issuecomment-4428291225

   ### Search before asking
   
   - [x] I had searched in the 
[issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and 
found no similar issues.
   
   
   ### What happened
   
   When performing a forced success operation on a worker node instance through 
the public void forceTaskSuccess(User loginUser, long projectCode, Integer 
taskInstanceId) method, if the node is the only failed/kill node in the 
workflow, the workflow instance should be automatically marked as
     SUCCESS. But in reality the workflow instance is never promoted to SUCCESS.
   
   **Example:**
   I now have two worker node instances, one successful and one failed
   
   <img width="907" height="428" alt="Image" 
src="https://github.com/user-attachments/assets/850952f3-553d-4962-9f25-0681ecb0fa68";
 />
   Now I force this failed worker node instance to succeed
   
   <img width="1587" height="284" alt="Image" 
src="https://github.com/user-attachments/assets/cc1884d7-248c-4ed5-b2c9-1501a322a928";
 />
   According to the logic of 
processService.forceWorkflowInstanceSuccessByTaskInstanceId(task);, the 
corresponding workflow instance should be set to success.
   
   <img width="1266" height="280" alt="Image" 
src="https://github.com/user-attachments/assets/d10f552f-62c6-40d2-a668-2a241db52ece";
 />
   
   But the workflow instance status is not updated.
   
   
   ### What you expected to happen
   
   <img width="1266" height="280" alt="Image" 
src="https://github.com/user-attachments/assets/8fb69d49-a3f5-443c-a7ed-cf1f2be2e428";
 />
   
   The status of this workflow instance was successfully updated.
   
   ### How to reproduce
   
   In the forceTaskSuccess method, the task instance status is first updated to 
FORCED_SUCCESS and persisted to the database, and then 
processService.forceWorkflowInstanceSuccessByTaskInstanceId(task); is called.
   
   <img width="1117" height="540" alt="Image" 
src="https://github.com/user-attachments/assets/9174052b-8ee3-494f-8053-6710a210792d";
 />
   
   
   Within processService.forceWorkflowInstanceSuccessByTaskInstanceId, the task 
instance list will be re-queried from the database:
   List<TaskInstance> validTaskList = 
taskInstanceDao.queryValidTaskListByWorkflowInstanceId(workflowInstance.getId());
   
   At this time, the status of the task instance in the database is 
FORCED_SUCCESS (its own write operations in the same transaction should be read 
immediately), and it no longer meets the filtering conditions of isFailure() || 
isKill():
   
   List<Integer> failTaskList = validTaskList.stream()
         .filter(instance -> instance.getState().isFailure() || 
instance.getState().isKill())
         .map(TaskInstance::getId).collect(Collectors.toList());
   if (failTaskList.size() == 1 && failTaskList.contains(task.getId())) {
         // Never able to enter - failTaskList does not contain tasks that have 
been forced to succeed
   }
   
    Since the task that is forced to succeed is no longer in the failure/kill 
state, the situation of failTaskList is:
     - If it is the only failed node → failTaskList is empty → condition is not 
met
     - If there are other failed nodes → failTaskList does not contain the 
current task → failTaskList.contains(task.getId()) returns false
   
   Therefore, a workflow instance can never be marked SUCCESS.
   
   **Fix:**
   Change the calling order: call 
forceWorkflowInstanceSuccessByTaskInstanceId() before updating the task 
instance status, so that the original failure/kill status can be read during 
internal query:
   processService.forceWorkflowInstanceSuccessByTaskInstanceId(task);
   // change the state of the task instance
   task.setState(TaskExecutionStatus.FORCED_SUCCESS);
   task.setEndTime(new Date());
   int changedNum = taskInstanceMapper.updateById(task);
   if (changedNum <= 0) {
       throw new ServiceException(Status.FORCE_TASK_SUCCESS_ERROR);
   }
   
   ### Anything else
   
   _No response_
   
   ### Version
   
   dev
   
   ### 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](https://www.apache.org/foundation/policies/conduct)


-- 
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]

Reply via email to