-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Add CountDownActionListener #92308
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
Add CountDownActionListener #92308
Conversation
It's very much like GroupedActionListener, but for when you don't care about the individual results at all.
It's a common enough calling pattern that it seems handy to add special support for it.
We don't want to allow too many invocations of the listener
So this is inspired by CountDown, but doesn't *use* CountDown. Crucially, this gives us the additional validation that you don't over-invoke the listener -- you get groupSize invocations, no more.
Pinging @elastic/es-core-infra (Team: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 reasonable to me, definitely nicer than accumulating an array of null
values in all those cases. Haven't looked in detail tho, but I left a suggestion.
server/src/main/java/org/elasticsearch/action/support/CountDownActionListener.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/action/support/CountDownActionListener.java
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/action/support/CountDownActionListener.java
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/action/support/CountDownActionListenerTests.java
Show resolved
Hide resolved
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.
LGTM! This looks pretty good to me. It handles nicely the case where we collect results in vain and the internal logic is pretty much what we have as proven in GroupedActionListener.
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.
LGTM
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.
LGTM3
It's very similar to
GroupedActionListener
-- it's basically a purpose-built class forGroupedActionListener<Void>
(that is, the existing uses ofGroupedActionListener
where the results tracking thatGroupedActionListener
provides is not actually useful).I originally used
CountDown
internally (hence the name), butCountDown
doesn't validate that you only call it at most N times, so I dropped the use ofCountDown
in favor of direct invocation counting and being able to do that additional validation.The part I'm least sure about is the application of this class to existing callers of
GroupedActionListener<Void>
-- I hunted them with search and replace, but given that there's additional validation thatCountDownActionListener
is doing it's possible that in some cases that is not actually correct.Note: I'm happy to back out any or all applications of this to existing code, this class is something I want with more-or-less these semantics for a soon-to-be-existing PR, so even with zero callers in the current codebase it will end up with a caller soon.
Adversarial reviews are most welcome, I really don't want to break anything, and I'm changing a lot of things that I'm not actually all that familiar with.