ccaominh commented on a change in pull request #8925: Parallel indexing single dim partitions URL: https://github.com/apache/incubator-druid/pull/8925#discussion_r352425178
########## 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( Review comment: Added ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org