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 2019/11/18 19:02:38 UTC

[GitHub] [incubator-pinot] Jackie-Jiang commented on a change in pull request #4828: Add segment batch deletion rest API

Jackie-Jiang commented on a change in pull request #4828: Add segment batch deletion rest API
URL: https://github.com/apache/incubator-pinot/pull/4828#discussion_r347555116
 
 

 ##########
 File path: pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotSegmentRestletResource.java
 ##########
 @@ -431,11 +432,36 @@ public SuccessResponse deleteAllSegments(
       throw new ControllerApplicationException(LOGGER, "Table type must not be null", Status.BAD_REQUEST);
     }
     String tableNameWithType = getExistingTableNamesWithType(tableName, tableType).get(0);
-    deleteSegments(tableNameWithType, _pinotHelixResourceManager.getSegmentsFor(tableNameWithType));
+    deleteSegmentsInternal(tableNameWithType, _pinotHelixResourceManager.getSegmentsFor(tableNameWithType));
     return new SuccessResponse("All segments of table " + tableNameWithType + " deleted");
   }
 
-  private void deleteSegments(String tableNameWithType, List<String> segments) {
+  @POST
+  @Consumes(MediaType.APPLICATION_JSON)
+  @Produces(MediaType.APPLICATION_JSON)
+  @Path("/segments/{tableName}/delete")
+  @ApiOperation(value = "Delete the segments in the JSON array payload", notes = "Delete the segments in the JSON array payload")
+  public SuccessResponse deleteSegments(
+      @ApiParam(value = "Name of the table", required = true) @PathParam("tableName") String tableName,
+      List<String> segments) {
+    int numSegments = segments.size();
+    if (numSegments == 0) {
+      throw new ControllerApplicationException(LOGGER, "Segments must be provided", Status.BAD_REQUEST);
+    }
+    boolean realtimeSegment = SegmentName.isRealtimeSegmentName(segments.get(0));
+    for (int i = 1; i < numSegments; i++) {
+      if (SegmentName.isRealtimeSegmentName(segments.get(i)) != realtimeSegment) {
+        throw new ControllerApplicationException(LOGGER, "All segments must be of the same type (OFFLINE|REALTIME)",
+            Status.BAD_REQUEST);
+      }
+    }
+    TableType tableType = realtimeSegment ? TableType.REALTIME : TableType.OFFLINE;
+    String tableNameWithType = getExistingTableNamesWithType(tableName, tableType).get(0);
+    deleteSegmentsInternal(tableNameWithType, segments);
+    return new SuccessResponse("Deleted segments: " + segments + " from table: " + tableNameWithType);
 
 Review comment:
   Done

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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