-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Refcount responses in TransportNodesAction
#103254
Refcount responses in TransportNodesAction
#103254
Conversation
Today we `decRef()` the per-node responses just after adding them to the `responses` collection, but in fact we should keep them alive until we've constructed the final response. This commit does that.
Pinging @elastic/es-distributed (Team:Distributed) |
This comment was marked as resolved.
This comment was marked as resolved.
addReleaseOnCancellationListener(); | ||
} | ||
|
||
private void addReleaseOnCancellationListener() { |
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.
Incredibly if you write this inline in the anonymous constructor then the compiler blows up with a NPE: https://gradle-enterprise.elastic.co/s/pp3aym5qktpa2
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.
LGTM
cancellableTask.addListener(() -> { | ||
final List<NodeResponse> drainedResponses; | ||
synchronized (responses) { | ||
drainedResponses = List.copyOf(responses); |
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.
I was wondering if could add copy and remove elements in one iteration:
var iterator = responses.iterator();
while (iterator.hasNext()) {
drainedResponses.add(iterator.next());
iterator.remove();
}
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.
You can, but adding elements one-by-one to a list potentially involves more allocations to grow the list incrementally, and removing items from a list iterator one-by-one is an O(N²) operation.
|
Similarly to elastic#103254, we should `decRef` the top-level response after completing the listener too.
Similarly to #103254, we should `decRef` the top-level response after completing the listener too.
Today we
decRef()
the per-node responses just after adding them to theresponses
collection, but in fact we should keep them alive untilwe've constructed the final response. This commit does that.