From 8980b7027a30f75445882280e5872b49985a5188 Mon Sep 17 00:00:00 2001 From: JinYong Li <42576980+JinyLeeChina@users.noreply.github.com> Date: Tue, 21 Sep 2021 22:35:50 +0800 Subject: [PATCH] fix deleteProcessDefinitionVersion bug (#6287) Co-authored-by: JinyLeeChina <297062848@qq.com> --- .../service/impl/ProcessDefinitionServiceImpl.java | 13 ++++++++++++- .../dao/mapper/ProcessTaskRelationLogMapper.java | 10 ++++++++++ .../dao/mapper/ProcessTaskRelationLogMapper.xml | 5 +++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java index a8c5d67b3d..f9c0952dce 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java @@ -23,6 +23,7 @@ import org.apache.dolphinscheduler.api.dto.DagDataSchedule; import org.apache.dolphinscheduler.api.dto.treeview.Instance; import org.apache.dolphinscheduler.api.dto.treeview.TreeViewDto; import org.apache.dolphinscheduler.api.enums.Status; +import org.apache.dolphinscheduler.api.exceptions.ServiceException; import org.apache.dolphinscheduler.api.service.ProcessDefinitionService; import org.apache.dolphinscheduler.api.service.ProcessInstanceService; import org.apache.dolphinscheduler.api.service.ProjectService; @@ -59,6 +60,7 @@ import org.apache.dolphinscheduler.dao.entity.Tenant; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionLogMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; +import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationLogMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; @@ -143,6 +145,9 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro @Autowired private ProcessTaskRelationMapper processTaskRelationMapper; + @Autowired + private ProcessTaskRelationLogMapper processTaskRelationLogMapper; + @Autowired TaskDefinitionLogMapper taskDefinitionLogMapper; @@ -1422,6 +1427,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro * @return delele result code */ @Override + @Transactional(rollbackFor = RuntimeException.class) public Map deleteProcessDefinitionVersion(User loginUser, long projectCode, long code, int version) { Project project = projectMapper.queryByCode(projectCode); //check user access for project @@ -1434,7 +1440,12 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro if (processDefinition == null) { putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, code); } else { - processDefinitionLogMapper.deleteByProcessDefinitionCodeAndVersion(code, version); + int deleteLog = processDefinitionLogMapper.deleteByProcessDefinitionCodeAndVersion(code, version); + int deleteRelationLog = processTaskRelationLogMapper.deleteByCode(processDefinition.getCode(), processDefinition.getVersion()); + if ((deleteLog & deleteRelationLog) == 0) { + putMsg(result, Status.DELETE_PROCESS_DEFINE_BY_CODE_ERROR); + throw new ServiceException(Status.DELETE_PROCESS_DEFINE_BY_CODE_ERROR); + } putMsg(result, Status.SUCCESS); } return result; diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationLogMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationLogMapper.java index e735a1cff7..472018baf6 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationLogMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationLogMapper.java @@ -47,4 +47,14 @@ public interface ProcessTaskRelationLogMapper extends BaseMapper taskRelationList); + + /** + * delete process task relation log by processCode and version + * + * @param processCode process definition code + * @param processVersion process version + * @return int + */ + int deleteByCode(@Param("processCode") long processCode, + @Param("processVersion") int processVersion); } diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationLogMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationLogMapper.xml index 3e11f97408..2eafb31a84 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationLogMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationLogMapper.xml @@ -41,4 +41,9 @@ #{relation.createTime},#{relation.updateTime}) + + delete from t_ds_process_task_relation_log + WHERE process_definition_code = #{processCode} + and process_definition_version = #{processVersion} +