tibrewalpratik17 commented on code in PR #11241:
URL: https://github.com/apache/pinot/pull/11241#discussion_r1283219613


##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotQueryResource.java:
##########
@@ -214,31 +215,19 @@ private String getMultiStageQueryResponse(String query, 
String queryOptions, Htt
       // tenants can be completely disjoint. The leaf stages which access 
segments will be processed on the respective
       // server tenants for each table. The intermediate stages can be 
processed in either or all of the server tenants
       // belonging to the tables.
-      brokerTenant = getCommonBrokerTenant(tableConfigList);
-      if (brokerTenant == null) {
+      brokerTenants = getCommonBrokerTenants(tableConfigList);
+      if (brokerTenants.isEmpty()) {
         return 
QueryException.getException(QueryException.BROKER_REQUEST_SEND_ERROR, new 
Exception(
             String.format("Unable to dispatch multistage query with multiple 
tables : %s " + "on different tenant",
                 tableNames))).toString();
       }
     } else {
       // TODO fail these queries going forward. Added this logic to take care 
of tautologies like BETWEEN 0 and -1.
-      List<String> allBrokerList = new 
ArrayList<>(_pinotHelixResourceManager.getAllBrokerTenantNames());
-      brokerTenant = allBrokerList.get(RANDOM.nextInt(allBrokerList.size()));
+      brokerTenants = _pinotHelixResourceManager.getAllBrokerTenantNames();
       LOGGER.error("Unable to find table name from SQL {} thus dispatching to 
random broker.", query);
     }
-    List<String> instanceIds = new 
ArrayList<>(_pinotHelixResourceManager.getAllInstancesForBrokerTenant(brokerTenant));
-
-    if (instanceIds.isEmpty()) {
-      return QueryException.BROKER_RESOURCE_MISSING_ERROR.toString();
-    }
-
-    instanceIds.retainAll(_pinotHelixResourceManager.getOnlineInstanceList());
-    if (instanceIds.isEmpty()) {
-      return QueryException.BROKER_INSTANCE_MISSING_ERROR.toString();
-    }
-
-    // Send query to a random broker.
-    String instanceId = instanceIds.get(RANDOM.nextInt(instanceIds.size()));
+    List<String> instanceIds = findCommonBrokerInstance(brokerTenants);
+    String instanceId = selectInstanceId(instanceIds);

Review Comment:
   Umm yes but say in a scenario where there are 3 tables  -- tableA, tableB, 
tableC on broker tenants A, B, C.
   Interesection of [A, B] has 2 broker-instances common but brokertenant C as 
no instances common to either A or B. In this case, `findCommonBrokerInstance` 
will return Collections.emptyList() and `selectInstanceId` will return 
BROKER_RESOURCE_MISSING_ERROR.
   
   Here `_pinotHelixResourceManager.getAllBrokerTenantNames()` doesn't include 
tableNames that are passed in the query but all tables in the cluster. Chances 
are high that there are no common instances among all these table brokerTenants.



-- 
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: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to