Jackie-Jiang commented on code in PR #12358:
URL: https://github.com/apache/pinot/pull/12358#discussion_r1477120044
##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/service/dispatch/QueryDispatcher.java:
##########
@@ -107,50 +110,76 @@ public ResultTable submitAndReduce(RequestContext
context, DispatchableSubPlan d
void submit(long requestId, DispatchableSubPlan dispatchableSubPlan, long
timeoutMs, Map<String, String> queryOptions)
throws Exception {
Deadline deadline = Deadline.after(timeoutMs, TimeUnit.MILLISECONDS);
- BlockingQueue<AsyncQueryDispatchResponse> dispatchCallbacks = new
LinkedBlockingQueue<>();
List<DispatchablePlanFragment> stagePlans =
dispatchableSubPlan.getQueryStageList();
int numStages = stagePlans.size();
- int numDispatchCalls = 0;
- // Do not submit the reduce stage (stage 0)
+ Set<QueryServerInstance> serverInstances = new HashSet<>();
+ // TODO: If serialization is slow, consider serializing each stage in
parallel
+ StageInfo[] stageInfoMap = new StageInfo[numStages];
+ // Ignore the reduce stage (stage 0)
for (int stageId = 1; stageId < numStages; stageId++) {
- for (Map.Entry<QueryServerInstance, List<Integer>> entry :
stagePlans.get(stageId)
- .getServerInstanceToWorkerIdMap().entrySet()) {
- QueryServerInstance queryServerInstance = entry.getKey();
- Worker.QueryRequest.Builder queryRequestBuilder =
Worker.QueryRequest.newBuilder();
- queryRequestBuilder.addStagePlan(
- QueryPlanSerDeUtils.serialize(dispatchableSubPlan, stageId,
queryServerInstance, entry.getValue()));
- Worker.QueryRequest queryRequest =
-
queryRequestBuilder.putMetadata(CommonConstants.Query.Request.MetadataKeys.REQUEST_ID,
- String.valueOf(requestId))
-
.putMetadata(CommonConstants.Broker.Request.QueryOptionKey.TIMEOUT_MS,
String.valueOf(timeoutMs))
- .putAllMetadata(queryOptions).build();
- DispatchClient client = getOrCreateDispatchClient(queryServerInstance);
- int finalStageId = stageId;
- _executorService.submit(
- () -> client.submit(queryRequest, finalStageId,
queryServerInstance, deadline, dispatchCallbacks::offer));
- numDispatchCalls++;
- }
+ DispatchablePlanFragment stagePlan = stagePlans.get(stageId);
+
serverInstances.addAll(stagePlan.getServerInstanceToWorkerIdMap().keySet());
+ Plan.StageNode rootNode =
+ StageNodeSerDeUtils.serializeStageNode((AbstractPlanNode)
stagePlan.getPlanFragment().getFragmentRoot());
+ List<Worker.WorkerMetadata> workerMetadataList =
QueryPlanSerDeUtils.toProtoWorkerMetadataList(stagePlan);
+ stageInfoMap[stageId] = new StageInfo(rootNode, workerMetadataList,
stagePlan.getCustomProperties());
+ }
+ Map<String, String> requestMetadata = new HashMap<>();
+ requestMetadata.put(CommonConstants.Query.Request.MetadataKeys.REQUEST_ID,
Long.toString(requestId));
+
requestMetadata.put(CommonConstants.Broker.Request.QueryOptionKey.TIMEOUT_MS,
Long.toString(timeoutMs));
+ requestMetadata.putAll(queryOptions);
+
+ // Submit the query plan to all servers in parallel
+ int numServers = serverInstances.size();
+ BlockingQueue<AsyncQueryDispatchResponse> dispatchCallbacks = new
ArrayBlockingQueue<>(numServers);
+ for (QueryServerInstance serverInstance : serverInstances) {
+ _executorService.submit(() -> {
Review Comment:
Good point! Will do it as a separate PR
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]