-
Notifications
You must be signed in to change notification settings - Fork 24.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace custom Future implementations by CompletableFuture #32512
Conversation
Pinging @elastic/es-core-infra |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks awesome. I left minor comments.
} | ||
whenComplete((val, throwable) -> { | ||
if (throwable == null) { | ||
listener.onResponse(val); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
old code caught exceptions here and routed them to listener.onFailure()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
notifyListener(listener, EsExecutors.newDirectExecutorService()); | ||
whenCompleteAsync((val, throwable) -> { | ||
if (throwable == null) { | ||
listener.onResponse(val); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.