clintropolis commented on a change in pull request #7547: Add support minor compaction with segment locking URL: https://github.com/apache/incubator-druid/pull/7547#discussion_r298815031
########## File path: indexing-service/src/main/java/org/apache/druid/indexing/common/task/AbstractBatchIndexTask.java ########## @@ -0,0 +1,377 @@ +/* + * 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.base.Preconditions; +import com.google.common.collect.Iterables; +import org.apache.druid.indexing.common.SegmentLock; +import org.apache.druid.indexing.common.TaskLock; +import org.apache.druid.indexing.common.TaskLockType; +import org.apache.druid.indexing.common.actions.SegmentLockReleaseAction; +import org.apache.druid.indexing.common.actions.SegmentLockTryAcquireAction; +import org.apache.druid.indexing.common.actions.TaskActionClient; +import org.apache.druid.indexing.common.actions.TimeChunkLockTryAcquireAction; +import org.apache.druid.indexing.overlord.LockResult; +import org.apache.druid.java.util.common.ISE; +import org.apache.druid.java.util.common.JodaUtils; +import org.apache.druid.java.util.common.granularity.Granularity; +import org.apache.druid.java.util.common.io.Closer; +import org.apache.druid.timeline.DataSegment; +import org.apache.druid.timeline.TimelineObjectHolder; +import org.apache.druid.timeline.VersionedIntervalTimeline; +import org.apache.druid.timeline.partition.PartitionChunk; +import org.joda.time.Interval; + +import javax.annotation.Nullable; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + +/** + * Abstract class for batch tasks like {@link IndexTask}. + * Provides some methods ({@link #tryLockWithIntervals} and {@link #tryLockWithSegments}) for easily acquiring task + * locks. + */ +public abstract class AbstractBatchIndexTask extends AbstractTask +{ + @Nullable + private Map<Interval, OverwritingRootGenerationPartitions> overwritingRootGenPartitions; + @Nullable + private Set<DataSegment> allInputSegments; + + @Nullable + private Boolean changeSegmentGranularity; + + public static class OverwritingRootGenerationPartitions + { + private final int startRootPartitionId; + private final int endRootPartitionId; + private final short maxMinorVersion; + + private OverwritingRootGenerationPartitions(int startRootPartitionId, int endRootPartitionId, short maxMinorVersion) + { + this.startRootPartitionId = startRootPartitionId; + this.endRootPartitionId = endRootPartitionId; + this.maxMinorVersion = maxMinorVersion; + } + + public int getStartRootPartitionId() + { + return startRootPartitionId; + } + + public int getEndRootPartitionId() + { + return endRootPartitionId; + } + + public short getMinorVersionForNewSegments() + { + return (short) (maxMinorVersion + 1); + } + } + + protected AbstractBatchIndexTask(String id, String dataSource, Map<String, Object> context) + { + super(id, dataSource, context); + } + + protected AbstractBatchIndexTask( + String id, + @Nullable String groupId, + @Nullable TaskResource taskResource, + String dataSource, + @Nullable Map<String, Object> context + ) + { + super(id, groupId, taskResource, dataSource, context); + } + + public abstract boolean requireLockInputSegments(); + + public abstract List<DataSegment> findInputSegments(TaskActionClient taskActionClient, List<Interval> intervals) + throws IOException; + + public abstract boolean checkIfChangeSegmentGranularity(List<Interval> intervalOfExistingSegments); + + public abstract boolean isPerfectRollup(); + + /** + * Returns the segmentGranularity for the given interval. Usually tasks are supposed to return its segmentGranularity + * if exists. The compactionTask can return different segmentGranularity depending on its configuration and the input + * interval. + * + * @return segmentGranularity or null if it doesn't support it. + */ + @Nullable + public abstract Granularity getSegmentGranularity(Interval interval); + + protected boolean tryLockWithIntervals(TaskActionClient client, List<Interval> intervals, boolean isInitialRequest) Review comment: I'm not sure if this is the most appropriate place for this comment, but should there be some additional configuration that allows/forces continuing to use time chunk locks, so as to be able to roll-back to previous versions? In other words, I think that this segment locking behavior should probably be opt-in; it's a rather strong position to take that by default upgrading will mean that you are unable to roll-back. I think it's probably much safer to retain the existing behavior by default, and then change that default in a future version where rollback will not be problematic. ---------------------------------------------------------------- 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]
