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_r298815113
 
 

 ##########
 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:
   Also agree with @jon-wei and would like to request for more javadocs on the 
methods in this class

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

Reply via email to