Search in sources :

Example 1 with MarkSegmentsAsUnusedAction

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());
}
Also used : RetrieveUnusedSegmentsAction(org.apache.druid.indexing.common.actions.RetrieveUnusedSegmentsAction) MarkSegmentsAsUnusedAction(org.apache.druid.indexing.common.actions.MarkSegmentsAsUnusedAction) SegmentNukeAction(org.apache.druid.indexing.common.actions.SegmentNukeAction) ArrayList(java.util.ArrayList) List(java.util.List) ISE(org.apache.druid.java.util.common.ISE) DataSegment(org.apache.druid.timeline.DataSegment) DateTime(org.joda.time.DateTime) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 MarkSegmentsAsUnusedAction (org.apache.druid.indexing.common.actions.MarkSegmentsAsUnusedAction)1 RetrieveUnusedSegmentsAction (org.apache.druid.indexing.common.actions.RetrieveUnusedSegmentsAction)1 SegmentNukeAction (org.apache.druid.indexing.common.actions.SegmentNukeAction)1 ISE (org.apache.druid.java.util.common.ISE)1 DataSegment (org.apache.druid.timeline.DataSegment)1 DateTime (org.joda.time.DateTime)1