From 3f7bca13c2e618abe17a49e4960b91e376e3d12a Mon Sep 17 00:00:00 2001 From: Pranshu Shukla Date: Mon, 22 Jul 2024 09:47:09 +0530 Subject: [PATCH] minor refactoring of AsyncAction Signed-off-by: Pranshu Shukla --- .../action/support/nodes/TransportNodesAction.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/server/src/main/java/org/opensearch/action/support/nodes/TransportNodesAction.java b/server/src/main/java/org/opensearch/action/support/nodes/TransportNodesAction.java index 9188c67728f6e..8471b01c0bfce 100644 --- a/server/src/main/java/org/opensearch/action/support/nodes/TransportNodesAction.java +++ b/server/src/main/java/org/opensearch/action/support/nodes/TransportNodesAction.java @@ -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)));