jihoonson commented on a change in pull request #9448: Fix superbatch merge
last partition boundaries
URL: https://github.com/apache/druid/pull/9448#discussion_r387318051
##########
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:
I think the comment would be nice.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]