Jackie-Jiang commented on code in PR #11241: URL: https://github.com/apache/pinot/pull/11241#discussion_r1281301707
########## pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotQueryResource.java: ########## @@ -299,16 +277,40 @@ private List<TableConfig> getListTableConfigs(List<String> tableNames) { return allTableConfigList; } + private String selectInstanceId(List<String> instanceIds) { + 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. + return instanceIds.get(RANDOM.nextInt(instanceIds.size())); + } + + private List<String> findCommonBrokerInstance(Set<String> brokerTenants) { + Set<String> commonInstances = null; + for (String brokerTenant : brokerTenants) { + Set<String> instances = _pinotHelixResourceManager.getAllInstancesForBrokerTenant(brokerTenant); + if (commonInstances == null) { + commonInstances = instances; + } else { + commonInstances.retainAll(instances); + } + } + return commonInstances == null ? Collections.emptyList() : new ArrayList<>(commonInstances); + } + // return the brokerTenant if all table configs point to the same broker, else returns null Review Comment: Please update the javadoc ########## pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotQueryResource.java: ########## @@ -299,16 +277,40 @@ private List<TableConfig> getListTableConfigs(List<String> tableNames) { return allTableConfigList; } + private String selectInstanceId(List<String> instanceIds) { + 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. + return instanceIds.get(RANDOM.nextInt(instanceIds.size())); + } + + private List<String> findCommonBrokerInstance(Set<String> brokerTenants) { + Set<String> commonInstances = null; + for (String brokerTenant : brokerTenants) { + Set<String> instances = _pinotHelixResourceManager.getAllInstancesForBrokerTenant(brokerTenant); + if (commonInstances == null) { + commonInstances = instances; + } else { + commonInstances.retainAll(instances); + } + } + return commonInstances == null ? Collections.emptyList() : new ArrayList<>(commonInstances); + } + // return the brokerTenant if all table configs point to the same broker, else returns null - private String getCommonBrokerTenant(List<TableConfig> tableConfigList) { - Set<String> tableBrokers = new HashSet<>(); + private Set<String> getCommonBrokerTenants(List<TableConfig> tableConfigList) { Review Comment: This is no longer the common broker tenants, but all broker tenants ########## 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(); Review Comment: This doesn't seem correct. We should pick a random tenant -- 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