move all allocations to be Decision base
this again will allow to provide better output as to why a specific decision has been made (like a shard needing to move from a node)
This commit is contained in:
parent
a963bc1dc9
commit
2c7850584d
|
@ -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) {
|
||||
|
|
|
@ -141,12 +141,13 @@ public class EvenShardsCountAllocator extends AbstractComponent implements Shard
|
|||
boolean relocated = false;
|
||||
List<MutableShardRouting> 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(),
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<MutableShardRouting> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
|
|
|
@ -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<MutableShardRouting> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue