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

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/126051.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 126051
summary: Run `TransportGetSettingsAction` on local node
area: Indices APIs
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesAction;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsAction;
import org.elasticsearch.action.admin.indices.recovery.RecoveryAction;
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsAction;
import org.elasticsearch.action.admin.indices.template.get.GetComponentTemplateAction;
import org.elasticsearch.action.admin.indices.template.get.GetComposableIndexTemplateAction;
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesAction;
Expand Down Expand Up @@ -114,6 +115,11 @@ public void testGetMappingsCancellation() {
runRestActionCancellationTest(new Request(HttpGet.METHOD_NAME, "/test/_mappings"), GetMappingsAction.NAME);
}

public void testGetIndexSettingsCancellation() {
createIndex("test");
runRestActionCancellationTest(new Request(HttpGet.METHOD_NAME, "/test/_settings"), GetSettingsAction.NAME);
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"description":"Return settings in flat format (default: false)"
},
"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 @@ -164,10 +164,14 @@ setup:

---
"Get /_settings with local flag":
- requires:
test_runner_features: ["allowed_warnings"]

- do:
indices.get_settings:
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_true: test_1
- is_true: test_2
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
import org.elasticsearch.action.admin.indices.refresh.TransportShardRefreshAction;
import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsAction;
import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsRequest;
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsAction;
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest;
import org.elasticsearch.action.admin.indices.settings.put.TransportUpdateSettingsAction;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest;
import org.elasticsearch.action.admin.indices.stats.IndicesStatsAction;
Expand Down Expand Up @@ -524,16 +522,6 @@ public void testPutMapping() {
assertSameIndices(putMappingRequest, TransportPutMappingAction.TYPE.name());
}

public void testGetSettings() {
interceptTransportActions(GetSettingsAction.NAME);

GetSettingsRequest getSettingsRequest = new GetSettingsRequest(TEST_REQUEST_TIMEOUT).indices(randomIndicesOrAliases());
internalCluster().coordOnlyNodeClient().admin().indices().getSettings(getSettingsRequest).actionGet();

clearInterceptedActions();
assertSameIndices(getSettingsRequest, GetSettingsAction.NAME);
}

