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..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 @@ -26,7 +26,11 @@ 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.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" } 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..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 @@ -58,6 +58,11 @@ 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_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); 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/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 648fd71158100..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; @@ -62,21 +61,28 @@ 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. + * + * 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 */ - public static boolean isDataNode(final Settings settings) { - return getRolesFromSettings(settings).stream().anyMatch(DiscoveryNodeRole::canContainData); + public static boolean hasDataRole(final Settings settings) { + return hasRole(settings, DiscoveryNodeRole.DATA_ROLE); } /** - * 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. + * 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 */ - 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 canContainData(final Settings settings) { + return getRolesFromSettings(settings).stream().anyMatch(DiscoveryNodeRole::canContainData); } public static boolean isIngestNode(final Settings settings) { @@ -331,7 +337,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/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/cluster/node/DiscoveryNodes.java b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java index ffd2e00a96a47..1d5d7a8035851 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java @@ -30,6 +30,9 @@ 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,25 +353,33 @@ 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()); + 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(dataNodes.keys()); + // the role is not a data role, we require an exact match (e.g., ingest) + predicate = s -> s.contains(role); } - } else if (DiscoveryNodeRole.MASTER_ROLE.roleName().equals(matchAttrName)) { + final Function mutation; if (Booleans.parseBoolean(matchAttrValue, true)) { - resolvedNodesIds.addAll(masterNodes.keys()); + mutation = resolvedNodesIds::add; } else { - resolvedNodesIds.removeAll(masterNodes.keys()); + mutation = resolvedNodesIds::remove; } - } else if (DiscoveryNodeRole.INGEST_ROLE.roleName().equals(matchAttrName)) { - if (Booleans.parseBoolean(matchAttrValue, true)) { - resolvedNodesIds.addAll(ingestNodes.keys()); - } else { - resolvedNodesIds.removeAll(ingestNodes.keys()); + for (final DiscoveryNode node : this) { + if (predicate.test(node.getRoles())) { + mutation.apply(node.getId()); + } } - } else if (DiscoveryNode.COORDINATING_ONLY.equals(matchAttrName)) { + } else if(DiscoveryNode.COORDINATING_ONLY.equals(matchAttrName)) { if (Booleans.parseBoolean(matchAttrValue, true)) { resolvedNodesIds.addAll(getCoordinatingOnlyNodes().keys()); } else { @@ -679,14 +690,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 740319ab595ea..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.isDataNodeBasedOnNamingConvention(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.isDataNodeBasedOnNamingConvention(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/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/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..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.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/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 diff --git a/server/src/test/java/org/elasticsearch/env/NodeRepurposeCommandTests.java b/server/src/test/java/org/elasticsearch/env/NodeRepurposeCommandTests.java index c00270e013d26..4321f29c8b493 100644 --- a/server/src/test/java/org/elasticsearch/env/NodeRepurposeCommandTests.java +++ b/server/src/test/java/org/elasticsearch/env/NodeRepurposeCommandTests.java @@ -71,8 +71,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/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/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)); 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..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; @@ -174,11 +175,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 +715,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"; } } @@ -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/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() { 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/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/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/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..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 @@ -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; @@ -131,9 +131,6 @@ 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) - ); ClusterState state = ClusterState.builder(new ClusterName("test")).build(); state = addRandomIndices(hotNodes, hotNodes, state); state = addDataNodes(DATA_HOT_NODE_ROLE, "hot", state, hotNodes); @@ -165,9 +162,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 +264,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 +273,7 @@ public void testMoveToEmpty() { moveToCold(candidates), ReactiveStorageDeciderService.AllocationState::storagePreventsRemainOrMove, allocatedCandidateShards, - DataTier.DATA_COLD_NODE_ROLE + DiscoveryNodeRole.DATA_COLD_NODE_ROLE ); } @@ -397,7 +394,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/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/main/java/org/elasticsearch/xpack/core/DataTier.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/DataTier.java index efe34f777b937..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 @@ -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,24 @@ 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 +93,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..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; @@ -377,16 +373,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..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 @@ -54,10 +54,11 @@ 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..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 @@ -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); @@ -73,64 +73,61 @@ 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))); } 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) - ); 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) - ); 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) - ); 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) - ); 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 +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(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); 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/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/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" 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/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..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 @@ -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; @@ -47,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; @@ -188,7 +188,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)); 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..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,7 @@ 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; import org.elasticsearch.env.NodeEnvironment; @@ -17,13 +17,11 @@ 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; import java.io.IOException; -import java.util.Set; import static org.elasticsearch.node.Node.NODE_NAME_SETTING; @@ -197,13 +195,10 @@ 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) - ); 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( 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