Skip to content

Commit 483f979

Browse files
authored
Run TransportGetIndexAction on local node (#125652)
This action solely needs the cluster state, it can run on any node. Since this is the last class/action that extends the `ClusterInfo` abstract classes, we remove those classes too as they're not required anymore. Relates #101805
1 parent e4fb22c commit 483f979

File tree

16 files changed

+146
-382
lines changed

16 files changed

+146
-382
lines changed

docs/changelog/125652.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 125652
2+
summary: Run `TransportGetIndexAction` on local node
3+
area: Indices APIs
4+
type: enhancement
5+
issues: []

qa/smoke-test-http/src/internalClusterTest/java/org/elasticsearch/http/RestActionCancellationIT.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsAction;
1616
import org.elasticsearch.action.admin.cluster.state.ClusterStateAction;
1717
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesAction;
18+
import org.elasticsearch.action.admin.indices.get.GetIndexAction;
1819
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsAction;
1920
import org.elasticsearch.action.admin.indices.recovery.RecoveryAction;
2021
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsAction;
@@ -115,6 +116,11 @@ public void testGetMappingsCancellation() {
115116
runRestActionCancellationTest(new Request(HttpGet.METHOD_NAME, "/test/_mappings"), GetMappingsAction.NAME);
116117
}
117118

119+
public void testGetIndicesCancellation() {
120+
createIndex("test");
121+
runRestActionCancellationTest(new Request(HttpGet.METHOD_NAME, "/test"), GetIndexAction.NAME);
122+
}
123+
118124
public void testGetIndexSettingsCancellation() {
119125
createIndex("test");
120126
runRestActionCancellationTest(new Request(HttpGet.METHOD_NAME, "/test/_settings"), GetSettingsAction.NAME);

qa/smoke-test-http/src/internalClusterTest/java/org/elasticsearch/http/RestClusterInfoActionCancellationIT.java

Lines changed: 0 additions & 110 deletions
This file was deleted.

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.exists/10_basic.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@
1717
- is_true: ''
1818
---
1919
"Test indices.exists with local flag":
20+
- requires:
21+
test_runner_features: ["allowed_warnings"]
22+
2023
- do:
2124
indices.exists:
2225
index: test_index
2326
local: true
27+
allowed_warnings:
28+
- "the [?local] query parameter to this API has no effect, is now deprecated, and will be removed in a future version"
2429

2530
- is_false: ''

server/src/main/java/module-info.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@
144144
exports org.elasticsearch.action.support.broadcast.node;
145145
exports org.elasticsearch.action.support.broadcast.unpromotable;
146146
exports org.elasticsearch.action.support.master;
147-
exports org.elasticsearch.action.support.master.info;
148147
exports org.elasticsearch.action.support.nodes;
149148
exports org.elasticsearch.action.support.local;
150149
exports org.elasticsearch.action.support.replication;

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

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99

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

12+
import org.elasticsearch.TransportVersions;
1213
import org.elasticsearch.action.ActionRequestValidationException;
14+
import org.elasticsearch.action.IndicesRequest;
1315
import org.elasticsearch.action.support.IndicesOptions;
14-
import org.elasticsearch.action.support.master.info.ClusterInfoRequest;
16+
import org.elasticsearch.action.support.local.LocalClusterStateRequest;
17+
import org.elasticsearch.common.Strings;
1518
import org.elasticsearch.common.io.stream.StreamInput;
16-
import org.elasticsearch.common.io.stream.StreamOutput;
1719
import org.elasticsearch.common.util.ArrayUtils;
1820
import org.elasticsearch.core.TimeValue;
21+
import org.elasticsearch.core.UpdateForV10;
1922
import org.elasticsearch.rest.RestRequest;
2023
import org.elasticsearch.tasks.CancellableTask;
2124
import org.elasticsearch.tasks.Task;
@@ -32,7 +35,7 @@
3235
/**
3336
* A request to retrieve information about an index.
3437
*/
35-
public class GetIndexRequest extends ClusterInfoRequest<GetIndexRequest> {
38+
public class GetIndexRequest extends LocalClusterStateRequest implements IndicesRequest.Replaceable {
3639
public enum Feature {
3740
ALIASES((byte) 0),
3841
MAPPINGS((byte) 1),
@@ -90,16 +93,30 @@ public static Feature[] fromRequest(RestRequest request) {
9093
}
9194

9295
static final Feature[] DEFAULT_FEATURES = new Feature[] { Feature.ALIASES, Feature.MAPPINGS, Feature.SETTINGS };
96+
97+
private String[] indices = Strings.EMPTY_ARRAY;
98+
private IndicesOptions indicesOptions;
9399
private Feature[] features = DEFAULT_FEATURES;
94100
private boolean humanReadable = false;
95101
private transient boolean includeDefaults = false;
96102

97103
public GetIndexRequest(TimeValue masterTimeout) {
98-
super(masterTimeout, IndicesOptions.strictExpandOpen());
104+
super(masterTimeout);
105+
indicesOptions = IndicesOptions.strictExpandOpen();
99106
}
100107

108+
/**
109+
* NB prior to 9.1 this was a TransportMasterNodeReadAction so for BwC we must remain able to read these requests until
110+
* we no longer need to support calling this action remotely.
111+
*/
112+
@UpdateForV10(owner = UpdateForV10.Owner.DATA_MANAGEMENT)
101113
public GetIndexRequest(StreamInput in) throws IOException {
102114
super(in);
115+
indices = in.readStringArray();
116+
if (in.getTransportVersion().before(TransportVersions.V_8_0_0)) {
117+
in.readStringArray();
118+
}
119+
indicesOptions = IndicesOptions.readIndicesOptions(in);
103120
features = in.readArray(i -> Feature.fromId(i.readByte()), Feature[]::new);
104121
humanReadable = in.readBoolean();
105122
includeDefaults = in.readBoolean();
@@ -162,11 +179,29 @@ public boolean includeDefaults() {
162179
}
163180

164181
@Override
165-
public void writeTo(StreamOutput out) throws IOException {
166-
super.writeTo(out);
167-
out.writeArray((o, f) -> o.writeByte(f.id), features);
168-
out.writeBoolean(humanReadable);
169-
out.writeBoolean(includeDefaults);
182+
public GetIndexRequest indices(String... indices) {
183+
this.indices = indices;
184+
return this;
185+
}
186+
187+
public GetIndexRequest indicesOptions(IndicesOptions indicesOptions) {
188+
this.indicesOptions = indicesOptions;
189+
return this;
190+
}
191+
192+
@Override
193+
public String[] indices() {
194+
return indices;
195+
}
196+
197+
@Override
198+
public IndicesOptions indicesOptions() {
199+
return indicesOptions;
200+
}
201+
202+
@Override
203+
public boolean includeDataStreams() {
204+
return true;
170205
}
171206

172207
@Override

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,34 @@
99

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

12+
import org.elasticsearch.action.ActionRequestBuilder;
1213
import org.elasticsearch.action.admin.indices.get.GetIndexRequest.Feature;
13-
import org.elasticsearch.action.support.master.info.ClusterInfoRequestBuilder;
14+
import org.elasticsearch.action.support.IndicesOptions;
1415
import org.elasticsearch.client.internal.ElasticsearchClient;
16+
import org.elasticsearch.common.util.ArrayUtils;
1517
import org.elasticsearch.core.TimeValue;
1618

17-
public class GetIndexRequestBuilder extends ClusterInfoRequestBuilder<GetIndexRequest, GetIndexResponse, GetIndexRequestBuilder> {
19+
public class GetIndexRequestBuilder extends ActionRequestBuilder<GetIndexRequest, GetIndexResponse> {
1820

1921
public GetIndexRequestBuilder(ElasticsearchClient client, TimeValue masterTimeout, String... indices) {
2022
super(client, GetIndexAction.INSTANCE, new GetIndexRequest(masterTimeout).indices(indices));
2123
}
2224

25+
public GetIndexRequestBuilder setIndices(String... indices) {
26+
request.indices(indices);
27+
return this;
28+
}
29+
30+
public GetIndexRequestBuilder addIndices(String... indices) {
31+
request.indices(ArrayUtils.concat(request.indices(), indices));
32+
return this;
33+
}
34+
35+
public GetIndexRequestBuilder setIndicesOptions(IndicesOptions indicesOptions) {
36+
request.indicesOptions(indicesOptions);
37+
return this;
38+
}
39+
2340
public GetIndexRequestBuilder setFeatures(Feature... features) {
2441
request.features(features);
2542
return this;

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.elasticsearch.common.io.stream.StreamOutput;
2020
import org.elasticsearch.common.settings.Settings;
2121
import org.elasticsearch.common.xcontent.ChunkedToXContentObject;
22+
import org.elasticsearch.core.UpdateForV10;
2223
import org.elasticsearch.index.mapper.MapperService;
2324
import org.elasticsearch.xcontent.ToXContent;
2425

@@ -69,6 +70,11 @@ public GetIndexResponse(
6970
}
7071
}
7172

73+
/**
74+
* The only usage of this constructor is for BwC cross-cluster transforms for clusters before v8.2. The ML team is aware that we
75+
* don't need to support that anymore now that we're on v9. Once they remove that BwC code, we can remove this constructor as well.
76+
*/
77+
@UpdateForV10(owner = UpdateForV10.Owner.DATA_MANAGEMENT)
7278
GetIndexResponse(StreamInput in) throws IOException {
7379
this.indices = in.readStringArray();
7480
mappings = in.readImmutableOpenMap(StreamInput::readString, in.getTransportVersion().before(TransportVersions.V_8_0_0) ? i -> {
@@ -165,6 +171,11 @@ public String getSetting(String index, String setting) {
165171
}
166172
}
167173

174+
/**
175+
* NB prior to 9.1 this was a TransportMasterNodeReadAction so for BwC we must remain able to write these responses until
176+
* we no longer need to support calling this action remotely.
177+
*/
178+
@UpdateForV10(owner = UpdateForV10.Owner.DATA_MANAGEMENT)
168179
@Override
169180
public void writeTo(StreamOutput out) throws IOException {
170181
out.writeStringArray(indices);

0 commit comments

Comments
 (0)