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

Refcount responses in TransportNodesAction #103254

Conversation

DaveCTurner
Copy link
Contributor

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.

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.
@DaveCTurner DaveCTurner added >non-issue :Distributed Indexing/Distributed A catch all label for anything in the Distributed Area. Please avoid if you can. v8.13.0 labels Dec 11, 2023
@elasticsearchmachine elasticsearchmachine added the Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. label Dec 11, 2023
@elasticsearchmachine
Copy link
Collaborator

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

@DaveCTurner

This comment was marked as resolved.

@DaveCTurner DaveCTurner marked this pull request as draft December 11, 2023 11:12
addReleaseOnCancellationListener();
}

private void addReleaseOnCancellationListener() {
Copy link
Contributor Author

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

@DaveCTurner DaveCTurner marked this pull request as ready for review December 12, 2023 08:54
Copy link
Contributor

@fcofdez fcofdez left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@arteam arteam left a 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);
Copy link
Contributor

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();
}

Copy link
Contributor Author

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.

@DaveCTurner
Copy link
Contributor Author

elasticsearch-ci/docs isn't working right now but it duplicates buildkite/docs-build-pr which has passed so I'm merging this.

@DaveCTurner DaveCTurner merged commit 6c13a81 into elastic:main Jan 2, 2024
@DaveCTurner DaveCTurner deleted the 2023/12/11/TransportNodesAction-response-refs branch January 2, 2024 13:38
DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Jan 3, 2024
Similarly to elastic#103254, we should `decRef` the top-level response after
completing the listener too.
elasticsearchmachine pushed a commit that referenced this pull request Jan 3, 2024
Similarly to #103254, we should `decRef` the top-level response after
completing the listener too.
@DaveCTurner DaveCTurner restored the 2023/12/11/TransportNodesAction-response-refs branch June 17, 2024 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Indexing/Distributed A catch all label for anything in the Distributed Area. Please avoid if you can. >non-issue Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants