Skip to content

Commit

Permalink
TransportNodesAction impls are local-only
Browse files Browse the repository at this point in the history
There are no remote invocations of any actions derived from
`TransportNodesAction` so there is no need to register the top-level
action with the `TransportService`, and that means that all the code
related to de/serialization of the top-level request and response is
unused and can be removed.

Relates #100111
Relates #100878
  • Loading branch information
DaveCTurner committed Oct 16, 2023
1 parent cb18463 commit 3292322
Show file tree
Hide file tree
Showing 110 changed files with 336 additions and 817 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.elasticsearch.TransportVersions;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.FailedNodeException;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.action.support.nodes.BaseNodeResponse;
import org.elasticsearch.action.support.nodes.BaseNodesRequest;
import org.elasticsearch.action.support.nodes.BaseNodesResponse;
Expand Down Expand Up @@ -44,10 +45,6 @@ public Request() {
super((String[]) null);
}

public Request(StreamInput in) throws IOException {
super(in);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
Expand All @@ -71,16 +68,19 @@ public boolean equals(Object obj) {
}
return true;
}

@Override
public void writeTo(StreamOutput out) {
TransportAction.localOnly();
}
}

public static class NodeRequest extends TransportRequest {
public NodeRequest(StreamInput in) throws IOException {
super(in);
}

public NodeRequest(Request request) {

}
public NodeRequest() {}
}

