DHBin opened a new pull request #8033: URL: https://github.com/apache/dolphinscheduler/pull/8033
<!--Thanks very much for contributing to Apache DolphinScheduler. Please review https://dolphinscheduler.apache.org/en-us/community/development/pull-request.html before opening a pull request.--> ## Purpose of the pull request fix when update process definition throw duplicate key 修复当更新任务流定义时会出现Key重复问题 抛出异常位置在org.apache.dolphinscheduler.service.process.ProcessService#transformTask中 ```java Map<Long, TaskDefinitionLog> taskDefinitionLogMap = taskDefinitionLogs.stream() .collect(Collectors.toMap(TaskDefinitionLog::getCode, taskDefinitionLog -> taskDefinitionLog)); ``` 复现方式: 1、创建一个任务流,并在图中创建一个任务,保存 2、更新任务流中的任务内容,比如SHELL脚本,这时任务版本+1,保存 3、打开任务流,直接点击保存,会抛出`Duplicate key TaskDefinition` 分析: org.apache.dolphinscheduler.service.process.ProcessService#genDagData ```java public DagData genDagData(ProcessDefinition processDefinition) { // 1 List<ProcessTaskRelation> taskRelations = this.findRelationByCode(processDefinition.getCode(), processDefinition.getVersion()); List<TaskDefinitionLog> taskDefinitionLogList = genTaskDefineList(taskRelations); List<TaskDefinition> taskDefinitions = taskDefinitionLogList.stream().map(t -> (TaskDefinition) t).collect(Collectors.toList()); return new DagData(processDefinition, taskRelations, taskDefinitions); } ``` org.apache.dolphinscheduler.api.service.impl.ProcessDefinitionServiceImpl#updateDagDefine ```java int insertVersion; // 2 if (processDefinition.equals(processDefinitionDeepCopy)) { insertVersion = processDefinitionDeepCopy.getVersion(); } else { processDefinition.setUpdateTime(new Date()); insertVersion = processService.saveProcessDefine(loginUser, processDefinition, Boolean.TRUE, Boolean.TRUE); } ``` 在`1`处是根据任务流定义的编码和版本号获取到任务的关系,在`2`处判断任务流的脚本信息如果不改变,不更新版本号,就导致了获取任务关系的时候出现同一个任务流版本号下有两个不同版本的同一个任务 修复方案: 因为org.apache.dolphinscheduler.api.service.impl.ProcessDefinitionServiceImpl#updateProcessDefinition涉及任务节点内容的更新,ProcessDefinition version + 1 ## Brief change log ## Verify this pull request <!--*(Please pick either of the following options)*--> This pull request is code cleanup without any test coverage. *(or)* This pull request is already covered by existing tests, such as *(please describe tests)*. (or) This change added tests and can be verified as follows: <!--*(example:)* - *Added dolphinscheduler-dao tests for end-to-end.* - *Added CronUtilsTest to verify the change.* - *Manually verified the change by testing locally.* --> -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
