diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java index 40cea0ba73..5f46c761ac 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java @@ -816,11 +816,9 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce try { processService.removeTaskLogFile(processInstanceId); - } catch (Exception ignore) { + } catch (Exception ex) { // ignore - logger.warn( - "Remove task log file exception, projectCode:{}, ProcessDefinitionCode{}, processInstanceId:{}.", - projectCode, processInstance.getProcessDefinitionCode(), processInstanceId); + logger.warn("Remove task log file exception, processInstanceId:{}.", processInstanceId, ex); } // delete database cascade @@ -828,7 +826,7 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce processService.deleteAllSubWorkProcessByParentId(processInstanceId); processService.deleteWorkProcessMapByParentId(processInstanceId); - processService.deleteWorkTaskInstanceByProcessInstanceId(processInstanceId); + taskInstanceDao.deleteByWorkflowInstanceId(processInstanceId); if (delete > 0) { logger.info( diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.java index 7bee2fc6b8..cd27167bfe 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.java @@ -153,4 +153,6 @@ public interface TaskInstanceMapper extends BaseMapper { List loadAllInfosNoRelease(@Param("processInstanceId") int processInstanceId, @Param("status") int status); + + void deleteByWorkflowInstanceId(@Param("workflowInstanceId") int workflowInstanceId); } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/TaskInstanceDao.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/TaskInstanceDao.java index 2b2adc9a3f..f132bbca64 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/TaskInstanceDao.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/TaskInstanceDao.java @@ -87,4 +87,6 @@ public interface TaskInstanceDao { */ List findTaskInstanceByIdList(List idList); + void deleteByWorkflowInstanceId(int workflowInstanceId); + } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/impl/TaskInstanceDaoImpl.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/impl/TaskInstanceDaoImpl.java index 648085cbd3..21058b6d95 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/impl/TaskInstanceDaoImpl.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/impl/TaskInstanceDaoImpl.java @@ -167,4 +167,9 @@ public class TaskInstanceDaoImpl implements TaskInstanceDao { return taskInstanceMapper.selectBatchIds(idList); } + @Override + public void deleteByWorkflowInstanceId(int workflowInstanceId) { + taskInstanceMapper.deleteByWorkflowInstanceId(workflowInstanceId); + } + } diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml index a9607740b2..3d988683ff 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml @@ -330,4 +330,10 @@ where instance.process_instance_id = #{processInstanceId} and que.status = #{status} + + + delete + from t_ds_task_instance + where process_instance_id = #{workflowInstanceId} + diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java index 74989430e4..bca4f0f7dc 100644 --- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java +++ b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java @@ -83,8 +83,6 @@ public interface ProcessService { void removeTaskLogFile(Integer processInstanceId); - void deleteWorkTaskInstanceByProcessInstanceId(int processInstanceId); - void recurseFindSubProcess(long parentCode, List ids); Tenant getTenantForProcess(int tenantId, int userId); diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java index a71edd61c0..226050dcb5 100644 --- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java +++ b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java @@ -527,27 +527,6 @@ public class ProcessServiceImpl implements ProcessService { } } - /** - * recursive delete all task instance by process instance id - */ - @Override - public void deleteWorkTaskInstanceByProcessInstanceId(int processInstanceId) { - ProcessInstance processInstance = processInstanceMapper.selectById(processInstanceId); - List taskInstanceList = - taskInstanceDao.findValidTaskListByProcessId(processInstanceId, processInstance.getTestFlag()); - if (CollectionUtils.isEmpty(taskInstanceList)) { - return; - } - - List taskInstanceIdList = new ArrayList<>(); - - for (TaskInstance taskInstance : taskInstanceList) { - taskInstanceIdList.add(taskInstance.getId()); - } - - taskInstanceMapper.deleteBatchIds(taskInstanceIdList); - } - /** * recursive query sub process definition id by parent id. *