Skip to content

Commit 7078b1b

Browse files
SwethaGupthaSwetha Guptha
and
Swetha Guptha
committed
Reset discovery nodes in most transport node actions request. (#15131)
Signed-off-by: Swetha Guptha <gupthasg@amazon.com> Co-authored-by: Swetha Guptha <gupthasg@amazon.com>
1 parent b408ef8 commit 7078b1b

25 files changed

+89
-113
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4545
- Add support for pluggable deciders for concurrent search ([#15363](https://github.com/opensearch-project/OpenSearch/pull/15363))
4646
- Add support for comma-separated list of index names to be used with Snapshot Status API ([#15409](https://github.com/opensearch-project/OpenSearch/pull/15409))[SnapshotV2] Snapshot Status API changes (#15409))
4747
- [Remote Publication] Added checksum validation for cluster state behind a cluster setting ([#15218](https://github.com/opensearch-project/OpenSearch/pull/15218))
48+
- Reset DiscoveryNodes in all transport node actions request ([#15131](https://github.com/opensearch-project/OpenSearch/pull/15131))
4849

4950
### Dependencies
5051
- Bump `netty` from 4.1.111.Final to 4.1.112.Final ([#15081](https://github.com/opensearch-project/OpenSearch/pull/15081))

server/src/main/java/org/opensearch/action/admin/cluster/node/hotthreads/NodesHotThreadsRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public NodesHotThreadsRequest(StreamInput in) throws IOException {
7070
* threads for all nodes is used.
7171
*/
7272
public NodesHotThreadsRequest(String... nodesIds) {
73-
super(nodesIds);
73+
super(false, nodesIds);
7474
}
7575

7676
public int threads() {

server/src/main/java/org/opensearch/action/admin/cluster/node/info/NodesInfoRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public NodesInfoRequest(StreamInput in) throws IOException {
8888
* for all nodes will be returned.
8989
*/
9090
public NodesInfoRequest(String... nodesIds) {
91-
super(nodesIds);
91+
super(false, nodesIds);
9292
all();
9393
}
9494

server/src/main/java/org/opensearch/action/admin/cluster/node/stats/NodesStatsRequest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class NodesStatsRequest extends BaseNodesRequest<NodesStatsRequest> {
5959
private final Set<String> requestedMetrics = new HashSet<>();
6060

6161
public NodesStatsRequest() {
62-
super((String[]) null);
62+
super(false, (String[]) null);
6363
}
6464

6565
public NodesStatsRequest(StreamInput in) throws IOException {
@@ -90,7 +90,7 @@ public NodesStatsRequest(StreamInput in) throws IOException {
9090
* for all nodes will be returned.
9191
*/
9292
public NodesStatsRequest(String... nodesIds) {
93-
super(nodesIds);
93+
super(false, nodesIds);
9494
}
9595

9696
/**

server/src/main/java/org/opensearch/action/admin/cluster/node/usage/NodesUsageRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public NodesUsageRequest(StreamInput in) throws IOException {
6464
* passed, usage for all nodes will be returned.
6565
*/
6666
public NodesUsageRequest(String... nodesIds) {
67-
super(nodesIds);
67+
super(false, nodesIds);
6868
}
6969

7070
/**

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportNodesSnapshotsStatus.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public Request(StreamInput in) throws IOException {
161161
}
162162

163163
public Request(String[] nodesIds) {
164-
super(nodesIds);
164+
super(false, nodesIds);
165165
}
166166

167167
public Request snapshots(Snapshot[] snapshots) {

server/src/main/java/org/opensearch/action/admin/cluster/stats/ClusterStatsRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public ClusterStatsRequest(StreamInput in) throws IOException {
6262
* based on all nodes will be returned.
6363
*/
6464
public ClusterStatsRequest(String... nodesIds) {
65-
super(nodesIds);
65+
super(false, nodesIds);
6666
}
6767

6868
public boolean useAggregatedNodeLevelResponses() {

server/src/main/java/org/opensearch/action/admin/indices/dangling/find/FindDanglingIndexRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public FindDanglingIndexRequest(StreamInput in) throws IOException {
5353
}
5454

5555
public FindDanglingIndexRequest(String indexUUID) {
56-
super(Strings.EMPTY_ARRAY);
56+
super(false, Strings.EMPTY_ARRAY);
5757
this.indexUUID = indexUUID;
5858
}
5959

server/src/main/java/org/opensearch/action/admin/indices/dangling/list/ListDanglingIndicesRequest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ public ListDanglingIndicesRequest(StreamInput in) throws IOException {
5858
}
5959

6060
public ListDanglingIndicesRequest() {
61-
super(Strings.EMPTY_ARRAY);
61+
super(false, Strings.EMPTY_ARRAY);
6262
this.indexUUID = null;
6363
}
6464

6565
public ListDanglingIndicesRequest(String indexUUID) {
66-
super(Strings.EMPTY_ARRAY);
66+
super(false, Strings.EMPTY_ARRAY);
6767
this.indexUUID = indexUUID;
6868
}
6969

server/src/main/java/org/opensearch/action/search/GetAllPitNodesRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class GetAllPitNodesRequest extends BaseNodesRequest<GetAllPitNodesReques
2727

2828
@Inject
2929
public GetAllPitNodesRequest(DiscoveryNode... concreteNodes) {
30-
super(concreteNodes);
30+
super(false, concreteNodes);
3131
}
3232

3333
public GetAllPitNodesRequest(StreamInput in) throws IOException {

server/src/main/java/org/opensearch/action/support/nodes/BaseNodesRequest.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public abstract class BaseNodesRequest<Request extends BaseNodesRequest<Request>
7373
* Setting default behavior as `true` but can be explicitly changed in requests that do not require.
7474
*/
7575
private boolean includeDiscoveryNodes = true;
76+
7677
private final TimeValue DEFAULT_TIMEOUT_SECS = TimeValue.timeValueSeconds(30);
7778

7879
private TimeValue timeout;
@@ -88,11 +89,22 @@ protected BaseNodesRequest(String... nodesIds) {
8889
this.nodesIds = nodesIds;
8990
}
9091

92+
protected BaseNodesRequest(boolean includeDiscoveryNodes, String... nodesIds) {
93+
this.nodesIds = nodesIds;
94+
this.includeDiscoveryNodes = includeDiscoveryNodes;
95+
}
96+
9197
protected BaseNodesRequest(DiscoveryNode... concreteNodes) {
9298
this.nodesIds = null;
9399
this.concreteNodes = concreteNodes;
94100
}
95101

102+
protected BaseNodesRequest(boolean includeDiscoveryNodes, DiscoveryNode... concreteNodes) {
103+
this.nodesIds = null;
104+
this.concreteNodes = concreteNodes;
105+
this.includeDiscoveryNodes = includeDiscoveryNodes;
106+
}
107+
96108
public final String[] nodesIds() {
97109
return nodesIds;
98110
}
@@ -127,10 +139,6 @@ public void setConcreteNodes(DiscoveryNode[] concreteNodes) {
127139
this.concreteNodes = concreteNodes;
128140
}
129141

130-
public void setIncludeDiscoveryNodes(boolean value) {
131-
includeDiscoveryNodes = value;
132-
}
133-
134142
public boolean getIncludeDiscoveryNodes() {
135143
return includeDiscoveryNodes;
136144
}

server/src/main/java/org/opensearch/action/support/nodes/TransportNodesAction.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -240,18 +240,16 @@ class AsyncAction {
240240
}
241241
this.responses = new AtomicReferenceArray<>(request.concreteNodes().length);
242242
this.concreteNodes = request.concreteNodes();
243-
244243
if (request.getIncludeDiscoveryNodes() == false) {
245-
// As we transfer the ownership of discovery nodes to route the request to into the AsyncAction class, we
246-
// remove the list of DiscoveryNodes from the request. This reduces the payload of the request and improves
244+
// As we transfer the ownership of discovery nodes to route the request to into the AsyncAction class,
245+
// we remove the list of DiscoveryNodes from the request. This reduces the payload of the request and improves
247246
// the number of concrete nodes in the memory.
248247
request.setConcreteNodes(null);
249248
}
250249
}
251250

252251
void start() {
253-
final DiscoveryNode[] nodes = this.concreteNodes;
254-
if (nodes.length == 0) {
252+
if (this.concreteNodes.length == 0) {
255253
// nothing to notify
256254
threadPool.generic().execute(() -> listener.onResponse(newResponse(request, responses)));
257255
return;
@@ -260,9 +258,9 @@ void start() {
260258
if (request.timeout() != null) {
261259
builder.withTimeout(request.timeout());
262260
}
263-
for (int i = 0; i < nodes.length; i++) {
261+
for (int i = 0; i < this.concreteNodes.length; i++) {
264262
final int idx = i;
265-
final DiscoveryNode node = nodes[i];
263+
final DiscoveryNode node = this.concreteNodes[i];
266264
final String nodeId = node.getId();
267265
try {
268266
TransportRequest nodeRequest = newNodeRequest(request);

server/src/main/java/org/opensearch/gateway/TransportNodesListGatewayMetaState.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public Request(StreamInput in) throws IOException {
133133
}
134134

135135
public Request(String... nodesIds) {
136-
super(nodesIds);
136+
super(false, nodesIds);
137137
}
138138
}
139139

server/src/main/java/org/opensearch/gateway/TransportNodesListGatewayStartedShards.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public Request(StreamInput in) throws IOException {
197197
}
198198

199199
public Request(ShardId shardId, String customDataPath, DiscoveryNode[] nodes) {
200-
super(nodes);
200+
super(false, nodes);
201201
this.shardId = Objects.requireNonNull(shardId);
202202
this.customDataPath = Objects.requireNonNull(customDataPath);
203203
}

server/src/main/java/org/opensearch/gateway/TransportNodesListGatewayStartedShardsBatch.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public Request(StreamInput in) throws IOException {
182182
}
183183

184184
public Request(DiscoveryNode[] nodes, Map<ShardId, ShardAttributes> shardAttributes) {
185-
super(nodes);
185+
super(false, nodes);
186186
this.shardAttributes = Objects.requireNonNull(shardAttributes);
187187
}
188188

server/src/main/java/org/opensearch/indices/store/TransportNodesListShardStoreMetadata.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public Request(StreamInput in) throws IOException {
176176
}
177177

178178
public Request(ShardId shardId, String customDataPath, DiscoveryNode[] nodes) {
179-
super(nodes);
179+
super(false, nodes);
180180
this.shardId = Objects.requireNonNull(shardId);
181181
this.customDataPath = Objects.requireNonNull(customDataPath);
182182
}

server/src/main/java/org/opensearch/indices/store/TransportNodesListShardStoreMetadataBatch.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public Request(StreamInput in) throws IOException {
188188
}
189189

190190
public Request(Map<ShardId, ShardAttributes> shardAttributes, DiscoveryNode[] nodes) {
191-
super(nodes);
191+
super(false, nodes);
192192
this.shardAttributes = Objects.requireNonNull(shardAttributes);
193193
}
194194

server/src/main/java/org/opensearch/rest/action/admin/cluster/RestClusterStatsAction.java

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public String getName() {
6666
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
6767
ClusterStatsRequest clusterStatsRequest = new ClusterStatsRequest().nodesIds(request.paramAsStringArray("nodeId", null));
6868
clusterStatsRequest.timeout(request.param("timeout"));
69-
clusterStatsRequest.setIncludeDiscoveryNodes(false);
7069
clusterStatsRequest.useAggregatedNodeLevelResponses(true);
7170
return channel -> client.admin().cluster().clusterStats(clusterStatsRequest, new NodesResponseRestListener<>(channel));
7271
}

server/src/main/java/org/opensearch/rest/action/admin/cluster/RestNodesInfoAction.java

-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
8888
final NodesInfoRequest nodesInfoRequest = prepareRequest(request);
8989
nodesInfoRequest.timeout(request.param("timeout"));
9090
settingsFilter.addFilterSettingParams(request);
91-
nodesInfoRequest.setIncludeDiscoveryNodes(false);
9291
return channel -> client.admin().cluster().nodesInfo(nodesInfoRequest, new NodesResponseRestListener<>(channel));
9392
}
9493

server/src/main/java/org/opensearch/rest/action/admin/cluster/RestNodesStatsAction.java

-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
232232
// If no levels are passed in this results in an empty array.
233233
String[] levels = Strings.splitStringByCommaToArray(request.param("level"));
234234
nodesStatsRequest.indices().setLevels(levels);
235-
nodesStatsRequest.setIncludeDiscoveryNodes(false);
236235

237236
return channel -> client.admin().cluster().nodesStats(nodesStatsRequest, new NodesResponseRestListener<>(channel));
238237
}

server/src/main/java/org/opensearch/rest/action/cat/RestNodesAction.java

-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ public RestChannelConsumer doCatRequest(final RestRequest request, final NodeCli
125125
public void processResponse(final ClusterStateResponse clusterStateResponse) {
126126
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
127127
nodesInfoRequest.timeout(request.param("timeout"));
128-
nodesInfoRequest.setIncludeDiscoveryNodes(false);
129128
nodesInfoRequest.clear()
130129
.addMetrics(
131130
NodesInfoRequest.Metric.JVM.metricName(),
@@ -138,7 +137,6 @@ public void processResponse(final ClusterStateResponse clusterStateResponse) {
138137
public void processResponse(final NodesInfoResponse nodesInfoResponse) {
139138
NodesStatsRequest nodesStatsRequest = new NodesStatsRequest();
140139
nodesStatsRequest.timeout(request.param("timeout"));
141-
nodesStatsRequest.setIncludeDiscoveryNodes(false);
142140
nodesStatsRequest.clear()
143141
.indices(true)
144142
.addMetrics(

server/src/test/java/org/opensearch/action/support/nodes/TransportClusterStatsActionTests.java

-37
Original file line numberDiff line numberDiff line change
@@ -33,48 +33,12 @@
3333

3434
public class TransportClusterStatsActionTests extends TransportNodesActionTests {
3535

36-
/**
37-
* By default, we send discovery nodes list to each request that is sent across from the coordinator node. This
38-
* behavior is asserted in this test.
39-
*/
40-
public void testClusterStatsActionWithRetentionOfDiscoveryNodesList() {
41-
ClusterStatsRequest request = new ClusterStatsRequest();
42-
request.setIncludeDiscoveryNodes(true);
43-
Map<String, List<MockClusterStatsNodeRequest>> combinedSentRequest = performNodesInfoAction(request);
44-
45-
assertNotNull(combinedSentRequest);
46-
combinedSentRequest.forEach((node, capturedRequestList) -> {
47-
assertNotNull(capturedRequestList);
48-
capturedRequestList.forEach(sentRequest -> {
49-
assertNotNull(sentRequest.getDiscoveryNodes());
50-
assertEquals(sentRequest.getDiscoveryNodes().length, clusterService.state().nodes().getSize());
51-
});
52-
});
53-
}
54-
55-
public void testClusterStatsActionWithPreFilledConcreteNodesAndWithRetentionOfDiscoveryNodesList() {
56-
ClusterStatsRequest request = new ClusterStatsRequest();
57-
Collection<DiscoveryNode> discoveryNodes = clusterService.state().getNodes().getNodes().values();
58-
request.setConcreteNodes(discoveryNodes.toArray(DiscoveryNode[]::new));
59-
Map<String, List<MockClusterStatsNodeRequest>> combinedSentRequest = performNodesInfoAction(request);
60-
61-
assertNotNull(combinedSentRequest);
62-
combinedSentRequest.forEach((node, capturedRequestList) -> {
63-
assertNotNull(capturedRequestList);
64-
capturedRequestList.forEach(sentRequest -> {
65-
assertNotNull(sentRequest.getDiscoveryNodes());
66-
assertEquals(sentRequest.getDiscoveryNodes().length, clusterService.state().nodes().getSize());
67-
});
68-
});
69-
}
70-
7136
/**
7237
* In the optimized ClusterStats Request, we do not send the DiscoveryNodes List to each node. This behavior is
7338
* asserted in this test.
7439
*/
7540
public void testClusterStatsActionWithoutRetentionOfDiscoveryNodesList() {
7641
ClusterStatsRequest request = new ClusterStatsRequest();
77-
request.setIncludeDiscoveryNodes(false);
7842
Map<String, List<MockClusterStatsNodeRequest>> combinedSentRequest = performNodesInfoAction(request);
7943

8044
assertNotNull(combinedSentRequest);
@@ -88,7 +52,6 @@ public void testClusterStatsActionWithPreFilledConcreteNodesAndWithoutRetentionO
8852
ClusterStatsRequest request = new ClusterStatsRequest();
8953
Collection<DiscoveryNode> discoveryNodes = clusterService.state().getNodes().getNodes().values();
9054
request.setConcreteNodes(discoveryNodes.toArray(DiscoveryNode[]::new));
91-
request.setIncludeDiscoveryNodes(false);
9255
Map<String, List<MockClusterStatsNodeRequest>> combinedSentRequest = performNodesInfoAction(request);
9356

9457
assertNotNull(combinedSentRequest);

0 commit comments

Comments
 (0)