Skip to content

Commit 65127cf

Browse files
authored
Merge branch 'main' into split-response-processor
Signed-off-by: Daniel Widdis <[email protected]>
2 parents f20efd4 + 0040f4b commit 65127cf

30 files changed

+1297
-685
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2222
- Refactor remote-routing-table service inline with remote state interfaces([#14668](https://github.com/opensearch-project/OpenSearch/pull/14668))
2323
- Add prefix mode verification setting for repository verification (([#14790](https://github.com/opensearch-project/OpenSearch/pull/14790)))
2424
- Add SplitResponseProcessor to Search Pipelines (([#14800](https://github.com/opensearch-project/OpenSearch/issues/14800)))
25+
- Optimize TransportNodesAction to not send DiscoveryNodes for NodeStats, NodesInfo and ClusterStats call ([14749](https://github.com/opensearch-project/OpenSearch/pull/14749))
2526

2627
### Dependencies
2728
- Bump `org.gradle.test-retry` from 1.5.8 to 1.5.9 ([#13442](https://github.com/opensearch-project/OpenSearch/pull/13442))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ protected NodeInfo nodeOperation(NodeInfoRequest nodeRequest) {
129129
*/
130130
public static class NodeInfoRequest extends TransportRequest {
131131

132-
NodesInfoRequest request;
132+
protected NodesInfoRequest request;
133133

134134
public NodeInfoRequest(StreamInput in) throws IOException {
135135
super(in);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ protected NodeStats nodeOperation(NodeStatsRequest nodeStatsRequest) {
140140
*/
141141
public static class NodeStatsRequest extends TransportRequest {
142142

143-
NodesStatsRequest request;
143+
protected NodesStatsRequest request;
144144

145145
public NodeStatsRequest(StreamInput in) throws IOException {
146146
super(in);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ protected ClusterStatsNodeResponse nodeOperation(ClusterStatsNodeRequest nodeReq
223223
*/
224224
public static class ClusterStatsNodeRequest extends TransportRequest {
225225

226-
ClusterStatsRequest request;
226+
protected ClusterStatsRequest request;
227227

228228
public ClusterStatsNodeRequest(StreamInput in) throws IOException {
229229
super(in);

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ public abstract class BaseNodesRequest<Request extends BaseNodesRequest<Request>
6565
* will be ignored and this will be used.
6666
* */
6767
private DiscoveryNode[] concreteNodes;
68+
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;
6876
private final TimeValue DEFAULT_TIMEOUT_SECS = TimeValue.timeValueSeconds(30);
6977

7078
private TimeValue timeout;
@@ -119,6 +127,14 @@ public void setConcreteNodes(DiscoveryNode[] concreteNodes) {
119127
this.concreteNodes = concreteNodes;
120128
}
121129

130+
public void setIncludeDiscoveryNodes(boolean value) {
131+
includeDiscoveryNodes = value;
132+
}
133+
134+
public boolean getIncludeDiscoveryNodes() {
135+
return includeDiscoveryNodes;
136+
}
137+
122138
@Override
123139
public ActionRequestValidationException validate() {
124140
return null;

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ class AsyncAction {
226226
private final NodesRequest request;
227227
private final ActionListener<NodesResponse> listener;
228228
private final AtomicReferenceArray<Object> responses;
229+
private final DiscoveryNode[] concreteNodes;
229230
private final AtomicInteger counter = new AtomicInteger();
230231
private final Task task;
231232

@@ -238,10 +239,18 @@ class AsyncAction {
238239
assert request.concreteNodes() != null;
239240
}
240241
this.responses = new AtomicReferenceArray<>(request.concreteNodes().length);
242+
this.concreteNodes = request.concreteNodes();
243+
244+
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
247+
// the number of concrete nodes in the memory.
248+
request.setConcreteNodes(null);
249+
}
241250
}
242251

243252
void start() {
244-
final DiscoveryNode[] nodes = request.concreteNodes();
253+
final DiscoveryNode[] nodes = this.concreteNodes;
245254
if (nodes.length == 0) {
246255
// nothing to notify
247256
threadPool.generic().execute(() -> listener.onResponse(newResponse(request, responses)));
@@ -260,7 +269,6 @@ void start() {
260269
if (task != null) {
261270
nodeRequest.setParentTask(clusterService.localNode().getId(), task.getId());
262271
}
263-
264272
transportService.sendRequest(
265273
node,
266274
getTransportNodeAction(node),

server/src/main/java/org/opensearch/cluster/routing/remote/InternalRemoteRoutingTableService.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.opensearch.cluster.DiffableUtils;
1616
import org.opensearch.cluster.routing.IndexRoutingTable;
1717
import org.opensearch.cluster.routing.RoutingTable;
18-
import org.opensearch.common.CheckedRunnable;
1918
import org.opensearch.common.blobstore.BlobPath;
2019
import org.opensearch.common.lifecycle.AbstractLifecycleComponent;
2120
import org.opensearch.common.remote.RemoteWritableEntityStore;
@@ -102,16 +101,16 @@ public DiffableUtils.MapDiff<String, IndexRoutingTable, Map<String, IndexRouting
102101
}
103102

104103
/**
105-
* Create async action for writing one {@code IndexRoutingTable} to remote store
104+
* Async action for writing one {@code IndexRoutingTable} to remote store
105+
*
106106
* @param term current term
107107
* @param version current version
108108
* @param clusterUUID current cluster UUID
109109
* @param indexRouting indexRoutingTable to write to remote store
110110
* @param latchedActionListener listener for handling async action response
111-
* @return returns runnable async action
112111
*/
113112
@Override
114-
public CheckedRunnable<IOException> getAsyncIndexRoutingWriteAction(
113+
public void getAsyncIndexRoutingWriteAction(
115114
String clusterUUID,
116115
long term,
117116
long version,
@@ -128,7 +127,7 @@ public CheckedRunnable<IOException> getAsyncIndexRoutingWriteAction(
128127
)
129128
);
130129

131-
return () -> remoteIndexRoutingTableStore.writeAsync(remoteIndexRoutingTable, completionListener);
130+
remoteIndexRoutingTableStore.writeAsync(remoteIndexRoutingTable, completionListener);
132131
}
133132

134133
/**
@@ -156,7 +155,7 @@ public List<ClusterMetadataManifest.UploadedIndexMetadata> getAllUploadedIndices
156155
}
157156

158157
@Override
159-
public CheckedRunnable<IOException> getAsyncIndexRoutingReadAction(
158+
public void getAsyncIndexRoutingReadAction(
160159
String clusterUUID,
161160
String uploadedFilename,
162161
LatchedActionListener<IndexRoutingTable> latchedActionListener
@@ -169,7 +168,7 @@ public CheckedRunnable<IOException> getAsyncIndexRoutingReadAction(
169168

170169
RemoteIndexRoutingTable remoteIndexRoutingTable = new RemoteIndexRoutingTable(uploadedFilename, clusterUUID, compressor);
171170

172-
return () -> remoteIndexRoutingTableStore.readAsync(remoteIndexRoutingTable, actionListener);
171+
remoteIndexRoutingTableStore.readAsync(remoteIndexRoutingTable, actionListener);
173172
}
174173

175174
@Override

server/src/main/java/org/opensearch/cluster/routing/remote/NoopRemoteRoutingTableService.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.opensearch.cluster.DiffableUtils;
1313
import org.opensearch.cluster.routing.IndexRoutingTable;
1414
import org.opensearch.cluster.routing.RoutingTable;
15-
import org.opensearch.common.CheckedRunnable;
1615
import org.opensearch.common.lifecycle.AbstractLifecycleComponent;
1716
import org.opensearch.gateway.remote.ClusterMetadataManifest;
1817

@@ -39,15 +38,14 @@ public DiffableUtils.MapDiff<String, IndexRoutingTable, Map<String, IndexRouting
3938
}
4039

4140
@Override
42-
public CheckedRunnable<IOException> getAsyncIndexRoutingWriteAction(
41+
public void getAsyncIndexRoutingWriteAction(
4342
String clusterUUID,
4443
long term,
4544
long version,
4645
IndexRoutingTable indexRouting,
4746
LatchedActionListener<ClusterMetadataManifest.UploadedMetadata> latchedActionListener
4847
) {
4948
// noop
50-
return () -> {};
5149
}
5250

5351
@Override
@@ -61,13 +59,12 @@ public List<ClusterMetadataManifest.UploadedIndexMetadata> getAllUploadedIndices
6159
}
6260

6361
@Override
64-
public CheckedRunnable<IOException> getAsyncIndexRoutingReadAction(
62+
public void getAsyncIndexRoutingReadAction(
6563
String clusterUUID,
6664
String uploadedFilename,
6765
LatchedActionListener<IndexRoutingTable> latchedActionListener
6866
) {
6967
// noop
70-
return () -> {};
7168
}
7269

7370
@Override

server/src/main/java/org/opensearch/cluster/routing/remote/RemoteRoutingTableService.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.opensearch.cluster.DiffableUtils;
1313
import org.opensearch.cluster.routing.IndexRoutingTable;
1414
import org.opensearch.cluster.routing.RoutingTable;
15-
import org.opensearch.common.CheckedRunnable;
1615
import org.opensearch.common.lifecycle.LifecycleComponent;
1716
import org.opensearch.core.common.io.stream.StreamInput;
1817
import org.opensearch.core.common.io.stream.StreamOutput;
@@ -43,7 +42,7 @@ public IndexRoutingTable read(StreamInput in, String key) throws IOException {
4342

4443
List<IndexRoutingTable> getIndicesRouting(RoutingTable routingTable);
4544

46-
CheckedRunnable<IOException> getAsyncIndexRoutingReadAction(
45+
void getAsyncIndexRoutingReadAction(
4746
String clusterUUID,
4847
String uploadedFilename,
4948
LatchedActionListener<IndexRoutingTable> latchedActionListener
@@ -59,7 +58,7 @@ DiffableUtils.MapDiff<String, IndexRoutingTable, Map<String, IndexRoutingTable>>
5958
RoutingTable after
6059
);
6160

62-
CheckedRunnable<IOException> getAsyncIndexRoutingWriteAction(
61+
void getAsyncIndexRoutingWriteAction(
6362
String clusterUUID,
6463
long term,
6564
long version,
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.common.remote;
10+
11+
import org.opensearch.core.action.ActionListener;
12+
import org.opensearch.gateway.remote.ClusterMetadataManifest;
13+
import org.opensearch.gateway.remote.model.RemoteReadResult;
14+
15+
import java.util.HashMap;
16+
import java.util.Map;
17+
18+
/**
19+
* An abstract class that provides a base implementation for managing remote entities in the remote store.
20+
*/
21+
public abstract class AbstractRemoteWritableEntityManager implements RemoteWritableEntityManager {
22+
/**
23+
* A map that stores the remote writable entity stores, keyed by the entity type.
24+
*/
25+
protected final Map<String, RemoteWritableEntityStore> remoteWritableEntityStores = new HashMap<>();
26+
27+
/**
28+
* Retrieves the remote writable entity store for the given entity.
29+
*
30+
* @param entity the entity for which the store is requested
31+
* @return the remote writable entity store for the given entity
32+
* @throws IllegalArgumentException if the entity type is unknown
33+
*/
34+
protected RemoteWritableEntityStore getStore(AbstractRemoteWritableBlobEntity entity) {
35+
RemoteWritableEntityStore remoteStore = remoteWritableEntityStores.get(entity.getType());
36+
if (remoteStore == null) {
37+
throw new IllegalArgumentException("Unknown entity type [" + entity.getType() + "]");
38+
}
39+
return remoteStore;
40+
}
41+
42+
/**
43+
* Returns an ActionListener for handling the write operation for the specified component, remote object, and latched action listener.
44+
*
45+
* @param component the component for which the write operation is performed
46+
* @param remoteEntity the remote object to be written
47+
* @param listener the listener to be notified when the write operation completes
48+
* @return an ActionListener for handling the write operation
49+
*/
50+
protected abstract ActionListener<Void> getWrappedWriteListener(
51+
String component,
52+
AbstractRemoteWritableBlobEntity remoteEntity,
53+
ActionListener<ClusterMetadataManifest.UploadedMetadata> listener
54+
);
55+
56+
/**
57+
* Returns an ActionListener for handling the read operation for the specified component,
58+
* remote object, and latched action listener.
59+
*
60+
* @param component the component for which the read operation is performed
61+
* @param remoteEntity the remote object to be read
62+
* @param listener the listener to be notified when the read operation completes
63+
* @return an ActionListener for handling the read operation
64+
*/
65+
protected abstract ActionListener<Object> getWrappedReadListener(
66+
String component,
67+
AbstractRemoteWritableBlobEntity remoteEntity,
68+
ActionListener<RemoteReadResult> listener
69+
);
70+
71+
@Override
72+
public void writeAsync(
73+
String component,
74+
AbstractRemoteWritableBlobEntity entity,
75+
ActionListener<ClusterMetadataManifest.UploadedMetadata> listener
76+
) {
77+
getStore(entity).writeAsync(entity, getWrappedWriteListener(component, entity, listener));
78+
}
79+
80+
@Override
81+
public void readAsync(String component, AbstractRemoteWritableBlobEntity entity, ActionListener<RemoteReadResult> listener) {
82+
getStore(entity).readAsync(entity, getWrappedReadListener(component, entity, listener));
83+
}
84+
}

0 commit comments

Comments
 (0)