Skip to content

Commit

Permalink
minor refactoring of AsyncAction
Browse files Browse the repository at this point in the history
Signed-off-by: Pranshu Shukla <[email protected]>
  • Loading branch information
Pranshu-S committed Jul 22, 2024
1 parent 9da507b commit 3f7bca1
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,20 +239,18 @@ class AsyncAction {
assert request.concreteNodes() != null;
}
this.responses = new AtomicReferenceArray<>(request.concreteNodes().length);
this.concreteNodes = request.concreteNodes();

if (request.sendDiscoveryNodes() == false) {
// We transfer the ownership of discovery nodes to route the request to into the AsyncAction class.
// This reduces the payload of the request and improves the number of concrete nodes in the memory
this.concreteNodes = request.concreteNodes();
// As we transfer the ownership of discovery nodes to route the request to into the AsyncAction class, we
// remove the list of DiscoveryNodes from the request. This reduces the payload of the request and improves
// the number of concrete nodes in the memory.
request.setConcreteNodes(null);
} else {
// initializing it separately as we keep the `concreteNodes` as final since we want it to be immutable.
this.concreteNodes = null;
}
}

void start() {
final DiscoveryNode[] nodes = request.concreteNodes() != null ? request.concreteNodes() : concreteNodes;
final DiscoveryNode[] nodes = this.concreteNodes;
if (nodes.length == 0) {
// nothing to notify
threadPool.generic().execute(() -> listener.onResponse(newResponse(request, responses)));
Expand Down

0 comments on commit 3f7bca1

Please sign in to comment.