This is an automated email from the ASF dual-hosted git repository.
jinyleechina pushed a commit to branch 2.0.6-prepare
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/2.0.6-prepare by this push:
new d9ea80a [Bug-8790][Api]fix Duplicate key TaskDefinition (#8979)
d9ea80a is described below
commit d9ea80afec05ac1a19c2bf1f7d40a07937291d00
Author: caishunfeng <[email protected]>
AuthorDate: Fri Mar 18 19:01:41 2022 +0800
[Bug-8790][Api]fix Duplicate key TaskDefinition (#8979)
Co-authored-by: caishunfeng <[email protected]>
---
.../service/process/ProcessService.java | 41 ++++++++++++----------
1 file changed, 22 insertions(+), 19 deletions(-)
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 3c43823..ac10db2 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
@@ -2261,23 +2261,6 @@ public class ProcessService {
taskDefinitionLog.setOperateTime(now);
taskDefinitionLog.setOperator(operator.getId());
taskDefinitionLog.setResourceIds(getResourceIds(taskDefinitionLog));
- if (taskDefinitionLog.getCode() > 0 &&
taskDefinitionLog.getVersion() > 0) {
- TaskDefinitionLog definitionCodeAndVersion =
taskDefinitionLogMapper
-
.queryByDefinitionCodeAndVersion(taskDefinitionLog.getCode(),
taskDefinitionLog.getVersion());
- if (definitionCodeAndVersion != null) {
- if (!taskDefinitionLog.equals(definitionCodeAndVersion)) {
-
taskDefinitionLog.setUserId(definitionCodeAndVersion.getUserId());
- Integer version =
taskDefinitionLogMapper.queryMaxVersionForDefinition(taskDefinitionLog.getCode());
- taskDefinitionLog.setVersion(version + 1);
-
taskDefinitionLog.setCreateTime(definitionCodeAndVersion.getCreateTime());
- updateTaskDefinitionLogs.add(taskDefinitionLog);
- }
- continue;
- }
- }
- taskDefinitionLog.setUserId(operator.getId());
- taskDefinitionLog.setVersion(Constants.VERSION_FIRST);
- taskDefinitionLog.setCreateTime(now);
if (taskDefinitionLog.getCode() == 0) {
try {
taskDefinitionLog.setCode(CodeGenerateUtils.getInstance().genCode());
@@ -2286,7 +2269,27 @@ public class ProcessService {
return Constants.DEFINITION_FAILURE;
}
}
- newTaskDefinitionLogs.add(taskDefinitionLog);
+ if (taskDefinitionLog.getVersion() == 0) {
+ // init first version
+ taskDefinitionLog.setVersion(Constants.VERSION_FIRST);
+ }
+ TaskDefinitionLog definitionCodeAndVersion =
taskDefinitionLogMapper
+
.queryByDefinitionCodeAndVersion(taskDefinitionLog.getCode(),
taskDefinitionLog.getVersion());
+ if (definitionCodeAndVersion == null) {
+ taskDefinitionLog.setUserId(operator.getId());
+ taskDefinitionLog.setCreateTime(now);
+ newTaskDefinitionLogs.add(taskDefinitionLog);
+ continue;
+ }
+ if (taskDefinitionLog.equals(definitionCodeAndVersion)) {
+ // do nothing if equals
+ continue;
+ }
+ taskDefinitionLog.setUserId(definitionCodeAndVersion.getUserId());
+ Integer version =
taskDefinitionLogMapper.queryMaxVersionForDefinition(taskDefinitionLog.getCode());
+ taskDefinitionLog.setVersion(version + 1);
+
taskDefinitionLog.setCreateTime(definitionCodeAndVersion.getCreateTime());
+ updateTaskDefinitionLogs.add(taskDefinitionLog);
}
int insertResult = 0;
int updateResult = 0;
@@ -2304,7 +2307,7 @@ public class ProcessService {
}
}
}
- if (!newTaskDefinitionLogs.isEmpty()) {
+ if (CollectionUtils.isNotEmpty(newTaskDefinitionLogs)) {
insertResult +=
taskDefinitionLogMapper.batchInsert(newTaskDefinitionLogs);
if (Boolean.TRUE.equals(syncDefine)) {
updateResult +=
taskDefinitionMapper.batchInsert(newTaskDefinitionLogs);