mumrah opened a new pull request, #12403:
URL: https://github.com/apache/kafka/pull/12403
In ControllerApis, we are making use of the CompletableFuture-s returned by
QuorumController to add callbacks via `whenComplete`. Since these chained
methods on CompletableFuture return a _new_ CompletableFuture instance, the
ControllerPurgatory does not capture any of downstream exceptions when
completing the original instance. The only way to see these errors is to call
`get` on the chained future, or to add additional completion stages to handle
the error explicitly. However, we do not want to call `get` since that would
block the request threads.
This patch changes the signature of the request handlers in ControllerApis
to all return CompletableFuture. It also converts all of the
`CompletableFuture#whenComplete` callbacks to `CompletableFuture#handle`. This
allows us to directly handle exceptions thrown by the controller in the
individual request handlers. A single `whenComplete` error handler is added in
`ControllerApis#handle` which will ensure we log exceptions thrown by the
response builders (or other logic in the chained `handle` calls).
The resulting future chain now looks like:
```scala
controller.doStuff()
.handle { (result, exception) =>
// Transform result or exception into a response
}
.whenComplete { (result, exception) =>
// Handle errors thrown in "handle"
}
```
The future is still completed by ControllerPurgatory, and that is when the
completion stages are run. We do not call `get` in ControllerApis to avoid
blocking the request threads.
There is some opportunity for cleanup and consolidation of error handling in
ControllerApis, but I'd rather make a separate PR for that.
--
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]