-
Notifications
You must be signed in to change notification settings - Fork 25.6k
New per-project only settings can be defined and used by components #127252
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
Changes from 4 commits
7a5d446
6eedbb4
a7ab20d
0c45219
20732ae
671ae16
efebd32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 127252 | ||
| summary: New per-project only settings can be defined and used by components | ||
| area: Infra/Settings | ||
| type: feature | ||
| issues: [] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,6 +102,8 @@ public class ProjectMetadata implements Iterable<IndexMetadata>, Diffable<Projec | |
| private volatile SortedMap<String, IndexAbstraction> indicesLookup; | ||
| private final Map<String, MappingMetadata> mappingsByHash; | ||
|
|
||
| private final Settings settings; | ||
|
|
||
| private final IndexVersion oldestIndexVersion; | ||
|
|
||
| @SuppressWarnings("this-escape") | ||
|
|
@@ -122,6 +124,7 @@ private ProjectMetadata( | |
| String[] visibleClosedIndices, | ||
| SortedMap<String, IndexAbstraction> indicesLookup, | ||
| Map<String, MappingMetadata> mappingsByHash, | ||
| Settings settings, | ||
| IndexVersion oldestIndexVersion | ||
| ) { | ||
| this.id = id; | ||
|
|
@@ -140,6 +143,7 @@ private ProjectMetadata( | |
| this.visibleClosedIndices = visibleClosedIndices; | ||
| this.indicesLookup = indicesLookup; | ||
| this.mappingsByHash = mappingsByHash; | ||
| this.settings = settings; | ||
| this.oldestIndexVersion = oldestIndexVersion; | ||
| assert assertConsistent(); | ||
| } | ||
|
|
@@ -221,6 +225,7 @@ public ProjectMetadata withLifecycleState(Index index, LifecycleExecutionState l | |
| visibleClosedIndices, | ||
| indicesLookup, | ||
| mappingsByHash, | ||
| settings, | ||
| oldestIndexVersion | ||
| ); | ||
| } | ||
|
|
@@ -254,6 +259,7 @@ public ProjectMetadata withIndexSettingsUpdates(Map<Index, Settings> updates) { | |
| visibleClosedIndices, | ||
| indicesLookup, | ||
| mappingsByHash, | ||
| settings, | ||
| oldestIndexVersion | ||
| ); | ||
| } | ||
|
|
@@ -288,6 +294,7 @@ public ProjectMetadata withAllocationAndTermUpdatesOnly(Map<String, IndexMetadat | |
| visibleClosedIndices, | ||
| indicesLookup, | ||
| mappingsByHash, | ||
| settings, | ||
| oldestIndexVersion | ||
| ); | ||
| } | ||
|
|
@@ -376,6 +383,7 @@ public ProjectMetadata withAddedIndex(IndexMetadata index) { | |
| updatedVisibleClosedIndices, | ||
| null, | ||
| updatedMappingsByHash, | ||
| settings, | ||
| IndexVersion.min(index.getCompatibilityVersion(), oldestIndexVersion) | ||
| ); | ||
| } | ||
|
|
@@ -727,6 +735,10 @@ public Map<String, IndexTemplateMetadata> templates() { | |
| return templates; | ||
| } | ||
|
|
||
| public Settings settings() { | ||
| return settings; | ||
| } | ||
|
|
||
| /** | ||
| * Checks whether the provided index is a data stream. | ||
| */ | ||
|
|
@@ -1130,6 +1142,7 @@ public static class Builder { | |
| private final ImmutableOpenMap.Builder<String, IndexTemplateMetadata> templates; | ||
| private final ImmutableOpenMap.Builder<String, Metadata.ProjectCustom> customs; | ||
| private final ImmutableOpenMap.Builder<String, ReservedStateMetadata> reservedStateMetadata; | ||
| private Settings settings = Settings.EMPTY; | ||
|
|
||
| private SortedMap<String, IndexAbstraction> previousIndicesLookup; | ||
|
|
||
|
|
@@ -1147,6 +1160,7 @@ public static class Builder { | |
| this.templates = ImmutableOpenMap.builder(projectMetadata.templates); | ||
| this.customs = ImmutableOpenMap.builder(projectMetadata.customs); | ||
| this.reservedStateMetadata = ImmutableOpenMap.builder(projectMetadata.reservedStateMetadata); | ||
| this.settings = projectMetadata.settings; | ||
| this.previousIndicesLookup = projectMetadata.indicesLookup; | ||
| this.mappingsByHash = new HashMap<>(projectMetadata.mappingsByHash); | ||
| this.checkForUnusedMappings = false; | ||
|
|
@@ -1525,6 +1539,15 @@ public Builder removeReservedState(ReservedStateMetadata metadata) { | |
| return this; | ||
| } | ||
|
|
||
| public Settings settings() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having accessor methods on
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done: #127280 |
||
| return this.settings; | ||
| } | ||
|
|
||
| public ProjectMetadata.Builder settings(Settings settings) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: no need to qualify this here. We can just use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done: #127280 |
||
| this.settings = settings; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder indexGraveyard(final IndexGraveyard indexGraveyard) { | ||
| return putCustom(IndexGraveyard.TYPE, indexGraveyard); | ||
| } | ||
|
|
@@ -1684,6 +1707,7 @@ public ProjectMetadata build(boolean skipNameCollisionChecks) { | |
| visibleClosedIndicesArray, | ||
| indicesLookup, | ||
| Collections.unmodifiableMap(mappingsByHash), | ||
| settings, | ||
| IndexVersion.fromId(oldestIndexVersionId) | ||
| ); | ||
| } | ||
|
|
@@ -2110,6 +2134,9 @@ public static ProjectMetadata fromXContent(XContentParser parser) throws IOExcep | |
| projectBuilder.put(IndexTemplateMetadata.Builder.fromXContent(parser, parser.currentName())); | ||
| } | ||
| } | ||
| case "settings" -> { | ||
| projectBuilder.settings(Settings.fromXContent(parser)); | ||
| } | ||
| default -> Metadata.Builder.parseCustomObject( | ||
| parser, | ||
| currentFieldName, | ||
|
|
@@ -2157,7 +2184,8 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params p) { | |
| customs, | ||
| multiProject | ||
| ? ChunkedToXContentHelper.object("reserved_state", reservedStateMetadata().values().iterator()) | ||
| : Collections.emptyIterator() | ||
| : Collections.emptyIterator(), | ||
| multiProject ? ChunkedToXContentHelper.object("settings", Iterators.single(settings)) : Collections.emptyIterator() | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -2189,6 +2217,10 @@ public static ProjectMetadata readFrom(StreamInput in) throws IOException { | |
| builder.put(ReservedStateMetadata.readFrom(in)); | ||
| } | ||
|
|
||
| if (in.getTransportVersion().onOrAfter(TransportVersions.PROJECT_METADATA_SETTINGS)) { | ||
| builder.settings(Settings.readSettingsFromStream(in)); | ||
| } | ||
|
|
||
| return builder.build(); | ||
| } | ||
|
|
||
|
|
@@ -2229,6 +2261,10 @@ public void writeTo(StreamOutput out) throws IOException { | |
| } | ||
| VersionedNamedWriteable.writeVersionedWriteables(out, filteredCustoms); | ||
| out.writeCollection(reservedStateMetadata.values()); | ||
|
|
||
| if (out.getTransportVersion().onOrAfter(TransportVersions.PROJECT_METADATA_SETTINGS)) { | ||
| settings.writeTo(out); | ||
| } | ||
| } | ||
|
|
||
| // this needs to be package accessible for bwc serialization in Metadata.java | ||
|
|
@@ -2248,13 +2284,15 @@ static class ProjectMetadataDiff implements Diff<ProjectMetadata> { | |
| String, | ||
| ReservedStateMetadata, | ||
| ImmutableOpenMap<String, ReservedStateMetadata>> reservedStateMetadata; | ||
| private final Diff<Settings> settingsDiff; | ||
|
|
||
| private ProjectMetadataDiff(ProjectMetadata before, ProjectMetadata after) { | ||
| if (before == after) { | ||
| indices = DiffableUtils.emptyDiff(); | ||
| templates = DiffableUtils.emptyDiff(); | ||
| customs = DiffableUtils.emptyDiff(); | ||
| reservedStateMetadata = DiffableUtils.emptyDiff(); | ||
| settingsDiff = Settings.EMPTY_DIFF; | ||
| } else { | ||
| indices = DiffableUtils.diff(before.indices, after.indices, DiffableUtils.getStringKeySerializer()); | ||
| templates = DiffableUtils.diff(before.templates, after.templates, DiffableUtils.getStringKeySerializer()); | ||
|
|
@@ -2269,19 +2307,22 @@ private ProjectMetadataDiff(ProjectMetadata before, ProjectMetadata after) { | |
| after.reservedStateMetadata, | ||
| DiffableUtils.getStringKeySerializer() | ||
| ); | ||
| settingsDiff = after.settings.diff(before.settings); | ||
| } | ||
| } | ||
|
|
||
| ProjectMetadataDiff( | ||
| DiffableUtils.MapDiff<String, IndexMetadata, ImmutableOpenMap<String, IndexMetadata>> indices, | ||
| DiffableUtils.MapDiff<String, IndexTemplateMetadata, ImmutableOpenMap<String, IndexTemplateMetadata>> templates, | ||
| DiffableUtils.MapDiff<String, Metadata.ProjectCustom, ImmutableOpenMap<String, Metadata.ProjectCustom>> customs, | ||
| DiffableUtils.MapDiff<String, ReservedStateMetadata, ImmutableOpenMap<String, ReservedStateMetadata>> reservedStateMetadata | ||
| DiffableUtils.MapDiff<String, ReservedStateMetadata, ImmutableOpenMap<String, ReservedStateMetadata>> reservedStateMetadata, | ||
| Diff<Settings> settingsDiff | ||
| ) { | ||
| this.indices = indices; | ||
| this.templates = templates; | ||
| this.customs = customs; | ||
| this.reservedStateMetadata = reservedStateMetadata; | ||
| this.settingsDiff = settingsDiff; | ||
| } | ||
|
|
||
| ProjectMetadataDiff(StreamInput in) throws IOException { | ||
|
|
@@ -2293,6 +2334,11 @@ private ProjectMetadataDiff(ProjectMetadata before, ProjectMetadata after) { | |
| DiffableUtils.getStringKeySerializer(), | ||
| RESERVED_DIFF_VALUE_READER | ||
| ); | ||
| if (in.getTransportVersion().onOrAfter(TransportVersions.PROJECT_METADATA_SETTINGS)) { | ||
| settingsDiff = Settings.readSettingsDiffFromStream(in); | ||
| } else { | ||
| settingsDiff = Settings.EMPTY_DIFF; | ||
| } | ||
| } | ||
|
|
||
| Diff<ImmutableOpenMap<String, IndexMetadata>> indices() { | ||
|
|
@@ -2317,11 +2363,18 @@ public void writeTo(StreamOutput out) throws IOException { | |
| templates.writeTo(out); | ||
| customs.writeTo(out); | ||
| reservedStateMetadata.writeTo(out); | ||
| if (out.getTransportVersion().onOrAfter(TransportVersions.PROJECT_METADATA_SETTINGS)) { | ||
| settingsDiff.writeTo(out); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public ProjectMetadata apply(ProjectMetadata part) { | ||
| if (indices.isEmpty() && templates.isEmpty() && customs.isEmpty() && reservedStateMetadata.isEmpty()) { | ||
| if (indices.isEmpty() | ||
| && templates.isEmpty() | ||
| && customs.isEmpty() | ||
| && reservedStateMetadata.isEmpty() | ||
| && settingsDiff == Settings.EMPTY_DIFF) { | ||
| // nothing to do | ||
| return part; | ||
| } | ||
|
|
@@ -2336,13 +2389,14 @@ public ProjectMetadata apply(ProjectMetadata part) { | |
| && builder.dataStreamMetadata() == part.custom(DataStreamMetadata.TYPE, DataStreamMetadata.EMPTY)) { | ||
| builder.previousIndicesLookup = part.indicesLookup; | ||
| } | ||
| builder.settings = settingsDiff.apply(builder.settings); | ||
| return builder.build(true); | ||
| } | ||
|
|
||
| ProjectMetadataDiff withCustoms( | ||
| DiffableUtils.MapDiff<String, Metadata.ProjectCustom, ImmutableOpenMap<String, Metadata.ProjectCustom>> customs | ||
| ) { | ||
| return new ProjectMetadataDiff(indices, templates, customs, reservedStateMetadata); | ||
| return new ProjectMetadataDiff(indices, templates, customs, reservedStateMetadata, settingsDiff); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* | ||
| * 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.common.settings; | ||
|
|
||
| import java.util.Set; | ||
|
|
||
| public class ProjectScopedSettings extends AbstractScopedSettings { | ||
| public ProjectScopedSettings(Settings settings, Set<Setting<?>> settingsSet) { | ||
| super(settings, settingsSet, Setting.Property.ProjectScope); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't designed to be user-facing, so I wouldn't flag this as a feature for inclusion in release notes.