From e4a974621346bf0b0c9f82e5ab4aec1517eeab7f Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 30 Mar 2021 18:19:44 -0400 Subject: [PATCH 01/22] Move data tier roles to server This commit moves the data tier roles to server. It is no longer necessary to separate these roles from server as we no longer build distributions that would not contain these roles. Moving these roles will simplify many things. This is deliberately the smallest possible commit that moves these roles. Other aspects related to the data tiers can move in separate, also small, commits. --- .../cluster/node/DiscoveryNode.java | 9 -- .../cluster/node/DiscoveryNodeRole.java | 130 ++++++++++++++++-- .../env/NodeRepurposeCommand.java | 4 +- .../indices/recovery/RecoverySettings.java | 3 +- .../storage/ReactiveStorageIT.java | 4 +- .../ProactiveStorageDeciderService.java | 3 +- .../ReactiveStorageDeciderService.java | 11 +- .../ReactiveStorageDeciderDecisionTests.java | 16 +-- .../ReactiveStorageDeciderServiceTests.java | 3 +- .../elasticsearch/xpack/core/DataTier.java | 116 +--------------- .../elasticsearch/xpack/core/XPackPlugin.java | 10 -- .../DataTierAllocationDeciderTests.java | 8 +- .../xpack/core/DataTierTests.java | 48 +++---- .../DataTiersUsageTransportActionTests.java | 8 +- .../ilm/DataTierMigrationRoutedStepTests.java | 18 +-- .../xpack/ilm/DataTiersMigrationsTests.java | 8 +- .../cache/shared/FrozenCacheServiceTests.java | 6 +- 17 files changed, 194 insertions(+), 211 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java index 648fd71158100..93cba93c71b1d 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -70,15 +70,6 @@ public static boolean isDataNode(final Settings settings) { return getRolesFromSettings(settings).stream().anyMatch(DiscoveryNodeRole::canContainData); } - /** - * Allows determining the "data" property without the need to load plugins, but does this purely based on - * naming conventions. Prefer using {@link #isDataNode(Settings)} if possible. - */ - public static boolean isDataNodeBasedOnNamingConvention(final Settings settings) { - return DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE) || - settings.getAsList("node.roles").stream().anyMatch(DiscoveryNodeRole::isDataRoleBasedOnNamingConvention); - } - public static boolean isIngestNode(final Settings settings) { return hasRole(settings, DiscoveryNodeRole.INGEST_ROLE); } diff --git a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeRole.java b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeRole.java index cc9fd6cc79a6d..973504383e7d7 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeRole.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeRole.java @@ -68,8 +68,6 @@ protected DiscoveryNodeRole(final String roleName, final String roleNameAbbrevia protected DiscoveryNodeRole(final String roleName, final String roleNameAbbreviation, final boolean canContainData) { this(true, roleName, roleNameAbbreviation, canContainData); - assert canContainData == isDataRoleBasedOnNamingConvention(roleName) : - "Role '" + roleName + "' not compliant to data role naming convention"; } private DiscoveryNodeRole( @@ -130,13 +128,115 @@ public Setting legacySetting() { }; - /** - * Allows determining the "data" property without the need to load plugins, but does this purely based on - * naming conventions. - */ - static boolean isDataRoleBasedOnNamingConvention(String role) { - return role.equals("data") || role.startsWith("data_"); - } + public static DiscoveryNodeRole DATA_CONTENT_NODE_ROLE = new DiscoveryNodeRole("data_content", "s", true) { + + @Override + public boolean isEnabledByDefault(final Settings settings) { + return DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE); + } + + @Override + public Setting legacySetting() { + // we do not register these settings, they're not intended to be used externally, only for proper defaults + return Setting.boolSetting( + "node.data_content", + settings -> + // Don't use DiscoveryNode#isDataNode(Settings) here, as it is called before all plugins are initialized + Boolean.toString(DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE)), + Property.Deprecated, + Property.NodeScope + ); + } + + }; + + public static DiscoveryNodeRole DATA_HOT_NODE_ROLE = new DiscoveryNodeRole("data_hot", "h", true) { + + @Override + public boolean isEnabledByDefault(final Settings settings) { + return DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE); + } + + @Override + public Setting legacySetting() { + // we do not register these settings, they're not intended to be used externally, only for proper defaults + return Setting.boolSetting( + "node.data_hot", + settings -> + // Don't use DiscoveryNode#isDataNode(Settings) here, as it is called before all plugins are initialized + Boolean.toString(DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE)), + Property.Deprecated, + Property.NodeScope + ); + } + + }; + + + public static DiscoveryNodeRole DATA_WARM_NODE_ROLE = new DiscoveryNodeRole("data_warm", "w", true) { + + @Override + public boolean isEnabledByDefault(final Settings settings) { + return DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE); + } + + @Override + public Setting legacySetting() { + // we do not register these settings, they're not intended to be used externally, only for proper defaults + return Setting.boolSetting( + "node.data_warm", + settings -> + // Don't use DiscoveryNode#isDataNode(Settings) here, as it is called before all plugins are initialized + Boolean.toString(DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE)), + Property.Deprecated, + Property.NodeScope + ); + } + + }; + public static DiscoveryNodeRole DATA_COLD_NODE_ROLE = new DiscoveryNodeRole("data_cold", "c", true) { + + @Override + public boolean isEnabledByDefault(final Settings settings) { + return DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE); + } + + @Override + public Setting legacySetting() { + // we do not register these settings, they're not intended to be used externally, only for proper defaults + return Setting.boolSetting( + "node.data_cold", + settings -> + // Don't use DiscoveryNode#isDataNode(Settings) here, as it is called before all plugins are initialized + Boolean.toString(DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE)), + Property.Deprecated, + Property.NodeScope + ); + } + + }; + + public static DiscoveryNodeRole DATA_FROZEN_NODE_ROLE = new DiscoveryNodeRole("data_frozen", "f", true) { + + @Override + public boolean isEnabledByDefault(final Settings settings) { + return DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE); + } + + @Override + public Setting legacySetting() { + // we do not register these settings, they're not intended to be used externally, only for proper defaults + return Setting.boolSetting( + "node.data_frozen", + settings -> + // Don't use DiscoveryNode#isDataNode(Settings) here, as it is called before all plugins are initialized + Boolean.toString(DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE)), + Property.Deprecated, + Property.NodeScope + ); + } + + }; /** * Represents the role for an ingest node. @@ -178,7 +278,17 @@ public Setting legacySetting() { * The built-in node roles. */ public static final SortedSet BUILT_IN_ROLES = - Set.of(DATA_ROLE, INGEST_ROLE, MASTER_ROLE, REMOTE_CLUSTER_CLIENT_ROLE).stream().collect(Sets.toUnmodifiableSortedSet()); + Set.of( + DATA_ROLE, + INGEST_ROLE, + MASTER_ROLE, + REMOTE_CLUSTER_CLIENT_ROLE, + DATA_CONTENT_NODE_ROLE, + DATA_HOT_NODE_ROLE, + DATA_WARM_NODE_ROLE, + DATA_COLD_NODE_ROLE, + DATA_FROZEN_NODE_ROLE + ).stream().collect(Sets.toUnmodifiableSortedSet()); /** * Represents an unknown role. This can occur if a newer version adds a role that an older version does not know about, or a newer diff --git a/server/src/main/java/org/elasticsearch/env/NodeRepurposeCommand.java b/server/src/main/java/org/elasticsearch/env/NodeRepurposeCommand.java index 740319ab595ea..dc169cf1edd69 100644 --- a/server/src/main/java/org/elasticsearch/env/NodeRepurposeCommand.java +++ b/server/src/main/java/org/elasticsearch/env/NodeRepurposeCommand.java @@ -54,7 +54,7 @@ void testExecute(Terminal terminal, OptionSet options, Environment env) throws E @Override protected boolean validateBeforeLock(Terminal terminal, Environment env) { Settings settings = env.settings(); - if (DiscoveryNode.isDataNodeBasedOnNamingConvention(settings)) { + if (DiscoveryNode.isDataNode(settings)) { terminal.println(Terminal.Verbosity.NORMAL, NO_CLEANUP); return false; } @@ -64,7 +64,7 @@ protected boolean validateBeforeLock(Terminal terminal, Environment env) { @Override protected void processNodePaths(Terminal terminal, Path[] dataPaths, OptionSet options, Environment env) throws IOException { - assert DiscoveryNode.isDataNodeBasedOnNamingConvention(env.settings()) == false; + assert DiscoveryNode.isDataNode(env.settings()) == false; if (DiscoveryNode.isMasterNode(env.settings()) == false) { processNoMasterNoDataNode(terminal, dataPaths, env); diff --git a/server/src/main/java/org/elasticsearch/indices/recovery/RecoverySettings.java b/server/src/main/java/org/elasticsearch/indices/recovery/RecoverySettings.java index 24ecb532e2339..47ad2f75beafa 100644 --- a/server/src/main/java/org/elasticsearch/indices/recovery/RecoverySettings.java +++ b/server/src/main/java/org/elasticsearch/indices/recovery/RecoverySettings.java @@ -43,7 +43,8 @@ public class RecoverySettings { // if the node is not a data node, this value doesn't matter, use the default return defaultMaxBytesPerSec.getStringRep(); } - if (dataRoles.stream().allMatch(dn -> dn.roleName().equals("data_cold") || dn.roleName().equals("data_frozen")) == false) { + if (dataRoles.stream().allMatch(dn -> dn.equals(DiscoveryNodeRole.DATA_COLD_NODE_ROLE) + || dn.equals(DiscoveryNodeRole.DATA_FROZEN_NODE_ROLE)) == false) { // the node is not a dedicated cold and/or frozen node, use the default return defaultMaxBytesPerSec.getStringRep(); } diff --git a/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageIT.java b/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageIT.java index abf7cd88e935a..ea1a0427103ac 100644 --- a/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageIT.java +++ b/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageIT.java @@ -109,7 +109,7 @@ public void testScaleFromEmptyWarmUnassigned() throws Exception { private void testScaleFromEmptyWarm(boolean allocatable) throws Exception { internalCluster().startMasterOnlyNode(); - internalCluster().startNode(NodeRoles.onlyRole(DataTier.DATA_HOT_NODE_ROLE)); + internalCluster().startNode(NodeRoles.onlyRole(DiscoveryNodeRole.DATA_HOT_NODE_ROLE)); putAutoscalingPolicy("hot", DataTier.DATA_HOT); putAutoscalingPolicy("warm", DataTier.DATA_WARM); @@ -152,7 +152,7 @@ public void testScaleFromEmptyLegacy() { internalCluster().startNode( NodeRoles.onlyRole( Settings.builder().put(Node.NODE_ATTRIBUTES.getKey() + "data_tier", "hot").build(), - DataTier.DATA_HOT_NODE_ROLE + DiscoveryNodeRole.DATA_HOT_NODE_ROLE ) ); putAutoscalingPolicy("hot", DataTier.DATA_HOT); diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/storage/ProactiveStorageDeciderService.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/storage/ProactiveStorageDeciderService.java index 6ec41a23d4443..865e20df8269a 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/storage/ProactiveStorageDeciderService.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/storage/ProactiveStorageDeciderService.java @@ -22,7 +22,6 @@ import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderResult; import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderService; import org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider; -import org.elasticsearch.xpack.core.DataTier; import java.io.IOException; import java.util.List; @@ -49,7 +48,7 @@ public String name() { @Override public List roles() { - return List.of(DiscoveryNodeRole.DATA_ROLE, DataTier.DATA_HOT_NODE_ROLE); + return List.of(DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.DATA_HOT_NODE_ROLE); } @Override diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderService.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderService.java index 371b2bfafc529..726f2b6a62764 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderService.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderService.java @@ -45,7 +45,6 @@ import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderResult; import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderService; import org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider; -import org.elasticsearch.xpack.core.DataTier; import java.io.IOException; import java.math.BigInteger; @@ -88,11 +87,11 @@ public List> deciderSettings() { public List roles() { return List.of( DiscoveryNodeRole.DATA_ROLE, - DataTier.DATA_CONTENT_NODE_ROLE, - DataTier.DATA_HOT_NODE_ROLE, - DataTier.DATA_WARM_NODE_ROLE, - DataTier.DATA_COLD_NODE_ROLE, - DataTier.DATA_FROZEN_NODE_ROLE + DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE, + DiscoveryNodeRole.DATA_HOT_NODE_ROLE, + DiscoveryNodeRole.DATA_WARM_NODE_ROLE, + DiscoveryNodeRole.DATA_COLD_NODE_ROLE, + DiscoveryNodeRole.DATA_FROZEN_NODE_ROLE ); } 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 071b4b3bf28bd..afa347998d00b 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 @@ -65,8 +65,8 @@ import java.util.stream.Stream; import java.util.stream.StreamSupport; -import static org.elasticsearch.xpack.core.DataTier.DATA_HOT_NODE_ROLE; -import static org.elasticsearch.xpack.core.DataTier.DATA_WARM_NODE_ROLE; +import static org.elasticsearch.cluster.node.DiscoveryNodeRole.DATA_HOT_NODE_ROLE; +import static org.elasticsearch.cluster.node.DiscoveryNodeRole.DATA_WARM_NODE_ROLE; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; @@ -132,7 +132,7 @@ public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAl @Before public void setup() { DiscoveryNode.setAdditionalRoles( - Set.of(DataTier.DATA_CONTENT_NODE_ROLE, DataTier.DATA_HOT_NODE_ROLE, DataTier.DATA_WARM_NODE_ROLE, DataTier.DATA_COLD_NODE_ROLE) + Set.of(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE, DiscoveryNodeRole.DATA_HOT_NODE_ROLE, DiscoveryNodeRole.DATA_WARM_NODE_ROLE, DiscoveryNodeRole.DATA_COLD_NODE_ROLE) ); ClusterState state = ClusterState.builder(new ClusterName("test")).build(); state = addRandomIndices(hotNodes, hotNodes, state); @@ -165,9 +165,9 @@ public void testStoragePreventsAllocation() { moveToCold(allIndices()), ReactiveStorageDeciderService.AllocationState::storagePreventsAllocation, state.getRoutingNodes().unassigned().size(), - DataTier.DATA_COLD_NODE_ROLE + DiscoveryNodeRole.DATA_COLD_NODE_ROLE ); - verify(ReactiveStorageDeciderService.AllocationState::storagePreventsAllocation, 0, DataTier.DATA_COLD_NODE_ROLE); + verify(ReactiveStorageDeciderService.AllocationState::storagePreventsAllocation, 0, DiscoveryNodeRole.DATA_COLD_NODE_ROLE); if (numPrevents > 0) { verifyScale(numPrevents, "not enough storage available, needs " + numPrevents + "b", mockCanAllocateDiskDecider); } else { @@ -267,7 +267,7 @@ public void testMoveToEmpty() { .forEach(shard -> allocation.routingNodes().startShard(logger, shard, allocation.changes())) ); - verify(ReactiveStorageDeciderService.AllocationState::storagePreventsRemainOrMove, 0, DataTier.DATA_COLD_NODE_ROLE); + verify(ReactiveStorageDeciderService.AllocationState::storagePreventsRemainOrMove, 0, DiscoveryNodeRole.DATA_COLD_NODE_ROLE); Set candidates = new HashSet<>(randomSubsetOf(allIndices())); int allocatedCandidateShards = candidates.stream().mapToInt(IndexMetadata::getNumberOfShards).sum(); @@ -276,7 +276,7 @@ public void testMoveToEmpty() { moveToCold(candidates), ReactiveStorageDeciderService.AllocationState::storagePreventsRemainOrMove, allocatedCandidateShards, - DataTier.DATA_COLD_NODE_ROLE + DiscoveryNodeRole.DATA_COLD_NODE_ROLE ); } @@ -397,7 +397,7 @@ private static void verifyScale(ClusterState state, long expectedDifference, Str new ClusterSettings(Settings.EMPTY, DataTierAllocationDeciderTests.ALL_SETTINGS), createAllocationDeciders(allocationDeciders) ); - TestAutoscalingDeciderContext context = createContext(state, Set.of(DataTier.DATA_HOT_NODE_ROLE)); + TestAutoscalingDeciderContext context = createContext(state, Set.of(DiscoveryNodeRole.DATA_HOT_NODE_ROLE)); AutoscalingDeciderResult result = decider.scale(Settings.EMPTY, context); if (context.currentCapacity != null) { assertThat( 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 4bb4f2b8371e4..76f5fed0753b2 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 @@ -51,7 +51,6 @@ import org.elasticsearch.xpack.autoscaling.AutoscalingTestCase; import org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider; import org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDeciderTests; -import org.elasticsearch.xpack.core.DataTier; import java.util.Arrays; import java.util.Collection; @@ -434,7 +433,7 @@ public boolean canRemainWithNoNodes(ClusterState clusterState, ShardRouting shar ClusterInfo.EMPTY, null, Set.of(), - Set.of(DataTier.DATA_WARM_NODE_ROLE) + Set.of(DiscoveryNodeRole.DATA_WARM_NODE_ROLE) ); RoutingAllocation allocation = new RoutingAllocation( diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/DataTier.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/DataTier.java index efe34f777b937..eade572e2f9d2 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/DataTier.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/DataTier.java @@ -12,7 +12,6 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; -import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.shard.IndexSettingProvider; import org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider; @@ -69,125 +68,20 @@ public static boolean isExplicitDataTier(Settings settings) { return false; } - public static DiscoveryNodeRole DATA_CONTENT_NODE_ROLE = new DiscoveryNodeRole("data_content", "s", true) { - @Override - public boolean isEnabledByDefault(final Settings settings) { - return DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE); - } - - @Override - public Setting legacySetting() { - // we do not register these settings, they're not intended to be used externally, only for proper defaults - return Setting.boolSetting( - "node.data_content", - settings -> - // Don't use DiscoveryNode#isDataNode(Settings) here, as it is called before all plugins are initialized - Boolean.toString(DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE)), - Setting.Property.Deprecated, - Setting.Property.NodeScope - ); - } - - }; - - public static DiscoveryNodeRole DATA_HOT_NODE_ROLE = new DiscoveryNodeRole("data_hot", "h", true) { - @Override - public boolean isEnabledByDefault(final Settings settings) { - return DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE); - } - - @Override - public Setting legacySetting() { - // we do not register these settings, they're not intended to be used externally, only for proper defaults - return Setting.boolSetting( - "node.data_hot", - settings -> - // Don't use DiscoveryNode#isDataNode(Settings) here, as it is called before all plugins are initialized - Boolean.toString(DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE)), - Setting.Property.Deprecated, - Setting.Property.NodeScope - ); - } - - }; - - public static DiscoveryNodeRole DATA_WARM_NODE_ROLE = new DiscoveryNodeRole("data_warm", "w", true) { - @Override - public boolean isEnabledByDefault(final Settings settings) { - return DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE); - } - - @Override - public Setting legacySetting() { - // we do not register these settings, they're not intended to be used externally, only for proper defaults - return Setting.boolSetting( - "node.data_warm", - settings -> - // Don't use DiscoveryNode#isDataNode(Settings) here, as it is called before all plugins are initialized - Boolean.toString(DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE)), - Setting.Property.Deprecated, - Setting.Property.NodeScope - ); - } - - }; - - public static DiscoveryNodeRole DATA_COLD_NODE_ROLE = new DiscoveryNodeRole("data_cold", "c", true) { - @Override - public boolean isEnabledByDefault(final Settings settings) { - return DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE); - } - - @Override - public Setting legacySetting() { - // we do not register these settings, they're not intended to be used externally, only for proper defaults - return Setting.boolSetting( - "node.data_cold", - settings -> - // Don't use DiscoveryNode#isDataNode(Settings) here, as it is called before all plugins are initialized - Boolean.toString(DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE)), - Setting.Property.Deprecated, - Setting.Property.NodeScope - ); - } - - }; - - public static DiscoveryNodeRole DATA_FROZEN_NODE_ROLE = new DiscoveryNodeRole("data_frozen", "f", true) { - @Override - public boolean isEnabledByDefault(final Settings settings) { - return DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE); - } - - @Override - public Setting legacySetting() { - // we do not register these settings, they're not intended to be used externally, only for proper defaults - return Setting.boolSetting( - "node.data_frozen", - settings -> - // Don't use DiscoveryNode#isDataNode(Settings) here, as it is called before all plugins are initialized - Boolean.toString(DiscoveryNode.hasRole(settings, DiscoveryNodeRole.DATA_ROLE)), - Setting.Property.Deprecated, - Setting.Property.NodeScope - ); - } - - }; - public static boolean isContentNode(DiscoveryNode discoveryNode) { - return discoveryNode.getRoles().contains(DATA_CONTENT_NODE_ROLE) || discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_ROLE); + return discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE) || discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_ROLE); } public static boolean isHotNode(DiscoveryNode discoveryNode) { - return discoveryNode.getRoles().contains(DATA_HOT_NODE_ROLE) || discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_ROLE); + return discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_HOT_NODE_ROLE) || discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_ROLE); } public static boolean isWarmNode(DiscoveryNode discoveryNode) { - return discoveryNode.getRoles().contains(DATA_WARM_NODE_ROLE) || discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_ROLE); + return discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_WARM_NODE_ROLE) || discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_ROLE); } public static boolean isColdNode(DiscoveryNode discoveryNode) { - return discoveryNode.getRoles().contains(DATA_COLD_NODE_ROLE) || discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_ROLE); + return discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_COLD_NODE_ROLE) || discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_ROLE); } public static boolean isFrozenNode(DiscoveryNode discoveryNode) { @@ -195,7 +89,7 @@ public static boolean isFrozenNode(DiscoveryNode discoveryNode) { } public static boolean isFrozenNode(final Set roles) { - return roles.contains(DATA_FROZEN_NODE_ROLE) || roles.contains(DiscoveryNodeRole.DATA_ROLE); + return roles.contains(DiscoveryNodeRole.DATA_FROZEN_NODE_ROLE) || roles.contains(DiscoveryNodeRole.DATA_ROLE); } /** diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java index 7483665806de6..73861da34fec7 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java @@ -377,16 +377,6 @@ public List> getSettings() { return settings; } - @Override - public Set getRoles() { - return new HashSet<>(Arrays.asList( - DataTier.DATA_CONTENT_NODE_ROLE, - DataTier.DATA_HOT_NODE_ROLE, - DataTier.DATA_WARM_NODE_ROLE, - DataTier.DATA_COLD_NODE_ROLE, - DataTier.DATA_FROZEN_NODE_ROLE)); - } - @Override public Collection createAllocationDeciders(Settings settings, ClusterSettings clusterSettings) { return Collections.singleton(new DataTierAllocationDecider(settings, clusterSettings)); 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 a45a74c08ed20..8535b6a23c840 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 @@ -54,10 +54,10 @@ public class DataTierAllocationDeciderTests extends ESAllocationTestCase { public static final Set> ALL_SETTINGS; - private static final DiscoveryNode HOT_NODE = newNode("node-hot", Collections.singleton(DataTier.DATA_HOT_NODE_ROLE)); - private static final DiscoveryNode WARM_NODE = newNode("node-warm", Collections.singleton(DataTier.DATA_WARM_NODE_ROLE)); - private static final DiscoveryNode COLD_NODE = newNode("node-cold", Collections.singleton(DataTier.DATA_COLD_NODE_ROLE)); - private static final DiscoveryNode CONTENT_NODE = newNode("node-content", Collections.singleton(DataTier.DATA_CONTENT_NODE_ROLE)); + private static final DiscoveryNode HOT_NODE = newNode("node-hot", Collections.singleton(DiscoveryNodeRole.DATA_HOT_NODE_ROLE)); + private static final DiscoveryNode WARM_NODE = newNode("node-warm", Collections.singleton(DiscoveryNodeRole.DATA_WARM_NODE_ROLE)); + private static final DiscoveryNode COLD_NODE = newNode("node-cold", Collections.singleton(DiscoveryNodeRole.DATA_COLD_NODE_ROLE)); + private static final DiscoveryNode CONTENT_NODE = newNode("node-content", Collections.singleton(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE)); private static final DiscoveryNode DATA_NODE = newNode("node-data", Collections.singleton(DiscoveryNodeRole.DATA_ROLE)); private final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ALL_SETTINGS); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTierTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTierTests.java index 46f9a16030e46..6b60c7769b7cc 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTierTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTierTests.java @@ -87,50 +87,50 @@ public void testNodeSelection() { public void testDefaultRolesImpliesTieredDataRoles() { DiscoveryNode.setAdditionalRoles( - Set.of(DataTier.DATA_CONTENT_NODE_ROLE, DataTier.DATA_HOT_NODE_ROLE, DataTier.DATA_WARM_NODE_ROLE, DataTier.DATA_COLD_NODE_ROLE) + Set.of(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE, DiscoveryNodeRole.DATA_HOT_NODE_ROLE, DiscoveryNodeRole.DATA_WARM_NODE_ROLE, DiscoveryNodeRole.DATA_COLD_NODE_ROLE) ); final DiscoveryNode node = DiscoveryNode.createLocal(Settings.EMPTY, buildNewFakeTransportAddress(), randomAlphaOfLength(8)); - assertThat(node.getRoles(), hasItem(DataTier.DATA_CONTENT_NODE_ROLE)); - assertThat(node.getRoles(), hasItem(DataTier.DATA_HOT_NODE_ROLE)); - assertThat(node.getRoles(), hasItem(DataTier.DATA_WARM_NODE_ROLE)); - assertThat(node.getRoles(), hasItem(DataTier.DATA_COLD_NODE_ROLE)); + assertThat(node.getRoles(), hasItem(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE)); + assertThat(node.getRoles(), hasItem(DiscoveryNodeRole.DATA_HOT_NODE_ROLE)); + assertThat(node.getRoles(), hasItem(DiscoveryNodeRole.DATA_WARM_NODE_ROLE)); + assertThat(node.getRoles(), hasItem(DiscoveryNodeRole.DATA_COLD_NODE_ROLE)); } public void testDataRoleDoesNotImplyTieredDataRoles() { DiscoveryNode.setAdditionalRoles( - Set.of(DataTier.DATA_CONTENT_NODE_ROLE, DataTier.DATA_HOT_NODE_ROLE, DataTier.DATA_WARM_NODE_ROLE, DataTier.DATA_COLD_NODE_ROLE) + Set.of(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE, DiscoveryNodeRole.DATA_HOT_NODE_ROLE, DiscoveryNodeRole.DATA_WARM_NODE_ROLE, DiscoveryNodeRole.DATA_COLD_NODE_ROLE) ); final Settings settings = Settings.builder().put(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), "data").build(); final DiscoveryNode node = DiscoveryNode.createLocal(settings, buildNewFakeTransportAddress(), randomAlphaOfLength(8)); - assertThat(node.getRoles(), not(hasItem(DataTier.DATA_CONTENT_NODE_ROLE))); - assertThat(node.getRoles(), not(hasItem(DataTier.DATA_HOT_NODE_ROLE))); - assertThat(node.getRoles(), not(hasItem(DataTier.DATA_WARM_NODE_ROLE))); - assertThat(node.getRoles(), not(hasItem(DataTier.DATA_COLD_NODE_ROLE))); + assertThat(node.getRoles(), not(hasItem(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE))); + assertThat(node.getRoles(), not(hasItem(DiscoveryNodeRole.DATA_HOT_NODE_ROLE))); + assertThat(node.getRoles(), not(hasItem(DiscoveryNodeRole.DATA_WARM_NODE_ROLE))); + assertThat(node.getRoles(), not(hasItem(DiscoveryNodeRole.DATA_COLD_NODE_ROLE))); } public void testLegacyDataRoleImpliesTieredDataRoles() { DiscoveryNode.setAdditionalRoles( - Set.of(DataTier.DATA_CONTENT_NODE_ROLE, DataTier.DATA_HOT_NODE_ROLE, DataTier.DATA_WARM_NODE_ROLE, DataTier.DATA_COLD_NODE_ROLE) + Set.of(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE, DiscoveryNodeRole.DATA_HOT_NODE_ROLE, DiscoveryNodeRole.DATA_WARM_NODE_ROLE, DiscoveryNodeRole.DATA_COLD_NODE_ROLE) ); final Settings settings = Settings.builder().put(DiscoveryNodeRole.DATA_ROLE.legacySetting().getKey(), true).build(); final DiscoveryNode node = DiscoveryNode.createLocal(settings, buildNewFakeTransportAddress(), randomAlphaOfLength(8)); - assertThat(node.getRoles(), hasItem(DataTier.DATA_CONTENT_NODE_ROLE)); - assertThat(node.getRoles(), hasItem(DataTier.DATA_HOT_NODE_ROLE)); - assertThat(node.getRoles(), hasItem(DataTier.DATA_WARM_NODE_ROLE)); - assertThat(node.getRoles(), hasItem(DataTier.DATA_COLD_NODE_ROLE)); + assertThat(node.getRoles(), hasItem(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE)); + assertThat(node.getRoles(), hasItem(DiscoveryNodeRole.DATA_HOT_NODE_ROLE)); + assertThat(node.getRoles(), hasItem(DiscoveryNodeRole.DATA_WARM_NODE_ROLE)); + assertThat(node.getRoles(), hasItem(DiscoveryNodeRole.DATA_COLD_NODE_ROLE)); assertSettingDeprecationsAndWarnings(new Setting[]{DiscoveryNodeRole.DATA_ROLE.legacySetting()}); } public void testDisablingLegacyDataRoleDisablesTieredDataRoles() { DiscoveryNode.setAdditionalRoles( - Set.of(DataTier.DATA_CONTENT_NODE_ROLE, DataTier.DATA_HOT_NODE_ROLE, DataTier.DATA_WARM_NODE_ROLE, DataTier.DATA_COLD_NODE_ROLE) + Set.of(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE, DiscoveryNodeRole.DATA_HOT_NODE_ROLE, DiscoveryNodeRole.DATA_WARM_NODE_ROLE, DiscoveryNodeRole.DATA_COLD_NODE_ROLE) ); final Settings settings = Settings.builder().put(DiscoveryNodeRole.DATA_ROLE.legacySetting().getKey(), false).build(); final DiscoveryNode node = DiscoveryNode.createLocal(settings, buildNewFakeTransportAddress(), randomAlphaOfLength(8)); - assertThat(node.getRoles(), not(hasItem(DataTier.DATA_CONTENT_NODE_ROLE))); - assertThat(node.getRoles(), not(hasItem(DataTier.DATA_HOT_NODE_ROLE))); - assertThat(node.getRoles(), not(hasItem(DataTier.DATA_WARM_NODE_ROLE))); - assertThat(node.getRoles(), not(hasItem(DataTier.DATA_COLD_NODE_ROLE))); + assertThat(node.getRoles(), not(hasItem(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE))); + assertThat(node.getRoles(), not(hasItem(DiscoveryNodeRole.DATA_HOT_NODE_ROLE))); + assertThat(node.getRoles(), not(hasItem(DiscoveryNodeRole.DATA_WARM_NODE_ROLE))); + assertThat(node.getRoles(), not(hasItem(DiscoveryNodeRole.DATA_COLD_NODE_ROLE))); assertSettingDeprecationsAndWarnings(new Setting[]{DiscoveryNodeRole.DATA_ROLE.legacySetting()}); } @@ -154,10 +154,10 @@ private static DiscoveryNode newNode(int nodeId, Map attributes, private static List randomNodes(final int numNodes) { Set allRoles = new HashSet<>(DiscoveryNodeRole.BUILT_IN_ROLES); allRoles.remove(DiscoveryNodeRole.DATA_ROLE); - allRoles.add(DataTier.DATA_CONTENT_NODE_ROLE); - allRoles.add(DataTier.DATA_HOT_NODE_ROLE); - allRoles.add(DataTier.DATA_WARM_NODE_ROLE); - allRoles.add(DataTier.DATA_COLD_NODE_ROLE); + allRoles.add(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE); + allRoles.add(DiscoveryNodeRole.DATA_HOT_NODE_ROLE); + allRoles.add(DiscoveryNodeRole.DATA_WARM_NODE_ROLE); + allRoles.add(DiscoveryNodeRole.DATA_COLD_NODE_ROLE); List nodesList = new ArrayList<>(); for (int i = 0; i < numNodes; i++) { Map attributes = new HashMap<>(); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTiersUsageTransportActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTiersUsageTransportActionTests.java index 99a0dc22cdb66..9c2d45e4493aa 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTiersUsageTransportActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTiersUsageTransportActionTests.java @@ -43,10 +43,10 @@ public void testCalculateMAD() { } public void testSeparateTiers() { - NodeStats hotStats = fakeStats(DataTier.DATA_HOT_NODE_ROLE); - NodeStats coldStats = fakeStats(DataTier.DATA_COLD_NODE_ROLE); - NodeStats warmStats = fakeStats(DataTier.DATA_WARM_NODE_ROLE); - NodeStats warmStats2 = fakeStats(DataTier.DATA_WARM_NODE_ROLE); + NodeStats hotStats = fakeStats(DiscoveryNodeRole.DATA_HOT_NODE_ROLE); + NodeStats coldStats = fakeStats(DiscoveryNodeRole.DATA_COLD_NODE_ROLE); + NodeStats warmStats = fakeStats(DiscoveryNodeRole.DATA_WARM_NODE_ROLE); + NodeStats warmStats2 = fakeStats(DiscoveryNodeRole.DATA_WARM_NODE_ROLE); NodesStatsResponse nodesStats = new NodesStatsResponse(new ClusterName("cluster"), Arrays.asList(hotStats, coldStats, warmStats, warmStats2), Collections.emptyList()); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/DataTierMigrationRoutedStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/DataTierMigrationRoutedStepTests.java index d87518052629d..6c321a990c219 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/DataTierMigrationRoutedStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/DataTierMigrationRoutedStepTests.java @@ -82,7 +82,7 @@ public void testExecuteWithUnassignedShard() { ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE).metadata(Metadata.builder().put(indexMetadata, true).build()) .nodes(DiscoveryNodes.builder() - .add(newNode("node1", Collections.singleton(DataTier.DATA_HOT_NODE_ROLE))) + .add(newNode("node1", Collections.singleton(DiscoveryNodeRole.DATA_HOT_NODE_ROLE))) ) .routingTable(RoutingTable.builder().add(indexRoutingTable).build()) .build(); @@ -105,8 +105,8 @@ public void testExecuteWithPendingShards() { ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE).metadata(Metadata.builder().put(indexMetadata, true).build()) .nodes(DiscoveryNodes.builder() - .add(newNode("node1", Collections.singleton(DataTier.DATA_HOT_NODE_ROLE))) - .add(newNode("node2", Collections.singleton(DataTier.DATA_WARM_NODE_ROLE))) + .add(newNode("node1", Collections.singleton(DiscoveryNodeRole.DATA_HOT_NODE_ROLE))) + .add(newNode("node2", Collections.singleton(DiscoveryNodeRole.DATA_WARM_NODE_ROLE))) ) .routingTable(RoutingTable.builder().add(indexRoutingTable).build()) .build(); @@ -132,7 +132,7 @@ public void testExecuteWithPendingShardsAndTargetRoleNotPresentInCluster() { ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE).metadata(Metadata.builder().put(indexMetadata, true).build()) .nodes(DiscoveryNodes.builder() - .add(newNode("node1", Collections.singleton(DataTier.DATA_HOT_NODE_ROLE))) + .add(newNode("node1", Collections.singleton(DiscoveryNodeRole.DATA_HOT_NODE_ROLE))) ) .routingTable(RoutingTable.builder().add(indexRoutingTable).build()) .build(); @@ -168,8 +168,8 @@ public void testExecuteIsComplete() { ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE).metadata(Metadata.builder().put(indexMetadata, true).build()) .nodes(DiscoveryNodes.builder() - .add(newNode("node1", Collections.singleton(DataTier.DATA_HOT_NODE_ROLE))) - .add(newNode("node2", Collections.singleton(DataTier.DATA_WARM_NODE_ROLE))) + .add(newNode("node1", Collections.singleton(DiscoveryNodeRole.DATA_HOT_NODE_ROLE))) + .add(newNode("node2", Collections.singleton(DiscoveryNodeRole.DATA_WARM_NODE_ROLE))) ) .routingTable(RoutingTable.builder().add(indexRoutingTable).build()) .build(); @@ -213,7 +213,7 @@ public void testExecuteForIndexWithoutTierRoutingInformationWaitsForReplicasToBe ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE).metadata(Metadata.builder().put(indexMetadata, true).build()) .nodes(DiscoveryNodes.builder() - .add(newNode("node1", Collections.singleton(DataTier.DATA_HOT_NODE_ROLE))) + .add(newNode("node1", Collections.singleton(DiscoveryNodeRole.DATA_HOT_NODE_ROLE))) ) .routingTable(RoutingTable.builder().add(indexRoutingTable).build()) .build(); @@ -233,8 +233,8 @@ public void testExecuteForIndexWithoutTierRoutingInformationWaitsForReplicasToBe ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE).metadata(Metadata.builder().put(indexMetadata, true).build()) .nodes(DiscoveryNodes.builder() - .add(newNode("node1", Collections.singleton(DataTier.DATA_HOT_NODE_ROLE))) - .add(newNode("node2", Collections.singleton(DataTier.DATA_WARM_NODE_ROLE))) + .add(newNode("node1", Collections.singleton(DiscoveryNodeRole.DATA_HOT_NODE_ROLE))) + .add(newNode("node2", Collections.singleton(DiscoveryNodeRole.DATA_WARM_NODE_ROLE))) ) .routingTable(RoutingTable.builder().add(indexRoutingTable).build()) .build(); diff --git a/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/DataTiersMigrationsTests.java b/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/DataTiersMigrationsTests.java index 40840081d5fcc..65c8db7af6522 100644 --- a/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/DataTiersMigrationsTests.java +++ b/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/DataTiersMigrationsTests.java @@ -11,13 +11,13 @@ import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse; import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest; +import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.routing.ShardRoutingState; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider; -import org.elasticsearch.xpack.core.DataTier; import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin; import org.elasticsearch.xpack.core.XPackSettings; import org.elasticsearch.xpack.core.ilm.DataTierMigrationRoutedStep; @@ -80,15 +80,15 @@ protected Settings nodeSettings(int nodeOrdinal) { } public static Settings hotNode(final Settings settings) { - return onlyRole(settings, DataTier.DATA_HOT_NODE_ROLE); + return onlyRole(settings, DiscoveryNodeRole.DATA_HOT_NODE_ROLE); } public static Settings warmNode(final Settings settings) { - return onlyRole(settings, DataTier.DATA_WARM_NODE_ROLE); + return onlyRole(settings, DiscoveryNodeRole.DATA_WARM_NODE_ROLE); } public static Settings coldNode(final Settings settings) { - return onlyRole(settings, DataTier.DATA_COLD_NODE_ROLE); + return onlyRole(settings, DiscoveryNodeRole.DATA_COLD_NODE_ROLE); } public void testIndexDataTierMigration() throws Exception { diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheServiceTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheServiceTests.java index 7811d0ddd4e21..22d2cbd5a3f2d 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheServiceTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheServiceTests.java @@ -9,6 +9,7 @@ import org.elasticsearch.cluster.coordination.DeterministicTaskQueue; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.env.NodeEnvironment; @@ -17,7 +18,6 @@ import org.elasticsearch.node.NodeRoleSettings; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.xpack.core.DataTier; import org.elasticsearch.xpack.searchablesnapshots.cache.common.ByteRange; import org.elasticsearch.xpack.searchablesnapshots.cache.common.CacheKey; import org.elasticsearch.xpack.searchablesnapshots.cache.shared.FrozenCacheService.CacheFileRegion; @@ -198,12 +198,12 @@ public void testDecay() throws IOException { public void testCacheSizeDeprecatedOnNonFrozenNodes() { DiscoveryNode.setAdditionalRoles( - Set.of(DataTier.DATA_HOT_NODE_ROLE, DataTier.DATA_WARM_NODE_ROLE, DataTier.DATA_COLD_NODE_ROLE, DataTier.DATA_FROZEN_NODE_ROLE) + Set.of(DiscoveryNodeRole.DATA_HOT_NODE_ROLE, DiscoveryNodeRole.DATA_WARM_NODE_ROLE, DiscoveryNodeRole.DATA_COLD_NODE_ROLE, DiscoveryNodeRole.DATA_FROZEN_NODE_ROLE) ); final Settings settings = Settings.builder() .put(FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.getKey(), new ByteSizeValue(size(500)).getStringRep()) .put(FrozenCacheService.SNAPSHOT_CACHE_REGION_SIZE_SETTING.getKey(), new ByteSizeValue(size(100)).getStringRep()) - .putList(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), DataTier.DATA_HOT_NODE_ROLE.roleName()) + .putList(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), DiscoveryNodeRole.DATA_HOT_NODE_ROLE.roleName()) .build(); FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.get(settings); assertWarnings( From b546570bfba8cddbe677df124453859913cc3b2c Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 30 Mar 2021 18:31:40 -0400 Subject: [PATCH 02/22] Remove unnecessary invocations --- .../storage/ReactiveStorageDeciderDecisionTests.java | 3 --- .../org/elasticsearch/xpack/core/DataTierTests.java | 12 ------------ .../cache/shared/FrozenCacheServiceTests.java | 3 --- 3 files changed, 18 deletions(-) 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 afa347998d00b..c67970b8358ca 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 @@ -131,9 +131,6 @@ public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAl @Before public void setup() { - DiscoveryNode.setAdditionalRoles( - Set.of(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE, DiscoveryNodeRole.DATA_HOT_NODE_ROLE, DiscoveryNodeRole.DATA_WARM_NODE_ROLE, DiscoveryNodeRole.DATA_COLD_NODE_ROLE) - ); ClusterState state = ClusterState.builder(new ClusterName("test")).build(); state = addRandomIndices(hotNodes, hotNodes, state); state = addDataNodes(DATA_HOT_NODE_ROLE, "hot", state, hotNodes); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTierTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTierTests.java index 6b60c7769b7cc..3b66969208816 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTierTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTierTests.java @@ -86,9 +86,6 @@ public void testNodeSelection() { } public void testDefaultRolesImpliesTieredDataRoles() { - DiscoveryNode.setAdditionalRoles( - Set.of(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE, DiscoveryNodeRole.DATA_HOT_NODE_ROLE, DiscoveryNodeRole.DATA_WARM_NODE_ROLE, DiscoveryNodeRole.DATA_COLD_NODE_ROLE) - ); final DiscoveryNode node = DiscoveryNode.createLocal(Settings.EMPTY, buildNewFakeTransportAddress(), randomAlphaOfLength(8)); assertThat(node.getRoles(), hasItem(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE)); assertThat(node.getRoles(), hasItem(DiscoveryNodeRole.DATA_HOT_NODE_ROLE)); @@ -97,9 +94,6 @@ public void testDefaultRolesImpliesTieredDataRoles() { } public void testDataRoleDoesNotImplyTieredDataRoles() { - DiscoveryNode.setAdditionalRoles( - Set.of(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE, DiscoveryNodeRole.DATA_HOT_NODE_ROLE, DiscoveryNodeRole.DATA_WARM_NODE_ROLE, DiscoveryNodeRole.DATA_COLD_NODE_ROLE) - ); final Settings settings = Settings.builder().put(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), "data").build(); final DiscoveryNode node = DiscoveryNode.createLocal(settings, buildNewFakeTransportAddress(), randomAlphaOfLength(8)); assertThat(node.getRoles(), not(hasItem(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE))); @@ -109,9 +103,6 @@ public void testDataRoleDoesNotImplyTieredDataRoles() { } public void testLegacyDataRoleImpliesTieredDataRoles() { - DiscoveryNode.setAdditionalRoles( - Set.of(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE, DiscoveryNodeRole.DATA_HOT_NODE_ROLE, DiscoveryNodeRole.DATA_WARM_NODE_ROLE, DiscoveryNodeRole.DATA_COLD_NODE_ROLE) - ); final Settings settings = Settings.builder().put(DiscoveryNodeRole.DATA_ROLE.legacySetting().getKey(), true).build(); final DiscoveryNode node = DiscoveryNode.createLocal(settings, buildNewFakeTransportAddress(), randomAlphaOfLength(8)); assertThat(node.getRoles(), hasItem(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE)); @@ -122,9 +113,6 @@ public void testLegacyDataRoleImpliesTieredDataRoles() { } public void testDisablingLegacyDataRoleDisablesTieredDataRoles() { - DiscoveryNode.setAdditionalRoles( - Set.of(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE, DiscoveryNodeRole.DATA_HOT_NODE_ROLE, DiscoveryNodeRole.DATA_WARM_NODE_ROLE, DiscoveryNodeRole.DATA_COLD_NODE_ROLE) - ); final Settings settings = Settings.builder().put(DiscoveryNodeRole.DATA_ROLE.legacySetting().getKey(), false).build(); final DiscoveryNode node = DiscoveryNode.createLocal(settings, buildNewFakeTransportAddress(), randomAlphaOfLength(8)); assertThat(node.getRoles(), not(hasItem(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE))); diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheServiceTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheServiceTests.java index 22d2cbd5a3f2d..19272ed3b6121 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheServiceTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheServiceTests.java @@ -197,9 +197,6 @@ public void testDecay() throws IOException { } public void testCacheSizeDeprecatedOnNonFrozenNodes() { - DiscoveryNode.setAdditionalRoles( - Set.of(DiscoveryNodeRole.DATA_HOT_NODE_ROLE, DiscoveryNodeRole.DATA_WARM_NODE_ROLE, DiscoveryNodeRole.DATA_COLD_NODE_ROLE, DiscoveryNodeRole.DATA_FROZEN_NODE_ROLE) - ); final Settings settings = Settings.builder() .put(FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.getKey(), new ByteSizeValue(size(500)).getStringRep()) .put(FrozenCacheService.SNAPSHOT_CACHE_REGION_SIZE_SETTING.getKey(), new ByteSizeValue(size(100)).getStringRep()) From 0f111070010443f372272cded30336d815c91a22 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 30 Mar 2021 18:38:47 -0400 Subject: [PATCH 03/22] Fix formatting --- .../cache/shared/FrozenCacheServiceTests.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheServiceTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheServiceTests.java index 19272ed3b6121..658b36286fa3e 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheServiceTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheServiceTests.java @@ -8,7 +8,6 @@ package org.elasticsearch.xpack.searchablesnapshots.cache.shared; import org.elasticsearch.cluster.coordination.DeterministicTaskQueue; -import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; @@ -23,7 +22,6 @@ import org.elasticsearch.xpack.searchablesnapshots.cache.shared.FrozenCacheService.CacheFileRegion; import java.io.IOException; -import java.util.Set; import static org.elasticsearch.node.Node.NODE_NAME_SETTING; From fd4176bef283aa827130435ffe27df7535ddcf51 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 30 Mar 2021 20:28:03 -0400 Subject: [PATCH 04/22] Fix failing test --- .../rest-api-spec/test/nodes.info/10_basic.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/nodes.info/10_basic.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/nodes.info/10_basic.yml index ea9aa06a58d6f..5e44a4db8b19b 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/nodes.info/10_basic.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/nodes.info/10_basic.yml @@ -25,8 +25,12 @@ setup: - is_true: nodes.$node_id.roles # the roles output is sorted - - match: { nodes.$node_id.roles.0: "data" } - - match: { nodes.$node_id.roles.1: "ingest" } - - match: { nodes.$node_id.roles.2: "master" } - - match: { nodes.$node_id.roles.3: "remote_cluster_client" } - + - match: { nodes.$node_id.roles.0: "data_cold" } + - match: { nodes.$node_id.roles.1: "data_content" } + - match: { nodes.$node_id.roles.2: "data_frozen" } + - match: { nodes.$node_id.roles.3: "data_hot" } + - match: { nodes.$node_id.roles.4: "data_warm" } + - match: { nodes.$node_id.roles.5: "data" } + - match: { nodes.$node_id.roles.6: "ingest" } + - match: { nodes.$node_id.roles.7: "master" } + - match: { nodes.$node_id.roles.8: "remote_cluster_client" } From 7ee513c228b4482a85435f9e09a2f1c7b144d2db Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 30 Mar 2021 20:35:18 -0400 Subject: [PATCH 05/22] Fix checkstyle --- .../java/org/elasticsearch/xpack/core/DataTier.java | 12 ++++++++---- .../org/elasticsearch/xpack/core/XPackPlugin.java | 4 ---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/DataTier.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/DataTier.java index eade572e2f9d2..5858e8b79373d 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/DataTier.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/DataTier.java @@ -69,19 +69,23 @@ public static boolean isExplicitDataTier(Settings settings) { } public static boolean isContentNode(DiscoveryNode discoveryNode) { - return discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE) || discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_ROLE); + return discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE) + || discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_ROLE); } public static boolean isHotNode(DiscoveryNode discoveryNode) { - return discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_HOT_NODE_ROLE) || discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_ROLE); + return discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_HOT_NODE_ROLE) + || discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_ROLE); } public static boolean isWarmNode(DiscoveryNode discoveryNode) { - return discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_WARM_NODE_ROLE) || discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_ROLE); + return discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_WARM_NODE_ROLE) + || discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_ROLE); } public static boolean isColdNode(DiscoveryNode discoveryNode) { - return discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_COLD_NODE_ROLE) || discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_ROLE); + return discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_COLD_NODE_ROLE) + || discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_ROLE); } public static boolean isFrozenNode(DiscoveryNode discoveryNode) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java index 73861da34fec7..a502fba804094 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java @@ -18,7 +18,6 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider; import org.elasticsearch.cluster.service.ClusterService; @@ -89,14 +88,11 @@ import java.security.PrivilegedAction; import java.time.Clock; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.Set; import java.util.function.LongSupplier; import java.util.function.Supplier; import java.util.stream.Collectors; From 4531a0bbb0119967b49f022150fb6a148149dce2 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 30 Mar 2021 20:48:59 -0400 Subject: [PATCH 06/22] Fix checkstyle --- .../routing/allocation/DataTierAllocationDeciderTests.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 8535b6a23c840..a96a292ed278a 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 @@ -57,7 +57,8 @@ public class DataTierAllocationDeciderTests extends ESAllocationTestCase { private static final DiscoveryNode HOT_NODE = newNode("node-hot", Collections.singleton(DiscoveryNodeRole.DATA_HOT_NODE_ROLE)); private static final DiscoveryNode WARM_NODE = newNode("node-warm", Collections.singleton(DiscoveryNodeRole.DATA_WARM_NODE_ROLE)); private static final DiscoveryNode COLD_NODE = newNode("node-cold", Collections.singleton(DiscoveryNodeRole.DATA_COLD_NODE_ROLE)); - private static final DiscoveryNode CONTENT_NODE = newNode("node-content", Collections.singleton(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE)); + private static final DiscoveryNode CONTENT_NODE = + newNode("node-content", Collections.singleton(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE)); private static final DiscoveryNode DATA_NODE = newNode("node-data", Collections.singleton(DiscoveryNodeRole.DATA_ROLE)); private final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ALL_SETTINGS); From 4a733745a507593cd6279d42d8d7e8ab25d2750b Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 30 Mar 2021 21:50:01 -0400 Subject: [PATCH 07/22] Simplify DiscoveryNodes#resolveNodes --- .../cluster/node/DiscoveryNodes.java | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java index ffd2e00a96a47..149fa9c73ca44 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java @@ -26,10 +26,14 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; +import java.util.function.Function; +import java.util.function.Predicate; import java.util.stream.Stream; import java.util.stream.StreamSupport; @@ -350,29 +354,31 @@ public String[] resolveNodes(String... nodes) { if (index != -1) { String matchAttrName = nodeId.substring(0, index); String matchAttrValue = nodeId.substring(index + 1); - if (DiscoveryNodeRole.DATA_ROLE.roleName().equals(matchAttrName)) { - if (Booleans.parseBoolean(matchAttrValue, true)) { - resolvedNodesIds.addAll(dataNodes.keys()); - } else { - resolvedNodesIds.removeAll(dataNodes.keys()); - } - } else if (DiscoveryNodeRole.MASTER_ROLE.roleName().equals(matchAttrName)) { - if (Booleans.parseBoolean(matchAttrValue, true)) { - resolvedNodesIds.addAll(masterNodes.keys()); + if (DiscoveryNodeRole.BUILT_IN_ROLES.stream() + .map(DiscoveryNodeRole::roleName) + .anyMatch(s -> s.equals(matchAttrName))) { + final DiscoveryNodeRole role = DiscoveryNode.getRoleFromRoleName(matchAttrName); + final Predicate> predicate; + if (role.equals(DiscoveryNodeRole.DATA_ROLE)) { + // if the node has *any* role that can contain data, then it matches the data attribute + predicate = s -> s.stream().anyMatch(DiscoveryNodeRole::canContainData); + } else if (role.canContainData()) { + // if the node has the matching data_ role, or the generic data role, then it matches the data_ attribute + predicate = s -> s.stream().anyMatch(r -> r.equals(role) || r.equals(DiscoveryNodeRole.DATA_ROLE)); } else { - resolvedNodesIds.removeAll(masterNodes.keys()); + // the role is not a data role, we require an exact match (e.g., ingest) + predicate = s -> s.contains(role); } - } else if (DiscoveryNodeRole.INGEST_ROLE.roleName().equals(matchAttrName)) { + Function mutation; if (Booleans.parseBoolean(matchAttrValue, true)) { - resolvedNodesIds.addAll(ingestNodes.keys()); + mutation = resolvedNodesIds::add; } else { - resolvedNodesIds.removeAll(ingestNodes.keys()); + mutation = resolvedNodesIds::remove; } - } else if (DiscoveryNode.COORDINATING_ONLY.equals(matchAttrName)) { - if (Booleans.parseBoolean(matchAttrValue, true)) { - resolvedNodesIds.addAll(getCoordinatingOnlyNodes().keys()); - } else { - resolvedNodesIds.removeAll(getCoordinatingOnlyNodes().keys()); + for (final DiscoveryNode node : this) { + if (predicate.test(node.getRoles())) { + mutation.apply(node.getId()); + } } } else { for (DiscoveryNode node : this) { From e64fe2407cdebc2c44a860096e7e1d571e3f3f88 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 30 Mar 2021 21:56:30 -0400 Subject: [PATCH 08/22] Fix node repurpose command tests --- .../org/elasticsearch/env/NodeRepurposeCommandTests.java | 5 +++-- .../src/main/java/org/elasticsearch/test/NodeRoles.java | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/env/NodeRepurposeCommandTests.java b/server/src/test/java/org/elasticsearch/env/NodeRepurposeCommandTests.java index c00270e013d26..e901e814f0d93 100644 --- a/server/src/test/java/org/elasticsearch/env/NodeRepurposeCommandTests.java +++ b/server/src/test/java/org/elasticsearch/env/NodeRepurposeCommandTests.java @@ -17,6 +17,7 @@ import org.elasticsearch.cluster.coordination.ElasticsearchNodeCommand; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.CheckedConsumer; import org.elasticsearch.common.CheckedRunnable; @@ -34,6 +35,7 @@ import java.nio.file.Path; import java.util.Arrays; import java.util.Set; +import java.util.stream.Collectors; import java.util.stream.Stream; import static org.elasticsearch.env.NodeRepurposeCommand.NO_CLEANUP; @@ -71,8 +73,7 @@ public void createNodePaths() throws IOException { } } dataNoMasterSettings = nonMasterNode(dataMasterSettings); - noDataNoMasterSettings = removeRoles(dataMasterSettings, Set.of(DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.MASTER_ROLE)); - + noDataNoMasterSettings = removeRoles(nonDataNode(dataMasterSettings), Set.of(DiscoveryNodeRole.MASTER_ROLE)); noDataMasterSettings = masterNode(nonDataNode(dataMasterSettings)); } diff --git a/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java b/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java index 34bb1c13ca2c9..d575d0233718a 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java +++ b/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java @@ -106,7 +106,9 @@ public static Settings nonDataNode() { } public static Settings nonDataNode(final Settings settings) { - return removeRoles(settings, Set.of(DiscoveryNodeRole.DATA_ROLE)); + final Set dataRoles = + DiscoveryNodeRole.BUILT_IN_ROLES.stream().filter(DiscoveryNodeRole::canContainData).collect(Collectors.toUnmodifiableSet()); + return removeRoles(settings, dataRoles); } public static Settings ingestNode() { From 0e50bf97ab7cb3a88a88c0f9ce9d50c0cf6da68c Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 30 Mar 2021 21:57:40 -0400 Subject: [PATCH 09/22] Fix node environment tests --- .../test/java/org/elasticsearch/env/NodeEnvironmentTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java b/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java index 86af16eb49c8e..7ddf90b2dec65 100644 --- a/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java +++ b/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java @@ -417,7 +417,7 @@ public void testEnsureNoShardDataOrIndexMetadata() throws IOException { // build settings using same path.data as original but without data and master roles Settings noDataNoMasterSettings = Settings.builder() .put(settings) - .put(NodeRoles.removeRoles(settings, Set.of(DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.MASTER_ROLE))) + .put(NodeRoles.removeRoles(nonDataNode(settings), Set.of(DiscoveryNodeRole.MASTER_ROLE))) .build(); // test that we can create data=false and master=false with no meta information From 1a0039e16af4355f9903bcb81f8c8709f6e41390 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 30 Mar 2021 21:57:52 -0400 Subject: [PATCH 10/22] Fix imports --- .../java/org/elasticsearch/env/NodeRepurposeCommandTests.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/env/NodeRepurposeCommandTests.java b/server/src/test/java/org/elasticsearch/env/NodeRepurposeCommandTests.java index e901e814f0d93..4321f29c8b493 100644 --- a/server/src/test/java/org/elasticsearch/env/NodeRepurposeCommandTests.java +++ b/server/src/test/java/org/elasticsearch/env/NodeRepurposeCommandTests.java @@ -17,7 +17,6 @@ import org.elasticsearch.cluster.coordination.ElasticsearchNodeCommand; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; -import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.CheckedConsumer; import org.elasticsearch.common.CheckedRunnable; @@ -35,7 +34,6 @@ import java.nio.file.Path; import java.util.Arrays; import java.util.Set; -import java.util.stream.Collectors; import java.util.stream.Stream; import static org.elasticsearch.env.NodeRepurposeCommand.NO_CLEANUP; From 21a3e167086d6b490d8894bb2c84a8051df4c207 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 30 Mar 2021 22:03:02 -0400 Subject: [PATCH 11/22] Fix more tests --- .../index/store/CorruptedFileIT.java | 4 ++-- .../index/store/ExceptionRetryIT.java | 2 +- .../breaker/CircuitBreakerServiceIT.java | 2 +- .../state/CloseWhileRelocatingShardsIT.java | 2 +- .../recovery/TruncatedRecoveryIT.java | 2 +- .../search/ccs/CrossClusterSearchIT.java | 2 +- .../cluster/InternalClusterInfoService.java | 2 +- .../cluster/node/DiscoveryNode.java | 21 ++++++++++++++----- .../cluster/node/DiscoveryNodes.java | 5 ++--- .../AbstractAllocateAllocationCommand.java | 2 +- .../command/MoveAllocationCommand.java | 4 ++-- .../elasticsearch/env/NodeEnvironment.java | 2 +- .../env/NodeRepurposeCommand.java | 4 ++-- .../gateway/GatewayMetaState.java | 4 ++-- .../IncrementalClusterStateWriter.java | 2 +- .../elasticsearch/indices/IndicesService.java | 2 +- .../cluster/IndicesClusterStateService.java | 4 ++-- .../recovery/PeerRecoverySourceService.java | 4 ++-- .../indices/store/IndicesStore.java | 4 ++-- .../persistent/PersistentTasksExecutor.java | 2 +- .../repositories/RepositoriesService.java | 6 +++--- .../snapshots/SnapshotShardsService.java | 2 +- .../transport/ConnectionProfile.java | 2 +- .../transport/SniffConnectionStrategy.java | 2 +- .../nodes/TransportNodesActionTests.java | 2 +- .../node/DiscoveryNodeRoleSettingTests.java | 2 +- .../cluster/node/DiscoveryNodesTests.java | 4 ++-- .../snapshots/SnapshotResiliencyTests.java | 2 +- .../test/ExternalTestCluster.java | 2 +- .../test/InternalTestCluster.java | 8 +++---- .../test/test/InternalTestClusterTests.java | 2 +- .../xpack/async/AsyncResultsIndexPlugin.java | 2 +- .../AutoscalingCalculateCapacityService.java | 4 ++-- .../ccr/action/ShardFollowTasksExecutor.java | 2 +- .../xpack/core/DataTierTests.java | 2 +- ...nsportExplainDataFrameAnalyticsAction.java | 2 +- .../SearchableSnapshots.java | 4 ++-- .../SearchableSnapshotIndexEventListener.java | 2 +- .../cache/full/PersistentCache.java | 2 +- .../testkit/RepositoryAnalyzeAction.java | 2 +- .../VotingOnlyNodePluginTests.java | 2 +- .../elasticsearch/xpack/watcher/Watcher.java | 2 +- .../watcher/WatcherIndexingListener.java | 2 +- .../watcher/WatcherLifeCycleService.java | 2 +- .../engine/TickerScheduleTriggerEngine.java | 2 +- 45 files changed, 76 insertions(+), 66 deletions(-) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/index/store/CorruptedFileIT.java b/server/src/internalClusterTest/java/org/elasticsearch/index/store/CorruptedFileIT.java index be59e5dad37ac..b87e0e350ecd3 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/index/store/CorruptedFileIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/index/store/CorruptedFileIT.java @@ -323,7 +323,7 @@ public void testCorruptionOnNetworkLayerFinalizingRecovery() throws ExecutionExc NodesStatsResponse nodeStats = client().admin().cluster().prepareNodesStats().get(); List dataNodeStats = new ArrayList<>(); for (NodeStats stat : nodeStats.getNodes()) { - if (stat.getNode().isDataNode()) { + if (stat.getNode().canContainData()) { dataNodeStats.add(stat); } } @@ -383,7 +383,7 @@ public void testCorruptionOnNetworkLayer() throws ExecutionException, Interrupte NodesStatsResponse nodeStats = client().admin().cluster().prepareNodesStats().get(); List dataNodeStats = new ArrayList<>(); for (NodeStats stat : nodeStats.getNodes()) { - if (stat.getNode().isDataNode()) { + if (stat.getNode().canContainData()) { dataNodeStats.add(stat); } } diff --git a/server/src/internalClusterTest/java/org/elasticsearch/index/store/ExceptionRetryIT.java b/server/src/internalClusterTest/java/org/elasticsearch/index/store/ExceptionRetryIT.java index e9fbfcd8dfa4e..a21109e5f14e3 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/index/store/ExceptionRetryIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/index/store/ExceptionRetryIT.java @@ -71,7 +71,7 @@ public void testRetryDueToExceptionOnNetworkLayer() throws ExecutionException, I int numDocs = scaledRandomIntBetween(100, 1000); Client client = internalCluster().coordOnlyNodeClient(); NodesStatsResponse nodeStats = client().admin().cluster().prepareNodesStats().get(); - NodeStats unluckyNode = randomFrom(nodeStats.getNodes().stream().filter((s) -> s.getNode().isDataNode()) + NodeStats unluckyNode = randomFrom(nodeStats.getNodes().stream().filter((s) -> s.getNode().canContainData()) .collect(Collectors.toList())); assertAcked(client().admin().indices().prepareCreate("index").setSettings(Settings.builder() .put("index.number_of_replicas", 1) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/indices/memory/breaker/CircuitBreakerServiceIT.java b/server/src/internalClusterTest/java/org/elasticsearch/indices/memory/breaker/CircuitBreakerServiceIT.java index 3f8b9c863e454..a7c5e977c0cb7 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/indices/memory/breaker/CircuitBreakerServiceIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/indices/memory/breaker/CircuitBreakerServiceIT.java @@ -325,7 +325,7 @@ public void testLimitsRequestSize() { NodesStatsResponse nodeStats = client().admin().cluster().prepareNodesStats().get(); List dataNodeStats = new ArrayList<>(); for (NodeStats stat : nodeStats.getNodes()) { - if (stat.getNode().isDataNode()) { + if (stat.getNode().canContainData()) { dataNodeStats.add(stat); } } diff --git a/server/src/internalClusterTest/java/org/elasticsearch/indices/state/CloseWhileRelocatingShardsIT.java b/server/src/internalClusterTest/java/org/elasticsearch/indices/state/CloseWhileRelocatingShardsIT.java index 7d9553f1395f0..314cca0bc77ac 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/indices/state/CloseWhileRelocatingShardsIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/indices/state/CloseWhileRelocatingShardsIT.java @@ -179,7 +179,7 @@ public void testCloseWhileRelocatingShards() throws Exception { (MockTransportService) internalCluster().getInstance(TransportService.class, targetNode); for (DiscoveryNode node : state.getNodes()) { - if (node.isDataNode() && node.getName().equals(targetNode) == false) { + if (node.canContainData() && node.getName().equals(targetNode) == false) { final TransportService sourceTransportService = internalCluster().getInstance(TransportService.class, node.getName()); targetTransportService.addSendBehavior(sourceTransportService, sendBehavior); } diff --git a/server/src/internalClusterTest/java/org/elasticsearch/recovery/TruncatedRecoveryIT.java b/server/src/internalClusterTest/java/org/elasticsearch/recovery/TruncatedRecoveryIT.java index 9c48bd2e5cd6e..c0f40b06e3f68 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/recovery/TruncatedRecoveryIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/recovery/TruncatedRecoveryIT.java @@ -62,7 +62,7 @@ public void testCancelRecoveryAndResume() throws Exception { NodesStatsResponse nodeStats = client().admin().cluster().prepareNodesStats().get(); List dataNodeStats = new ArrayList<>(); for (NodeStats stat : nodeStats.getNodes()) { - if (stat.getNode().isDataNode()) { + if (stat.getNode().canContainData()) { dataNodeStats.add(stat); } } diff --git a/server/src/internalClusterTest/java/org/elasticsearch/search/ccs/CrossClusterSearchIT.java b/server/src/internalClusterTest/java/org/elasticsearch/search/ccs/CrossClusterSearchIT.java index 7827cc398e080..b3d3cfad3f8ae 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/search/ccs/CrossClusterSearchIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/search/ccs/CrossClusterSearchIT.java @@ -151,7 +151,7 @@ public void testCancel() throws Exception { if (randomBoolean()) { remoteCluster.ensureAtLeastNumDataNodes(3); List remoteDataNodes = StreamSupport.stream(remoteCluster.clusterService().state().nodes().spliterator(), false) - .filter(DiscoveryNode::isDataNode) + .filter(DiscoveryNode::canContainData) .map(DiscoveryNode::getName) .collect(Collectors.toList()); assertThat(remoteDataNodes.size(), Matchers.greaterThanOrEqualTo(3)); diff --git a/server/src/main/java/org/elasticsearch/cluster/InternalClusterInfoService.java b/server/src/main/java/org/elasticsearch/cluster/InternalClusterInfoService.java index 5aa0895cb3f25..70f85fd5e94f8 100644 --- a/server/src/main/java/org/elasticsearch/cluster/InternalClusterInfoService.java +++ b/server/src/main/java/org/elasticsearch/cluster/InternalClusterInfoService.java @@ -136,7 +136,7 @@ public void clusterChanged(ClusterChangedEvent event) { // Refresh if a data node was added for (DiscoveryNode addedNode : event.nodesDelta().addedNodes()) { - if (addedNode.isDataNode()) { + if (addedNode.canContainData()) { refreshAsync(new PlainActionFuture<>()); break; } diff --git a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java index 93cba93c71b1d..84c186bd6f0cc 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -62,11 +62,22 @@ public static boolean isMasterNode(final Settings settings) { } /** - * Due to the way that plugins may not be available when settings are being initialized, - * not all roles may be available from a static/initializing context such as a {@link Setting} - * default value function. In that case, be warned that this may not include all plugin roles. + * Check if the given settings are indicative of having the top-level data role. + * + * @param settings the settings + * @return true if the given settings are indicative of having the top-level data role, otherwise false + */ + public static boolean hasDataRole(final Settings settings) { + return hasRole(settings, DiscoveryNodeRole.DATA_ROLE); + } + + /** + * Check if the given settings are indicative of any role that can contain data. + * + * @param settings the settings + * @return true if the given settings are indicative of having any role that can contain data, otherwise false */ - public static boolean isDataNode(final Settings settings) { + public static boolean canContainData(final Settings settings) { return getRolesFromSettings(settings).stream().anyMatch(DiscoveryNodeRole::canContainData); } @@ -322,7 +333,7 @@ public Map getAttributes() { /** * Should this node hold data (shards) or not. */ - public boolean isDataNode() { + public boolean canContainData() { return roles.stream().anyMatch(DiscoveryNodeRole::canContainData); } diff --git a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java index 149fa9c73ca44..0382b17b5c004 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java @@ -26,7 +26,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collections; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -685,14 +684,14 @@ public DiscoveryNodes build() { Version minNonClientNodeVersion = null; Version maxNonClientNodeVersion = null; for (ObjectObjectCursor nodeEntry : nodes) { - if (nodeEntry.value.isDataNode()) { + if (nodeEntry.value.canContainData()) { dataNodesBuilder.put(nodeEntry.key, nodeEntry.value); } if (nodeEntry.value.isMasterNode()) { masterNodesBuilder.put(nodeEntry.key, nodeEntry.value); } final Version version = nodeEntry.value.getVersion(); - if (nodeEntry.value.isDataNode() || nodeEntry.value.isMasterNode()) { + if (nodeEntry.value.canContainData() || nodeEntry.value.isMasterNode()) { if (minNonClientNodeVersion == null) { minNonClientNodeVersion = version; maxNonClientNodeVersion = version; diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AbstractAllocateAllocationCommand.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AbstractAllocateAllocationCommand.java index 68d27d61218ce..bba1522c86a5c 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AbstractAllocateAllocationCommand.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AbstractAllocateAllocationCommand.java @@ -140,7 +140,7 @@ public String node() { * Handle case where a disco node cannot be found in the routing table. Usually means that it's not a data node. */ protected RerouteExplanation explainOrThrowMissingRoutingNode(RoutingAllocation allocation, boolean explain, DiscoveryNode discoNode) { - if (discoNode.isDataNode() == false) { + if (discoNode.canContainData() == false) { return explainOrThrowRejectedCommand(explain, allocation, "allocation can only be done on data nodes, not [" + node + "]"); } else { return explainOrThrowRejectedCommand(explain, allocation, "could not find [" + node + "] among the routing nodes"); diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/command/MoveAllocationCommand.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/command/MoveAllocationCommand.java index 2876bc35faad5..af4de9f90db44 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/command/MoveAllocationCommand.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/command/MoveAllocationCommand.java @@ -92,13 +92,13 @@ public RerouteExplanation execute(RoutingAllocation allocation, boolean explain) boolean found = false; RoutingNode fromRoutingNode = allocation.routingNodes().node(fromDiscoNode.getId()); - if (fromRoutingNode == null && fromDiscoNode.isDataNode() == false) { + if (fromRoutingNode == null && fromDiscoNode.canContainData() == false) { throw new IllegalArgumentException("[move_allocation] can't move [" + index + "][" + shardId + "] from " + fromDiscoNode + " to " + toDiscoNode + ": source [" + fromDiscoNode.getName() + "] is not a data node."); } RoutingNode toRoutingNode = allocation.routingNodes().node(toDiscoNode.getId()); - if (toRoutingNode == null && toDiscoNode.isDataNode() == false) { + if (toRoutingNode == null && toDiscoNode.canContainData() == false) { throw new IllegalArgumentException("[move_allocation] can't move [" + index + "][" + shardId + "] from " + fromDiscoNode + " to " + toDiscoNode + ": source [" + toDiscoNode.getName() + "] is not a data node."); diff --git a/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java b/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java index 1b832a6635089..466e0b068b435 100644 --- a/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java +++ b/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java @@ -281,7 +281,7 @@ public NodeEnvironment(Settings settings, Environment environment) throws IOExce assertCanWrite(); } - if (DiscoveryNode.isDataNode(settings) == false) { + if (DiscoveryNode.canContainData(settings) == false) { if (DiscoveryNode.isMasterNode(settings) == false) { ensureNoIndexMetadata(nodePaths); } diff --git a/server/src/main/java/org/elasticsearch/env/NodeRepurposeCommand.java b/server/src/main/java/org/elasticsearch/env/NodeRepurposeCommand.java index dc169cf1edd69..bfd3b2667b2b0 100644 --- a/server/src/main/java/org/elasticsearch/env/NodeRepurposeCommand.java +++ b/server/src/main/java/org/elasticsearch/env/NodeRepurposeCommand.java @@ -54,7 +54,7 @@ void testExecute(Terminal terminal, OptionSet options, Environment env) throws E @Override protected boolean validateBeforeLock(Terminal terminal, Environment env) { Settings settings = env.settings(); - if (DiscoveryNode.isDataNode(settings)) { + if (DiscoveryNode.canContainData(settings)) { terminal.println(Terminal.Verbosity.NORMAL, NO_CLEANUP); return false; } @@ -64,7 +64,7 @@ protected boolean validateBeforeLock(Terminal terminal, Environment env) { @Override protected void processNodePaths(Terminal terminal, Path[] dataPaths, OptionSet options, Environment env) throws IOException { - assert DiscoveryNode.isDataNode(env.settings()) == false; + assert DiscoveryNode.canContainData(env.settings()) == false; if (DiscoveryNode.isMasterNode(env.settings()) == false) { processNoMasterNoDataNode(terminal, dataPaths, env); diff --git a/server/src/main/java/org/elasticsearch/gateway/GatewayMetaState.java b/server/src/main/java/org/elasticsearch/gateway/GatewayMetaState.java index 04564ebb0f8c1..41a615e961a0f 100644 --- a/server/src/main/java/org/elasticsearch/gateway/GatewayMetaState.java +++ b/server/src/main/java/org/elasticsearch/gateway/GatewayMetaState.java @@ -92,7 +92,7 @@ public void start(Settings settings, TransportService transportService, ClusterS MetadataUpgrader metadataUpgrader, PersistedClusterStateService persistedClusterStateService) { assert persistedState.get() == null : "should only start once, but already have " + persistedState.get(); - if (DiscoveryNode.isMasterNode(settings) || DiscoveryNode.isDataNode(settings)) { + if (DiscoveryNode.isMasterNode(settings) || DiscoveryNode.canContainData(settings)) { try { final PersistedClusterStateService.OnDiskState onDiskState = persistedClusterStateService.loadBestOnDiskState(); @@ -125,7 +125,7 @@ public void start(Settings settings, TransportService transportService, ClusterS persistedState = new AsyncLucenePersistedState(settings, transportService.getThreadPool(), new LucenePersistedState(persistedClusterStateService, currentTerm, clusterState)); } - if (DiscoveryNode.isDataNode(settings)) { + if (DiscoveryNode.canContainData(settings)) { metaStateService.unreferenceAll(); // unreference legacy files (only keep them for dangling indices functionality) } else { metaStateService.deleteAll(); // delete legacy files diff --git a/server/src/main/java/org/elasticsearch/gateway/IncrementalClusterStateWriter.java b/server/src/main/java/org/elasticsearch/gateway/IncrementalClusterStateWriter.java index ac63ab1644300..f044117453316 100644 --- a/server/src/main/java/org/elasticsearch/gateway/IncrementalClusterStateWriter.java +++ b/server/src/main/java/org/elasticsearch/gateway/IncrementalClusterStateWriter.java @@ -187,7 +187,7 @@ static List resolveIndexMetadataActions(Map pr // exposed for tests static Set getRelevantIndices(ClusterState state) { - assert state.nodes().getLocalNode().isDataNode(); + assert state.nodes().getLocalNode().canContainData(); final RoutingNode newRoutingNode = state.getRoutingNodes().node(state.nodes().getLocalNodeId()); if (newRoutingNode == null) { throw new IllegalStateException("cluster state does not contain this node - cannot write index meta state"); diff --git a/server/src/main/java/org/elasticsearch/indices/IndicesService.java b/server/src/main/java/org/elasticsearch/indices/IndicesService.java index fc58bc270a8a9..a11cdbd38a090 100644 --- a/server/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/server/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -1602,7 +1602,7 @@ private void setIdFieldDataEnabled(boolean value) { } private void updateDanglingIndicesInfo(Index index) { - assert DiscoveryNode.isDataNode(settings) : "dangling indices information should only be persisted on data nodes"; + assert DiscoveryNode.canContainData(settings) : "dangling indices information should only be persisted on data nodes"; assert nodeWriteDanglingIndicesInfo : "writing dangling indices info is not enabled"; assert danglingIndicesThreadPoolExecutor != null : "executor for dangling indices info is not available"; if (danglingIndicesToWrite.add(index)) { diff --git a/server/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java b/server/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java index 25ff8bfc9d2d0..595b9c526c53b 100644 --- a/server/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java +++ b/server/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java @@ -172,14 +172,14 @@ public IndicesClusterStateService( @Override protected void doStart() { // Doesn't make sense to manage shards on non-master and non-data nodes - if (DiscoveryNode.isDataNode(settings) || DiscoveryNode.isMasterNode(settings)) { + if (DiscoveryNode.canContainData(settings) || DiscoveryNode.isMasterNode(settings)) { clusterService.addHighPriorityApplier(this); } } @Override protected void doStop() { - if (DiscoveryNode.isDataNode(settings) || DiscoveryNode.isMasterNode(settings)) { + if (DiscoveryNode.canContainData(settings) || DiscoveryNode.isMasterNode(settings)) { clusterService.removeApplier(this); } } diff --git a/server/src/main/java/org/elasticsearch/indices/recovery/PeerRecoverySourceService.java b/server/src/main/java/org/elasticsearch/indices/recovery/PeerRecoverySourceService.java index a41b2f899f601..b34139d880725 100644 --- a/server/src/main/java/org/elasticsearch/indices/recovery/PeerRecoverySourceService.java +++ b/server/src/main/java/org/elasticsearch/indices/recovery/PeerRecoverySourceService.java @@ -84,7 +84,7 @@ public PeerRecoverySourceService(TransportService transportService, IndicesServi @Override protected void doStart() { final ClusterService clusterService = indicesService.clusterService(); - if (DiscoveryNode.isDataNode(clusterService.getSettings())) { + if (DiscoveryNode.canContainData(clusterService.getSettings())) { clusterService.addListener(this); } } @@ -92,7 +92,7 @@ protected void doStart() { @Override protected void doStop() { final ClusterService clusterService = indicesService.clusterService(); - if (DiscoveryNode.isDataNode(clusterService.getSettings())) { + if (DiscoveryNode.canContainData(clusterService.getSettings())) { ongoingRecoveries.awaitEmpty(); indicesService.clusterService().removeListener(this); } diff --git a/server/src/main/java/org/elasticsearch/indices/store/IndicesStore.java b/server/src/main/java/org/elasticsearch/indices/store/IndicesStore.java index 2518e85b2473d..ef6daf34c0e11 100644 --- a/server/src/main/java/org/elasticsearch/indices/store/IndicesStore.java +++ b/server/src/main/java/org/elasticsearch/indices/store/IndicesStore.java @@ -93,7 +93,7 @@ public IndicesStore(Settings settings, IndicesService indicesService, new ShardActiveRequestHandler()); this.deleteShardTimeout = INDICES_STORE_DELETE_SHARD_TIMEOUT.get(settings); // Doesn't make sense to delete shards on non-data nodes - if (DiscoveryNode.isDataNode(settings)) { + if (DiscoveryNode.canContainData(settings)) { // we double check nothing has changed when responses come back from other nodes. // it's easier to do that check when the current cluster state is visible. // also it's good in general to let things settle down @@ -103,7 +103,7 @@ public IndicesStore(Settings settings, IndicesService indicesService, @Override public void close() { - if (DiscoveryNode.isDataNode(settings)) { + if (DiscoveryNode.canContainData(settings)) { clusterService.removeListener(this); } } diff --git a/server/src/main/java/org/elasticsearch/persistent/PersistentTasksExecutor.java b/server/src/main/java/org/elasticsearch/persistent/PersistentTasksExecutor.java index a40862c29127d..158bd4a8d4eb7 100644 --- a/server/src/main/java/org/elasticsearch/persistent/PersistentTasksExecutor.java +++ b/server/src/main/java/org/elasticsearch/persistent/PersistentTasksExecutor.java @@ -44,7 +44,7 @@ public String getTaskName() { * The default implementation returns the least loaded data node */ public Assignment getAssignment(Params params, ClusterState clusterState) { - DiscoveryNode discoveryNode = selectLeastLoadedNode(clusterState, DiscoveryNode::isDataNode); + DiscoveryNode discoveryNode = selectLeastLoadedNode(clusterState, DiscoveryNode::canContainData); if (discoveryNode == null) { return NO_NODE_FOUND; } else { diff --git a/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java b/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java index 55f7f9d33f0e2..d7a9b3d885914 100644 --- a/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java +++ b/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java @@ -93,7 +93,7 @@ public RepositoriesService(Settings settings, ClusterService clusterService, Tra this.threadPool = threadPool; // Doesn't make sense to maintain repositories on non-master and non-data nodes // Nothing happens there anyway - if (DiscoveryNode.isDataNode(settings) || DiscoveryNode.isMasterNode(settings)) { + if (DiscoveryNode.canContainData(settings) || DiscoveryNode.isMasterNode(settings)) { if (isDedicatedVotingOnlyNode(DiscoveryNode.getRolesFromSettings(settings)) == false) { clusterService.addHighPriorityApplier(this); } @@ -209,7 +209,7 @@ public void onFailure(String source, Exception e) { @Override public boolean mustAck(DiscoveryNode discoveryNode) { // repository is created on both master and data nodes - return discoveryNode.isMasterNode() || discoveryNode.isDataNode(); + return discoveryNode.isMasterNode() || discoveryNode.canContainData(); } @Override @@ -336,7 +336,7 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS @Override public boolean mustAck(DiscoveryNode discoveryNode) { // repository was created on both master and data nodes - return discoveryNode.isMasterNode() || discoveryNode.isDataNode(); + return discoveryNode.isMasterNode() || discoveryNode.canContainData(); } }); } diff --git a/server/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java b/server/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java index d3c48fd57c8ff..ce1635f69906d 100644 --- a/server/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java +++ b/server/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java @@ -90,7 +90,7 @@ public SnapshotShardsService(Settings settings, ClusterService clusterService, R this.transportService = transportService; this.clusterService = clusterService; this.threadPool = transportService.getThreadPool(); - if (DiscoveryNode.isDataNode(settings)) { + if (DiscoveryNode.canContainData(settings)) { // this is only useful on the nodes that can hold data clusterService.addListener(this); } diff --git a/server/src/main/java/org/elasticsearch/transport/ConnectionProfile.java b/server/src/main/java/org/elasticsearch/transport/ConnectionProfile.java index 1a1b822e87b96..03da8187dd0a8 100644 --- a/server/src/main/java/org/elasticsearch/transport/ConnectionProfile.java +++ b/server/src/main/java/org/elasticsearch/transport/ConnectionProfile.java @@ -77,7 +77,7 @@ public static ConnectionProfile buildDefaultConnectionProfile(Settings settings) // if we are not master eligible we don't need a dedicated channel to publish the state builder.addConnections(DiscoveryNode.isMasterNode(settings) ? connectionsPerNodeState : 0, TransportRequestOptions.Type.STATE); // if we are not a data-node we don't need any dedicated channels for recovery - builder.addConnections(DiscoveryNode.isDataNode(settings) ? connectionsPerNodeRecovery : 0, TransportRequestOptions.Type.RECOVERY); + builder.addConnections(DiscoveryNode.canContainData(settings) ? connectionsPerNodeRecovery : 0, TransportRequestOptions.Type.RECOVERY); builder.addConnections(connectionsPerNodeReg, TransportRequestOptions.Type.REG); return builder.build(); } diff --git a/server/src/main/java/org/elasticsearch/transport/SniffConnectionStrategy.java b/server/src/main/java/org/elasticsearch/transport/SniffConnectionStrategy.java index ca0eca85795af..ecaf0530ef5ee 100644 --- a/server/src/main/java/org/elasticsearch/transport/SniffConnectionStrategy.java +++ b/server/src/main/java/org/elasticsearch/transport/SniffConnectionStrategy.java @@ -119,7 +119,7 @@ public class SniffConnectionStrategy extends RemoteConnectionStrategy { static final int CHANNELS_PER_CONNECTION = 6; private static final Predicate DEFAULT_NODE_PREDICATE = (node) -> Version.CURRENT.isCompatible(node.getVersion()) - && (node.isMasterNode() == false || node.isDataNode() || node.isIngestNode()); + && (node.isMasterNode() == false || node.canContainData() || node.isIngestNode()); private final List configuredSeedNodes; diff --git a/server/src/test/java/org/elasticsearch/action/support/nodes/TransportNodesActionTests.java b/server/src/test/java/org/elasticsearch/action/support/nodes/TransportNodesActionTests.java index 48f044d509a6d..ed88ba49e2ea8 100644 --- a/server/src/test/java/org/elasticsearch/action/support/nodes/TransportNodesActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/support/nodes/TransportNodesActionTests.java @@ -134,7 +134,7 @@ public void testCustomResolving() throws Exception { Map> capturedRequests = transport.getCapturedRequestsByTargetNodeAndClear(); // check requests were only sent to data nodes for (String nodeTarget : capturedRequests.keySet()) { - assertTrue(clusterService.state().nodes().get(nodeTarget).isDataNode()); + assertTrue(clusterService.state().nodes().get(nodeTarget).canContainData()); } assertEquals(clusterService.state().nodes().getDataNodes().size(), capturedRequests.size()); } diff --git a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeRoleSettingTests.java b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeRoleSettingTests.java index 94664266c5b01..ebf1f1ff8562d 100644 --- a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeRoleSettingTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeRoleSettingTests.java @@ -24,7 +24,7 @@ public class DiscoveryNodeRoleSettingTests extends ESTestCase { public void testIsDataNode() { - runRoleTest(DiscoveryNode::isDataNode, DiscoveryNodeRole.DATA_ROLE); + runRoleTest(DiscoveryNode::hasDataRole, DiscoveryNodeRole.DATA_ROLE); } public void testIsIngestNode() { diff --git a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java index 606d45bb6d8a7..54683a76b6b17 100644 --- a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java @@ -99,14 +99,14 @@ public void testCoordinatorOnlyNodes() { final String[] coordinatorOnlyNodes = StreamSupport.stream(discoveryNodes.getNodes().values().spliterator(), false) .map(n -> n.value) - .filter(n -> n.isDataNode() == false && n.isIngestNode() == false && n.isMasterNode() == false) + .filter(n -> n.canContainData() == false && n.isIngestNode() == false && n.isMasterNode() == false) .map(DiscoveryNode::getId) .toArray(String[]::new); final String[] nonCoordinatorOnlyNodes = StreamSupport.stream(discoveryNodes.getNodes().values().spliterator(), false) .map(n -> n.value) - .filter(n -> n.isMasterNode() || n.isDataNode() || n.isIngestNode()) + .filter(n -> n.isMasterNode() || n.canContainData() || n.isIngestNode()) .map(DiscoveryNode::getId) .toArray(String[]::new); diff --git a/server/src/test/java/org/elasticsearch/snapshots/SnapshotResiliencyTests.java b/server/src/test/java/org/elasticsearch/snapshots/SnapshotResiliencyTests.java index 903e6d70a9d67..d33e0185b368e 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/SnapshotResiliencyTests.java +++ b/server/src/test/java/org/elasticsearch/snapshots/SnapshotResiliencyTests.java @@ -1284,7 +1284,7 @@ public TestClusterNode randomDataNodeSafe(String... excludedNames) { public Optional randomDataNode(String... excludedNames) { // Select from sorted list of data-nodes here to not have deterministic behaviour - final List dataNodes = testClusterNodes.nodes.values().stream().filter(n -> n.node.isDataNode()) + final List dataNodes = testClusterNodes.nodes.values().stream().filter(n -> n.node.canContainData()) .filter(n -> { for (final String nodeName : excludedNames) { if (n.node.getName().equals(nodeName)) { diff --git a/test/framework/src/main/java/org/elasticsearch/test/ExternalTestCluster.java b/test/framework/src/main/java/org/elasticsearch/test/ExternalTestCluster.java index 697e967171ab6..586db61de0401 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ExternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ExternalTestCluster.java @@ -108,7 +108,7 @@ public ExternalTestCluster(Path tempDir, Settings additionalSettings, Collection for (int i = 0; i < nodeInfos.getNodes().size(); i++) { NodeInfo nodeInfo = nodeInfos.getNodes().get(i); httpAddresses[i] = nodeInfo.getInfo(HttpInfo.class).address().publishAddress().address(); - if (DiscoveryNode.isDataNode(nodeInfo.getSettings())) { + if (DiscoveryNode.canContainData(nodeInfo.getSettings())) { dataNodes++; masterAndDataNodes++; } else if (DiscoveryNode.isMasterNode(nodeInfo.getSettings())) { diff --git a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java index 84c3c8f848a43..7e71658b65ead 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java @@ -174,11 +174,11 @@ public final class InternalTestCluster extends TestCluster { private final Logger logger = LogManager.getLogger(getClass()); private static final Predicate DATA_NODE_PREDICATE = - nodeAndClient -> DiscoveryNode.isDataNode(nodeAndClient.node.settings()); + nodeAndClient -> DiscoveryNode.canContainData(nodeAndClient.node.settings()); private static final Predicate NO_DATA_NO_MASTER_PREDICATE = nodeAndClient -> DiscoveryNode.isMasterNode(nodeAndClient.node.settings()) == false - && DiscoveryNode.isDataNode(nodeAndClient.node.settings()) == false; + && DiscoveryNode.canContainData(nodeAndClient.node.settings()) == false; private static final Predicate MASTER_NODE_PREDICATE = nodeAndClient -> DiscoveryNode.isMasterNode(nodeAndClient.node.settings()); @@ -714,11 +714,11 @@ private static String getRoleSuffix(Settings settings) { if (DiscoveryNode.hasRole(settings, DiscoveryNodeRole.MASTER_ROLE)) { suffix = suffix + DiscoveryNodeRole.MASTER_ROLE.roleNameAbbreviation(); } - if (DiscoveryNode.isDataNode(settings)) { + if (DiscoveryNode.canContainData(settings)) { suffix = suffix + DiscoveryNodeRole.DATA_ROLE.roleNameAbbreviation(); } if (DiscoveryNode.hasRole(settings, DiscoveryNodeRole.MASTER_ROLE) == false - && DiscoveryNode.isDataNode(settings) == false) { + && DiscoveryNode.canContainData(settings) == false) { suffix = suffix + "c"; } } diff --git a/test/framework/src/test/java/org/elasticsearch/test/test/InternalTestClusterTests.java b/test/framework/src/test/java/org/elasticsearch/test/test/InternalTestClusterTests.java index 9a2bf830ab4d7..48db8fe974b27 100644 --- a/test/framework/src/test/java/org/elasticsearch/test/test/InternalTestClusterTests.java +++ b/test/framework/src/test/java/org/elasticsearch/test/test/InternalTestClusterTests.java @@ -342,7 +342,7 @@ public Path nodeConfigPath(int nodeOrdinal) { List paths = Arrays.stream(getNodePaths(cluster, name)).map(Path::toString).collect(Collectors.toList()); if (node.isMasterNode()) { result.computeIfAbsent(DiscoveryNodeRole.MASTER_ROLE, k -> new HashSet<>()).addAll(paths); - } else if (node.isDataNode()) { + } else if (node.canContainData()) { result.computeIfAbsent(DiscoveryNodeRole.DATA_ROLE, k -> new HashSet<>()).addAll(paths); } else { result.computeIfAbsent(DiscoveryNodeRole.INGEST_ROLE, k -> new HashSet<>()).addAll(paths); diff --git a/x-pack/plugin/async/src/main/java/org/elasticsearch/xpack/async/AsyncResultsIndexPlugin.java b/x-pack/plugin/async/src/main/java/org/elasticsearch/xpack/async/AsyncResultsIndexPlugin.java index fdc2abb909617..9869069f85b18 100644 --- a/x-pack/plugin/async/src/main/java/org/elasticsearch/xpack/async/AsyncResultsIndexPlugin.java +++ b/x-pack/plugin/async/src/main/java/org/elasticsearch/xpack/async/AsyncResultsIndexPlugin.java @@ -73,7 +73,7 @@ public Collection createComponents( Supplier repositoriesServiceSupplier ) { List components = new ArrayList<>(); - if (DiscoveryNode.isDataNode(environment.settings())) { + if (DiscoveryNode.canContainData(environment.settings())) { // only data nodes should be eligible to run the maintenance service. AsyncTaskIndexService indexService = new AsyncTaskIndexService<>( XPackPlugin.ASYNC_RESULTS_INDEX, diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingCalculateCapacityService.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingCalculateCapacityService.java index 06101117954e6..bbf4461702fe3 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingCalculateCapacityService.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/AutoscalingCalculateCapacityService.java @@ -268,7 +268,7 @@ private boolean calculateCurrentCapacityAccurate() { } private boolean nodeHasAccurateCapacity(DiscoveryNode node) { - if (node.isDataNode()) { + if (node.canContainData()) { // todo: multiple data path support. DiskUsage mostAvailable = clusterInfo.getNodeMostAvailableDiskUsages().get(node.getId()); DiskUsage leastAvailable = clusterInfo.getNodeLeastAvailableDiskUsages().get(node.getId()); @@ -296,7 +296,7 @@ private AutoscalingCapacity calculateCurrentCapacity() { } private AutoscalingCapacity.AutoscalingResources resourcesFor(DiscoveryNode node) { - long storage = node.isDataNode() + long storage = node.canContainData() ? Math.max( totalStorage(clusterInfo.getNodeLeastAvailableDiskUsages(), node), totalStorage(clusterInfo.getNodeMostAvailableDiskUsages(), node) diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowTasksExecutor.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowTasksExecutor.java index 85ac37d786bf1..694b3b56cc8d9 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowTasksExecutor.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowTasksExecutor.java @@ -128,7 +128,7 @@ public void validate(ShardFollowTask params, ClusterState clusterState) { public Assignment getAssignment(final ShardFollowTask params, final ClusterState clusterState) { final DiscoveryNode node = selectLeastLoadedNode( clusterState, - ((Predicate) DiscoveryNode::isDataNode).and(DiscoveryNode::isRemoteClusterClient) + ((Predicate) DiscoveryNode::canContainData).and(DiscoveryNode::isRemoteClusterClient) ); if (node == null) { return NO_ASSIGNMENT; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTierTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTierTests.java index 3b66969208816..6f44f725d8df1 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTierTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTierTests.java @@ -41,7 +41,7 @@ public void testNodeSelection() { final String[] dataNodes = StreamSupport.stream(discoveryNodes.getNodes().values().spliterator(), false) .map(n -> n.value) - .filter(DiscoveryNode::isDataNode) + .filter(DiscoveryNode::canContainData) .map(DiscoveryNode::getId) .toArray(String[]::new); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportExplainDataFrameAnalyticsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportExplainDataFrameAnalyticsAction.java index b05cfd253bf0f..0cdfd21be58b9 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportExplainDataFrameAnalyticsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportExplainDataFrameAnalyticsAction.java @@ -102,7 +102,7 @@ protected void doExecute(Task task, // added. We know the ML plugin is enabled on the current node, because this code is in it! DiscoveryNode localNode = clusterService.localNode(); boolean isMlNode = MachineLearning.isMlNode(localNode); - if (isMlNode || localNode.isMasterNode() || localNode.isDataNode() || localNode.isIngestNode()) { + if (isMlNode || localNode.isMasterNode() || localNode.canContainData() || localNode.isIngestNode()) { if (isMlNode == false) { logger.debug("estimating data frame analytics memory on non-ML node"); } diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshots.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshots.java index 6b0701d7a6f55..7a55ad24ee1b6 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshots.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshots.java @@ -324,7 +324,7 @@ public Collection createComponents( this.repositoriesServiceSupplier = repositoriesServiceSupplier; this.threadPool.set(threadPool); this.failShardsListener.set(new FailShardsOnInvalidLicenseClusterListener(getLicenseState(), clusterService.getRerouteService())); - if (DiscoveryNode.isDataNode(settings)) { + if (DiscoveryNode.canContainData(settings)) { final CacheService cacheService = new CacheService(settings, clusterService, threadPool, new PersistentCache(nodeEnvironment)); this.cacheService.set(cacheService); final FrozenCacheService frozenCacheService = new FrozenCacheService(nodeEnvironment, settings, threadPool); @@ -364,7 +364,7 @@ public void onIndexModule(IndexModule indexModule) { @Override public List getIndexFoldersDeletionListeners() { - if (DiscoveryNode.isDataNode(settings)) { + if (DiscoveryNode.canContainData(settings)) { return List.of(new SearchableSnapshotIndexFoldersDeletionListener(cacheService::get, frozenCacheService::get)); } return List.of(); diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/SearchableSnapshotIndexEventListener.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/SearchableSnapshotIndexEventListener.java index ded2accb2b753..bb6514290b774 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/SearchableSnapshotIndexEventListener.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/SearchableSnapshotIndexEventListener.java @@ -50,7 +50,7 @@ public SearchableSnapshotIndexEventListener( @Nullable CacheService cacheService, @Nullable FrozenCacheService frozenCacheService ) { - assert cacheService != null || DiscoveryNode.isDataNode(settings) == false; + assert cacheService != null || DiscoveryNode.canContainData(settings) == false; this.cacheService = cacheService; this.frozenCacheService = frozenCacheService; } diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/full/PersistentCache.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/full/PersistentCache.java index 975fa2aabaa40..bd3102bfe6b2f 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/full/PersistentCache.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/full/PersistentCache.java @@ -444,7 +444,7 @@ static Map loadDocuments(Path directoryPath) throws IOExceptio * @param nodeEnvironment the {@link NodeEnvironment} to cleanup */ public static void cleanUp(Settings settings, NodeEnvironment nodeEnvironment) { - final boolean isDataNode = DiscoveryNode.isDataNode(settings); + final boolean isDataNode = DiscoveryNode.canContainData(settings); if (isDataNode) { assert false : "should not be called on data nodes"; throw new IllegalStateException("Cannot clean searchable snapshot caches: node is a data node"); diff --git a/x-pack/plugin/snapshot-repo-test-kit/src/main/java/org/elasticsearch/repositories/blobstore/testkit/RepositoryAnalyzeAction.java b/x-pack/plugin/snapshot-repo-test-kit/src/main/java/org/elasticsearch/repositories/blobstore/testkit/RepositoryAnalyzeAction.java index b9b0c057fb5f3..91047334f743e 100644 --- a/x-pack/plugin/snapshot-repo-test-kit/src/main/java/org/elasticsearch/repositories/blobstore/testkit/RepositoryAnalyzeAction.java +++ b/x-pack/plugin/snapshot-repo-test-kit/src/main/java/org/elasticsearch/repositories/blobstore/testkit/RepositoryAnalyzeAction.java @@ -173,7 +173,7 @@ protected void doExecute(Task task, Request request, ActionListener li } private static boolean isSnapshotNode(DiscoveryNode discoveryNode) { - return (discoveryNode.isDataNode() || discoveryNode.isMasterNode()) + return (discoveryNode.canContainData() || discoveryNode.isMasterNode()) && RepositoriesService.isDedicatedVotingOnlyNode(discoveryNode.getRoles()) == false; } diff --git a/x-pack/plugin/voting-only-node/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/VotingOnlyNodePluginTests.java b/x-pack/plugin/voting-only-node/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/VotingOnlyNodePluginTests.java index b6bb1cc1d8930..b74e4df5b6e88 100644 --- a/x-pack/plugin/voting-only-node/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/VotingOnlyNodePluginTests.java +++ b/x-pack/plugin/voting-only-node/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/VotingOnlyNodePluginTests.java @@ -219,7 +219,7 @@ private AccessVerifyingRepo(RepositoryMetadata metadata, Environment environment protected BlobStore createBlobStore() throws Exception { final DiscoveryNode localNode = clusterService.state().nodes().getLocalNode(); if (localNode.getRoles().contains(VotingOnlyNodePlugin.VOTING_ONLY_NODE_ROLE)) { - assertTrue(localNode.isDataNode()); + assertTrue(localNode.canContainData()); } return super.createBlobStore(); } diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java index 8c7e1d0e173f4..1bf97bd05432b 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java @@ -530,7 +530,7 @@ public List> getExecutorBuilders(final Settings settings) { * @return A number between 5 and the number of processors */ static int getWatcherThreadPoolSize(final Settings settings) { - return getWatcherThreadPoolSize(DiscoveryNode.isDataNode(settings), EsExecutors.allocatedProcessors(settings)); + return getWatcherThreadPoolSize(DiscoveryNode.canContainData(settings), EsExecutors.allocatedProcessors(settings)); } static int getWatcherThreadPoolSize(final boolean isDataNode, final int allocatedProcessors) { diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherIndexingListener.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherIndexingListener.java index fe4ab63430772..914b2d3e84647 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherIndexingListener.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherIndexingListener.java @@ -202,7 +202,7 @@ public void clusterChanged(ClusterChangedEvent event) { return; } - if (event.state().nodes().getLocalNode().isDataNode() && event.metadataChanged()) { + if (event.state().nodes().getLocalNode().canContainData() && event.metadataChanged()) { try { IndexMetadata metadata = WatchStoreUtils.getConcreteIndex(Watch.INDEX, event.state().metadata()); if (metadata == null) { diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherLifeCycleService.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherLifeCycleService.java index 661d711f578bb..3b14a93ff50df 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherLifeCycleService.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherLifeCycleService.java @@ -99,7 +99,7 @@ public void clusterChanged(ClusterChangedEvent event) { boolean isWatcherStoppedManually = isWatcherStoppedManually(event.state()); boolean isStoppedOrStopping = stopStates.contains(this.state.get()); // if this is not a data node, we need to start it ourselves possibly - if (event.state().nodes().getLocalNode().isDataNode() == false && + if (event.state().nodes().getLocalNode().canContainData() == false && isWatcherStoppedManually == false && isStoppedOrStopping) { this.state.set(WatcherState.STARTING); watcherService.start(event.state(), () -> this.state.set(WatcherState.STARTED)); diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/trigger/schedule/engine/TickerScheduleTriggerEngine.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/trigger/schedule/engine/TickerScheduleTriggerEngine.java index 7656e3e977bcb..e4015e6d0a62c 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/trigger/schedule/engine/TickerScheduleTriggerEngine.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/trigger/schedule/engine/TickerScheduleTriggerEngine.java @@ -50,7 +50,7 @@ public class TickerScheduleTriggerEngine extends ScheduleTriggerEngine { public TickerScheduleTriggerEngine(Settings settings, ScheduleRegistry scheduleRegistry, Clock clock) { super(scheduleRegistry, clock); this.tickInterval = TICKER_INTERVAL_SETTING.get(settings); - this.ticker = new Ticker(DiscoveryNode.isDataNode(settings)); + this.ticker = new Ticker(DiscoveryNode.canContainData(settings)); } @Override From c04c0cd662e5c260324330ad582c90cf43c314af Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 30 Mar 2021 22:06:08 -0400 Subject: [PATCH 12/22] Fix more tests --- .../org/elasticsearch/transport/ConnectionProfileTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/test/java/org/elasticsearch/transport/ConnectionProfileTests.java b/server/src/test/java/org/elasticsearch/transport/ConnectionProfileTests.java index a30f4e7eb6a6e..4b975e6158d13 100644 --- a/server/src/test/java/org/elasticsearch/transport/ConnectionProfileTests.java +++ b/server/src/test/java/org/elasticsearch/transport/ConnectionProfileTests.java @@ -220,7 +220,7 @@ public void testDefaultConnectionProfile() { assertEquals(3, profile.getNumConnectionsPerType(TransportRequestOptions.Type.BULK)); profile = ConnectionProfile.buildDefaultConnectionProfile( - removeRoles(Set.of(DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.MASTER_ROLE)) + removeRoles(nonDataNode(), Set.of(DiscoveryNodeRole.MASTER_ROLE)) ); assertEquals(10, profile.getNumConnections()); assertEquals(1, profile.getNumConnectionsPerType(TransportRequestOptions.Type.PING)); From 4ebe1c4ab4e97d84abf185e61c3707cf91b56a13 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 30 Mar 2021 22:06:50 -0400 Subject: [PATCH 13/22] Fix more tests --- .../rest-api-spec/test/nodes.info/10_basic.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/nodes.info/10_basic.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/nodes.info/10_basic.yml index 5e44a4db8b19b..4d845b40a2194 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/nodes.info/10_basic.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/nodes.info/10_basic.yml @@ -25,12 +25,12 @@ setup: - is_true: nodes.$node_id.roles # the roles output is sorted - - match: { nodes.$node_id.roles.0: "data_cold" } - - match: { nodes.$node_id.roles.1: "data_content" } - - match: { nodes.$node_id.roles.2: "data_frozen" } - - match: { nodes.$node_id.roles.3: "data_hot" } - - match: { nodes.$node_id.roles.4: "data_warm" } - - match: { nodes.$node_id.roles.5: "data" } + - match: { nodes.$node_id.roles.0: "data" } + - match: { nodes.$node_id.roles.1: "data_cold" } + - match: { nodes.$node_id.roles.2: "data_content" } + - match: { nodes.$node_id.roles.3: "data_frozen" } + - match: { nodes.$node_id.roles.4: "data_hot" } + - match: { nodes.$node_id.roles.5: "data_warm" } - match: { nodes.$node_id.roles.6: "ingest" } - match: { nodes.$node_id.roles.7: "master" } - match: { nodes.$node_id.roles.8: "remote_cluster_client" } From c3bcfb7485e4026d77ecdbff1f1c68cef5122995 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 30 Mar 2021 22:08:29 -0400 Subject: [PATCH 14/22] Safety first --- .../java/org/elasticsearch/cluster/node/DiscoveryNodes.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java index 0382b17b5c004..a61881d3c408d 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java @@ -368,7 +368,7 @@ public String[] resolveNodes(String... nodes) { // the role is not a data role, we require an exact match (e.g., ingest) predicate = s -> s.contains(role); } - Function mutation; + final Function mutation; if (Booleans.parseBoolean(matchAttrValue, true)) { mutation = resolvedNodesIds::add; } else { From 5c8c179358d3d4ee23e0d0d6d272c051bb68bb45 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 31 Mar 2021 09:20:42 -0400 Subject: [PATCH 15/22] Revert inadvertent removal of handling coordinating_only nodes --- .../java/org/elasticsearch/cluster/node/DiscoveryNodes.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java index a61881d3c408d..1d5d7a8035851 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java @@ -379,6 +379,12 @@ public String[] resolveNodes(String... nodes) { mutation.apply(node.getId()); } } + } else if(DiscoveryNode.COORDINATING_ONLY.equals(matchAttrName)) { + if (Booleans.parseBoolean(matchAttrValue, true)) { + resolvedNodesIds.addAll(getCoordinatingOnlyNodes().keys()); + } else { + resolvedNodesIds.removeAll(getCoordinatingOnlyNodes().keys()); + } } else { for (DiscoveryNode node : this) { for (DiscoveryNodeRole role : Sets.difference(node.getRoles(), DiscoveryNodeRole.BUILT_IN_ROLES)) { From a08c1782095b02f2c01a20b7ee0cb95f938e58ae Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 31 Mar 2021 09:23:42 -0400 Subject: [PATCH 16/22] Clarify docs --- .../java/org/elasticsearch/cluster/node/DiscoveryNode.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java index 84c186bd6f0cc..bcc0c99b7030f 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -64,6 +64,9 @@ public static boolean isMasterNode(final Settings settings) { /** * Check if the given settings are indicative of having the top-level data role. * + * Note that if you want to test for whether or not the given settings are indicative of any role that can contain data, you should use + * {@link #canContainData(Settings)}. + * * @param settings the settings * @return true if the given settings are indicative of having the top-level data role, otherwise false */ @@ -74,6 +77,8 @@ public static boolean hasDataRole(final Settings settings) { /** * Check if the given settings are indicative of any role that can contain data. * + * Note that if you want to test for exactly the data role, you should use {@link #hasDataRole(Settings)}. + * * @param settings the settings * @return true if the given settings are indicative of having any role that can contain data, otherwise false */ From 2723620eb713764bd1b610a7914ff5f378e7365e Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 31 Mar 2021 09:35:39 -0400 Subject: [PATCH 17/22] Fix checkstyle --- .../java/org/elasticsearch/cluster/node/DiscoveryNode.java | 1 - .../java/org/elasticsearch/transport/ConnectionProfile.java | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java index bcc0c99b7030f..982f35862dc80 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; -import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.xcontent.ToXContentFragment; diff --git a/server/src/main/java/org/elasticsearch/transport/ConnectionProfile.java b/server/src/main/java/org/elasticsearch/transport/ConnectionProfile.java index 03da8187dd0a8..5ae109a590cf9 100644 --- a/server/src/main/java/org/elasticsearch/transport/ConnectionProfile.java +++ b/server/src/main/java/org/elasticsearch/transport/ConnectionProfile.java @@ -77,7 +77,8 @@ public static ConnectionProfile buildDefaultConnectionProfile(Settings settings) // if we are not master eligible we don't need a dedicated channel to publish the state builder.addConnections(DiscoveryNode.isMasterNode(settings) ? connectionsPerNodeState : 0, TransportRequestOptions.Type.STATE); // if we are not a data-node we don't need any dedicated channels for recovery - builder.addConnections(DiscoveryNode.canContainData(settings) ? connectionsPerNodeRecovery : 0, TransportRequestOptions.Type.RECOVERY); + builder.addConnections( + DiscoveryNode.canContainData(settings) ? connectionsPerNodeRecovery : 0, TransportRequestOptions.Type.RECOVERY); builder.addConnections(connectionsPerNodeReg, TransportRequestOptions.Type.REG); return builder.build(); } From dff08e3208f6432aaf3aa236a6ad5aa2a1cbd1ba Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 31 Mar 2021 10:00:52 -0400 Subject: [PATCH 18/22] Adjust test --- .../org/elasticsearch/xpack/core/DataTierTests.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTierTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTierTests.java index 6f44f725d8df1..44f29601430e7 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTierTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTierTests.java @@ -73,15 +73,24 @@ public void testNodeSelection() { .map(DiscoveryNode::getId) .toArray(String[]::new); + final String[] frozenNodes = + StreamSupport.stream(discoveryNodes.getNodes().values().spliterator(), false) + .map(n -> n.value) + .filter(DataTier::isFrozenNode) + .map(DiscoveryNode::getId) + .toArray(String[]::new); + assertThat(discoveryNodes.resolveNodes("data:true"), arrayContainingInAnyOrder(dataNodes)); assertThat(discoveryNodes.resolveNodes("data_content:true"), arrayContainingInAnyOrder(contentNodes)); assertThat(discoveryNodes.resolveNodes("data_hot:true"), arrayContainingInAnyOrder(hotNodes)); assertThat(discoveryNodes.resolveNodes("data_warm:true"), arrayContainingInAnyOrder(warmNodes)); assertThat(discoveryNodes.resolveNodes("data_cold:true"), arrayContainingInAnyOrder(coldNodes)); + assertThat(discoveryNodes.resolveNodes("data_frozen:true"), arrayContainingInAnyOrder(frozenNodes)); Set allTiers = new HashSet<>(Arrays.asList(contentNodes)); allTiers.addAll(Arrays.asList(hotNodes)); allTiers.addAll(Arrays.asList(warmNodes)); allTiers.addAll(Arrays.asList(coldNodes)); + allTiers.addAll(Arrays.asList(frozenNodes)); assertThat(discoveryNodes.resolveNodes("data:true"), arrayContainingInAnyOrder(allTiers.toArray(Strings.EMPTY_ARRAY))); } @@ -142,10 +151,6 @@ private static DiscoveryNode newNode(int nodeId, Map attributes, private static List randomNodes(final int numNodes) { Set allRoles = new HashSet<>(DiscoveryNodeRole.BUILT_IN_ROLES); allRoles.remove(DiscoveryNodeRole.DATA_ROLE); - allRoles.add(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE); - allRoles.add(DiscoveryNodeRole.DATA_HOT_NODE_ROLE); - allRoles.add(DiscoveryNodeRole.DATA_WARM_NODE_ROLE); - allRoles.add(DiscoveryNodeRole.DATA_COLD_NODE_ROLE); List nodesList = new ArrayList<>(); for (int i = 0; i < numNodes; i++) { Map attributes = new HashMap<>(); From f4377240558f7924e23af5b4da7c03c92671f1a0 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 31 Mar 2021 10:04:37 -0400 Subject: [PATCH 19/22] Fix test --- .../collector/cluster/ClusterStatsMonitoringDocTests.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java index 8584ee0e04039..21372316e3dba 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java @@ -477,6 +477,11 @@ public void testToXContent() throws IOException { + " \"total\": 1," + " \"coordinating_only\": 0," + " \"data\": 0," + + " \"data_cold\": 0," + + " \"data_content\": 0," + + " \"data_frozen\": 0," + + " \"data_hot\": 0," + + " \"data_warm\": 0," + " \"ingest\": 0," + " \"master\": 1," + " \"remote_cluster_client\": 0" From 66364bb2b2b4fda451e06319c142e80cef469d71 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 31 Mar 2021 11:55:15 -0400 Subject: [PATCH 20/22] Fix tests --- .../cache/full/PersistentCacheTests.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/full/PersistentCacheTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/full/PersistentCacheTests.java index 0f89ccb68768f..e426e6e48e182 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/full/PersistentCacheTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/full/PersistentCacheTests.java @@ -13,6 +13,7 @@ import org.apache.lucene.mockfile.FilterFileChannel; import org.apache.lucene.mockfile.FilterFileSystemProvider; import org.apache.lucene.mockfile.FilterPath; +import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.io.PathUtilsForTesting; import org.elasticsearch.common.settings.Settings; @@ -188,7 +189,10 @@ public void testCleanUp() throws Exception { } final Settings nodeSettings = Settings.builder() - .put(NODE_ROLES_SETTING.getKey(), randomValueOtherThan(DATA_ROLE, () -> randomFrom(BUILT_IN_ROLES)).roleName()) + .put( + NODE_ROLES_SETTING.getKey(), + randomValueOtherThanMany(DiscoveryNodeRole::canContainData, () -> randomFrom(BUILT_IN_ROLES)).roleName() + ) .build(); assertTrue(cacheFiles.stream().allMatch(Files::exists)); From 7b57aec6d95cbda1080ee349c125b94d43eaa336 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 31 Mar 2021 13:07:54 -0400 Subject: [PATCH 21/22] Additonal test fixes --- .../action/admin/cluster/stats/ClusterStatsIT.java | 4 ++++ .../java/org/elasticsearch/env/NodeEnvironmentIT.java | 2 +- .../java/org/elasticsearch/env/NodeRepurposeCommandIT.java | 4 +++- .../main/java/org/elasticsearch/test/InternalTestCluster.java | 3 ++- .../searchablesnapshots/cache/full/PersistentCacheTests.java | 3 +-- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIT.java b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIT.java index 8feb59db40303..e90338e0cbcf0 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIT.java @@ -58,6 +58,10 @@ public void testNodeCounts() { internalCluster().startNode(); Map expectedCounts = new HashMap<>(); expectedCounts.put(DiscoveryNodeRole.DATA_ROLE.roleName(), 1); + expectedCounts.put(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE.roleName(), 1); + expectedCounts.put(DiscoveryNodeRole.DATA_COLD_NODE_ROLE.roleName(), 1); + expectedCounts.put(DiscoveryNodeRole.DATA_HOT_NODE_ROLE.roleName(), 1); + expectedCounts.put(DiscoveryNodeRole.DATA_WARM_NODE_ROLE.roleName(), 1); expectedCounts.put(DiscoveryNodeRole.MASTER_ROLE.roleName(), 1); expectedCounts.put(DiscoveryNodeRole.INGEST_ROLE.roleName(), 1); expectedCounts.put(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName(), 1); diff --git a/server/src/internalClusterTest/java/org/elasticsearch/env/NodeEnvironmentIT.java b/server/src/internalClusterTest/java/org/elasticsearch/env/NodeEnvironmentIT.java index 83719aa4144ad..386860a401e9c 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/env/NodeEnvironmentIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/env/NodeEnvironmentIT.java @@ -68,7 +68,7 @@ public void testStartFailureOnDataForNonDataNode() throws Exception { internalCluster().restartRandomDataNode(new InternalTestCluster.RestartCallback() { @Override public Settings onNodeStopped(String nodeName) { - return NodeRoles.removeRoles(Set.of(DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.MASTER_ROLE)); + return NodeRoles.removeRoles(nonDataNode(), Set.of(DiscoveryNodeRole.MASTER_ROLE)); } })); if (writeDanglingIndices) { diff --git a/server/src/internalClusterTest/java/org/elasticsearch/env/NodeRepurposeCommandIT.java b/server/src/internalClusterTest/java/org/elasticsearch/env/NodeRepurposeCommandIT.java index ab0ce31304dfd..29c860c78535c 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/env/NodeRepurposeCommandIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/env/NodeRepurposeCommandIT.java @@ -14,6 +14,8 @@ import org.elasticsearch.test.ESIntegTestCase; import org.hamcrest.Matcher; +import static org.elasticsearch.test.NodeRoles.nonDataNode; +import static org.elasticsearch.test.NodeRoles.nonMasterNode; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.containsString; @@ -45,7 +47,7 @@ public void testRepurpose() throws Exception { final Settings dataNodeDataPathSettings = internalCluster().dataPathSettings(dataNode); // put some unknown role here to make sure the tool does not bark when encountering an unknown role - final Settings noMasterNoDataSettings = Settings.builder().putList("node.roles", "unknown_role").build(); + final Settings noMasterNoDataSettings = nonMasterNode(nonDataNode()); final Settings noMasterNoDataSettingsForMasterNode = Settings.builder() .put(noMasterNoDataSettings) diff --git a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java index 7e71658b65ead..77cc8a90141cc 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java @@ -145,6 +145,7 @@ import static org.elasticsearch.test.NodeRoles.dataOnlyNode; import static org.elasticsearch.test.NodeRoles.masterOnlyNode; import static org.elasticsearch.test.NodeRoles.noRoles; +import static org.elasticsearch.test.NodeRoles.nonDataNode; import static org.elasticsearch.test.NodeRoles.onlyRole; import static org.elasticsearch.test.NodeRoles.removeRoles; import static org.hamcrest.Matchers.equalTo; @@ -1048,7 +1049,7 @@ private synchronized void reset(boolean wipeData) throws IOException { for (int i = 0; i < numSharedDedicatedMasterNodes; i++) { final Settings nodeSettings = getNodeSettings(i, sharedNodesSeeds[i], Settings.EMPTY); - settings.add(removeRoles(nodeSettings, Set.of(DiscoveryNodeRole.DATA_ROLE))); + settings.add(nonDataNode(nodeSettings)); } for (int i = numSharedDedicatedMasterNodes; i < numSharedDedicatedMasterNodes + numSharedDataNodes; i++) { final Settings nodeSettings = getNodeSettings(i, sharedNodesSeeds[i], Settings.EMPTY); diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/full/PersistentCacheTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/full/PersistentCacheTests.java index e426e6e48e182..f3ede5724e660 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/full/PersistentCacheTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/full/PersistentCacheTests.java @@ -48,11 +48,10 @@ import java.util.stream.Collectors; import static org.elasticsearch.cluster.node.DiscoveryNodeRole.BUILT_IN_ROLES; -import static org.elasticsearch.cluster.node.DiscoveryNodeRole.DATA_ROLE; +import static org.elasticsearch.node.NodeRoleSettings.NODE_ROLES_SETTING; import static org.elasticsearch.xpack.searchablesnapshots.cache.common.TestUtils.assertCacheFileEquals; import static org.elasticsearch.xpack.searchablesnapshots.cache.common.TestUtils.randomPopulateAndReads; import static org.elasticsearch.xpack.searchablesnapshots.cache.common.TestUtils.sumOfCompletedRangesLengths; -import static org.elasticsearch.node.NodeRoleSettings.NODE_ROLES_SETTING; import static org.elasticsearch.xpack.searchablesnapshots.cache.full.PersistentCache.createCacheIndexWriter; import static org.elasticsearch.xpack.searchablesnapshots.cache.full.PersistentCache.resolveCacheIndexFolder; import static org.hamcrest.Matchers.equalTo; From edc577040be68f35481e6793a694dba13771ef06 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 31 Mar 2021 14:13:14 -0400 Subject: [PATCH 22/22] The final test? --- .../elasticsearch/action/admin/cluster/stats/ClusterStatsIT.java | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIT.java b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIT.java index e90338e0cbcf0..07f6a97e89332 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIT.java @@ -60,6 +60,7 @@ public void testNodeCounts() { expectedCounts.put(DiscoveryNodeRole.DATA_ROLE.roleName(), 1); expectedCounts.put(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE.roleName(), 1); expectedCounts.put(DiscoveryNodeRole.DATA_COLD_NODE_ROLE.roleName(), 1); + expectedCounts.put(DiscoveryNodeRole.DATA_FROZEN_NODE_ROLE.roleName(), 1); expectedCounts.put(DiscoveryNodeRole.DATA_HOT_NODE_ROLE.roleName(), 1); expectedCounts.put(DiscoveryNodeRole.DATA_WARM_NODE_ROLE.roleName(), 1); expectedCounts.put(DiscoveryNodeRole.MASTER_ROLE.roleName(), 1);