kfaraz opened a new pull request, #20784:
URL: https://github.com/apache/druid/pull/20784

   ## Description
   
   `OverlordResource` had a small private nested class `AsyncRequest` that 
wraps a request's `AsyncContext` to safely complete an async HTTP response 
exactly once (guarding against writing to an already-completed or timed-out 
request). This PR extracts that class into a standalone, reusable 
`org.apache.druid.server.http.AsyncRequest` in `druid-server`, and migrates 
other resource classes with a similar pattern to use it, removing a fair amount 
of duplicated boilerplate.
   
   ### Changes
   
   - Added `org.apache.druid.server.http.AsyncRequest` (in `druid-server`), 
generalizing the original `OverlordResource.AsyncRequest`:
     - Accepts an `ObjectMapper` (and optionally a content type) instead of 
being hardcoded to JSON.
     - `complete(statusCode, result)` / `complete(statusCode, result, 
TypeReference)` / `complete(statusCode, result, JavaType)` — write a response 
body (JSON/Smile) via the configured mapper, with an optional explicit type 
hint for generic/type-erased payloads (needed to preserve polymorphic 
`@JsonTypeInfo` serialization, e.g. `ChangeRequestsSnapshot<T>`).
     - `completeWithError(statusCode, message)` — wraps 
`HttpServletResponse#sendError`.
     - `completeWithStatus(statusCode)` — status-only completion, no body.
     - `addTimeoutListener(...)` / `setTimeout(...)` — convenience wrappers 
around the existing `ServletResourceUtils.createAsyncTimeoutListener` helper.
     - All fields are private, all methods are public, and the class plus each 
method carry a short (1-line) javadoc.
   
   - Updated `OverlordResource` to use the new shared class (reference example 
for wiring it up), removing its private nested `AsyncRequest`.
   
   - Migrated the following `*Resource.java` classes that use `AsyncContext` 
with a similar "wait on a future, then write the result or an error" shape:
     - `SegmentListerResource`
     - `TaskManagementResource`
     - `MessageRelayResource`
   
   - Left `QueryResource` and `WorkerResource` untouched: their `AsyncContext` 
usage doesn't fit this abstraction (`QueryResource`'s is a one-off 
error-fallback path with bespoke `isCommitted()` handling; `WorkerResource`'s 
is a raw chunked octet-stream transfer, not a mapped-object response).
   
   ### Testing
   
   - `mvn -pl :druid-server,:druid-indexing-service,:druid-multi-stage-query 
-am compile` succeeds.
   - Existing `SegmentListerResourceTest` and `OverlordResourceTest` pass 
unchanged.
   - Checkstyle passes on all touched modules.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-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: [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