allow to change awareness settings using cluster update settings API

This commit is contained in:
Shay Banon 2011-09-21 23:48:23 +03:00
parent 44efcca108
commit 3f8b7f0fce
4 changed files with 42 additions and 5 deletions

View File

@ -45,7 +45,7 @@ public class AllocationDeciders extends AllocationDecider {
.add(new RebalanceOnlyWhenActiveAllocationDecider(settings))
.add(new ClusterRebalanceAllocationDecider(settings))
.add(new ConcurrentRebalanceAllocationDecider(settings))
.add(new AwarenessAllocationDecider(settings))
.add(new AwarenessAllocationDecider(settings, nodeSettingsService))
.build()
);
}

View File

@ -20,6 +20,7 @@
package org.elasticsearch.cluster.routing.allocation.decider;
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;
@ -28,28 +29,63 @@ import org.elasticsearch.common.collect.Maps;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.trove.map.hash.TObjectIntHashMap;
import org.elasticsearch.node.settings.NodeSettingsService;
import java.util.HashMap;
import java.util.Map;
/**
*/
public class AwarenessAllocationDecider extends AllocationDecider {
static {
MetaData.addDynamicSettings(
"cluster.routing.allocation.awareness.attributes",
"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);
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.");
if (!forceGroups.isEmpty()) {
for (Map.Entry<String, Settings> entry : forceGroups.entrySet()) {
String[] aValues = entry.getValue().getAsArray("values");
if (aValues.length > 0) {
forcedAwarenessAttributes.put(entry.getKey(), aValues);
}
}
}
AwarenessAllocationDecider.this.forcedAwarenessAttributes = forcedAwarenessAttributes;
}
}
private String[] awarenessAttributes;
private Map<String, String[]> forcedAwarenessAttributes;
@Inject public AwarenessAllocationDecider(Settings settings) {
@Inject public AwarenessAllocationDecider(Settings settings, NodeSettingsService nodeSettingsService) {
super(settings);
this.awarenessAttributes = settings.getAsArray("cluster.routing.allocation.awareness.attributes");
forcedAwarenessAttributes = Maps.newHashMap();
Map<String, Settings> forceGroups = settings.getGroups("cluster.routing.allocation.awareness.force.");
for (Map.Entry<String, Settings> entry : forceGroups.entrySet()) {
forcedAwarenessAttributes.put(entry.getKey(), entry.getValue().getAsArray("values"));
String[] aValues = entry.getValue().getAsArray("values");
if (aValues.length > 0) {
forcedAwarenessAttributes.put(entry.getKey(), aValues);
}
}
nodeSettingsService.addListener(new ApplySettings());
}
public String[] awarenessAttributes() {
return this.awarenessAttributes;
}

View File

@ -246,7 +246,7 @@ public class MinimumMasterNodesTests extends AbstractZenNodesTests {
closeNode(nodeToShutdown);
}
Thread.sleep(500);
Thread.sleep(1000);
String lastNonMasterNodeUp = nonMasterNodes.removeLast();
logger.info("--> verify that there is no master anymore on remaining nodes");

View File

@ -36,6 +36,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.trove.ExtTIntArrayList;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.node.settings.NodeSettingsService;
import org.elasticsearch.search.Scroll;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
@ -400,7 +401,7 @@ public class ThreeShardsUnbalancedShardsEmbeddedSearchTests extends AbstractNode
public static class UnevenOperationRoutingStrategy extends PlainOperationRouting {
@Inject public UnevenOperationRoutingStrategy(Settings settings) {
super(settings, null, new AwarenessAllocationDecider(Builder.EMPTY_SETTINGS));
super(settings, null, new AwarenessAllocationDecider(Builder.EMPTY_SETTINGS, new NodeSettingsService(Builder.EMPTY_SETTINGS)));
}
@Override protected int hash(String routing) {