Search in sources :

Example 1 with YieldingSequenceBase

use of io.druid.java.util.common.guava.YieldingSequenceBase in project druid by druid-io.

the class RetryQueryRunner method run.

@Override
public Sequence<T> run(final Query<T> query, final Map<String, Object> context) {
    final List<Sequence<T>> listOfSequences = Lists.newArrayList();
    listOfSequences.add(baseRunner.run(query, context));
    return new YieldingSequenceBase<T>() {

        @Override
        public <OutType> Yielder<OutType> toYielder(OutType initValue, YieldingAccumulator<OutType, T> accumulator) {
            List<SegmentDescriptor> missingSegments = getMissingSegments(context);
            if (!missingSegments.isEmpty()) {
                for (int i = 0; i < config.getNumTries(); i++) {
                    log.info("[%,d] missing segments found. Retry attempt [%,d]", missingSegments.size(), i);
                    context.put(Result.MISSING_SEGMENTS_KEY, Lists.newArrayList());
                    final Query<T> retryQuery = query.withQuerySegmentSpec(new MultipleSpecificSegmentSpec(missingSegments));
                    Sequence<T> retrySequence = baseRunner.run(retryQuery, context);
                    listOfSequences.add(retrySequence);
                    missingSegments = getMissingSegments(context);
                    if (missingSegments.isEmpty()) {
                        break;
                    }
                }
                final List<SegmentDescriptor> finalMissingSegs = getMissingSegments(context);
                if (!config.isReturnPartialResults() && !finalMissingSegs.isEmpty()) {
                    throw new SegmentMissingException("No results found for segments[%s]", finalMissingSegs);
                }
                return new MergeSequence<>(query.getResultOrdering(), Sequences.simple(listOfSequences)).toYielder(initValue, accumulator);
            } else {
                return Iterables.getOnlyElement(listOfSequences).toYielder(initValue, accumulator);
            }
        }
    };
}
Also used : MultipleSpecificSegmentSpec(io.druid.query.spec.MultipleSpecificSegmentSpec) YieldingSequenceBase(io.druid.java.util.common.guava.YieldingSequenceBase) SegmentMissingException(io.druid.segment.SegmentMissingException) MergeSequence(io.druid.java.util.common.guava.MergeSequence) Sequence(io.druid.java.util.common.guava.Sequence) YieldingAccumulator(io.druid.java.util.common.guava.YieldingAccumulator)

Aggregations

MergeSequence (io.druid.java.util.common.guava.MergeSequence)1 Sequence (io.druid.java.util.common.guava.Sequence)1 YieldingAccumulator (io.druid.java.util.common.guava.YieldingAccumulator)1 YieldingSequenceBase (io.druid.java.util.common.guava.YieldingSequenceBase)1 MultipleSpecificSegmentSpec (io.druid.query.spec.MultipleSpecificSegmentSpec)1 SegmentMissingException (io.druid.segment.SegmentMissingException)1