Source:
Sequence<T> run(final UnaryOperator<TimelineLookup<String, ServerSelector>> timelineConverter) { @Nullable TimelineLookup<String, ServerSelector> timeline = serverView.getTimeline(query.getDataSource()); if (timeline == null) { return Sequences.empty(); } timeline = timelineConverter.apply(timeline); if (uncoveredIntervalsLimit > 0) { computeUncoveredIntervals(timeline); } final Set<ServerToSegment> segments = computeSegmentsToQuery(timeline); @Nullable final byte[] queryCacheKey = computeQueryCacheKey(); @Nullable final String queryResultKey = computeCurrentEtag(segments, queryCacheKey); if (query.getContext().get(QueryResource.HEADER_IF_NONE_MATCH) != null) { @Nullable final String prevEtag = (String) query.getContext().get(QueryResource.HEADER_IF_NONE_MATCH); @Nullable final String currentEtag = queryResultKey; if (currentEtag != null && currentEtag.equals(prevEtag)) { return Sequences.empty(); } } @Nullable final byte[] cachedResultSet = fetchFromResultLevelCache(queryResultKey); if (cachedResultSet != null) { log.info("Fetching entire result set from cache"); return fetchSequenceFromResultLevelCache(cachedResultSet); } final List<Pair<Interval, byte[]>> alreadyCachedResults = pruneSegmentsWithCachedResults(queryCacheKey, segments); final SortedMap<DruidServer, List<SegmentDescriptor>> segmentsByServer = groupSegmentsByServer(segments); return Sequences.wrap(new LazySequence<>(() -> { List<Sequence<T>> sequencesByInterval = new ArrayList<>(alreadyCachedResults.size() + segmentsByServer.size()); addSequencesFromCache(sequencesByInterval, alreadyCachedResults); addSequencesFromServer(sequencesByInterval, segmentsByServer); return Sequences .simple(sequencesByInterval) .flatMerge(seq -> seq, query.getResultOrdering()); }).map(r -> cacheResultEntry(r, queryResultKey)), new SequenceWrapper() { @Override public void after(boolean isDone, Throwable thrown) throws Exception { final CachePopulator cachePopulator = getResultCachePopulator(queryResultKey); if (cachePopulator != null) { cachePopulator.populate(); } } }); }

Target:
Sequence<T> run(final UnaryOperator<TimelineLookup<String, ServerSelector>> timelineConverter) { @Nullable TimelineLookup<String, ServerSelector> timeline = serverView.getTimeline(query.getDataSource()); if (timeline == null) { return Sequences.empty(); } timeline = timelineConverter.apply(timeline); if (uncoveredIntervalsLimit > 0) { computeUncoveredIntervals(timeline); } final Set<ServerToSegment> segments = computeSegmentsToQuery(timeline); @Nullable final byte[] queryCacheKey = computeQueryCacheKey(); if (query.getContext().get(QueryResource.HEADER_IF_NONE_MATCH) != null) { @Nullable final String prevEtag = (String) query.getContext().get(QueryResource.HEADER_IF_NONE_MATCH); @Nullable final String currentEtag = computeCurrentEtag(segments, queryCacheKey); if (currentEtag != null && currentEtag.equals(prevEtag)) { return Sequences.empty(); } } final List<Pair<Interval, byte[]>> alreadyCachedResults = pruneSegmentsWithCachedResults(queryCacheKey, segments); final SortedMap<DruidServer, List<SegmentDescriptor>> segmentsByServer = groupSegmentsByServer(segments); return new LazySequence<>(() -> { List<Sequence<T>> sequencesByInterval = new ArrayList<>(alreadyCachedResults.size() + segmentsByServer.size()); addSequencesFromCache(sequencesByInterval, alreadyCachedResults); addSequencesFromServer(sequencesByInterval, segmentsByServer); return Sequences .simple(sequencesByInterval) .flatMerge(seq -> seq, query.getResultOrdering()); }); }