Search in sources :

Example 1 with RetrieveUnusedSegmentsAction

use of org.apache.druid.indexing.common.actions.RetrieveUnusedSegmentsAction in project druid by druid-io.

the class ArchiveTask method run.

@Override
public TaskStatus run(TaskToolbox toolbox) throws Exception {
    final TaskLock myLock = getAndCheckLock(toolbox);
    // List unused segments
    final List<DataSegment> unusedSegments = toolbox.getTaskActionClient().submit(new RetrieveUnusedSegmentsAction(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("Unused segment[%s] has version[%s] > task version[%s]", unusedSegment.getId(), unusedSegment.getVersion(), myLock.getVersion());
        }
        log.info("OK to archive segment: %s", unusedSegment.getId());
    }
    // 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.getId());
        }
    }
    return TaskStatus.success(getId());
}
Also used : SegmentMetadataUpdateAction(org.apache.druid.indexing.common.actions.SegmentMetadataUpdateAction) RetrieveUnusedSegmentsAction(org.apache.druid.indexing.common.actions.RetrieveUnusedSegmentsAction) TaskLock(org.apache.druid.indexing.common.TaskLock) ISE(org.apache.druid.java.util.common.ISE) DataSegment(org.apache.druid.timeline.DataSegment)

Example 2 with RetrieveUnusedSegmentsAction

use of org.apache.druid.indexing.common.actions.RetrieveUnusedSegmentsAction in project druid by druid-io.

the class RestoreTask method run.

@Override
public TaskStatus run(TaskToolbox toolbox) throws Exception {
    final TaskLock myLock = getAndCheckLock(toolbox);
    // List unused segments
    final List<DataSegment> unusedSegments = toolbox.getTaskActionClient().submit(new RetrieveUnusedSegmentsAction(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("Unused segment[%s] has version[%s] > task version[%s]", unusedSegment.getId(), unusedSegment.getVersion(), myLock.getVersion());
        }
        log.info("OK to restore segment: %s", unusedSegment.getId());
    }
    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.getId());
        }
    }
    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(org.apache.druid.indexing.common.actions.SegmentMetadataUpdateAction) RetrieveUnusedSegmentsAction(org.apache.druid.indexing.common.actions.RetrieveUnusedSegmentsAction) TaskLock(org.apache.druid.indexing.common.TaskLock) ArrayList(java.util.ArrayList) ISE(org.apache.druid.java.util.common.ISE) DataSegment(org.apache.druid.timeline.DataSegment)

Example 3 with RetrieveUnusedSegmentsAction

use of org.apache.druid.indexing.common.actions.RetrieveUnusedSegmentsAction 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)

Example 4 with RetrieveUnusedSegmentsAction

use of org.apache.druid.indexing.common.actions.RetrieveUnusedSegmentsAction in project druid by druid-io.

the class MoveTask method run.

@Override
public TaskStatus run(TaskToolbox toolbox) throws Exception {
    final TaskLock myLock = getAndCheckLock(toolbox);
    // List unused segments
    final List<DataSegment> unusedSegments = toolbox.getTaskActionClient().submit(new RetrieveUnusedSegmentsAction(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("Unused segment[%s] has version[%s] > task version[%s]", unusedSegment.getId(), unusedSegment.getVersion(), myLock.getVersion());
        }
        log.info("OK to move segment: %s", unusedSegment.getId());
    }
    // 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(org.apache.druid.indexing.common.actions.SegmentMetadataUpdateAction) RetrieveUnusedSegmentsAction(org.apache.druid.indexing.common.actions.RetrieveUnusedSegmentsAction) TaskLock(org.apache.druid.indexing.common.TaskLock) ISE(org.apache.druid.java.util.common.ISE) DataSegment(org.apache.druid.timeline.DataSegment)

Aggregations

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