Replace custom Future implementations by CompletableFuture#32512
Replace custom Future implementations by CompletableFuture#32512ywelsch wants to merge 20 commits intoelastic:mainfrom
Conversation
|
Pinging @elastic/es-core-infra |
bleskes
left a comment
There was a problem hiding this comment.
Looks awesome. I left minor comments.
| } | ||
| whenComplete((val, throwable) -> { | ||
| if (throwable == null) { | ||
| listener.onResponse(val); |
There was a problem hiding this comment.
old code caught exceptions here and routed them to listener.onFailure()
There was a problem hiding this comment.
Good catch. I'm not a fan of having this anti-pattern in library code but I'm still making this change for BWC purposes. In the future (pun intended) we can also think about adding these methods directly to BaseFuture as every Future has now listening capabilities.
| ClusterApplierService.assertNotClusterStateUpdateThread(BLOCKING_OP_REASON) && | ||
| MasterService.assertNotMasterUpdateThread(BLOCKING_OP_REASON)); | ||
| return sync.get(unit.toNanos(timeout)); | ||
| assert timeout <= 0 || blockingAllowed(); |
| notifyListener(listener, EsExecutors.newDirectExecutorService()); | ||
| whenCompleteAsync((val, throwable) -> { | ||
| if (throwable == null) { | ||
| listener.onResponse(val); |
There was a problem hiding this comment.
same comment about exception handling.
|
I have a comment. This is similar to work I did in That assertion is swallowed and never seen again. This is because when the listener is executed, I had not decided how I was going to fix that issue. But I was thinking of wrapping attached listeners, catching I just thought I would mention that here as I assume it will impact this work and it was causing me issues for assertions to disappear. |
|
Note that we handled a similar problem in #28667. |
|
The recent updates seem like they will work. The only downside seems to be that all the |
|
I have reworked this PR so that the CompletableFutures now properly bubble up Errors to the uncaught exception handler.
yes, but only if they make use of the methods on CompletionStage that require to do so. We can also provide convenient alternatives on BaseFuture if need be. As follow-ups, I would like to:
|
|
Hi @ywelsch, I've created a changelog YAML for you. |
|
Pinging @elastic/es-core-infra (Team:Core/Infra) |
This PR replaces our custom future implementations by Java 8's
CompletableFuture, which results in less custom code to maintain (see PR stats), and enables the use of more powerful async programming features across our codebase. Furthermore, it fixes an issue withCompletableFuture, where it's not properly bubbling up Errors to the uncaught exception handler.