Search in sources :

Example 1 with ReportTimelineMissingSegmentQueryRunner

use of io.druid.query.ReportTimelineMissingSegmentQueryRunner in project druid by druid-io.

the class ServerManager method getQueryRunnerForSegments.

@Override
public <T> QueryRunner<T> getQueryRunnerForSegments(Query<T> query, Iterable<SegmentDescriptor> specs) {
    final QueryRunnerFactory<T, Query<T>> factory = conglomerate.findFactory(query);
    if (factory == null) {
        log.makeAlert("Unknown query type, [%s]", query.getClass()).addData("dataSource", query.getDataSource()).emit();
        return new NoopQueryRunner<T>();
    }
    final QueryToolChest<T, Query<T>> toolChest = factory.getToolchest();
    String dataSourceName = getDataSourceName(query.getDataSource());
    final VersionedIntervalTimeline<String, ReferenceCountingSegment> timeline = dataSources.get(dataSourceName);
    if (timeline == null) {
        return new NoopQueryRunner<T>();
    }
    final Function<Query<T>, ServiceMetricEvent.Builder> builderFn = getBuilderFn(toolChest);
    final AtomicLong cpuTimeAccumulator = new AtomicLong(0L);
    FunctionalIterable<QueryRunner<T>> queryRunners = FunctionalIterable.create(specs).transformCat(new Function<SegmentDescriptor, Iterable<QueryRunner<T>>>() {

        @Override
        @SuppressWarnings("unchecked")
        public Iterable<QueryRunner<T>> apply(SegmentDescriptor input) {
            final PartitionHolder<ReferenceCountingSegment> entry = timeline.findEntry(input.getInterval(), input.getVersion());
            if (entry == null) {
                return Arrays.<QueryRunner<T>>asList(new ReportTimelineMissingSegmentQueryRunner<T>(input));
            }
            final PartitionChunk<ReferenceCountingSegment> chunk = entry.getChunk(input.getPartitionNumber());
            if (chunk == null) {
                return Arrays.<QueryRunner<T>>asList(new ReportTimelineMissingSegmentQueryRunner<T>(input));
            }
            final ReferenceCountingSegment adapter = chunk.getObject();
            return Arrays.asList(buildAndDecorateQueryRunner(factory, toolChest, adapter, input, builderFn, cpuTimeAccumulator));
        }
    });
    return CPUTimeMetricQueryRunner.safeBuild(new FinalizeResultsQueryRunner<>(toolChest.mergeResults(factory.mergeRunners(exec, queryRunners)), toolChest), builderFn, emitter, cpuTimeAccumulator, true);
}
Also used : ReferenceCountingSegment(io.druid.segment.ReferenceCountingSegment) PartitionHolder(io.druid.timeline.partition.PartitionHolder) Query(io.druid.query.Query) FunctionalIterable(io.druid.java.util.common.guava.FunctionalIterable) MetricsEmittingQueryRunner(io.druid.query.MetricsEmittingQueryRunner) ReportTimelineMissingSegmentQueryRunner(io.druid.query.ReportTimelineMissingSegmentQueryRunner) BySegmentQueryRunner(io.druid.query.BySegmentQueryRunner) SpecificSegmentQueryRunner(io.druid.query.spec.SpecificSegmentQueryRunner) ReferenceCountingSegmentQueryRunner(io.druid.query.ReferenceCountingSegmentQueryRunner) FinalizeResultsQueryRunner(io.druid.query.FinalizeResultsQueryRunner) CPUTimeMetricQueryRunner(io.druid.query.CPUTimeMetricQueryRunner) NoopQueryRunner(io.druid.query.NoopQueryRunner) CachingQueryRunner(io.druid.client.CachingQueryRunner) QueryRunner(io.druid.query.QueryRunner) AtomicLong(java.util.concurrent.atomic.AtomicLong) ReportTimelineMissingSegmentQueryRunner(io.druid.query.ReportTimelineMissingSegmentQueryRunner) NoopQueryRunner(io.druid.query.NoopQueryRunner) SegmentDescriptor(io.druid.query.SegmentDescriptor) PartitionChunk(io.druid.timeline.partition.PartitionChunk)

