Jackie-Jiang commented on code in PR #12201: URL: https://github.com/apache/pinot/pull/12201#discussion_r1508366878
########## pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java: ########## @@ -3921,7 +3921,16 @@ public TableStats getTableStats(String tableNameWithType) { * Returns map of tableName to list of live brokers * @return Map of tableName to list of ONLINE brokers serving the table */ - public Map<String, List<InstanceInfo>> getTableToLiveBrokersMapping() { + public Map<String, List<InstanceInfo>> getTableToLiveBrokersMapping() throws TableNotFoundException { + return getTableToLiveBrokersMapping(null); + } + + /** + * Returns map of arg tableName to list of live brokers + * @return Map of arg tableName to list of ONLINE brokers serving the table + */ + public Map<String, List<InstanceInfo>> getTableToLiveBrokersMapping(@Nullable Object nullableTableName) Review Comment: ```suggestion public Map<String, List<InstanceInfo>> getTableToLiveBrokersMapping(@Nullable String tableName) ``` ########## pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java: ########## @@ -3933,6 +3942,29 @@ public Map<String, List<InstanceInfo>> getTableToLiveBrokersMapping() { Map<String, List<InstanceInfo>> result = new HashMap<>(); ZNRecord znRecord = ev.getRecord(); + + if (nullableTableName != null && !nullableTableName.toString().isEmpty()) { Review Comment: ```suggestion if (StringUtils.isEmpty(tableName)) { ``` ########## pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java: ########## @@ -3933,6 +3942,29 @@ public Map<String, List<InstanceInfo>> getTableToLiveBrokersMapping() { Map<String, List<InstanceInfo>> result = new HashMap<>(); ZNRecord znRecord = ev.getRecord(); + + if (nullableTableName != null && !nullableTableName.toString().isEmpty()) { + List<String> tableNameWithType = getExistingTableNamesWithType(nullableTableName.toString(), null); + if (tableNameWithType.isEmpty()) { + throw new ControllerApplicationException(LOGGER, String.format("Table=%s not found", nullableTableName), + Response.Status.NOT_FOUND); + } + tableNameWithType.forEach(tableName -> { + Map<String, String> brokersToState = znRecord.getMapField(tableName); + List<InstanceInfo> hosts = new ArrayList<>(); + for (Map.Entry<String, String> brokerEntry : brokersToState.entrySet()) { + if ("ONLINE".equalsIgnoreCase(brokerEntry.getValue()) + && instanceConfigMap.containsKey(brokerEntry.getKey())) { + InstanceConfig instanceConfig = instanceConfigMap.get(brokerEntry.getKey()); + hosts.add(new InstanceInfo(instanceConfig.getInstanceName(), instanceConfig.getHostName(), + Integer.parseInt(instanceConfig.getPort()))); + } + } Review Comment: Consider extracting a common method ########## pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java: ########## @@ -3921,7 +3921,16 @@ public TableStats getTableStats(String tableNameWithType) { * Returns map of tableName to list of live brokers * @return Map of tableName to list of ONLINE brokers serving the table */ - public Map<String, List<InstanceInfo>> getTableToLiveBrokersMapping() { + public Map<String, List<InstanceInfo>> getTableToLiveBrokersMapping() throws TableNotFoundException { Review Comment: (minor) reformat this change ########## pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableInstances.java: ########## @@ -165,9 +166,11 @@ public List<String> getLiveBrokersForTable( @ApiResponses(value = { @ApiResponse(code = 200, message = "Success"), @ApiResponse(code = 500, message = "Internal server error") }) - public Map<String, List<InstanceInfo>> getLiveBrokers() { + public Map<String, List<InstanceInfo>> getLiveBrokers( + @ApiParam(value = "Table name (with or without type)", required = false) @DefaultValue("") Review Comment: Are we going to ask for liver brokers on multiple tables (e.g. for JOIN queries)? If so, suggest taking `tableName` as a list. Search for `allowMultiple = true` to find examples of using list as api param -- 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