AmatyaAvadhanula commented on code in PR #15085:
URL: https://github.com/apache/druid/pull/15085#discussion_r1361479638
##########
indexing-service/src/main/java/org/apache/druid/indexing/common/task/batch/parallel/AbstractBatchSubtask.java:
##########
@@ -29,21 +30,34 @@
public abstract class AbstractBatchSubtask extends AbstractBatchIndexTask
{
+ private final String supervisorTaskId;
+
protected AbstractBatchSubtask(
String id,
@Nullable String groupId,
@Nullable TaskResource taskResource,
String dataSource,
@Nullable Map<String, Object> context,
- @Nonnull IngestionMode ingestionMode
+ @Nonnull IngestionMode ingestionMode,
+ @Nonnull String supervisorTaskId
)
{
super(id, groupId, taskResource, dataSource, context, -1, ingestionMode);
+ this.supervisorTaskId = supervisorTaskId;
}
/**
* Returns the ID of {@link SubTaskSpec} that is assigned to this subtask.
* This ID is used to identify duplicate work of retry tasks for the same
spec.
*/
public abstract String getSubtaskSpecId();
+
+ /**
+ * @return the id of the subtask's supervisor
Review Comment:
Done
##########
indexing-service/src/main/java/org/apache/druid/indexing/common/actions/RetrieveSegmentsToReplaceAction.java:
##########
@@ -0,0 +1,171 @@
+/*
+ * 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.actions;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.core.type.TypeReference;
+import org.apache.druid.indexing.common.task.Task;
+import
org.apache.druid.indexing.common.task.batch.parallel.AbstractBatchSubtask;
+import org.apache.druid.indexing.overlord.Segments;
+import org.apache.druid.java.util.common.Intervals;
+import org.apache.druid.java.util.common.Pair;
+import org.apache.druid.metadata.ReplaceTaskLock;
+import org.apache.druid.timeline.DataSegment;
+import org.apache.druid.timeline.Partitions;
+import org.apache.druid.timeline.SegmentTimeline;
+import org.joda.time.Interval;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * This TaskAction returns a collection of segments which have data within the
specified interval and are marked as
+ * used, and have been created before a REPLACE lock, if any, was acquired.
+ *
+ * The order of segments within the returned collection is unspecified, but
each segment is guaranteed to appear in
+ * the collection only once.
+ *
+ * @implNote This action doesn't produce a {@link Set} because it's
implemented via {@link
+ *
org.apache.druid.indexing.overlord.IndexerMetadataStorageCoordinator#retrieveUsedSegmentsForIntervals}
which returns
+ * a collection. Producing a {@link Set} would require an unnecessary copy of
segments collection.
+ */
+public class RetrieveSegmentsToReplaceAction implements
TaskAction<Collection<DataSegment>>
+{
+ @JsonIgnore
+ private final String dataSource;
+
+ @JsonIgnore
+ private final Interval interval;
+
+ @JsonCreator
+ public RetrieveSegmentsToReplaceAction(
+ @JsonProperty("dataSource") String dataSource,
+ @JsonProperty("interval") Interval interval
+ )
+ {
+ this.dataSource = dataSource;
+ this.interval = interval;
+ }
+
+ @JsonProperty
+ public String getDataSource()
+ {
+ return dataSource;
+ }
+
+ @JsonProperty
+ public Interval getInterval()
+ {
+ return interval;
+ }
+
+ @Override
+ public TypeReference<Collection<DataSegment>> getReturnTypeReference()
+ {
+ return new TypeReference<Collection<DataSegment>>() {};
+ }
+
+ @Override
+ public Collection<DataSegment> perform(Task task, TaskActionToolbox toolbox)
+ {
+ if (!task.getDataSource().equals(dataSource)) {
+ return toolbox.getIndexerMetadataStorageCoordinator()
+ .retrieveUsedSegmentsForInterval(dataSource, interval,
Segments.ONLY_VISIBLE);
+ }
+
+ final String supervisorId;
+ if (task instanceof AbstractBatchSubtask) {
+ supervisorId = ((AbstractBatchSubtask) task).getSupervisorTaskId();
+ } else {
+ supervisorId = task.getId();
+ }
+
+ final Set<ReplaceTaskLock> replaceLocksForTask = toolbox
+ .getTaskLockbox()
+ .getAllReplaceLocksForDatasource(task.getDataSource())
+ .stream()
+ .filter(lock -> supervisorId.equals(lock.getSupervisorTaskId()))
+ .collect(Collectors.toSet());
+
+ Collection<Pair<DataSegment, String>> segmentsAndCreatedDates =
Review Comment:
Done
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]