[ALLOCATION] Early terminate if the cluster can't be rebalanced
By default we won't allow rebalance operation if no all shards are active. if this is the case we don't need to worry about costly rebalance calculations at all.
This commit is contained in:
parent
9ad1434a3b
commit
56a2fb04ee
|
@ -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)) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() ) {
|
||||
|
|
Loading…
Reference in New Issue