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 9231dfb744a36..eb4db6c24507d 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 @@ -95,21 +95,18 @@ public static Decision shouldFilter( ); if (tier.isPresent()) { String tierName = tier.get(); - if (allocationAllowed(tierName, node)) { - if (allocation.debugDecision()) { - return debugYesAllowed(allocation, tierPreference, tierName); - } - return Decision.YES; + assert Strings.hasText(tierName) : "tierName must be not null and non-empty, but was [" + tierName + "]"; + if (node.hasRole(DiscoveryNodeRole.DATA_ROLE.roleName())) { + return allocation.debugDecision() + ? debugYesAllowed(allocation, tierPreference, DiscoveryNodeRole.DATA_ROLE.roleName()) + : Decision.YES; } - if (allocation.debugDecision()) { - return debugNoRequirementsNotMet(allocation, tierPreference, tierName); + if (node.hasRole(tierName)) { + return allocation.debugDecision() ? debugYesAllowed(allocation, tierPreference, tierName) : Decision.YES; } - return Decision.NO; + return allocation.debugDecision() ? debugNoRequirementsNotMet(allocation, tierPreference, tierName) : Decision.NO; } - if (allocation.debugDecision()) { - return debugNoNoNodesAvailable(allocation, tierPreference); - } - return Decision.NO; + return allocation.debugDecision() ? debugNoNoNodesAvailable(allocation, tierPreference) : Decision.NO; } private static Decision debugNoNoNodesAvailable(RoutingAllocation allocation, List tierPreference) { @@ -278,11 +275,6 @@ static boolean tierNodesPresentConsideringRemovals(String singleTier, DiscoveryN return false; } - public static boolean allocationAllowed(String tierName, DiscoveryNode node) { - assert Strings.hasText(tierName) : "tierName must be not null and non-empty, but was [" + tierName + "]"; - return node.hasRole(DiscoveryNodeRole.DATA_ROLE.roleName()) || node.hasRole(tierName); - } - public static boolean allocationAllowed(String tierName, Set roles) { assert Strings.hasText(tierName) : "tierName must be not null and non-empty, but was [" + tierName + "]"; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDeciderTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDeciderTests.java index 7134ceba475fe..7ed57ca93adf0 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDeciderTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDeciderTests.java @@ -202,7 +202,16 @@ public void testIndexPrefer() { ) ); } + } + { + final var state = clusterStateWithIndexAndNodes("data_warm", DiscoveryNodes.builder().add(DATA_NODE).build(), null); + assertAllocationDecision( + state, + DATA_NODE, + Decision.Type.YES, + "index has a preference for tiers [data_warm] and node has tier [data]" + ); } }