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 2021/08/07 03:22:47 UTC

[GitHub] [dolphinscheduler] kyoty commented on a change in pull request #5912: [NEW FEATURE][FIX-4385] compensation task add the ability to configure parallelism

kyoty commented on a change in pull request #5912:
URL: https://github.com/apache/dolphinscheduler/pull/5912#discussion_r684576386



##########
File path: dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java
##########
@@ -553,14 +555,21 @@ private int createCommand(CommandType commandType, int processDefineId,
                         }
                     }
                     if (!CollectionUtils.isEmpty(listDate)) {
-                        // loop by schedule date
-                        for (Date date : listDate) {
-                            cmdParam.put(CMDPARAM_COMPLEMENT_DATA_START_DATE, DateUtils.dateToString(date));
-                            cmdParam.put(CMDPARAM_COMPLEMENT_DATA_END_DATE, DateUtils.dateToString(date));
+
+                        int effectThreadsCount = expectedParallelismNumber == null ? 1 : Math.min(listDate.size(), expectedParallelismNumber);
+                        logger.info("In parallel mode, current expectedParallelismNumber:{}", expectedParallelismNumber);
+
+                        int average = listDate.size() / effectThreadsCount;
+                        int slice = listDate.size() % effectThreadsCount == 0 ? average : average + 1;
+
+                        Lists.partition(listDate, slice).stream().forEach(partition -> {
+                            cmdParam.put(CMDPARAM_COMPLEMENT_DATA_START_DATE, DateUtils.dateToString(partition.get(0)));
+                            cmdParam.put(CMDPARAM_COMPLEMENT_DATA_END_DATE, DateUtils.dateToString(partition.get(partition.size() - 1)));

Review comment:
       Thanks @zhuangchong.
   In fact, when startTime is same as endTime, the listDate would be empty, and then the code would run into the  [ExecutorServiceImpl.java#L567](https://github.com/apache/dolphinscheduler/blob/f5675170311ccc3cc8e6f88e74c956220297e8cd/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java#L567) like below:
   ```java
   else {
                           // loop by day
                           int runCunt = 0;
                           while (!start.after(end)) {
                               runCunt += 1;
                               cmdParam.put(CMDPARAM_COMPLEMENT_DATA_START_DATE, DateUtils.dateToString(start));
                               cmdParam.put(CMDPARAM_COMPLEMENT_DATA_END_DATE, DateUtils.dateToString(start));
                               command.setCommandParam(JSONUtils.toJsonString(cmdParam));
                               processService.createCommand(command);
                               start = DateUtils.getSomeDay(start, 1);
                           }
                           return runCunt;
                       }
   ```
   the runCunt would be 1.
   The part I updated will not affect this case.




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