Skip to content

Commit

Permalink
Changing dynamic index and cluster settings should work on master-onl…
Browse files Browse the repository at this point in the history
…y nodes

Fixes #2675
  • Loading branch information
imotov committed Feb 26, 2013
1 parent 8f657f9 commit e87e516
Show file tree
Hide file tree
Showing 38 changed files with 548 additions and 369 deletions.
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -88,7 +93,7 @@ public ClusterState execute(ClusterState currentState) {
ImmutableSettings.Builder transientSettings = ImmutableSettings.settingsBuilder();
transientSettings.put(currentState.metaData().transientSettings());
for (Map.Entry<String, String> 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 {
Expand All @@ -99,7 +104,7 @@ public ClusterState execute(ClusterState currentState) {
ImmutableSettings.Builder persistentSettings = ImmutableSettings.settingsBuilder();
persistentSettings.put(currentState.metaData().persistentSettings());
for (Map.Entry<String, String> 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 {
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/elasticsearch/cluster/ClusterModule.java
Expand Up @@ -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;

/**
*
Expand All @@ -46,7 +48,10 @@ public ClusterModule(Settings settings) {

@Override
public Iterable<? extends Module> spawnModules() {
return ImmutableList.of(new AllocationModule(settings), new OperationRoutingModule(settings));
return ImmutableList.of(new AllocationModule(settings),
new OperationRoutingModule(settings),
new ClusterDynamicSettingsModule(),
new IndexDynamicSettingsModule());
}

@Override
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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.*;

/**
Expand Down Expand Up @@ -108,39 +109,11 @@ public static <T extends Custom> Custom.Factory<T> lookupFactorySafe(String type
return factory;
}

private static ImmutableSet<String> dynamicSettings = ImmutableSet.<String>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<String> 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<String> updatedSettings = new HashSet<String>(dynamicSettings);
updatedSettings.addAll(Arrays.asList(settings));
dynamicSettings = ImmutableSet.copyOf(updatedSettings);
}

public static enum State {
OPEN((byte) 0),
CLOSE((byte) 1);
Expand Down
23 changes: 0 additions & 23 deletions src/main/java/org/elasticsearch/cluster/metadata/MetaData.java
Expand Up @@ -99,29 +99,6 @@ public static <T extends Custom> Custom.Factory<T> 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<String> dynamicSettings = ImmutableSet.<String>builder()
.add(SETTING_READ_ONLY)
.build();

public static ImmutableSet<String> 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<String> updatedSettings = new HashSet<String>(dynamicSettings);
updatedSettings.addAll(Arrays.asList(settings));
dynamicSettings = ImmutableSet.copyOf(updatedSettings);
}

public static final MetaData EMPTY_META_DATA = newMetaDataBuilder().build();

private final long version;
Expand Down
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -138,7 +143,7 @@ public void updateSettings(final Settings pSettings, final String[] indices, fin

final Set<String> removedSettings = Sets.newHashSet();
for (String key : updatedSettingsBuilder.internalMap().keySet()) {
if (!IndexMetaData.hasDynamicSetting(key)) {
if (!dynamicSettings.hasDynamicSetting(key)) {
removedSettings.add(key);
}
}
Expand Down
Expand Up @@ -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;
Expand All @@ -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<String, String[]> forcedAwarenessAttributes = new HashMap<String, String[]>(AwarenessAllocationDecider.this.forcedAwarenessAttributes);
Map<String, Settings> forceGroups = settings.getGroups("cluster.routing.allocation.awareness.force.");
Map<String, Settings> forceGroups = settings.getGroups(CLUSTER_ROUTING_ALLOCATION_AWARENESS_FORCE_GROUP);
if (!forceGroups.isEmpty()) {
for (Map.Entry<String, Settings> entry : forceGroups.entrySet()) {
String[] aValues = entry.getValue().getAsArray("values");
Expand Down Expand Up @@ -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<String, Settings> forceGroups = settings.getGroups("cluster.routing.allocation.awareness.force.");
Map<String, Settings> forceGroups = settings.getGroups(CLUSTER_ROUTING_ALLOCATION_AWARENESS_FORCE_GROUP);
for (Map.Entry<String, Settings> entry : forceGroups.entrySet()) {
String[] aValues = entry.getValue().getAsArray("values");
if (aValues.length > 0) {
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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());
}
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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());
}
Expand Down

0 comments on commit e87e516

Please sign in to comment.