adarshsanjeev commented on code in PR #17775: URL: https://github.com/apache/druid/pull/17775#discussion_r1985011791
########## server/src/main/java/org/apache/druid/server/http/SegmentListerResource.java: ########## @@ -215,23 +215,131 @@ public void onFailure(Throwable th) return null; } + /** + * Deprecated. + * + * @see SegmentListerResource#applyDataSegmentChangeRequests(long, HistoricalSegmentChangeRequest, HttpServletRequest) + */ + @Deprecated + @POST + @Path("/changeRequests") + @Produces({MediaType.APPLICATION_JSON, SmileMediaTypes.APPLICATION_JACKSON_SMILE}) + @Consumes({MediaType.APPLICATION_JSON, SmileMediaTypes.APPLICATION_JACKSON_SMILE}) + public void applyDataSegmentChangeRequests( + @QueryParam("timeout") long timeout, + List<DataSegmentChangeRequest> changeRequestList, + @Context final HttpServletRequest req + ) throws IOException + { + if (loadDropRequestHandler == null) { + sendErrorResponse(req, HttpServletResponse.SC_NOT_FOUND, "load/drop handler is not available."); + return; + } + + if (timeout <= 0) { + sendErrorResponse(req, HttpServletResponse.SC_BAD_REQUEST, "timeout must be positive."); + return; + } + + if (changeRequestList == null || changeRequestList.isEmpty()) { + sendErrorResponse(req, HttpServletResponse.SC_BAD_REQUEST, "No change requests provided."); + return; + } + + final ResponseContext context = createContext(req.getHeader("Accept")); + final ListenableFuture<List<DataSegmentChangeResponse>> future = + loadDropRequestHandler.processBatch(changeRequestList, SegmentLoadDropHandler.SegmentLoadingMode.NORMAL); + + final AsyncContext asyncContext = req.startAsync(); + + asyncContext.addListener( + new AsyncListener() + { + @Override + public void onComplete(AsyncEvent event) + { + } + + @Override + public void onTimeout(AsyncEvent event) + { + + // HTTP 204 NO_CONTENT is sent to the client. + future.cancel(true); + event.getAsyncContext().complete(); + } + + @Override + public void onError(AsyncEvent event) + { + } + + @Override + public void onStartAsync(AsyncEvent event) + { + } + } + ); + + Futures.addCallback( + future, + new FutureCallback<>() + { + @Override + public void onSuccess(List<DataSegmentChangeResponse> result) + { + try { + HttpServletResponse response = (HttpServletResponse) asyncContext.getResponse(); + response.setStatus(HttpServletResponse.SC_OK); + context.inputMapper.writerFor(HttpLoadQueuePeon.RESPONSE_ENTITY_TYPE_REF) + .writeValue(asyncContext.getResponse().getOutputStream(), result); + asyncContext.complete(); + } + catch (Exception ex) { + log.debug(ex, "Request timed out or closed already."); + } + } + + @Override + public void onFailure(Throwable th) + { + try { + HttpServletResponse response = (HttpServletResponse) asyncContext.getResponse(); + if (th instanceof IllegalArgumentException) { + response.sendError(HttpServletResponse.SC_BAD_REQUEST, th.getMessage()); + } else { + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, th.getMessage()); + } + asyncContext.complete(); + } + catch (Exception ex) { + log.debug(ex, "Request timed out or closed already."); + } + } + }, + MoreExecutors.directExecutor() + ); + + asyncContext.setTimeout(timeout); + } + /** * This endpoint is used by HttpLoadQueuePeon to assign segment load/drop requests batch. This endpoint makes the * client wait till one of the following events occur. Note that this is implemented using async IO so no jetty * threads are held while in wait. - * + * <br> * (1) Given timeout elapses. * (2) Some load/drop request completed. - * + * <br> * It returns a map of "load/drop request -> SUCCESS/FAILED/PENDING status" for each request in the batch. */ @POST - @Path("/changeRequests") + @Path("/segmentChangeRequests") @Produces({MediaType.APPLICATION_JSON, SmileMediaTypes.APPLICATION_JACKSON_SMILE}) @Consumes({MediaType.APPLICATION_JSON, SmileMediaTypes.APPLICATION_JACKSON_SMILE}) public void applyDataSegmentChangeRequests( Review Comment: Removed the new API and reused the existing one -- 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...@druid.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org