diff --git a/server/src/internalClusterTest/java/org/elasticsearch/cluster/routing/ShardRoutingRoleIT.java b/server/src/internalClusterTest/java/org/elasticsearch/cluster/routing/ShardRoutingRoleIT.java index 455c53049747f..46e617a50a272 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/cluster/routing/ShardRoutingRoleIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/cluster/routing/ShardRoutingRoleIT.java @@ -35,6 +35,7 @@ import org.elasticsearch.cluster.routing.allocation.command.CancelAllocationCommand; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.Decision; +import org.elasticsearch.cluster.routing.allocation.decider.DefaultAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.bytes.BytesReference; @@ -179,7 +180,7 @@ public Collection getActions() { @Override public Collection createAllocationDeciders(Settings settings, ClusterSettings clusterSettings) { - return List.of(new AllocationDecider() { + return List.of(new DefaultAllocationDecider() { @Override public Decision canForceAllocatePrimary(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { // once a primary is cancelled it _stays_ cancelled diff --git a/server/src/internalClusterTest/java/org/elasticsearch/gateway/GatewayServiceIT.java b/server/src/internalClusterTest/java/org/elasticsearch/gateway/GatewayServiceIT.java index 58e2a1bbf0509..8987bd36ab262 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/gateway/GatewayServiceIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/gateway/GatewayServiceIT.java @@ -15,6 +15,7 @@ import org.elasticsearch.cluster.routing.allocation.FailedShard; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider; +import org.elasticsearch.cluster.routing.allocation.decider.DefaultAllocationDecider; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; @@ -104,7 +105,7 @@ public int getNumberOfInFlightFetches() { } } - private static class TestAllocationDecider extends AllocationDecider { + private static class TestAllocationDecider extends DefaultAllocationDecider { TestAllocationDecider(Settings settings, ClusterSettings clusterSettings, AtomicBoolean settingApplied) { if (TEST_SETTING.get(settings)) { settingApplied.set(true); diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDecider.java index 7fae18a332f0c..ce62beff95ed6 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDecider.java @@ -14,102 +14,94 @@ import org.elasticsearch.cluster.routing.RoutingNode; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; -import org.elasticsearch.cluster.routing.allocation.decider.Decision.Type; import java.util.Optional; import java.util.Set; /** - * {@link AllocationDecider} is an abstract base class that allows to make - * dynamic cluster- or index-wide shard allocation decisions on a per-node - * basis. + * A collection of Decider interfaces. */ -public abstract class AllocationDecider { - /** - * Returns a {@link Decision} whether the given shard routing can be - * re-balanced to the given allocation. The default is - * {@link Decision#ALWAYS}. - */ - public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) { - return Decision.ALWAYS; - } +public interface AllocationDecider { - /** - * Returns a {@link Decision} whether the given shard routing can be - * allocated on the given node. The default is {@link Decision#ALWAYS}. - */ - public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { - return Decision.ALWAYS; - } + interface ShardToNode extends AllocationDecider { + /** + * Returns a {@link Decision} whether the given shard routing can be allocated on the given node. + */ + Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation); - /** - * Returns a {@link Decision} whether the given shard routing can be remain - * on the given node. The default is {@link Decision#ALWAYS}. - */ - public Decision canRemain(IndexMetadata indexMetadata, ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { - return Decision.ALWAYS; - } + /** + * Returns a {@link Decision} whether the given primary shard can be + * forcibly allocated on the given node. This method should only be called + * for unassigned primary shards where the node has a shard copy on disk. + * + * Note: all implementations that override this behavior should take into account + * the results of {@link ShardToNode#canAllocate(ShardRouting, RoutingNode, RoutingAllocation)} + * before making a decision on force allocation, because force allocation should only + * be considered if all deciders return {@link Decision#NO}. + */ + default Decision canForceAllocatePrimary(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { + assert shardRouting.primary() : "must not call canForceAllocatePrimary on a non-primary shard " + shardRouting; + assert shardRouting.unassigned() : "must not call canForceAllocatePrimary on an assigned shard " + shardRouting; + Decision decision = canAllocate(shardRouting, node, allocation); + if (decision.type() == Decision.Type.NO) { + // On a NO decision, by default, we allow force allocating the primary. + return allocation.decision( + Decision.YES, + decision.label(), + "primary shard [%s] allowed to force allocate on node [%s]", + shardRouting.shardId(), + node.nodeId() + ); + } else { + // On a THROTTLE/YES decision, we use the same decision instead of forcing allocation + return decision; + } + } - /** - * Returns a {@link Decision} whether the given shard routing can be allocated at all at this state of the - * {@link RoutingAllocation}. The default is {@link Decision#ALWAYS}. - */ - public Decision canAllocate(ShardRouting shardRouting, RoutingAllocation allocation) { - return Decision.ALWAYS; - } + /** + * Returns a {@link Decision} whether the given replica shard can be + * allocated to the given node when there is an existing retention lease + * already existing on the node (meaning it has been allocated there previously) + * + * This method does not actually check whether there is a retention lease, + * that is the responsibility of the caller. + * + * It defaults to the same value as {@code canAllocate}. + */ + default Decision canAllocateReplicaWhenThereIsRetentionLease( + ShardRouting shardRouting, + RoutingNode node, + RoutingAllocation allocation + ) { + return canAllocate(shardRouting, node, allocation); + } - /** - * Returns a {@link Decision} whether the given shard routing can be allocated at all at this state of the - * {@link RoutingAllocation}. The default is {@link Decision#ALWAYS}. - */ - public Decision canAllocate(IndexMetadata indexMetadata, RoutingNode node, RoutingAllocation allocation) { - return Decision.ALWAYS; } /** - * Returns a {@link Decision} whether shards of the given index should be auto-expanded to this node at this state of the - * {@link RoutingAllocation}. The default is {@link Decision#ALWAYS}. + * Returns a {@link Decision} whether any shard of index can be allocated to given node. */ - public Decision shouldAutoExpandToNode(IndexMetadata indexMetadata, DiscoveryNode node, RoutingAllocation allocation) { - return Decision.ALWAYS; + @FunctionalInterface + interface IndexToNode extends AllocationDecider { + Decision canAllocate(IndexMetadata indexMetadata, RoutingNode node, RoutingAllocation allocation); } /** - * Returns a {@link Decision} on whether the cluster is allowed to rebalance shards to improve relative node shard weights and - * performance. - * @return {@link Decision#ALWAYS} is returned by default if not overridden. + * Returns a {@link Decision} whether the given shard routing can be allocated at all at this state of the {@link RoutingAllocation}. */ - public Decision canRebalance(RoutingAllocation allocation) { - return Decision.ALWAYS; + @FunctionalInterface + interface ShardToCluster extends AllocationDecider { + Decision canAllocate(ShardRouting shardRouting, RoutingAllocation allocation); } /** - * Returns a {@link Decision} whether the given primary shard can be - * forcibly allocated on the given node. This method should only be called - * for unassigned primary shards where the node has a shard copy on disk. + * Returns a {@code empty()} if shard could be initially allocated anywhere or {@code Optional.of(Set.of(nodeIds))} if shard could be + * initially allocated only on subset of a nodes. * - * Note: all implementations that override this behavior should take into account - * the results of {@link #canAllocate(ShardRouting, RoutingNode, RoutingAllocation)} - * before making a decision on force allocation, because force allocation should only - * be considered if all deciders return {@link Decision#NO}. + * This might be required for splitting or shrinking index as resulting shards have to be on the same node as a source shard. */ - public Decision canForceAllocatePrimary(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { - assert shardRouting.primary() : "must not call canForceAllocatePrimary on a non-primary shard " + shardRouting; - assert shardRouting.unassigned() : "must not call canForceAllocatePrimary on an assigned shard " + shardRouting; - Decision decision = canAllocate(shardRouting, node, allocation); - if (decision.type() == Type.NO) { - // On a NO decision, by default, we allow force allocating the primary. - return allocation.decision( - Decision.YES, - decision.label(), - "primary shard [%s] allowed to force allocate on node [%s]", - shardRouting.shardId(), - node.nodeId() - ); - } else { - // On a THROTTLE/YES decision, we use the same decision instead of forcing allocation - return decision; - } + interface ForcedInitialShardAllocation extends AllocationDecider { + Optional> getForcedInitialShardAllocationToNodes(ShardRouting shardRouting, RoutingAllocation allocation); } /** @@ -126,31 +118,37 @@ public Decision canForceAllocatePrimary(ShardRouting shardRouting, RoutingNode n * - that a replacement is ongoing * - the shard routing's current node is the source of the replacement */ - public Decision canForceAllocateDuringReplace(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { - return Decision.YES; + interface ForceDuringReplace extends AllocationDecider { + Decision canForceAllocateDuringReplace(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation); } /** - * Returns a {@link Decision} whether the given replica shard can be - * allocated to the given node when there is an existing retention lease - * already existing on the node (meaning it has been allocated there previously) - * - * This method does not actually check whether there is a retention lease, - * that is the responsibility of the caller. - * - * It defaults to the same value as {@code canAllocate}. + * Returns a {@link Decision} on whether the cluster is allowed to rebalance shards to improve relative node shard weights and + * performance. */ - public Decision canAllocateReplicaWhenThereIsRetentionLease(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { - return canAllocate(shardRouting, node, allocation); + interface ClusterRebalance extends AllocationDecider { + Decision canRebalance(RoutingAllocation allocation); } /** - * Returns a {@code empty()} if shard could be initially allocated anywhere or {@code Optional.of(Set.of(nodeIds))} if shard could be - * initially allocated only on subset of a nodes. - * - * This might be required for splitting or shrinking index as resulting shards have to be on the same node as a source shard. + * Returns a {@link Decision} whether shards of the given index should be auto-expanded to this node at this state of the + * {@link RoutingAllocation}. + */ + interface AutoExpandToNode extends AllocationDecider { + Decision shouldAutoExpandToNode(IndexMetadata indexMetadata, DiscoveryNode node, RoutingAllocation allocation); + } + + /** + * Returns a {@link Decision} whether the given shard routing can be remain on the given node. + */ + interface ShardRemain extends AllocationDecider { + Decision canRemain(IndexMetadata indexMetadata, ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation); + } + + /** + * Returns a {@link Decision} whether the given shard routing can be re-balanced to the given allocation. */ - public Optional> getForcedInitialShardAllocationToNodes(ShardRouting shardRouting, RoutingAllocation allocation) { - return Optional.empty(); + interface ShardRebalance extends AllocationDecider { + Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation); } } diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDeciders.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDeciders.java index c80aa1e69f212..5feab7582391f 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDeciders.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDeciders.java @@ -19,12 +19,24 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.util.set.Sets; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; import java.util.Optional; import java.util.Set; import java.util.function.BiFunction; import java.util.function.Function; +import static org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider.AutoExpandToNode; +import static org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider.ClusterRebalance; +import static org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider.ForceDuringReplace; +import static org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider.ForcedInitialShardAllocation; +import static org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider.IndexToNode; +import static org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider.ShardRebalance; +import static org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider.ShardRemain; +import static org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider.ShardToCluster; +import static org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider.ShardToNode; + /** * Combines the decision of multiple {@link AllocationDecider} implementations into a single allocation decision. */ @@ -38,15 +50,52 @@ public class AllocationDeciders { "shard temporarily ignored for node due to earlier failure" ); - private final AllocationDecider[] deciders; + private final List shardToNodeDeciders = new ArrayList<>(); + private final List indexToNodeDeciders = new ArrayList<>(); + private final List shardToClusterDeciders = new ArrayList<>(); + private final List shardRemainDeciders = new ArrayList<>(); + private final List shardRebalanceDeciders = new ArrayList<>(); + private final List clusterRebalanceDeciders = new ArrayList<>(); + private final List autoExpandToNodeDeciders = new ArrayList<>(); + private final List forceDuringReplaceDeciders = new ArrayList<>(); + private final List forcedInitialShardAllocationsDeciders = new ArrayList<>(); public AllocationDeciders(Collection deciders) { - this.deciders = deciders.toArray(AllocationDecider[]::new); + for (var decider : deciders) { + if (decider instanceof ShardToNode d) { + shardToNodeDeciders.add(d); + } + if (decider instanceof IndexToNode d) { + indexToNodeDeciders.add(d); + } + if (decider instanceof ShardToCluster d) { + shardToClusterDeciders.add(d); + } + if (decider instanceof ShardRemain d) { + shardRemainDeciders.add(d); + } + if (decider instanceof ShardRebalance d) { + shardRebalanceDeciders.add(d); + } + if (decider instanceof ClusterRebalance d) { + clusterRebalanceDeciders.add(d); + } + if (decider instanceof AutoExpandToNode d) { + autoExpandToNodeDeciders.add(d); + } + if (decider instanceof ForceDuringReplace d) { + forceDuringReplaceDeciders.add(d); + } + if (decider instanceof ForcedInitialShardAllocation d) { + forcedInitialShardAllocationsDeciders.add(d); + } + } } public Decision canAllocate(ShardRouting shardRouting, RoutingAllocation allocation) { return withDeciders( allocation, + shardToClusterDeciders, decider -> decider.canAllocate(shardRouting, allocation), (decider, decision) -> Strings.format("Can not allocate [%s] on any node. [%s]: %s", shardRouting, decider, decision) ); @@ -55,6 +104,7 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingAllocation allocat public Decision canAllocate(IndexMetadata indexMetadata, RoutingNode node, RoutingAllocation allocation) { return withDeciders( allocation, + indexToNodeDeciders, decider -> decider.canAllocate(indexMetadata, node, allocation), (decider, decision) -> Strings.format( "Can not allocate [%s] on node [%s]. [%s]: %s", @@ -71,6 +121,7 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing allocation, shardRouting, node, + shardToNodeDeciders, decider -> decider.canAllocate(shardRouting, node, allocation), (decider, decision) -> Strings.format( "Can not allocate [%s] on node [%s]. [%s]: %s", @@ -89,6 +140,7 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing public Decision canRebalance(RoutingAllocation allocation) { return withDeciders( allocation, + clusterRebalanceDeciders, decider -> decider.canRebalance(allocation), (decider, decision) -> Strings.format("Can not rebalance. [%s]: %s", decider, decision) ); @@ -98,6 +150,7 @@ public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation alloca assert shardRouting.started() : "Only started shard could be rebalanced: " + shardRouting; return withDeciders( allocation, + shardRebalanceDeciders, decider -> decider.canRebalance(shardRouting, allocation), (decider, decision) -> Strings.format("Can not rebalance [%s]. [%s]: %s", shardRouting, decider, decision) ); @@ -109,6 +162,7 @@ public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAl allocation, shardRouting, node, + shardRemainDeciders, decider -> decider.canRemain(indexMetadata, shardRouting, node, allocation), (decider, decision) -> Strings.format("Can not remain [%s] on node [%s]. [%s]: %s", shardRouting, node, decider, decision) ); @@ -117,6 +171,7 @@ public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAl public Decision shouldAutoExpandToNode(IndexMetadata indexMetadata, DiscoveryNode node, RoutingAllocation allocation) { return withDeciders( allocation, + autoExpandToNodeDeciders, decider -> decider.shouldAutoExpandToNode(indexMetadata, node, allocation), (decider, decision) -> Strings.format( "Should not auto expand [%s] to node [%s]. [%s]: %s", @@ -134,6 +189,7 @@ public Decision canForceAllocatePrimary(ShardRouting shardRouting, RoutingNode n allocation, shardRouting, node, + shardToNodeDeciders, decider -> decider.canForceAllocatePrimary(shardRouting, node, allocation), (decider, decision) -> Strings.format( "Can not force allocate shard [%s] on node [%s]. [%s]: %s", @@ -148,6 +204,7 @@ public Decision canForceAllocatePrimary(ShardRouting shardRouting, RoutingNode n public Decision canForceAllocateDuringReplace(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { return withDeciders( allocation, + forceDuringReplaceDeciders, decider -> decider.canForceAllocateDuringReplace(shardRouting, node, allocation), (decider, decision) -> Strings.format( "Can not force allocate during replace shard [%s] on node [%s]. [%s]: %s", @@ -164,6 +221,7 @@ public Decision canAllocateReplicaWhenThereIsRetentionLease(ShardRouting shardRo allocation, shardRouting, node, + shardToNodeDeciders, decider -> decider.canAllocateReplicaWhenThereIsRetentionLease(shardRouting, node, allocation), (decider, decision) -> Strings.format( "Can not allocate replica when there is retention lease shard [%s] on node [%s]. [%s]: %s", @@ -175,19 +233,21 @@ public Decision canAllocateReplicaWhenThereIsRetentionLease(ShardRouting shardRo ); } - private Decision withDeciders( + private Decision withDeciders( RoutingAllocation allocation, - Function deciderAction, + List deciders, + Function deciderAction, BiFunction logMessageCreator ) { - return withDeciders(allocation.getDebugMode(), deciderAction, logMessageCreator); + return withDeciders(allocation.getDebugMode(), deciders, deciderAction, logMessageCreator); } - private Decision withDecidersCheckingShardIgnoredNodes( + private Decision withDecidersCheckingShardIgnoredNodes( RoutingAllocation allocation, ShardRouting shardRouting, RoutingNode node, - Function deciderAction, + List deciders, + Function deciderAction, BiFunction logMessageCreator ) { if (allocation.shouldIgnoreShardForNode(shardRouting.shardId(), node.nodeId())) { @@ -196,17 +256,18 @@ private Decision withDecidersCheckingShardIgnoredNodes( } return NO_IGNORING_SHARD_FOR_NODE; } - return withDeciders(allocation.getDebugMode(), deciderAction, logMessageCreator); + return withDeciders(allocation.getDebugMode(), deciders, deciderAction, logMessageCreator); } - private Decision withDeciders( + private Decision withDeciders( RoutingAllocation.DebugMode debugMode, - Function deciderAction, + List deciders, + Function deciderAction, BiFunction logMessageCreator ) { if (debugMode == RoutingAllocation.DebugMode.OFF) { var result = Decision.YES; - for (AllocationDecider decider : deciders) { + for (D decider : deciders) { var decision = deciderAction.apply(decider); if (decision.type() == Decision.Type.NO) { if (logger.isTraceEnabled()) { @@ -220,7 +281,7 @@ private Decision withDeciders( return result; } else { var result = new Decision.Multi(); - for (AllocationDecider decider : deciders) { + for (var decider : deciders) { var decision = deciderAction.apply(decider); if (logger.isTraceEnabled() && decision.type() == Decision.Type.NO) { logger.trace(() -> logMessageCreator.apply(decider.getClass().getSimpleName(), decision)); @@ -235,7 +296,7 @@ private Decision withDeciders( public Optional> getForcedInitialShardAllocationToNodes(ShardRouting shardRouting, RoutingAllocation allocation) { var result = Optional.>empty(); - for (AllocationDecider decider : deciders) { + for (var decider : forcedInitialShardAllocationsDeciders) { var forcedInitialNodeIds = decider.getForcedInitialShardAllocationToNodes(shardRouting, allocation); if (forcedInitialNodeIds.isPresent()) { result = result.map(nodeIds -> Sets.intersection(nodeIds, forcedInitialNodeIds.get())).or(() -> forcedInitialNodeIds); diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AwarenessAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AwarenessAllocationDecider.java index 901bc21192016..2d4f86b63ff5d 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AwarenessAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AwarenessAllocationDecider.java @@ -69,7 +69,11 @@ * node.zone: zone1 * */ -public class AwarenessAllocationDecider extends AllocationDecider { +public class AwarenessAllocationDecider + implements + AllocationDecider.ShardToNode, + AllocationDecider.ForceDuringReplace, + AllocationDecider.ShardRemain { public static final String NAME = "awareness"; diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ClusterRebalanceAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ClusterRebalanceAllocationDecider.java index 3cf012d3faa3f..1256be2f21557 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ClusterRebalanceAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ClusterRebalanceAllocationDecider.java @@ -38,7 +38,7 @@ * is active * */ -public class ClusterRebalanceAllocationDecider extends AllocationDecider { +public class ClusterRebalanceAllocationDecider implements AllocationDecider.ShardRebalance, AllocationDecider.ClusterRebalance { private static final Logger logger = LogManager.getLogger(ClusterRebalanceAllocationDecider.class); diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ConcurrentRebalanceAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ConcurrentRebalanceAllocationDecider.java index deb3e4440f4ab..c95c957fe0306 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ConcurrentRebalanceAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ConcurrentRebalanceAllocationDecider.java @@ -29,7 +29,7 @@ * setting is set to {@code -1} the number of concurrent re-balance operations * are unlimited. */ -public class ConcurrentRebalanceAllocationDecider extends AllocationDecider { +public class ConcurrentRebalanceAllocationDecider implements AllocationDecider.ShardRebalance, AllocationDecider.ClusterRebalance { private static final Logger logger = LogManager.getLogger(ConcurrentRebalanceAllocationDecider.class); diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DefaultAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DefaultAllocationDecider.java new file mode 100644 index 0000000000000..64c9029282b3a --- /dev/null +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DefaultAllocationDecider.java @@ -0,0 +1,76 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +package org.elasticsearch.cluster.routing.allocation.decider; + +import org.elasticsearch.cluster.metadata.IndexMetadata; +import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.routing.RoutingNode; +import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; + +import java.util.Optional; +import java.util.Set; + +public class DefaultAllocationDecider + implements + AllocationDecider.ShardToNode, + AllocationDecider.ShardToCluster, + AllocationDecider.IndexToNode, + AllocationDecider.ShardRemain, + AllocationDecider.ShardRebalance, + AllocationDecider.ClusterRebalance, + AllocationDecider.ForceDuringReplace, + AllocationDecider.ForcedInitialShardAllocation, + AllocationDecider.AutoExpandToNode { + @Override + public Decision shouldAutoExpandToNode(IndexMetadata indexMetadata, DiscoveryNode node, RoutingAllocation allocation) { + return Decision.ALWAYS; + } + + @Override + public Decision canRebalance(RoutingAllocation allocation) { + return Decision.ALWAYS; + } + + @Override + public Decision canForceAllocateDuringReplace(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { + return Decision.ALWAYS; + } + + @Override + public Optional> getForcedInitialShardAllocationToNodes(ShardRouting shardRouting, RoutingAllocation allocation) { + return Optional.empty(); + } + + @Override + public Decision canAllocate(IndexMetadata indexMetadata, RoutingNode node, RoutingAllocation allocation) { + return Decision.ALWAYS; + } + + @Override + public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) { + return Decision.ALWAYS; + } + + @Override + public Decision canRemain(IndexMetadata indexMetadata, ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { + return Decision.ALWAYS; + } + + @Override + public Decision canAllocate(ShardRouting shardRouting, RoutingAllocation allocation) { + return Decision.ALWAYS; + } + + @Override + public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { + return Decision.ALWAYS; + } +} diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDecider.java index b4264aa55ad4c..9d2c59c2e97ff 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDecider.java @@ -65,7 +65,11 @@ * cluster.routing.allocation.disk.threshold_enabled is used to * enable or disable this decider. It defaults to true (enabled). */ -public class DiskThresholdDecider extends AllocationDecider { +public class DiskThresholdDecider + implements + AllocationDecider.ShardToNode, + AllocationDecider.ForceDuringReplace, + AllocationDecider.ShardRemain { private static final Logger logger = LogManager.getLogger(DiskThresholdDecider.class); @@ -352,7 +356,7 @@ public Decision canForceAllocateDuringReplace(ShardRouting shardRouting, Routing -freeBytesAfterShard ); } else { - return super.canForceAllocateDuringReplace(shardRouting, node, allocation); + return Decision.ALWAYS; } } diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationDecider.java index e539fa23c5f5a..43be0da713c86 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationDecider.java @@ -49,7 +49,12 @@ * @see Rebalance * @see Allocation */ -public class EnableAllocationDecider extends AllocationDecider { +public class EnableAllocationDecider + implements + AllocationDecider.ShardToNode, + AllocationDecider.ShardToCluster, + AllocationDecider.ShardRebalance, + AllocationDecider.ClusterRebalance { public static final String NAME = "enable"; diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDecider.java index a7f0aa3cea89f..1d92f81d88cd4 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDecider.java @@ -58,7 +58,13 @@ * filtered node * */ -public class FilterAllocationDecider extends AllocationDecider { +public class FilterAllocationDecider + implements + AllocationDecider.ShardToNode, + AllocationDecider.IndexToNode, + AllocationDecider.ShardRemain, + AllocationDecider.AutoExpandToNode, + AllocationDecider.ForcedInitialShardAllocation { public static final String NAME = "filter"; @@ -242,6 +248,6 @@ public Optional> getForcedInitialShardAllocationToNodes(ShardRouting ); } } - return super.getForcedInitialShardAllocationToNodes(shardRouting, allocation); + return Optional.empty(); } } diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/IndexVersionAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/IndexVersionAllocationDecider.java index 061646e51c881..9914c5214f23b 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/IndexVersionAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/IndexVersionAllocationDecider.java @@ -23,7 +23,7 @@ * on the lowest level since it might have already written segments that use a new postings format or codec that is not * available on the target node. */ -public class IndexVersionAllocationDecider extends AllocationDecider { +public class IndexVersionAllocationDecider implements AllocationDecider.ShardToNode, AllocationDecider.ForceDuringReplace { public static final String NAME = "index_version"; diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/MaxRetryAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/MaxRetryAllocationDecider.java index a7d7a1bb8f7d1..7e1ef782219a0 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/MaxRetryAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/MaxRetryAllocationDecider.java @@ -25,7 +25,11 @@ * API is manually invoked. This allows single retries without raising the limits. * */ -public class MaxRetryAllocationDecider extends AllocationDecider { +public class MaxRetryAllocationDecider + implements + AllocationDecider.ShardToCluster, + AllocationDecider.ShardToNode, + AllocationDecider.ForceDuringReplace { public static final Setting SETTING_ALLOCATION_MAX_RETRY = Setting.intSetting( "index.allocation.max_retries", diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/NodeReplacementAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/NodeReplacementAllocationDecider.java index 949ea5c3fc87b..bfb9982585dab 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/NodeReplacementAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/NodeReplacementAllocationDecider.java @@ -21,7 +21,12 @@ * It also ensures that auto-expands replicas are expanded to only the replacement source or target (not both at the same time) * and only of the shards that were already present on the source node. */ -public class NodeReplacementAllocationDecider extends AllocationDecider { +public class NodeReplacementAllocationDecider + implements + AllocationDecider.ShardToNode, + AllocationDecider.AutoExpandToNode, + AllocationDecider.ShardRemain, + AllocationDecider.ForceDuringReplace { public static final String NAME = "node_replacement"; diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/NodeShutdownAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/NodeShutdownAllocationDecider.java index 0e60ce3589d8f..13835d82c17f7 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/NodeShutdownAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/NodeShutdownAllocationDecider.java @@ -22,7 +22,11 @@ * No shards can be allocated to or remain on a node which is shutting down for removal. * Shards can be allocated to or remain on a node scheduled for a restart. */ -public class NodeShutdownAllocationDecider extends AllocationDecider { +public class NodeShutdownAllocationDecider + implements + AllocationDecider.ShardToNode, + AllocationDecider.ShardRemain, + AllocationDecider.AutoExpandToNode { private static final String NAME = "node_shutdown"; diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/NodeVersionAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/NodeVersionAllocationDecider.java index 25de3ed70e922..0f6be4e012b07 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/NodeVersionAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/NodeVersionAllocationDecider.java @@ -23,7 +23,7 @@ * on the lowest level since it might have already written segments that use a new postings format or codec that is not * available on the target node. */ -public class NodeVersionAllocationDecider extends AllocationDecider { +public class NodeVersionAllocationDecider implements AllocationDecider.ShardToNode, AllocationDecider.ForceDuringReplace { public static final String NAME = "node_version"; diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/RebalanceOnlyWhenActiveAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/RebalanceOnlyWhenActiveAllocationDecider.java index 378cc8b09d7c2..e0791cead8de0 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/RebalanceOnlyWhenActiveAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/RebalanceOnlyWhenActiveAllocationDecider.java @@ -15,7 +15,7 @@ /** * Only allow rebalancing when all shards are active within the shard replication group. */ -public class RebalanceOnlyWhenActiveAllocationDecider extends AllocationDecider { +public class RebalanceOnlyWhenActiveAllocationDecider implements AllocationDecider.ShardRebalance { public static final String NAME = "rebalance_only_when_active"; diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ReplicaAfterPrimaryActiveAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ReplicaAfterPrimaryActiveAllocationDecider.java index ec831f703c575..1117f65f0159e 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ReplicaAfterPrimaryActiveAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ReplicaAfterPrimaryActiveAllocationDecider.java @@ -16,7 +16,11 @@ /** * An allocation strategy that only allows for a replica to be allocated when the primary is active. */ -public class ReplicaAfterPrimaryActiveAllocationDecider extends AllocationDecider { +public class ReplicaAfterPrimaryActiveAllocationDecider + implements + AllocationDecider.ShardToNode, + AllocationDecider.ShardToCluster, + AllocationDecider.ForceDuringReplace { private static final String NAME = "replica_after_primary_active"; diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ResizeAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ResizeAllocationDecider.java index 6f8fd734ccf73..d4a1602e0f101 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ResizeAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ResizeAllocationDecider.java @@ -24,7 +24,12 @@ /** * An allocation decider that ensures we allocate the shards of a target index for resize operations next to the source primaries */ -public class ResizeAllocationDecider extends AllocationDecider { +public class ResizeAllocationDecider + implements + AllocationDecider.ShardToCluster, + AllocationDecider.ShardToNode, + AllocationDecider.ForceDuringReplace, + AllocationDecider.ForcedInitialShardAllocation { public static final String NAME = "resize"; @@ -66,7 +71,7 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing return allocation.decision(Decision.YES, NAME, "source primary is active"); } } - return super.canAllocate(shardRouting, node, allocation); + return Decision.ALWAYS; } @Override @@ -102,6 +107,6 @@ public Optional> getForcedInitialShardAllocationToNodes(ShardRouting } return Optional.of(Set.of(activePrimary.currentNodeId())); } - return super.getForcedInitialShardAllocationToNodes(shardRouting, allocation); + return Optional.empty(); } } diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/RestoreInProgressAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/RestoreInProgressAllocationDecider.java index e945795bdb083..00a0323db87a1 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/RestoreInProgressAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/RestoreInProgressAllocationDecider.java @@ -19,7 +19,11 @@ * This {@link AllocationDecider} prevents shards that have failed to be * restored from a snapshot to be allocated. */ -public class RestoreInProgressAllocationDecider extends AllocationDecider { +public class RestoreInProgressAllocationDecider + implements + AllocationDecider.ShardToNode, + AllocationDecider.ShardToCluster, + AllocationDecider.ForceDuringReplace { public static final String NAME = "restore_in_progress"; diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SameShardAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SameShardAllocationDecider.java index 637744c4480aa..d8344004d784c 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SameShardAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SameShardAllocationDecider.java @@ -33,7 +33,7 @@ * {@code node} are not allowed independently of this setting. *

*/ -public class SameShardAllocationDecider extends AllocationDecider { +public class SameShardAllocationDecider implements AllocationDecider.ShardToNode, AllocationDecider.ForceDuringReplace { public static final String NAME = "same_shard"; diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ShardsLimitAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ShardsLimitAllocationDecider.java index a2fb926e2b3b7..dd725fce3feda 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ShardsLimitAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ShardsLimitAllocationDecider.java @@ -40,7 +40,7 @@ * trigger relocation and significant additional load on the clusters nodes. *

*/ -public class ShardsLimitAllocationDecider extends AllocationDecider { +public class ShardsLimitAllocationDecider implements AllocationDecider.ShardToNode, AllocationDecider.ShardRemain { public static final String NAME = "shards_limit"; diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SnapshotInProgressAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SnapshotInProgressAllocationDecider.java index 03ae7c6f1d32c..d37e7d178ba59 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SnapshotInProgressAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SnapshotInProgressAllocationDecider.java @@ -19,37 +19,16 @@ import java.util.Objects; /** - * This {@link org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider} prevents shards that + * This {@link AllocationDecider} prevents shards that * are currently been snapshotted to be moved to other nodes. */ -public class SnapshotInProgressAllocationDecider extends AllocationDecider { +public class SnapshotInProgressAllocationDecider + implements + AllocationDecider.ShardRebalance, + AllocationDecider.ShardToNode, + AllocationDecider.ForceDuringReplace { public static final String NAME = "snapshot_in_progress"; - - /** - * Returns a {@link Decision} whether the given shard routing can be - * re-balanced to the given allocation. The default is - * {@link Decision#ALWAYS}. - */ - @Override - public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) { - return canMove(shardRouting, allocation); - } - - /** - * Returns a {@link Decision} whether the given shard routing can be - * allocated on the given node. The default is {@link Decision#ALWAYS}. - */ - @Override - public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { - return canMove(shardRouting, allocation); - } - - @Override - public Decision canForceAllocateDuringReplace(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { - return canAllocate(shardRouting, node, allocation); - } - private static final Decision YES_NOT_RUNNING = Decision.single(Decision.Type.YES, NAME, "no snapshots are currently running"); private static final Decision YES_NOT_SNAPSHOTTED = Decision.single(Decision.Type.YES, NAME, "the shard is not being snapshotted"); @@ -131,4 +110,28 @@ private static Decision canMove(ShardRouting shardRouting, RoutingAllocation all return YES_NOT_SNAPSHOTTED; } + + /** + * Returns a {@link Decision} whether the given shard routing can be + * re-balanced to the given allocation. The default is + * {@link Decision#ALWAYS}. + */ + @Override + public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) { + return canMove(shardRouting, allocation); + } + + /** + * Returns a {@link Decision} whether the given shard routing can be + * allocated on the given node. The default is {@link Decision#ALWAYS}. + */ + @Override + public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { + return canMove(shardRouting, allocation); + } + + @Override + public Decision canForceAllocateDuringReplace(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { + return canAllocate(shardRouting, node, allocation); + } } diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ThrottlingAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ThrottlingAllocationDecider.java index 8fdfce179f090..4d1d255701997 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ThrottlingAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ThrottlingAllocationDecider.java @@ -41,7 +41,7 @@ * the allocation process to prevent overloading nodes due to too many concurrent recovery * processes. */ -public class ThrottlingAllocationDecider extends AllocationDecider { +public class ThrottlingAllocationDecider implements AllocationDecider.ShardToNode, AllocationDecider.ForceDuringReplace { private static final Logger logger = LogManager.getLogger(ThrottlingAllocationDecider.class); diff --git a/server/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java b/server/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java index 2908bff995340..6324d8bd8f852 100644 --- a/server/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java @@ -20,6 +20,7 @@ import org.elasticsearch.cluster.routing.allocation.decider.AwarenessAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.ConcurrentRebalanceAllocationDecider; +import org.elasticsearch.cluster.routing.allocation.decider.DefaultAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDecider; import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider; @@ -99,7 +100,7 @@ public void tearDown() throws Exception { clusterService.close(); } - static class FakeAllocationDecider extends AllocationDecider { + static class FakeAllocationDecider extends DefaultAllocationDecider { protected FakeAllocationDecider() {} } diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/BalancedSingleShardTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/BalancedSingleShardTests.java index ea732a93f4e1e..feddbfe905041 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/BalancedSingleShardTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/BalancedSingleShardTests.java @@ -21,10 +21,10 @@ import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardRoutingState; import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator; -import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.routing.allocation.decider.Decision; import org.elasticsearch.cluster.routing.allocation.decider.Decision.Type; +import org.elasticsearch.cluster.routing.allocation.decider.DefaultAllocationDecider; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.core.Tuple; import org.elasticsearch.snapshots.SnapshotShardSizeInfo; @@ -87,7 +87,7 @@ public void testRebalanceNotAllowedDuringPendingAsyncFetch() { public void testRebalancingNotAllowedDueToCanRebalance() { final Decision canRebalanceDecision = randomFrom(Decision.NO, Decision.THROTTLE); - AllocationDecider noRebalanceDecider = new AllocationDecider() { + DefaultAllocationDecider noRebalanceDecider = new DefaultAllocationDecider() { @Override public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) { return allocation.decision(canRebalanceDecision, "TEST", "foobar"); @@ -126,7 +126,7 @@ public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation alloca } public void testRebalancePossible() { - AllocationDecider canAllocateDecider = new AllocationDecider() { + DefaultAllocationDecider canAllocateDecider = new DefaultAllocationDecider() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { return Decision.YES; @@ -141,7 +141,7 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing } public void testRebalancingNotAllowedDueToCanAllocate() { - AllocationDecider canAllocateDecider = new AllocationDecider() { + DefaultAllocationDecider canAllocateDecider = new DefaultAllocationDecider() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { return Decision.NO; @@ -163,7 +163,7 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing } public void testDontBalanceShardWhenThresholdNotMet() { - AllocationDecider canAllocateDecider = new AllocationDecider() { + DefaultAllocationDecider canAllocateDecider = new DefaultAllocationDecider() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { return Decision.YES; @@ -215,7 +215,7 @@ public void testSingleShardBalanceProducesSameResultsAsBalanceStep() { } clusterState = ClusterState.builder(clusterState).nodes(nodesBuilder).build(); - AllocationDecider allocationDecider = new AllocationDecider() { + DefaultAllocationDecider allocationDecider = new DefaultAllocationDecider() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { if (excludeNodes.contains(node.nodeId())) { @@ -224,13 +224,13 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing return Decision.YES; } }; - AllocationDecider rebalanceDecider = new AllocationDecider() { + DefaultAllocationDecider rebalanceDecider = new DefaultAllocationDecider() { @Override public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) { return Decision.YES; } }; - List allocationDeciders = Arrays.asList(rebalanceDecider, allocationDecider); + List allocationDeciders = Arrays.asList(rebalanceDecider, allocationDecider); RoutingAllocation routingAllocation = newRoutingAllocation(new AllocationDeciders(allocationDeciders), clusterState); // allocate and get the node that is now relocating BalancedShardsAllocator allocator = new BalancedShardsAllocator(Settings.EMPTY); @@ -321,7 +321,7 @@ private MoveDecision executeRebalanceFor( final ClusterState clusterState, final Set noDecisionNodes ) { - AllocationDecider allocationDecider = new AllocationDecider() { + DefaultAllocationDecider allocationDecider = new DefaultAllocationDecider() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { if (noDecisionNodes.contains(node.nodeId())) { @@ -330,7 +330,7 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing return Decision.YES; } }; - AllocationDecider rebalanceDecider = new AllocationDecider() { + DefaultAllocationDecider rebalanceDecider = new DefaultAllocationDecider() { @Override public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) { return Decision.YES; @@ -358,17 +358,17 @@ private ClusterState addNodesToClusterState(ClusterState clusterState, int numNo } private Tuple setupStateAndRebalance( - AllocationDecider allocationDecider, + DefaultAllocationDecider allocationDecider, Settings balancerSettings, boolean rebalanceExpected ) { - AllocationDecider rebalanceDecider = new AllocationDecider() { + DefaultAllocationDecider rebalanceDecider = new DefaultAllocationDecider() { @Override public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) { return Decision.YES; } }; - List allocationDeciders = Arrays.asList(rebalanceDecider, allocationDecider); + List allocationDeciders = Arrays.asList(rebalanceDecider, allocationDecider); final int numShards = randomIntBetween(8, 13); BalancedShardsAllocator allocator = new BalancedShardsAllocator(balancerSettings); ClusterState clusterState = ClusterStateCreationUtils.state("idx", 2, numShards); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/RandomAllocationDeciderTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/RandomAllocationDeciderTests.java index 169cae3b815c8..bd375f52ee10d 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/RandomAllocationDeciderTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/RandomAllocationDeciderTests.java @@ -24,9 +24,9 @@ import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardRoutingState; import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator; -import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.routing.allocation.decider.Decision; +import org.elasticsearch.cluster.routing.allocation.decider.DefaultAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.ReplicaAfterPrimaryActiveAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider; import org.elasticsearch.common.settings.Settings; @@ -194,7 +194,7 @@ public void testRandomDecisions() { } } - public static final class RandomAllocationDecider extends AllocationDecider { + public static final class RandomAllocationDecider extends DefaultAllocationDecider { private final Random random; diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocatorTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocatorTests.java index 8ab031aa53fe1..89e4446e5d836 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocatorTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocatorTests.java @@ -35,9 +35,9 @@ import org.elasticsearch.cluster.routing.ShardRoutingState; import org.elasticsearch.cluster.routing.allocation.AllocateUnassignedDecision; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; -import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.routing.allocation.decider.Decision; +import org.elasticsearch.cluster.routing.allocation.decider.DefaultAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider; import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.settings.Settings; @@ -865,7 +865,7 @@ public BalancedShardsAllocator.NodeSorter sorterForShard(ShardRouting shard) { * as the index they're from */ private AllocationDeciders prefixAllocationDeciders() { - return new AllocationDeciders(List.of(new AllocationDecider() { + return new AllocationDeciders(List.of(new DefaultAllocationDecider() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { return nodePrefixMatchesIndexPrefix(shardRouting, node); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconcilerTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconcilerTests.java index 844912cba4c17..8c0e0d78dab8f 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconcilerTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconcilerTests.java @@ -46,6 +46,7 @@ import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.routing.allocation.decider.ConcurrentRebalanceAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.Decision; +import org.elasticsearch.cluster.routing.allocation.decider.DefaultAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.NodeReplacementAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.NodeShutdownAllocationDecider; @@ -260,7 +261,7 @@ private static void doTestUnassignedPrimariesBeforeUnassignedReplicas(boolean mu new SameShardAllocationDecider(clusterSettings), new ReplicaAfterPrimaryActiveAllocationDecider(), new ThrottlingAllocationDecider(clusterSettings), - new AllocationDecider() { + new DefaultAllocationDecider() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { return allocationFilter.get().test(shardRouting.getIndexName(), node.nodeId()) ? Decision.YES : Decision.NO; @@ -441,7 +442,7 @@ public void testUnassignedShardsPriority() { new SameShardAllocationDecider(clusterSettings), new ReplicaAfterPrimaryActiveAllocationDecider(), new ThrottlingAllocationDecider(clusterSettings), - new AllocationDecider() { + new DefaultAllocationDecider() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { return (shardRouting.primary() && node.nodeId().equals("node-0")) || assignReplicas.get() ? Decision.YES : Decision.NO; @@ -680,7 +681,7 @@ public void testUnassignedSkipsEquivalentReplicas() { routingAllocation -> reconcile(routingAllocation, desiredBalance), new SameShardAllocationDecider(clusterSettings), new ReplicaAfterPrimaryActiveAllocationDecider(), - new AllocationDecider() { + new DefaultAllocationDecider() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { if (shardRouting.primary()) { @@ -739,7 +740,7 @@ public void testUnassignedSetsAllocationStatusOnUnassignedShards() { routingAllocation -> reconcile(routingAllocation, desiredBalance), new SameShardAllocationDecider(clusterSettings), new ReplicaAfterPrimaryActiveAllocationDecider(), - new AllocationDecider() { + new DefaultAllocationDecider() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { if (shardRouting.primary()) { @@ -798,7 +799,7 @@ public void testUnassignedPrimariesThrottlingAndFallback() { new SameShardAllocationDecider(clusterSettings), new ReplicaAfterPrimaryActiveAllocationDecider(), new ThrottlingAllocationDecider(clusterSettings), - new AllocationDecider() { + new DefaultAllocationDecider() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { return allocationFilter.get().test(shardRouting.getId(), node.nodeId()) ? Decision.YES : Decision.NO; @@ -884,7 +885,7 @@ public void testMoveShards() { new FilterAllocationDecider(settings, clusterSettings), new NodeShutdownAllocationDecider(), new NodeReplacementAllocationDecider(), - new AllocationDecider() { + new DefaultAllocationDecider() { @Override public Decision canRebalance(RoutingAllocation allocation) { return Decision.NO; @@ -1015,7 +1016,7 @@ public void testRebalance() { new ReplicaAfterPrimaryActiveAllocationDecider(), new ThrottlingAllocationDecider(clusterSettings), new ConcurrentRebalanceAllocationDecider(clusterSettings), - new AllocationDecider() { + new DefaultAllocationDecider() { @Override public Decision canRebalance(RoutingAllocation allocation) { return canRebalanceGlobalRef.get(); @@ -1150,7 +1151,7 @@ public void testFallbackAllocation() { .build(); final Set desiredNodeIds = Set.of("node-1", "node-2"); - final var initialForcedAllocationDecider = new AllocationDecider() { + final var initialForcedAllocationDecider = new DefaultAllocationDecider.ShardToNode() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { // allocation on desired nodes is temporarily not possible @@ -1181,11 +1182,10 @@ public void testForcedInitialAllocation() { .routingTable(RoutingTable.builder(TestShardRoutingRoleStrategies.DEFAULT_ROLE_ONLY).addAsNew(indexMetadata)) .build(); - final var allocationIsNotPossibleOnDesiredNodeDesiredNode = new AllocationDecider() { - @Override - public Optional> getForcedInitialShardAllocationToNodes(ShardRouting shardRouting, RoutingAllocation allocation) { - return Optional.of(Set.of("node-1"));// intentionally different from the desired balance - } + final DefaultAllocationDecider.ForcedInitialShardAllocation allocationIsNotPossibleOnDesiredNodeDesiredNode = ( + shardRouting, + allocation) -> { + return Optional.of(Set.of("node-1"));// intentionally different from the desired balance }; final var allocation = createRoutingAllocationFrom(clusterState, allocationIsNotPossibleOnDesiredNodeDesiredNode); @@ -1210,7 +1210,7 @@ public void testForcedInitialAllocationDoNotFallback() { .routingTable(RoutingTable.builder(TestShardRoutingRoleStrategies.DEFAULT_ROLE_ONLY).addAsNew(indexMetadata)) .build(); - final var initialForcedAllocationDecider = new AllocationDecider() { + final var initialForcedAllocationDecider = new DefaultAllocationDecider() { @Override public Optional> getForcedInitialShardAllocationToNodes(ShardRouting shardRouting, RoutingAllocation allocation) { return Optional.of(Set.of("node-1"));// intentionally different from the desired balance diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDecidersTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDecidersTests.java index 20ad4a751e3df..7d211e231b05f 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDecidersTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDecidersTests.java @@ -246,11 +246,11 @@ private static RoutingAllocation createRoutingAllocation(AllocationDeciders deci return new RoutingAllocation(deciders, ClusterState.builder(new ClusterName("test")).build(), null, null, 0L); } - private static final class AnyNodeInitialShardAllocationDecider extends AllocationDecider { + private static final class AnyNodeInitialShardAllocationDecider extends DefaultAllocationDecider { } - private static final class FixedNodesInitialShardAllocationDecider extends AllocationDecider { + private static final class FixedNodesInitialShardAllocationDecider extends DefaultAllocationDecider { private final Set initialNodeIds; private FixedNodesInitialShardAllocationDecider(Set initialNodeIds) { @@ -263,7 +263,7 @@ public Optional> getForcedInitialShardAllocationToNodes(ShardRouting } } - private static final class TestAllocationDecider extends AllocationDecider { + private static final class TestAllocationDecider extends DefaultAllocationDecider { private final Supplier decision; diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java index 5467d313834b8..e335e8fd42387 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java @@ -1030,7 +1030,7 @@ private void doTestCanRemainWithShardRelocatingAway(boolean testMaxHeadroom) { clusterInfo, diskThresholdDecider, // fake allocation decider to block allocation of the `foo` shard - new AllocationDecider() { + new DefaultAllocationDecider() { @Override public Decision canAllocate(IndexMetadata indexMetadata, RoutingNode node, RoutingAllocation allocation) { return cannotAllocateFooShards(indexMetadata.getIndex()); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationShortCircuitTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationShortCircuitTests.java index ba0c431493f57..2bfca41ce2751 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationShortCircuitTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationShortCircuitTests.java @@ -226,7 +226,7 @@ public Collection createAllocationDeciders(Settings settings, return Collections.singletonList(new RebalanceShortCircuitAllocationDecider()); } - private class RebalanceShortCircuitAllocationDecider extends AllocationDecider { + private class RebalanceShortCircuitAllocationDecider extends DefaultAllocationDecider { @Override public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) { @@ -250,7 +250,7 @@ public Collection createAllocationDeciders(Settings settings, return Collections.singletonList(new AllocateShortCircuitAllocationDecider()); } - private class AllocateShortCircuitAllocationDecider extends AllocationDecider { + private class AllocateShortCircuitAllocationDecider extends DefaultAllocationDecider { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/RestoreInProgressAllocationDeciderTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/RestoreInProgressAllocationDeciderTests.java index bc684fd0ea01c..f979d45ea1aad 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/RestoreInProgressAllocationDeciderTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/RestoreInProgressAllocationDeciderTests.java @@ -207,7 +207,7 @@ private ClusterState createInitialClusterState() { } private Decision executeAllocation(final ClusterState clusterState, final ShardRouting shardRouting) { - final AllocationDecider decider = new RestoreInProgressAllocationDecider(); + final var decider = new RestoreInProgressAllocationDecider(); final RoutingAllocation allocation = new RoutingAllocation( new AllocationDeciders(Collections.singleton(decider)), clusterState, diff --git a/server/src/test/java/org/elasticsearch/gateway/PrimaryShardAllocatorTests.java b/server/src/test/java/org/elasticsearch/gateway/PrimaryShardAllocatorTests.java index f119f47ea8611..bd4c7d021c097 100644 --- a/server/src/test/java/org/elasticsearch/gateway/PrimaryShardAllocatorTests.java +++ b/server/src/test/java/org/elasticsearch/gateway/PrimaryShardAllocatorTests.java @@ -243,7 +243,7 @@ public void testFoundAllocationAndAllocating() { /** * Tests that when the nodes with prior copies of the given shard all return a decision of NO, but - * {@link AllocationDecider#canForceAllocatePrimary(ShardRouting, RoutingNode, RoutingAllocation)} + * {@link AllocationDecider.ShardToNode#canForceAllocatePrimary(ShardRouting, RoutingNode, RoutingAllocation)} * returns a YES decision for at least one of those NO nodes, then we force allocate to one of them */ public void testForceAllocatePrimary() { @@ -267,7 +267,7 @@ public void testForceAllocatePrimary() { /** * Tests that when the nodes with prior copies of the given shard all return a decision of NO, and - * {@link AllocationDecider#canForceAllocatePrimary(ShardRouting, RoutingNode, RoutingAllocation)} + * {@link AllocationDecider.ShardToNode#canForceAllocatePrimary(ShardRouting, RoutingNode, RoutingAllocation)} * returns a NO or THROTTLE decision for a node, then we do not force allocate to that node. */ public void testDontAllocateOnNoOrThrottleForceAllocationDecision() { diff --git a/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java b/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java index b84edd1f3eb29..436f733f46035 100644 --- a/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java +++ b/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java @@ -30,9 +30,9 @@ import org.elasticsearch.cluster.routing.TestShardRouting; import org.elasticsearch.cluster.routing.UnassignedInfo; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; -import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.routing.allocation.decider.Decision; +import org.elasticsearch.cluster.routing.allocation.decider.DefaultAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.set.Sets; @@ -372,7 +372,7 @@ public void testThrottleWhenAllocatingToMatchingNode() { Arrays.asList( new TestAllocateDecision(Decision.YES), new SameShardAllocationDecider(createBuiltInClusterSettings()), - new AllocationDecider() { + new DefaultAllocationDecider() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { if (node.node().equals(node2)) { diff --git a/test/framework/src/main/java/org/elasticsearch/cluster/ESAllocationTestCase.java b/test/framework/src/main/java/org/elasticsearch/cluster/ESAllocationTestCase.java index 8a49db652374e..571f284bc35ae 100644 --- a/test/framework/src/main/java/org/elasticsearch/cluster/ESAllocationTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/cluster/ESAllocationTestCase.java @@ -38,6 +38,7 @@ import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.routing.allocation.decider.Decision; +import org.elasticsearch.cluster.routing.allocation.decider.DefaultAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; @@ -346,7 +347,7 @@ public static ClusterState reroute(AllocationService allocationService, ClusterS return result; } - public static class TestAllocateDecision extends AllocationDecider { + public static class TestAllocateDecision extends DefaultAllocationDecider { private final Decision decision; diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ProactiveStorageDeciderServiceTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ProactiveStorageDeciderServiceTests.java index 8c1f18e84a619..9387b685d1ef4 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ProactiveStorageDeciderServiceTests.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ProactiveStorageDeciderServiceTests.java @@ -29,6 +29,7 @@ import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.routing.allocation.decider.Decision; +import org.elasticsearch.cluster.routing.allocation.decider.DefaultAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDecider; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; @@ -90,7 +91,7 @@ public void testScale() { Collection allocationDecidersList = new ArrayList<>( ClusterModule.createAllocationDeciders(Settings.EMPTY, clusterSettings, Collections.emptyList()) ); - allocationDecidersList.add(new AllocationDecider() { + allocationDecidersList.add(new DefaultAllocationDecider() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { return allocation.decision(Decision.NO, DiskThresholdDecider.NAME, "test"); diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderDecisionTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderDecisionTests.java index 3f56065f41e09..927a79a072b4c 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderDecisionTests.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderDecisionTests.java @@ -34,6 +34,7 @@ import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.routing.allocation.decider.Decision; +import org.elasticsearch.cluster.routing.allocation.decider.DefaultAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDecider; import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider; @@ -88,13 +89,13 @@ public class ReactiveStorageDeciderDecisionTests extends AutoscalingTestCase { private static final Logger logger = LogManager.getLogger(ReactiveStorageDeciderDecisionTests.class); - private static final AllocationDecider CAN_ALLOCATE_NO_DECIDER = new AllocationDecider() { + private static final DefaultAllocationDecider CAN_ALLOCATE_NO_DECIDER = new DefaultAllocationDecider() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { return Decision.NO; } }; - private static final AllocationDecider CAN_REMAIN_NO_DECIDER = new AllocationDecider() { + private static final DefaultAllocationDecider CAN_REMAIN_NO_DECIDER = new DefaultAllocationDecider() { @Override public Decision canRemain(IndexMetadata indexMetadata, ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { return Decision.NO; @@ -112,7 +113,7 @@ public Decision canRemain(IndexMetadata indexMetadata, ShardRouting shardRouting // these are the shards that the decider tests work on private Set subjectShards; // say NO with disk label for subject shards - private final AllocationDecider mockCanAllocateDiskDecider = new AllocationDecider() { + private final DefaultAllocationDecider mockCanAllocateDiskDecider = new DefaultAllocationDecider() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { if (subjectShards.contains(shardRouting.shardId()) && node.node().getName().startsWith("hot")) { @@ -122,7 +123,7 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing } }; // say NO with disk label for subject shards - private final AllocationDecider mockCanRemainDiskDecider = new AllocationDecider() { + private final AllocationDecider mockCanRemainDiskDecider = new DefaultAllocationDecider() { @Override public Decision canRemain(IndexMetadata indexMetadata, ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { if (subjectShards.contains(shardRouting.shardId()) && node.node().getName().startsWith("hot")) return allocation.decision( diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderServiceTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderServiceTests.java index 2ee94340f6d2c..6518b8a1bf330 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderServiceTests.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderServiceTests.java @@ -36,6 +36,7 @@ import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.routing.allocation.decider.AwarenessAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.Decision; +import org.elasticsearch.cluster.routing.allocation.decider.DefaultAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDecider; import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider; @@ -595,7 +596,7 @@ public void testCanRemainOnlyHighestTierPreference() { ShardRoutingState.STARTED ); - AllocationDecider no = new AllocationDecider() { + DefaultAllocationDecider no = new DefaultAllocationDecider() { @Override public Decision canRemain( IndexMetadata indexMetadata, @@ -704,19 +705,19 @@ public void testNeedsThisTierLegacy() { ShardRoutingState.STARTED ); - AllocationDecider noFilter = new AllocationDecider() { + DefaultAllocationDecider noFilter = new DefaultAllocationDecider() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { return Decision.single(Decision.Type.NO, FilterAllocationDecider.NAME, "test"); } }; - AllocationDecider noSameShard = new AllocationDecider() { + DefaultAllocationDecider noSameShard = new DefaultAllocationDecider() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { return Decision.single(Decision.Type.NO, SameShardAllocationDecider.NAME, "test"); } }; - AllocationDecider no = new AllocationDecider() { + DefaultAllocationDecider no = new DefaultAllocationDecider() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { return Decision.single(Decision.Type.NO, AwarenessAllocationDecider.NAME, "test"); @@ -732,7 +733,7 @@ private void verifyNeedsWarmTier( ClusterState clusterState, ShardRouting shardRouting, boolean expected, - AllocationDecider... deciders + DefaultAllocationDecider... deciders ) { AllocationDeciders allocationDeciders = new AllocationDeciders(Arrays.asList(deciders)); ReactiveStorageDeciderService.AllocationState allocationState = new ReactiveStorageDeciderService.AllocationState( diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/allocation/CcrPrimaryFollowerAllocationDecider.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/allocation/CcrPrimaryFollowerAllocationDecider.java index 3fd7145d2b3ee..db53a50376b05 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/allocation/CcrPrimaryFollowerAllocationDecider.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/allocation/CcrPrimaryFollowerAllocationDecider.java @@ -22,7 +22,7 @@ * remote cluster client role. This is necessary as those nodes reach out to the leader shards on the remote cluster to copy Lucene segment * files and periodically renew retention leases during the bootstrap. */ -public final class CcrPrimaryFollowerAllocationDecider extends AllocationDecider { +public final class CcrPrimaryFollowerAllocationDecider implements AllocationDecider.ShardToNode { static final String NAME = "ccr_primary_follower"; @Override diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/allocation/CcrPrimaryFollowerAllocationDeciderTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/allocation/CcrPrimaryFollowerAllocationDeciderTests.java index b039e93093331..ce0ffeae8fe07 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/allocation/CcrPrimaryFollowerAllocationDeciderTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/allocation/CcrPrimaryFollowerAllocationDeciderTests.java @@ -213,7 +213,7 @@ public void testBootstrappingFollowerIndex() { } static Decision executeAllocation(ClusterState clusterState, ShardRouting shardRouting, DiscoveryNode node) { - final AllocationDecider decider = new CcrPrimaryFollowerAllocationDecider(); + final AllocationDecider.ShardToNode decider = new CcrPrimaryFollowerAllocationDecider(); final RoutingAllocation routingAllocation = new RoutingAllocation( new AllocationDeciders(List.of(decider)), RoutingNodes.immutable(clusterState.globalRoutingTable(), clusterState.nodes()), diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDecider.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDecider.java index 40259d02e92f8..44b24a64ee452 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDecider.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDecider.java @@ -34,7 +34,12 @@ * {@link org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider}, however it * is specific to the {@code _tier} setting for both the cluster and index level. */ -public final class DataTierAllocationDecider extends AllocationDecider { +public final class DataTierAllocationDecider + implements + AllocationDecider.ShardToNode, + AllocationDecider.IndexToNode, + AllocationDecider.ShardRemain, + AllocationDecider.AutoExpandToNode { public static final String NAME = "data_tier"; diff --git a/x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/ArchiveAllocationDecider.java b/x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/ArchiveAllocationDecider.java index 2a58b9d833859..2b9198170a5f7 100644 --- a/x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/ArchiveAllocationDecider.java +++ b/x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/ArchiveAllocationDecider.java @@ -16,7 +16,11 @@ import java.util.function.BooleanSupplier; -public class ArchiveAllocationDecider extends AllocationDecider { +public class ArchiveAllocationDecider + implements + AllocationDecider.ShardToNode, + AllocationDecider.ShardToCluster, + AllocationDecider.IndexToNode { static final String NAME = "archive"; diff --git a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/cache/blob/SearchableSnapshotsBlobStoreCacheIntegTests.java b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/cache/blob/SearchableSnapshotsBlobStoreCacheIntegTests.java index 0f5b617a99034..51c9f04caf470 100644 --- a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/cache/blob/SearchableSnapshotsBlobStoreCacheIntegTests.java +++ b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/cache/blob/SearchableSnapshotsBlobStoreCacheIntegTests.java @@ -26,6 +26,7 @@ import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.Decision; +import org.elasticsearch.cluster.routing.allocation.decider.DefaultAllocationDecider; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Setting; @@ -391,7 +392,7 @@ public Collection createAllocationDeciders(Settings settings, return List.of(); } final String name = "wait_for_snapshot_blob_cache_shards_active"; - return List.of(new AllocationDecider() { + return List.of(new DefaultAllocationDecider() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/DedicatedFrozenNodeAllocationDecider.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/DedicatedFrozenNodeAllocationDecider.java index dd9cd6630ee95..a517202f49e2f 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/DedicatedFrozenNodeAllocationDecider.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/DedicatedFrozenNodeAllocationDecider.java @@ -18,7 +18,12 @@ import static org.elasticsearch.cluster.node.DiscoveryNodeRole.DATA_FROZEN_NODE_ROLE; -public class DedicatedFrozenNodeAllocationDecider extends AllocationDecider { +public class DedicatedFrozenNodeAllocationDecider + implements + AllocationDecider.ShardToNode, + AllocationDecider.ShardRemain, + AllocationDecider.IndexToNode, + AllocationDecider.AutoExpandToNode { private static final String NAME = "dedicated_frozen_node"; diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/HasFrozenCacheAllocationDecider.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/HasFrozenCacheAllocationDecider.java index db5b4750ccdf8..27e3ca54b1a1b 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/HasFrozenCacheAllocationDecider.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/HasFrozenCacheAllocationDecider.java @@ -18,7 +18,12 @@ import static org.elasticsearch.blobcache.shared.SharedBlobCacheService.SHARED_CACHE_SIZE_SETTING; -public class HasFrozenCacheAllocationDecider extends AllocationDecider { +public class HasFrozenCacheAllocationDecider + implements + AllocationDecider.ShardToNode, + AllocationDecider.IndexToNode, + AllocationDecider.ShardRemain, + AllocationDecider.AutoExpandToNode { private static final String NAME = "has_frozen_cache"; diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/SearchableSnapshotAllocationDecider.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/SearchableSnapshotAllocationDecider.java index d597b335348cf..582a60d365331 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/SearchableSnapshotAllocationDecider.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/SearchableSnapshotAllocationDecider.java @@ -16,7 +16,11 @@ import java.util.function.BooleanSupplier; -public class SearchableSnapshotAllocationDecider extends AllocationDecider { +public class SearchableSnapshotAllocationDecider + implements + AllocationDecider.ShardToNode, + AllocationDecider.ShardToCluster, + AllocationDecider.IndexToNode { static final String NAME = "searchable_snapshots"; diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/SearchableSnapshotEnableAllocationDecider.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/SearchableSnapshotEnableAllocationDecider.java index 292c09af44cf5..44455239c6bb8 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/SearchableSnapshotEnableAllocationDecider.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/SearchableSnapshotEnableAllocationDecider.java @@ -17,7 +17,7 @@ import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; -public class SearchableSnapshotEnableAllocationDecider extends AllocationDecider { +public class SearchableSnapshotEnableAllocationDecider implements AllocationDecider.ShardToNode, AllocationDecider.ShardToCluster { static final String NAME = "searchable_snapshots_enable"; diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/SearchableSnapshotRepositoryExistsAllocationDecider.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/SearchableSnapshotRepositoryExistsAllocationDecider.java index e90f38295c1ae..3753415260a1a 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/SearchableSnapshotRepositoryExistsAllocationDecider.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/SearchableSnapshotRepositoryExistsAllocationDecider.java @@ -23,7 +23,11 @@ import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots.SNAPSHOT_REPOSITORY_NAME_SETTING; import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots.SNAPSHOT_REPOSITORY_UUID_SETTING; -public class SearchableSnapshotRepositoryExistsAllocationDecider extends AllocationDecider { +public class SearchableSnapshotRepositoryExistsAllocationDecider + implements + AllocationDecider.ShardToNode, + AllocationDecider.ShardToCluster, + AllocationDecider.IndexToNode { private static final String NAME = "searchable_snapshot_repository_exists"; @@ -39,21 +43,6 @@ public class SearchableSnapshotRepositoryExistsAllocationDecider extends Allocat "the repository containing the data for this index exists" ); - @Override - public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { - return allowAllocation(allocation.metadata().indexMetadata(shardRouting.index()), allocation); - } - - @Override - public Decision canAllocate(ShardRouting shardRouting, RoutingAllocation allocation) { - return allowAllocation(allocation.metadata().indexMetadata(shardRouting.index()), allocation); - } - - @Override - public Decision canAllocate(IndexMetadata indexMetadata, RoutingNode node, RoutingAllocation allocation) { - return allowAllocation(indexMetadata, allocation); - } - private static Decision allowAllocation(IndexMetadata indexMetadata, RoutingAllocation allocation) { if (indexMetadata.isSearchableSnapshot()) { final Settings settings = indexMetadata.getSettings(); @@ -97,4 +86,19 @@ private static Decision allowAllocation(IndexMetadata indexMetadata, RoutingAllo return YES_INAPPLICABLE; } } + + @Override + public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { + return allowAllocation(allocation.metadata().indexMetadata(shardRouting.index()), allocation); + } + + @Override + public Decision canAllocate(ShardRouting shardRouting, RoutingAllocation allocation) { + return allowAllocation(allocation.metadata().indexMetadata(shardRouting.index()), allocation); + } + + @Override + public Decision canAllocate(IndexMetadata indexMetadata, RoutingNode node, RoutingAllocation allocation) { + return allowAllocation(indexMetadata, allocation); + } } diff --git a/x-pack/plugin/shutdown/src/test/java/org/elasticsearch/xpack/shutdown/TransportGetShutdownStatusActionTests.java b/x-pack/plugin/shutdown/src/test/java/org/elasticsearch/xpack/shutdown/TransportGetShutdownStatusActionTests.java index c8f1d8b58a490..bedc051ad9087 100644 --- a/x-pack/plugin/shutdown/src/test/java/org/elasticsearch/xpack/shutdown/TransportGetShutdownStatusActionTests.java +++ b/x-pack/plugin/shutdown/src/test/java/org/elasticsearch/xpack/shutdown/TransportGetShutdownStatusActionTests.java @@ -31,9 +31,9 @@ import org.elasticsearch.cluster.routing.allocation.Explanations; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator; -import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.routing.allocation.decider.Decision; +import org.elasticsearch.cluster.routing.allocation.decider.DefaultAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.NodeReplacementAllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.NodeShutdownAllocationDecider; import org.elasticsearch.common.settings.Settings; @@ -106,7 +106,7 @@ private void setup() { clusterInfoService = EmptyClusterInfoService.INSTANCE; allocationDeciders = new AllocationDeciders( - List.of(new NodeShutdownAllocationDecider(), new NodeReplacementAllocationDecider(), new AllocationDecider() { + List.of(new NodeShutdownAllocationDecider(), new NodeReplacementAllocationDecider(), new DefaultAllocationDecider() { @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { return canAllocate.get().test(shardRouting, node, allocation);