Skip to content

Commit

Permalink
Move cluster.routing.allocation.same_shard.host setting to new settin…
Browse files Browse the repository at this point in the history
…gs infrastructure

Fixes #20045
  • Loading branch information
masaruh committed Aug 22, 2016
1 parent 6ed83ce commit c7e3653
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Expand Up @@ -23,13 +23,14 @@
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;

/**
* An allocation decider that prevents multiple instances of the same shard to
* be allocated on the same <tt>node</tt>.
*
* The {@value #SAME_HOST_SETTING} setting allows to perform a check to prevent
* The {@link #CLUSTER_ROUTING_ALLOCATION_SAME_HOST_SETTING} setting allows to perform a check to prevent
* allocation of multiple instances of the same shard on a single <tt>host</tt>,
* based on host name and host address. Defaults to `false`, meaning that no
* check is performed by default.
Expand All @@ -44,14 +45,15 @@ public class SameShardAllocationDecider extends AllocationDecider {

public static final String NAME = "same_shard";

public static final String SAME_HOST_SETTING = "cluster.routing.allocation.same_shard.host";
public static final Setting<Boolean> CLUSTER_ROUTING_ALLOCATION_SAME_HOST_SETTING =
Setting.boolSetting("cluster.routing.allocation.same_shard.host", false, Setting.Property.NodeScope);

private final boolean sameHost;

public SameShardAllocationDecider(Settings settings) {
super(settings);

this.sameHost = settings.getAsBoolean(SAME_HOST_SETTING, false);
this.sameHost = CLUSTER_ROUTING_ALLOCATION_SAME_HOST_SETTING.get(settings);
}

@Override
Expand Down
Expand Up @@ -39,6 +39,7 @@
import org.elasticsearch.cluster.routing.allocation.decider.ConcurrentRebalanceAllocationDecider;
import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider;
import org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider;
import org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider;
import org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider;
import org.elasticsearch.cluster.routing.allocation.decider.SnapshotInProgressAllocationDecider;
import org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider;
Expand Down Expand Up @@ -198,6 +199,7 @@ public void apply(Settings value, Settings current, Settings previous) {
DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED_SETTING,
DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING,
DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_REROUTE_INTERVAL_SETTING,
SameShardAllocationDecider.CLUSTER_ROUTING_ALLOCATION_SAME_HOST_SETTING,
InternalClusterInfoService.INTERNAL_CLUSTER_INFO_UPDATE_INTERVAL_SETTING,
InternalClusterInfoService.INTERNAL_CLUSTER_INFO_TIMEOUT_SETTING,
SnapshotInProgressAllocationDecider.CLUSTER_ROUTING_ALLOCATION_SNAPSHOT_RELOCATION_ENABLED_SETTING,
Expand Down
Expand Up @@ -47,8 +47,8 @@ public class SameShardRoutingTests extends ESAllocationTestCase {
private final ESLogger logger = Loggers.getLogger(SameShardRoutingTests.class);

public void testSameHost() {
AllocationService strategy = createAllocationService(Settings.builder()
.put(SameShardAllocationDecider.SAME_HOST_SETTING, true).build());
AllocationService strategy = createAllocationService(
Settings.builder().put(SameShardAllocationDecider.CLUSTER_ROUTING_ALLOCATION_SAME_HOST_SETTING.getKey(), true).build());

MetaData metaData = MetaData.builder()
.put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(2).numberOfReplicas(1))
Expand Down

0 comments on commit c7e3653

Please sign in to comment.