kfaraz commented on code in PR #14407:
URL: https://github.com/apache/druid/pull/14407#discussion_r1349610732
##########
indexing-service/src/main/java/org/apache/druid/indexing/common/actions/TaskLocks.java:
##########
@@ -110,6 +127,63 @@ public static boolean isLockCoversSegments(
);
}
+ /**
+ * Determines the type of time chunk lock to use for appending segments.
+ * <p>
+ * This method should be de-duplicated with {@link
AbstractBatchIndexTask#determineLockType}
+ * by passing the ParallelIndexSupervisorTask instance into the
+ * SinglePhaseParallelIndexTaskRunner.
+ */
+ public static TaskLockType determineLockTypeForAppend(
+ Map<String, Object> taskContext
+ )
+ {
+ final Object lockType = taskContext.get(Tasks.TASK_LOCK_TYPE);
+ if (lockType == null) {
+ final boolean useSharedLock = (boolean)
taskContext.getOrDefault(Tasks.USE_SHARED_LOCK, false);
+ return useSharedLock ? TaskLockType.SHARED : TaskLockType.EXCLUSIVE;
+ } else {
+ return TaskLockType.valueOf(lockType.toString());
+ }
+ }
+
+ /**
+ * Finds locks of type {@link TaskLockType#REPLACE} for each of the given
segments
+ * that have an interval completely covering the interval of the respective
segments.
+ *
+ * @return Map from segment to REPLACE lock that completely covers it. The
map
+ * does not contain an entry for segments that have no covering REPLACE lock.
+ */
+ public static Map<DataSegment, ReplaceTaskLock>
findReplaceLocksCoveringSegments(
+ final String datasource,
+ final TaskLockbox taskLockbox,
+ final Set<DataSegment> segments
+ )
+ {
+ // Identify unique segment intervals
+ final Map<Interval, List<DataSegment>> intervalToSegments = new
HashMap<>();
+ segments.forEach(
+ segment -> intervalToSegments.computeIfAbsent(
+ segment.getInterval(), interval -> new ArrayList<>()
+ ).add(segment)
+ );
+
+ final Set<ReplaceTaskLock> replaceLocks =
taskLockbox.getAllReplaceLocksForDatasource(datasource);
Review Comment:
No, the locks are cached inside the `TaskLockbox`, field `running`.
--
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]