From 2475a25b1184f3df3718daeef615e8b7eb020dca Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Sun, 10 Oct 2021 21:49:06 +0200 Subject: [PATCH] Introduce a Few Settings Singleton Instances This is mostly motivated by the ILM steps changes, that showed up as hot in profiling since instantiating a `Settings` instance turns out to be somewhat expensive. Also cleans up a couple of other spots and some duplication as well. --- .../client/indices/CreateIndexRequest.java | 4 +- .../client/indices/IndexTemplateMetadata.java | 2 +- .../indices/PutIndexTemplateRequest.java | 4 +- .../recovery/SimpleRecoveryIT.java | 2 +- .../put/PutRepositoryRequest.java | 3 +- .../ClusterUpdateSettingsRequest.java | 5 +- .../restore/RestoreSnapshotRequest.java | 3 +- .../CreateIndexClusterStateUpdateRequest.java | 2 +- .../indices/create/CreateIndexRequest.java | 5 +- .../rollover/MetadataRolloverService.java | 4 +- .../settings/put/UpdateSettingsRequest.java | 3 +- .../template/put/PutIndexTemplateRequest.java | 3 +- .../cluster/metadata/IndexMetadata.java | 2 +- .../metadata/IndexTemplateMetadata.java | 2 +- .../cluster/metadata/Metadata.java | 4 +- .../MetadataCreateDataStreamService.java | 4 +- .../MetadataIndexTemplateService.java | 2 +- .../cluster/routing/allocation/DataTier.java | 46 ++++++++++++++++--- .../allocation/DiskThresholdMonitor.java | 10 ++-- .../common/settings/Settings.java | 2 - .../index/analysis/AnalysisRegistry.java | 2 +- .../org/elasticsearch/plugins/Plugin.java | 2 +- .../allocation/BalanceConfigurationTests.java | 2 +- .../index/IndexSortSettingsTests.java | 3 +- .../index/MergePolicySettingsTests.java | 5 +- .../cluster/ESAllocationTestCase.java | 2 +- .../analysis/MyFilterTokenFilterFactory.java | 2 +- .../xpack/core/ilm/ForceMergeAction.java | 13 +++--- .../xpack/core/ilm/MigrateAction.java | 6 +-- .../xpack/core/ilm/RolloverAction.java | 6 +-- .../xpack/core/ilm/SetPriorityAction.java | 5 +- .../rollup/v2/TransportRollupAction.java | 13 +++--- 32 files changed, 100 insertions(+), 73 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/CreateIndexRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/CreateIndexRequest.java index 3e979b26e1ac4..758eb480935cb 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/CreateIndexRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/CreateIndexRequest.java @@ -36,8 +36,6 @@ import java.util.Objects; import java.util.Set; -import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS; - /** * A request to create an index. */ @@ -47,7 +45,7 @@ public class CreateIndexRequest extends TimedRequest implements Validatable, ToX static final ParseField ALIASES = new ParseField("aliases"); private final String index; - private Settings settings = EMPTY_SETTINGS; + private Settings settings = Settings.EMPTY; private BytesReference mappings; private XContentType mappingsXContentType; diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/IndexTemplateMetadata.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/IndexTemplateMetadata.java index 3733a712d3d4e..1017986beb544 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/IndexTemplateMetadata.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/IndexTemplateMetadata.java @@ -178,7 +178,7 @@ public static class Builder { private List indexPatterns; - private Settings settings = Settings.Builder.EMPTY_SETTINGS; + private Settings settings = Settings.EMPTY; private MappingMetadata mappings; diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/PutIndexTemplateRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/PutIndexTemplateRequest.java index 76f4e4d1ec136..0bf518501e476 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/PutIndexTemplateRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/PutIndexTemplateRequest.java @@ -36,8 +36,6 @@ import java.util.Set; import java.util.stream.Collectors; -import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS; - /** * A request to create an index template. */ @@ -53,7 +51,7 @@ public class PutIndexTemplateRequest extends TimedRequest implements ToXContentF private boolean create; - private Settings settings = EMPTY_SETTINGS; + private Settings settings = Settings.EMPTY; private BytesReference mappings = null; diff --git a/server/src/internalClusterTest/java/org/elasticsearch/recovery/SimpleRecoveryIT.java b/server/src/internalClusterTest/java/org/elasticsearch/recovery/SimpleRecoveryIT.java index 26da1657631f5..8231c733e08ce 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/recovery/SimpleRecoveryIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/recovery/SimpleRecoveryIT.java @@ -29,7 +29,7 @@ public Settings indexSettings() { } protected Settings recoverySettings() { - return Settings.Builder.EMPTY_SETTINGS; + return Settings.EMPTY; } @Override diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryRequest.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryRequest.java index 3aa500403062c..00acf3d04b83d 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryRequest.java @@ -21,7 +21,6 @@ import java.util.Map; import static org.elasticsearch.action.ValidateActions.addValidationError; -import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS; import static org.elasticsearch.common.settings.Settings.readSettingsFromStream; import static org.elasticsearch.common.settings.Settings.writeSettingsToStream; @@ -39,7 +38,7 @@ public class PutRepositoryRequest extends AcknowledgedRequest r.transientSettings = t, (p, c) -> Settings.fromXContent(p), TRANSIENT); } - private Settings transientSettings = EMPTY_SETTINGS; - private Settings persistentSettings = EMPTY_SETTINGS; + private Settings transientSettings = Settings.EMPTY; + private Settings persistentSettings = Settings.EMPTY; public ClusterUpdateSettingsRequest(StreamInput in) throws IOException { super(in); diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java index b22ec18234e1c..8eb5f6d48ecc2 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java @@ -28,7 +28,6 @@ import java.util.Objects; import static org.elasticsearch.action.ValidateActions.addValidationError; -import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS; import static org.elasticsearch.common.settings.Settings.readSettingsFromStream; import static org.elasticsearch.common.settings.Settings.writeSettingsToStream; import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBooleanValue; @@ -49,7 +48,7 @@ public class RestoreSnapshotRequest extends MasterNodeRequest private String index; - private Settings settings = EMPTY_SETTINGS; + private Settings settings = Settings.EMPTY; private String mappings = "{}"; @@ -116,7 +115,7 @@ public CreateIndexRequest() { * @param index the name of the index */ public CreateIndexRequest(String index) { - this(index, EMPTY_SETTINGS); + this(index, Settings.EMPTY); } /** diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/MetadataRolloverService.java b/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/MetadataRolloverService.java index ef0586717ad87..c0354d0f404ee 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/MetadataRolloverService.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/MetadataRolloverService.java @@ -53,6 +53,8 @@ public class MetadataRolloverService { private static final Pattern INDEX_NAME_PATTERN = Pattern.compile("^.*-\\d+$"); private static final List VALID_ROLLOVER_TARGETS = List.of(ALIAS, DATA_STREAM); + public static final Settings HIDDEN_INDEX_SETTINGS = Settings.builder().put(IndexMetadata.SETTING_INDEX_HIDDEN, true).build(); + private final ThreadPool threadPool; private final MetadataCreateIndexService createIndexService; private final MetadataIndexAliasesService indexAliasesService; @@ -272,7 +274,7 @@ static CreateIndexClusterStateUpdateRequest prepareDataStreamCreateIndexRequest( final String targetIndexName, CreateIndexRequest createIndexRequest, final SystemDataStreamDescriptor descriptor) { - Settings settings = descriptor != null ? Settings.EMPTY : Settings.builder().put("index.hidden", true).build(); + Settings settings = descriptor != null ? Settings.EMPTY : HIDDEN_INDEX_SETTINGS; return prepareCreateIndexRequest(targetIndexName, targetIndexName, "rollover_data_stream", createIndexRequest, settings) .dataStreamName(dataStreamName) .systemDataStreamDescriptor(descriptor); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java index f2e5a17ef1800..810b00e78e16b 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsRequest.java @@ -31,7 +31,6 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; import static org.elasticsearch.common.settings.Settings.readSettingsFromStream; import static org.elasticsearch.common.settings.Settings.writeSettingsToStream; -import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS; /** * Request for an update index settings action @@ -43,7 +42,7 @@ public class UpdateSettingsRequest extends AcknowledgedRequest mappings; private final ImmutableOpenMap.Builder aliases; private final ImmutableOpenMap.Builder customMetadata; diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetadata.java index e817a9c47af3e..a3237bb47791d 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetadata.java @@ -245,7 +245,7 @@ public static class Builder { private List indexPatterns; - private Settings settings = Settings.Builder.EMPTY_SETTINGS; + private Settings settings = Settings.EMPTY; private final ImmutableOpenMap.Builder mappings; diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/Metadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/Metadata.java index d00d3dd27d9af..754ff3511eecc 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/Metadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/Metadata.java @@ -1029,8 +1029,8 @@ public static class Builder { private long version; private CoordinationMetadata coordinationMetadata = CoordinationMetadata.EMPTY_METADATA; - private Settings transientSettings = Settings.Builder.EMPTY_SETTINGS; - private Settings persistentSettings = Settings.Builder.EMPTY_SETTINGS; + private Settings transientSettings = Settings.EMPTY; + private Settings persistentSettings = Settings.EMPTY; private DiffableStringMap hashesOfConsistentSettings = DiffableStringMap.EMPTY; private final ImmutableOpenMap.Builder indices; diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateDataStreamService.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateDataStreamService.java index afa88ec61e729..0521937047981 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateDataStreamService.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateDataStreamService.java @@ -13,6 +13,7 @@ import org.elasticsearch.ResourceAlreadyExistsException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.create.CreateIndexClusterStateUpdateRequest; +import org.elasticsearch.action.admin.indices.rollover.MetadataRolloverService; import org.elasticsearch.action.support.ActiveShardCount; import org.elasticsearch.action.support.ActiveShardsObserver; import org.elasticsearch.action.support.master.AcknowledgedResponse; @@ -22,7 +23,6 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Priority; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.core.TimeValue; import org.elasticsearch.index.Index; import org.elasticsearch.index.mapper.DataStreamTimestampFieldMapper; @@ -195,7 +195,7 @@ static ClusterState createDataStream(MetadataCreateIndexService metadataCreateIn .systemDataStreamDescriptor(systemDataStreamDescriptor); if (isSystem == false) { - createIndexRequest.settings(Settings.builder().put("index.hidden", true).build()); + createIndexRequest.settings(MetadataRolloverService.HIDDEN_INDEX_SETTINGS); } try { diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java index 5da664fae55f3..1b928f81cebd0 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java @@ -1424,7 +1424,7 @@ public static class PutRequest { int order; Integer version; List indexPatterns; - Settings settings = Settings.Builder.EMPTY_SETTINGS; + Settings settings = Settings.EMPTY; String mappings = null; List aliases = new ArrayList<>(); diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/DataTier.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/DataTier.java index 34bda24bde330..9a1ab49f55748 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/DataTier.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/DataTier.java @@ -21,12 +21,12 @@ import org.elasticsearch.snapshots.SearchableSnapshotsSettings; import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.Function; -import java.util.stream.Collectors; /** * The {@code DataTier} class encapsulates the formalization of the "content", @@ -46,6 +46,12 @@ public class DataTier { public static final String TIER_PREFERENCE = "index.routing.allocation.include._tier_preference"; + private static final Settings DATA_CONTENT_TIER_PREFERENCE_SETTINGS = Settings.builder().put(TIER_PREFERENCE, DATA_CONTENT).build(); + + private static final Settings DATA_HOT_TIER_PREFERENCE_SETTINGS = Settings.builder().put(TIER_PREFERENCE, DATA_HOT).build(); + + private static final Settings NULL_TIER_PREFERENCE_SETTINGS = Settings.builder().putNull(TIER_PREFERENCE).build(); + public static final Setting TIER_PREFERENCE_SETTING = new Setting<>( new Setting.SimpleKey(TIER_PREFERENCE), DataTierSettingValidator::getDefaultTierPreference, @@ -66,6 +72,24 @@ public class DataTier { // Represents an ordered list of data tiers from frozen to hot (or slow to fast) private static final List ORDERED_FROZEN_TO_HOT_TIERS = List.of(DATA_FROZEN, DATA_COLD, DATA_WARM, DATA_HOT); + private static final Map PREFERENCE_TIER_CONFIGURATIONS; + + private static final Map PREFERENCE_TIER_CONFIGURATION_SETTINGS; + + static { + final Map tmp = new HashMap<>(); + final Map tmpSettings = new HashMap<>(); + for (int i = 0, ordered_frozen_to_hot_tiersSize = ORDERED_FROZEN_TO_HOT_TIERS.size(); i < ordered_frozen_to_hot_tiersSize; i++) { + String tier = ORDERED_FROZEN_TO_HOT_TIERS.get(i); + final String prefTierString = + String.join(",", ORDERED_FROZEN_TO_HOT_TIERS.subList(i, ORDERED_FROZEN_TO_HOT_TIERS.size())).intern(); + tmp.put(tier, prefTierString); + tmpSettings.put(tier, Settings.builder().put(DataTier.TIER_PREFERENCE, prefTierString).build()); + } + PREFERENCE_TIER_CONFIGURATIONS = Map.copyOf(tmp); + PREFERENCE_TIER_CONFIGURATION_SETTINGS = Map.copyOf(tmpSettings); + } + /** * Returns true if the given tier name is a valid tier */ @@ -79,11 +103,19 @@ public static boolean validTierName(String tierName) { * This is usually used in conjunction with {@link #TIER_PREFERENCE_SETTING}. */ public static String getPreferredTiersConfiguration(String targetTier) { - int indexOfTargetTier = ORDERED_FROZEN_TO_HOT_TIERS.indexOf(targetTier); - if (indexOfTargetTier == -1) { + final String res = PREFERENCE_TIER_CONFIGURATIONS.get(targetTier); + if (res == null) { + throw new IllegalArgumentException("invalid data tier [" + targetTier + "]"); + } + return res; + } + + public static Settings getPreferredTiersConfigurationSettings(String targetTier) { + final Settings res = PREFERENCE_TIER_CONFIGURATION_SETTINGS.get(targetTier); + if (res == null) { throw new IllegalArgumentException("invalid data tier [" + targetTier + "]"); } - return ORDERED_FROZEN_TO_HOT_TIERS.stream().skip(indexOfTargetTier).collect(Collectors.joining(",")); + return res; } /** @@ -155,7 +187,7 @@ public Settings getAdditionalIndexSettings(String indexName, boolean isDataStrea Set settings = indexSettings.keySet(); if (settings.contains(TIER_PREFERENCE)) { // just a marker -- this null value will be removed or overridden by the template/request settings - return Settings.builder().putNull(TIER_PREFERENCE).build(); + return NULL_TIER_PREFERENCE_SETTINGS; } else if (settings.stream().anyMatch(s -> s.startsWith(IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_PREFIX + ".")) || settings.stream().anyMatch(s -> s.startsWith(IndexMetadata.INDEX_ROUTING_EXCLUDE_GROUP_PREFIX + ".")) || settings.stream().anyMatch(s -> s.startsWith(IndexMetadata.INDEX_ROUTING_INCLUDE_GROUP_PREFIX + "."))) { @@ -167,9 +199,9 @@ public Settings getAdditionalIndexSettings(String indexName, boolean isDataStrea // tier if the index is part of a data stream, the "content" // tier if it is not. if (isDataStreamIndex) { - return Settings.builder().put(TIER_PREFERENCE, DATA_HOT).build(); + return DATA_HOT_TIER_PREFERENCE_SETTINGS; } else { - return Settings.builder().put(TIER_PREFERENCE, DATA_CONTENT).build(); + return DATA_CONTENT_TIER_PREFERENCE_SETTINGS; } } } diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/DiskThresholdMonitor.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/DiskThresholdMonitor.java index cf10c7f268d0b..26805e0175de6 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/DiskThresholdMonitor.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/DiskThresholdMonitor.java @@ -56,6 +56,12 @@ public class DiskThresholdMonitor { private static final Logger logger = LogManager.getLogger(DiskThresholdMonitor.class); + private static final Settings READ_ONLY_ALLOW_DELETE_SETTINGS = Settings.builder() + .put(IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE, Boolean.TRUE.toString()).build(); + + private static final Settings NOT_READ_ONLY_ALLOW_DELETE_SETTINGS = + Settings.builder().putNull(IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE).build(); + private final DiskThresholdSettings diskThresholdSettings; private final Client client; private final Supplier clusterStateSupplier; @@ -351,9 +357,7 @@ protected void updateIndicesReadOnly(Set indicesToUpdate, ActionListener setLastRunTimeMillis(); listener.onFailure(e); }); - Settings readOnlySettings = readOnly ? Settings.builder() - .put(IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE, Boolean.TRUE.toString()).build() : - Settings.builder().putNull(IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE).build(); + Settings readOnlySettings = readOnly ? READ_ONLY_ALLOW_DELETE_SETTINGS : NOT_READ_ONLY_ALLOW_DELETE_SETTINGS; client.admin().indices().prepareUpdateSettings(indicesToUpdate.toArray(Strings.EMPTY_ARRAY)) .setSettings(readOnlySettings) .execute(wrappedListener.map(r -> null)); diff --git a/server/src/main/java/org/elasticsearch/common/settings/Settings.java b/server/src/main/java/org/elasticsearch/common/settings/Settings.java index f0944017818ad..4596aca5383c4 100644 --- a/server/src/main/java/org/elasticsearch/common/settings/Settings.java +++ b/server/src/main/java/org/elasticsearch/common/settings/Settings.java @@ -731,8 +731,6 @@ public Set keySet() { */ public static class Builder { - public static final Settings EMPTY_SETTINGS = new Builder().build(); - // we use a sorted map for consistent serialization when using getAsMap() private final Map map = new TreeMap<>(); diff --git a/server/src/main/java/org/elasticsearch/index/analysis/AnalysisRegistry.java b/server/src/main/java/org/elasticsearch/index/analysis/AnalysisRegistry.java index e81f02ea6a36c..991976a267077 100644 --- a/server/src/main/java/org/elasticsearch/index/analysis/AnalysisRegistry.java +++ b/server/src/main/java/org/elasticsearch/index/analysis/AnalysisRegistry.java @@ -532,7 +532,7 @@ public IndexAnalyzers build(IndexSettings indexSettings, if (analyzers.containsKey(DEFAULT_ANALYZER_NAME) == false) { analyzers.put(DEFAULT_ANALYZER_NAME, produceAnalyzer(DEFAULT_ANALYZER_NAME, - new StandardAnalyzerProvider(indexSettings, null, DEFAULT_ANALYZER_NAME, Settings.Builder.EMPTY_SETTINGS), + new StandardAnalyzerProvider(indexSettings, null, DEFAULT_ANALYZER_NAME, Settings.EMPTY), tokenFilterFactoryFactories, charFilterFactoryFactories, tokenizerFactoryFactories)); } NamedAnalyzer defaultAnalyzer = analyzers.get(DEFAULT_ANALYZER_NAME); diff --git a/server/src/main/java/org/elasticsearch/plugins/Plugin.java b/server/src/main/java/org/elasticsearch/plugins/Plugin.java index 88b0180b3b304..581b64c2e1b30 100644 --- a/server/src/main/java/org/elasticsearch/plugins/Plugin.java +++ b/server/src/main/java/org/elasticsearch/plugins/Plugin.java @@ -93,7 +93,7 @@ public Collection createComponents(Client client, ClusterService cluster * overwritten with the additional settings. These settings added if they don't exist. */ public Settings additionalSettings() { - return Settings.Builder.EMPTY_SETTINGS; + return Settings.EMPTY; } /** diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceConfigurationTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceConfigurationTests.java index a82749ca53432..4eccd82807a33 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceConfigurationTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceConfigurationTests.java @@ -264,7 +264,7 @@ public void testPersistedSettings() { public void testNoRebalanceOnPrimaryOverload() { Settings.Builder settings = Settings.builder(); AllocationService strategy = new AllocationService(randomAllocationDeciders(settings.build(), - new ClusterSettings(Settings.Builder.EMPTY_SETTINGS, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), random()), + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), random()), new TestGatewayAllocator(), new ShardsAllocator() { /* * // this allocator tries to rebuild this scenario where a rebalance is diff --git a/server/src/test/java/org/elasticsearch/index/IndexSortSettingsTests.java b/server/src/test/java/org/elasticsearch/index/IndexSortSettingsTests.java index 00b0a8f8e164d..56d638cfc72df 100644 --- a/server/src/test/java/org/elasticsearch/index/IndexSortSettingsTests.java +++ b/server/src/test/java/org/elasticsearch/index/IndexSortSettingsTests.java @@ -28,7 +28,6 @@ import java.util.Collections; import java.util.function.Supplier; -import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS; import static org.elasticsearch.index.IndexSettingsTests.newIndexMeta; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; @@ -40,7 +39,7 @@ private static IndexSettings indexSettings(Settings settings) { } public void testNoIndexSort() { - IndexSettings indexSettings = indexSettings(EMPTY_SETTINGS); + IndexSettings indexSettings = indexSettings(Settings.EMPTY); assertFalse(indexSettings.getIndexSortConfig().hasIndexSort()); } diff --git a/server/src/test/java/org/elasticsearch/index/MergePolicySettingsTests.java b/server/src/test/java/org/elasticsearch/index/MergePolicySettingsTests.java index 5396b0b880b49..0ac4001546953 100644 --- a/server/src/test/java/org/elasticsearch/index/MergePolicySettingsTests.java +++ b/server/src/test/java/org/elasticsearch/index/MergePolicySettingsTests.java @@ -16,7 +16,6 @@ import java.io.IOException; -import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS; import static org.elasticsearch.index.IndexSettingsTests.newIndexMeta; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; @@ -54,7 +53,7 @@ public void testNoMerges() { } public void testUpdateSettings() throws IOException { - IndexSettings indexSettings = indexSettings(EMPTY_SETTINGS); + IndexSettings indexSettings = indexSettings(Settings.EMPTY); assertThat(indexSettings.getMergePolicy().getNoCFSRatio(), equalTo(0.1)); indexSettings = indexSettings(build(0.9)); assertThat((indexSettings.getMergePolicy()).getNoCFSRatio(), equalTo(0.9)); @@ -123,7 +122,7 @@ public void testTieredMergePolicySettingsUpdate() throws IOException { Settings.builder().put(MergePolicyConfig.INDEX_MERGE_POLICY_DELETES_PCT_ALLOWED_SETTING.getKey(), 53).build()))); final Throwable cause = exc.getCause(); assertThat(cause.getMessage(), containsString("must be <= 50.0")); - indexSettings.updateIndexMetadata(newIndexMeta("index", EMPTY_SETTINGS)); // see if defaults are restored + indexSettings.updateIndexMetadata(newIndexMeta("index", Settings.EMPTY)); // see if defaults are restored assertEquals(((EsTieredMergePolicy) indexSettings.getMergePolicy()).getForceMergeDeletesPctAllowed(), MergePolicyConfig.DEFAULT_EXPUNGE_DELETES_ALLOWED, 0.0d); assertEquals(((EsTieredMergePolicy) indexSettings.getMergePolicy()).getFloorSegmentMB(), diff --git a/test/framework/src/main/java/org/elasticsearch/cluster/ESAllocationTestCase.java b/test/framework/src/main/java/org/elasticsearch/cluster/ESAllocationTestCase.java index 1d6bc2b7b1dc6..4bbd085ab93f1 100644 --- a/test/framework/src/main/java/org/elasticsearch/cluster/ESAllocationTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/cluster/ESAllocationTestCase.java @@ -59,7 +59,7 @@ public Long getShardSize(ShardRouting shardRouting) { }; public static MockAllocationService createAllocationService() { - return createAllocationService(Settings.Builder.EMPTY_SETTINGS); + return createAllocationService(Settings.EMPTY); } public static MockAllocationService createAllocationService(Settings settings) { diff --git a/test/framework/src/main/java/org/elasticsearch/index/analysis/MyFilterTokenFilterFactory.java b/test/framework/src/main/java/org/elasticsearch/index/analysis/MyFilterTokenFilterFactory.java index c0bbeea51f3e0..388dac78f07db 100644 --- a/test/framework/src/main/java/org/elasticsearch/index/analysis/MyFilterTokenFilterFactory.java +++ b/test/framework/src/main/java/org/elasticsearch/index/analysis/MyFilterTokenFilterFactory.java @@ -17,7 +17,7 @@ public class MyFilterTokenFilterFactory extends AbstractTokenFilterFactory { public MyFilterTokenFilterFactory(IndexSettings indexSettings, Environment env, String name, Settings settings) { - super(indexSettings, name, Settings.Builder.EMPTY_SETTINGS); + super(indexSettings, name, Settings.EMPTY); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ForceMergeAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ForceMergeAction.java index a34f22fe6918d..ab29f891f2269 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ForceMergeAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ForceMergeAction.java @@ -35,6 +35,11 @@ public class ForceMergeAction implements LifecycleAction { private static final Logger logger = LogManager.getLogger(ForceMergeAction.class); + private static final Settings READ_ONLY_SETTINGS = Settings.builder().put(IndexMetadata.SETTING_BLOCKS_WRITE, true).build(); + + private static final Settings BEST_COMPRESSION_SETTINGS = + Settings.builder().put(EngineConfig.INDEX_CODEC_SETTING.getKey(), CodecService.BEST_COMPRESSION_CODEC).build(); + public static final String NAME = "forcemerge"; public static final ParseField MAX_NUM_SEGMENTS_FIELD = new ParseField("max_num_segments"); public static final ParseField CODEC = new ParseField("index_codec"); @@ -113,10 +118,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws @Override public List toSteps(Client client, String phase, Step.StepKey nextStepKey) { - Settings readOnlySettings = Settings.builder().put(IndexMetadata.SETTING_BLOCKS_WRITE, true).build(); - Settings bestCompressionSettings = Settings.builder() - .put(EngineConfig.INDEX_CODEC_SETTING.getKey(), CodecService.BEST_COMPRESSION_CODEC).build(); - final boolean codecChange = codec != null && codec.equals(CodecService.BEST_COMPRESSION_CODEC); StepKey preForceMergeBranchingKey = new StepKey(phase, NAME, CONDITIONAL_SKIP_FORCE_MERGE_STEP); @@ -146,11 +147,11 @@ public List toSteps(Client client, String phase, Step.StepKey nextStepKey) CheckNotDataStreamWriteIndexStep checkNotWriteIndexStep = new CheckNotDataStreamWriteIndexStep(checkNotWriteIndex, readOnlyKey); UpdateSettingsStep readOnlyStep = - new UpdateSettingsStep(readOnlyKey, codecChange ? closeKey : forceMergeKey, client, readOnlySettings); + new UpdateSettingsStep(readOnlyKey, codecChange ? closeKey : forceMergeKey, client, READ_ONLY_SETTINGS); CloseIndexStep closeIndexStep = new CloseIndexStep(closeKey, updateCompressionKey, client); UpdateSettingsStep updateBestCompressionSettings = new UpdateSettingsStep(updateCompressionKey, - openKey, client, bestCompressionSettings); + openKey, client, BEST_COMPRESSION_SETTINGS); OpenIndexStep openIndexStep = new OpenIndexStep(openKey, waitForGreenIndexKey, client); WaitForIndexColorStep waitForIndexGreenStep = new WaitForIndexColorStep(waitForGreenIndexKey, forceMergeKey, ClusterHealthStatus.GREEN); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/MigrateAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/MigrateAction.java index 4765d26c773ef..2210f03db46e5 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/MigrateAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/MigrateAction.java @@ -25,7 +25,7 @@ import java.util.List; import java.util.Objects; -import static org.elasticsearch.cluster.routing.allocation.DataTier.getPreferredTiersConfiguration; +import static org.elasticsearch.cluster.routing.allocation.DataTier.getPreferredTiersConfigurationSettings; /** * A {@link LifecycleAction} which enables or disables the automatic migration of data between @@ -115,9 +115,7 @@ public List toSteps(Client client, String phase, StepKey nextStepKey) { return false; }); UpdateSettingsStep updateMigrationSettingStep = new UpdateSettingsStep(migrationKey, migrationRoutedKey, client, - Settings.builder() - .put(DataTier.TIER_PREFERENCE, getPreferredTiersConfiguration(targetTier)) - .build()); + getPreferredTiersConfigurationSettings(targetTier)); DataTierMigrationRoutedStep migrationRoutedStep = new DataTierMigrationRoutedStep(migrationRoutedKey, nextStepKey); return List.of(conditionalSkipActionStep, updateMigrationSettingStep, migrationRoutedStep); } else { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverAction.java index f9b151361b091..038aec6477938 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverAction.java @@ -41,6 +41,8 @@ public class RolloverAction implements LifecycleAction { public static final Setting LIFECYCLE_ROLLOVER_ALIAS_SETTING = Setting.simpleString(LIFECYCLE_ROLLOVER_ALIAS, Setting.Property.Dynamic, Setting.Property.IndexScope); + private static final Settings INDEXING_COMPLETE = Settings.builder().put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, true).build(); + private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>(NAME, a -> new RolloverAction((ByteSizeValue) a[0], (ByteSizeValue) a[1], (TimeValue) a[2], (Long) a[3])); @@ -155,8 +157,6 @@ public boolean isSafeAction() { @Override public List toSteps(Client client, String phase, Step.StepKey nextStepKey) { - Settings indexingComplete = Settings.builder().put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, true).build(); - StepKey waitForRolloverReadyStepKey = new StepKey(phase, NAME, WaitForRolloverReadyStep.NAME); StepKey rolloverStepKey = new StepKey(phase, NAME, RolloverStep.NAME); StepKey waitForActiveShardsKey = new StepKey(phase, NAME, WaitForActiveShardsStep.NAME); @@ -170,7 +170,7 @@ public List toSteps(Client client, String phase, Step.StepKey nextStepKey) UpdateRolloverLifecycleDateStep updateDateStep = new UpdateRolloverLifecycleDateStep(updateDateStepKey, setIndexingCompleteStepKey, System::currentTimeMillis); UpdateSettingsStep setIndexingCompleteStep = new UpdateSettingsStep(setIndexingCompleteStepKey, nextStepKey, - client, indexingComplete); + client, INDEXING_COMPLETE); return Arrays.asList(waitForRolloverReadyStep, rolloverStep, waitForActiveShardsStep, updateDateStep, setIndexingCompleteStep); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SetPriorityAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SetPriorityAction.java index 361f5e763daef..e1ad51b4beb46 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SetPriorityAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SetPriorityAction.java @@ -35,6 +35,9 @@ public class SetPriorityAction implements LifecycleAction { private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>(NAME, a -> new SetPriorityAction((Integer) a[0])); + private static final Settings NULL_PRIORITY_SETTINGS = + Settings.builder().putNull(IndexMetadata.INDEX_PRIORITY_SETTING.getKey()).build(); + //package private for testing final Integer recoveryPriority; @@ -90,7 +93,7 @@ public boolean isSafeAction() { public List toSteps(Client client, String phase, StepKey nextStepKey) { StepKey key = new StepKey(phase, NAME, NAME); Settings indexPriority = recoveryPriority == null ? - Settings.builder().putNull(IndexMetadata.INDEX_PRIORITY_SETTING.getKey()).build() + NULL_PRIORITY_SETTINGS : Settings.builder().put(IndexMetadata.INDEX_PRIORITY_SETTING.getKey(), recoveryPriority).build(); return Collections.singletonList(new UpdateSettingsStep(key, nextStepKey, client, indexPriority)); } diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/v2/TransportRollupAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/v2/TransportRollupAction.java index bc66f834575da..f5e0b7fb5ace8 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/v2/TransportRollupAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/v2/TransportRollupAction.java @@ -10,6 +10,7 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.create.CreateIndexClusterStateUpdateRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; +import org.elasticsearch.action.admin.indices.rollover.MetadataRolloverService; import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest; import org.elasticsearch.action.admin.indices.shrink.ResizeRequest; import org.elasticsearch.action.admin.indices.shrink.ResizeType; @@ -68,6 +69,9 @@ */ public class TransportRollupAction extends AcknowledgedTransportMasterNodeAction { + private static final Settings VISIBLE_INDEX_SETTINGS = Settings.builder().put(IndexMetadata.SETTING_INDEX_HIDDEN, false).build(); + private static final Settings WRITE_BLOCKED_SETTINGS = Settings.builder().put(IndexMetadata.SETTING_BLOCKS_WRITE, true).build(); + private final Client client; private final ClusterService clusterService; private final MetadataCreateIndexService metadataCreateIndexService; @@ -140,17 +144,14 @@ protected void masterOperation( "rollup", tmpIndexName, tmpIndexName - ).settings(Settings.builder().put(IndexMetadata.SETTING_INDEX_HIDDEN, true).build()) + ).settings(MetadataRolloverService.HIDDEN_INDEX_SETTINGS) .mappings(XContentHelper.convertToJson(BytesReference.bytes(mapping), false, XContentType.JSON)); RollupIndexerAction.Request rollupIndexerRequest = new RollupIndexerAction.Request(request); ResizeRequest resizeRequest = new ResizeRequest(request.getRollupIndex(), tmpIndexName); resizeRequest.setResizeType(ResizeType.CLONE); - resizeRequest.getTargetIndexRequest().settings(Settings.builder().put(IndexMetadata.SETTING_INDEX_HIDDEN, false).build()); - UpdateSettingsRequest updateSettingsReq = new UpdateSettingsRequest( - Settings.builder().put(IndexMetadata.SETTING_BLOCKS_WRITE, true).build(), - tmpIndexName - ); + resizeRequest.getTargetIndexRequest().settings(VISIBLE_INDEX_SETTINGS); + UpdateSettingsRequest updateSettingsReq = new UpdateSettingsRequest(WRITE_BLOCKED_SETTINGS, tmpIndexName); // 1. validate Rollup Config against Field Caps // 2. create hidden temporary index