kfaraz commented on code in PR #19772:
URL: https://github.com/apache/druid/pull/19772#discussion_r3727138094


##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/SegmentStatusManager.java:
##########
@@ -0,0 +1,254 @@
+/*
+ * 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.overlord;
+
+import com.google.inject.Inject;
+import org.apache.druid.common.utils.IdUtils;
+import org.apache.druid.error.DruidException;
+import org.apache.druid.error.InternalServerError;
+import org.apache.druid.indexer.TaskStatus;
+import org.apache.druid.indexing.common.TaskLock;
+import org.apache.druid.indexing.common.TaskLockType;
+import org.apache.druid.indexing.common.TaskToolbox;
+import org.apache.druid.indexing.common.actions.TaskActionClient;
+import org.apache.druid.indexing.common.actions.TaskActionClientFactory;
+import org.apache.druid.indexing.common.actions.TimeChunkLockTryAcquireAction;
+import org.apache.druid.indexing.common.task.AbstractFixedIntervalTask;
+import org.apache.druid.indexing.common.task.Task;
+import org.apache.druid.indexing.common.task.TaskMetrics;
+import org.apache.druid.java.util.common.Intervals;
+import org.apache.druid.java.util.common.JodaUtils;
+import org.apache.druid.java.util.common.Stopwatch;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.java.util.emitter.service.ServiceEmitter;
+import org.apache.druid.java.util.emitter.service.ServiceMetricEvent;
+import org.apache.druid.query.DruidMetrics;
+import org.apache.druid.timeline.SegmentId;
+import org.joda.time.Interval;
+
+import javax.annotation.Nullable;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Performs updates on segments to change their "used" status in the metadata 
store.
+ * <p>
+ * Currently, this class exposes methods that are used to acquire an EXCLUSIVE
+ * lock while marking segments in an interval as "used". A similar restriction
+ * may be imposed on marking (non-overshadowed) segments as unused in the 
future.
+ *
+ * @see #markAsUsedWithExclusiveLock(String, Interval, UpdateOperation)
+ * Reasons for using EXCLUSIVE locks
+ */
+public class SegmentStatusManager
+{
+  private static final Logger log = new Logger(SegmentStatusManager.class);
+  private static final String TASK_TYPE_MARK_USED = "markSegmentAsUsed";
+
+  private final ServiceEmitter emitter;
+  private final GlobalTaskLockbox taskLockbox;
+  private final TaskActionClientFactory taskActionClientFactory;
+  private final IndexerMetadataStorageCoordinator storageCoordinator;
+
+  @Inject
+  public SegmentStatusManager(
+      GlobalTaskLockbox taskLockbox,
+      IndexerMetadataStorageCoordinator storageCoordinator,
+      TaskActionClientFactory taskActionClientFactory,
+      ServiceEmitter emitter
+  )
+  {
+    this.emitter = emitter;
+    this.taskLockbox = taskLockbox;
+    this.storageCoordinator = storageCoordinator;
+    this.taskActionClientFactory = taskActionClientFactory;
+  }
+
+  /**
+   * Same as {@link 
IndexerMetadataStorageCoordinator#markAllNonOvershadowedSegmentsAsUsed(String)}
+   * but with an EXCLUSIVE lock.
+   */
+  public int markAllNonOvershadowedSegmentsAsUsed(String dataSource)
+  {
+    return markAsUsedWithExclusiveLock(

Review Comment:
   Yes, that's true.
   
   I suppose we could first identify the intervals that have eligible 
non-overshadowed segments that may be marked as used, and only try to lock 
those intervals.



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

Reply via email to