Skip to content

Commit 7d913c8

Browse files
committed
Run cluster info requests on local node
1 parent 4e0e36b commit 7d913c8

File tree

17 files changed

+68
-300
lines changed

17 files changed

+68
-300
lines changed

server/src/internalClusterTest/java/org/elasticsearch/cluster/SimpleClusterStateIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ public void testLargeClusterStatePublishing() throws Exception {
266266
MappingMetadata mappingMetadata = client.admin()
267267
.indices()
268268
.prepareGetMappings(TEST_REQUEST_TIMEOUT, "test")
269-
.setLocal(true)
270269
.get()
271270
.getMappings()
272271
.get("test");

server/src/main/java/org/elasticsearch/action/admin/indices/get/TransportGetIndexAction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ public TransportGetIndexAction(
6363
threadPool,
6464
actionFilters,
6565
GetIndexRequest::new,
66-
indexNameExpressionResolver,
67-
GetIndexResponse::new
66+
indexNameExpressionResolver
6867
);
6968
this.indicesService = indicesService;
7069
this.settingsFilter = settingsFilter;

server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99

1010
package org.elasticsearch.action.admin.indices.mapping.get;
1111

12-
import org.elasticsearch.TransportVersions;
1312
import org.elasticsearch.action.ActionResponse;
1413
import org.elasticsearch.cluster.metadata.MappingMetadata;
1514
import org.elasticsearch.common.Strings;
1615
import org.elasticsearch.common.collect.Iterators;
17-
import org.elasticsearch.common.io.stream.StreamInput;
1816
import org.elasticsearch.common.io.stream.StreamOutput;
1917
import org.elasticsearch.common.xcontent.ChunkedToXContentObject;
20-
import org.elasticsearch.index.mapper.MapperService;
18+
import org.elasticsearch.core.UpdateForV10;
2119
import org.elasticsearch.xcontent.ParseField;
2220
import org.elasticsearch.xcontent.ToXContent;
2321

@@ -35,21 +33,6 @@ public GetMappingsResponse(Map<String, MappingMetadata> mappings) {
3533
this.mappings = mappings;
3634
}
3735

38-
GetMappingsResponse(StreamInput in) throws IOException {
39-
super(in);
40-
mappings = in.readImmutableMap(in.getTransportVersion().before(TransportVersions.V_8_0_0) ? i -> {
41-
int mappingCount = i.readVInt();
42-
assert mappingCount == 1 || mappingCount == 0 : "Expected 0 or 1 mappings but got " + mappingCount;
43-
if (mappingCount == 1) {
44-
String type = i.readString();
45-
assert MapperService.SINGLE_MAPPING_NAME.equals(type) : "Expected type [_doc] but got [" + type + "]";
46-
return new MappingMetadata(i);
47-
} else {
48-
return MappingMetadata.EMPTY_MAPPINGS;
49-
}
50-
} : i -> i.readBoolean() ? new MappingMetadata(i) : MappingMetadata.EMPTY_MAPPINGS);
51-
}
52-
5336
public Map<String, MappingMetadata> mappings() {
5437
return mappings;
5538
}
@@ -58,6 +41,11 @@ public Map<String, MappingMetadata> getMappings() {
5841
return mappings();
5942
}
6043

44+
/**
45+
* NB prior to 9.0 this was a TransportMasterNodeReadAction so for BwC we must remain able to write these responses until
46+
* we no longer need to support calling this action remotely.
47+
*/
48+
@UpdateForV10(owner = UpdateForV10.Owner.DATA_MANAGEMENT)
6149
@Override
6250
public void writeTo(StreamOutput out) throws IOException {
6351
MappingMetadata.writeMappingMetadata(out, mappings);

server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ public TransportGetMappingsAction(
5050
threadPool,
5151
actionFilters,
5252
GetMappingsRequest::new,
53-
indexNameExpressionResolver,
54-
GetMappingsResponse::new
53+
indexNameExpressionResolver
5554
);
5655
this.indicesService = indicesService;
5756
}

server/src/main/java/org/elasticsearch/action/support/local/LocalClusterStateRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected LocalClusterStateRequest(StreamInput in) throws IOException {
5050
}
5151

5252
@Override
53-
public final void writeTo(StreamOutput out) throws IOException {
53+
public void writeTo(StreamOutput out) throws IOException {
5454
TransportAction.localOnly();
5555
}
5656

server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequest.java

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
import org.elasticsearch.TransportVersions;
1313
import org.elasticsearch.action.IndicesRequest;
1414
import org.elasticsearch.action.support.IndicesOptions;
15-
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
15+
import org.elasticsearch.action.support.local.LocalClusterStateRequest;
1616
import org.elasticsearch.common.Strings;
1717
import org.elasticsearch.common.io.stream.StreamInput;
18-
import org.elasticsearch.common.io.stream.StreamOutput;
1918
import org.elasticsearch.core.TimeValue;
19+
import org.elasticsearch.core.UpdateForV10;
2020

2121
import java.io.IOException;
2222

23-
public abstract class ClusterInfoRequest<Request extends ClusterInfoRequest<Request>> extends MasterNodeReadRequest<Request>
23+
public abstract class ClusterInfoRequest<Request extends ClusterInfoRequest<Request>> extends LocalClusterStateRequest
2424
implements
2525
IndicesRequest.Replaceable {
2626

@@ -37,18 +37,11 @@ public ClusterInfoRequest(TimeValue masterTimeout, IndicesOptions indicesOptions
3737
this.indicesOptions = indicesOptions;
3838
}
3939

40-
@Deprecated(forRemoval = true)
41-
public ClusterInfoRequest() {
42-
super(TRAPPY_IMPLICIT_DEFAULT_MASTER_NODE_TIMEOUT);
43-
}
44-
45-
// So subclasses can override the default indices options, if needed
46-
@Deprecated(forRemoval = true)
47-
protected ClusterInfoRequest(IndicesOptions indicesOptions) {
48-
super(TRAPPY_IMPLICIT_DEFAULT_MASTER_NODE_TIMEOUT);
49-
this.indicesOptions = indicesOptions;
50-
}
51-
40+
/**
41+
* NB prior to 9.0 this was a TransportMasterNodeReadAction so for BwC we must remain able to read these requests until
42+
* we no longer need to support calling this action remotely.
43+
*/
44+
@UpdateForV10(owner = UpdateForV10.Owner.DATA_MANAGEMENT)
5245
public ClusterInfoRequest(StreamInput in) throws IOException {
5346
super(in);
5447
indices = in.readStringArray();
@@ -58,16 +51,6 @@ public ClusterInfoRequest(StreamInput in) throws IOException {
5851
indicesOptions = IndicesOptions.readIndicesOptions(in);
5952
}
6053

61-
@Override
62-
public void writeTo(StreamOutput out) throws IOException {
63-
super.writeTo(out);
64-
out.writeStringArray(indices);
65-
if (out.getTransportVersion().before(TransportVersions.V_8_0_0)) {
66-
out.writeStringArray(Strings.EMPTY_ARRAY);
67-
}
68-
indicesOptions.writeIndicesOptions(out);
69-
}
70-
7154
@Override
7255
@SuppressWarnings("unchecked")
7356
public Request indices(String... indices) {

server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequestBuilder.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,17 @@
88
*/
99
package org.elasticsearch.action.support.master.info;
1010

11+
import org.elasticsearch.action.ActionRequestBuilder;
1112
import org.elasticsearch.action.ActionResponse;
1213
import org.elasticsearch.action.ActionType;
1314
import org.elasticsearch.action.support.IndicesOptions;
14-
import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder;
1515
import org.elasticsearch.client.internal.ElasticsearchClient;
1616
import org.elasticsearch.common.util.ArrayUtils;
1717

1818
public abstract class ClusterInfoRequestBuilder<
1919
Request extends ClusterInfoRequest<Request>,
2020
Response extends ActionResponse,
21-
Builder extends ClusterInfoRequestBuilder<Request, Response, Builder>> extends MasterNodeReadOperationRequestBuilder<
22-
Request,
23-
Response,
24-
Builder> {
21+
Builder extends ClusterInfoRequestBuilder<Request, Response, Builder>> extends ActionRequestBuilder<Request, Response> {
2522

2623
protected ClusterInfoRequestBuilder(ElasticsearchClient client, ActionType<Response> action, Request request) {
2724
super(client, action, request);

server/src/main/java/org/elasticsearch/action/support/master/info/TransportClusterInfoAction.java

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,56 @@
1111
import org.elasticsearch.action.ActionListener;
1212
import org.elasticsearch.action.ActionResponse;
1313
import org.elasticsearch.action.support.ActionFilters;
14-
import org.elasticsearch.action.support.master.TransportMasterNodeReadAction;
14+
import org.elasticsearch.action.support.ChannelActionListener;
15+
import org.elasticsearch.action.support.local.TransportLocalClusterStateAction;
1516
import org.elasticsearch.cluster.ClusterState;
1617
import org.elasticsearch.cluster.block.ClusterBlockException;
1718
import org.elasticsearch.cluster.block.ClusterBlockLevel;
1819
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
1920
import org.elasticsearch.cluster.service.ClusterService;
2021
import org.elasticsearch.common.io.stream.Writeable;
22+
import org.elasticsearch.core.UpdateForV10;
2123
import org.elasticsearch.tasks.Task;
2224
import org.elasticsearch.threadpool.ThreadPool;
2325
import org.elasticsearch.transport.TransportService;
2426

2527
public abstract class TransportClusterInfoAction<Request extends ClusterInfoRequest<Request>, Response extends ActionResponse> extends
26-
TransportMasterNodeReadAction<Request, Response> {
28+
TransportLocalClusterStateAction<Request, Response> {
2729

30+
protected final IndexNameExpressionResolver indexNameExpressionResolver;
31+
32+
/**
33+
* NB prior to 9.0 this was a TransportMasterNodeReadAction so for BwC it must be registered with the TransportService until
34+
* we no longer need to support calling this action remotely.
35+
*/
36+
@UpdateForV10(owner = UpdateForV10.Owner.DATA_MANAGEMENT)
37+
@SuppressWarnings("this-escape")
2838
public TransportClusterInfoAction(
2939
String actionName,
3040
TransportService transportService,
3141
ClusterService clusterService,
3242
ThreadPool threadPool,
3343
ActionFilters actionFilters,
3444
Writeable.Reader<Request> request,
35-
IndexNameExpressionResolver indexNameExpressionResolver,
36-
Writeable.Reader<Response> response
45+
IndexNameExpressionResolver indexNameExpressionResolver
3746
) {
3847
super(
3948
actionName,
40-
transportService,
41-
clusterService,
42-
threadPool,
4349
actionFilters,
44-
request,
45-
indexNameExpressionResolver,
46-
response,
50+
transportService.getTaskManager(),
51+
clusterService,
4752
threadPool.executor(ThreadPool.Names.MANAGEMENT)
4853
);
54+
this.indexNameExpressionResolver = indexNameExpressionResolver;
55+
56+
transportService.registerRequestHandler(
57+
actionName,
58+
executor,
59+
false,
60+
true,
61+
request,
62+
(r, channel, task) -> executeDirect(task, r, new ChannelActionListener<>(channel))
63+
);
4964
}
5065

5166
@Override
@@ -55,7 +70,7 @@ protected ClusterBlockException checkBlock(Request request, ClusterState state)
5570
}
5671

5772
@Override
58-
protected final void masterOperation(
73+
protected final void localClusterStateOperation(
5974
Task task,
6075
final Request request,
6176
final ClusterState state,

server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesAction.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.elasticsearch.common.settings.Settings;
1717
import org.elasticsearch.rest.BaseRestHandler;
1818
import org.elasticsearch.rest.RestRequest;
19+
import org.elasticsearch.rest.RestUtils;
1920
import org.elasticsearch.rest.Scope;
2021
import org.elasticsearch.rest.ServerlessScope;
2122
import org.elasticsearch.rest.action.RestCancellableNodeClient;
@@ -27,7 +28,6 @@
2728

2829
import static org.elasticsearch.rest.RestRequest.Method.GET;
2930
import static org.elasticsearch.rest.RestRequest.Method.HEAD;
30-
import static org.elasticsearch.rest.RestUtils.getMasterNodeTimeout;
3131

3232
/**
3333
* The REST handler for get index and head index APIs.
@@ -48,10 +48,10 @@ public String getName() {
4848
@Override
4949
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
5050
String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
51-
final GetIndexRequest getIndexRequest = new GetIndexRequest(getMasterNodeTimeout(request));
51+
final GetIndexRequest getIndexRequest = new GetIndexRequest(RestUtils.getMasterNodeTimeout(request));
5252
getIndexRequest.indices(indices);
5353
getIndexRequest.indicesOptions(IndicesOptions.fromRequest(request, getIndexRequest.indicesOptions()));
54-
getIndexRequest.local(request.paramAsBoolean("local", getIndexRequest.local()));
54+
RestUtils.consumeDeprecatedLocalParameter(request);
5555
getIndexRequest.humanReadable(request.paramAsBoolean("human", false));
5656
getIndexRequest.includeDefaults(request.paramAsBoolean("include_defaults", false));
5757
getIndexRequest.features(GetIndexRequest.Feature.fromRequest(request));

server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingAction.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.elasticsearch.http.HttpChannel;
1717
import org.elasticsearch.rest.BaseRestHandler;
1818
import org.elasticsearch.rest.RestRequest;
19+
import org.elasticsearch.rest.RestUtils;
1920
import org.elasticsearch.rest.Scope;
2021
import org.elasticsearch.rest.ServerlessScope;
2122
import org.elasticsearch.rest.action.RestCancellableNodeClient;
@@ -25,7 +26,6 @@
2526
import java.util.List;
2627

2728
import static org.elasticsearch.rest.RestRequest.Method.GET;
28-
import static org.elasticsearch.rest.RestUtils.getMasterNodeTimeout;
2929

3030
@ServerlessScope(Scope.PUBLIC)
3131
public class RestGetMappingAction extends BaseRestHandler {
@@ -50,10 +50,10 @@ public String getName() {
5050
@Override
5151
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
5252
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
53-
final GetMappingsRequest getMappingsRequest = new GetMappingsRequest(getMasterNodeTimeout(request));
53+
final GetMappingsRequest getMappingsRequest = new GetMappingsRequest(RestUtils.getMasterNodeTimeout(request));
5454
getMappingsRequest.indices(indices);
5555
getMappingsRequest.indicesOptions(IndicesOptions.fromRequest(request, getMappingsRequest.indicesOptions()));
56-
getMappingsRequest.local(request.paramAsBoolean("local", getMappingsRequest.local()));
56+
RestUtils.consumeDeprecatedLocalParameter(request);
5757
final HttpChannel httpChannel = request.getHttpChannel();
5858
return channel -> new RestCancellableNodeClient(client, httpChannel).admin()
5959
.indices()

0 commit comments

Comments
 (0)