Skip to content

Run cluster info requests on local node #120982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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/120982.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 120982
summary: Run cluster info requests on local node
area: Indices APIs
type: enhancement
issues: []
2 changes: 1 addition & 1 deletion docs/reference/indices/get-index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=include-defaults]
If `false`, requests that target a missing index return an error. Defaults to
`false`.

include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=local]
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=local-deprecated-9.0.0]

include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=master-timeout]
2 changes: 1 addition & 1 deletion docs/reference/indices/get-mapping.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Defaults to `open`.

include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]

include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=local]
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=local-deprecated-9.0.0]

include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=master-timeout]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
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;
import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction;
Expand Down Expand Up @@ -108,6 +110,16 @@ public void testGetPipelineCancellation() {
runRestActionCancellationTest(new Request(HttpGet.METHOD_NAME, "/_ingest/pipeline"), GetPipelineAction.NAME);
}

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

public void testGetMappingsCancellation() {
createIndex("test");
runRestActionCancellationTest(new Request(HttpGet.METHOD_NAME, "/test/_mappings"), GetMappingsAction.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 @@ -36,7 +36,7 @@
},
"master_timeout":{
"type":"time",
"description":"Explicit operation timeout for connection to master node"
"description":"Timeout for waiting for new cluster state in case it is blocked"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"params":{
"local":{
"deprecated":true,
"type":"boolean",
"description":"Return local information, do not retrieve the state from master node (default: false)"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"params":{
"local":{
"deprecated":true,
"type":"boolean",
"description":"Return local information, do not retrieve the state from master node (default: false)"
},
Expand Down Expand Up @@ -71,7 +72,7 @@
},
"master_timeout":{
"type":"time",
"description":"Specify timeout for connection to master"
"description":"Timeout for waiting for new cluster state in case it is blocked"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@
],
"default":"open",
"description":"Whether to expand wildcard expression to concrete indices that are open, closed or both."
},
"local":{
"type":"boolean",
"description":"Return local information, do not retrieve the state from master node (default: false)"
Comment on lines -68 to -71
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This param for the GetFieldMapping API was deprecated in #55014 and I think #57265 aimed to propagate that deprecation to the REST API spec, but it changed get_mapping.json instead of get_field_mapping.json. #55100 removed the local param for the field mapping API but the regular mapping API still supports the local param. That's why I'm deleting the param here and deprecating it in get_mapping.json below.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you pull this out to a separate PR?

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@
"local":{
"type":"boolean",
"description":"Return local information, do not retrieve the state from master node (default: false)",
"deprecated":{
"version":"7.8.0",
"description":"This parameter is a no-op and field mappings are always retrieved locally."
}
"deprecated": true
}
}
}
Expand Down
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: ''
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,3 @@ setup:

- match: {test_index.mappings.text.mapping.text.type: text}
- match: {test_index.mappings.text.mapping.text.analyzer: default}

---
"Get field mapping with local parameter should fail":

- requires:
test_runner_features: ["warnings"]
cluster_features: ["gte_v8.0.0"]
reason: "local parameter for get field mapping API was allowed before v8"

- do:
catch: bad_request
indices.get_field_mapping:
fields: text
local: true
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsAction;
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsAction;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.elasticsearch.action.admin.indices.mapping.put.TransportPutMappingAction;
import org.elasticsearch.action.admin.indices.open.OpenIndexAction;
Expand Down Expand Up @@ -516,16 +514,6 @@ public void testDeleteIndex() {
assertSameIndices(deleteIndexRequest, TransportDeleteIndexAction.TYPE.name());
}

public void testGetMappings() {
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 deleted this test because it didn't seem to make much sense to keep it when we run the action on the local node -- and it was failing.

interceptTransportActions(GetMappingsAction.NAME);

GetMappingsRequest getMappingsRequest = new GetMappingsRequest(TEST_REQUEST_TIMEOUT).indices(randomIndicesOrAliases());
internalCluster().coordOnlyNodeClient().admin().indices().getMappings(getMappingsRequest).actionGet();

clearInterceptedActions();
assertSameIndices(getMappingsRequest, GetMappingsAction.NAME);
}

public void testPutMapping() {
interceptTransportActions(TransportPutMappingAction.TYPE.name());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ public void testLargeClusterStatePublishing() throws Exception {
MappingMetadata mappingMetadata = client.admin()
.indices()
.prepareGetMappings(TEST_REQUEST_TIMEOUT, "test")
.setLocal(true)
.get()
.getMappings()
.get("test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@
import org.elasticsearch.common.util.ArrayUtils;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.tasks.CancellableTask;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.tasks.TaskId;

import java.io.IOException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

/**
Expand Down Expand Up @@ -98,6 +94,10 @@ public GetIndexRequest(TimeValue masterTimeout) {
super(masterTimeout, IndicesOptions.strictExpandOpen());
}

/**
* Even though this action is executed on the local node, we still need to be able to read an incoming request as it's used across
* clusters.
*/
Comment on lines +97 to +100
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one is worth discussing. It looks like the GetIndexAction is used across clusters:

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

which means we'll need to support transport serialization for both GetIndexRequest and GetIndexResponse. That in turn meant I had to remove final LocalClusterStateRequest#writeTo (see further down this PR). I don't really see a way around this but any suggestions are welcome.

We could also add final back into LocalClusterStateReuqest#writeTo and add a method like writeToRemoteCluster to something along those lines, to make it more explicit that that method is required for cross-cluster requests.

public GetIndexRequest(StreamInput in) throws IOException {
super(in);
features = in.readArray(i -> Feature.fromId(i.readByte()), Feature[]::new);
Expand Down Expand Up @@ -168,9 +168,4 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeBoolean(humanReadable);
out.writeBoolean(includeDefaults);
}

@Override
public Task createTask(long id, String type, String action, TaskId parentTaskId, Map<String, String> headers) {
return new CancellableTask(id, type, action, getDescription(), parentTaskId, headers);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public TransportGetIndexAction(
threadPool,
actionFilters,
GetIndexRequest::new,
indexNameExpressionResolver,
GetIndexResponse::new
indexNameExpressionResolver
);
this.indicesService = indicesService;
this.settingsFilter = settingsFilter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@
import org.elasticsearch.action.support.master.info.ClusterInfoRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.tasks.CancellableTask;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.tasks.TaskId;
import org.elasticsearch.core.UpdateForV10;

import java.io.IOException;
import java.util.Map;

public class GetMappingsRequest extends ClusterInfoRequest<GetMappingsRequest> {

public GetMappingsRequest(TimeValue masterTimeout) {
super(masterTimeout, IndicesOptions.strictExpandOpen());
}

/**
* NB prior to 9.0 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 GetMappingsRequest(StreamInput in) throws IOException {
super(in);
}
Expand All @@ -35,9 +37,4 @@ public GetMappingsRequest(StreamInput in) throws IOException {
public ActionRequestValidationException validate() {
return null;
}

@Override
public Task createTask(long id, String type, String action, TaskId parentTaskId, Map<String, String> headers) {
return new CancellableTask(id, type, action, "", parentTaskId, headers);
}
}
Loading