Search in sources :

Example 6 with SegmentListUsedAction

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

the class ActionBasedUsedSegmentChecker method findUsedSegments.

@Override
public Set<DataSegment> findUsedSegments(Set<SegmentIdentifier> identifiers) throws IOException {
    // Group by dataSource
    final Map<String, Set<SegmentIdentifier>> identifiersByDataSource = Maps.newTreeMap();
    for (SegmentIdentifier identifier : identifiers) {
        if (!identifiersByDataSource.containsKey(identifier.getDataSource())) {
            identifiersByDataSource.put(identifier.getDataSource(), Sets.<SegmentIdentifier>newHashSet());
        }
        identifiersByDataSource.get(identifier.getDataSource()).add(identifier);
    }
    final Set<DataSegment> retVal = Sets.newHashSet();
    for (Map.Entry<String, Set<SegmentIdentifier>> entry : identifiersByDataSource.entrySet()) {
        final List<Interval> intervals = JodaUtils.condenseIntervals(Iterables.transform(entry.getValue(), new Function<SegmentIdentifier, Interval>() {

            @Override
            public Interval apply(SegmentIdentifier input) {
                return input.getInterval();
            }
        }));
        final List<DataSegment> usedSegmentsForIntervals = taskActionClient.submit(new SegmentListUsedAction(entry.getKey(), null, intervals));
        for (DataSegment segment : usedSegmentsForIntervals) {
            if (identifiers.contains(SegmentIdentifier.fromDataSegment(segment))) {
                retVal.add(segment);
            }
        }
    }
    return retVal;
}
Also used : Set(java.util.Set) SegmentIdentifier(io.druid.segment.realtime.appenderator.SegmentIdentifier) DataSegment(io.druid.timeline.DataSegment) Function(com.google.common.base.Function) SegmentListUsedAction(io.druid.indexing.common.actions.SegmentListUsedAction) Map(java.util.Map) Interval(org.joda.time.Interval)

Example 7 with SegmentListUsedAction

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

the class ActionBasedUsedSegmentCheckerTest method testBasic.

@Test
public void testBasic() throws IOException {
    final TaskActionClient taskActionClient = EasyMock.createMock(TaskActionClient.class);
    EasyMock.expect(taskActionClient.submit(new SegmentListUsedAction("bar", null, ImmutableList.of(new Interval("2002/P1D"))))).andReturn(ImmutableList.of(DataSegment.builder().dataSource("bar").interval(new Interval("2002/P1D")).shardSpec(new LinearShardSpec(0)).version("b").build(), DataSegment.builder().dataSource("bar").interval(new Interval("2002/P1D")).shardSpec(new LinearShardSpec(1)).version("b").build()));
    EasyMock.expect(taskActionClient.submit(new SegmentListUsedAction("foo", null, ImmutableList.of(new Interval("2000/P1D"), new Interval("2001/P1D"))))).andReturn(ImmutableList.of(DataSegment.builder().dataSource("foo").interval(new Interval("2000/P1D")).shardSpec(new LinearShardSpec(0)).version("a").build(), DataSegment.builder().dataSource("foo").interval(new Interval("2000/P1D")).shardSpec(new LinearShardSpec(1)).version("a").build(), DataSegment.builder().dataSource("foo").interval(new Interval("2001/P1D")).shardSpec(new LinearShardSpec(1)).version("b").build(), DataSegment.builder().dataSource("foo").interval(new Interval("2002/P1D")).shardSpec(new LinearShardSpec(1)).version("b").build()));
    EasyMock.replay(taskActionClient);
    final UsedSegmentChecker checker = new ActionBasedUsedSegmentChecker(taskActionClient);
    final Set<DataSegment> segments = checker.findUsedSegments(ImmutableSet.of(new SegmentIdentifier("foo", new Interval("2000/P1D"), "a", new LinearShardSpec(1)), new SegmentIdentifier("foo", new Interval("2001/P1D"), "b", new LinearShardSpec(0)), new SegmentIdentifier("bar", new Interval("2002/P1D"), "b", new LinearShardSpec(0))));
    Assert.assertEquals(ImmutableSet.of(DataSegment.builder().dataSource("foo").interval(new Interval("2000/P1D")).shardSpec(new LinearShardSpec(1)).version("a").build(), DataSegment.builder().dataSource("bar").interval(new Interval("2002/P1D")).shardSpec(new LinearShardSpec(0)).version("b").build()), segments);
    EasyMock.verify(taskActionClient);
}
Also used : TaskActionClient(io.druid.indexing.common.actions.TaskActionClient) SegmentIdentifier(io.druid.segment.realtime.appenderator.SegmentIdentifier) LinearShardSpec(io.druid.timeline.partition.LinearShardSpec) UsedSegmentChecker(io.druid.segment.realtime.appenderator.UsedSegmentChecker) SegmentListUsedAction(io.druid.indexing.common.actions.SegmentListUsedAction) DataSegment(io.druid.timeline.DataSegment) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 8 with SegmentListUsedAction

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

the class SameIntervalMergeTask method run.

@Override
public TaskStatus run(TaskToolbox toolbox) throws Exception {
    final List<DataSegment> segments = toolbox.getTaskActionClient().submit(new SegmentListUsedAction(getDataSource(), getInterval(), null));
    SubTask mergeTask = new SubTask(getId(), getDataSource(), segments, aggregators, rollup, indexSpec, buildV9Directly, getContext());
    final TaskStatus status = mergeTask.run(toolbox);
    if (!status.isSuccess()) {
        return TaskStatus.fromCode(getId(), status.getStatusCode());
    }
    return success();
}
Also used : SegmentListUsedAction(io.druid.indexing.common.actions.SegmentListUsedAction) TaskStatus(io.druid.indexing.common.TaskStatus) DataSegment(io.druid.timeline.DataSegment)

Example 9 with SegmentListUsedAction

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

SegmentListUsedAction (io.druid.indexing.common.actions.SegmentListUsedAction)9 DataSegment (io.druid.timeline.DataSegment)8 TaskActionClient (io.druid.indexing.common.actions.TaskActionClient)4 Function (com.google.common.base.Function)3 File (java.io.File)3 Interval (org.joda.time.Interval)3 TaskStatus (io.druid.indexing.common.TaskStatus)2 SegmentInsertAction (io.druid.indexing.common.actions.SegmentInsertAction)2 TaskAction (io.druid.indexing.common.actions.TaskAction)2 SegmentIdentifier (io.druid.segment.realtime.appenderator.SegmentIdentifier)2 NoopServiceEmitter (io.druid.server.metrics.NoopServiceEmitter)2 IOException (java.io.IOException)2 Set (java.util.Set)2 Predicate (com.google.common.base.Predicate)1 ImmutableList (com.google.common.collect.ImmutableList)1 Binder (com.google.inject.Binder)1 Injector (com.google.inject.Injector)1 Module (com.google.inject.Module)1 SegmentLoaderFactory (io.druid.indexing.common.SegmentLoaderFactory)1 TaskLock (io.druid.indexing.common.TaskLock)1