use of org.apache.druid.indexing.common.actions.MarkSegmentsAsUnusedAction in project druid by druid-io.
the class KillUnusedSegmentsTask method run.
@Override
public TaskStatus run(TaskToolbox toolbox) throws Exception {
final NavigableMap<DateTime, List<TaskLock>> taskLockMap = getTaskLockMap(toolbox.getTaskActionClient());
if (markAsUnused) {
int numMarked = toolbox.getTaskActionClient().submit(new MarkSegmentsAsUnusedAction(getDataSource(), getInterval()));
LOG.info("Marked %d segments as unused.", numMarked);
}
// List unused segments
final List<DataSegment> unusedSegments = toolbox.getTaskActionClient().submit(new RetrieveUnusedSegmentsAction(getDataSource(), getInterval()));
if (!TaskLocks.isLockCoversSegments(taskLockMap, unusedSegments)) {
throw new ISE("Locks[%s] for task[%s] can't cover segments[%s]", taskLockMap.values().stream().flatMap(List::stream).collect(Collectors.toList()), getId(), unusedSegments);
}
// Kill segments
toolbox.getTaskActionClient().submit(new SegmentNukeAction(new HashSet<>(unusedSegments)));
for (DataSegment segment : unusedSegments) {
toolbox.getDataSegmentKiller().kill(segment);
}
return TaskStatus.success(getId());
}
Aggregations