You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2022/08/28 05:43:13 UTC

[GitHub] [dolphinscheduler] zhongjiajie commented on a diff in pull request #11490: [Fix] Delete task definition when delete workflow

zhongjiajie commented on code in PR #11490:
URL: https://github.com/apache/dolphinscheduler/pull/11490#discussion_r956665935


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java:
##########
@@ -877,9 +864,25 @@ public Map<String, Object> deleteProcessDefinitionByCode(User loginUser, long pr
             putMsg(result, Status.DELETE_PROCESS_DEFINE_BY_CODE_ERROR);
             throw new ServiceException(Status.DELETE_PROCESS_DEFINE_BY_CODE_ERROR);
         }
-        int deleteRelation = processTaskRelationMapper.deleteByCode(project.getCode(), processDefinition.getCode());
-        if (deleteRelation == 0) {
-            logger.warn("The process definition has not relation, it will be delete successfully");
+        processDefinitionLogMapper.deleteByProcessDefinitionCode(code);
+        List<ProcessTaskRelation> processTaskRelations =
+                processTaskRelationMapper.queryByProcessCode(project.getCode(), code);
+        if (!processTaskRelations.isEmpty()) {
+            int deleteRelation = processTaskRelationMapper.deleteByCode(project.getCode(), code);
+            if (deleteRelation == 0) {
+                logger.warn("The process definition has not relation, it will be delete successfully");
+            } else {
+                processTaskRelationLogMapper.deleteByProcessCode(code);
+                // delete relation task definition
+                List<Long> taskCodeList = processTaskRelations.stream().map(ProcessTaskRelation::getPostTaskCode)
+                        .collect(Collectors.toList());
+                int deleteTask = taskDefinitionMapper.deleteByCodeList(taskCodeList);

Review Comment:
   in the table task definition, we use `project` and `code` as unique key instead of `project`, `process_code` and `code`. This means the same task can be reused in more than one process definition, So I do not think we should delete the task definition when a single process definition is deleted, Am I right? @caishunfeng @SbloodyS 



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org