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


##########
indexing-service/src/main/java/org/apache/druid/indexing/common/task/KillUnusedSegmentsTask.java:
##########
@@ -218,7 +221,22 @@ public TaskStatus runTask(TaskToolbox toolbox) throws 
Exception
       // abandoned.
 
       toolbox.getTaskActionClient().submit(new SegmentNukeAction(new 
HashSet<>(unusedSegments)));
-      toolbox.getDataSegmentKiller().kill(unusedSegments);
+
+      // Fetch the load specs of all segments overlapping with the given 
interval
+      final Set<Map<String, Object>> usedSegmentLoadSpecs = toolbox
+          .getTaskActionClient()
+          .submit(new RetrieveUsedSegmentsAction(getDataSource(), 
getInterval(), null, Segments.INCLUDING_OVERSHADOWED))
+          .stream()
+          .map(DataSegment::getLoadSpec)
+          .collect(Collectors.toSet());
+
+      // Kill segments from the deep storage only if their load specs are not 
being used by any used segments
+      final List<DataSegment> segmentsToBeKilled = unusedSegments
+          .stream()
+          .filter(unusedSegment -> 
!usedSegmentLoadSpecs.contains(unusedSegment.getLoadSpec()))
+          .collect(Collectors.toList());
+
+      toolbox.getDataSegmentKiller().kill(segmentsToBeKilled);

Review Comment:
   This was already happening, this PR has just reduced the number of segments 
that are being killed by the `DataSegmentKiller`.



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