From 8a152aebc70f57cc400c1cd8b16991817bed0d0e Mon Sep 17 00:00:00 2001 From: Wenjun Ruan Date: Tue, 6 Dec 2022 11:23:20 +0800 Subject: [PATCH] Fix task log file might not be clear (#13102) --- .../service/impl/ProcessInstanceServiceImpl.java | 11 ++++------- .../dao/mapper/TaskInstanceMapper.java | 2 ++ .../dao/repository/TaskInstanceDao.java | 1 + .../dao/repository/impl/TaskInstanceDaoImpl.java | 5 +++++ .../dao/mapper/TaskInstanceMapper.xml | 6 ++++++ .../dolphinscheduler/service/log/LogClient.java | 14 ++++++-------- .../service/process/ProcessServiceImpl.java | 15 +++++++++------ .../service/log/LogClientTest.java | 2 +- 8 files changed, 34 insertions(+), 22 deletions(-) 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 5f46c761ac..be1ff200dd 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 @@ -814,18 +814,15 @@ public class ProcessInstanceServiceImpl extends BaseServiceImpl implements Proce throw new ServiceException(PROCESS_INSTANCE_NOT_EXIST, processInstanceId); } - try { - processService.removeTaskLogFile(processInstanceId); - } catch (Exception ex) { - // ignore - logger.warn("Remove task log file exception, processInstanceId:{}.", processInstanceId, ex); - } - // delete database cascade int delete = processService.deleteWorkProcessInstanceById(processInstanceId); processService.deleteAllSubWorkProcessByParentId(processInstanceId); processService.deleteWorkProcessMapByParentId(processInstanceId); + // We need to remove the task log file before deleting the task instance + // because the task log file is query from task instance. + // When delete task instance error, the task log file will also be deleted, this may cause data inconsistency. + processService.removeTaskLogFile(processInstanceId); taskInstanceDao.deleteByWorkflowInstanceId(processInstanceId); if (delete > 0) { 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 cd27167bfe..faa481e294 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 @@ -155,4 +155,6 @@ public interface TaskInstanceMapper extends BaseMapper { @Param("status") int status); void deleteByWorkflowInstanceId(@Param("workflowInstanceId") int workflowInstanceId); + + List findByWorkflowInstanceId(@Param("workflowInstanceId") Integer 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 f132bbca64..4c16a56322 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 @@ -89,4 +89,5 @@ public interface TaskInstanceDao { void deleteByWorkflowInstanceId(int workflowInstanceId); + List findTaskInstanceByWorkflowInstanceId(Integer processInstanceId); } 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 21058b6d95..aca18171b7 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 @@ -172,4 +172,9 @@ public class TaskInstanceDaoImpl implements TaskInstanceDao { taskInstanceMapper.deleteByWorkflowInstanceId(workflowInstanceId); } + @Override + public List findTaskInstanceByWorkflowInstanceId(Integer workflowInstanceId) { + return taskInstanceMapper.findByWorkflowInstanceId(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 3d988683ff..d3726ebf95 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 @@ -57,6 +57,12 @@ and test_flag=#{testFlag} order by start_time desc +