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 2019/12/01 00:42:42 UTC

[GitHub] [incubator-druid] jihoonson commented on a change in pull request #8925: Parallel indexing single dim partitions

jihoonson commented on a change in pull request #8925: Parallel indexing single dim partitions
URL: https://github.com/apache/incubator-druid/pull/8925#discussion_r352312323
 
 

 ##########
 File path: indexing-service/src/main/java/org/apache/druid/indexing/common/task/RangePartitionCachingLocalSegmentAllocator.java
 ##########
 @@ -0,0 +1,195 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.indexing.common.task;
+
+import com.google.common.collect.Maps;
+import org.apache.druid.data.input.InputRow;
+import org.apache.druid.indexing.common.TaskToolbox;
+import org.apache.druid.segment.realtime.appenderator.SegmentIdWithShardSpec;
+import org.apache.druid.timeline.partition.SingleDimensionShardSpec;
+import org.joda.time.Interval;
+
+import javax.annotation.Nullable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+/**
+ * Allocates all necessary range-partitioned segments locally at the beginning and reuses them.
+ *
+ * @see CachingLocalSegmentAllocator
+ */
+public class RangePartitionCachingLocalSegmentAllocator implements IndexTaskSegmentAllocator
+{
+  private final String dataSource;
+  private final String partitionDimension;
+  private final Map<Interval, String[]> intervalsToPartitions;
+  private final IndexTaskSegmentAllocator delegate;
+
+  public RangePartitionCachingLocalSegmentAllocator(
+      TaskToolbox toolbox,
+      String taskId,
+      String supervisorTaskId,
+      String dataSource,
+      String partitionDimension,
+      Map<Interval, String[]> intervalsToPartitions
+  ) throws IOException
+  {
+    this.dataSource = dataSource;
+    this.partitionDimension = partitionDimension;
+    this.intervalsToPartitions = intervalsToPartitions;
+
+    this.delegate = new CachingLocalSegmentAllocator(
+        toolbox,
+        taskId,
+        supervisorTaskId,
+        this::getIntervalToSegmentIds
+    );
+  }
+
+  private Map<Interval, List<SegmentIdWithShardSpec>> getIntervalToSegmentIds(Function<Interval, String> versionFinder)
+  {
+    Map<Interval, List<SegmentIdWithShardSpec>> intervalToSegmentIds =
+        Maps.newHashMapWithExpectedSize(intervalsToPartitions.size());
+
+    intervalsToPartitions.forEach(
+        (interval, partitions) ->
+            intervalToSegmentIds.put(
+                interval,
+                translatePartitions(interval, partitions, versionFinder)
+            )
+    );
+
+    return intervalToSegmentIds;
+  }
+
+  private List<SegmentIdWithShardSpec> translatePartitions(
+      Interval interval,
+      String[] partitions,
+      Function<Interval, String> versionFinder
+  )
+  {
+    if (partitions.length == 0) {
+      return Collections.emptyList();
+    }
+
+    String[] uniquePartitions = Arrays.stream(partitions).distinct().toArray(String[]::new);
+    int numUniquePartition = uniquePartitions.length;
+
+    if (numUniquePartition == 1) {
+      return Collections.singletonList(
+          createLastSegmentIdWithShardSpec(
+              interval,
+              versionFinder.apply(interval),
+              uniquePartitions[0],
+              0
+          )
+      );
+    }
+
+    if (isLastPartitionOnlyMaxValue(partitions)) {
+      // The last partition only contains the max value. A shard that just contains the max value is likely to be
+      // small, so combine it with the second to last one.
 
 Review comment:
   Or probably we should collect the number of elements in each partition together. Does sketch provide such functionality?

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