Search in sources :

Example 1 with SegmentListUnusedAction

use of io.druid.indexing.common.actions.SegmentListUnusedAction 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)

Example 2 with SegmentListUnusedAction

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

the class MoveTask 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 move segment: %s", unusedSegment.getIdentifier());
    }
    // Move segments
    for (DataSegment segment : unusedSegments) {
        final DataSegment movedSegment = toolbox.getDataSegmentMover().move(segment, targetLoadSpec);
        toolbox.getTaskActionClient().submit(new SegmentMetadataUpdateAction(ImmutableSet.of(movedSegment)));
    }
    return TaskStatus.success(getId());
}
Also used : SegmentMetadataUpdateAction(io.druid.indexing.common.actions.SegmentMetadataUpdateAction) TaskLock(io.druid.indexing.common.TaskLock) ISE(io.druid.java.util.common.ISE) SegmentListUnusedAction(io.druid.indexing.common.actions.SegmentListUnusedAction) DataSegment(io.druid.timeline.DataSegment)

Example 3 with SegmentListUnusedAction

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

the class RestoreTask 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 restore segment: %s", unusedSegment.getIdentifier());
    }
    final List<DataSegment> restoredSegments = new ArrayList<>();
    // Move segments
    for (DataSegment segment : unusedSegments) {
        final DataSegment restored = toolbox.getDataSegmentArchiver().restore(segment);
        if (restored != null) {
            restoredSegments.add(restored);
        } else {
            log.info("Segment [%s] did not move, not updating metadata", segment);
        }
    }
    if (restoredSegments.isEmpty()) {
        log.info("No segments restored");
    } else {
        // Update metadata for moved segments
        toolbox.getTaskActionClient().submit(new SegmentMetadataUpdateAction(ImmutableSet.copyOf(restoredSegments)));
    }
    return TaskStatus.success(getId());
}
Also used : SegmentMetadataUpdateAction(io.druid.indexing.common.actions.SegmentMetadataUpdateAction) TaskLock(io.druid.indexing.common.TaskLock) ArrayList(java.util.ArrayList) ISE(io.druid.java.util.common.ISE) SegmentListUnusedAction(io.druid.indexing.common.actions.SegmentListUnusedAction) DataSegment(io.druid.timeline.DataSegment)

Example 4 with SegmentListUnusedAction

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

the class ArchiveTask 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 archive segment: %s", unusedSegment.getIdentifier());
    }
    // Move segments
    for (DataSegment segment : unusedSegments) {
        final DataSegment archivedSegment = toolbox.getDataSegmentArchiver().archive(segment);
        if (archivedSegment != null) {
            toolbox.getTaskActionClient().submit(new SegmentMetadataUpdateAction(ImmutableSet.of(archivedSegment)));
        } else {
            log.info("No action was taken for [%s]", segment);
        }
    }
    return TaskStatus.success(getId());
}
Also used : SegmentMetadataUpdateAction(io.druid.indexing.common.actions.SegmentMetadataUpdateAction) TaskLock(io.druid.indexing.common.TaskLock) 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)4 SegmentListUnusedAction (io.druid.indexing.common.actions.SegmentListUnusedAction)4 ISE (io.druid.java.util.common.ISE)4 DataSegment (io.druid.timeline.DataSegment)4 SegmentMetadataUpdateAction (io.druid.indexing.common.actions.SegmentMetadataUpdateAction)3 SegmentNukeAction (io.druid.indexing.common.actions.SegmentNukeAction)1 ArrayList (java.util.ArrayList)1