Mrhs121 commented on code in PR #17799:
URL:
https://github.com/apache/dolphinscheduler/pull/17799#discussion_r2623839189
##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectWorkerGroupRelationServiceImpl.java:
##########
@@ -94,7 +94,25 @@ public Result assignWorkerGroupsToProject(User loginUser,
Long projectCode, List
return result;
}
+ Project project = projectMapper.queryByCode(projectCode);
+ if (Objects.isNull(project)) {
+ putMsg(result, Status.PROJECT_NOT_EXIST);
+ return result;
+ }
+
if (CollectionUtils.isEmpty(workerGroups)) {
+ Set<String> projectWorkerGroupNames =
+
projectWorkerGroupDao.queryAssignedWorkerGroupNamesByProjectCode(projectCode);
+ if (CollectionUtils.isNotEmpty(projectWorkerGroupNames)) {
+ Set<String> usedWorkerGroups = getAllUsedWorkerGroups(project);
+ if (CollectionUtils.isNotEmpty(usedWorkerGroups)) {
+ Set<String> usedInProject =
SetUtils.intersection(usedWorkerGroups, projectWorkerGroupNames);
+ if (!usedInProject.isEmpty()) {
+ throw new
ServiceException(Status.USED_WORKER_GROUP_EXISTS, usedInProject);
+ }
+ }
Review Comment:
Thank you for the insightful review, You're absolutely right about the
concurrency risk.
For instance, the `getAllUsedWorkerGroups` check and the subsequent delete
operation are not atomic. There is indeed a theoretical window where concurrent
operations (like createTaskDefinition, updateTaskDefinition) could create or
modify tasks using the Worker Groups that are about to be removed. Perhaps
could open a DSIP to refactor the existing metadata design.
Do you think it's okay to add a simple row lock and transactional to this
pr, such as simply changing the original select to select wg from xx for update.
--
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]