Skip to content
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

Improve mechanism for extracting the result of a PlainActionFuture #110019

Conversation

nicktindall
Copy link
Contributor

@nicktindall nicktindall commented Jun 21, 2024

  • Provides consistent wrapping for exceptions when result() is called on a PlainActionFuture that completed exceptionally
    • Any time it completes exceptionally it throws new ExecutionException(cause)
  • Removes PlainActionFuture#actionResult() as it makes less sense with the consistent wrapping

Closes #108125

@elasticsearchmachine elasticsearchmachine added v8.15.0 needs:triage Requires assignment of a team area label labels Jun 21, 2024
return future.result();
} catch (ExecutionException e) {
throw new UncategorizedExecutionException("An error occurred fetching timestamp field type for " + index, e);
}
Copy link
Contributor Author

@nicktindall nicktindall Jun 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not quite the same as before, I believe previously, if there was a RuntimeException it would be thrown directly, and if there was a checked exception the behaviour would be consistent with the above. But looking up the call stack there doesn't appear to be any behaviour specific to the exception thrown. I'm happy to try and restore the original behaviour but fear it might just be adding noise to be consistent with something that nobody was depending on in the first place.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think this is ok, indeed possibly preferable, because now we get the call stack to the .result() call as well as the one which failed the future.

throw e;
}
}
}
Copy link
Contributor Author

@nicktindall nicktindall Jun 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this down the hierarchy as it's used to prevent excessive nesting of execution exceptions here, but this one is private.

@nicktindall nicktindall added :Distributed/Distributed A catch all label for anything in the Distributed Area. If you aren't sure, use this one. >tech debt labels Jun 21, 2024
@elasticsearchmachine
Copy link
Collaborator

Hi @nicktindall, I've created a changelog YAML for you.

@elasticsearchmachine elasticsearchmachine added Team:Distributed Meta label for distributed team and removed needs:triage Requires assignment of a team area label labels Jun 21, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

} catch (Exception e) {
return fail(e);
}
}
Copy link
Contributor Author

@nicktindall nicktindall Jun 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be controversial. As the javadoc suggests it's just to reduce boilerplate in places where we don't want checked exceptions to propagate, and we don't expect them to occur. There's something like this in JUnit 5.

Perhaps there's already a utility for this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I'd be inclined to call it safeGet since it's kinda doing the same thing as safeGet(Future<T>), getting a result and asserting that this succeeded.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

return future.result();
} catch (ExecutionException e) {
throw new UncategorizedExecutionException("An error occurred fetching timestamp field type for " + index, e);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think this is ok, indeed possibly preferable, because now we get the call stack to the .result() call as well as the one which failed the future.

@nicktindall nicktindall merged commit 7a8a7c0 into elastic:main Jul 4, 2024
15 checks passed
@nicktindall nicktindall deleted the enhancement/108125_improve_plainactionfuture_result branch July 4, 2024 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed/Distributed A catch all label for anything in the Distributed Area. If you aren't sure, use this one. >enhancement Team:Distributed Meta label for distributed team v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve mechanism for extracting the result of a PlainActionFuture
3 participants