diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/settings/SettingsUpdater.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/settings/SettingsUpdater.java index 2b222eb1b90..24e9cd05aad 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/settings/SettingsUpdater.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/settings/SettingsUpdater.java @@ -52,11 +52,11 @@ final class SettingsUpdater { boolean changed = false; Settings.Builder transientSettings = Settings.settingsBuilder(); transientSettings.put(currentState.metaData().transientSettings()); - changed |= clusterSettings.updateSettings(transientToApply, transientSettings, transientUpdates, "transient", false); + changed |= clusterSettings.updateDynamicSettings(transientToApply, transientSettings, transientUpdates, "transient"); Settings.Builder persistentSettings = Settings.settingsBuilder(); persistentSettings.put(currentState.metaData().persistentSettings()); - changed |= clusterSettings.updateSettings(persistentToApply, persistentSettings, persistentUpdates, "persistent", false); + changed |= clusterSettings.updateDynamicSettings(persistentToApply, persistentSettings, persistentUpdates, "persistent"); if (!changed) { return currentState; diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/TransportPutIndexTemplateAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/TransportPutIndexTemplateAction.java index c7365fd9f6a..c5fed57d013 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/TransportPutIndexTemplateAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/TransportPutIndexTemplateAction.java @@ -29,7 +29,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.MetaDataIndexTemplateService; import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.IndexScopeSettings; +import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -40,15 +40,15 @@ import org.elasticsearch.transport.TransportService; public class TransportPutIndexTemplateAction extends TransportMasterNodeAction { private final MetaDataIndexTemplateService indexTemplateService; - private final IndexScopeSettings indexScopeSettings; + private final IndexScopedSettings indexScopedSettings; @Inject public TransportPutIndexTemplateAction(Settings settings, TransportService transportService, ClusterService clusterService, ThreadPool threadPool, MetaDataIndexTemplateService indexTemplateService, - ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, IndexScopeSettings indexScopeSettings) { + ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, IndexScopedSettings indexScopedSettings) { super(settings, PutIndexTemplateAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, PutIndexTemplateRequest::new); this.indexTemplateService = indexTemplateService; - this.indexScopeSettings = indexScopeSettings; + this.indexScopedSettings = indexScopedSettings; } @Override @@ -75,7 +75,7 @@ public class TransportPutIndexTemplateAction extends TransportMasterNodeAction

index.auto_expand_replicas setting. * This setting or rather it's value is expanded into a min and max value which requires special handling - * based on the number of datanodes in the cluster. This class handels all the parsing and streamlines the access to these values. + * based on the number of datanodes in the cluster. This class handles all the parsing and streamlines the access to these values. */ final class AutoExpandReplicas { // the value we recognize in the "max" position to mean all the nodes @@ -62,7 +62,7 @@ final class AutoExpandReplicas { private final int maxReplicas; private final boolean enabled; - AutoExpandReplicas(int minReplicas, int maxReplicas, boolean enabled) { + private AutoExpandReplicas(int minReplicas, int maxReplicas, boolean enabled) { if (minReplicas > maxReplicas) { throw new IllegalArgumentException("[" + IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS + "] minReplicas must be =< maxReplicas but wasn't " + minReplicas + " > " + maxReplicas); } @@ -81,7 +81,7 @@ final class AutoExpandReplicas { @Override public String toString() { - return enabled == false ? Boolean.toString(enabled) : minReplicas + "-" + maxReplicas; + return enabled ? minReplicas + "-" + maxReplicas : "false"; } boolean isEnabled() { diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java index ec943c843f3..b2772c0b2c1 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java @@ -162,7 +162,7 @@ public class IndexMetaData implements Diffable, FromXContentBuild public static final Setting INDEX_SHARED_FILESYSTEM_SETTING = Setting.boolSetting(SETTING_SHARED_FILESYSTEM, false, false, Setting.Scope.INDEX); public static final String SETTING_AUTO_EXPAND_REPLICAS = "index.auto_expand_replicas"; - public static final Setting SETTING_AUTO_EXPAND_REPLICAS_SETTING = AutoExpandReplicas.SETTING; + public static final Setting INDEX_AUTO_EXPAND_REPLICAS_SETTING = AutoExpandReplicas.SETTING; public static final String SETTING_READ_ONLY = "index.blocks.read_only"; public static final Setting INDEX_READ_ONLY_SETTING = Setting.boolSetting(SETTING_READ_ONLY, false, true, Setting.Scope.INDEX); diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java index c620a79d3d6..3d9894699a5 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java @@ -47,7 +47,7 @@ import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.regex.Regex; -import org.elasticsearch.common.settings.IndexScopeSettings; +import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentHelper; @@ -104,14 +104,14 @@ public class MetaDataCreateIndexService extends AbstractComponent { private final IndexTemplateFilter indexTemplateFilter; private final Environment env; private final NodeServicesProvider nodeServicesProvider; - private final IndexScopeSettings indexScopeSettings; + private final IndexScopedSettings indexScopedSettings; @Inject public MetaDataCreateIndexService(Settings settings, ClusterService clusterService, IndicesService indicesService, AllocationService allocationService, Version version, AliasValidator aliasValidator, - Set indexTemplateFilters, Environment env, NodeServicesProvider nodeServicesProvider, IndexScopeSettings indexScopeSettings) { + Set indexTemplateFilters, Environment env, NodeServicesProvider nodeServicesProvider, IndexScopedSettings indexScopedSettings) { super(settings); this.clusterService = clusterService; this.indicesService = indicesService; @@ -120,7 +120,7 @@ public class MetaDataCreateIndexService extends AbstractComponent { this.aliasValidator = aliasValidator; this.env = env; this.nodeServicesProvider = nodeServicesProvider; - this.indexScopeSettings = indexScopeSettings; + this.indexScopedSettings = indexScopedSettings; if (indexTemplateFilters.isEmpty()) { this.indexTemplateFilter = DEFAULT_INDEX_TEMPLATE_FILTER; @@ -177,7 +177,7 @@ public class MetaDataCreateIndexService extends AbstractComponent { public void createIndex(final CreateIndexClusterStateUpdateRequest request, final ActionListener listener) { Settings.Builder updatedSettingsBuilder = Settings.settingsBuilder(); updatedSettingsBuilder.put(request.settings()).normalizePrefix(IndexMetaData.INDEX_SETTING_PREFIX); - indexScopeSettings.validate(updatedSettingsBuilder); + indexScopedSettings.validate(updatedSettingsBuilder); request.settings(updatedSettingsBuilder.build()); clusterService.submitStateUpdateTask("create-index [" + request.index() + "], cause [" + request.cause() + "]", diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java index 81cd9e28b6a..43944541cc1 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java @@ -69,7 +69,6 @@ public class MetaDataIndexUpgradeService extends AbstractComponent { } checkSupportedVersion(indexMetaData); IndexMetaData newMetaData = indexMetaData; - newMetaData = addDefaultUnitsIfNeeded(newMetaData); checkMappingsCompatibility(newMetaData); newMetaData = markAsUpgraded(newMetaData); return newMetaData; @@ -112,103 +111,6 @@ public class MetaDataIndexUpgradeService extends AbstractComponent { return false; } - /** All known byte-sized settings for an index. */ - public static final Set INDEX_BYTES_SIZE_SETTINGS = unmodifiableSet(newHashSet( - "index.merge.policy.floor_segment", - "index.merge.policy.max_merged_segment", - "index.merge.policy.max_merge_size", - "index.merge.policy.min_merge_size", - "index.shard.recovery.file_chunk_size", - "index.shard.recovery.translog_size", - "index.store.throttle.max_bytes_per_sec", - "index.translog.flush_threshold_size", - "index.translog.fs.buffer_size", - "index.version_map_size")); - - /** All known time settings for an index. */ - public static final Set INDEX_TIME_SETTINGS = unmodifiableSet(newHashSet( - "index.gateway.wait_for_mapping_update_post_recovery", - "index.shard.wait_for_mapping_update_post_recovery", - "index.gc_deletes", - "index.indexing.slowlog.threshold.index.debug", - "index.indexing.slowlog.threshold.index.info", - "index.indexing.slowlog.threshold.index.trace", - "index.indexing.slowlog.threshold.index.warn", - "index.refresh_interval", - "index.search.slowlog.threshold.fetch.debug", - "index.search.slowlog.threshold.fetch.info", - "index.search.slowlog.threshold.fetch.trace", - "index.search.slowlog.threshold.fetch.warn", - "index.search.slowlog.threshold.query.debug", - "index.search.slowlog.threshold.query.info", - "index.search.slowlog.threshold.query.trace", - "index.search.slowlog.threshold.query.warn", - "index.shadow.wait_for_initial_commit", - "index.store.stats_refresh_interval", - "index.translog.flush_threshold_period", - "index.translog.interval", - "index.translog.sync_interval", - "index.shard.inactive_time", - "index.unassigned.node_left.delayed_timeout")); - - /** - * Elasticsearch 2.0 requires units on byte/memory and time settings; this method adds the default unit to any such settings that are - * missing units. - */ - private IndexMetaData addDefaultUnitsIfNeeded(IndexMetaData indexMetaData) { - if (indexMetaData.getCreationVersion().before(Version.V_2_0_0_beta1)) { - // TODO: can we somehow only do this *once* for a pre-2.0 index? Maybe we could stuff a "fake marker setting" here? Seems hackish... - // Created lazily if we find any settings that are missing units: - Settings settings = indexMetaData.getSettings(); - Settings.Builder newSettings = null; - for(String byteSizeSetting : INDEX_BYTES_SIZE_SETTINGS) { - String value = settings.get(byteSizeSetting); - if (value != null) { - try { - Long.parseLong(value); - } catch (NumberFormatException nfe) { - continue; - } - // It's a naked number that previously would be interpreted as default unit (bytes); now we add it: - logger.warn("byte-sized index setting [{}] with value [{}] is missing units; assuming default units (b) but in future versions this will be a hard error", byteSizeSetting, value); - if (newSettings == null) { - newSettings = Settings.builder(); - newSettings.put(settings); - } - newSettings.put(byteSizeSetting, value + "b"); - } - } - for(String timeSetting : INDEX_TIME_SETTINGS) { - String value = settings.get(timeSetting); - if (value != null) { - try { - Long.parseLong(value); - } catch (NumberFormatException nfe) { - continue; - } - // It's a naked number that previously would be interpreted as default unit (ms); now we add it: - logger.warn("time index setting [{}] with value [{}] is missing units; assuming default units (ms) but in future versions this will be a hard error", timeSetting, value); - if (newSettings == null) { - newSettings = Settings.builder(); - newSettings.put(settings); - } - newSettings.put(timeSetting, value + "ms"); - } - } - if (newSettings != null) { - // At least one setting was changed: - return IndexMetaData.builder(indexMetaData) - .version(indexMetaData.getVersion()) - .settings(newSettings.build()) - .build(); - } - } - - // No changes: - return indexMetaData; - } - - /** * Checks the mappings for compatibility with the current version */ diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java index 0943ebdcb8b..8e9dbc6b673 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java @@ -30,6 +30,7 @@ import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateListener; import org.elasticsearch.cluster.ack.ClusterStateUpdateResponse; +import org.elasticsearch.cluster.block.ClusterBlock; import org.elasticsearch.cluster.block.ClusterBlocks; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.allocation.AllocationService; @@ -38,7 +39,7 @@ import org.elasticsearch.common.Priority; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.IndexScopeSettings; +import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; @@ -64,16 +65,16 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements private final AllocationService allocationService; private final IndexNameExpressionResolver indexNameExpressionResolver; - private final IndexScopeSettings indexScopeSettings; + private final IndexScopedSettings indexScopedSettings; @Inject - public MetaDataUpdateSettingsService(Settings settings, ClusterService clusterService, AllocationService allocationService, IndexScopeSettings indexScopeSettings, IndexNameExpressionResolver indexNameExpressionResolver) { + public MetaDataUpdateSettingsService(Settings settings, ClusterService clusterService, AllocationService allocationService, IndexScopedSettings indexScopedSettings, IndexNameExpressionResolver indexNameExpressionResolver) { super(settings); this.clusterService = clusterService; this.indexNameExpressionResolver = indexNameExpressionResolver; this.clusterService.add(this); this.allocationService = allocationService; - this.indexScopeSettings = indexScopeSettings; + this.indexScopedSettings = indexScopedSettings; } @Override @@ -88,8 +89,15 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements Map> nrReplicasChanged = new HashMap<>(); // we need to do this each time in case it was changed by update settings for (final IndexMetaData indexMetaData : event.state().metaData()) { - AutoExpandReplicas autoExpandReplicas = IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS_SETTING.get(indexMetaData.getSettings()); + AutoExpandReplicas autoExpandReplicas = IndexMetaData.INDEX_AUTO_EXPAND_REPLICAS_SETTING.get(indexMetaData.getSettings()); if (autoExpandReplicas.isEnabled()) { + /* + * we have to expand the number of replicas for this index to at least min and at most max nodes here + * so we are bumping it up if we have to or reduce it depending on min/max and the number of datanodes. + * If we change the number of replicas we just let the shard allocator do it's thing once we updated it + * since it goes through the index metadata to figure out if something needs to be done anyway. Do do that + * we issue a cluster settings update command below and kicks off a reroute. + */ final int min = autoExpandReplicas.getMinReplicas(); final int max = autoExpandReplicas.getMaxReplicas(dataNodeCount); int numberOfReplicas = dataNodeCount - 1; @@ -115,6 +123,7 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements } if (nrReplicasChanged.size() > 0) { + // update settings and kick of a reroute (implicit) for them to take effect for (final Integer fNumberOfReplicas : nrReplicasChanged.keySet()) { Settings settings = Settings.settingsBuilder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, fNumberOfReplicas).build(); final List indices = nrReplicasChanged.get(fNumberOfReplicas); @@ -144,24 +153,20 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements } public void updateSettings(final UpdateSettingsClusterStateUpdateRequest request, final ActionListener listener) { - Settings.Builder updatedSettingsBuilder = Settings.settingsBuilder(); - updatedSettingsBuilder.put(request.settings()).normalizePrefix(IndexMetaData.INDEX_SETTING_PREFIX); + final Settings normalizedSettings = Settings.settingsBuilder().put(request.settings()).normalizePrefix(IndexMetaData.INDEX_SETTING_PREFIX).build(); Settings.Builder settingsForClosedIndices = Settings.builder(); Settings.Builder settingsForOpenIndices = Settings.builder(); Settings.Builder skipppedSettings = Settings.builder(); - + indexScopedSettings.validate(normalizedSettings); // never allow to change the number of shards - for (Map.Entry entry : updatedSettingsBuilder.internalMap().entrySet()) { + for (Map.Entry entry : normalizedSettings.getAsMap().entrySet()) { if (entry.getKey().equals(IndexMetaData.SETTING_NUMBER_OF_SHARDS)) { listener.onFailure(new IllegalArgumentException("can't change the number of shards for an index")); return; } - Setting setting = indexScopeSettings.get(entry.getKey()); - if (setting == null) { - throw new IllegalArgumentException("setting [" + entry.getKey() + "] is unknown"); - } - indexScopeSettings.validate(entry.getKey(), entry.getValue()); + Setting setting = indexScopedSettings.get(entry.getKey()); + assert setting != null; // we already validated the normalized settings settingsForClosedIndices.put(entry.getKey(), entry.getValue()); if (setting.isDynamic()) { settingsForOpenIndices.put(entry.getKey(), entry.getValue()); @@ -221,40 +226,10 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements } ClusterBlocks.Builder blocks = ClusterBlocks.builder().blocks(currentState.blocks()); - final boolean updatedReadOnly = IndexMetaData.INDEX_READ_ONLY_SETTING.get(openSettings); - for (String index : actualIndices) { - if (updatedReadOnly) { - blocks.addIndexBlock(index, IndexMetaData.INDEX_READ_ONLY_BLOCK); - } else { - blocks.removeIndexBlock(index, IndexMetaData.INDEX_READ_ONLY_BLOCK); - } - } - final boolean updateMetaDataBlock = IndexMetaData.INDEX_BLOCKS_METADATA_SETTING.get(openSettings); - for (String index : actualIndices) { - if (updateMetaDataBlock) { - blocks.addIndexBlock(index, IndexMetaData.INDEX_METADATA_BLOCK); - } else { - blocks.removeIndexBlock(index, IndexMetaData.INDEX_METADATA_BLOCK); - } - } - - final boolean updateWriteBlock = IndexMetaData.INDEX_BLOCKS_WRITE_SETTING.get(openSettings); - for (String index : actualIndices) { - if (updateWriteBlock) { - blocks.addIndexBlock(index, IndexMetaData.INDEX_WRITE_BLOCK); - } else { - blocks.removeIndexBlock(index, IndexMetaData.INDEX_WRITE_BLOCK); - } - } - - final boolean updateReadBlock = IndexMetaData.INDEX_BLOCKS_READ_SETTING.get(openSettings); - for (String index : actualIndices) { - if (updateReadBlock) { - blocks.addIndexBlock(index, IndexMetaData.INDEX_READ_BLOCK); - } else { - blocks.removeIndexBlock(index, IndexMetaData.INDEX_READ_BLOCK); - } - } + maybeUpdateClusterBlock(actualIndices, blocks, IndexMetaData.INDEX_READ_ONLY_BLOCK, IndexMetaData.INDEX_READ_ONLY_SETTING, openSettings); + maybeUpdateClusterBlock(actualIndices, blocks, IndexMetaData.INDEX_METADATA_BLOCK, IndexMetaData.INDEX_BLOCKS_METADATA_SETTING, openSettings); + maybeUpdateClusterBlock(actualIndices, blocks, IndexMetaData.INDEX_WRITE_BLOCK, IndexMetaData.INDEX_BLOCKS_WRITE_SETTING, openSettings); + maybeUpdateClusterBlock(actualIndices, blocks, IndexMetaData.INDEX_READ_BLOCK, IndexMetaData.INDEX_BLOCKS_READ_SETTING, openSettings); if (!openIndices.isEmpty()) { for (String index : openIndices) { @@ -264,7 +239,7 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements } Settings.Builder updates = Settings.builder(); Settings.Builder indexSettings = Settings.builder().put(indexMetaData.getSettings()); - if (indexScopeSettings.updateSettings(openSettings, indexSettings, updates, index, false)) { + if (indexScopedSettings.updateDynamicSettings(openSettings, indexSettings, updates, index)) { metaDataBuilder.put(IndexMetaData.builder(indexMetaData).settings(indexSettings)); } } @@ -278,7 +253,7 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements } Settings.Builder updates = Settings.builder(); Settings.Builder indexSettings = Settings.builder().put(indexMetaData.getSettings()); - if (indexScopeSettings.updateSettings(closedSettings, indexSettings, updates, index, true)) { + if (indexScopedSettings.updateSettings(closedSettings, indexSettings, updates, index)) { metaDataBuilder.put(IndexMetaData.builder(indexMetaData).settings(indexSettings)); } } @@ -291,16 +266,32 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements RoutingAllocation.Result routingResult = allocationService.reroute(updatedState, "settings update"); updatedState = ClusterState.builder(updatedState).routingResult(routingResult).build(); for (String index : openIndices) { - indexScopeSettings.dryRun(updatedState.metaData().index(index).getSettings()); + indexScopedSettings.dryRun(updatedState.metaData().index(index).getSettings()); } for (String index : closeIndices) { - indexScopeSettings.dryRun(updatedState.metaData().index(index).getSettings()); + indexScopedSettings.dryRun(updatedState.metaData().index(index).getSettings()); } return updatedState; } }); } + /** + * Updates the cluster block only iff the setting exists in the given settings + */ + private static void maybeUpdateClusterBlock(String[] actualIndices, ClusterBlocks.Builder blocks, ClusterBlock block, Setting setting, Settings openSettings) { + if (setting.exists(openSettings)) { + final boolean updateReadBlock = setting.get(openSettings); + for (String index : actualIndices) { + if (updateReadBlock) { + blocks.addIndexBlock(index, block); + } else { + blocks.removeIndexBlock(index, block); + } + } + } + } + public void upgradeIndexSettings(final UpgradeSettingsClusterStateUpdateRequest request, final ActionListener listener) { diff --git a/core/src/main/java/org/elasticsearch/common/settings/AbstractScopedSettings.java b/core/src/main/java/org/elasticsearch/common/settings/AbstractScopedSettings.java index 83f31e059f5..f3885607984 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/AbstractScopedSettings.java +++ b/core/src/main/java/org/elasticsearch/common/settings/AbstractScopedSettings.java @@ -183,9 +183,7 @@ public abstract class AbstractScopedSettings extends AbstractComponent { * Validates that all settings in the builder are registered and valid */ public final void validate(Settings.Builder settingsBuilder) { - for (Map.Entry entry : settingsBuilder.internalMap().entrySet()) { - validate(entry.getKey(), entry.getValue()); - } + validate(settingsBuilder.build()); } /** @@ -193,7 +191,7 @@ public abstract class AbstractScopedSettings extends AbstractComponent { */ public final void validate(Settings settings) { for (Map.Entry entry : settings.getAsMap().entrySet()) { - validate(entry.getKey(), entry.getValue()); + validate(entry.getKey(), settings); } } @@ -201,13 +199,12 @@ public abstract class AbstractScopedSettings extends AbstractComponent { /** * Validates that the setting is valid */ - public final void validate(String key, String value) { - Settings.Builder builder = Settings.builder().put(key, value); + public final void validate(String key, Settings settings) { Setting setting = get(key); if (setting == null) { throw new IllegalArgumentException("unknown setting [" + key + "]"); } - setting.get(builder.build()); + setting.get(settings); } /** @@ -317,22 +314,49 @@ public abstract class AbstractScopedSettings extends AbstractComponent { /** * Updates a target settings builder with new, updated or deleted settings from a given settings builder. + *

+ * Note: This method will only allow updates to dynamic settings. if a non-dynamic setting is updated an {@link IllegalArgumentException} is thrown instead. + *

* @param toApply the new settings to apply * @param target the target settings builder that the updates are applied to. All keys that have explicit null value in toApply will be removed from this builder * @param updates a settings builder that holds all updates applied to target * @param type a free text string to allow better exceptions messages - * @param all if true all settings are updated otherwise only dynamic settings are updated. if set to false and a non-dynamic setting is updated an exception is thrown * @return true if the target has changed otherwise false */ - public boolean updateSettings(Settings toApply, Settings.Builder target, Settings.Builder updates, String type, boolean all) { + public boolean updateDynamicSettings(Settings toApply, Settings.Builder target, Settings.Builder updates, String type) { + return updateSettings(toApply, target, updates, type, true); + } + + /** + * Updates a target settings builder with new, updated or deleted settings from a given settings builder. + * @param toApply the new settings to apply + * @param target the target settings builder that the updates are applied to. All keys that have explicit null value in toApply will be removed from this builder + * @param updates a settings builder that holds all updates applied to target + * @param type a free text string to allow better exceptions messages + * @return true if the target has changed otherwise false + */ + public boolean updateSettings(Settings toApply, Settings.Builder target, Settings.Builder updates, String type) { + return updateSettings(toApply, target, updates, type, false); + } + + /** + * Updates a target settings builder with new, updated or deleted settings from a given settings builder. + * @param toApply the new settings to apply + * @param target the target settings builder that the updates are applied to. All keys that have explicit null value in toApply will be removed from this builder + * @param updates a settings builder that holds all updates applied to target + * @param type a free text string to allow better exceptions messages + * @param onlyDynamic if false all settings are updated otherwise only dynamic settings are updated. if set to true and a non-dynamic setting is updated an exception is thrown. + * @return true if the target has changed otherwise false + */ + private boolean updateSettings(Settings toApply, Settings.Builder target, Settings.Builder updates, String type, boolean onlyDynamic) { boolean changed = false; final Set toRemove = new HashSet<>(); Settings.Builder settingsBuilder = Settings.settingsBuilder(); for (Map.Entry entry : toApply.getAsMap().entrySet()) { if (entry.getValue() == null) { toRemove.add(entry.getKey()); - } else if ((all && get(entry.getKey()) != null) || hasDynamicSetting(entry.getKey())) { - validate(entry.getKey(), entry.getValue()); + } else if ((onlyDynamic == false && get(entry.getKey()) != null) || hasDynamicSetting(entry.getKey())) { + validate(entry.getKey(), toApply); settingsBuilder.put(entry.getKey(), entry.getValue()); updates.put(entry.getKey(), entry.getValue()); changed = true; diff --git a/core/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java b/core/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java index 0d058b7c2c8..8ab08256c8b 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java +++ b/core/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java @@ -65,7 +65,7 @@ public final class IndexScopedSettings extends AbstractScopedSettings { IndexMetaData.INDEX_ROUTING_EXCLUDE_GROUP_SETTING, IndexMetaData.INDEX_ROUTING_INCLUDE_GROUP_SETTING, IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_SETTING, - IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS_SETTING, + IndexMetaData.INDEX_AUTO_EXPAND_REPLICAS_SETTING, IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING, IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING, IndexMetaData.INDEX_SHADOW_REPLICAS_SETTING, diff --git a/core/src/main/java/org/elasticsearch/common/settings/SettingsModule.java b/core/src/main/java/org/elasticsearch/common/settings/SettingsModule.java index b2ddce02564..91a515bf357 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/SettingsModule.java +++ b/core/src/main/java/org/elasticsearch/common/settings/SettingsModule.java @@ -20,7 +20,6 @@ package org.elasticsearch.common.settings; import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.index.IndexSettings; import java.util.HashMap; import java.util.HashSet; @@ -44,22 +43,22 @@ public class SettingsModule extends AbstractModule { for (Setting setting : ClusterSettings.BUILT_IN_CLUSTER_SETTINGS) { registerSetting(setting); } - for (Setting setting : IndexScopeSettings.BUILT_IN_INDEX_SETTINGS) { + for (Setting setting : IndexScopedSettings.BUILT_IN_INDEX_SETTINGS) { registerSetting(setting); } } @Override protected void configure() { - final IndexScopeSettings indexScopeSettings = new IndexScopeSettings(settings, new HashSet<>(this.indexSettings.values())); + final IndexScopedSettings indexScopedSettings = new IndexScopedSettings(settings, new HashSet<>(this.indexSettings.values())); // by now we are fully configured, lets check node level settings for unregistered index settings - indexScopeSettings.validate(settings.filter(IndexScopeSettings.INDEX_SETTINGS_KEY_PREDICATE)); + indexScopedSettings.validate(settings.filter(IndexScopedSettings.INDEX_SETTINGS_KEY_PREDICATE)); bind(Settings.class).toInstance(settings); bind(SettingsFilter.class).toInstance(settingsFilter); final ClusterSettings clusterSettings = new ClusterSettings(settings, new HashSet<>(this.clusterSettings.values())); bind(ClusterSettings.class).toInstance(clusterSettings); - bind(IndexScopeSettings.class).toInstance(indexScopeSettings); + bind(IndexScopedSettings.class).toInstance(indexScopedSettings); } public void registerSetting(Setting setting) { diff --git a/core/src/main/java/org/elasticsearch/common/unit/ByteSizeValue.java b/core/src/main/java/org/elasticsearch/common/unit/ByteSizeValue.java index 105bda28a99..32df65850a8 100644 --- a/core/src/main/java/org/elasticsearch/common/unit/ByteSizeValue.java +++ b/core/src/main/java/org/elasticsearch/common/unit/ByteSizeValue.java @@ -20,12 +20,10 @@ package org.elasticsearch.common.unit; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.cluster.metadata.MetaDataIndexUpgradeService; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; -import org.elasticsearch.common.settings.Settings; import java.io.IOException; import java.util.Locale; @@ -176,7 +174,6 @@ public class ByteSizeValue implements Streamable { public static ByteSizeValue parseBytesSizeValue(String sValue, ByteSizeValue defaultValue, String settingName) throws ElasticsearchParseException { settingName = Objects.requireNonNull(settingName); - assert settingName.startsWith("index.") == false || MetaDataIndexUpgradeService.INDEX_BYTES_SIZE_SETTINGS.contains(settingName); if (sValue == null) { return defaultValue; } diff --git a/core/src/main/java/org/elasticsearch/common/unit/TimeValue.java b/core/src/main/java/org/elasticsearch/common/unit/TimeValue.java index dfa0c62d7a6..b1081c2c623 100644 --- a/core/src/main/java/org/elasticsearch/common/unit/TimeValue.java +++ b/core/src/main/java/org/elasticsearch/common/unit/TimeValue.java @@ -20,12 +20,10 @@ package org.elasticsearch.common.unit; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.cluster.metadata.MetaDataIndexUpgradeService; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; -import org.elasticsearch.common.settings.Settings; import org.joda.time.Period; import org.joda.time.PeriodType; import org.joda.time.format.PeriodFormat; @@ -254,7 +252,6 @@ public class TimeValue implements Streamable { public static TimeValue parseTimeValue(String sValue, TimeValue defaultValue, String settingName) { settingName = Objects.requireNonNull(settingName); - assert settingName.startsWith("index.") == false || MetaDataIndexUpgradeService.INDEX_TIME_SETTINGS.contains(settingName) : settingName; if (sValue == null) { return defaultValue; } diff --git a/core/src/main/java/org/elasticsearch/index/IndexSettings.java b/core/src/main/java/org/elasticsearch/index/IndexSettings.java index d87aedb5fbf..715bea51694 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexSettings.java +++ b/core/src/main/java/org/elasticsearch/index/IndexSettings.java @@ -25,7 +25,7 @@ import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.regex.Regex; -import org.elasticsearch.common.settings.IndexScopeSettings; +import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeUnit; @@ -115,7 +115,7 @@ public final class IndexSettings { private volatile ByteSizeValue flushThresholdSize; private final MergeSchedulerConfig mergeSchedulerConfig; private final MergePolicyConfig mergePolicyConfig; - private final IndexScopeSettings scopedSettings; + private final IndexScopedSettings scopedSettings; private long gcDeletesInMillis = DEFAULT_GC_DELETES.millis(); private volatile boolean warmerEnabled; private volatile int maxResultWindow; @@ -164,10 +164,10 @@ public final class IndexSettings { * @param nodeSettings the nodes settings this index is allocated on. */ public IndexSettings(final IndexMetaData indexMetaData, final Settings nodeSettings) { - this(indexMetaData, nodeSettings, (index) -> Regex.simpleMatch(index, indexMetaData.getIndex()), IndexScopeSettings.DEFAULT_SCOPED_SETTINGS); + this(indexMetaData, nodeSettings, (index) -> Regex.simpleMatch(index, indexMetaData.getIndex()), IndexScopedSettings.DEFAULT_SCOPED_SETTINGS); } - IndexSettings(final IndexMetaData indexMetaData, final Settings nodeSettings, IndexScopeSettings indexScopedSettings) { + IndexSettings(final IndexMetaData indexMetaData, final Settings nodeSettings, IndexScopedSettings indexScopedSettings) { this(indexMetaData, nodeSettings, (index) -> Regex.simpleMatch(index, indexMetaData.getIndex()), indexScopedSettings); } @@ -179,7 +179,7 @@ public final class IndexSettings { * @param nodeSettings the nodes settings this index is allocated on. * @param indexNameMatcher a matcher that can resolve an expression to the index name or index alias */ - public IndexSettings(final IndexMetaData indexMetaData, final Settings nodeSettings, final Predicate indexNameMatcher, IndexScopeSettings indexScopedSettings) { + public IndexSettings(final IndexMetaData indexMetaData, final Settings nodeSettings, final Predicate indexNameMatcher, IndexScopedSettings indexScopedSettings) { scopedSettings = indexScopedSettings.copy(nodeSettings, indexMetaData); this.nodeSettings = nodeSettings; this.settings = Settings.builder().put(nodeSettings).put(indexMetaData.getSettings()).build(); @@ -358,7 +358,7 @@ public final class IndexSettings { } this.indexMetaData = indexMetaData; final Settings existingSettings = this.settings; - if (existingSettings.filter(IndexScopeSettings.INDEX_SETTINGS_KEY_PREDICATE).getAsMap().equals(newSettings.filter(IndexScopeSettings.INDEX_SETTINGS_KEY_PREDICATE).getAsMap())) { + if (existingSettings.filter(IndexScopedSettings.INDEX_SETTINGS_KEY_PREDICATE).getAsMap().equals(newSettings.filter(IndexScopedSettings.INDEX_SETTINGS_KEY_PREDICATE).getAsMap())) { // nothing to update, same settings return false; } @@ -457,5 +457,5 @@ public final class IndexSettings { } - public IndexScopeSettings getScopedSettings() { return scopedSettings;} + public IndexScopedSettings getScopedSettings() { return scopedSettings;} } diff --git a/core/src/main/java/org/elasticsearch/indices/IndicesService.java b/core/src/main/java/org/elasticsearch/indices/IndicesService.java index ab69d1a626e..fdc448989d5 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/core/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -37,7 +37,7 @@ import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.FileSystemUtils; import org.elasticsearch.common.settings.ClusterSettings; -import org.elasticsearch.common.settings.IndexScopeSettings; +import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.EsExecutors; @@ -71,7 +71,6 @@ import org.elasticsearch.threadpool.ThreadPool; import java.io.IOException; import java.nio.file.Files; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -102,7 +101,7 @@ public class IndicesService extends AbstractLifecycleComponent i private final IndicesQueriesRegistry indicesQueriesRegistry; private final ClusterService clusterService; private final IndexNameExpressionResolver indexNameExpressionResolver; - private final IndexScopeSettings indexScopeSetting; + private final IndexScopedSettings indexScopeSetting; private volatile Map indices = emptyMap(); private final Map> pendingDeletes = new HashMap<>(); private final OldShardsStats oldShardsStats = new OldShardsStats(); @@ -118,7 +117,7 @@ public class IndicesService extends AbstractLifecycleComponent i public IndicesService(Settings settings, PluginsService pluginsService, NodeEnvironment nodeEnv, ClusterSettings clusterSettings, AnalysisRegistry analysisRegistry, IndicesQueriesRegistry indicesQueriesRegistry, IndexNameExpressionResolver indexNameExpressionResolver, - ClusterService clusterService, MapperRegistry mapperRegistry, ThreadPool threadPool, IndexScopeSettings indexScopeSettings) { + ClusterService clusterService, MapperRegistry mapperRegistry, ThreadPool threadPool, IndexScopedSettings indexScopedSettings) { super(settings); this.pluginsService = pluginsService; this.nodeEnv = nodeEnv; @@ -132,7 +131,7 @@ public class IndicesService extends AbstractLifecycleComponent i clusterSettings.addSettingsUpdateConsumer(IndexStoreConfig.INDICES_STORE_THROTTLE_TYPE_SETTING, indexStoreConfig::setRateLimitingType); clusterSettings.addSettingsUpdateConsumer(IndexStoreConfig.INDICES_STORE_THROTTLE_MAX_BYTES_PER_SEC_SETTING, indexStoreConfig::setRateLimitingThrottle); indexingMemoryController = new IndexingMemoryController(settings, threadPool, this); - this.indexScopeSetting = indexScopeSettings; + this.indexScopeSetting = indexScopedSettings; } @Override diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/get/RestGetIndicesAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/get/RestGetIndicesAction.java index 248e61e18ba..e23dec0f0bc 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/get/RestGetIndicesAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/get/RestGetIndicesAction.java @@ -29,7 +29,7 @@ import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.common.Strings; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.IndexScopeSettings; +import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ToXContent.Params; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -53,12 +53,12 @@ import static org.elasticsearch.rest.RestStatus.OK; */ public class RestGetIndicesAction extends BaseRestHandler { - private final IndexScopeSettings indexScopeSettings; + private final IndexScopedSettings indexScopedSettings; @Inject - public RestGetIndicesAction(Settings settings, RestController controller, Client client, IndexScopeSettings indexScopeSettings) { + public RestGetIndicesAction(Settings settings, RestController controller, Client client, IndexScopedSettings indexScopedSettings) { super(settings, controller, client); - this.indexScopeSettings = indexScopeSettings; + this.indexScopedSettings = indexScopedSettings; controller.registerHandler(GET, "/{index}", this); controller.registerHandler(GET, "/{index}/{type}", this); } @@ -143,7 +143,7 @@ public class RestGetIndicesAction extends BaseRestHandler { builder.endObject(); if (renderDefaults) { builder.startObject("defaults"); - indexScopeSettings.diff(settings, settings).toXContent(builder, request); + indexScopedSettings.diff(settings, settings).toXContent(builder, request); builder.endObject(); } } diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/settings/RestGetSettingsAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/settings/RestGetSettingsAction.java index ec21c77d4ec..b924acc5fb3 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/settings/RestGetSettingsAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/settings/RestGetSettingsAction.java @@ -26,10 +26,9 @@ import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.client.Client; import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.IndexScopeSettings; +import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestChannel; @@ -43,12 +42,12 @@ import static org.elasticsearch.rest.RestStatus.OK; public class RestGetSettingsAction extends BaseRestHandler { - private final IndexScopeSettings indexScopeSettings; + private final IndexScopedSettings indexScopedSettings; @Inject - public RestGetSettingsAction(Settings settings, RestController controller, Client client, IndexScopeSettings indexScopeSettings) { + public RestGetSettingsAction(Settings settings, RestController controller, Client client, IndexScopedSettings indexScopedSettings) { super(settings, controller, client); - this.indexScopeSettings = indexScopeSettings; + this.indexScopedSettings = indexScopedSettings; controller.registerHandler(GET, "/{index}/_settings/{name}", this); controller.registerHandler(GET, "/_settings/{name}", this); controller.registerHandler(GET, "/{index}/_setting/{name}", this); @@ -81,7 +80,7 @@ public class RestGetSettingsAction extends BaseRestHandler { builder.endObject(); if (renderDefaults) { builder.startObject("defaults"); - indexScopeSettings.diff(cursor.value, settings).toXContent(builder, request); + indexScopedSettings.diff(cursor.value, settings).toXContent(builder, request); builder.endObject(); } builder.endObject(); diff --git a/core/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java b/core/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java index 0967e4a8776..7cfa0eeaaa7 100644 --- a/core/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java @@ -33,7 +33,7 @@ import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider; import org.elasticsearch.common.inject.ModuleTestCase; import org.elasticsearch.common.settings.ClusterSettings; -import org.elasticsearch.common.settings.IndexScopeSettings; +import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsFilter; @@ -103,7 +103,7 @@ public class ClusterModuleTests extends ModuleTestCase { final SettingsFilter settingsFilter = new SettingsFilter(Settings.EMPTY); SettingsModule module = new SettingsModule(Settings.EMPTY, settingsFilter); module.registerSetting(Setting.boolSetting("foo.bar", false, true, Setting.Scope.INDEX)); - assertInstanceBinding(module, IndexScopeSettings.class, service -> service.hasDynamicSetting("foo.bar")); + assertInstanceBinding(module, IndexScopedSettings.class, service -> service.hasDynamicSetting("foo.bar")); } public void testRegisterAllocationDeciderDuplicate() { diff --git a/core/src/test/java/org/elasticsearch/common/settings/ScopedSettingsTests.java b/core/src/test/java/org/elasticsearch/common/settings/ScopedSettingsTests.java index 310c50a5483..088d4fa5ac6 100644 --- a/core/src/test/java/org/elasticsearch/common/settings/ScopedSettingsTests.java +++ b/core/src/test/java/org/elasticsearch/common/settings/ScopedSettingsTests.java @@ -170,19 +170,19 @@ public class ScopedSettingsTests extends ESTestCase { } public void testGetSetting() { - IndexScopeSettings settings = new IndexScopeSettings( + IndexScopedSettings settings = new IndexScopedSettings( Settings.EMPTY, - IndexScopeSettings.BUILT_IN_INDEX_SETTINGS); - IndexScopeSettings copy = settings.copy(Settings.builder().put("index.store.type", "boom").build(), newIndexMeta("foo", Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 3).build())); + IndexScopedSettings.BUILT_IN_INDEX_SETTINGS); + IndexScopedSettings copy = settings.copy(Settings.builder().put("index.store.type", "boom").build(), newIndexMeta("foo", Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 3).build())); assertEquals(3, copy.get(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING).intValue()); assertEquals(1, copy.get(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING).intValue()); assertEquals("boom", copy.get(IndexModule.INDEX_STORE_TYPE_SETTING)); // test fallback to node settings } public void testValidate() { - IndexScopeSettings settings = new IndexScopeSettings( + IndexScopedSettings settings = new IndexScopedSettings( Settings.EMPTY, - IndexScopeSettings.BUILT_IN_INDEX_SETTINGS); + IndexScopedSettings.BUILT_IN_INDEX_SETTINGS); settings.validate(Settings.builder().put("index.store.type", "boom")); settings.validate(Settings.builder().put("index.store.type", "boom").build()); try { @@ -207,7 +207,7 @@ public class ScopedSettingsTests extends ESTestCase { } try { - settings.validate("index.number_of_replicas", "true"); + settings.validate("index.number_of_replicas", Settings.builder().put("index.number_of_replicas", "true").build()); fail(); } catch (IllegalArgumentException e) { assertEquals("Failed to parse value [true] for setting [index.number_of_replicas]", e.getMessage()); diff --git a/core/src/test/java/org/elasticsearch/index/IndexSettingsTests.java b/core/src/test/java/org/elasticsearch/index/IndexSettingsTests.java index af721a3fa74..56179d5390b 100644 --- a/core/src/test/java/org/elasticsearch/index/IndexSettingsTests.java +++ b/core/src/test/java/org/elasticsearch/index/IndexSettingsTests.java @@ -21,26 +21,20 @@ package org.elasticsearch.index; import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.regex.Regex; -import org.elasticsearch.common.settings.AbstractScopedSettings; -import org.elasticsearch.common.settings.IndexScopeSettings; +import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.translog.Translog; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.IndexSettingsModule; import org.elasticsearch.test.VersionUtils; -import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.HashSet; -import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Consumer; import java.util.function.Function; public class IndexSettingsTests extends ESTestCase { @@ -116,11 +110,11 @@ public class IndexSettingsTests extends ESTestCase { } public IndexSettings newIndexSettings(IndexMetaData metaData, Settings nodeSettings, Setting... settings) { - Set> settingSet = new HashSet<>(IndexScopeSettings.BUILT_IN_INDEX_SETTINGS); + Set> settingSet = new HashSet<>(IndexScopedSettings.BUILT_IN_INDEX_SETTINGS); if (settings.length > 0) { settingSet.addAll(Arrays.asList(settings)); } - return new IndexSettings(metaData, nodeSettings, (idx) -> Regex.simpleMatch(idx, metaData.getIndex()), new IndexScopeSettings(Settings.EMPTY, settingSet)); + return new IndexSettings(metaData, nodeSettings, (idx) -> Regex.simpleMatch(idx, metaData.getIndex()), new IndexScopedSettings(Settings.EMPTY, settingSet)); } diff --git a/test/framework/src/main/java/org/elasticsearch/test/IndexSettingsModule.java b/test/framework/src/main/java/org/elasticsearch/test/IndexSettingsModule.java index a0300e7a391..f4e08979e7c 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/IndexSettingsModule.java +++ b/test/framework/src/main/java/org/elasticsearch/test/IndexSettingsModule.java @@ -22,14 +22,13 @@ import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.regex.Regex; -import org.elasticsearch.common.settings.IndexScopeSettings; +import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexSettings; import java.util.Arrays; -import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -60,10 +59,10 @@ public class IndexSettingsModule extends AbstractModule { .put(settings) .build(); IndexMetaData metaData = IndexMetaData.builder(index.getName()).settings(build).build(); - Set> settingSet = new HashSet<>(IndexScopeSettings.BUILT_IN_INDEX_SETTINGS); + Set> settingSet = new HashSet<>(IndexScopedSettings.BUILT_IN_INDEX_SETTINGS); if (setting.length > 0) { settingSet.addAll(Arrays.asList(setting)); } - return new IndexSettings(metaData, Settings.EMPTY, (idx) -> Regex.simpleMatch(idx, metaData.getIndex()), new IndexScopeSettings(Settings.EMPTY, settingSet)); + return new IndexSettings(metaData, Settings.EMPTY, (idx) -> Regex.simpleMatch(idx, metaData.getIndex()), new IndexScopedSettings(Settings.EMPTY, settingSet)); } }