Browse Source

[Fix #15129] [Dependent] The date rules of the dependent node are ambiguous. (#15289)

* [Fix-15129][Dependent] Fix the ambiguity in date rules for dependent node.

* [fix #15129] Revert ddl

* restore findLastProcessInterval

* update: mvn spotless:apply

---------

Co-authored-by: 李乐 <lile@boimc.com>
Co-authored-by: xiangzihao <460888207@qq.com>
3.2.1-prepare
ll 12 months ago committed by GitHub
parent
commit
0c470ffe66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.java
  2. 12
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/TaskInstanceDao.java
  3. 16
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/impl/TaskInstanceDaoImpl.java
  4. 14
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml
  5. 18
      dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/utils/DependentExecute.java

12
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.java

@ -170,18 +170,14 @@ public interface TaskInstanceMapper extends BaseMapper<TaskInstance> {
* find last task instance list in the date interval * find last task instance list in the date interval
* *
* @param taskCodes taskCodes * @param taskCodes taskCodes
* @param startTime startTime
* @param endTime endTime
* @param testFlag testFlag * @param testFlag testFlag
* @return task instance list * @return task instance list
*/ */
List<TaskInstance> findLastTaskInstances(@Param("taskCodes") Set<Long> taskCodes, List<TaskInstance> findLastTaskInstances(@Param("processInstanceId") Integer processInstanceId,
@Param("startTime") Date startTime, @Param("taskCodes") Set<Long> taskCodes,
@Param("endTime") Date endTime,
@Param("testFlag") int testFlag); @Param("testFlag") int testFlag);
TaskInstance findLastTaskInstance(@Param("taskCode") long depTaskCode, TaskInstance findLastTaskInstance(@Param("processInstanceId") Integer processInstanceId,
@Param("startTime") Date startTime, @Param("taskCode") long depTaskCode,
@Param("endTime") Date endTime,
@Param("testFlag") int testFlag); @Param("testFlag") int testFlag);
} }

12
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/TaskInstanceDao.java

@ -19,7 +19,6 @@ package org.apache.dolphinscheduler.dao.repository;
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
import org.apache.dolphinscheduler.dao.entity.TaskInstance; import org.apache.dolphinscheduler.dao.entity.TaskInstance;
import org.apache.dolphinscheduler.plugin.task.api.model.DateInterval;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -91,20 +90,21 @@ public interface TaskInstanceDao extends IDao<TaskInstance> {
/** /**
* find last task instance list corresponding to taskCodes in the date interval * find last task instance list corresponding to taskCodes in the date interval
* *
* @param processInstanceId Task's parent process instance id
* @param taskCodes taskCodes * @param taskCodes taskCodes
* @param dateInterval dateInterval
* @param testFlag test flag * @param testFlag test flag
* @return task instance list * @return task instance list
*/ */
List<TaskInstance> queryLastTaskInstanceListIntervalByTaskCodes(Set<Long> taskCodes, DateInterval dateInterval, List<TaskInstance> queryLastTaskInstanceListIntervalInProcessInstance(Integer processInstanceId,
int testFlag); Set<Long> taskCodes, int testFlag);
/** /**
* find last task instance corresponding to taskCode in the date interval * find last task instance corresponding to taskCode in the date interval
* @param processInstanceId Task's parent process instance id
* @param depTaskCode taskCode * @param depTaskCode taskCode
* @param dateInterval dateInterval
* @param testFlag test flag * @param testFlag test flag
* @return task instance * @return task instance
*/ */
TaskInstance queryLastTaskInstanceIntervalByTaskCode(long depTaskCode, DateInterval dateInterval, int testFlag); TaskInstance queryLastTaskInstanceIntervalInProcessInstance(Integer processInstanceId,
long depTaskCode, int testFlag);
} }

16
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/impl/TaskInstanceDaoImpl.java

