ruanwenjun commented on code in PR #12874:
URL: 
https://github.com/apache/dolphinscheduler/pull/12874#discussion_r1020834741


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java:
##########
@@ -165,20 +161,21 @@ protected void handleDefaultWorkGroup(WorkerGroupMapper 
workerGroupMapper, Worke
      * @return boolean
      */
     private boolean checkWorkerGroupNameExists(WorkerGroup workerGroup) {
+        // check database
         List<WorkerGroup> workerGroupList = 
workerGroupMapper.queryWorkerGroupByName(workerGroup.getName());
         if (CollectionUtils.isNotEmpty(workerGroupList)) {
-            // new group has same name
+            // create group, the same group name exists in the database
             if (workerGroup.getId() == null) {
                 return true;
             }
-            // check group id
-            for (WorkerGroup group : workerGroupList) {
-                if (Objects.equals(group.getId(), workerGroup.getId())) {
-                    return true;
-                }
+            // update group, the database exists with the same group name 
except itself
+            Optional<WorkerGroup> sameNameWorkGroupOptional = 
workerGroupList.stream()
+                    .filter(group -> !Objects.equals(group.getId(), 
workerGroup.getId())).findFirst();
+            if (sameNameWorkGroupOptional.isPresent()) {
+                return true;
             }
         }
-        // check zookeeper
+        // check registry server

Review Comment:
   We don't need to check the worker group exist in registry, we have removed 
the worker group in registry path.



-- 
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]

Reply via email to