jihoonson 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_r214210501
##########
File path: server/src/main/java/io/druid/client/CachingClusteredClient.java
##########
@@ -162,34 +184,75 @@ public CachingClusteredClient(
return new SpecificQueryRunnable<>(queryPlus,
responseContext).run(timelineConverter);
}
- @Override
- public <T> QueryRunner<T> getQueryRunnerForSegments(final Query<T> query,
final Iterable<SegmentDescriptor> specs)
+ private <T> QueryRunner<T> runAndMergeWithTimelineChange(
+ final Query<T> query,
+ final UnaryOperator<TimelineLookup<String, ServerSelector>>
timelineConverter
+ )
{
- return new QueryRunner<T>()
- {
- @Override
- public Sequence<T> run(final QueryPlus<T> queryPlus, final Map<String,
Object> responseContext)
- {
- return CachingClusteredClient.this.run(
+ final OptionalLong mergeBatch =
QueryContexts.getIntermediateMergeBatchThreshold(query);
+
+ if (mergeBatch.isPresent()) {
+ final QueryRunnerFactory<T, Query<T>> queryRunnerFactory =
conglomerate.findFactory(query);
+ final QueryToolChest<T, Query<T>> toolChest =
queryRunnerFactory.getToolchest();
+ return (queryPlus, responseContext) -> {
+ final Stream<? extends Sequence<T>> sequences = run(
queryPlus,
responseContext,
- timeline -> {
- final VersionedIntervalTimeline<String, ServerSelector>
timeline2 =
- new VersionedIntervalTimeline<>(Ordering.natural());
- for (SegmentDescriptor spec : specs) {
- final PartitionHolder<ServerSelector> entry =
timeline.findEntry(spec.getInterval(), spec.getVersion());
- if (entry != null) {
- final PartitionChunk<ServerSelector> chunk =
entry.getChunk(spec.getPartitionNumber());
- if (chunk != null) {
- timeline2.add(spec.getInterval(), spec.getVersion(),
chunk);
- }
- }
- }
- return timeline2;
- }
+ timelineConverter
+ );
+ return MergeWorkTask.parallelMerge(
+ sequences.parallel(),
+ sequenceStream ->
+ new FluentQueryRunnerBuilder<>(toolChest)
+ .create(
+ queryRunnerFactory.mergeRunners(
Review comment:
@drcrallen thanks, but some of my comments are not addressed. Some queries
don't use `ChainedExecutionQueryRunner`. The groupBy query is an example.
groupBy v1 and groupBy v2 use `GroupByMergedQueryRunner.run()` and
`GroupByMergingQueryRunnerV2.run()` in `QueryRunnerFactory.mergeRunners`,
respectively. And they also have some blocking mechanism which requires to be
wrapped by `ForkJoinPool.managedBlock()`. For example, there are two places in
`GroupByMergingQueryRunnerV2.run()`. One is to [get
mergeBuffers](https://github.com/apache/incubator-druid/blob/master/processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/GroupByMergingQueryRunnerV2.java#L336-L340)
and another is to [wait for futures to
complete](https://github.com/apache/incubator-druid/blob/master/processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/GroupByMergingQueryRunnerV2.java#L365).
All these places should be handled properly.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]