public void testUpdateSettings() {
interceptTransportActions(TransportUpdateSettingsAction.TYPE.name());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.ValidateActions;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
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.core.TimeValue;
import org.elasticsearch.core.UpdateForV10;
import org.elasticsearch.tasks.CancellableTask;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.tasks.TaskId;

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

public class GetSettingsRequest extends MasterNodeReadRequest<GetSettingsRequest> implements IndicesRequest.Replaceable {
public class GetSettingsRequest extends LocalClusterStateRequest implements IndicesRequest.Replaceable {

public static final IndicesOptions DEFAULT_INDICES_OPTIONS = IndicesOptions.fromOptions(false, true, true, true);

Expand Down Expand Up @@ -57,6 +61,11 @@ public GetSettingsRequest(TimeValue masterTimeout) {
super(masterTimeout);
}

/**
* 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 GetSettingsRequest(StreamInput in) throws IOException {
super(in);
indices = in.readStringArray();
Expand All @@ -66,16 +75,6 @@ public GetSettingsRequest(StreamInput in) throws IOException {
includeDefaults = in.readBoolean();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeStringArray(indices);
indicesOptions.writeIndicesOptions(out);
out.writeStringArray(names);
out.writeBoolean(humanReadable);
out.writeBoolean(includeDefaults);
}

@Override
public String[] indices() {
return indices;
Expand Down Expand Up @@ -122,6 +121,11 @@ public ActionRequestValidationException validate() {
return validationException;
}

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

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@

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

import org.elasticsearch.action.ActionRequestBuilder;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder;
import org.elasticsearch.client.internal.ElasticsearchClient;
import org.elasticsearch.common.util.ArrayUtils;
import org.elasticsearch.core.TimeValue;

public class GetSettingsRequestBuilder extends MasterNodeReadOperationRequestBuilder<
GetSettingsRequest,
GetSettingsResponse,
GetSettingsRequestBuilder> {
public class GetSettingsRequestBuilder extends ActionRequestBuilder<GetSettingsRequest, GetSettingsResponse> {

public GetSettingsRequestBuilder(ElasticsearchClient client, TimeValue masterTimeout, String... indices) {
super(client, GetSettingsAction.INSTANCE, new GetSettingsRequest(masterTimeout).indices(indices));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.Iterators;
import org.elasticsearch.common.io.stream.StreamInput;
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.xcontent.ToXContent;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.json.JsonXContent;
Expand All @@ -36,11 +36,6 @@ public GetSettingsResponse(Map<String, Settings> indexToSettings, Map<String, Se
this.indexToDefaultSettings = indexToDefaultSettings;
}

public GetSettingsResponse(StreamInput in) throws IOException {
indexToSettings = in.readImmutableMap(Settings::readSettingsFromStream);
indexToDefaultSettings = in.readImmutableMap(Settings::readSettingsFromStream);
}

/**
* Returns a map of index name to {@link Settings} object. The returned {@link Settings}
* objects contain only those settings explicitly set on a given index.
Expand Down Expand Up @@ -82,6 +77,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.writeMap(indexToSettings, StreamOutput::writeWriteable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@

import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.master.TransportMasterNodeReadAction;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.action.support.ChannelActionListener;
import org.elasticsearch.action.support.local.TransportLocalProjectMetadataAction;
import org.elasticsearch.cluster.ProjectState;
import org.elasticsearch.cluster.block.ClusterBlockException;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.project.ProjectResolver;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.IndexScopedSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.common.util.Maps;
import org.elasticsearch.core.UpdateForV10;
import org.elasticsearch.index.Index;
import org.elasticsearch.injection.guice.Inject;
import org.elasticsearch.tasks.Task;
Expand All @@ -35,62 +38,80 @@

import static java.util.Collections.unmodifiableMap;

public class TransportGetSettingsAction extends TransportMasterNodeReadAction<GetSettingsRequest, GetSettingsResponse> {
public class TransportGetSettingsAction extends TransportLocalProjectMetadataAction<GetSettingsRequest, GetSettingsResponse> {

private final SettingsFilter settingsFilter;
private final IndexScopedSettings indexScopedSettings;
private final IndexNameExpressionResolver indexNameExpressionResolver;

/**
* NB prior to 9.1 this was a TransportMasterNodeReadAction so for BwC it must be registered with the TransportService until
* we no longer need to support calling this action remotely.
*/
@UpdateForV10(owner = UpdateForV10.Owner.DATA_MANAGEMENT)
@SuppressWarnings("this-escape")
@Inject
public TransportGetSettingsAction(
TransportService transportService,
ClusterService clusterService,
ThreadPool threadPool,
SettingsFilter settingsFilter,
ActionFilters actionFilters,
ProjectResolver projectResolver,
IndexNameExpressionResolver indexNameExpressionResolver,
IndexScopedSettings indexedScopedSettings
) {
super(
GetSettingsAction.NAME,
transportService,
clusterService,
threadPool,
actionFilters,
GetSettingsRequest::new,
GetSettingsResponse::new,
threadPool.executor(ThreadPool.Names.MANAGEMENT)
transportService.getTaskManager(),
clusterService,
threadPool.executor(ThreadPool.Names.MANAGEMENT),
projectResolver
);
this.settingsFilter = settingsFilter;
this.indexScopedSettings = indexedScopedSettings;
this.indexNameExpressionResolver = indexNameExpressionResolver;

transportService.registerRequestHandler(
actionName,
executor,
false,
true,
GetSettingsRequest::new,
(request, channel, task) -> executeDirect(task, request, new ChannelActionListener<>(channel))
);
}

@Override
protected ClusterBlockException checkBlock(GetSettingsRequest request, ClusterState state) {
protected ClusterBlockException checkBlock(GetSettingsRequest request, ProjectState state) {
return state.blocks()
.indicesBlockedException(ClusterBlockLevel.METADATA_READ, indexNameExpressionResolver.concreteIndexNames(state, request));
.indicesBlockedException(
state.projectId(),
ClusterBlockLevel.METADATA_READ,
indexNameExpressionResolver.concreteIndexNames(state.metadata(), request)
);
}

private static boolean isFilteredRequest(GetSettingsRequest request) {
return CollectionUtils.isEmpty(request.names()) == false;
}

@Override
protected void masterOperation(
protected void localClusterStateOperation(
Task task,
GetSettingsRequest request,
ClusterState state,
ProjectState state,
ActionListener<GetSettingsResponse> listener
) {
assert Transports.assertNotTransportThread("O(indices) work is too much for a transport thread");
final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request);
final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state.metadata(), request);
final Map<String, Settings> indexToSettings = Maps.newHashMapWithExpectedSize(concreteIndices.length);
final Map<String, Settings> indexToDefaultSettings = request.includeDefaults()
? Maps.newHashMapWithExpectedSize(concreteIndices.length)
: null;
for (Index concreteIndex : concreteIndices) {
IndexMetadata indexMetadata = state.getMetadata().findIndex(concreteIndex).orElse(null);
IndexMetadata indexMetadata = state.metadata().index(concreteIndex);
if (indexMetadata == null) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.elasticsearch.rest.RestUtils;
import org.elasticsearch.rest.Scope;
import org.elasticsearch.rest.ServerlessScope;
import org.elasticsearch.rest.action.RestCancellableNodeClient;
import org.elasticsearch.rest.action.RestRefCountedChunkedToXContentListener;

import java.io.IOException;
Expand Down Expand Up @@ -58,7 +59,9 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
.humanReadable(request.hasParam("human"))
.includeDefaults(renderDefaults)
.names(names);
getSettingsRequest.local(request.paramAsBoolean("local", getSettingsRequest.local()));
return channel -> client.admin().indices().getSettings(getSettingsRequest, new RestRefCountedChunkedToXContentListener<>(channel));
RestUtils.consumeDeprecatedLocalParameter(request);
return channel -> new RestCancellableNodeClient(client, request.getHttpChannel()).admin()
.indices()
.getSettings(getSettingsRequest, new RestRefCountedChunkedToXContentListener<>(channel));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ public RestResponse buildResponse(Void ignored) throws Exception {
.indices()
.prepareGetSettings(masterNodeTimeout, indices)
.setIndicesOptions(indicesOptions)
.setMasterNodeTimeout(masterNodeTimeout)
.execute(listeners.acquire(indexSettingsRef::set));

// The other requests just provide additional detail, and wildcards may be resolved differently depending on the type of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.ActionTestUtils;
import org.elasticsearch.action.support.replication.ClusterStateCreationUtils;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.ProjectState;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.metadata.ProjectMetadata;
import org.elasticsearch.cluster.project.TestProjectResolvers;
Expand Down Expand Up @@ -59,20 +59,21 @@ class TestTransportGetSettingsAction extends TransportGetSettingsAction {
GetSettingsActionTests.this.threadPool,
settingsFilter,
new ActionFilters(Collections.emptySet()),
TestProjectResolvers.DEFAULT_PROJECT_ONLY,
new Resolver(),
IndexScopedSettings.DEFAULT_SCOPED_SETTINGS
);
}

@Override
protected void masterOperation(
protected void localClusterStateOperation(
Task task,
GetSettingsRequest request,
ClusterState state,
ProjectState state,
ActionListener<GetSettingsResponse> listener
) {
ClusterState stateWithIndex = ClusterStateCreationUtils.state(indexName, 1, 1);
super.masterOperation(task, request, stateWithIndex, listener);
ProjectState stateWithIndex = ClusterStateCreationUtils.state(indexName, 1, 1).projectState(state.projectId());
super.localClusterStateOperation(task, request, stateWithIndex, listener);
}
}

Expand Down
Loading
Loading