Skip to content

Commit 2bd3e3d

Browse files
authored
Unset discovery nodes for every transport node actions request (#17682)
* Removed includeDiscoveryNodes from BaseNodesRequest Signed-off-by: Manik Garg <[email protected]>
1 parent f122c46 commit 2bd3e3d

20 files changed

+30
-71
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
## [Unreleased 3.x]
77
### Added
88
- Add multi-threaded writer support in pull-based ingestion ([#17912](https://github.com/opensearch-project/OpenSearch/pull/17912))
9+
- Unset discovery nodes for every transport node actions request ([#17682](https://github.com/opensearch-project/OpenSearch/pull/17682))
910
- Implement parallel shard refresh behind cluster settings ([#17782](https://github.com/opensearch-project/OpenSearch/pull/17782))
1011

1112
### Changed

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

Lines changed: 1 addition & 1 deletion
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(false, nodesIds);
73+
super(nodesIds);
7474
}
7575

7676
public int threads() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public NodesInfoRequest(StreamInput in) throws IOException {
7272
* for all nodes will be returned.
7373
*/
7474
public NodesInfoRequest(String... nodesIds) {
75-
super(false, nodesIds);
75+
super(nodesIds);
7676
defaultMetrics();
7777
}
7878

server/src/main/java/org/opensearch/action/admin/cluster/node/reload/NodesReloadSecureSettingsRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class NodesReloadSecureSettingsRequest extends BaseNodesRequest<NodesRelo
6060
private SecureString secureSettingsPassword;
6161

6262
public NodesReloadSecureSettingsRequest() {
63-
super(true, (String[]) null);
63+
super((String[]) null);
6464
}
6565

6666
public NodesReloadSecureSettingsRequest(StreamInput in) throws IOException {
@@ -84,7 +84,7 @@ public NodesReloadSecureSettingsRequest(StreamInput in) throws IOException {
8484
* nodes.
8585
*/
8686
public NodesReloadSecureSettingsRequest(String... nodesIds) {
87-
super(true, nodesIds);
87+
super(nodesIds);
8888
}
8989

9090
@Nullable

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class NodesStatsRequest extends BaseNodesRequest<NodesStatsRequest> {
5858
private final Set<String> requestedMetrics = new HashSet<>();
5959

6060
public NodesStatsRequest() {
61-
super(false, (String[]) null);
61+
super((String[]) null);
6262
}
6363

6464
public NodesStatsRequest(StreamInput in) throws IOException {
@@ -74,7 +74,7 @@ public NodesStatsRequest(StreamInput in) throws IOException {
7474
* for all nodes will be returned.
7575
*/
7676
public NodesStatsRequest(String... nodesIds) {
77-
super(false, nodesIds);
77+
super(nodesIds);
7878
}
7979

8080
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public NodesUsageRequest(StreamInput in) throws IOException {
6161
* passed, usage for all nodes will be returned.
6262
*/
6363
public NodesUsageRequest(String... nodesIds) {
64-
super(false, nodesIds);
64+
super(nodesIds);
6565
}
6666

6767
/**

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

Lines changed: 1 addition & 1 deletion
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(false, nodesIds);
164+
super(nodesIds);
165165
}
166166

167167
public Request snapshots(Snapshot[] snapshots) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public ClusterStatsRequest(StreamInput in) throws IOException {
8383
* based on all nodes will be returned.
8484
*/
8585
public ClusterStatsRequest(String... nodesIds) {
86-
super(false, nodesIds);
86+
super(nodesIds);
8787
}
8888

8989
public boolean useAggregatedNodeLevelResponses() {

server/src/main/java/org/opensearch/action/admin/cluster/wlm/WlmStatsRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ public WlmStatsRequest(StreamInput in) throws IOException {
3737
* for all nodes will be returned.
3838
*/
3939
public WlmStatsRequest(String[] nodesIds, Set<String> workloadGroupIds, Boolean breach) {
40-
super(false, nodesIds);
40+
super(nodesIds);
4141
this.workloadGroupIds = workloadGroupIds;
4242
this.breach = breach;
4343
}
4444

4545
public WlmStatsRequest() {
46-
super(false, (String[]) null);
46+
super((String[]) null);
4747
workloadGroupIds = new HashSet<>();
4848
this.breach = false;
4949
}

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

Lines changed: 1 addition & 1 deletion
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(false, Strings.EMPTY_ARRAY);
56+
super(Strings.EMPTY_ARRAY);
5757
this.indexUUID = indexUUID;
5858
}
5959

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

Lines changed: 2 additions & 2 deletions
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(false, Strings.EMPTY_ARRAY);
61+
super(Strings.EMPTY_ARRAY);
6262
this.indexUUID = null;
6363
}
6464

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

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

Lines changed: 1 addition & 1 deletion
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(false, concreteNodes);
30+
super(concreteNodes);
3131
}
3232

3333
public GetAllPitNodesRequest(StreamInput in) throws IOException {

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

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,12 @@ public abstract class BaseNodesRequest<Request extends BaseNodesRequest<Request>
6363
/**
6464
* once {@link #nodesIds} are resolved this will contain the concrete nodes that are part of this request. If set, {@link #nodesIds}
6565
* will be ignored and this will be used.
66-
* */
66+
* <p>
67+
* Note: concreteNodes when accessed by transport actions will be null.
68+
* See {@link TransportNodesAction.AsyncAction#AsyncAction}
69+
**/
6770
private DiscoveryNode[] concreteNodes;
6871

69-
/**
70-
* Since do not use the discovery nodes coming from the request in all code paths following a request extended off from
71-
* BaseNodeRequest, we do not require it to sent around across all nodes.
72-
*
73-
* Setting default behavior as `true` but can be explicitly changed in requests that do not require.
74-
*/
75-
private boolean includeDiscoveryNodes = true;
76-
7772
private final TimeValue DEFAULT_TIMEOUT_SECS = TimeValue.timeValueSeconds(30);
7873

7974
private TimeValue timeout;
@@ -89,22 +84,11 @@ protected BaseNodesRequest(String... nodesIds) {
8984
this.nodesIds = nodesIds;
9085
}
9186

92-
protected BaseNodesRequest(boolean includeDiscoveryNodes, String... nodesIds) {
93-
this.nodesIds = nodesIds;
94-
this.includeDiscoveryNodes = includeDiscoveryNodes;
95-
}
96-
9787
protected BaseNodesRequest(DiscoveryNode... concreteNodes) {
9888
this.nodesIds = null;
9989
this.concreteNodes = concreteNodes;
10090
}
10191

102-
protected BaseNodesRequest(boolean includeDiscoveryNodes, DiscoveryNode... concreteNodes) {
103-
this.nodesIds = null;
104-
this.concreteNodes = concreteNodes;
105-
this.includeDiscoveryNodes = includeDiscoveryNodes;
106-
}
107-
10892
public final String[] nodesIds() {
10993
return nodesIds;
11094
}
@@ -139,10 +123,6 @@ public void setConcreteNodes(DiscoveryNode[] concreteNodes) {
139123
this.concreteNodes = concreteNodes;
140124
}
141125

142-
public boolean getIncludeDiscoveryNodes() {
143-
return includeDiscoveryNodes;
144-
}
145-
146126
@Override
147127
public ActionRequestValidationException validate() {
148128
return null;

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,10 @@ class AsyncAction {
240240
}
241241
this.responses = new AtomicReferenceArray<>(request.concreteNodes().length);
242242
this.concreteNodes = request.concreteNodes();
243-
if (request.getIncludeDiscoveryNodes() == false) {
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
246-
// the number of concrete nodes in the memory.
247-
request.setConcreteNodes(null);
248-
}
243+
// As we transfer the ownership of discovery nodes to route the request to into the AsyncAction class,
244+
// we remove the list of DiscoveryNodes from the request. This reduces the payload of the request and improves
245+
// the number of concrete nodes in the memory.
246+
request.setConcreteNodes(null);
249247
}
250248

251249
void start() {

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

Lines changed: 1 addition & 1 deletion
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(false, nodesIds);
136+
super(nodesIds);
137137
}
138138
}
139139

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

Lines changed: 1 addition & 1 deletion
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(false, nodes);
200+
super(nodes);
201201
this.shardId = Objects.requireNonNull(shardId);
202202
this.customDataPath = Objects.requireNonNull(customDataPath);
203203
}

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

Lines changed: 1 addition & 1 deletion
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(false, nodes);
185+
super(nodes);
186186
this.shardAttributes = Objects.requireNonNull(shardAttributes);
187187
}
188188

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

Lines changed: 1 addition & 1 deletion
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(false, nodes);
179+
super(nodes);
180180
this.shardId = Objects.requireNonNull(shardId);
181181
this.customDataPath = Objects.requireNonNull(customDataPath);
182182
}

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

Lines changed: 1 addition & 1 deletion
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(false, nodes);
191+
super(nodes);
192192
this.shardAttributes = Objects.requireNonNull(shardAttributes);
193193
}
194194

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

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -168,25 +168,9 @@ public void testCustomResolving() throws Exception {
168168
assertEquals(clusterService.state().nodes().getDataNodes().size(), capturedRequests.size());
169169
}
170170

171-
public void testTransportNodesActionWithDiscoveryNodesIncluded() {
172-
String[] nodeIds = clusterService.state().nodes().getNodes().keySet().toArray(new String[0]);
173-
TestNodesRequest request = new TestNodesRequest(true, nodeIds);
174-
getTestTransportNodesAction().new AsyncAction(null, request, new PlainActionFuture<>()).start();
175-
Map<String, List<CapturingTransport.CapturedRequest>> capturedRequests = transport.getCapturedRequestsByTargetNodeAndClear();
176-
List<TestNodeRequest> capturedTransportNodeRequestList = capturedRequests.values()
177-
.stream()
178-
.flatMap(Collection::stream)
179-
.map(capturedRequest -> (TestNodeRequest) capturedRequest.request)
180-
.collect(Collectors.toList());
181-
assertEquals(nodeIds.length, capturedTransportNodeRequestList.size());
182-
capturedTransportNodeRequestList.forEach(
183-
capturedRequest -> assertEquals(nodeIds.length, capturedRequest.testNodesRequest.concreteNodes().length)
184-
);
185-
}
186-
187171
public void testTransportNodesActionWithDiscoveryNodesReset() {
188172
String[] nodeIds = clusterService.state().nodes().getNodes().keySet().toArray(new String[0]);
189-
TestNodesRequest request = new TestNodesRequest(false, nodeIds);
173+
TestNodesRequest request = new TestNodesRequest(nodeIds);
190174
getTestTransportNodesAction().new AsyncAction(null, request, new PlainActionFuture<>()).start();
191175
Map<String, List<CapturingTransport.CapturedRequest>> capturedRequests = transport.getCapturedRequestsByTargetNodeAndClear();
192176
List<TestNodeRequest> capturedTransportNodeRequestList = capturedRequests.values()
@@ -389,10 +373,6 @@ private static class TestNodesRequest extends BaseNodesRequest<TestNodesRequest>
389373
TestNodesRequest(String... nodesIds) {
390374
super(nodesIds);
391375
}
392-
393-
TestNodesRequest(boolean includeDiscoveryNodes, String... nodesIds) {
394-
super(includeDiscoveryNodes, nodesIds);
395-
}
396376
}
397377

398378
private static class TestNodesResponse extends BaseNodesResponse<TestNodeResponse> {

0 commit comments

Comments
 (0)