Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/125652.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 125652
summary: Run `TransportGetIndexAction` on local node
area: Indices APIs
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsAction;
import org.elasticsearch.action.admin.cluster.state.ClusterStateAction;
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesAction;
import org.elasticsearch.action.admin.indices.get.GetIndexAction;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsAction;
import org.elasticsearch.action.admin.indices.recovery.RecoveryAction;
import org.elasticsearch.action.admin.indices.template.get.GetComponentTemplateAction;
Expand Down Expand Up @@ -114,6 +115,11 @@ public void testGetMappingsCancellation() {
runRestActionCancellationTest(new Request(HttpGet.METHOD_NAME, "/test/_mappings"), GetMappingsAction.NAME);
}

public void testGetIndicesCancellation() {
createIndex("test");
runRestActionCancellationTest(new Request(HttpGet.METHOD_NAME, "/test"), GetIndexAction.NAME);
}

private void runRestActionCancellationTest(Request request, String actionName) {
final var node = usually() ? internalCluster().getRandomNodeName() : internalCluster().startCoordinatingOnlyNode(Settings.EMPTY);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
- is_true: ''
---
"Test indices.exists with local flag":
- requires:
test_runner_features: ["allowed_warnings"]

- do:
indices.exists:
index: test_index
local: true
allowed_warnings:
- "the [?local] query parameter to this API has no effect, is now deprecated, and will be removed in a future version"

- is_false: ''
1 change: 0 additions & 1 deletion server/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@
exports org.elasticsearch.action.support.broadcast.node;
exports org.elasticsearch.action.support.broadcast.unpromotable;
exports org.elasticsearch.action.support.master;
exports org.elasticsearch.action.support.master.info;
exports org.elasticsearch.action.support.nodes;
exports org.elasticsearch.action.support.local;
exports org.elasticsearch.action.support.replication;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@

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

import org.elasticsearch.TransportVersions;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.info.ClusterInfoRequest;
import org.elasticsearch.action.support.local.LocalClusterStateRequest;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.util.ArrayUtils;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.core.UpdateForV10;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.tasks.CancellableTask;
import org.elasticsearch.tasks.Task;
Expand All @@ -32,7 +35,7 @@
/**
* A request to retrieve information about an index.
*/
public class GetIndexRequest extends ClusterInfoRequest<GetIndexRequest> {
public class GetIndexRequest extends LocalClusterStateRequest implements IndicesRequest.Replaceable {
public enum Feature {
ALIASES((byte) 0),
MAPPINGS((byte) 1),
Expand Down Expand Up @@ -90,16 +93,30 @@ public static Feature[] fromRequest(RestRequest request) {
}

static final Feature[] DEFAULT_FEATURES = new Feature[] { Feature.ALIASES, Feature.MAPPINGS, Feature.SETTINGS };

private String[] indices = Strings.EMPTY_ARRAY;
private IndicesOptions indicesOptions;
private Feature[] features = DEFAULT_FEATURES;
private boolean humanReadable = false;
private transient boolean includeDefaults = false;

public GetIndexRequest(TimeValue masterTimeout) {
super(masterTimeout, IndicesOptions.strictExpandOpen());
super(masterTimeout);
indicesOptions = IndicesOptions.strictExpandOpen();
}

/**
* NB prior to 9.1 this was a TransportMasterNodeReadAction so for BwC we must remain able to read these requests until
* we no longer need to support calling this action remotely.
*/
@UpdateForV10(owner = UpdateForV10.Owner.DATA_MANAGEMENT)
public GetIndexRequest(StreamInput in) throws IOException {
super(in);
indices = in.readStringArray();
if (in.getTransportVersion().before(TransportVersions.V_8_0_0)) {
in.readStringArray();
}
indicesOptions = IndicesOptions.readIndicesOptions(in);
features = in.readArray(i -> Feature.fromId(i.readByte()), Feature[]::new);
humanReadable = in.readBoolean();
includeDefaults = in.readBoolean();
Expand Down Expand Up @@ -162,11 +179,29 @@ public boolean includeDefaults() {
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeArray((o, f) -> o.writeByte(f.id), features);
out.writeBoolean(humanReadable);
out.writeBoolean(includeDefaults);
public GetIndexRequest indices(String... indices) {
this.indices = indices;
return this;
}

public GetIndexRequest indicesOptions(IndicesOptions indicesOptions) {
this.indicesOptions = indicesOptions;
return this;
}

@Override
public String[] indices() {
return indices;
}

@Override
public IndicesOptions indicesOptions() {
return indicesOptions;
}

@Override
public boolean includeDataStreams() {
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,34 @@

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

import org.elasticsearch.action.ActionRequestBuilder;
import org.elasticsearch.action.admin.indices.get.GetIndexRequest.Feature;
import org.elasticsearch.action.support.master.info.ClusterInfoRequestBuilder;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.client.internal.ElasticsearchClient;
import org.elasticsearch.common.util.ArrayUtils;
import org.elasticsearch.core.TimeValue;

public class GetIndexRequestBuilder extends ClusterInfoRequestBuilder<GetIndexRequest, GetIndexResponse, GetIndexRequestBuilder> {
public class GetIndexRequestBuilder extends ActionRequestBuilder<GetIndexRequest, GetIndexResponse> {

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

public GetIndexRequestBuilder setIndices(String... indices) {
request.indices(indices);
return this;
}

public GetIndexRequestBuilder addIndices(String... indices) {
request.indices(ArrayUtils.concat(request.indices(), indices));
return this;
}

public GetIndexRequestBuilder setIndicesOptions(IndicesOptions indicesOptions) {
request.indicesOptions(indicesOptions);
return this;
}

public GetIndexRequestBuilder setFeatures(Feature... features) {
request.features(features);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ChunkedToXContentObject;
import org.elasticsearch.core.UpdateForV10;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.xcontent.ToXContent;

Expand Down Expand Up @@ -69,6 +70,11 @@ public GetIndexResponse(
}
}

/**
* The only usage of this constructor is for BwC cross-cluster transforms for clusters before v8.2. The ML team is aware that we
* 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.
*/
@UpdateForV10(owner = UpdateForV10.Owner.DATA_MANAGEMENT)
GetIndexResponse(StreamInput in) throws IOException {
Comment on lines +73 to 78
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reached out to the ML team and they confirmed that the code that uses the GET index action is for BwC to a version that is no longer supported (v8.2) for cross-cluster transforms. This last usage is:

public static final RemoteClusterActionType<GetIndexResponse> REMOTE_TYPE = new RemoteClusterActionType<>(NAME, GetIndexResponse::new);

this.indices = in.readStringArray();
mappings = in.readImmutableOpenMap(StreamInput::readString, in.getTransportVersion().before(TransportVersions.V_8_0_0) ? i -> {
Expand Down Expand Up @@ -165,6 +171,11 @@ public String getSetting(String index, String setting) {
}
}

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