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


##########
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:
   no. i think that's the problem with previous implementation. what i did here 
is:
   1. get a UNION of all the table's broker tag from all the tables (not 
intersect). e.g. tableA has tenant tag A and tableB has tenant tag B then the 
UNION will be [A, B]
   2. get a list of brokers that contains all the broker tags in the UNION --> 
only the broker that are tagged with both A and B will be selected. 
   3. select a random broker from the list of brokers. 
   
   
   
   



-- 
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