diff --git a/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java b/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java index a85d80c971c..6dde296c186 100644 --- a/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java +++ b/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java @@ -333,7 +333,7 @@ public class BalancedShardsAllocator extends AbstractComponent implements Shards } final RoutingNodes.UnassignedShards unassigned = routingNodes.unassigned().transactionBegin(); boolean changed = initialize(routingNodes, unassigned); - if (!changed) { + if (!changed && allocation.deciders().canRebalance(allocation).type() == Type.YES) { NodeSorter sorter = newNodeSorter(); if (nodes.size() > 1) { /* skip if we only have one node */ for (String index : buildWeightOrderedIndidces(Operation.BALANCE, sorter)) { diff --git a/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDecider.java b/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDecider.java index a99e1b87fbe..a6204485d7d 100644 --- a/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDecider.java +++ b/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDecider.java @@ -80,4 +80,13 @@ public abstract class AllocationDecider extends AbstractComponent { public Decision canAllocate(RoutingNode node, RoutingAllocation allocation) { return Decision.ALWAYS; } + + /** + * Returns a {@link Decision} whether the cluster can execute + * re-balanced operations at all. + * {@link Decision#ALWAYS}. + */ + public Decision canRebalance(RoutingAllocation allocation) { + return Decision.ALWAYS; + } } diff --git a/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDeciders.java b/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDeciders.java index cccbc11535f..f57c48e8a75 100644 --- a/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDeciders.java +++ b/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDeciders.java @@ -157,4 +157,23 @@ public class AllocationDeciders extends AllocationDecider { } return ret; } + + @Override + public Decision canRebalance(RoutingAllocation allocation) { + Decision.Multi ret = new Decision.Multi(); + for (AllocationDecider allocationDecider : allocations) { + Decision decision = allocationDecider.canRebalance(allocation); + // short track if a NO is returned. + if (decision == Decision.NO) { + if (!allocation.debugDecision()) { + return decision; + } else { + ret.add(decision); + } + } else if (decision != Decision.ALWAYS) { + ret.add(decision); + } + } + return ret; + } } diff --git a/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ClusterRebalanceAllocationDecider.java b/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ClusterRebalanceAllocationDecider.java index fc263ee8bd2..f0480c4af7c 100644 --- a/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ClusterRebalanceAllocationDecider.java +++ b/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ClusterRebalanceAllocationDecider.java @@ -135,6 +135,11 @@ public class ClusterRebalanceAllocationDecider extends AllocationDecider { @Override public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) { + return canRebalance(allocation); + } + + @Override + public Decision canRebalance(RoutingAllocation allocation) { if (type == ClusterRebalanceType.INDICES_PRIMARIES_ACTIVE) { // check if there are unassigned primaries. if ( allocation.routingNodes().hasUnassignedPrimaries() ) {