-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Faster GET _cluster/settings API (#86405)
The existing API to retrieve the cluster settings relies on pulling in the full cluster state, which can be very expensive. This change adds a dedicated cluster settings API, avoiding serializing the full cluster state. Co-authored-by: David Turner <david.turner@elastic.co>
- Loading branch information
1 parent
15ea957
commit 4b536c6
Showing
9 changed files
with
393 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pr: 86405 | ||
summary: Faster GET _cluster/settings API | ||
area: Infra/Core | ||
type: enhancement | ||
issues: | ||
- 82342 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
...c/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.cluster.settings; | ||
|
||
import org.elasticsearch.Version; | ||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.action.ActionResponse; | ||
import org.elasticsearch.action.ActionType; | ||
import org.elasticsearch.action.support.master.MasterNodeReadRequest; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.settings.Settings; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
public class ClusterGetSettingsAction extends ActionType<ClusterGetSettingsAction.Response> { | ||
|
||
public static final ClusterGetSettingsAction INSTANCE = new ClusterGetSettingsAction(); | ||
public static final String NAME = "cluster:monitor/settings"; | ||
|
||
public ClusterGetSettingsAction() { | ||
super(NAME, Response::new); | ||
} | ||
|
||
/** | ||
* Request to retrieve the cluster settings | ||
*/ | ||
public static class Request extends MasterNodeReadRequest<Request> { | ||
public Request() {} | ||
|
||
public Request(StreamInput in) throws IOException { | ||
super(in); | ||
assert in.getVersion().onOrAfter(Version.V_8_3_0); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
assert out.getVersion().onOrAfter(Version.V_8_3_0); | ||
super.writeTo(out); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Response for cluster settings | ||
*/ | ||
public static class Response extends ActionResponse { | ||
private final Settings persistentSettings; | ||
private final Settings transientSettings; | ||
private final Settings settings; | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Response response = (Response) o; | ||
return Objects.equals(persistentSettings, response.persistentSettings) | ||
&& Objects.equals(transientSettings, response.transientSettings) | ||
&& Objects.equals(settings, response.settings); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(persistentSettings, transientSettings, settings); | ||
} | ||
|
||
public Response(StreamInput in) throws IOException { | ||
super(in); | ||
assert in.getVersion().onOrAfter(Version.V_8_3_0); | ||
persistentSettings = Settings.readSettingsFromStream(in); | ||
transientSettings = Settings.readSettingsFromStream(in); | ||
settings = Settings.readSettingsFromStream(in); | ||
} | ||
|
||
public Response(Settings persistentSettings, Settings transientSettings, Settings settings) { | ||
this.persistentSettings = Objects.requireNonNullElse(persistentSettings, Settings.EMPTY); | ||
this.transientSettings = Objects.requireNonNullElse(transientSettings, Settings.EMPTY); | ||
this.settings = Objects.requireNonNullElse(settings, Settings.EMPTY); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
assert out.getVersion().onOrAfter(Version.V_8_3_0); | ||
Settings.writeSettingsToStream(persistentSettings, out); | ||
Settings.writeSettingsToStream(transientSettings, out); | ||
Settings.writeSettingsToStream(settings, out); | ||
} | ||
|
||
public Settings persistentSettings() { | ||
return persistentSettings; | ||
} | ||
|
||
public Settings transientSettings() { | ||
return transientSettings; | ||
} | ||
|
||
public Settings settings() { | ||
return settings; | ||
} | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...va/org/elasticsearch/action/admin/cluster/settings/TransportClusterGetSettingsAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.cluster.settings; | ||
|
||
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.cluster.block.ClusterBlockException; | ||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; | ||
import org.elasticsearch.cluster.metadata.Metadata; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.settings.SettingsFilter; | ||
import org.elasticsearch.tasks.Task; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.TransportService; | ||
|
||
public class TransportClusterGetSettingsAction extends TransportMasterNodeReadAction< | ||
ClusterGetSettingsAction.Request, | ||
ClusterGetSettingsAction.Response> { | ||
|
||
private final SettingsFilter settingsFilter; | ||
|
||
@Inject | ||
public TransportClusterGetSettingsAction( | ||
TransportService transportService, | ||
ClusterService clusterService, | ||
ThreadPool threadPool, | ||
SettingsFilter settingsFilter, | ||
ActionFilters actionFilters, | ||
IndexNameExpressionResolver indexNameExpressionResolver | ||
) { | ||
super( | ||
ClusterGetSettingsAction.NAME, | ||
false, | ||
transportService, | ||
clusterService, | ||
threadPool, | ||
actionFilters, | ||
ClusterGetSettingsAction.Request::new, | ||
indexNameExpressionResolver, | ||
ClusterGetSettingsAction.Response::new, | ||
ThreadPool.Names.SAME | ||
); | ||
|
||
this.settingsFilter = settingsFilter; | ||
} | ||
|
||
@Override | ||
protected void masterOperation( | ||
Task task, | ||
ClusterGetSettingsAction.Request request, | ||
ClusterState state, | ||
ActionListener<ClusterGetSettingsAction.Response> listener | ||
) throws Exception { | ||
Metadata metadata = state.metadata(); | ||
listener.onResponse( | ||
new ClusterGetSettingsAction.Response( | ||
settingsFilter.filter(metadata.persistentSettings()), | ||
settingsFilter.filter(metadata.transientSettings()), | ||
settingsFilter.filter(metadata.settings()) | ||
) | ||
); | ||
} | ||
|
||
@Override | ||
protected ClusterBlockException checkBlock(ClusterGetSettingsAction.Request request, ClusterState state) { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...org/elasticsearch/action/admin/cluster/settings/ClusterGetSettingsSerializationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.cluster.settings; | ||
|
||
import org.elasticsearch.common.io.stream.Writeable; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.test.AbstractWireSerializingTestCase; | ||
|
||
public class ClusterGetSettingsSerializationTests extends AbstractWireSerializingTestCase<ClusterGetSettingsAction.Response> { | ||
@Override | ||
protected Writeable.Reader<ClusterGetSettingsAction.Response> instanceReader() { | ||
return ClusterGetSettingsAction.Response::new; | ||
} | ||
|
||
@Override | ||
protected ClusterGetSettingsAction.Response createTestInstance() { | ||
final Settings persistentSettings = Settings.builder() | ||
.put("persistent.foo.filtered", "bar") | ||
.put("persistent.foo.non_filtered", "baz") | ||
.build(); | ||
|
||
final Settings transientSettings = Settings.builder() | ||
.put("transient.foo.filtered", "bar") | ||
.put("transient.foo.non_filtered", "baz") | ||
.build(); | ||
|
||
final Settings allSettings = Settings.builder().put(persistentSettings).put(transientSettings).build(); | ||
|
||
return new ClusterGetSettingsAction.Response(persistentSettings, transientSettings, allSettings); | ||
} | ||
|
||
@Override | ||
protected ClusterGetSettingsAction.Response mutateInstance(ClusterGetSettingsAction.Response instance) { | ||
final Settings otherSettings = Settings.builder().put("random.setting", randomAlphaOfLength(randomIntBetween(1, 12))).build(); | ||
return switch (between(0, 2)) { | ||
case 0 -> new ClusterGetSettingsAction.Response(otherSettings, instance.transientSettings(), instance.settings()); | ||
case 1 -> new ClusterGetSettingsAction.Response(instance.persistentSettings(), otherSettings, instance.settings()); | ||
case 2 -> new ClusterGetSettingsAction.Response(instance.persistentSettings(), instance.transientSettings(), otherSettings); | ||
default -> throw new IllegalStateException("Unexpected switch value"); | ||
}; | ||
} | ||
} |
Oops, something went wrong.