Jackie-Jiang commented on code in PR #17494:
URL: https://github.com/apache/pinot/pull/17494#discussion_r2697237843


##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotSegmentUploadDownloadRestletResource.java:
##########
@@ -984,29 +994,45 @@ public void uploadSegmentAsMultiPartV2(FormDataMultiPart 
multiPart,
   @Authenticate(AccessType.UPDATE)
   @Produces(MediaType.APPLICATION_JSON)
   @ApiOperation(value = "Start to replace segments", notes = "Start to replace 
segments")
-  public Response startReplaceSegments(
+  public void startReplaceSegments(
       @ApiParam(value = "Name of the table", required = true) 
@PathParam("tableName") String tableName,
       @ApiParam(value = "OFFLINE|REALTIME", required = true) 
@QueryParam("type") String tableTypeStr,
       @ApiParam(value = "Force cleanup") @QueryParam("forceCleanup") 
@DefaultValue("false") boolean forceCleanup,
       @ApiParam(value = "Fields belonging to start replace segment request", 
required = true)
-      StartReplaceSegmentsRequest startReplaceSegmentsRequest, @Context 
HttpHeaders headers) {
-    tableName = DatabaseUtils.translateTableName(tableName, headers);
-    TableType tableType = Constants.validateTableType(tableTypeStr);
-    if (tableType == null) {
-      throw new ControllerApplicationException(LOGGER, "Table type should 
either be offline or realtime",
-          Response.Status.BAD_REQUEST);
-    }
-    String tableNameWithType =
-        
ResourceUtils.getExistingTableNamesWithType(_pinotHelixResourceManager, 
tableName, tableType, LOGGER).get(0);
-    try {
-      String segmentLineageEntryId = 
_pinotHelixResourceManager.startReplaceSegments(tableNameWithType,
-          startReplaceSegmentsRequest.getSegmentsFrom(), 
startReplaceSegmentsRequest.getSegmentsTo(), forceCleanup,
-          startReplaceSegmentsRequest.getCustomMap());
-      return 
Response.ok(JsonUtils.newObjectNode().put("segmentLineageEntryId", 
segmentLineageEntryId)).build();
-    } catch (Exception e) {
-      _controllerMetrics.addMeteredTableValue(tableNameWithType, 
ControllerMeter.NUMBER_START_REPLACE_FAILURE, 1);
-      throw new ControllerApplicationException(LOGGER, e.getMessage(), 
Response.Status.INTERNAL_SERVER_ERROR, e);
-    }
+      StartReplaceSegmentsRequest startReplaceSegmentsRequest, @Context 
HttpHeaders headers,
+      @Suspended final AsyncResponse asyncResponse) {
+    _resourceExecutorService.execute(() -> {
+      String translatedTableName;
+      TableType tableType;
+      String tableNameWithType;
+      try {
+        translatedTableName = DatabaseUtils.translateTableName(tableName, 
headers);

Review Comment:
   When using `AsyncResponse`, does it work when the method throws exception? 
If it has the same behavior without `AsyncResponse`, we can keep the table 
translation and type check logic as is to simplify the code



##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotSegmentUploadDownloadRestletResource.java:
##########
@@ -984,29 +994,49 @@ public void uploadSegmentAsMultiPartV2(FormDataMultiPart 
multiPart,
   @Authenticate(AccessType.UPDATE)
   @Produces(MediaType.APPLICATION_JSON)
   @ApiOperation(value = "Start to replace segments", notes = "Start to replace 
segments")
-  public Response startReplaceSegments(
+  public void startReplaceSegments(
       @ApiParam(value = "Name of the table", required = true) 
@PathParam("tableName") String tableName,
       @ApiParam(value = "OFFLINE|REALTIME", required = true) 
@QueryParam("type") String tableTypeStr,
       @ApiParam(value = "Force cleanup") @QueryParam("forceCleanup") 
@DefaultValue("false") boolean forceCleanup,
       @ApiParam(value = "Fields belonging to start replace segment request", 
required = true)
-      StartReplaceSegmentsRequest startReplaceSegmentsRequest, @Context 
HttpHeaders headers) {
-    tableName = DatabaseUtils.translateTableName(tableName, headers);
-    TableType tableType = Constants.validateTableType(tableTypeStr);
-    if (tableType == null) {
-      throw new ControllerApplicationException(LOGGER, "Table type should 
either be offline or realtime",
-          Response.Status.BAD_REQUEST);
-    }
-    String tableNameWithType =
-        
ResourceUtils.getExistingTableNamesWithType(_pinotHelixResourceManager, 
tableName, tableType, LOGGER).get(0);
-    try {
-      String segmentLineageEntryId = 
_pinotHelixResourceManager.startReplaceSegments(tableNameWithType,
-          startReplaceSegmentsRequest.getSegmentsFrom(), 
startReplaceSegmentsRequest.getSegmentsTo(), forceCleanup,
-          startReplaceSegmentsRequest.getCustomMap());
-      return 
Response.ok(JsonUtils.newObjectNode().put("segmentLineageEntryId", 
segmentLineageEntryId)).build();
-    } catch (Exception e) {
-      _controllerMetrics.addMeteredTableValue(tableNameWithType, 
ControllerMeter.NUMBER_START_REPLACE_FAILURE, 1);
-      throw new ControllerApplicationException(LOGGER, e.getMessage(), 
Response.Status.INTERNAL_SERVER_ERROR, e);
-    }
+      StartReplaceSegmentsRequest startReplaceSegmentsRequest, @Context 
HttpHeaders headers,
+      @Suspended final AsyncResponse asyncResponse) {

Review Comment:
   (minor) We follow our own convention. Also the ones added in 
`PinotTaskRestletResource` do not have `final` as well



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to