You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2022/02/15 22:39:23 UTC

[GitHub] [pinot] Jackie-Jiang commented on a change in pull request #8188: Add Support for Getting Live Brokers for a Table (without type suffix)

Jackie-Jiang commented on a change in pull request #8188:
URL: https://github.com/apache/pinot/pull/8188#discussion_r807375910



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableInstances.java
##########
@@ -116,16 +121,42 @@ public String getTableInstances(
   }
 
   @GET
-  @Path("/tables/{tableNameWithType}/livebrokers")
+  @Path("/tables/{tableName}/livebrokers")
   @Produces(MediaType.APPLICATION_JSON)
   @ApiOperation(value = "List the brokers serving a table", notes = "List live brokers of the given table based on EV")
   @ApiResponses(value = {
       @ApiResponse(code = 200, message = "Success"),
       @ApiResponse(code = 404, message = "Table not found"),
       @ApiResponse(code = 500, message = "Internal server error")})
   public List<String> getLiveBrokersForTable(
-      @ApiParam(value = "Table name with type", required = true)
-      @PathParam("tableNameWithType") String tableNameWithType) {
-    return _pinotHelixResourceManager.getLiveBrokersForTable(tableNameWithType);
+      @ApiParam(value = "Table name (with or without type)", required = true)
+      @PathParam("tableName") String tableName) {
+    if (TableNameBuilder.getTableTypeFromTableName(tableName) != null) {
+      return _pinotHelixResourceManager.getLiveBrokersForTable(tableName);

Review comment:
       Shall we push down this logic into the `PinotHelixResourceManager`? I.e. change `PinotHelixResourceManager.getLiveBrokersForTable()` to take table name with or without type suffix

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableInstances.java
##########
@@ -116,16 +121,42 @@ public String getTableInstances(
   }
 
   @GET
-  @Path("/tables/{tableNameWithType}/livebrokers")
+  @Path("/tables/{tableName}/livebrokers")
   @Produces(MediaType.APPLICATION_JSON)
   @ApiOperation(value = "List the brokers serving a table", notes = "List live brokers of the given table based on EV")
   @ApiResponses(value = {
       @ApiResponse(code = 200, message = "Success"),
       @ApiResponse(code = 404, message = "Table not found"),
       @ApiResponse(code = 500, message = "Internal server error")})
   public List<String> getLiveBrokersForTable(
-      @ApiParam(value = "Table name with type", required = true)
-      @PathParam("tableNameWithType") String tableNameWithType) {
-    return _pinotHelixResourceManager.getLiveBrokersForTable(tableNameWithType);
+      @ApiParam(value = "Table name (with or without type)", required = true)
+      @PathParam("tableName") String tableName) {
+    if (TableNameBuilder.getTableTypeFromTableName(tableName) != null) {
+      return _pinotHelixResourceManager.getLiveBrokersForTable(tableName);
+    }
+    // If table doesn't have table-type suffix, then we return the intersection
+    // of brokers for both realtime and offline table-types.
+    boolean hasOfflineTable = _pinotHelixResourceManager.hasOfflineTable(tableName);
+    boolean hasRealtimeTable = _pinotHelixResourceManager.hasRealtimeTable(tableName);
+    if (hasOfflineTable && hasRealtimeTable) {
+      Set<String> offlineBrokers = new HashSet<>(_pinotHelixResourceManager.getLiveBrokersForTable(
+              TableNameBuilder.OFFLINE.tableNameWithType(tableName)));
+      return _pinotHelixResourceManager.getLiveBrokersForTable(
+              TableNameBuilder.REALTIME.tableNameWithType(tableName))
+              .stream()
+              .filter(offlineBrokers::contains)
+              .collect(Collectors.toList());
+    } else if (hasOfflineTable) {
+      return _pinotHelixResourceManager.getLiveBrokersForTable(
+              TableNameBuilder.OFFLINE.tableNameWithType(tableName));
+    } else if (hasRealtimeTable) {
+      return _pinotHelixResourceManager.getLiveBrokersForTable(
+              TableNameBuilder.REALTIME.tableNameWithType(tableName));
+    }
+    return new ArrayList<>();
+  }
+
+  public void setPinotHelixResourceManager(PinotHelixResourceManager pinotHelixResourceManager) {
+      _pinotHelixResourceManager = pinotHelixResourceManager;

Review comment:
       Please set up the [Pinot Style](https://docs.pinot.apache.org/developers/developers-and-contributors/code-setup#setup-ide) and re-format the code




-- 
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-unsubscribe@pinot.apache.org

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



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