Example 2 with ReportTimelineMissingSegmentQueryRunner

use of io.druid.query.ReportTimelineMissingSegmentQueryRunner in project druid by druid-io.

the class SinkQuerySegmentWalker method getQueryRunnerForSegments.

@Override
public <T> QueryRunner<T> getQueryRunnerForSegments(final Query<T> query, final Iterable<SegmentDescriptor> specs) {
    // We only handle one particular dataSource. Make sure that's what we have, then ignore from here on out.
    if (!(query.getDataSource() instanceof TableDataSource) || !dataSource.equals(((TableDataSource) query.getDataSource()).getName())) {
        log.makeAlert("Received query for unknown dataSource").addData("dataSource", query.getDataSource()).emit();
        return new NoopQueryRunner<>();
    }
    final QueryRunnerFactory<T, Query<T>> factory = conglomerate.findFactory(query);
    if (factory == null) {
        throw new ISE("Unknown query type[%s].", query.getClass());
    }
    final QueryToolChest<T, Query<T>> toolChest = factory.getToolchest();
    final Function<Query<T>, ServiceMetricEvent.Builder> builderFn = new Function<Query<T>, ServiceMetricEvent.Builder>() {

        @Override
        public ServiceMetricEvent.Builder apply(@Nullable Query<T> input) {
            return toolChest.makeMetricBuilder(query);
        }
    };
    final boolean skipIncrementalSegment = query.getContextValue(CONTEXT_SKIP_INCREMENTAL_SEGMENT, false);
    final AtomicLong cpuTimeAccumulator = new AtomicLong(0L);
    return CPUTimeMetricQueryRunner.safeBuild(toolChest.mergeResults(factory.mergeRunners(queryExecutorService, FunctionalIterable.create(specs).transform(new Function<SegmentDescriptor, QueryRunner<T>>() {

        @Override
        public QueryRunner<T> apply(final SegmentDescriptor descriptor) {
            final PartitionHolder<Sink> holder = sinkTimeline.findEntry(descriptor.getInterval(), descriptor.getVersion());
            if (holder == null) {
                return new ReportTimelineMissingSegmentQueryRunner<>(descriptor);
            }
            final PartitionChunk<Sink> chunk = holder.getChunk(descriptor.getPartitionNumber());
            if (chunk == null) {
                return new ReportTimelineMissingSegmentQueryRunner<>(descriptor);
            }
            final Sink theSink = chunk.getObject();
            final String sinkSegmentIdentifier = theSink.getSegment().getIdentifier();
            return new SpecificSegmentQueryRunner<>(withPerSinkMetrics(new BySegmentQueryRunner<>(sinkSegmentIdentifier, descriptor.getInterval().getStart(), factory.mergeRunners(MoreExecutors.sameThreadExecutor(), Iterables.transform(theSink, new Function<FireHydrant, QueryRunner<T>>() {

                @Override
                public QueryRunner<T> apply(final FireHydrant hydrant) {
                    // Hydrant might swap at any point, but if it's swapped at the start
                    // then we know it's *definitely* swapped.
                    final boolean hydrantDefinitelySwapped = hydrant.hasSwapped();
                    if (skipIncrementalSegment && !hydrantDefinitelySwapped) {
                        return new NoopQueryRunner<>();
                    }
                    // Prevent the underlying segment from swapping when its being iterated
                    final Pair<Segment, Closeable> segment = hydrant.getAndIncrementSegment();
                    try {
                        QueryRunner<T> baseRunner = QueryRunnerHelper.makeClosingQueryRunner(factory.createRunner(segment.lhs), segment.rhs);
                        // 2) Hydrants are not the same between replicas, make sure cache is local
                        if (hydrantDefinitelySwapped && cache.isLocal()) {
                            return new CachingQueryRunner<>(makeHydrantCacheIdentifier(hydrant), descriptor, objectMapper, cache, toolChest, baseRunner, MoreExecutors.sameThreadExecutor(), cacheConfig);
                        } else {
                            return baseRunner;
                        }
                    } catch (RuntimeException e) {
                        CloseQuietly.close(segment.rhs);
                        throw e;
                    }
                }
            }))), builderFn, sinkSegmentIdentifier, cpuTimeAccumulator), new SpecificSegmentSpec(descriptor));
        }
    }))), builderFn, emitter, cpuTimeAccumulator, true);
}
Also used : Query(io.druid.query.Query) Function(com.google.common.base.Function) ReportTimelineMissingSegmentQueryRunner(io.druid.query.ReportTimelineMissingSegmentQueryRunner) Sink(io.druid.segment.realtime.plumber.Sink) SpecificSegmentQueryRunner(io.druid.query.spec.SpecificSegmentQueryRunner) NoopQueryRunner(io.druid.query.NoopQueryRunner) SegmentDescriptor(io.druid.query.SegmentDescriptor) ISE(io.druid.java.util.common.ISE) FireHydrant(io.druid.segment.realtime.FireHydrant) Pair(io.druid.java.util.common.Pair) BySegmentQueryRunner(io.druid.query.BySegmentQueryRunner) MetricsEmittingQueryRunner(io.druid.query.MetricsEmittingQueryRunner) ReportTimelineMissingSegmentQueryRunner(io.druid.query.ReportTimelineMissingSegmentQueryRunner) CachingQueryRunner(io.druid.client.CachingQueryRunner) BySegmentQueryRunner(io.druid.query.BySegmentQueryRunner) SpecificSegmentQueryRunner(io.druid.query.spec.SpecificSegmentQueryRunner) QueryRunner(io.druid.query.QueryRunner) CPUTimeMetricQueryRunner(io.druid.query.CPUTimeMetricQueryRunner) NoopQueryRunner(io.druid.query.NoopQueryRunner) AtomicLong(java.util.concurrent.atomic.AtomicLong) TableDataSource(io.druid.query.TableDataSource) SpecificSegmentSpec(io.druid.query.spec.SpecificSegmentSpec) ServiceMetricEvent(com.metamx.emitter.service.ServiceMetricEvent) Nullable(javax.annotation.Nullable)

