You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2020/03/02 20:18:09 UTC

[GitHub] [druid] maytasm3 commented on a change in pull request #9448: Fix superbatch merge last partition boundaries

maytasm3 commented on a change in pull request #9448: Fix superbatch merge last partition boundaries
URL: https://github.com/apache/druid/pull/9448#discussion_r386626730
 
 

 ##########
 File path: indexing-service/src/main/java/org/apache/druid/indexing/common/task/batch/parallel/ParallelIndexSupervisorTask.java
 ##########
 @@ -760,29 +761,39 @@ private PartitionBoundaries determineRangePartition(Collection<StringDistributio
     // See PartitionStat in GeneratedPartitionsReport.
     final List<Pair<Interval, Integer>> partitions = new ArrayList<>(partitionToLocations.keySet());
     Collections.shuffle(partitions, ThreadLocalRandom.current());
-    final int numPartitionsPerTask = (int) Math.round(partitions.size() / (double) numMergeTasks);
 
     final List<M> assignedPartitionLocations = new ArrayList<>(numMergeTasks);
-    for (int i = 0; i < numMergeTasks - 1; i++) {
+    for (int i = 0; i < numMergeTasks; i++) {
+      Pair<Integer, Integer> partitionBoundaries = getPartitionBoundaries(i, partitions.size(), numMergeTasks);
       final List<L> assignedToSameTask = partitions
-          .subList(i * numPartitionsPerTask, (i + 1) * numPartitionsPerTask)
+          .subList(partitionBoundaries.lhs, partitionBoundaries.rhs)
           .stream()
           .flatMap(intervalAndPartitionId -> partitionToLocations.get(intervalAndPartitionId).stream())
           .collect(Collectors.toList());
       assignedPartitionLocations.add(createPartialSegmentMergeIOConfig.apply(assignedToSameTask));
     }
 
-    // The last task is assigned all remaining partitions.
-    final List<L> assignedToSameTask = partitions
-        .subList((numMergeTasks - 1) * numPartitionsPerTask, partitions.size())
-        .stream()
-        .flatMap(intervalAndPartitionId -> partitionToLocations.get(intervalAndPartitionId).stream())
-        .collect(Collectors.toList());
-    assignedPartitionLocations.add(createPartialSegmentMergeIOConfig.apply(assignedToSameTask));
-
     return assignedPartitionLocations;
   }
 
+  /**
+   * Partition items into as evenly-sized splits as possible.
+   *
+   * @param index  index of partition
+   * @param total  number of items to partitions
+   * @param splits number of desired partitions
+   *
+   * @return partition range: [lhs, rhs)
+   */
+  private static Pair<Integer, Integer> getPartitionBoundaries(int index, int total, int splits)
+  {
+    int chunk = total / splits;
+    int remainder = total % splits;
+    int start = index * chunk + (index < remainder ? index : remainder);
 
 Review comment:
   Can you add comment on  purpose of `(index < remainder ? index : remainder)` ?
   i.e. splitting the `remainder` across the first `remainder` tasks etc.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org