@ -27,7 +27,6 @@ import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper;
import org.apache.dolphinscheduler.dao.repository.BaseDao; import org.apache.dolphinscheduler.dao.repository.BaseDao;
import org.apache.dolphinscheduler.dao.repository.TaskInstanceDao; import org.apache.dolphinscheduler.dao.repository.TaskInstanceDao;
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
import org.apache.dolphinscheduler.plugin.task.api.model.DateInterval;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -174,16 +173,15 @@ public class TaskInstanceDaoImpl extends BaseDao<TaskInstance, TaskInstanceMappe
} }
@Override @Override
public List<TaskInstance> queryLastTaskInstanceListIntervalByTaskCodes(Set<Long> taskCodes, public List<TaskInstance> queryLastTaskInstanceListIntervalInProcessInstance(Integer processInstanceId,
DateInterval dateInterval, int testFlag) { Set<Long> taskCodes,
return mybatisMapper.findLastTaskInstances(taskCodes, dateInterval.getStartTime(), dateInterval.getEndTime(), int testFlag) {
testFlag); return mybatisMapper.findLastTaskInstances(processInstanceId, taskCodes, testFlag);
} }
@Override @Override
public TaskInstance queryLastTaskInstanceIntervalByTaskCode(long depTaskCode, DateInterval dateInterval, public TaskInstance queryLastTaskInstanceIntervalInProcessInstance(Integer processInstanceId, long depTaskCode,
int testFlag) { int testFlag) {
return mybatisMapper.findLastTaskInstance(depTaskCode, dateInterval.getStartTime(), dateInterval.getEndTime(), return mybatisMapper.findLastTaskInstance(processInstanceId, depTaskCode, testFlag);
testFlag);
} }
} }

14
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml

@ -350,27 +350,25 @@
select task_code, max(end_time) as max_end_time select task_code, max(end_time) as max_end_time
from t_ds_task_instance from t_ds_task_instance
where 1=1 and test_flag = #{testFlag} where 1=1 and test_flag = #{testFlag}
and instance.process_instance_id = #{processInstanceId}
<if test="taskCodes != null and taskCodes.size() != 0"> <if test="taskCodes != null and taskCodes.size() != 0">
and task_code in and task_code in
<foreach collection="taskCodes" index="index" item="i" open="(" separator="," close=")"> <foreach collection="taskCodes" index="index" item="i" open="(" separator="," close=")">
#{i} #{i}
</foreach> </foreach>
</if> </if>
<if test="startTime!=null and endTime != null">
and start_time <![CDATA[ >= ]]> #{startTime} and start_time <![CDATA[ <= ]]> #{endTime}
</if>
group by task_code group by task_code
) t_max ) t_max
on instance.task_code = t_max.task_code and instance.end_time = t_max.max_end_time on instance.process_instance_id = t_max.process_instance_id
and instance.task_code = t_max.task_code
and instance.end_time = t_max.max_end_time
</select> </select>
<select id="findLastTaskInstance" resultType="org.apache.dolphinscheduler.dao.entity.TaskInstance"> <select id="findLastTaskInstance" resultType="org.apache.dolphinscheduler.dao.entity.TaskInstance">
select select
<include refid="baseSql"/> <include refid="baseSql"/>
from t_ds_task_instance from t_ds_task_instance
where task_code = #{taskCode} where process_instance_id = #{processInstanceId}
<if test="startTime!=null and endTime != null"> and task_code = #{taskCode}
and start_time <![CDATA[ >= ]]> #{startTime} and start_time <![CDATA[ <= ]]> #{endTime}
</if>
order by end_time desc limit 1 order by end_time desc limit 1
</select> </select>

18
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/utils/DependentExecute.java