public static class Response extends BaseNodesResponse<NodeResponse> implements Writeable, ToXContentObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ public GeoIpDownloaderStatsTransportAction(
) {
super(
GeoIpDownloaderStatsAction.NAME,
threadPool,
clusterService,
transportService,
actionFilters,
Request::new,
NodeRequest::new,
threadPool.executor(ThreadPool.Names.MANAGEMENT)
);
Expand All @@ -66,7 +64,7 @@ protected Response newResponse(Request request, List<NodeResponse> nodeResponses

@Override
protected NodeRequest newNodeRequest(Request request) {
return new NodeRequest(request);
return new NodeRequest();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
package org.elasticsearch.action.admin.cluster.node.hotthreads;

import org.elasticsearch.action.ActionType;
import org.elasticsearch.common.io.stream.Writeable;

public class NodesHotThreadsAction extends ActionType<NodesHotThreadsResponse> {

public static final NodesHotThreadsAction INSTANCE = new NodesHotThreadsAction();
public static final String NAME = "cluster:monitor/nodes/hot_threads";

private NodesHotThreadsAction() {
super(NAME, NodesHotThreadsResponse::new);
super(NAME, Writeable.Reader.localOnly());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.elasticsearch.action.admin.cluster.node.hotthreads;

import org.elasticsearch.action.FailedNodeException;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.action.support.nodes.BaseNodesResponse;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.common.collect.Iterators;
Expand All @@ -26,10 +27,6 @@

public class NodesHotThreadsResponse extends BaseNodesResponse<NodeHotThreads> {

public NodesHotThreadsResponse(StreamInput in) throws IOException {
super(in);
}

public NodesHotThreadsResponse(ClusterName clusterName, List<NodeHotThreads> nodes, List<FailedNodeException> failures) {
super(clusterName, nodes, failures);
}
Expand All @@ -52,7 +49,7 @@ protected List<NodeHotThreads> readNodesFrom(StreamInput in) throws IOException

@Override
protected void writeNodesTo(StreamOutput out, List<NodeHotThreads> nodes) throws IOException {
out.writeCollection(nodes);
TransportAction.localOnly();
}

private static class LinesIterator implements Iterator<String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ public TransportNodesHotThreadsAction(
) {
super(
NodesHotThreadsAction.NAME,
threadPool,
clusterService,
transportService,
actionFilters,
NodesHotThreadsRequest::new,
NodeRequest::new,
threadPool.executor(ThreadPool.Names.GENERIC)
);
Expand Down Expand Up @@ -87,6 +85,7 @@ protected NodeHotThreads nodeOperation(NodeRequest request, Task task) {

public static class NodeRequest extends TransportRequest {

// TODO don't wrap the whole top-level request, it contains heavy and irrelevant DiscoveryNode things; see #100878
NodesHotThreadsRequest request;

public NodeRequest(StreamInput in) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
package org.elasticsearch.action.admin.cluster.node.info;

import org.elasticsearch.action.ActionType;
import org.elasticsearch.common.io.stream.Writeable;

public class NodesInfoAction extends ActionType<NodesInfoResponse> {

public static final NodesInfoAction INSTANCE = new NodesInfoAction();
public static final String NAME = "cluster:monitor/nodes/info";

private NodesInfoAction() {
super(NAME, NodesInfoResponse::new);
super(NAME, Writeable.Reader.localOnly());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
public class NodesInfoRequest extends BaseNodesRequest<NodesInfoRequest> {

private NodesInfoMetrics nodesInfoMetrics;
private final NodesInfoMetrics nodesInfoMetrics;

/**
* Create a new NodeInfoRequest from a {@link StreamInput} object.
Expand Down Expand Up @@ -118,20 +118,6 @@ public void writeTo(StreamOutput out) throws IOException {
nodesInfoMetrics.writeTo(out);
}

/**
* Helper method for creating NodesInfoRequests with desired metrics
* @param metrics the metrics to include in the request
* @return
*/
public static NodesInfoRequest requestWithMetrics(NodesInfoMetrics.Metric... metrics) {
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
nodesInfoRequest.clear();
for (var metric : metrics) {
nodesInfoRequest.addMetric(metric.metricName());
}
return nodesInfoRequest;
}

public NodesInfoMetrics getNodesInfoMetrics() {
return nodesInfoMetrics;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.elasticsearch.action.admin.cluster.node.info;

import org.elasticsearch.action.FailedNodeException;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.action.support.nodes.BaseNodesResponse;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.node.DiscoveryNodeRole;
Expand All @@ -34,22 +35,18 @@

public class NodesInfoResponse extends BaseNodesResponse<NodeInfo> implements ToXContentFragment {

public NodesInfoResponse(StreamInput in) throws IOException {
super(in);
}

public NodesInfoResponse(ClusterName clusterName, List<NodeInfo> nodes, List<FailedNodeException> failures) {
super(clusterName, nodes, failures);
}

@Override
protected List<NodeInfo> readNodesFrom(StreamInput in) throws IOException {
return in.readCollectionAsList(NodeInfo::new);
return TransportAction.localOnly();
}

@Override
protected void writeNodesTo(StreamOutput out, List<NodeInfo> nodes) throws IOException {
out.writeCollection(nodes);
TransportAction.localOnly();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ public TransportNodesInfoAction(
) {
super(
NodesInfoAction.NAME,
threadPool,
clusterService,
transportService,
actionFilters,
NodesInfoRequest::new,
NodeInfoRequest::new,
threadPool.executor(ThreadPool.Names.MANAGEMENT)
);
Expand Down Expand Up @@ -97,7 +95,7 @@ protected NodeInfo nodeOperation(NodeInfoRequest nodeRequest, Task task) {

public static class NodeInfoRequest extends TransportRequest {

private NodesInfoMetrics nodesInfoMetrics;
private final NodesInfoMetrics nodesInfoMetrics;

public NodeInfoRequest(StreamInput in) throws IOException {
super(in);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
package org.elasticsearch.action.admin.cluster.node.reload;

import org.elasticsearch.action.ActionType;
import org.elasticsearch.common.io.stream.Writeable;

public class NodesReloadSecureSettingsAction extends ActionType<NodesReloadSecureSettingsResponse> {

public static final NodesReloadSecureSettingsAction INSTANCE = new NodesReloadSecureSettingsAction();
public static final String NAME = "cluster:admin/nodes/reload_secure_settings";

private NodesReloadSecureSettingsAction() {
super(NAME, NodesReloadSecureSettingsResponse::new);
super(NAME, Writeable.Reader.localOnly());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public void close() {
}

public static class NodeRequest extends TransportRequest implements Releasable {

// TODO don't wrap the whole top-level request, it contains heavy and irrelevant DiscoveryNode things; see #100878
NodesReloadSecureSettingsRequest request;

NodeRequest(StreamInput in) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.FailedNodeException;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.action.support.nodes.BaseNodeResponse;
import org.elasticsearch.action.support.nodes.BaseNodesResponse;
import org.elasticsearch.cluster.ClusterName;
Expand All @@ -30,22 +31,18 @@ public class NodesReloadSecureSettingsResponse extends BaseNodesResponse<NodesRe
implements
ToXContentFragment {

public NodesReloadSecureSettingsResponse(StreamInput in) throws IOException {
super(in);
}

public NodesReloadSecureSettingsResponse(ClusterName clusterName, List<NodeResponse> nodes, List<FailedNodeException> failures) {
super(clusterName, nodes, failures);
}

@Override
protected List<NodesReloadSecureSettingsResponse.NodeResponse> readNodesFrom(StreamInput in) throws IOException {
return in.readCollectionAsList(NodeResponse::new);
return TransportAction.localOnly();
}

@Override
protected void writeNodesTo(StreamOutput out, List<NodesReloadSecureSettingsResponse.NodeResponse> nodes) throws IOException {
out.writeCollection(nodes);
TransportAction.localOnly();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,9 @@ public TransportNodesReloadSecureSettingsAction(
) {
super(
NodesReloadSecureSettingsAction.NAME,
threadPool,
clusterService,
transportService,
actionFilters,
NodesReloadSecureSettingsRequest::new,
NodesReloadSecureSettingsRequest.NodeRequest::new,
threadPool.executor(ThreadPool.Names.GENERIC)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

package org.elasticsearch.action.admin.cluster.node.shutdown;

import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.action.support.nodes.BaseNodesRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.index.shard.ShardId;

Expand All @@ -27,15 +27,10 @@ public PrevalidateShardPathRequest(Set<ShardId> shardIds, String... nodeIds) {
this.shardIds = Set.copyOf(Objects.requireNonNull(shardIds));
}

public PrevalidateShardPathRequest(StreamInput in) throws IOException {
super(in);
this.shardIds = in.readCollectionAsImmutableSet(ShardId::new);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeCollection(shardIds);
TransportAction.localOnly();
}

public Set<ShardId> getShardIds() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.elasticsearch.action.admin.cluster.node.shutdown;

import org.elasticsearch.action.FailedNodeException;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.action.support.nodes.BaseNodesResponse;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.common.io.stream.StreamInput;
Expand All @@ -27,17 +28,13 @@ public PrevalidateShardPathResponse(
super(clusterName, nodes, failures);
}

public PrevalidateShardPathResponse(StreamInput in) throws IOException {
super(in);
}

@Override
protected List<NodePrevalidateShardPathResponse> readNodesFrom(StreamInput in) throws IOException {
return in.readCollectionAsList(NodePrevalidateShardPathResponse::new);
return TransportAction.localOnly();
}

@Override
protected void writeNodesTo(StreamOutput out, List<NodePrevalidateShardPathResponse> nodes) throws IOException {
out.writeCollection(nodes);
TransportAction.localOnly();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.index.IndexSettings;
Expand Down Expand Up @@ -46,7 +47,7 @@ public class TransportPrevalidateShardPathAction extends TransportNodesAction<
NodePrevalidateShardPathResponse> {

public static final String ACTION_NAME = "internal:admin/indices/prevalidate_shard_path";
public static final ActionType<PrevalidateShardPathResponse> TYPE = new ActionType<>(ACTION_NAME, PrevalidateShardPathResponse::new);
public static final ActionType<PrevalidateShardPathResponse> TYPE = new ActionType<>(ACTION_NAME, Writeable.Reader.localOnly());
private static final Logger logger = LogManager.getLogger(TransportPrevalidateShardPathAction.class);

private final TransportService transportService;
Expand All @@ -64,11 +65,9 @@ public TransportPrevalidateShardPathAction(
) {
super(
ACTION_NAME,
threadPool,
clusterService,
transportService,
actionFilters,
PrevalidateShardPathRequest::new,
NodePrevalidateShardPathRequest::new,
threadPool.executor(ThreadPool.Names.MANAGEMENT)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
package org.elasticsearch.action.admin.cluster.node.stats;

import org.elasticsearch.action.ActionType;
import org.elasticsearch.common.io.stream.Writeable;

public class NodesStatsAction extends ActionType<NodesStatsResponse> {

public static final NodesStatsAction INSTANCE = new NodesStatsAction();
public static final String NAME = "cluster:monitor/nodes/stats";

private NodesStatsAction() {
super(NAME, NodesStatsResponse::new);
super(NAME, Writeable.Reader.localOnly());
}
}
Loading

0 comments on commit 3292322

Please sign in to comment.