Search in sources :

Example 1 with SegmentNukeAction

use of io.druid.indexing.common.actions.SegmentNukeAction in project druid by druid-io.

the class KillTask method run.

@Override
public TaskStatus run(TaskToolbox toolbox) throws Exception {
    // Confirm we have a lock (will throw if there isn't exactly one element)
    final TaskLock myLock = Iterables.getOnlyElement(getTaskLocks(toolbox));
    if (!myLock.getDataSource().equals(getDataSource())) {
        throw new ISE("WTF?! Lock dataSource[%s] != task dataSource[%s]", myLock.getDataSource(), getDataSource());
    }
    if (!myLock.getInterval().equals(getInterval())) {
        throw new ISE("WTF?! Lock interval[%s] != task interval[%s]", myLock.getInterval(), getInterval());
    }
    // List unused segments
    final List<DataSegment> unusedSegments = toolbox.getTaskActionClient().submit(new SegmentListUnusedAction(myLock.getDataSource(), myLock.getInterval()));
    // Verify none of these segments have versions > lock version
    for (final DataSegment unusedSegment : unusedSegments) {
        if (unusedSegment.getVersion().compareTo(myLock.getVersion()) > 0) {
            throw new ISE("WTF?! Unused segment[%s] has version[%s] > task version[%s]", unusedSegment.getIdentifier(), unusedSegment.getVersion(), myLock.getVersion());
        }
        log.info("OK to kill segment: %s", unusedSegment.getIdentifier());
    }
    // Kill segments
    for (DataSegment segment : unusedSegments) {
        toolbox.getDataSegmentKiller().kill(segment);
        toolbox.getTaskActionClient().submit(new SegmentNukeAction(ImmutableSet.of(segment)));
    }
    return TaskStatus.success(getId());
}
Also used : TaskLock(io.druid.indexing.common.TaskLock) SegmentNukeAction(io.druid.indexing.common.actions.SegmentNukeAction) ISE(io.druid.java.util.common.ISE) SegmentListUnusedAction(io.druid.indexing.common.actions.SegmentListUnusedAction) DataSegment(io.druid.timeline.DataSegment)

Aggregations

TaskLock (io.druid.indexing.common.TaskLock)1 SegmentListUnusedAction (io.druid.indexing.common.actions.SegmentListUnusedAction)1 SegmentNukeAction (io.druid.indexing.common.actions.SegmentNukeAction)1 ISE (io.druid.java.util.common.ISE)1 DataSegment (io.druid.timeline.DataSegment)1