@ -158,10 +158,9 @@ public class DependentExecute {
if (dependentItem.getDepTaskCode() == Constants.DEPENDENT_WORKFLOW_CODE) { if (dependentItem.getDepTaskCode() == Constants.DEPENDENT_WORKFLOW_CODE) {
result = dependResultByProcessInstance(processInstance); result = dependResultByProcessInstance(processInstance);
} else if (dependentItem.getDepTaskCode() == Constants.DEPENDENT_ALL_TASK_CODE) { } else if (dependentItem.getDepTaskCode() == Constants.DEPENDENT_ALL_TASK_CODE) {
result = dependResultByAllTaskOfProcessInstance(processInstance, dateInterval, testFlag); result = dependResultByAllTaskOfProcessInstance(processInstance, testFlag);
} else { } else {
result = dependResultBySingleTaskInstance(processInstance, dependentItem.getDepTaskCode(), dateInterval, result = dependResultBySingleTaskInstance(processInstance, dependentItem.getDepTaskCode(), testFlag);
testFlag);
} }
if (result != DependResult.SUCCESS) { if (result != DependResult.SUCCESS) {
break; break;
@ -194,8 +193,7 @@ public class DependentExecute {
* *
* @return * @return
*/ */
private DependResult dependResultByAllTaskOfProcessInstance(ProcessInstance processInstance, private DependResult dependResultByAllTaskOfProcessInstance(ProcessInstance processInstance, int testFlag) {
DateInterval dateInterval, int testFlag) {
if (!processInstance.getState().isFinished()) { if (!processInstance.getState().isFinished()) {
log.info("Wait for the dependent workflow to complete, processCode: {}, processInstanceId: {}.", log.info("Wait for the dependent workflow to complete, processCode: {}, processInstanceId: {}.",
processInstance.getProcessDefinitionCode(), processInstance.getId()); processInstance.getProcessDefinitionCode(), processInstance.getId());
@ -212,8 +210,8 @@ public class DependentExecute {
.collect(Collectors.toMap(TaskDefinitionLog::getCode, TaskDefinitionLog::getName)); .collect(Collectors.toMap(TaskDefinitionLog::getCode, TaskDefinitionLog::getName));
List<TaskInstance> taskInstanceList = List<TaskInstance> taskInstanceList =
taskInstanceDao.queryLastTaskInstanceListIntervalByTaskCodes(taskDefinitionCodeMap.keySet(), taskInstanceDao.queryLastTaskInstanceListIntervalInProcessInstance(processInstance.getId(),
dateInterval, testFlag); taskDefinitionCodeMap.keySet(), testFlag);
Map<Long, TaskExecutionStatus> taskExecutionStatusMap = Map<Long, TaskExecutionStatus> taskExecutionStatusMap =
taskInstanceList.stream() taskInstanceList.stream()
.filter(taskInstance -> taskInstance.getTaskExecuteType() != TaskExecuteType.STREAM) .filter(taskInstance -> taskInstance.getTaskExecuteType() != TaskExecuteType.STREAM)
@ -245,14 +243,14 @@ public class DependentExecute {
* *
* @param processInstance last process instance in the date interval * @param processInstance last process instance in the date interval
* @param depTaskCode the dependent task code * @param depTaskCode the dependent task code
* @param dateInterval date interval
* @param testFlag test flag * @param testFlag test flag
* @return depend result * @return depend result
*/ */
private DependResult dependResultBySingleTaskInstance(ProcessInstance processInstance, long depTaskCode, private DependResult dependResultBySingleTaskInstance(ProcessInstance processInstance, long depTaskCode,
DateInterval dateInterval, int testFlag) { int testFlag) {
TaskInstance taskInstance = TaskInstance taskInstance =
taskInstanceDao.queryLastTaskInstanceIntervalByTaskCode(depTaskCode, dateInterval, testFlag); taskInstanceDao.queryLastTaskInstanceIntervalInProcessInstance(processInstance.getId(),
depTaskCode, testFlag);
if (taskInstance == null) { if (taskInstance == null) {
TaskDefinition taskDefinition = taskDefinitionDao.queryByCode(depTaskCode); TaskDefinition taskDefinition = taskDefinitionDao.queryByCode(depTaskCode);

Loading…
Cancel
Save