Search in sources :

Example 6 with SegmentInsertAction

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

the class ConvertSegmentTask method convertSegment.

private static void convertSegment(TaskToolbox toolbox, final DataSegment segment, IndexSpec indexSpec, boolean force, boolean validate) throws SegmentLoadingException, IOException {
    log.info("Converting segment[%s]", segment);
    final TaskActionClient actionClient = toolbox.getTaskActionClient();
    final List<DataSegment> currentSegments = actionClient.submit(new SegmentListUsedAction(segment.getDataSource(), segment.getInterval(), null));
    for (DataSegment currentSegment : currentSegments) {
        final String version = currentSegment.getVersion();
        final Integer binaryVersion = currentSegment.getBinaryVersion();
        if (!force && (version.startsWith(segment.getVersion()) && CURR_VERSION_INTEGER.equals(binaryVersion))) {
            log.info("Skipping already updated segment[%s].", segment);
            return;
        }
    }
    final Map<DataSegment, File> localSegments = toolbox.fetchSegments(Collections.singletonList(segment));
    final File location = localSegments.get(segment);
    final File outLocation = new File(location, "v9_out");
    if (toolbox.getIndexIO().convertSegment(location, outLocation, indexSpec, force, validate)) {
        final int outVersion = IndexIO.getVersionFromDir(outLocation);
        // Appending to the version makes a new version that inherits most comparability parameters of the original
        // version, but is "newer" than said original version.
        DataSegment updatedSegment = segment.withVersion(String.format("%s_v%s", segment.getVersion(), outVersion));
        updatedSegment = toolbox.getSegmentPusher().push(outLocation, updatedSegment);
        actionClient.submit(new SegmentInsertAction(Sets.newHashSet(updatedSegment)));
    } else {
        log.info("Conversion failed.");
    }
}
Also used : TaskActionClient(io.druid.indexing.common.actions.TaskActionClient) SegmentInsertAction(io.druid.indexing.common.actions.SegmentInsertAction) SegmentListUsedAction(io.druid.indexing.common.actions.SegmentListUsedAction) DataSegment(io.druid.timeline.DataSegment) File(java.io.File)

Aggregations

SegmentInsertAction (io.druid.indexing.common.actions.SegmentInsertAction)6 TaskLock (io.druid.indexing.common.TaskLock)5 LockListAction (io.druid.indexing.common.actions.LockListAction)5 DataSegment (io.druid.timeline.DataSegment)5 Interval (org.joda.time.Interval)5 TaskToolbox (io.druid.indexing.common.TaskToolbox)4 TaskStatus (io.druid.indexing.common.TaskStatus)3 AbstractFixedIntervalTask (io.druid.indexing.common.task.AbstractFixedIntervalTask)3 IndexTask (io.druid.indexing.common.task.IndexTask)3 KillTask (io.druid.indexing.common.task.KillTask)3 RealtimeIndexTask (io.druid.indexing.common.task.RealtimeIndexTask)3 Task (io.druid.indexing.common.task.Task)3 FireDepartmentTest (io.druid.segment.realtime.FireDepartmentTest)3 Test (org.junit.Test)3 SegmentListUsedAction (io.druid.indexing.common.actions.SegmentListUsedAction)2 TaskActionClient (io.druid.indexing.common.actions.TaskActionClient)2 File (java.io.File)2 LockAcquireAction (io.druid.indexing.common.actions.LockAcquireAction)1 LockReleaseAction (io.druid.indexing.common.actions.LockReleaseAction)1 LockTryAcquireAction (io.druid.indexing.common.actions.LockTryAcquireAction)1