leventov commented on a change in pull request #5913: Move Caching Cluster Client to java streams and allow parallel intermediate merges URL: https://github.com/apache/incubator-druid/pull/5913#discussion_r205996653
########## File path: processing/src/main/java/io/druid/query/ChainedExecutionQueryRunner.java ########## @@ -70,87 +74,113 @@ public ChainedExecutionQueryRunner( QueryRunner<T>... queryables ) { - this(exec, queryWatcher, Arrays.asList(queryables)); + this(exec, queryWatcher, Arrays.stream(queryables)); } public ChainedExecutionQueryRunner( ExecutorService exec, QueryWatcher queryWatcher, Iterable<QueryRunner<T>> queryables ) + { + this(exec, queryWatcher, StreamSupport.stream(queryables.spliterator(), false)); + } + + public ChainedExecutionQueryRunner( + ExecutorService exec, + QueryWatcher queryWatcher, + Stream<QueryRunner<T>> queryables + ) { // listeningDecorator will leave PrioritizedExecutorService unchanged, // since it already implements ListeningExecutorService this.exec = MoreExecutors.listeningDecorator(exec); - this.queryables = Iterables.unmodifiableIterable(queryables); this.queryWatcher = queryWatcher; + this.queryables = queryables; } @Override public Sequence<T> run(final QueryPlus<T> queryPlus, final Map<String, Object> responseContext) { - Query<T> query = queryPlus.getQuery(); + final Query<T> query = queryPlus.getQuery(); final int priority = QueryContexts.getPriority(query); - final Ordering ordering = query.getResultOrdering(); + final Ordering<T> ordering = query.getResultOrdering(); final QueryPlus<T> threadSafeQueryPlus = queryPlus.withoutThreadUnsafeState(); - return new BaseSequence<T, Iterator<T>>( + return new BaseSequence<>( new BaseSequence.IteratorMaker<T, Iterator<T>>() { @Override public Iterator<T> make() { // Make it a List<> to materialize all of the values (so that it will submit everything to the executor) - ListenableFuture<List<Iterable<T>>> futures = Futures.allAsList( - Lists.newArrayList( - Iterables.transform( - queryables, - input -> { - if (input == null) { - throw new ISE("Null queryRunner! Looks to be some segment unmapping action happening"); + final ListenableFuture<List<Iterable<T>>> futures = GuavaUtils.allFuturesAsList( + queryables.peek( + queryRunner -> { + if (queryRunner == null) { + throw new ISE("Null queryRunner! Looks to be some segment unmapping action happening"); + } + } + ).map( + queryRunner -> new AbstractPrioritizedCallable<Iterable<T>>(priority) + { + @Override + public Iterable<T> call() + { + try { + Sequence<T> result = queryRunner.run(threadSafeQueryPlus, responseContext); + if (result == null) { + throw new ISE("Got a null result! Segments are missing!"); } - return exec.submit( - new AbstractPrioritizedCallable<Iterable<T>>(priority) - { - @Override - public Iterable<T> call() - { - try { - Sequence<T> result = input.run(threadSafeQueryPlus, responseContext); - if (result == null) { - throw new ISE("Got a null result! Segments are missing!"); - } - - List<T> retVal = result.toList(); - if (retVal == null) { - throw new ISE("Got a null list of results! WTF?!"); - } - - return retVal; - } - catch (QueryInterruptedException e) { - throw Throwables.propagate(e); - } - catch (Exception e) { - log.error(e, "Exception with one of the sequences!"); - throw Throwables.propagate(e); - } - } - } - ); + List<T> retVal = result.toList(); + if (retVal == null) { + throw new ISE("Got a null list of results! WTF?!"); + } + + return retVal; + } + catch (QueryInterruptedException e) { + throw Throwables.propagate(e); + } + catch (Exception e) { + log.error(e, "Exception with one of the sequences!"); + throw Throwables.propagate(e); } - ) - ) + } + } + ).map(exec::submit) ); queryWatcher.registerQuery(query, futures); try { + final DateTime deadline = + QueryContexts.hasTimeout(query) ? + DateTimes.utc(DateTimes.nowUtc().getMillis() + QueryContexts.getTimeout(query)) : Review comment: `DateTimes.nowUtc().plusMillis(QueryContexts.getTimeout(query))` is better ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org