Aggregations

CachingQueryRunner (io.druid.client.CachingQueryRunner)2 BySegmentQueryRunner (io.druid.query.BySegmentQueryRunner)2 CPUTimeMetricQueryRunner (io.druid.query.CPUTimeMetricQueryRunner)2 MetricsEmittingQueryRunner (io.druid.query.MetricsEmittingQueryRunner)2 NoopQueryRunner (io.druid.query.NoopQueryRunner)2 Query (io.druid.query.Query)2 QueryRunner (io.druid.query.QueryRunner)2 ReportTimelineMissingSegmentQueryRunner (io.druid.query.ReportTimelineMissingSegmentQueryRunner)2 SegmentDescriptor (io.druid.query.SegmentDescriptor)2 SpecificSegmentQueryRunner (io.druid.query.spec.SpecificSegmentQueryRunner)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Function (com.google.common.base.Function)1 ServiceMetricEvent (com.metamx.emitter.service.ServiceMetricEvent)1 ISE (io.druid.java.util.common.ISE)1 Pair (io.druid.java.util.common.Pair)1 FunctionalIterable (io.druid.java.util.common.guava.FunctionalIterable)1 FinalizeResultsQueryRunner (io.druid.query.FinalizeResultsQueryRunner)1 ReferenceCountingSegmentQueryRunner (io.druid.query.ReferenceCountingSegmentQueryRunner)1 TableDataSource (io.druid.query.TableDataSource)1 SpecificSegmentSpec (io.druid.query.spec.SpecificSegmentSpec)1