From 4bfedd039a750e344084af79646a9836c568c504 Mon Sep 17 00:00:00 2001 From: Igor Motov Date: Mon, 25 Feb 2013 18:39:59 -0500 Subject: [PATCH] Changing dynamic index and cluster settings should work on master-only nodes Fixes #2675 --- .../TransportClusterUpdateSettingsAction.java | 11 +- .../elasticsearch/cluster/ClusterModule.java | 7 +- .../cluster/metadata/IndexMetaData.java | 37 +---- .../cluster/metadata/MetaData.java | 23 ---- .../MetaDataUpdateSettingsService.java | 9 +- .../decider/AwarenessAllocationDecider.java | 17 +-- .../ConcurrentRebalanceAllocationDecider.java | 11 +- .../decider/DisableAllocationDecider.java | 23 ++-- .../decider/FilterAllocationDecider.java | 35 +++-- .../decider/ShardsLimitAllocationDecider.java | 6 - .../decider/ThrottlingAllocationDecider.java | 17 +-- .../settings/ClusterDynamicSettings.java | 38 ++++++ .../ClusterDynamicSettingsModule.java | 77 +++++++++++ .../cluster/settings/DynamicSettings.java | 49 +++++++ .../zen/elect/ElectMasterService.java | 7 +- .../gateway/local/LocalGatewayAllocator.java | 6 +- .../data/resident/ResidentFieldDataCache.java | 17 +-- .../index/engine/robin/RobinEngine.java | 30 ++--- .../gateway/IndexShardGatewayService.java | 7 +- .../slowlog/ShardSlowLogIndexingService.java | 29 ++-- .../LogByteSizeMergePolicyProvider.java | 27 ++-- .../policy/LogDocMergePolicyProvider.java | 24 ++-- .../policy/TieredMergePolicyProvider.java | 39 +++--- .../slowlog/ShardSlowLogSearchService.java | 45 +++---- .../index/settings/IndexDynamicSettings.java | 39 ++++++ .../settings/IndexDynamicSettingsModule.java | 126 ++++++++++++++++++ .../index/settings/IndexSettingsService.java | 3 + .../shard/service/InternalIndexShard.java | 9 +- .../org/elasticsearch/index/store/Store.java | 13 +- .../store/support/AbstractIndexStore.java | 17 +-- .../index/translog/TranslogService.java | 21 ++- .../index/translog/fs/FsTranslog.java | 17 +-- .../cache/filter/IndicesFilterCache.java | 12 +- .../indices/recovery/RecoverySettings.java | 27 ++-- .../indices/store/IndicesStore.java | 13 +- .../indices/ttl/IndicesTTLService.java | 17 +-- .../node/settings/NodeSettingsService.java | 3 + .../elasticsearch/threadpool/ThreadPool.java | 9 +- 38 files changed, 548 insertions(+), 369 deletions(-) create mode 100644 src/main/java/org/elasticsearch/cluster/settings/ClusterDynamicSettings.java create mode 100644 src/main/java/org/elasticsearch/cluster/settings/ClusterDynamicSettingsModule.java create mode 100644 src/main/java/org/elasticsearch/cluster/settings/DynamicSettings.java create mode 100644 src/main/java/org/elasticsearch/index/settings/IndexDynamicSettings.java create mode 100644 src/main/java/org/elasticsearch/index/settings/IndexDynamicSettingsModule.java diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterUpdateSettingsAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterUpdateSettingsAction.java index c00712cb57a48..6530f526c4903 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterUpdateSettingsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterUpdateSettingsAction.java @@ -29,6 +29,8 @@ import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.routing.allocation.AllocationService; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; +import org.elasticsearch.cluster.settings.ClusterDynamicSettings; +import org.elasticsearch.cluster.settings.DynamicSettings; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; @@ -48,11 +50,14 @@ public class TransportClusterUpdateSettingsAction extends TransportMasterNodeOpe private final AllocationService allocationService; + private final DynamicSettings dynamicSettings; + @Inject public TransportClusterUpdateSettingsAction(Settings settings, TransportService transportService, ClusterService clusterService, ThreadPool threadPool, - AllocationService allocationService) { + AllocationService allocationService, @ClusterDynamicSettings DynamicSettings dynamicSettings) { super(settings, transportService, clusterService, threadPool); this.allocationService = allocationService; + this.dynamicSettings = dynamicSettings; } @Override @@ -88,7 +93,7 @@ public ClusterState execute(ClusterState currentState) { ImmutableSettings.Builder transientSettings = ImmutableSettings.settingsBuilder(); transientSettings.put(currentState.metaData().transientSettings()); for (Map.Entry entry : request.transientSettings().getAsMap().entrySet()) { - if (MetaData.hasDynamicSetting(entry.getKey()) || entry.getKey().startsWith("logger.")) { + if (dynamicSettings.hasDynamicSetting(entry.getKey()) || entry.getKey().startsWith("logger.")) { transientSettings.put(entry.getKey(), entry.getValue()); changed = true; } else { @@ -99,7 +104,7 @@ public ClusterState execute(ClusterState currentState) { ImmutableSettings.Builder persistentSettings = ImmutableSettings.settingsBuilder(); persistentSettings.put(currentState.metaData().persistentSettings()); for (Map.Entry entry : request.persistentSettings().getAsMap().entrySet()) { - if (MetaData.hasDynamicSetting(entry.getKey()) || entry.getKey().startsWith("logger.")) { + if (dynamicSettings.hasDynamicSetting(entry.getKey()) || entry.getKey().startsWith("logger.")) { changed = true; persistentSettings.put(entry.getKey(), entry.getValue()); } else { diff --git a/src/main/java/org/elasticsearch/cluster/ClusterModule.java b/src/main/java/org/elasticsearch/cluster/ClusterModule.java index ac20ca2c33f63..2adf89e519692 100644 --- a/src/main/java/org/elasticsearch/cluster/ClusterModule.java +++ b/src/main/java/org/elasticsearch/cluster/ClusterModule.java @@ -28,10 +28,12 @@ import org.elasticsearch.cluster.routing.allocation.AllocationModule; import org.elasticsearch.cluster.routing.operation.OperationRoutingModule; import org.elasticsearch.cluster.service.InternalClusterService; +import org.elasticsearch.cluster.settings.ClusterDynamicSettingsModule; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.SpawnModules; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.settings.IndexDynamicSettingsModule; /** * @@ -46,7 +48,10 @@ public ClusterModule(Settings settings) { @Override public Iterable spawnModules() { - return ImmutableList.of(new AllocationModule(settings), new OperationRoutingModule(settings)); + return ImmutableList.of(new AllocationModule(settings), + new OperationRoutingModule(settings), + new ClusterDynamicSettingsModule(), + new IndexDynamicSettingsModule()); } @Override diff --git a/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java b/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java index 771b9cf5c2b08..de51fcd1bfcdf 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java @@ -20,7 +20,6 @@ package org.elasticsearch.cluster.metadata; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.cluster.block.ClusterBlock; @@ -32,7 +31,6 @@ import org.elasticsearch.common.compress.CompressedString; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.loader.SettingsLoader; @@ -45,9 +43,12 @@ import org.elasticsearch.search.warmer.IndexWarmersMetaData; import java.io.IOException; -import java.util.*; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; -import static org.elasticsearch.cluster.node.DiscoveryNodeFilters.OpType.*; +import static org.elasticsearch.cluster.node.DiscoveryNodeFilters.OpType.AND; +import static org.elasticsearch.cluster.node.DiscoveryNodeFilters.OpType.OR; import static org.elasticsearch.common.settings.ImmutableSettings.*; /** @@ -108,39 +109,11 @@ public static Custom.Factory lookupFactorySafe(String type return factory; } - private static ImmutableSet dynamicSettings = ImmutableSet.builder() - .add(IndexMetaData.SETTING_NUMBER_OF_REPLICAS) - .add(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS) - .add(IndexMetaData.SETTING_READ_ONLY) - .add(IndexMetaData.SETTING_BLOCKS_READ) - .add(IndexMetaData.SETTING_BLOCKS_WRITE) - .add(IndexMetaData.SETTING_BLOCKS_METADATA) - .build(); - public static final ClusterBlock INDEX_READ_ONLY_BLOCK = new ClusterBlock(5, "index read-only (api)", false, false, RestStatus.FORBIDDEN, ClusterBlockLevel.WRITE, ClusterBlockLevel.METADATA); public static final ClusterBlock INDEX_READ_BLOCK = new ClusterBlock(7, "index read (api)", false, false, RestStatus.FORBIDDEN, ClusterBlockLevel.READ); public static final ClusterBlock INDEX_WRITE_BLOCK = new ClusterBlock(8, "index write (api)", false, false, RestStatus.FORBIDDEN, ClusterBlockLevel.WRITE); public static final ClusterBlock INDEX_METADATA_BLOCK = new ClusterBlock(9, "index metadata (api)", false, false, RestStatus.FORBIDDEN, ClusterBlockLevel.METADATA); - public static ImmutableSet dynamicSettings() { - return dynamicSettings; - } - - public static boolean hasDynamicSetting(String key) { - for (String dynamicSetting : dynamicSettings) { - if (Regex.simpleMatch(dynamicSetting, key)) { - return true; - } - } - return false; - } - - public static synchronized void addDynamicSettings(String... settings) { - HashSet updatedSettings = new HashSet(dynamicSettings); - updatedSettings.addAll(Arrays.asList(settings)); - dynamicSettings = ImmutableSet.copyOf(updatedSettings); - } - public static enum State { OPEN((byte) 0), CLOSE((byte) 1); diff --git a/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java b/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java index 0e00bfc0692f1..13aef90c2da86 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java @@ -99,29 +99,6 @@ public static Custom.Factory lookupFactorySafe(String type public static final ClusterBlock CLUSTER_READ_ONLY_BLOCK = new ClusterBlock(6, "cluster read-only (api)", false, false, RestStatus.FORBIDDEN, ClusterBlockLevel.WRITE, ClusterBlockLevel.METADATA); - private static ImmutableSet dynamicSettings = ImmutableSet.builder() - .add(SETTING_READ_ONLY) - .build(); - - public static ImmutableSet dynamicSettings() { - return dynamicSettings; - } - - public static boolean hasDynamicSetting(String key) { - for (String dynamicSetting : dynamicSettings) { - if (Regex.simpleMatch(dynamicSetting, key)) { - return true; - } - } - return false; - } - - public static synchronized void addDynamicSettings(String... settings) { - HashSet updatedSettings = new HashSet(dynamicSettings); - updatedSettings.addAll(Arrays.asList(settings)); - dynamicSettings = ImmutableSet.copyOf(updatedSettings); - } - public static final MetaData EMPTY_META_DATA = newMetaDataBuilder().build(); private final long version; diff --git a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java index 599ac0f71976c..bec0a2044370f 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java @@ -26,11 +26,13 @@ import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.allocation.AllocationService; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; +import org.elasticsearch.cluster.settings.DynamicSettings; import org.elasticsearch.common.Booleans; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.settings.IndexDynamicSettings; import java.util.Map; import java.util.Set; @@ -46,12 +48,15 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements private final AllocationService allocationService; + private final DynamicSettings dynamicSettings; + @Inject - public MetaDataUpdateSettingsService(Settings settings, ClusterService clusterService, AllocationService allocationService) { + public MetaDataUpdateSettingsService(Settings settings, ClusterService clusterService, AllocationService allocationService, @IndexDynamicSettings DynamicSettings dynamicSettings) { super(settings); this.clusterService = clusterService; this.clusterService.add(this); this.allocationService = allocationService; + this.dynamicSettings = dynamicSettings; } @Override @@ -138,7 +143,7 @@ public void updateSettings(final Settings pSettings, final String[] indices, fin final Set removedSettings = Sets.newHashSet(); for (String key : updatedSettingsBuilder.internalMap().keySet()) { - if (!IndexMetaData.hasDynamicSetting(key)) { + if (!dynamicSettings.hasDynamicSetting(key)) { removedSettings.add(key); } } diff --git a/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AwarenessAllocationDecider.java b/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AwarenessAllocationDecider.java index 01ad72c6fbb64..8dae69afddf92 100644 --- a/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AwarenessAllocationDecider.java +++ b/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AwarenessAllocationDecider.java @@ -22,7 +22,6 @@ import com.google.common.collect.Maps; import gnu.trove.map.hash.TObjectIntHashMap; import org.elasticsearch.cluster.metadata.IndexMetaData; -import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.routing.MutableShardRouting; import org.elasticsearch.cluster.routing.RoutingNode; import org.elasticsearch.cluster.routing.ShardRouting; @@ -39,23 +38,19 @@ */ public class AwarenessAllocationDecider extends AllocationDecider { - static { - MetaData.addDynamicSettings( - "cluster.routing.allocation.awareness.attributes", - "cluster.routing.allocation.awareness.force.*" - ); - } + public static final String CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTES = "cluster.routing.allocation.awareness.attributes"; + public static final String CLUSTER_ROUTING_ALLOCATION_AWARENESS_FORCE_GROUP = "cluster.routing.allocation.awareness.force."; class ApplySettings implements NodeSettingsService.Listener { @Override public void onRefreshSettings(Settings settings) { - String[] awarenessAttributes = settings.getAsArray("cluster.routing.allocation.awareness.attributes", null); + String[] awarenessAttributes = settings.getAsArray(CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTES, null); if (awarenessAttributes != null) { logger.info("updating [cluster.routing.allocation.awareness.attributes] from [{}] to [{}]", AwarenessAllocationDecider.this.awarenessAttributes, awarenessAttributes); AwarenessAllocationDecider.this.awarenessAttributes = awarenessAttributes; } Map forcedAwarenessAttributes = new HashMap(AwarenessAllocationDecider.this.forcedAwarenessAttributes); - Map forceGroups = settings.getGroups("cluster.routing.allocation.awareness.force."); + Map forceGroups = settings.getGroups(CLUSTER_ROUTING_ALLOCATION_AWARENESS_FORCE_GROUP); if (!forceGroups.isEmpty()) { for (Map.Entry entry : forceGroups.entrySet()) { String[] aValues = entry.getValue().getAsArray("values"); @@ -83,10 +78,10 @@ public AwarenessAllocationDecider(Settings settings) { @Inject public AwarenessAllocationDecider(Settings settings, NodeSettingsService nodeSettingsService) { super(settings); - this.awarenessAttributes = settings.getAsArray("cluster.routing.allocation.awareness.attributes"); + this.awarenessAttributes = settings.getAsArray(CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTES); forcedAwarenessAttributes = Maps.newHashMap(); - Map forceGroups = settings.getGroups("cluster.routing.allocation.awareness.force."); + Map forceGroups = settings.getGroups(CLUSTER_ROUTING_ALLOCATION_AWARENESS_FORCE_GROUP); for (Map.Entry entry : forceGroups.entrySet()) { String[] aValues = entry.getValue().getAsArray("values"); if (aValues.length > 0) { diff --git a/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ConcurrentRebalanceAllocationDecider.java b/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ConcurrentRebalanceAllocationDecider.java index 32f9f7c84456e..eae8003c14aa0 100644 --- a/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ConcurrentRebalanceAllocationDecider.java +++ b/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ConcurrentRebalanceAllocationDecider.java @@ -19,7 +19,6 @@ package org.elasticsearch.cluster.routing.allocation.decider; -import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.routing.MutableShardRouting; import org.elasticsearch.cluster.routing.RoutingNode; import org.elasticsearch.cluster.routing.ShardRouting; @@ -33,16 +32,12 @@ public class ConcurrentRebalanceAllocationDecider extends AllocationDecider { - static { - MetaData.addDynamicSettings( - "cluster.routing.allocation.cluster_concurrent_rebalance" - ); - } + public static final String CLUSTER_ROUTING_ALLOCATION_CLUSTER_CONCURRENT_REBALANCE = "cluster.routing.allocation.cluster_concurrent_rebalance"; class ApplySettings implements NodeSettingsService.Listener { @Override public void onRefreshSettings(Settings settings) { - int clusterConcurrentRebalance = settings.getAsInt("cluster.routing.allocation.cluster_concurrent_rebalance", ConcurrentRebalanceAllocationDecider.this.clusterConcurrentRebalance); + int clusterConcurrentRebalance = settings.getAsInt(CLUSTER_ROUTING_ALLOCATION_CLUSTER_CONCURRENT_REBALANCE, ConcurrentRebalanceAllocationDecider.this.clusterConcurrentRebalance); if (clusterConcurrentRebalance != ConcurrentRebalanceAllocationDecider.this.clusterConcurrentRebalance) { logger.info("updating [cluster.routing.allocation.cluster_concurrent_rebalance] from [{}], to [{}]", ConcurrentRebalanceAllocationDecider.this.clusterConcurrentRebalance, clusterConcurrentRebalance); ConcurrentRebalanceAllocationDecider.this.clusterConcurrentRebalance = clusterConcurrentRebalance; @@ -55,7 +50,7 @@ public void onRefreshSettings(Settings settings) { @Inject public ConcurrentRebalanceAllocationDecider(Settings settings, NodeSettingsService nodeSettingsService) { super(settings); - this.clusterConcurrentRebalance = settings.getAsInt("cluster.routing.allocation.cluster_concurrent_rebalance", 2); + this.clusterConcurrentRebalance = settings.getAsInt(CLUSTER_ROUTING_ALLOCATION_CLUSTER_CONCURRENT_REBALANCE, 2); logger.debug("using [cluster_concurrent_rebalance] with [{}]", clusterConcurrentRebalance); nodeSettingsService.addListener(new ApplySettings()); } diff --git a/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DisableAllocationDecider.java b/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DisableAllocationDecider.java index 1d923d884c6c1..cca42e8485a18 100644 --- a/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DisableAllocationDecider.java +++ b/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DisableAllocationDecider.java @@ -19,7 +19,6 @@ package org.elasticsearch.cluster.routing.allocation.decider; -import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.routing.RoutingNode; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; @@ -31,30 +30,26 @@ */ public class DisableAllocationDecider extends AllocationDecider { - static { - MetaData.addDynamicSettings( - "cluster.routing.allocation.disable_new_allocation", - "cluster.routing.allocation.disable_allocation", - "cluster.routing.allocation.disable_replica_allocation" - ); - } + public static final String CLUSTER_ROUTING_ALLOCATION_DISABLE_NEW_ALLOCATION = "cluster.routing.allocation.disable_new_allocation"; + public static final String CLUSTER_ROUTING_ALLOCATION_DISABLE_ALLOCATION = "cluster.routing.allocation.disable_allocation"; + public static final String CLUSTER_ROUTING_ALLOCATION_DISABLE_REPLICA_ALLOCATION = "cluster.routing.allocation.disable_replica_allocation"; class ApplySettings implements NodeSettingsService.Listener { @Override public void onRefreshSettings(Settings settings) { - boolean disableNewAllocation = settings.getAsBoolean("cluster.routing.allocation.disable_new_allocation", DisableAllocationDecider.this.disableNewAllocation); + boolean disableNewAllocation = settings.getAsBoolean(CLUSTER_ROUTING_ALLOCATION_DISABLE_NEW_ALLOCATION, DisableAllocationDecider.this.disableNewAllocation); if (disableNewAllocation != DisableAllocationDecider.this.disableNewAllocation) { logger.info("updating [cluster.routing.allocation.disable_new_allocation] from [{}] to [{}]", DisableAllocationDecider.this.disableNewAllocation, disableNewAllocation); DisableAllocationDecider.this.disableNewAllocation = disableNewAllocation; } - boolean disableAllocation = settings.getAsBoolean("cluster.routing.allocation.disable_allocation", DisableAllocationDecider.this.disableAllocation); + boolean disableAllocation = settings.getAsBoolean(CLUSTER_ROUTING_ALLOCATION_DISABLE_ALLOCATION, DisableAllocationDecider.this.disableAllocation); if (disableAllocation != DisableAllocationDecider.this.disableAllocation) { logger.info("updating [cluster.routing.allocation.disable_allocation] from [{}] to [{}]", DisableAllocationDecider.this.disableAllocation, disableAllocation); DisableAllocationDecider.this.disableAllocation = disableAllocation; } - boolean disableReplicaAllocation = settings.getAsBoolean("cluster.routing.allocation.disable_replica_allocation", DisableAllocationDecider.this.disableReplicaAllocation); + boolean disableReplicaAllocation = settings.getAsBoolean(CLUSTER_ROUTING_ALLOCATION_DISABLE_REPLICA_ALLOCATION, DisableAllocationDecider.this.disableReplicaAllocation); if (disableReplicaAllocation != DisableAllocationDecider.this.disableReplicaAllocation) { logger.info("updating [cluster.routing.allocation.disable_replica_allocation] from [{}] to [{}]", DisableAllocationDecider.this.disableReplicaAllocation, disableReplicaAllocation); DisableAllocationDecider.this.disableReplicaAllocation = disableReplicaAllocation; @@ -69,9 +64,9 @@ public void onRefreshSettings(Settings settings) { @Inject public DisableAllocationDecider(Settings settings, NodeSettingsService nodeSettingsService) { super(settings); - this.disableNewAllocation = settings.getAsBoolean("cluster.routing.allocation.disable_new_allocation", false); - this.disableAllocation = settings.getAsBoolean("cluster.routing.allocation.disable_allocation", false); - this.disableReplicaAllocation = settings.getAsBoolean("cluster.routing.allocation.disable_replica_allocation", false); + this.disableNewAllocation = settings.getAsBoolean(CLUSTER_ROUTING_ALLOCATION_DISABLE_NEW_ALLOCATION, false); + this.disableAllocation = settings.getAsBoolean(CLUSTER_ROUTING_ALLOCATION_DISABLE_ALLOCATION, false); + this.disableReplicaAllocation = settings.getAsBoolean(CLUSTER_ROUTING_ALLOCATION_DISABLE_REPLICA_ALLOCATION, false); nodeSettingsService.addListener(new ApplySettings()); } diff --git a/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDecider.java b/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDecider.java index c18c0567ba15f..8da31103a4526 100644 --- a/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDecider.java +++ b/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDecider.java @@ -21,7 +21,6 @@ import com.google.common.collect.ImmutableMap; import org.elasticsearch.cluster.metadata.IndexMetaData; -import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.node.DiscoveryNodeFilters; import org.elasticsearch.cluster.routing.RoutingNode; import org.elasticsearch.cluster.routing.ShardRouting; @@ -30,24 +29,20 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.node.settings.NodeSettingsService; -import static org.elasticsearch.cluster.node.DiscoveryNodeFilters.OpType.*; +import static org.elasticsearch.cluster.node.DiscoveryNodeFilters.OpType.AND; +import static org.elasticsearch.cluster.node.DiscoveryNodeFilters.OpType.OR; /** */ public class FilterAllocationDecider extends AllocationDecider { - static { - MetaData.addDynamicSettings( - "cluster.routing.allocation.require.*", - "cluster.routing.allocation.include.*", - "cluster.routing.allocation.exclude.*" - ); - IndexMetaData.addDynamicSettings( - "index.routing.allocation.require.*", - "index.routing.allocation.include.*", - "index.routing.allocation.exclude.*" - ); - } + public static final String INDEX_ROUTING_REQUIRE_GROUP = "index.routing.allocation.require."; + public static final String INDEX_ROUTING_INCLUDE_GROUP = "index.routing.allocation.include."; + public static final String INDEX_ROUTING_EXCLUDE_GROUP = "index.routing.allocation.exclude."; + + public static final String CLUSTER_ROUTING_REQUIRE_GROUP = "cluster.routing.allocation.require."; + public static final String CLUSTER_ROUTING_INCLUDE_GROUP = "cluster.routing.allocation.include."; + public static final String CLUSTER_ROUTING_EXCLUDE_GROUP = "cluster.routing.allocation.exclude."; private volatile DiscoveryNodeFilters clusterRequireFilters; private volatile DiscoveryNodeFilters clusterIncludeFilters; @@ -56,19 +51,19 @@ public class FilterAllocationDecider extends AllocationDecider { @Inject public FilterAllocationDecider(Settings settings, NodeSettingsService nodeSettingsService) { super(settings); - ImmutableMap requireMap = settings.getByPrefix("cluster.routing.allocation.require.").getAsMap(); + ImmutableMap requireMap = settings.getByPrefix(CLUSTER_ROUTING_REQUIRE_GROUP).getAsMap(); if (requireMap.isEmpty()) { clusterRequireFilters = null; } else { clusterRequireFilters = DiscoveryNodeFilters.buildFromKeyValue(AND, requireMap); } - ImmutableMap includeMap = settings.getByPrefix("cluster.routing.allocation.include.").getAsMap(); + ImmutableMap includeMap = settings.getByPrefix(CLUSTER_ROUTING_INCLUDE_GROUP).getAsMap(); if (includeMap.isEmpty()) { clusterIncludeFilters = null; } else { clusterIncludeFilters = DiscoveryNodeFilters.buildFromKeyValue(OR, includeMap); } - ImmutableMap excludeMap = settings.getByPrefix("cluster.routing.allocation.exclude.").getAsMap(); + ImmutableMap excludeMap = settings.getByPrefix(CLUSTER_ROUTING_EXCLUDE_GROUP).getAsMap(); if (excludeMap.isEmpty()) { clusterExcludeFilters = null; } else { @@ -127,15 +122,15 @@ private boolean shouldFilter(ShardRouting shardRouting, RoutingNode node, Routin class ApplySettings implements NodeSettingsService.Listener { @Override public void onRefreshSettings(Settings settings) { - ImmutableMap requireMap = settings.getByPrefix("cluster.routing.allocation.require.").getAsMap(); + ImmutableMap requireMap = settings.getByPrefix(CLUSTER_ROUTING_REQUIRE_GROUP).getAsMap(); if (!requireMap.isEmpty()) { clusterRequireFilters = DiscoveryNodeFilters.buildFromKeyValue(AND, requireMap); } - ImmutableMap includeMap = settings.getByPrefix("cluster.routing.allocation.include.").getAsMap(); + ImmutableMap includeMap = settings.getByPrefix(CLUSTER_ROUTING_INCLUDE_GROUP).getAsMap(); if (!includeMap.isEmpty()) { clusterIncludeFilters = DiscoveryNodeFilters.buildFromKeyValue(OR, includeMap); } - ImmutableMap excludeMap = settings.getByPrefix("cluster.routing.allocation.exclude.").getAsMap(); + ImmutableMap excludeMap = settings.getByPrefix(CLUSTER_ROUTING_EXCLUDE_GROUP).getAsMap(); if (!excludeMap.isEmpty()) { clusterExcludeFilters = DiscoveryNodeFilters.buildFromKeyValue(OR, excludeMap); } diff --git a/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ShardsLimitAllocationDecider.java b/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ShardsLimitAllocationDecider.java index 6f39ec9217cbe..6ddbaf4ac3c02 100644 --- a/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ShardsLimitAllocationDecider.java +++ b/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ShardsLimitAllocationDecider.java @@ -36,12 +36,6 @@ public class ShardsLimitAllocationDecider extends AllocationDecider { public static final String INDEX_TOTAL_SHARDS_PER_NODE = "index.routing.allocation.total_shards_per_node"; - static { - IndexMetaData.addDynamicSettings( - INDEX_TOTAL_SHARDS_PER_NODE - ); - } - @Inject public ShardsLimitAllocationDecider(Settings settings) { super(settings); diff --git a/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ThrottlingAllocationDecider.java b/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ThrottlingAllocationDecider.java index 8f5ee2f567a51..4b6688970c743 100644 --- a/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ThrottlingAllocationDecider.java +++ b/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ThrottlingAllocationDecider.java @@ -19,7 +19,6 @@ package org.elasticsearch.cluster.routing.allocation.decider; -import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.routing.MutableShardRouting; import org.elasticsearch.cluster.routing.RoutingNode; import org.elasticsearch.cluster.routing.ShardRouting; @@ -35,12 +34,8 @@ */ public class ThrottlingAllocationDecider extends AllocationDecider { - static { - MetaData.addDynamicSettings( - "cluster.routing.allocation.node_initial_primaries_recoveries", - "cluster.routing.allocation.node_concurrent_recoveries" - ); - } + public static final String CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_PRIMARIES_RECOVERIES = "cluster.routing.allocation.node_initial_primaries_recoveries"; + public static final String CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_RECOVERIES = "cluster.routing.allocation.node_concurrent_recoveries"; private volatile int primariesInitialRecoveries; private volatile int concurrentRecoveries; @@ -49,8 +44,8 @@ public class ThrottlingAllocationDecider extends AllocationDecider { public ThrottlingAllocationDecider(Settings settings, NodeSettingsService nodeSettingsService) { super(settings); - this.primariesInitialRecoveries = settings.getAsInt("cluster.routing.allocation.node_initial_primaries_recoveries", settings.getAsInt("cluster.routing.allocation.node_initial_primaries_recoveries", 4)); - this.concurrentRecoveries = settings.getAsInt("cluster.routing.allocation.concurrent_recoveries", settings.getAsInt("cluster.routing.allocation.node_concurrent_recoveries", 2)); + this.primariesInitialRecoveries = settings.getAsInt(CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_PRIMARIES_RECOVERIES, 4); + this.concurrentRecoveries = settings.getAsInt("cluster.routing.allocation.concurrent_recoveries", settings.getAsInt(CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_RECOVERIES, 2)); logger.debug("using node_concurrent_recoveries [{}], node_initial_primaries_recoveries [{}]", concurrentRecoveries, primariesInitialRecoveries); nodeSettingsService.addListener(new ApplySettings()); @@ -106,13 +101,13 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing class ApplySettings implements NodeSettingsService.Listener { @Override public void onRefreshSettings(Settings settings) { - int primariesInitialRecoveries = settings.getAsInt("cluster.routing.allocation.node_initial_primaries_recoveries", ThrottlingAllocationDecider.this.primariesInitialRecoveries); + int primariesInitialRecoveries = settings.getAsInt(CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_PRIMARIES_RECOVERIES, ThrottlingAllocationDecider.this.primariesInitialRecoveries); if (primariesInitialRecoveries != ThrottlingAllocationDecider.this.primariesInitialRecoveries) { logger.info("updating [cluster.routing.allocation.node_initial_primaries_recoveries] from [{}] to [{}]", ThrottlingAllocationDecider.this.primariesInitialRecoveries, primariesInitialRecoveries); ThrottlingAllocationDecider.this.primariesInitialRecoveries = primariesInitialRecoveries; } - int concurrentRecoveries = settings.getAsInt("cluster.routing.allocation.node_concurrent_recoveries", ThrottlingAllocationDecider.this.concurrentRecoveries); + int concurrentRecoveries = settings.getAsInt(CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_RECOVERIES, ThrottlingAllocationDecider.this.concurrentRecoveries); if (concurrentRecoveries != ThrottlingAllocationDecider.this.concurrentRecoveries) { logger.info("updating [cluster.routing.allocation.node_concurrent_recoveries] from [{}] to [{}]", ThrottlingAllocationDecider.this.concurrentRecoveries, concurrentRecoveries); ThrottlingAllocationDecider.this.concurrentRecoveries = concurrentRecoveries; diff --git a/src/main/java/org/elasticsearch/cluster/settings/ClusterDynamicSettings.java b/src/main/java/org/elasticsearch/cluster/settings/ClusterDynamicSettings.java new file mode 100644 index 0000000000000..8834856818174 --- /dev/null +++ b/src/main/java/org/elasticsearch/cluster/settings/ClusterDynamicSettings.java @@ -0,0 +1,38 @@ +/* + * Licensed to ElasticSearch and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. ElasticSearch licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.cluster.settings; + +import org.elasticsearch.common.inject.BindingAnnotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + + +@BindingAnnotation +@Target({FIELD, PARAMETER}) +@Retention(RUNTIME) +@Documented +public @interface ClusterDynamicSettings { +} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/cluster/settings/ClusterDynamicSettingsModule.java b/src/main/java/org/elasticsearch/cluster/settings/ClusterDynamicSettingsModule.java new file mode 100644 index 0000000000000..047a6ebed9ac6 --- /dev/null +++ b/src/main/java/org/elasticsearch/cluster/settings/ClusterDynamicSettingsModule.java @@ -0,0 +1,77 @@ +/* + * Licensed to ElasticSearch and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. ElasticSearch licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.cluster.settings; + +import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.cluster.routing.allocation.decider.*; +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.discovery.zen.elect.ElectMasterService; +import org.elasticsearch.indices.cache.filter.IndicesFilterCache; +import org.elasticsearch.indices.recovery.RecoverySettings; +import org.elasticsearch.indices.store.IndicesStore; +import org.elasticsearch.indices.ttl.IndicesTTLService; +import org.elasticsearch.threadpool.ThreadPool; + +/** + */ +public class ClusterDynamicSettingsModule extends AbstractModule { + + private final DynamicSettings clusterDynamicSettings; + + public ClusterDynamicSettingsModule() { + clusterDynamicSettings = new DynamicSettings(); + clusterDynamicSettings.addDynamicSettings( + AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTES, + AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_FORCE_GROUP + "*", + ConcurrentRebalanceAllocationDecider.CLUSTER_ROUTING_ALLOCATION_CLUSTER_CONCURRENT_REBALANCE, + DisableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_DISABLE_NEW_ALLOCATION, + DisableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_DISABLE_ALLOCATION, + DisableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_DISABLE_REPLICA_ALLOCATION, + ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES, + FilterAllocationDecider.CLUSTER_ROUTING_INCLUDE_GROUP + "*", + FilterAllocationDecider.CLUSTER_ROUTING_EXCLUDE_GROUP + "*", + FilterAllocationDecider.CLUSTER_ROUTING_REQUIRE_GROUP + "*", + IndicesFilterCache.INDICES_CACHE_FILTER_SIZE, + IndicesFilterCache.INDICES_CACHE_FILTER_EXPIRE, + IndicesStore.INDICES_STORE_THROTTLE_TYPE, + IndicesStore.INDICES_STORE_THROTTLE_MAX_BYTES_PER_SEC, + IndicesTTLService.INDICES_TTL_INTERVAL, + MetaData.SETTING_READ_ONLY, + RecoverySettings.INDICES_RECOVERY_FILE_CHUNK_SIZE, + RecoverySettings.INDICES_RECOVERY_TRANSLOG_OPS, + RecoverySettings.INDICES_RECOVERY_TRANSLOG_SIZE, + RecoverySettings.INDICES_RECOVERY_COMPRESS, + RecoverySettings.INDICES_RECOVERY_CONCURRENT_STREAMS, + RecoverySettings.INDICES_RECOVERY_MAX_SIZE_PER_SEC, + ThreadPool.THREADPOOL_GROUP + "*", + ThrottlingAllocationDecider.CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_PRIMARIES_RECOVERIES, + ThrottlingAllocationDecider.CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_RECOVERIES + ); + } + + public void addDynamicSetting(String... settings) { + clusterDynamicSettings.addDynamicSettings(settings); + } + + @Override + protected void configure() { + bind(DynamicSettings.class).annotatedWith(ClusterDynamicSettings.class).toInstance(clusterDynamicSettings); + } +} diff --git a/src/main/java/org/elasticsearch/cluster/settings/DynamicSettings.java b/src/main/java/org/elasticsearch/cluster/settings/DynamicSettings.java new file mode 100644 index 0000000000000..61c3e1f90376f --- /dev/null +++ b/src/main/java/org/elasticsearch/cluster/settings/DynamicSettings.java @@ -0,0 +1,49 @@ +/* + * Licensed to ElasticSearch and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. ElasticSearch licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.cluster.settings; + +import com.google.common.collect.ImmutableSet; +import org.elasticsearch.common.regex.Regex; + +import java.util.Arrays; +import java.util.HashSet; + +/** + */ +public class DynamicSettings { + + private ImmutableSet dynamicSettings = ImmutableSet.of(); + + public boolean hasDynamicSetting(String key) { + for (String dynamicSetting : dynamicSettings) { + if (Regex.simpleMatch(dynamicSetting, key)) { + return true; + } + } + return false; + } + + public synchronized void addDynamicSettings(String... settings) { + HashSet updatedSettings = new HashSet(dynamicSettings); + updatedSettings.addAll(Arrays.asList(settings)); + dynamicSettings = ImmutableSet.copyOf(updatedSettings); + } + +} diff --git a/src/main/java/org/elasticsearch/discovery/zen/elect/ElectMasterService.java b/src/main/java/org/elasticsearch/discovery/zen/elect/ElectMasterService.java index 9726b11b289d9..e0192a4573983 100644 --- a/src/main/java/org/elasticsearch/discovery/zen/elect/ElectMasterService.java +++ b/src/main/java/org/elasticsearch/discovery/zen/elect/ElectMasterService.java @@ -20,7 +20,6 @@ package org.elasticsearch.discovery.zen.elect; import com.google.common.collect.Lists; -import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.settings.Settings; @@ -35,9 +34,7 @@ */ public class ElectMasterService extends AbstractComponent { - static { - MetaData.addDynamicSettings("discovery.zen.minimum_master_nodes"); - } + public static final String DISCOVERY_ZEN_MINIMUM_MASTER_NODES = "discovery.zen.minimum_master_nodes"; private final NodeComparator nodeComparator = new NodeComparator(); @@ -45,7 +42,7 @@ public class ElectMasterService extends AbstractComponent { public ElectMasterService(Settings settings) { super(settings); - this.minimumMasterNodes = settings.getAsInt("discovery.zen.minimum_master_nodes", -1); + this.minimumMasterNodes = settings.getAsInt(DISCOVERY_ZEN_MINIMUM_MASTER_NODES, -1); logger.debug("using minimum_master_nodes [{}]", minimumMasterNodes); } diff --git a/src/main/java/org/elasticsearch/gateway/local/LocalGatewayAllocator.java b/src/main/java/org/elasticsearch/gateway/local/LocalGatewayAllocator.java index 9d65b72a0ffd4..a95a6806e7efd 100644 --- a/src/main/java/org/elasticsearch/gateway/local/LocalGatewayAllocator.java +++ b/src/main/java/org/elasticsearch/gateway/local/LocalGatewayAllocator.java @@ -58,9 +58,7 @@ */ public class LocalGatewayAllocator extends AbstractComponent implements GatewayAllocator { - static { - IndexMetaData.addDynamicSettings("index.recovery.initial_shards"); - } + public static final String INDEX_RECOVERY_INITIAL_SHARDS = "index.recovery.initial_shards"; private final TransportNodesListGatewayStartedShards listGatewayStartedShards; @@ -156,7 +154,7 @@ public boolean allocateUnassigned(RoutingAllocation allocation) { int requiredAllocation = 1; try { IndexMetaData indexMetaData = routingNodes.metaData().index(shard.index()); - String initialShards = indexMetaData.settings().get("index.recovery.initial_shards", settings.get("index.recovery.initial_shards", this.initialShards)); + String initialShards = indexMetaData.settings().get(INDEX_RECOVERY_INITIAL_SHARDS, settings.get(INDEX_RECOVERY_INITIAL_SHARDS, this.initialShards)); if ("quorum".equals(initialShards)) { if (indexMetaData.numberOfReplicas() > 1) { requiredAllocation = ((1 + indexMetaData.numberOfReplicas()) / 2) + 1; diff --git a/src/main/java/org/elasticsearch/index/cache/field/data/resident/ResidentFieldDataCache.java b/src/main/java/org/elasticsearch/index/cache/field/data/resident/ResidentFieldDataCache.java index 6bd2effb578e3..50a96cbd80cf7 100644 --- a/src/main/java/org/elasticsearch/index/cache/field/data/resident/ResidentFieldDataCache.java +++ b/src/main/java/org/elasticsearch/index/cache/field/data/resident/ResidentFieldDataCache.java @@ -25,7 +25,6 @@ import com.google.common.cache.RemovalListener; import com.google.common.cache.RemovalNotification; import org.elasticsearch.ElasticSearchException; -import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.metrics.CounterMetric; import org.elasticsearch.common.settings.Settings; @@ -57,8 +56,8 @@ public ResidentFieldDataCache(Index index, @IndexSettings Settings indexSettings super(index, indexSettings); this.indexSettingsService = indexSettingsService; - this.maxSize = indexSettings.getAsInt("index.cache.field.max_size", componentSettings.getAsInt("max_size", -1)); - this.expire = indexSettings.getAsTime("index.cache.field.expire", componentSettings.getAsTime("expire", null)); + this.maxSize = indexSettings.getAsInt(INDEX_CACHE_FIELD_MAX_SIZE, componentSettings.getAsInt("max_size", -1)); + this.expire = indexSettings.getAsTime(INDEX_CACHE_FIELD_EXPIRE, componentSettings.getAsTime("expire", null)); logger.debug("using [resident] field cache with max_size [{}], expire [{}]", maxSize, expire); indexSettingsService.addListener(applySettings); @@ -99,18 +98,14 @@ public void onRemoval(RemovalNotification removalNotification } } - static { - IndexMetaData.addDynamicSettings( - "index.cache.field.max_size", - "index.cache.field.expire" - ); - } + public static final String INDEX_CACHE_FIELD_MAX_SIZE = "index.cache.field.max_size"; + public static final String INDEX_CACHE_FIELD_EXPIRE = "index.cache.field.expire"; class ApplySettings implements IndexSettingsService.Listener { @Override public void onRefreshSettings(Settings settings) { - int maxSize = settings.getAsInt("index.cache.field.max_size", ResidentFieldDataCache.this.maxSize); - TimeValue expire = settings.getAsTime("index.cache.field.expire", ResidentFieldDataCache.this.expire); + int maxSize = settings.getAsInt(INDEX_CACHE_FIELD_MAX_SIZE, ResidentFieldDataCache.this.maxSize); + TimeValue expire = settings.getAsTime(INDEX_CACHE_FIELD_EXPIRE, ResidentFieldDataCache.this.expire); boolean changed = false; if (maxSize != ResidentFieldDataCache.this.maxSize) { logger.info("updating index.cache.field.max_size from [{}] to [{}]", ResidentFieldDataCache.this.maxSize, maxSize); diff --git a/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java b/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java index 872a18627776b..f4376bdcc0e8d 100644 --- a/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java +++ b/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java @@ -26,7 +26,6 @@ import org.apache.lucene.util.UnicodeUtil; import org.elasticsearch.ElasticSearchException; import org.elasticsearch.ElasticSearchIllegalStateException; -import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.routing.operation.hash.djb.DjbHashFunction; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Preconditions; @@ -161,10 +160,10 @@ public RobinEngine(ShardId shardId, @IndexSettings Settings indexSettings, Threa Preconditions.checkNotNull(deletionPolicy, "Snapshot deletion policy must be provided to the engine"); Preconditions.checkNotNull(translog, "Translog must be provided to the engine"); - this.gcDeletesInMillis = indexSettings.getAsTime("index.gc_deletes", TimeValue.timeValueSeconds(60)).millis(); + this.gcDeletesInMillis = indexSettings.getAsTime(INDEX_GC_DELETES, TimeValue.timeValueSeconds(60)).millis(); this.indexingBufferSize = componentSettings.getAsBytesSize("index_buffer_size", new ByteSizeValue(64, ByteSizeUnit.MB)); // not really important, as it is set by the IndexingMemory manager - this.termIndexInterval = indexSettings.getAsInt("index.term_index_interval", IndexWriterConfig.DEFAULT_TERM_INDEX_INTERVAL); - this.termIndexDivisor = indexSettings.getAsInt("index.term_index_divisor", 1); // IndexReader#DEFAULT_TERMS_INDEX_DIVISOR + this.termIndexInterval = indexSettings.getAsInt(INDEX_TERM_INDEX_INTERVAL, IndexWriterConfig.DEFAULT_TERM_INDEX_INTERVAL); + this.termIndexDivisor = indexSettings.getAsInt(INDEX_TERM_INDEX_DIVISOR, 1); // IndexReader#DEFAULT_TERMS_INDEX_DIVISOR this.asyncLoadBloomFilter = componentSettings.getAsBoolean("async_load_bloom", true); // Here for testing, should always be true this.threadPool = threadPool; @@ -180,7 +179,7 @@ public RobinEngine(ShardId shardId, @IndexSettings Settings indexSettings, Threa this.similarityService = similarityService; this.bloomCache = bloomCache; - this.indexConcurrency = indexSettings.getAsInt("index.index_concurrency", IndexWriterConfig.DEFAULT_MAX_THREAD_STATES); + this.indexConcurrency = indexSettings.getAsInt(INDEX_INDEX_CONCURRENCY, IndexWriterConfig.DEFAULT_MAX_THREAD_STATES); this.versionMap = ConcurrentCollections.newConcurrentMap(); this.dirtyLocks = new Object[indexConcurrency * 50]; // we multiply it to have enough... for (int i = 0; i < dirtyLocks.length; i++) { @@ -1370,28 +1369,23 @@ private IndexWriter createWriter() throws IOException { return indexWriter; } - static { - IndexMetaData.addDynamicSettings( - "index.term_index_interval", - "index.term_index_divisor", - "index.index_concurrency", - "index.gc_deletes" - ); - } - + public static final String INDEX_TERM_INDEX_INTERVAL = "index.term_index_interval"; + public static final String INDEX_TERM_INDEX_DIVISOR = "index.term_index_divisor"; + public static final String INDEX_INDEX_CONCURRENCY = "index.index_concurrency"; + public static final String INDEX_GC_DELETES = "index.gc_deletes"; class ApplySettings implements IndexSettingsService.Listener { @Override public void onRefreshSettings(Settings settings) { - long gcDeletesInMillis = indexSettings.getAsTime("index.gc_deletes", TimeValue.timeValueMillis(RobinEngine.this.gcDeletesInMillis)).millis(); + long gcDeletesInMillis = indexSettings.getAsTime(INDEX_GC_DELETES, TimeValue.timeValueMillis(RobinEngine.this.gcDeletesInMillis)).millis(); if (gcDeletesInMillis != RobinEngine.this.gcDeletesInMillis) { logger.info("updating index.gc_deletes from [{}] to [{}]", TimeValue.timeValueMillis(RobinEngine.this.gcDeletesInMillis), TimeValue.timeValueMillis(gcDeletesInMillis)); RobinEngine.this.gcDeletesInMillis = gcDeletesInMillis; } - int termIndexInterval = settings.getAsInt("index.term_index_interval", RobinEngine.this.termIndexInterval); - int termIndexDivisor = settings.getAsInt("index.term_index_divisor", RobinEngine.this.termIndexDivisor); // IndexReader#DEFAULT_TERMS_INDEX_DIVISOR - int indexConcurrency = settings.getAsInt("index.index_concurrency", RobinEngine.this.indexConcurrency); + int termIndexInterval = settings.getAsInt(INDEX_TERM_INDEX_INTERVAL, RobinEngine.this.termIndexInterval); + int termIndexDivisor = settings.getAsInt(INDEX_TERM_INDEX_DIVISOR, RobinEngine.this.termIndexDivisor); // IndexReader#DEFAULT_TERMS_INDEX_DIVISOR + int indexConcurrency = settings.getAsInt(INDEX_INDEX_CONCURRENCY, RobinEngine.this.indexConcurrency); boolean requiresFlushing = false; if (termIndexInterval != RobinEngine.this.termIndexInterval || termIndexDivisor != RobinEngine.this.termIndexDivisor) { rwl.readLock().lock(); diff --git a/src/main/java/org/elasticsearch/index/gateway/IndexShardGatewayService.java b/src/main/java/org/elasticsearch/index/gateway/IndexShardGatewayService.java index 04282dbe37ff0..5f17a651d55c4 100644 --- a/src/main/java/org/elasticsearch/index/gateway/IndexShardGatewayService.java +++ b/src/main/java/org/elasticsearch/index/gateway/IndexShardGatewayService.java @@ -19,7 +19,6 @@ package org.elasticsearch.index.gateway; -import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; @@ -92,14 +91,12 @@ public IndexShardGatewayService(ShardId shardId, @IndexSettings Settings indexSe indexSettingsService.addListener(applySettings); } - static { - IndexMetaData.addDynamicSettings("index.gateway.snapshot_interval"); - } + public static final String INDEX_GATEWAY_SNAPSHOT_INTERVAL = "index.gateway.snapshot_interval"; class ApplySettings implements IndexSettingsService.Listener { @Override public void onRefreshSettings(Settings settings) { - TimeValue snapshotInterval = settings.getAsTime("index.gateway.snapshot_interval", IndexShardGatewayService.this.snapshotInterval); + TimeValue snapshotInterval = settings.getAsTime(INDEX_GATEWAY_SNAPSHOT_INTERVAL, IndexShardGatewayService.this.snapshotInterval); if (!snapshotInterval.equals(IndexShardGatewayService.this.snapshotInterval)) { logger.info("updating snapshot_interval from [{}] to [{}]", IndexShardGatewayService.this.snapshotInterval, snapshotInterval); IndexShardGatewayService.this.snapshotInterval = snapshotInterval; diff --git a/src/main/java/org/elasticsearch/index/indexing/slowlog/ShardSlowLogIndexingService.java b/src/main/java/org/elasticsearch/index/indexing/slowlog/ShardSlowLogIndexingService.java index 1933d1375f2c2..15035219d7e29 100644 --- a/src/main/java/org/elasticsearch/index/indexing/slowlog/ShardSlowLogIndexingService.java +++ b/src/main/java/org/elasticsearch/index/indexing/slowlog/ShardSlowLogIndexingService.java @@ -19,7 +19,6 @@ package org.elasticsearch.index.indexing.slowlog; -import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; @@ -52,45 +51,41 @@ public class ShardSlowLogIndexingService extends AbstractIndexShardComponent { private final ESLogger indexLogger; private final ESLogger deleteLogger; - static { - IndexMetaData.addDynamicSettings( - "index.indexing.slowlog.threshold.index.warn", - "index.indexing.slowlog.threshold.index.info", - "index.indexing.slowlog.threshold.index.debug", - "index.indexing.slowlog.threshold.index.trace", - "index.indexing.slowlog.reformat", - "index.indexing.slowlog.level" - ); - } + public static final String INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_WARN = "index.indexing.slowlog.threshold.index.warn"; + public static final String INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_INFO = "index.indexing.slowlog.threshold.index.info"; + public static final String INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_DEBUG = "index.indexing.slowlog.threshold.index.debug"; + public static final String INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_TRACE = "index.indexing.slowlog.threshold.index.trace"; + public static final String INDEX_INDEXING_SLOWLOG_REFORMAT = "index.indexing.slowlog.reformat"; + public static final String INDEX_INDEXING_SLOWLOG_LEVEL = "index.indexing.slowlog.level"; class ApplySettings implements IndexSettingsService.Listener { @Override public synchronized void onRefreshSettings(Settings settings) { - long indexWarnThreshold = settings.getAsTime("index.indexing.slowlog.threshold.index.warn", TimeValue.timeValueNanos(ShardSlowLogIndexingService.this.indexWarnThreshold)).nanos(); + long indexWarnThreshold = settings.getAsTime(INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_WARN, TimeValue.timeValueNanos(ShardSlowLogIndexingService.this.indexWarnThreshold)).nanos(); if (indexWarnThreshold != ShardSlowLogIndexingService.this.indexWarnThreshold) { ShardSlowLogIndexingService.this.indexWarnThreshold = indexWarnThreshold; } - long indexInfoThreshold = settings.getAsTime("index.indexing.slowlog.threshold.index.info", TimeValue.timeValueNanos(ShardSlowLogIndexingService.this.indexInfoThreshold)).nanos(); + long indexInfoThreshold = settings.getAsTime(INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_INFO, TimeValue.timeValueNanos(ShardSlowLogIndexingService.this.indexInfoThreshold)).nanos(); if (indexInfoThreshold != ShardSlowLogIndexingService.this.indexInfoThreshold) { ShardSlowLogIndexingService.this.indexInfoThreshold = indexInfoThreshold; } - long indexDebugThreshold = settings.getAsTime("index.indexing.slowlog.threshold.index.debug", TimeValue.timeValueNanos(ShardSlowLogIndexingService.this.indexDebugThreshold)).nanos(); + long indexDebugThreshold = settings.getAsTime(INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_DEBUG, TimeValue.timeValueNanos(ShardSlowLogIndexingService.this.indexDebugThreshold)).nanos(); if (indexDebugThreshold != ShardSlowLogIndexingService.this.indexDebugThreshold) { ShardSlowLogIndexingService.this.indexDebugThreshold = indexDebugThreshold; } - long indexTraceThreshold = settings.getAsTime("index.indexing.slowlog.threshold.index.trace", TimeValue.timeValueNanos(ShardSlowLogIndexingService.this.indexTraceThreshold)).nanos(); + long indexTraceThreshold = settings.getAsTime(INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_TRACE, TimeValue.timeValueNanos(ShardSlowLogIndexingService.this.indexTraceThreshold)).nanos(); if (indexTraceThreshold != ShardSlowLogIndexingService.this.indexTraceThreshold) { ShardSlowLogIndexingService.this.indexTraceThreshold = indexTraceThreshold; } - String level = settings.get("index.indexing.slowlog.level", ShardSlowLogIndexingService.this.level); + String level = settings.get(INDEX_INDEXING_SLOWLOG_LEVEL, ShardSlowLogIndexingService.this.level); if (!level.equals(ShardSlowLogIndexingService.this.level)) { ShardSlowLogIndexingService.this.indexLogger.setLevel(level.toUpperCase()); ShardSlowLogIndexingService.this.deleteLogger.setLevel(level.toUpperCase()); ShardSlowLogIndexingService.this.level = level; } - boolean reformat = settings.getAsBoolean("index.indexing.slowlog.reformat", ShardSlowLogIndexingService.this.reformat); + boolean reformat = settings.getAsBoolean(INDEX_INDEXING_SLOWLOG_REFORMAT, ShardSlowLogIndexingService.this.reformat); if (reformat != ShardSlowLogIndexingService.this.reformat) { ShardSlowLogIndexingService.this.reformat = reformat; } diff --git a/src/main/java/org/elasticsearch/index/merge/policy/LogByteSizeMergePolicyProvider.java b/src/main/java/org/elasticsearch/index/merge/policy/LogByteSizeMergePolicyProvider.java index fcede657031b5..97ab324e86c8e 100644 --- a/src/main/java/org/elasticsearch/index/merge/policy/LogByteSizeMergePolicyProvider.java +++ b/src/main/java/org/elasticsearch/index/merge/policy/LogByteSizeMergePolicyProvider.java @@ -24,7 +24,6 @@ import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.SegmentInfos; import org.elasticsearch.ElasticSearchException; -import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.Preconditions; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; @@ -64,7 +63,7 @@ public LogByteSizeMergePolicyProvider(Store store, IndexSettingsService indexSet Preconditions.checkNotNull(store, "Store must be provided to merge policy"); this.indexSettingsService = indexSettingsService; - this.compoundFormat = indexSettings.getAsBoolean("index.compound_format", store.suggestUseCompoundFile()); + this.compoundFormat = indexSettings.getAsBoolean(INDEX_COMPOUND_FORMAT, store.suggestUseCompoundFile()); this.minMergeSize = componentSettings.getAsBytesSize("min_merge_size", new ByteSizeValue((long) (LogByteSizeMergePolicy.DEFAULT_MIN_MERGE_MB * 1024 * 1024), ByteSizeUnit.BYTES)); this.maxMergeSize = componentSettings.getAsBytesSize("max_merge_size", new ByteSizeValue((long) LogByteSizeMergePolicy.DEFAULT_MAX_MERGE_MB, ByteSizeUnit.MB)); this.mergeFactor = componentSettings.getAsInt("merge_factor", LogByteSizeMergePolicy.DEFAULT_MERGE_FACTOR); @@ -101,20 +100,16 @@ public void close(boolean delete) throws ElasticSearchException { indexSettingsService.removeListener(applySettings); } - static { - IndexMetaData.addDynamicSettings( - "index.merge.policy.min_merge_size", - "index.merge.policy.max_merge_size", - "index.merge.policy.max_merge_docs", - "index.merge.policy.merge_factor", - "index.compound_format" - ); - } + public static final String INDEX_MERGE_POLICY_MIN_MERGE_SIZE = "index.merge.policy.min_merge_size"; + public static final String INDEX_MERGE_POLICY_MAX_MERGE_SIZE = "index.merge.policy.max_merge_size"; + public static final String INDEX_MERGE_POLICY_MAX_MERGE_DOCS = "index.merge.policy.max_merge_docs"; + public static final String INDEX_MERGE_POLICY_MERGE_FACTOR = "index.merge.policy.merge_factor"; + public static final String INDEX_COMPOUND_FORMAT = "index.compound_format"; class ApplySettings implements IndexSettingsService.Listener { @Override public void onRefreshSettings(Settings settings) { - ByteSizeValue minMergeSize = settings.getAsBytesSize("index.merge.policy.min_merge_size", LogByteSizeMergePolicyProvider.this.minMergeSize); + ByteSizeValue minMergeSize = settings.getAsBytesSize(INDEX_MERGE_POLICY_MIN_MERGE_SIZE, LogByteSizeMergePolicyProvider.this.minMergeSize); if (!minMergeSize.equals(LogByteSizeMergePolicyProvider.this.minMergeSize)) { logger.info("updating min_merge_size from [{}] to [{}]", LogByteSizeMergePolicyProvider.this.minMergeSize, minMergeSize); LogByteSizeMergePolicyProvider.this.minMergeSize = minMergeSize; @@ -123,7 +118,7 @@ public void onRefreshSettings(Settings settings) { } } - ByteSizeValue maxMergeSize = settings.getAsBytesSize("index.merge.policy.max_merge_size", LogByteSizeMergePolicyProvider.this.maxMergeSize); + ByteSizeValue maxMergeSize = settings.getAsBytesSize(INDEX_MERGE_POLICY_MAX_MERGE_SIZE, LogByteSizeMergePolicyProvider.this.maxMergeSize); if (!maxMergeSize.equals(LogByteSizeMergePolicyProvider.this.maxMergeSize)) { logger.info("updating max_merge_size from [{}] to [{}]", LogByteSizeMergePolicyProvider.this.maxMergeSize, maxMergeSize); LogByteSizeMergePolicyProvider.this.maxMergeSize = maxMergeSize; @@ -132,7 +127,7 @@ public void onRefreshSettings(Settings settings) { } } - int maxMergeDocs = settings.getAsInt("index.merge.policy.max_merge_docs", LogByteSizeMergePolicyProvider.this.maxMergeDocs); + int maxMergeDocs = settings.getAsInt(INDEX_MERGE_POLICY_MAX_MERGE_DOCS, LogByteSizeMergePolicyProvider.this.maxMergeDocs); if (maxMergeDocs != LogByteSizeMergePolicyProvider.this.maxMergeDocs) { logger.info("updating max_merge_docs from [{}] to [{}]", LogByteSizeMergePolicyProvider.this.maxMergeDocs, maxMergeDocs); LogByteSizeMergePolicyProvider.this.maxMergeDocs = maxMergeDocs; @@ -141,7 +136,7 @@ public void onRefreshSettings(Settings settings) { } } - int mergeFactor = settings.getAsInt("index.merge.policy.merge_factor", LogByteSizeMergePolicyProvider.this.mergeFactor); + int mergeFactor = settings.getAsInt(INDEX_MERGE_POLICY_MERGE_FACTOR, LogByteSizeMergePolicyProvider.this.mergeFactor); if (mergeFactor != LogByteSizeMergePolicyProvider.this.mergeFactor) { logger.info("updating merge_factor from [{}] to [{}]", LogByteSizeMergePolicyProvider.this.mergeFactor, mergeFactor); LogByteSizeMergePolicyProvider.this.mergeFactor = mergeFactor; @@ -150,7 +145,7 @@ public void onRefreshSettings(Settings settings) { } } - boolean compoundFormat = settings.getAsBoolean("index.compound_format", LogByteSizeMergePolicyProvider.this.compoundFormat); + boolean compoundFormat = settings.getAsBoolean(INDEX_COMPOUND_FORMAT, LogByteSizeMergePolicyProvider.this.compoundFormat); if (compoundFormat != LogByteSizeMergePolicyProvider.this.compoundFormat) { logger.info("updating index.compound_format from [{}] to [{}]", LogByteSizeMergePolicyProvider.this.compoundFormat, compoundFormat); LogByteSizeMergePolicyProvider.this.compoundFormat = compoundFormat; diff --git a/src/main/java/org/elasticsearch/index/merge/policy/LogDocMergePolicyProvider.java b/src/main/java/org/elasticsearch/index/merge/policy/LogDocMergePolicyProvider.java index 4467e20a1738a..f686224bc3d43 100644 --- a/src/main/java/org/elasticsearch/index/merge/policy/LogDocMergePolicyProvider.java +++ b/src/main/java/org/elasticsearch/index/merge/policy/LogDocMergePolicyProvider.java @@ -24,7 +24,6 @@ import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.SegmentInfos; import org.elasticsearch.ElasticSearchException; -import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.Preconditions; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; @@ -61,7 +60,7 @@ public LogDocMergePolicyProvider(Store store, IndexSettingsService indexSettings Preconditions.checkNotNull(store, "Store must be provided to merge policy"); this.indexSettingsService = indexSettingsService; - this.compoundFormat = indexSettings.getAsBoolean("index.compound_format", store.suggestUseCompoundFile()); + this.compoundFormat = indexSettings.getAsBoolean(INDEX_COMPOUND_FORMAT, store.suggestUseCompoundFile()); this.minMergeDocs = componentSettings.getAsInt("min_merge_docs", LogDocMergePolicy.DEFAULT_MIN_MERGE_DOCS); this.maxMergeDocs = componentSettings.getAsInt("max_merge_docs", LogDocMergePolicy.DEFAULT_MAX_MERGE_DOCS); this.mergeFactor = componentSettings.getAsInt("merge_factor", LogDocMergePolicy.DEFAULT_MERGE_FACTOR); @@ -95,19 +94,16 @@ public LogDocMergePolicy newMergePolicy() { return mergePolicy; } - static { - IndexMetaData.addDynamicSettings( - "index.merge.policy.min_merge_docs", - "index.merge.policy.max_merge_docs", - "index.merge.policy.merge_factor", - "index.compound_format" - ); - } + public static final String INDEX_MERGE_POLICY_MIN_MERGE_DOCS = "index.merge.policy.min_merge_docs"; + public static final String INDEX_MERGE_POLICY_MAX_MERGE_DOCS = "index.merge.policy.max_merge_docs"; + public static final String INDEX_MERGE_POLICY_MERGE_FACTOR = "index.merge.policy.merge_factor"; + public static final String INDEX_COMPOUND_FORMAT = "index.compound_format"; + class ApplySettings implements IndexSettingsService.Listener { @Override public void onRefreshSettings(Settings settings) { - int minMergeDocs = settings.getAsInt("index.merge.policy.min_merge_docs", LogDocMergePolicyProvider.this.minMergeDocs); + int minMergeDocs = settings.getAsInt(INDEX_MERGE_POLICY_MIN_MERGE_DOCS, LogDocMergePolicyProvider.this.minMergeDocs); if (minMergeDocs != LogDocMergePolicyProvider.this.minMergeDocs) { logger.info("updating min_merge_docs from [{}] to [{}]", LogDocMergePolicyProvider.this.minMergeDocs, minMergeDocs); LogDocMergePolicyProvider.this.minMergeDocs = minMergeDocs; @@ -116,7 +112,7 @@ public void onRefreshSettings(Settings settings) { } } - int maxMergeDocs = settings.getAsInt("index.merge.policy.max_merge_docs", LogDocMergePolicyProvider.this.maxMergeDocs); + int maxMergeDocs = settings.getAsInt(INDEX_MERGE_POLICY_MAX_MERGE_DOCS, LogDocMergePolicyProvider.this.maxMergeDocs); if (maxMergeDocs != LogDocMergePolicyProvider.this.maxMergeDocs) { logger.info("updating max_merge_docs from [{}] to [{}]", LogDocMergePolicyProvider.this.maxMergeDocs, maxMergeDocs); LogDocMergePolicyProvider.this.maxMergeDocs = maxMergeDocs; @@ -125,7 +121,7 @@ public void onRefreshSettings(Settings settings) { } } - int mergeFactor = settings.getAsInt("index.merge.policy.merge_factor", LogDocMergePolicyProvider.this.mergeFactor); + int mergeFactor = settings.getAsInt(INDEX_MERGE_POLICY_MERGE_FACTOR, LogDocMergePolicyProvider.this.mergeFactor); if (mergeFactor != LogDocMergePolicyProvider.this.mergeFactor) { logger.info("updating merge_factor from [{}] to [{}]", LogDocMergePolicyProvider.this.mergeFactor, mergeFactor); LogDocMergePolicyProvider.this.mergeFactor = mergeFactor; @@ -134,7 +130,7 @@ public void onRefreshSettings(Settings settings) { } } - boolean compoundFormat = settings.getAsBoolean("index.compound_format", LogDocMergePolicyProvider.this.compoundFormat); + boolean compoundFormat = settings.getAsBoolean(INDEX_COMPOUND_FORMAT, LogDocMergePolicyProvider.this.compoundFormat); if (compoundFormat != LogDocMergePolicyProvider.this.compoundFormat) { logger.info("updating index.compound_format from [{}] to [{}]", LogDocMergePolicyProvider.this.compoundFormat, compoundFormat); LogDocMergePolicyProvider.this.compoundFormat = compoundFormat; diff --git a/src/main/java/org/elasticsearch/index/merge/policy/TieredMergePolicyProvider.java b/src/main/java/org/elasticsearch/index/merge/policy/TieredMergePolicyProvider.java index 8906d2e3309a0..381afdefea4cf 100644 --- a/src/main/java/org/elasticsearch/index/merge/policy/TieredMergePolicyProvider.java +++ b/src/main/java/org/elasticsearch/index/merge/policy/TieredMergePolicyProvider.java @@ -21,7 +21,6 @@ import org.apache.lucene.index.*; import org.elasticsearch.ElasticSearchException; -import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeUnit; @@ -58,7 +57,7 @@ public TieredMergePolicyProvider(Store store, IndexSettingsService indexSettings super(store.shardId(), store.indexSettings()); this.indexSettingsService = indexSettingsService; - this.compoundFormat = indexSettings.getAsBoolean("index.compound_format", store.suggestUseCompoundFile()); + this.compoundFormat = indexSettings.getAsBoolean(INDEX_COMPOUND_FORMAT, store.suggestUseCompoundFile()); this.asyncMerge = indexSettings.getAsBoolean("index.merge.async", true); this.forceMergeDeletesPctAllowed = componentSettings.getAsDouble("expunge_deletes_allowed", 10d); // percentage this.floorSegment = componentSettings.getAsBytesSize("floor_segment", new ByteSizeValue(2, ByteSizeUnit.MB)); @@ -115,23 +114,19 @@ public void close(boolean delete) throws ElasticSearchException { indexSettingsService.removeListener(applySettings); } - static { - IndexMetaData.addDynamicSettings( - "index.merge.policy.expunge_deletes_allowed", - "index.merge.policy.floor_segment", - "index.merge.policy.max_merge_at_once", - "index.merge.policy.max_merge_at_once_explicit", - "index.merge.policy.max_merged_segment", - "index.merge.policy.segments_per_tier", - "index.merge.policy.reclaim_deletes_weight", - "index.compound_format" - ); - } + public static final String INDEX_MERGE_POLICY_EXPUNGE_DELETES_ALLOWED = "index.merge.policy.expunge_deletes_allowed"; + public static final String INDEX_MERGE_POLICY_FLOOR_SEGMENT = "index.merge.policy.floor_segment"; + public static final String INDEX_MERGE_POLICY_MAX_MERGE_AT_ONCE = "index.merge.policy.max_merge_at_once"; + public static final String INDEX_MERGE_POLICY_MAX_MERGE_AT_ONCE_EXPLICIT = "index.merge.policy.max_merge_at_once_explicit"; + public static final String INDEX_MERGE_POLICY_MAX_MERGED_SEGMENT = "index.merge.policy.max_merged_segment"; + public static final String INDEX_MERGE_POLICY_SEGMENTS_PER_TIER = "index.merge.policy.segments_per_tier"; + public static final String INDEX_MERGE_POLICY_RECLAIM_DELETES_WEIGHT = "index.merge.policy.reclaim_deletes_weight"; + public static final String INDEX_COMPOUND_FORMAT = "index.compound_format"; class ApplySettings implements IndexSettingsService.Listener { @Override public void onRefreshSettings(Settings settings) { - double expungeDeletesPctAllowed = settings.getAsDouble("index.merge.policy.expunge_deletes_allowed", TieredMergePolicyProvider.this.forceMergeDeletesPctAllowed); + double expungeDeletesPctAllowed = settings.getAsDouble(INDEX_MERGE_POLICY_EXPUNGE_DELETES_ALLOWED, TieredMergePolicyProvider.this.forceMergeDeletesPctAllowed); if (expungeDeletesPctAllowed != TieredMergePolicyProvider.this.forceMergeDeletesPctAllowed) { logger.info("updating [expunge_deletes_allowed] from [{}] to [{}]", TieredMergePolicyProvider.this.forceMergeDeletesPctAllowed, expungeDeletesPctAllowed); TieredMergePolicyProvider.this.forceMergeDeletesPctAllowed = expungeDeletesPctAllowed; @@ -140,7 +135,7 @@ public void onRefreshSettings(Settings settings) { } } - ByteSizeValue floorSegment = settings.getAsBytesSize("index.merge.policy.floor_segment", TieredMergePolicyProvider.this.floorSegment); + ByteSizeValue floorSegment = settings.getAsBytesSize(INDEX_MERGE_POLICY_FLOOR_SEGMENT, TieredMergePolicyProvider.this.floorSegment); if (!floorSegment.equals(TieredMergePolicyProvider.this.floorSegment)) { logger.info("updating [floor_segment] from [{}] to [{}]", TieredMergePolicyProvider.this.floorSegment, floorSegment); TieredMergePolicyProvider.this.floorSegment = floorSegment; @@ -149,7 +144,7 @@ public void onRefreshSettings(Settings settings) { } } - int maxMergeAtOnce = settings.getAsInt("index.merge.policy.max_merge_at_once", TieredMergePolicyProvider.this.maxMergeAtOnce); + int maxMergeAtOnce = settings.getAsInt(INDEX_MERGE_POLICY_MAX_MERGE_AT_ONCE, TieredMergePolicyProvider.this.maxMergeAtOnce); if (maxMergeAtOnce != TieredMergePolicyProvider.this.maxMergeAtOnce) { logger.info("updating [max_merge_at_once] from [{}] to [{}]", TieredMergePolicyProvider.this.maxMergeAtOnce, maxMergeAtOnce); TieredMergePolicyProvider.this.maxMergeAtOnce = maxMergeAtOnce; @@ -158,7 +153,7 @@ public void onRefreshSettings(Settings settings) { } } - int maxMergeAtOnceExplicit = settings.getAsInt("index.merge.policy.max_merge_at_once_explicit", TieredMergePolicyProvider.this.maxMergeAtOnceExplicit); + int maxMergeAtOnceExplicit = settings.getAsInt(INDEX_MERGE_POLICY_MAX_MERGE_AT_ONCE_EXPLICIT, TieredMergePolicyProvider.this.maxMergeAtOnceExplicit); if (maxMergeAtOnceExplicit != TieredMergePolicyProvider.this.maxMergeAtOnceExplicit) { logger.info("updating [max_merge_at_once_explicit] from [{}] to [{}]", TieredMergePolicyProvider.this.maxMergeAtOnceExplicit, maxMergeAtOnceExplicit); TieredMergePolicyProvider.this.maxMergeAtOnceExplicit = maxMergeAtOnceExplicit; @@ -167,7 +162,7 @@ public void onRefreshSettings(Settings settings) { } } - ByteSizeValue maxMergedSegment = settings.getAsBytesSize("index.merge.policy.max_merged_segment", TieredMergePolicyProvider.this.maxMergedSegment); + ByteSizeValue maxMergedSegment = settings.getAsBytesSize(INDEX_MERGE_POLICY_MAX_MERGED_SEGMENT, TieredMergePolicyProvider.this.maxMergedSegment); if (!maxMergedSegment.equals(TieredMergePolicyProvider.this.maxMergedSegment)) { logger.info("updating [max_merged_segment] from [{}] to [{}]", TieredMergePolicyProvider.this.maxMergedSegment, maxMergedSegment); TieredMergePolicyProvider.this.maxMergedSegment = maxMergedSegment; @@ -176,7 +171,7 @@ public void onRefreshSettings(Settings settings) { } } - double segmentsPerTier = settings.getAsDouble("index.merge.policy.segments_per_tier", TieredMergePolicyProvider.this.segmentsPerTier); + double segmentsPerTier = settings.getAsDouble(INDEX_MERGE_POLICY_SEGMENTS_PER_TIER, TieredMergePolicyProvider.this.segmentsPerTier); if (segmentsPerTier != TieredMergePolicyProvider.this.segmentsPerTier) { logger.info("updating [segments_per_tier] from [{}] to [{}]", TieredMergePolicyProvider.this.segmentsPerTier, segmentsPerTier); TieredMergePolicyProvider.this.segmentsPerTier = segmentsPerTier; @@ -185,7 +180,7 @@ public void onRefreshSettings(Settings settings) { } } - double reclaimDeletesWeight = settings.getAsDouble("index.merge.policy.reclaim_deletes_weight", TieredMergePolicyProvider.this.reclaimDeletesWeight); + double reclaimDeletesWeight = settings.getAsDouble(INDEX_MERGE_POLICY_RECLAIM_DELETES_WEIGHT, TieredMergePolicyProvider.this.reclaimDeletesWeight); if (reclaimDeletesWeight != TieredMergePolicyProvider.this.reclaimDeletesWeight) { logger.info("updating [reclaim_deletes_weight] from [{}] to [{}]", TieredMergePolicyProvider.this.reclaimDeletesWeight, reclaimDeletesWeight); TieredMergePolicyProvider.this.reclaimDeletesWeight = reclaimDeletesWeight; @@ -194,7 +189,7 @@ public void onRefreshSettings(Settings settings) { } } - boolean compoundFormat = settings.getAsBoolean("index.compound_format", TieredMergePolicyProvider.this.compoundFormat); + boolean compoundFormat = settings.getAsBoolean(INDEX_COMPOUND_FORMAT, TieredMergePolicyProvider.this.compoundFormat); if (compoundFormat != TieredMergePolicyProvider.this.compoundFormat) { logger.info("updating index.compound_format from [{}] to [{}]", TieredMergePolicyProvider.this.compoundFormat, compoundFormat); TieredMergePolicyProvider.this.compoundFormat = compoundFormat; diff --git a/src/main/java/org/elasticsearch/index/search/slowlog/ShardSlowLogSearchService.java b/src/main/java/org/elasticsearch/index/search/slowlog/ShardSlowLogSearchService.java index 67518b855e9ae..8e21ef68a8e07 100644 --- a/src/main/java/org/elasticsearch/index/search/slowlog/ShardSlowLogSearchService.java +++ b/src/main/java/org/elasticsearch/index/search/slowlog/ShardSlowLogSearchService.java @@ -19,7 +19,6 @@ package org.elasticsearch.index.search.slowlog; -import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.logging.ESLogger; @@ -57,66 +56,62 @@ public class ShardSlowLogSearchService extends AbstractIndexShardComponent { private final ESLogger queryLogger; private final ESLogger fetchLogger; - static { - IndexMetaData.addDynamicSettings( - "index.search.slowlog.threshold.query.warn", - "index.search.slowlog.threshold.query.info", - "index.search.slowlog.threshold.query.debug", - "index.search.slowlog.threshold.query.trace", - "index.search.slowlog.threshold.fetch.warn", - "index.search.slowlog.threshold.fetch.info", - "index.search.slowlog.threshold.fetch.debug", - "index.search.slowlog.threshold.fetch.trace", - "index.search.slowlog.reformat", - "index.search.slowlog.level" - ); - } + public static final String INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_WARN = "index.search.slowlog.threshold.query.warn"; + public static final String INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_INFO = "index.search.slowlog.threshold.query.info"; + public static final String INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_DEBUG = "index.search.slowlog.threshold.query.debug"; + public static final String INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_TRACE = "index.search.slowlog.threshold.query.trace"; + public static final String INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_WARN = "index.search.slowlog.threshold.fetch.warn"; + public static final String INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_INFO = "index.search.slowlog.threshold.fetch.info"; + public static final String INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_DEBUG = "index.search.slowlog.threshold.fetch.debug"; + public static final String INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_TRACE = "index.search.slowlog.threshold.fetch.trace"; + public static final String INDEX_SEARCH_SLOWLOG_REFORMAT = "index.search.slowlog.reformat"; + public static final String INDEX_SEARCH_SLOWLOG_LEVEL = "index.search.slowlog.level"; class ApplySettings implements IndexSettingsService.Listener { @Override public synchronized void onRefreshSettings(Settings settings) { - long queryWarnThreshold = settings.getAsTime("index.search.slowlog.threshold.query.warn", TimeValue.timeValueNanos(ShardSlowLogSearchService.this.queryWarnThreshold)).nanos(); + long queryWarnThreshold = settings.getAsTime(INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_WARN, TimeValue.timeValueNanos(ShardSlowLogSearchService.this.queryWarnThreshold)).nanos(); if (queryWarnThreshold != ShardSlowLogSearchService.this.queryWarnThreshold) { ShardSlowLogSearchService.this.queryWarnThreshold = queryWarnThreshold; } - long queryInfoThreshold = settings.getAsTime("index.search.slowlog.threshold.query.info", TimeValue.timeValueNanos(ShardSlowLogSearchService.this.queryInfoThreshold)).nanos(); + long queryInfoThreshold = settings.getAsTime(INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_INFO, TimeValue.timeValueNanos(ShardSlowLogSearchService.this.queryInfoThreshold)).nanos(); if (queryInfoThreshold != ShardSlowLogSearchService.this.queryInfoThreshold) { ShardSlowLogSearchService.this.queryInfoThreshold = queryInfoThreshold; } - long queryDebugThreshold = settings.getAsTime("index.search.slowlog.threshold.query.debug", TimeValue.timeValueNanos(ShardSlowLogSearchService.this.queryDebugThreshold)).nanos(); + long queryDebugThreshold = settings.getAsTime(INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_DEBUG, TimeValue.timeValueNanos(ShardSlowLogSearchService.this.queryDebugThreshold)).nanos(); if (queryDebugThreshold != ShardSlowLogSearchService.this.queryDebugThreshold) { ShardSlowLogSearchService.this.queryDebugThreshold = queryDebugThreshold; } - long queryTraceThreshold = settings.getAsTime("index.search.slowlog.threshold.query.trace", TimeValue.timeValueNanos(ShardSlowLogSearchService.this.queryTraceThreshold)).nanos(); + long queryTraceThreshold = settings.getAsTime(INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_TRACE, TimeValue.timeValueNanos(ShardSlowLogSearchService.this.queryTraceThreshold)).nanos(); if (queryTraceThreshold != ShardSlowLogSearchService.this.queryTraceThreshold) { ShardSlowLogSearchService.this.queryTraceThreshold = queryTraceThreshold; } - long fetchWarnThreshold = settings.getAsTime("index.search.slowlog.threshold.fetch.warn", TimeValue.timeValueNanos(ShardSlowLogSearchService.this.fetchWarnThreshold)).nanos(); + long fetchWarnThreshold = settings.getAsTime(INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_WARN, TimeValue.timeValueNanos(ShardSlowLogSearchService.this.fetchWarnThreshold)).nanos(); if (fetchWarnThreshold != ShardSlowLogSearchService.this.fetchWarnThreshold) { ShardSlowLogSearchService.this.fetchWarnThreshold = fetchWarnThreshold; } - long fetchInfoThreshold = settings.getAsTime("index.search.slowlog.threshold.fetch.info", TimeValue.timeValueNanos(ShardSlowLogSearchService.this.fetchInfoThreshold)).nanos(); + long fetchInfoThreshold = settings.getAsTime(INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_INFO, TimeValue.timeValueNanos(ShardSlowLogSearchService.this.fetchInfoThreshold)).nanos(); if (fetchInfoThreshold != ShardSlowLogSearchService.this.fetchInfoThreshold) { ShardSlowLogSearchService.this.fetchInfoThreshold = fetchInfoThreshold; } - long fetchDebugThreshold = settings.getAsTime("index.search.slowlog.threshold.fetch.debug", TimeValue.timeValueNanos(ShardSlowLogSearchService.this.fetchDebugThreshold)).nanos(); + long fetchDebugThreshold = settings.getAsTime(INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_DEBUG, TimeValue.timeValueNanos(ShardSlowLogSearchService.this.fetchDebugThreshold)).nanos(); if (fetchDebugThreshold != ShardSlowLogSearchService.this.fetchDebugThreshold) { ShardSlowLogSearchService.this.fetchDebugThreshold = fetchDebugThreshold; } - long fetchTraceThreshold = settings.getAsTime("index.search.slowlog.threshold.fetch.trace", TimeValue.timeValueNanos(ShardSlowLogSearchService.this.fetchTraceThreshold)).nanos(); + long fetchTraceThreshold = settings.getAsTime(INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_TRACE, TimeValue.timeValueNanos(ShardSlowLogSearchService.this.fetchTraceThreshold)).nanos(); if (fetchTraceThreshold != ShardSlowLogSearchService.this.fetchTraceThreshold) { ShardSlowLogSearchService.this.fetchTraceThreshold = fetchTraceThreshold; } - String level = settings.get("index.search.slowlog.level", ShardSlowLogSearchService.this.level); + String level = settings.get(INDEX_SEARCH_SLOWLOG_LEVEL, ShardSlowLogSearchService.this.level); if (!level.equals(ShardSlowLogSearchService.this.level)) { ShardSlowLogSearchService.this.queryLogger.setLevel(level.toUpperCase()); ShardSlowLogSearchService.this.fetchLogger.setLevel(level.toUpperCase()); ShardSlowLogSearchService.this.level = level; } - boolean reformat = settings.getAsBoolean("index.search.slowlog.reformat", ShardSlowLogSearchService.this.reformat); + boolean reformat = settings.getAsBoolean(INDEX_SEARCH_SLOWLOG_REFORMAT, ShardSlowLogSearchService.this.reformat); if (reformat != ShardSlowLogSearchService.this.reformat) { ShardSlowLogSearchService.this.reformat = reformat; } diff --git a/src/main/java/org/elasticsearch/index/settings/IndexDynamicSettings.java b/src/main/java/org/elasticsearch/index/settings/IndexDynamicSettings.java new file mode 100644 index 0000000000000..8e8c809ea4ec5 --- /dev/null +++ b/src/main/java/org/elasticsearch/index/settings/IndexDynamicSettings.java @@ -0,0 +1,39 @@ +/* + * Licensed to ElasticSearch and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. ElasticSearch licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.settings; + +import org.elasticsearch.common.inject.BindingAnnotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + + +@BindingAnnotation +@Target({FIELD, PARAMETER}) +@Retention(RUNTIME) +@Documented +public @interface IndexDynamicSettings { + +} diff --git a/src/main/java/org/elasticsearch/index/settings/IndexDynamicSettingsModule.java b/src/main/java/org/elasticsearch/index/settings/IndexDynamicSettingsModule.java new file mode 100644 index 0000000000000..2afc64cd53ab9 --- /dev/null +++ b/src/main/java/org/elasticsearch/index/settings/IndexDynamicSettingsModule.java @@ -0,0 +1,126 @@ +/* + * Licensed to ElasticSearch and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. ElasticSearch licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.settings; + +import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider; +import org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider; +import org.elasticsearch.cluster.settings.DynamicSettings; +import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.gateway.local.LocalGatewayAllocator; +import org.elasticsearch.index.cache.field.data.resident.ResidentFieldDataCache; +import org.elasticsearch.index.engine.robin.RobinEngine; +import org.elasticsearch.index.gateway.IndexShardGatewayService; +import org.elasticsearch.index.indexing.slowlog.ShardSlowLogIndexingService; +import org.elasticsearch.index.merge.policy.LogByteSizeMergePolicyProvider; +import org.elasticsearch.index.merge.policy.LogDocMergePolicyProvider; +import org.elasticsearch.index.merge.policy.TieredMergePolicyProvider; +import org.elasticsearch.index.search.slowlog.ShardSlowLogSearchService; +import org.elasticsearch.index.shard.service.InternalIndexShard; +import org.elasticsearch.index.store.Store; +import org.elasticsearch.index.store.support.AbstractIndexStore; +import org.elasticsearch.index.translog.TranslogService; +import org.elasticsearch.index.translog.fs.FsTranslog; +import org.elasticsearch.indices.ttl.IndicesTTLService; + +/** + */ +public class IndexDynamicSettingsModule extends AbstractModule { + + private final DynamicSettings indexDynamicSettings; + + public IndexDynamicSettingsModule() { + indexDynamicSettings = new DynamicSettings(); + indexDynamicSettings.addDynamicSettings( + AbstractIndexStore.INDEX_STORE_THROTTLE_MAX_BYTES_PER_SEC, + AbstractIndexStore.INDEX_STORE_THROTTLE_TYPE, + FilterAllocationDecider.INDEX_ROUTING_REQUIRE_GROUP + "*", + FilterAllocationDecider.INDEX_ROUTING_INCLUDE_GROUP + "*", + FilterAllocationDecider.INDEX_ROUTING_EXCLUDE_GROUP + "*", + FsTranslog.INDEX_TRANSLOG_FS_TYPE, + FsTranslog.INDEX_TRANSLOG_FS_BUFFER_SIZE, + FsTranslog.INDEX_TRANSLOG_FS_TRANSIENT_BUFFER_SIZE, + IndexMetaData.SETTING_NUMBER_OF_REPLICAS, + IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS, + IndexMetaData.SETTING_READ_ONLY, + IndexMetaData.SETTING_BLOCKS_READ, + IndexMetaData.SETTING_BLOCKS_WRITE, + IndexMetaData.SETTING_BLOCKS_METADATA, + IndexShardGatewayService.INDEX_GATEWAY_SNAPSHOT_INTERVAL, + IndicesTTLService.INDEX_TTL_DISABLE_PURGE, + InternalIndexShard.INDEX_REFRESH_INTERVAL, + LocalGatewayAllocator.INDEX_RECOVERY_INITIAL_SHARDS, + LogByteSizeMergePolicyProvider.INDEX_MERGE_POLICY_MIN_MERGE_SIZE, + LogByteSizeMergePolicyProvider.INDEX_MERGE_POLICY_MAX_MERGE_SIZE, + LogByteSizeMergePolicyProvider.INDEX_MERGE_POLICY_MAX_MERGE_DOCS, + LogByteSizeMergePolicyProvider.INDEX_MERGE_POLICY_MERGE_FACTOR, + LogByteSizeMergePolicyProvider.INDEX_COMPOUND_FORMAT, + LogDocMergePolicyProvider.INDEX_MERGE_POLICY_MIN_MERGE_DOCS, + LogDocMergePolicyProvider.INDEX_MERGE_POLICY_MAX_MERGE_DOCS, + LogDocMergePolicyProvider.INDEX_MERGE_POLICY_MERGE_FACTOR, + LogDocMergePolicyProvider.INDEX_COMPOUND_FORMAT, + ResidentFieldDataCache.INDEX_CACHE_FIELD_MAX_SIZE, + ResidentFieldDataCache.INDEX_CACHE_FIELD_EXPIRE, + RobinEngine.INDEX_TERM_INDEX_INTERVAL, + RobinEngine.INDEX_TERM_INDEX_DIVISOR, + RobinEngine.INDEX_INDEX_CONCURRENCY, + RobinEngine.INDEX_GC_DELETES, + ShardSlowLogIndexingService.INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_WARN, + ShardSlowLogIndexingService.INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_INFO, + ShardSlowLogIndexingService.INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_DEBUG, + ShardSlowLogIndexingService.INDEX_INDEXING_SLOWLOG_THRESHOLD_INDEX_TRACE, + ShardSlowLogIndexingService.INDEX_INDEXING_SLOWLOG_REFORMAT, + ShardSlowLogIndexingService.INDEX_INDEXING_SLOWLOG_LEVEL, + ShardSlowLogSearchService.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_WARN, + ShardSlowLogSearchService.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_INFO, + ShardSlowLogSearchService.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_DEBUG, + ShardSlowLogSearchService.INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_TRACE, + ShardSlowLogSearchService.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_WARN, + ShardSlowLogSearchService.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_INFO, + ShardSlowLogSearchService.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_DEBUG, + ShardSlowLogSearchService.INDEX_SEARCH_SLOWLOG_THRESHOLD_FETCH_TRACE, + ShardSlowLogSearchService.INDEX_SEARCH_SLOWLOG_REFORMAT, + ShardSlowLogSearchService.INDEX_SEARCH_SLOWLOG_LEVEL, + ShardsLimitAllocationDecider.INDEX_TOTAL_SHARDS_PER_NODE, + Store.INDEX_STORE_COMPRESS_STORED, + Store.INDEX_STORE_COMPRESS_TV, + TieredMergePolicyProvider.INDEX_MERGE_POLICY_EXPUNGE_DELETES_ALLOWED, + TieredMergePolicyProvider.INDEX_MERGE_POLICY_FLOOR_SEGMENT, + TieredMergePolicyProvider.INDEX_MERGE_POLICY_MAX_MERGE_AT_ONCE, + TieredMergePolicyProvider.INDEX_MERGE_POLICY_MAX_MERGE_AT_ONCE_EXPLICIT, + TieredMergePolicyProvider.INDEX_MERGE_POLICY_MAX_MERGED_SEGMENT, + TieredMergePolicyProvider.INDEX_MERGE_POLICY_SEGMENTS_PER_TIER, + TieredMergePolicyProvider.INDEX_MERGE_POLICY_RECLAIM_DELETES_WEIGHT, + TieredMergePolicyProvider.INDEX_COMPOUND_FORMAT, + TranslogService.INDEX_TRANSLOG_FLUSH_THRESHOLD_OPS, + TranslogService.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE, + TranslogService.INDEX_TRANSLOG_FLUSH_THRESHOLD_PERIOD, + TranslogService.INDEX_TRANSLOG_DISABLE_FLUSH); + } + + public void addDynamicSetting(String... settings) { + indexDynamicSettings.addDynamicSettings(settings); + } + + @Override + protected void configure() { + bind(DynamicSettings.class).annotatedWith(IndexDynamicSettings.class).toInstance(indexDynamicSettings); + } +} diff --git a/src/main/java/org/elasticsearch/index/settings/IndexSettingsService.java b/src/main/java/org/elasticsearch/index/settings/IndexSettingsService.java index 2dc3d1e2eaf0f..e8241b6d6ee7c 100644 --- a/src/main/java/org/elasticsearch/index/settings/IndexSettingsService.java +++ b/src/main/java/org/elasticsearch/index/settings/IndexSettingsService.java @@ -62,6 +62,9 @@ public Settings getSettings() { return this.settings; } + /** + * Only settings registered in {@link IndexDynamicSettingsModule} can be changed dynamically. + */ public void addListener(Listener listener) { this.listeners.add(listener); } diff --git a/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java b/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java index 6c92f4c9ac843..1938b9a82001d 100644 --- a/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java +++ b/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java @@ -29,7 +29,6 @@ import org.elasticsearch.ElasticSearchException; import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.ElasticSearchIllegalStateException; -import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.common.Booleans; import org.elasticsearch.common.Nullable; @@ -157,7 +156,7 @@ public InternalIndexShard(ShardId shardId, @IndexSettings Settings indexSettings this.shardWarmerService = shardWarmerService; state = IndexShardState.CREATED; - this.refreshInterval = indexSettings.getAsTime("engine.robin.refresh_interval", indexSettings.getAsTime("index.refresh_interval", engine.defaultRefreshInterval())); + this.refreshInterval = indexSettings.getAsTime("engine.robin.refresh_interval", indexSettings.getAsTime(INDEX_REFRESH_INTERVAL, engine.defaultRefreshInterval())); this.mergeInterval = indexSettings.getAsTime("index.merge.async_interval", TimeValue.timeValueSeconds(1)); indexSettingsService.addListener(applyRefreshSettings); @@ -686,9 +685,7 @@ private Query filterQueryIfNeeded(Query query, String[] types) { return query; } - static { - IndexMetaData.addDynamicSettings("index.refresh_interval"); - } + public static final String INDEX_REFRESH_INTERVAL = "index.refresh_interval"; private class ApplyRefreshSettings implements IndexSettingsService.Listener { @Override @@ -697,7 +694,7 @@ public void onRefreshSettings(Settings settings) { if (state == IndexShardState.CLOSED) { return; } - TimeValue refreshInterval = settings.getAsTime("engine.robin.refresh_interval", settings.getAsTime("index.refresh_interval", InternalIndexShard.this.refreshInterval)); + TimeValue refreshInterval = settings.getAsTime("engine.robin.refresh_interval", settings.getAsTime(INDEX_REFRESH_INTERVAL, InternalIndexShard.this.refreshInterval)); if (!refreshInterval.equals(InternalIndexShard.this.refreshInterval)) { logger.info("updating refresh_interval from [{}] to [{}]", InternalIndexShard.this.refreshInterval, refreshInterval); if (refreshScheduledFuture != null) { diff --git a/src/main/java/org/elasticsearch/index/store/Store.java b/src/main/java/org/elasticsearch/index/store/Store.java index 14e32a860fa45..8fc3befbfd52f 100644 --- a/src/main/java/org/elasticsearch/index/store/Store.java +++ b/src/main/java/org/elasticsearch/index/store/Store.java @@ -24,7 +24,6 @@ import com.google.common.collect.Maps; import jsr166y.ThreadLocalRandom; import org.apache.lucene.store.*; -import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.Strings; import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.compress.CompressedIndexOutput; @@ -55,22 +54,18 @@ */ public class Store extends AbstractIndexShardComponent { - static { - IndexMetaData.addDynamicSettings( - "index.store.compress.stored", - "index.store.compress.tv" - ); - } + public static final String INDEX_STORE_COMPRESS_STORED = "index.store.compress.stored"; + public static final String INDEX_STORE_COMPRESS_TV = "index.store.compress.tv"; class ApplySettings implements IndexSettingsService.Listener { @Override public void onRefreshSettings(Settings settings) { - boolean compressStored = settings.getAsBoolean("index.store.compress.stored", Store.this.compressStored); + boolean compressStored = settings.getAsBoolean(INDEX_STORE_COMPRESS_STORED, Store.this.compressStored); if (compressStored != Store.this.compressStored) { logger.info("updating [index.store.compress.stored] from [{}] to [{}]", Store.this.compressStored, compressStored); Store.this.compressStored = compressStored; } - boolean compressTv = settings.getAsBoolean("index.store.compress.tv", Store.this.compressTv); + boolean compressTv = settings.getAsBoolean(INDEX_STORE_COMPRESS_TV, Store.this.compressTv); if (compressTv != Store.this.compressTv) { logger.info("updating [index.store.compress.tv] from [{}] to [{}]", Store.this.compressTv, compressTv); Store.this.compressTv = compressTv; diff --git a/src/main/java/org/elasticsearch/index/store/support/AbstractIndexStore.java b/src/main/java/org/elasticsearch/index/store/support/AbstractIndexStore.java index 6c98be8ec9357..929cb91a631c0 100644 --- a/src/main/java/org/elasticsearch/index/store/support/AbstractIndexStore.java +++ b/src/main/java/org/elasticsearch/index/store/support/AbstractIndexStore.java @@ -21,7 +21,6 @@ import org.apache.lucene.store.StoreRateLimiting; import org.elasticsearch.ElasticSearchException; -import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.index.AbstractIndexComponent; @@ -40,17 +39,13 @@ */ public abstract class AbstractIndexStore extends AbstractIndexComponent implements IndexStore { - static { - IndexMetaData.addDynamicSettings( - "index.store.throttle.type", - "index.store.throttle.max_bytes_per_sec" - ); - } + public static final String INDEX_STORE_THROTTLE_TYPE = "index.store.throttle.type"; + public static final String INDEX_STORE_THROTTLE_MAX_BYTES_PER_SEC = "index.store.throttle.max_bytes_per_sec"; class ApplySettings implements IndexSettingsService.Listener { @Override public void onRefreshSettings(Settings settings) { - String rateLimitingType = indexSettings.get("index.store.throttle.type", AbstractIndexStore.this.rateLimitingType); + String rateLimitingType = indexSettings.get(INDEX_STORE_THROTTLE_TYPE, AbstractIndexStore.this.rateLimitingType); if (!rateLimitingType.equals(AbstractIndexStore.this.rateLimitingType)) { logger.info("updating index.store.throttle.type from [{}] to [{}]", AbstractIndexStore.this.rateLimitingType, rateLimitingType); if (rateLimitingType.equalsIgnoreCase("node")) { @@ -64,7 +59,7 @@ public void onRefreshSettings(Settings settings) { } } - ByteSizeValue rateLimitingThrottle = settings.getAsBytesSize("index.store.throttle.max_bytes_per_sec", AbstractIndexStore.this.rateLimitingThrottle); + ByteSizeValue rateLimitingThrottle = settings.getAsBytesSize(INDEX_STORE_THROTTLE_MAX_BYTES_PER_SEC, AbstractIndexStore.this.rateLimitingThrottle); if (!rateLimitingThrottle.equals(AbstractIndexStore.this.rateLimitingThrottle)) { logger.info("updating index.store.throttle.max_bytes_per_sec from [{}] to [{}], note, type is [{}]", AbstractIndexStore.this.rateLimitingThrottle, rateLimitingThrottle, AbstractIndexStore.this.rateLimitingType); AbstractIndexStore.this.rateLimitingThrottle = rateLimitingThrottle; @@ -91,14 +86,14 @@ protected AbstractIndexStore(Index index, @IndexSettings Settings indexSettings, this.indexService = indexService; this.indicesStore = indicesStore; - this.rateLimitingType = indexSettings.get("index.store.throttle.type", "node"); + this.rateLimitingType = indexSettings.get(INDEX_STORE_THROTTLE_TYPE, "node"); if (rateLimitingType.equalsIgnoreCase("node")) { nodeRateLimiting = true; } else { nodeRateLimiting = false; rateLimiting.setType(rateLimitingType); } - this.rateLimitingThrottle = indexSettings.getAsBytesSize("index.store.throttle.max_bytes_per_sec", new ByteSizeValue(0)); + this.rateLimitingThrottle = indexSettings.getAsBytesSize(INDEX_STORE_THROTTLE_MAX_BYTES_PER_SEC, new ByteSizeValue(0)); rateLimiting.setMaxRate(rateLimitingThrottle); logger.debug("using index.store.throttle.type [{}], with index.store.throttle.max_bytes_per_sec [{}]", rateLimitingType, rateLimitingThrottle); diff --git a/src/main/java/org/elasticsearch/index/translog/TranslogService.java b/src/main/java/org/elasticsearch/index/translog/TranslogService.java index 9337d15b01e22..c18c17c94c89d 100644 --- a/src/main/java/org/elasticsearch/index/translog/TranslogService.java +++ b/src/main/java/org/elasticsearch/index/translog/TranslogService.java @@ -19,7 +19,6 @@ package org.elasticsearch.index.translog; -import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeUnit; @@ -94,34 +93,30 @@ public void close() { this.future.cancel(true); } - static { - IndexMetaData.addDynamicSettings( - "index.translog.flush_threshold_ops", - "index.translog.flush_threshold_size", - "index.translog.flush_threshold_period", - "index.translog.disable_flush" - ); - } + public static final String INDEX_TRANSLOG_FLUSH_THRESHOLD_OPS = "index.translog.flush_threshold_ops"; + public static final String INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE = "index.translog.flush_threshold_size"; + public static final String INDEX_TRANSLOG_FLUSH_THRESHOLD_PERIOD = "index.translog.flush_threshold_period"; + public static final String INDEX_TRANSLOG_DISABLE_FLUSH = "index.translog.disable_flush"; class ApplySettings implements IndexSettingsService.Listener { @Override public void onRefreshSettings(Settings settings) { - int flushThresholdOperations = settings.getAsInt("index.translog.flush_threshold_ops", TranslogService.this.flushThresholdOperations); + int flushThresholdOperations = settings.getAsInt(INDEX_TRANSLOG_FLUSH_THRESHOLD_OPS, TranslogService.this.flushThresholdOperations); if (flushThresholdOperations != TranslogService.this.flushThresholdOperations) { logger.info("updating flush_threshold_ops from [{}] to [{}]", TranslogService.this.flushThresholdOperations, flushThresholdOperations); TranslogService.this.flushThresholdOperations = flushThresholdOperations; } - ByteSizeValue flushThresholdSize = settings.getAsBytesSize("index.translog.flush_threshold_size", TranslogService.this.flushThresholdSize); + ByteSizeValue flushThresholdSize = settings.getAsBytesSize(INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE, TranslogService.this.flushThresholdSize); if (!flushThresholdSize.equals(TranslogService.this.flushThresholdSize)) { logger.info("updating flush_threshold_size from [{}] to [{}]", TranslogService.this.flushThresholdSize, flushThresholdSize); TranslogService.this.flushThresholdSize = flushThresholdSize; } - TimeValue flushThresholdPeriod = settings.getAsTime("index.translog.flush_threshold_period", TranslogService.this.flushThresholdPeriod); + TimeValue flushThresholdPeriod = settings.getAsTime(INDEX_TRANSLOG_FLUSH_THRESHOLD_PERIOD, TranslogService.this.flushThresholdPeriod); if (!flushThresholdPeriod.equals(TranslogService.this.flushThresholdPeriod)) { logger.info("updating flush_threshold_period from [{}] to [{}]", TranslogService.this.flushThresholdPeriod, flushThresholdPeriod); TranslogService.this.flushThresholdPeriod = flushThresholdPeriod; } - boolean disableFlush = settings.getAsBoolean("index.translog.disable_flush", TranslogService.this.disableFlush); + boolean disableFlush = settings.getAsBoolean(INDEX_TRANSLOG_DISABLE_FLUSH, TranslogService.this.disableFlush); if (disableFlush != TranslogService.this.disableFlush) { logger.info("updating disable_flush from [{}] to [{}]", TranslogService.this.disableFlush, disableFlush); TranslogService.this.disableFlush = disableFlush; diff --git a/src/main/java/org/elasticsearch/index/translog/fs/FsTranslog.java b/src/main/java/org/elasticsearch/index/translog/fs/FsTranslog.java index 696fc074d3050..e82b2bffe4596 100644 --- a/src/main/java/org/elasticsearch/index/translog/fs/FsTranslog.java +++ b/src/main/java/org/elasticsearch/index/translog/fs/FsTranslog.java @@ -20,7 +20,6 @@ package org.elasticsearch.index.translog.fs; import jsr166y.ThreadLocalRandom; -import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.FileSystemUtils; import org.elasticsearch.common.io.stream.BytesStreamOutput; @@ -47,30 +46,26 @@ */ public class FsTranslog extends AbstractIndexShardComponent implements Translog { - static { - IndexMetaData.addDynamicSettings( - "index.translog.fs.type", - "index.translog.fs.buffer_size", - "index.translog.fs.transient_buffer_size" - ); - } + public static final String INDEX_TRANSLOG_FS_TYPE = "index.translog.fs.type"; + public static final String INDEX_TRANSLOG_FS_BUFFER_SIZE = "index.translog.fs.buffer_size"; + public static final String INDEX_TRANSLOG_FS_TRANSIENT_BUFFER_SIZE = "index.translog.fs.transient_buffer_size"; class ApplySettings implements IndexSettingsService.Listener { @Override public void onRefreshSettings(Settings settings) { - int bufferSize = (int) settings.getAsBytesSize("index.translog.fs.buffer_size", new ByteSizeValue(FsTranslog.this.bufferSize)).bytes(); + int bufferSize = (int) settings.getAsBytesSize(INDEX_TRANSLOG_FS_BUFFER_SIZE, new ByteSizeValue(FsTranslog.this.bufferSize)).bytes(); if (bufferSize != FsTranslog.this.bufferSize) { logger.info("updating buffer_size from [{}] to [{}]", new ByteSizeValue(FsTranslog.this.bufferSize), new ByteSizeValue(bufferSize)); FsTranslog.this.bufferSize = bufferSize; } - int transientBufferSize = (int) settings.getAsBytesSize("index.translog.fs.transient_buffer_size", new ByteSizeValue(FsTranslog.this.transientBufferSize)).bytes(); + int transientBufferSize = (int) settings.getAsBytesSize(INDEX_TRANSLOG_FS_TRANSIENT_BUFFER_SIZE, new ByteSizeValue(FsTranslog.this.transientBufferSize)).bytes(); if (transientBufferSize != FsTranslog.this.transientBufferSize) { logger.info("updating transient_buffer_size from [{}] to [{}]", new ByteSizeValue(FsTranslog.this.transientBufferSize), new ByteSizeValue(transientBufferSize)); FsTranslog.this.transientBufferSize = transientBufferSize; } - FsTranslogFile.Type type = FsTranslogFile.Type.fromString(settings.get("index.translog.fs.type", FsTranslog.this.type.name())); + FsTranslogFile.Type type = FsTranslogFile.Type.fromString(settings.get(INDEX_TRANSLOG_FS_TYPE, FsTranslog.this.type.name())); if (type != FsTranslog.this.type) { logger.info("updating type from [{}] to [{}]", FsTranslog.this.type, type); FsTranslog.this.type = type; diff --git a/src/main/java/org/elasticsearch/indices/cache/filter/IndicesFilterCache.java b/src/main/java/org/elasticsearch/indices/cache/filter/IndicesFilterCache.java index 837a1e6894096..829f713976795 100644 --- a/src/main/java/org/elasticsearch/indices/cache/filter/IndicesFilterCache.java +++ b/src/main/java/org/elasticsearch/indices/cache/filter/IndicesFilterCache.java @@ -59,24 +59,20 @@ public class IndicesFilterCache extends AbstractComponent implements RemovalList private volatile boolean closed; - static { - MetaData.addDynamicSettings( - "indices.cache.filter.size", - "indices.cache.filter.expire" - ); - } + public static final String INDICES_CACHE_FILTER_SIZE = "indices.cache.filter.size"; + public static final String INDICES_CACHE_FILTER_EXPIRE = "indices.cache.filter.expire"; class ApplySettings implements NodeSettingsService.Listener { @Override public void onRefreshSettings(Settings settings) { boolean replace = false; - String size = settings.get("indices.cache.filter.size", IndicesFilterCache.this.size); + String size = settings.get(INDICES_CACHE_FILTER_SIZE, IndicesFilterCache.this.size); if (!size.equals(IndicesFilterCache.this.size)) { logger.info("updating [indices.cache.filter.size] from [{}] to [{}]", IndicesFilterCache.this.size, size); IndicesFilterCache.this.size = size; replace = true; } - TimeValue expire = settings.getAsTime("indices.cache.filter.expire", IndicesFilterCache.this.expire); + TimeValue expire = settings.getAsTime(INDICES_CACHE_FILTER_EXPIRE, IndicesFilterCache.this.expire); if (!Objects.equal(expire, IndicesFilterCache.this.expire)) { logger.info("updating [indices.cache.filter.expire] from [{}] to [{}]", IndicesFilterCache.this.expire, expire); IndicesFilterCache.this.expire = expire; diff --git a/src/main/java/org/elasticsearch/indices/recovery/RecoverySettings.java b/src/main/java/org/elasticsearch/indices/recovery/RecoverySettings.java index 534519b541700..823bf1717d273 100644 --- a/src/main/java/org/elasticsearch/indices/recovery/RecoverySettings.java +++ b/src/main/java/org/elasticsearch/indices/recovery/RecoverySettings.java @@ -20,7 +20,6 @@ package org.elasticsearch.indices.recovery; import com.google.common.base.Objects; -import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.RateLimiter; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; @@ -37,14 +36,12 @@ */ public class RecoverySettings extends AbstractComponent { - static { - MetaData.addDynamicSettings("indices.recovery.file_chunk_size"); - MetaData.addDynamicSettings("indices.recovery.translog_ops"); - MetaData.addDynamicSettings("indices.recovery.translog_size"); - MetaData.addDynamicSettings("indices.recovery.compress"); - MetaData.addDynamicSettings("indices.recovery.concurrent_streams"); - MetaData.addDynamicSettings("indices.recovery.max_size_per_sec"); - } + public static final String INDICES_RECOVERY_FILE_CHUNK_SIZE = "indices.recovery.file_chunk_size"; + public static final String INDICES_RECOVERY_TRANSLOG_OPS = "indices.recovery.translog_ops"; + public static final String INDICES_RECOVERY_TRANSLOG_SIZE = "indices.recovery.translog_size"; + public static final String INDICES_RECOVERY_COMPRESS = "indices.recovery.compress"; + public static final String INDICES_RECOVERY_CONCURRENT_STREAMS = "indices.recovery.concurrent_streams"; + public static final String INDICES_RECOVERY_MAX_SIZE_PER_SEC = "indices.recovery.max_size_per_sec"; private volatile ByteSizeValue fileChunkSize; @@ -124,7 +121,7 @@ public RateLimiter rateLimiter() { class ApplySettings implements NodeSettingsService.Listener { @Override public void onRefreshSettings(Settings settings) { - ByteSizeValue maxSizePerSec = settings.getAsBytesSize("indices.recovery.max_size_per_sec", RecoverySettings.this.maxSizePerSec); + ByteSizeValue maxSizePerSec = settings.getAsBytesSize(INDICES_RECOVERY_MAX_SIZE_PER_SEC, RecoverySettings.this.maxSizePerSec); if (!Objects.equal(maxSizePerSec, RecoverySettings.this.maxSizePerSec)) { logger.info("updating [indices.recovery.max_size_per_sec] from [{}] to [{}]", RecoverySettings.this.maxSizePerSec, maxSizePerSec); RecoverySettings.this.maxSizePerSec = maxSizePerSec; @@ -137,31 +134,31 @@ public void onRefreshSettings(Settings settings) { } } - ByteSizeValue fileChunkSize = settings.getAsBytesSize("indices.recovery.file_chunk_size", RecoverySettings.this.fileChunkSize); + ByteSizeValue fileChunkSize = settings.getAsBytesSize(INDICES_RECOVERY_FILE_CHUNK_SIZE, RecoverySettings.this.fileChunkSize); if (!fileChunkSize.equals(RecoverySettings.this.fileChunkSize)) { logger.info("updating [indices.recovery.file_chunk_size] from [{}] to [{}]", RecoverySettings.this.fileChunkSize, fileChunkSize); RecoverySettings.this.fileChunkSize = fileChunkSize; } - int translogOps = settings.getAsInt("indices.recovery.translog_ops", RecoverySettings.this.translogOps); + int translogOps = settings.getAsInt(INDICES_RECOVERY_TRANSLOG_OPS, RecoverySettings.this.translogOps); if (translogOps != RecoverySettings.this.translogOps) { logger.info("updating [indices.recovery.translog_ops] from [{}] to [{}]", RecoverySettings.this.translogOps, translogOps); RecoverySettings.this.translogOps = translogOps; } - ByteSizeValue translogSize = settings.getAsBytesSize("indices.recovery.translog_size", RecoverySettings.this.translogSize); + ByteSizeValue translogSize = settings.getAsBytesSize(INDICES_RECOVERY_TRANSLOG_SIZE, RecoverySettings.this.translogSize); if (!translogSize.equals(RecoverySettings.this.translogSize)) { logger.info("updating [indices.recovery.translog_size] from [{}] to [{}]", RecoverySettings.this.translogSize, translogSize); RecoverySettings.this.translogSize = translogSize; } - boolean compress = settings.getAsBoolean("indices.recovery.compress", RecoverySettings.this.compress); + boolean compress = settings.getAsBoolean(INDICES_RECOVERY_COMPRESS, RecoverySettings.this.compress); if (compress != RecoverySettings.this.compress) { logger.info("updating [indices.recovery.compress] from [{}] to [{}]", RecoverySettings.this.compress, compress); RecoverySettings.this.compress = compress; } - int concurrentStreams = settings.getAsInt("indices.recovery.concurrent_streams", RecoverySettings.this.concurrentStreams); + int concurrentStreams = settings.getAsInt(INDICES_RECOVERY_CONCURRENT_STREAMS, RecoverySettings.this.concurrentStreams); if (concurrentStreams != RecoverySettings.this.concurrentStreams) { logger.info("updating [indices.recovery.concurrent_streams] from [{}] to [{}]", RecoverySettings.this.concurrentStreams, concurrentStreams); RecoverySettings.this.concurrentStreams = concurrentStreams; diff --git a/src/main/java/org/elasticsearch/indices/store/IndicesStore.java b/src/main/java/org/elasticsearch/indices/store/IndicesStore.java index 6a5d548044371..acaa718610466 100644 --- a/src/main/java/org/elasticsearch/indices/store/IndicesStore.java +++ b/src/main/java/org/elasticsearch/indices/store/IndicesStore.java @@ -23,7 +23,6 @@ import org.elasticsearch.cluster.ClusterChangedEvent; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterStateListener; -import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.ShardRouting; @@ -46,17 +45,13 @@ */ public class IndicesStore extends AbstractComponent implements ClusterStateListener { - static { - MetaData.addDynamicSettings( - "indices.store.throttle.type", - "indices.store.throttle.max_bytes_per_sec" - ); - } + public static final String INDICES_STORE_THROTTLE_TYPE = "indices.store.throttle.type"; + public static final String INDICES_STORE_THROTTLE_MAX_BYTES_PER_SEC = "indices.store.throttle.max_bytes_per_sec"; class ApplySettings implements NodeSettingsService.Listener { @Override public void onRefreshSettings(Settings settings) { - String rateLimitingType = settings.get("indices.store.throttle.type", IndicesStore.this.rateLimitingType); + String rateLimitingType = settings.get(INDICES_STORE_THROTTLE_TYPE, IndicesStore.this.rateLimitingType); // try and parse the type StoreRateLimiting.Type.fromString(rateLimitingType); if (!rateLimitingType.equals(IndicesStore.this.rateLimitingType)) { @@ -65,7 +60,7 @@ public void onRefreshSettings(Settings settings) { IndicesStore.this.rateLimiting.setType(rateLimitingType); } - ByteSizeValue rateLimitingThrottle = settings.getAsBytesSize("indices.store.throttle.max_bytes_per_sec", IndicesStore.this.rateLimitingThrottle); + ByteSizeValue rateLimitingThrottle = settings.getAsBytesSize(INDICES_STORE_THROTTLE_MAX_BYTES_PER_SEC, IndicesStore.this.rateLimitingThrottle); if (!rateLimitingThrottle.equals(IndicesStore.this.rateLimitingThrottle)) { logger.info("updating indices.store.throttle.max_bytes_per_sec from [{}] to [{}], note, type is [{}]", IndicesStore.this.rateLimitingThrottle, rateLimitingThrottle, IndicesStore.this.rateLimitingType); IndicesStore.this.rateLimitingThrottle = rateLimitingThrottle; diff --git a/src/main/java/org/elasticsearch/indices/ttl/IndicesTTLService.java b/src/main/java/org/elasticsearch/indices/ttl/IndicesTTLService.java index e68af6e95a6c7..3f800d959cc06 100644 --- a/src/main/java/org/elasticsearch/indices/ttl/IndicesTTLService.java +++ b/src/main/java/org/elasticsearch/indices/ttl/IndicesTTLService.java @@ -63,15 +63,8 @@ */ public class IndicesTTLService extends AbstractLifecycleComponent { - static { - MetaData.addDynamicSettings( - "indices.ttl.interval" - ); - - IndexMetaData.addDynamicSettings( - "index.ttl.disable_purge" - ); - } + public static final String INDICES_TTL_INTERVAL = "indices.ttl.interval"; + public static final String INDEX_TTL_DISABLE_PURGE = "index.ttl.disable_purge"; private final ClusterService clusterService; private final IndicesService indicesService; @@ -152,7 +145,7 @@ private List getShardsToPurge() { if (indexMetaData == null) { continue; } - boolean disablePurge = indexMetaData.settings().getAsBoolean("index.ttl.disable_purge", false); + boolean disablePurge = indexMetaData.settings().getAsBoolean(INDEX_TTL_DISABLE_PURGE, false); if (disablePurge) { continue; } @@ -278,11 +271,11 @@ public void onFailure(Throwable e) { class ApplySettings implements NodeSettingsService.Listener { @Override public void onRefreshSettings(Settings settings) { - TimeValue interval = settings.getAsTime("indices.ttl.interval", IndicesTTLService.this.interval); + TimeValue interval = settings.getAsTime(INDICES_TTL_INTERVAL, IndicesTTLService.this.interval); if (!interval.equals(IndicesTTLService.this.interval)) { logger.info("updating indices.ttl.interval from [{}] to [{}]", IndicesTTLService.this.interval, interval); IndicesTTLService.this.interval = interval; } } } -} \ No newline at end of file +} diff --git a/src/main/java/org/elasticsearch/node/settings/NodeSettingsService.java b/src/main/java/org/elasticsearch/node/settings/NodeSettingsService.java index a88863ff59699..85fb59422daec 100644 --- a/src/main/java/org/elasticsearch/node/settings/NodeSettingsService.java +++ b/src/main/java/org/elasticsearch/node/settings/NodeSettingsService.java @@ -89,6 +89,9 @@ public void clusterChanged(ClusterChangedEvent event) { lastSettingsApplied = event.state().metaData().settings(); } + /** + * Only settings registered in {@link org.elasticsearch.cluster.settings.ClusterDynamicSettingsModule} can be changed dynamically. + */ public void addListener(Listener listener) { this.listeners.add(listener); } diff --git a/src/main/java/org/elasticsearch/threadpool/ThreadPool.java b/src/main/java/org/elasticsearch/threadpool/ThreadPool.java index b7b8261e388d5..b36a59b9dc464 100644 --- a/src/main/java/org/elasticsearch/threadpool/ThreadPool.java +++ b/src/main/java/org/elasticsearch/threadpool/ThreadPool.java @@ -24,7 +24,6 @@ import com.google.common.collect.Maps; import com.google.common.util.concurrent.MoreExecutors; import org.elasticsearch.ElasticSearchIllegalArgumentException; -import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; @@ -75,11 +74,7 @@ public static class Names { public static final String SNAPSHOT = "snapshot"; } - static { - MetaData.addDynamicSettings( - "threadpool.*" - ); - } + public static final String THREADPOOL_GROUP = "threadpool."; private volatile ImmutableMap executors; @@ -99,7 +94,7 @@ public ThreadPool() { public ThreadPool(Settings settings, @Nullable NodeSettingsService nodeSettingsService) { super(settings); - Map groupSettings = settings.getGroups("threadpool"); + Map groupSettings = settings.getGroups(THREADPOOL_GROUP); defaultExecutorTypeSettings = ImmutableMap.builder() .put(Names.GENERIC, settingsBuilder().put("type", "cached").put("keep_alive", "30s").build())