diff --git a/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java b/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java index 832f34ff69b..83e63d7a303 100644 --- a/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java +++ b/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java @@ -28,6 +28,7 @@ import org.elasticsearch.cluster.routing.*; import org.elasticsearch.cluster.routing.allocation.allocator.ShardsAllocators; import org.elasticsearch.cluster.routing.allocation.command.AllocationCommands; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; +import org.elasticsearch.cluster.routing.allocation.decider.Decision; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.ImmutableSettings; @@ -223,7 +224,8 @@ public class AllocationService extends AbstractComponent { continue; } RoutingNode routingNode = allocation.routingNodes().node(shardRouting.currentNodeId()); - if (!allocation.deciders().canRemain(shardRouting, routingNode, allocation)) { + Decision decision = allocation.deciders().canRemain(shardRouting, routingNode, allocation); + if (decision.type() == Decision.Type.NO) { logger.debug("[{}][{}] allocated on [{}], but can no longer be allocated on it, moving...", shardRouting.index(), shardRouting.id(), routingNode.node()); boolean moved = shardsAllocators.move(shardRouting, routingNode, allocation); if (!moved) { diff --git a/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/EvenShardsCountAllocator.java b/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/EvenShardsCountAllocator.java index 8561408814f..f515448dd35 100644 --- a/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/EvenShardsCountAllocator.java +++ b/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/EvenShardsCountAllocator.java @@ -141,12 +141,13 @@ public class EvenShardsCountAllocator extends AbstractComponent implements Shard boolean relocated = false; List startedShards = highRoutingNode.shardsWithState(STARTED); for (MutableShardRouting startedShard : startedShards) { - if (!allocation.deciders().canRebalance(startedShard, allocation)) { + Decision rebalanceDecision = allocation.deciders().canRebalance(startedShard, allocation); + if (rebalanceDecision.type() == Decision.Type.NO) { continue; } - Decision decision = allocation.deciders().canAllocate(startedShard, lowRoutingNode, allocation); - if (decision.type() == Decision.Type.YES) { + Decision allocateDecision = allocation.deciders().canAllocate(startedShard, lowRoutingNode, allocation); + if (allocateDecision.type() == Decision.Type.YES) { changed = true; lowRoutingNode.add(new MutableShardRouting(startedShard.index(), startedShard.id(), lowRoutingNode.nodeId(), startedShard.currentNodeId(), 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 34752c13679..85d95f50334 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 @@ -34,10 +34,16 @@ public abstract class AllocationDecider extends AbstractComponent { super(settings); } - public boolean canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) { - return true; + /** + * Are we allowed to rebalance this shard? + */ + public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) { + return Decision.ALWAYS; } + /** + * Can the provided shard routing be allocated on the node. + */ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { return Decision.ALWAYS; } @@ -45,7 +51,7 @@ public abstract class AllocationDecider extends AbstractComponent { /** * Can the provided shard routing remain on the node? */ - public boolean canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { - return true; + public Decision canRemain(ShardRouting shardRouting, RoutingNode node, 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 b8a71e1eb6a..15efd16d9f0 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 @@ -59,13 +59,15 @@ public class AllocationDeciders extends AllocationDecider { } @Override - public boolean canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) { - for (AllocationDecider allocation1 : allocations) { - if (!allocation1.canRebalance(shardRouting, allocation)) { - return false; + public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) { + Decision.Multi ret = new Decision.Multi(); + for (AllocationDecider allocationDecider : allocations) { + Decision decision = allocationDecider.canRebalance(shardRouting, allocation); + if (decision != Decision.ALWAYS) { + ret.add(decision); } } - return true; + return ret; } @Override @@ -86,15 +88,17 @@ public class AllocationDeciders extends AllocationDecider { } @Override - public boolean canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { + public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { if (allocation.shouldIgnoreShardForNode(shardRouting.shardId(), node.nodeId())) { - return false; + return Decision.NO; } - for (AllocationDecider allocation1 : allocations) { - if (!allocation1.canRemain(shardRouting, node, allocation)) { - return false; + Decision.Multi ret = new Decision.Multi(); + for (AllocationDecider allocationDecider : allocations) { + Decision decision = allocationDecider.canRemain(shardRouting, node, allocation); + if (decision != Decision.ALWAYS) { + ret.add(decision); } } - return true; + return ret; } } 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 376fc44625f..01ad72c6fbb 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 @@ -107,8 +107,8 @@ public class AwarenessAllocationDecider extends AllocationDecider { } @Override - public boolean canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { - return underCapacity(shardRouting, node, allocation, false); + public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { + return underCapacity(shardRouting, node, allocation, false) ? Decision.YES : Decision.NO; } private boolean underCapacity(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation, boolean moveToNode) { 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 98d4a3e39c3..f6239cf1d27 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 @@ -56,11 +56,11 @@ public class ClusterRebalanceAllocationDecider extends AllocationDecider { } @Override - public boolean canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) { + public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) { if (type == ClusterRebalanceType.INDICES_PRIMARIES_ACTIVE) { for (MutableShardRouting shard : allocation.routingNodes().unassigned()) { if (shard.primary()) { - return false; + return Decision.NO; } } for (RoutingNode node : allocation.routingNodes()) { @@ -68,27 +68,27 @@ public class ClusterRebalanceAllocationDecider extends AllocationDecider { for (int i = 0; i < shards.size(); i++) { MutableShardRouting shard = shards.get(i); if (shard.primary() && !shard.active() && shard.relocatingNodeId() == null) { - return false; + return Decision.NO; } } } - return true; + return Decision.YES; } if (type == ClusterRebalanceType.INDICES_ALL_ACTIVE) { if (!allocation.routingNodes().unassigned().isEmpty()) { - return false; + return Decision.NO; } for (RoutingNode node : allocation.routingNodes()) { List shards = node.shards(); for (int i = 0; i < shards.size(); i++) { MutableShardRouting shard = shards.get(i); if (!shard.active() && shard.relocatingNodeId() == null) { - return false; + return Decision.NO; } } } } // type == Type.ALWAYS - return true; + return Decision.YES; } } 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 c5ea5728a72..32f9f7c8445 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 @@ -61,9 +61,9 @@ public class ConcurrentRebalanceAllocationDecider extends AllocationDecider { } @Override - public boolean canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) { + public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) { if (clusterConcurrentRebalance == -1) { - return true; + return Decision.YES; } int rebalance = 0; for (RoutingNode node : allocation.routingNodes()) { @@ -75,8 +75,8 @@ public class ConcurrentRebalanceAllocationDecider extends AllocationDecider { } } if (rebalance >= clusterConcurrentRebalance) { - return false; + return Decision.NO; } - return true; + return Decision.YES; } } \ No newline at end of file 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 487d9829590..d3194003232 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 @@ -72,8 +72,8 @@ public class FilterAllocationDecider extends AllocationDecider { } @Override - public boolean canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { - return !shouldFilter(shardRouting, node, allocation); + public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { + return shouldFilter(shardRouting, node, allocation) ? Decision.NO : Decision.YES; } private boolean shouldFilter(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { diff --git a/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/RebalanceOnlyWhenActiveAllocationDecider.java b/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/RebalanceOnlyWhenActiveAllocationDecider.java index b581d37b16d..f95d5dc575d 100644 --- a/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/RebalanceOnlyWhenActiveAllocationDecider.java +++ b/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/RebalanceOnlyWhenActiveAllocationDecider.java @@ -38,15 +38,15 @@ public class RebalanceOnlyWhenActiveAllocationDecider extends AllocationDecider } @Override - public boolean canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) { + public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) { List shards = allocation.routingNodes().shardsRoutingFor(shardRouting); // its ok to check for active here, since in relocation, a shard is split into two in routing // nodes, once relocating, and one initializing for (int i = 0; i < shards.size(); i++) { if (!shards.get(i).active()) { - return false; + return Decision.NO; } } - return true; + return Decision.YES; } } 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 61c2cb4f319..6f39ec9217c 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 @@ -75,11 +75,11 @@ public class ShardsLimitAllocationDecider extends AllocationDecider { } @Override - public boolean canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { + public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { IndexMetaData indexMd = allocation.routingNodes().metaData().index(shardRouting.index()); int totalShardsPerNode = indexMd.settings().getAsInt(INDEX_TOTAL_SHARDS_PER_NODE, -1); if (totalShardsPerNode <= 0) { - return true; + return Decision.YES; } int nodeCount = 0; @@ -96,8 +96,8 @@ public class ShardsLimitAllocationDecider extends AllocationDecider { nodeCount++; } if (nodeCount > totalShardsPerNode) { - return false; + return Decision.NO; } - return true; + return Decision.YES; } }