mirror of https://github.com/apache/druid.git
Optimize used segment fetching in Kill tasks (#15107)
* Optimize used segment fetching in Kill tasks
This commit is contained in:
parent
7a35ce886d
commit
40a6dc4631
|
@ -222,18 +222,30 @@ public class KillUnusedSegmentsTask extends AbstractFixedIntervalTask
|
||||||
|
|
||||||
toolbox.getTaskActionClient().submit(new SegmentNukeAction(new HashSet<>(unusedSegments)));
|
toolbox.getTaskActionClient().submit(new SegmentNukeAction(new HashSet<>(unusedSegments)));
|
||||||
|
|
||||||
// Fetch the load specs of all segments overlapping with the given interval
|
final Set<Interval> unusedSegmentIntervals = unusedSegments.stream()
|
||||||
final Set<Map<String, Object>> usedSegmentLoadSpecs = toolbox
|
.map(DataSegment::getInterval)
|
||||||
.getTaskActionClient()
|
.collect(Collectors.toSet());
|
||||||
.submit(new RetrieveUsedSegmentsAction(getDataSource(), getInterval(), null, Segments.INCLUDING_OVERSHADOWED))
|
final Set<Map<String, Object>> usedSegmentLoadSpecs = new HashSet<>();
|
||||||
|
if (!unusedSegmentIntervals.isEmpty()) {
|
||||||
|
RetrieveUsedSegmentsAction retrieveUsedSegmentsAction = new RetrieveUsedSegmentsAction(
|
||||||
|
getDataSource(),
|
||||||
|
null,
|
||||||
|
unusedSegmentIntervals,
|
||||||
|
Segments.INCLUDING_OVERSHADOWED
|
||||||
|
);
|
||||||
|
// Fetch the load specs of all segments overlapping with the unused segment intervals
|
||||||
|
usedSegmentLoadSpecs.addAll(toolbox.getTaskActionClient().submit(retrieveUsedSegmentsAction)
|
||||||
.stream()
|
.stream()
|
||||||
.map(DataSegment::getLoadSpec)
|
.map(DataSegment::getLoadSpec)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Kill segments from the deep storage only if their load specs are not being used by any used segments
|
// Kill segments from the deep storage only if their load specs are not being used by any used segments
|
||||||
final List<DataSegment> segmentsToBeKilled = unusedSegments
|
final List<DataSegment> segmentsToBeKilled = unusedSegments
|
||||||
.stream()
|
.stream()
|
||||||
.filter(unusedSegment -> !usedSegmentLoadSpecs.contains(unusedSegment.getLoadSpec()))
|
.filter(unusedSegment -> unusedSegment.getLoadSpec() == null
|
||||||
|
|| !usedSegmentLoadSpecs.contains(unusedSegment.getLoadSpec()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
toolbox.getDataSegmentKiller().kill(segmentsToBeKilled);
|
toolbox.getDataSegmentKiller().kill(segmentsToBeKilled);
|
||||||
|
|
Loading…
Reference in New Issue