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 f9060ff6c58c7..415a467d28d25 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIT.java @@ -60,6 +60,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/client/transport/TransportClientIT.java b/server/src/internalClusterTest/java/org/elasticsearch/client/transport/TransportClientIT.java index 265ac99860eda..5bb5024dde432 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/client/transport/TransportClientIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/client/transport/TransportClientIT.java @@ -42,7 +42,7 @@ public void testPickingUpChangesInDiscoveryNode() { String nodeName = internalCluster().startNode(nonDataNode()); TransportClient client = (TransportClient) internalCluster().client(nodeName); - assertThat(client.connectedNodes().get(0).isDataNode(), equalTo(false)); + assertThat(client.connectedNodes().get(0).canContainData(), equalTo(false)); } diff --git a/server/src/internalClusterTest/java/org/elasticsearch/env/NodeEnvironmentIT.java b/server/src/internalClusterTest/java/org/elasticsearch/env/NodeEnvironmentIT.java index 5cfc4d8c2ea81..7557249defdbb 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/env/NodeEnvironmentIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/env/NodeEnvironmentIT.java @@ -11,6 +11,7 @@ import org.elasticsearch.Version; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.CheckedConsumer; +import org.elasticsearch.common.collect.Set; import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.gateway.PersistedClusterStateService; @@ -22,9 +23,6 @@ import java.io.IOException; import java.nio.file.Path; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; import java.util.List; import static org.elasticsearch.test.NodeRoles.nonDataNode; @@ -62,9 +60,7 @@ public void testStartFailureOnDataForNonDataNode() throws Exception { internalCluster().restartRandomDataNode(new InternalTestCluster.RestartCallback() { @Override public Settings onNodeStopped(String nodeName) { - return NodeRoles.removeRoles(Collections.unmodifiableSet( - new HashSet<>(Arrays.asList(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 cd41e57b201eb..c52ba851ad9c1 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 a8310d9bb2dc4..7d8aa02d7f5e2 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/index/store/CorruptedFileIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/index/store/CorruptedFileIT.java @@ -324,7 +324,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); } } @@ -384,7 +384,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 cb604b109ebc3..49bb330e79037 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 73b503901981e..702eaa91c6f75 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 @@ -333,7 +333,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 e6edd1b2e7ae6..b1313dc9024dc 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 bf760ef105aa6..62eec7e114edf 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 847ddc35760ab..29938314435f9 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/search/ccs/CrossClusterSearchIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/search/ccs/CrossClusterSearchIT.java @@ -111,7 +111,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 fec357ab4e412..999c636807e90 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 c3b5eed5704e4..22cdfc5e65344 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; @@ -47,7 +46,7 @@ public class DiscoveryNode implements Writeable, ToXContentFragment { public static boolean nodeRequiresLocalStorage(Settings settings) { boolean localStorageEnable = Node.NODE_LOCAL_STORAGE_SETTING.get(settings); - if (localStorageEnable == false && (isDataNode(settings) || isMasterNode(settings))) { + if (localStorageEnable == false && (canContainData(settings) || isMasterNode(settings))) { // TODO: make this a proper setting validation logic, requiring multi-settings validation throw new IllegalArgumentException("storage can not be disabled for master and data nodes"); } @@ -74,21 +73,28 @@ public static boolean isMasterNode(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) { @@ -388,7 +394,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 bf5c189e56981..3854a1c0d483b 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeRole.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeRole.java @@ -9,9 +9,11 @@ package org.elasticsearch.cluster.node; import org.elasticsearch.Version; +import org.elasticsearch.common.collect.Set; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.transport.RemoteClusterService; import java.util.Arrays; @@ -78,8 +80,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( @@ -150,13 +150,126 @@ 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)), + Setting.Property.Deprecated, + Setting.Property.NodeScope + ); + } + + @Override + public DiscoveryNodeRole getCompatibilityRole(Version nodeVersion) { + return nodeVersion.before(Version.V_7_10_0) ? DiscoveryNodeRole.DATA_ROLE : this; + } + }; + + 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 + ); + } + + @Override + public DiscoveryNodeRole getCompatibilityRole(Version nodeVersion) { + return nodeVersion.before(Version.V_7_10_0) ? DiscoveryNodeRole.DATA_ROLE : this; + } + }; + + 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 + ); + } + + @Override + public DiscoveryNodeRole getCompatibilityRole(Version nodeVersion) { + return nodeVersion.before(Version.V_7_10_0) ? DiscoveryNodeRole.DATA_ROLE : this; + } + }; + + 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 + ); + } + + @Override + public DiscoveryNodeRole getCompatibilityRole(Version nodeVersion) { + return nodeVersion.before(Version.V_7_10_0) ? DiscoveryNodeRole.DATA_ROLE : this; + } + }; + + 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 + ); + } + + }; /** * Represents the role for an ingest node. @@ -202,8 +315,18 @@ public Setting legacySetting() { /** * The built-in node roles. */ - public static SortedSet BUILT_IN_ROLES = Collections.unmodifiableSortedSet( - new TreeSet<>(Arrays.asList(DATA_ROLE, INGEST_ROLE, MASTER_ROLE, REMOTE_CLUSTER_CLIENT_ROLE))); + public static final SortedSet BUILT_IN_ROLES = + 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()); /** * The version that {@link #REMOTE_CLUSTER_CLIENT_ROLE} is introduced. Nodes before this version do not have that role even 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 813d771f25c1e..d9cd58eff2a92 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; @@ -363,25 +366,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 { @@ -696,14 +707,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/common/util/set/Sets.java b/server/src/main/java/org/elasticsearch/common/util/set/Sets.java index a2504393ceff9..8b9165d222101 100644 --- a/server/src/main/java/org/elasticsearch/common/util/set/Sets.java +++ b/server/src/main/java/org/elasticsearch/common/util/set/Sets.java @@ -97,7 +97,28 @@ public static SortedSet sortedDifference(Set left, Set right) { return left.stream().filter(k -> right.contains(k) == false).collect(new SortedSetCollector<>()); } - private static class SortedSetCollector implements Collector, SortedSet> { + /** + * Returns a {@link Collector} that accumulates the input elements into a sorted set. + * + * @param the type of the input elements + * @return a sorted set + */ + public static Collector, SortedSet> toSortedSet() { + return new SortedSetCollector<>(); + } + + /** + * Returns a {@link Collector} that accumulates the input elements into a sorted set and finishes the resulting set into an + * unmodifiable set. The resulting read-only view through the unmodifiable set is a sorted set. + * + * @param the type of the input elements + * @return an unmodifiable set where the underlying set is sorted + */ + public static Collector, SortedSet> toUnmodifiableSortedSet() { + return new UnmodifiableSortedSetCollector<>(); + } + + abstract static class AbstractSortedSetCollector implements Collector, SortedSet> { @Override public Supplier> supplier() { @@ -106,7 +127,7 @@ public Supplier> supplier() { @Override public BiConsumer, T> accumulator() { - return (s, e) -> s.add(e); + return SortedSet::add; } @Override @@ -117,13 +138,21 @@ public BinaryOperator> combiner() { }; } + public abstract Function, SortedSet> finisher(); + + public abstract Set characteristics(); + + } + + private static class SortedSetCollector extends AbstractSortedSetCollector { + @Override public Function, SortedSet> finisher() { return Function.identity(); } static final Set CHARACTERISTICS = - Collections.unmodifiableSet(EnumSet.of(Collector.Characteristics.IDENTITY_FINISH)); + Collections.unmodifiableSet(EnumSet.of(Characteristics.IDENTITY_FINISH)); @Override public Set characteristics() { @@ -132,6 +161,20 @@ public Set characteristics() { } + private static class UnmodifiableSortedSetCollector extends AbstractSortedSetCollector { + + @Override + public Function, SortedSet> finisher() { + return Collections::unmodifiableSortedSet; + } + + @Override + public Set characteristics() { + return Collections.emptySet(); + } + + } + public static Set union(Set left, Set right) { Objects.requireNonNull(left); Objects.requireNonNull(right); diff --git a/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java b/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java index 0c7d2dd0dce70..6719a91c63177 100644 --- a/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java +++ b/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java @@ -305,11 +305,11 @@ public NodeEnvironment(Settings settings, Environment environment) throws IOExce applySegmentInfosTrace(settings); assertCanWrite(); - if (DiscoveryNode.isMasterNode(settings) || DiscoveryNode.isDataNode(settings)) { + if (DiscoveryNode.isMasterNode(settings) || DiscoveryNode.canContainData(settings)) { ensureAtomicMoveSupported(nodePaths); } - 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 7ee3078296f98..a8683058b99c8 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; } @@ -65,7 +65,7 @@ protected boolean validateBeforeLock(Terminal terminal, Environment env) { @Override protected void processNodePaths(Terminal terminal, Path[] dataPaths, int nodeLockId, 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 2777bf0c747c4..40c72f5ee58c8 100644 --- a/server/src/main/java/org/elasticsearch/gateway/GatewayMetaState.java +++ b/server/src/main/java/org/elasticsearch/gateway/GatewayMetaState.java @@ -24,10 +24,10 @@ import org.elasticsearch.cluster.coordination.CoordinationState.PersistedState; import org.elasticsearch.cluster.coordination.InMemoryPersistedState; import org.elasticsearch.cluster.metadata.IndexMetadata; +import org.elasticsearch.cluster.metadata.IndexMetadataVerifier; import org.elasticsearch.cluster.metadata.IndexTemplateMetadata; import org.elasticsearch.cluster.metadata.Manifest; import org.elasticsearch.cluster.metadata.Metadata; -import org.elasticsearch.cluster.metadata.IndexMetadataVerifier; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.collect.ImmutableOpenMap; @@ -115,14 +115,14 @@ public void start(Settings settings, TransportService transportService, ClusterS prepareInitialClusterState(transportService, clusterService, clusterState), transportService.getThreadPool()::relativeTimeInMillis); - if (DiscoveryNode.isMasterNode(settings) || DiscoveryNode.isDataNode(settings)) { + if (DiscoveryNode.isMasterNode(settings) || DiscoveryNode.canContainData(settings)) { clusterService.addLowPriorityApplier(new GatewayClusterApplier(incrementalClusterStateWriter)); } persistedState.set(new InMemoryPersistedState(manifestClusterStateTuple.v1().getCurrentTerm(), clusterState)); return; } - if (DiscoveryNode.isMasterNode(settings) || DiscoveryNode.isDataNode(settings)) { + if (DiscoveryNode.isMasterNode(settings) || DiscoveryNode.canContainData(settings)) { try { final PersistedClusterStateService.OnDiskState onDiskState = persistedClusterStateService.loadBestOnDiskState(); @@ -156,7 +156,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 3077b26132283..11b8c0f0d5c4f 100644 --- a/server/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/server/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -1604,7 +1604,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 f7a3507a97451..f05f93bfb2e85 100644 --- a/server/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java +++ b/server/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java @@ -178,14 +178,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 078d38c12c078..3543338c7f20d 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 bf3fe82130c4a..d1611882f0d8f 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 0cee1c6dafe33..87ed310eb5143 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 fdef122aa6423..8b90838d0c7aa 100644 --- a/server/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java +++ b/server/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java @@ -16,6 +16,7 @@ import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.action.ResultDeduplicator; import org.elasticsearch.cluster.ClusterChangedEvent; import org.elasticsearch.cluster.ClusterStateListener; import org.elasticsearch.cluster.SnapshotsInProgress; @@ -46,7 +47,6 @@ import org.elasticsearch.repositories.ShardGenerations; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportException; -import org.elasticsearch.action.ResultDeduplicator; import org.elasticsearch.transport.TransportResponseHandler; import org.elasticsearch.transport.TransportService; @@ -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 602abc827f44c..10f84d9d8d628 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 43de16267c257..df0413860de0a 100644 --- a/server/src/main/java/org/elasticsearch/transport/SniffConnectionStrategy.java +++ b/server/src/main/java/org/elasticsearch/transport/SniffConnectionStrategy.java @@ -188,7 +188,7 @@ public String getKey(final String key) { 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 cd57ca95c9e2a..d9f0cdcdf7e14 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 @@ -133,7 +133,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 d81e3739a46be..8ceb5c1a3ede6 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 5e8d372ef6f14..dbd24f3f9ce74 100644 --- a/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java +++ b/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java @@ -31,8 +31,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -477,9 +475,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, - Collections.unmodifiableSet(new HashSet<>(Arrays.asList(DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.MASTER_ROLE))))) + .put(NodeRoles.removeRoles(nonDataNode(settings), org.elasticsearch.common.collect.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 a3a4386881938..e000cb03894fc 100644 --- a/server/src/test/java/org/elasticsearch/env/NodeRepurposeCommandTests.java +++ b/server/src/test/java/org/elasticsearch/env/NodeRepurposeCommandTests.java @@ -20,6 +20,7 @@ import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.CheckedConsumer; import org.elasticsearch.common.CheckedRunnable; +import org.elasticsearch.common.collect.Set; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.BigArrays; @@ -33,8 +34,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; import java.util.stream.Stream; import static org.elasticsearch.env.NodeRepurposeCommand.NO_CLEANUP; @@ -72,10 +71,8 @@ public void createNodePaths() throws IOException { } } dataNoMasterSettings = nonMasterNode(dataMasterSettings); - noDataNoMasterSettings = removeRoles( - dataMasterSettings, - Collections.unmodifiableSet(new HashSet<>(Arrays.asList(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 177f0f220b60a..760dda2d779e0 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/SnapshotResiliencyTests.java +++ b/server/src/test/java/org/elasticsearch/snapshots/SnapshotResiliencyTests.java @@ -1288,7 +1288,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 2200df8f8c9e4..f495f3d04c83c 100644 --- a/server/src/test/java/org/elasticsearch/transport/ConnectionProfileTests.java +++ b/server/src/test/java/org/elasticsearch/transport/ConnectionProfileTests.java @@ -8,16 +8,15 @@ package org.elasticsearch.transport; import org.elasticsearch.cluster.node.DiscoveryNodeRole; +import org.elasticsearch.common.collect.Set; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.test.ESTestCase; import org.hamcrest.Matchers; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.EnumSet; -import java.util.HashSet; import java.util.List; import static org.elasticsearch.test.NodeRoles.nonDataNode; @@ -221,9 +220,7 @@ public void testDefaultConnectionProfile() { assertEquals(3, profile.getNumConnectionsPerType(TransportRequestOptions.Type.BULK)); profile = ConnectionProfile.buildDefaultConnectionProfile( - removeRoles( - Collections.unmodifiableSet(new HashSet<>(Arrays.asList(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 ce2b80d4cf00e..e5563a68d36b1 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ExternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ExternalTestCluster.java @@ -97,7 +97,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 2c64d3986fc91..73daa06b412eb 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java @@ -159,6 +159,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.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; @@ -189,11 +190,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()); @@ -757,11 +758,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"; } } @@ -1210,7 +1211,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, defaultMinMasterNodes); - settings.add(removeRoles(nodeSettings, Collections.singleton(DiscoveryNodeRole.DATA_ROLE))); + settings.add(nonDataNode(nodeSettings)); } for (int i = numSharedDedicatedMasterNodes; i < numSharedDedicatedMasterNodes + numSharedDataNodes; i++) { final Settings nodeSettings = getNodeSettings(i, sharedNodesSeeds[i], Settings.EMPTY, defaultMinMasterNodes); 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 b1bd4efb556a6..19d989aae5098 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java +++ b/test/framework/src/main/java/org/elasticsearch/test/NodeRoles.java @@ -107,7 +107,9 @@ public static Settings nonDataNode() { } public static Settings nonDataNode(final Settings settings) { - return removeRoles(settings, Collections.singleton(DiscoveryNodeRole.DATA_ROLE)); + final Set dataRoles = + DiscoveryNodeRole.BUILT_IN_ROLES.stream().filter(DiscoveryNodeRole::canContainData).collect(Collectors.toSet()); + 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 bacd8282b5fb6..eda28da0298a1 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 @@ -363,7 +363,7 @@ public Settings transportClientSettings() { 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 defb838f39b55..337c417a4fff8 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 @@ -74,7 +74,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 6b0951bc96f55..b880410267591 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 @@ -23,8 +23,8 @@ import org.elasticsearch.node.Node; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; -import org.elasticsearch.xpack.autoscaling.LocalStateAutoscaling; import org.elasticsearch.test.NodeRoles; +import org.elasticsearch.xpack.autoscaling.LocalStateAutoscaling; import org.elasticsearch.xpack.autoscaling.action.GetAutoscalingCapacityAction; import org.elasticsearch.xpack.autoscaling.action.PutAutoscalingPolicyAction; import org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider; @@ -124,7 +124,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); @@ -167,7 +167,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 a81787748a0d7..388ccb75e1b53 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 @@ -269,7 +269,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()); @@ -297,7 +297,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 4ddab1e37b1fd..b425c093044ef 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 org.elasticsearch.common.collect.List.of(DiscoveryNodeRole.DATA_ROLE, DataTier.DATA_HOT_NODE_ROLE); + return org.elasticsearch.common.collect.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 ceb8aa64a9380..b40fdd68fd138 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 @@ -46,7 +46,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; @@ -89,11 +88,11 @@ public List> deciderSettings() { public List roles() { return org.elasticsearch.common.collect.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 49fd215f09fd0..b4d47a6ac35f6 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 @@ -64,8 +64,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; @@ -130,14 +130,6 @@ public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAl @Before public void setup() { - DiscoveryNode.setAdditionalRoles( - org.elasticsearch.common.collect.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); @@ -169,9 +161,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 { @@ -271,7 +263,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(); @@ -280,7 +272,7 @@ public void testMoveToEmpty() { moveToCold(candidates), ReactiveStorageDeciderService.AllocationState::storagePreventsRemainOrMove, allocatedCandidateShards, - DataTier.DATA_COLD_NODE_ROLE + DiscoveryNodeRole.DATA_COLD_NODE_ROLE ); } @@ -401,7 +393,10 @@ private static void verifyScale(ClusterState state, long expectedDifference, Str new ClusterSettings(Settings.EMPTY, DataTierAllocationDeciderTests.ALL_SETTINGS), createAllocationDeciders(allocationDeciders) ); - TestAutoscalingDeciderContext context = createContext(state, org.elasticsearch.common.collect.Set.of(DataTier.DATA_HOT_NODE_ROLE)); + TestAutoscalingDeciderContext context = createContext( + state, + org.elasticsearch.common.collect.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 1032eb0d69a32..ed869b4fc6dbd 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 @@ -52,7 +52,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, org.elasticsearch.common.collect.Set.of(), - org.elasticsearch.common.collect.Set.of(DataTier.DATA_WARM_NODE_ROLE) + org.elasticsearch.common.collect.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 5ece48871bf02..f028b1af5ffdb 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,13 +128,14 @@ public void validate(ShardFollowTask params, ClusterState clusterState) { @Override public Assignment getAssignment(final ShardFollowTask params, final ClusterState clusterState) { - DiscoveryNode selectedNode = selectLeastLoadedNode(clusterState, - ((Predicate) DiscoveryNode::isDataNode).and(DiscoveryNode::isRemoteClusterClient) + DiscoveryNode selectedNode = selectLeastLoadedNode( + clusterState, + ((Predicate) DiscoveryNode::canContainData).and(DiscoveryNode::isRemoteClusterClient) ); if (selectedNode == null) { // best effort as nodes before 7.8 might not be able to connect to remote clusters selectedNode = selectLeastLoadedNode(clusterState, - node -> node.isDataNode() && node.getVersion().before(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE_VERSION)); + node -> node.canContainData() && node.getVersion().before(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE_VERSION)); } if (selectedNode == 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 b207ef721aa42..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 @@ -9,11 +9,9 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.elasticsearch.Version; 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; @@ -70,141 +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 - ); - } - - @Override - public DiscoveryNodeRole getCompatibilityRole(Version nodeVersion) { - return nodeVersion.before(Version.V_7_10_0) ? DiscoveryNodeRole.DATA_ROLE : this; - } - }; - - 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 - ); - } - - @Override - public DiscoveryNodeRole getCompatibilityRole(Version nodeVersion) { - return nodeVersion.before(Version.V_7_10_0) ? DiscoveryNodeRole.DATA_ROLE : this; - } - }; - - 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 - ); - } - - @Override - public DiscoveryNodeRole getCompatibilityRole(Version nodeVersion) { - return nodeVersion.before(Version.V_7_10_0) ? DiscoveryNodeRole.DATA_ROLE : this; - } - }; - - 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 - ); - } - - @Override - public DiscoveryNodeRole getCompatibilityRole(Version nodeVersion) { - return nodeVersion.before(Version.V_7_10_0) ? DiscoveryNodeRole.DATA_ROLE : this; - } - }; - - 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) { @@ -212,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 078f5c545e6c1..d7bef633b1de5 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 @@ -19,7 +19,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; @@ -87,14 +86,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; @@ -421,16 +417,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 bc357ca4ef00d..1aa3ec1574587 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 61b67d5831ce0..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,72 +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( - org.elasticsearch.common.collect.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( - org.elasticsearch.common.collect.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( - org.elasticsearch.common.collect.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( - org.elasticsearch.common.collect.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()}); } @@ -162,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/DataTiersFeatureSetTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTiersFeatureSetTests.java index 261a7f6543e55..525ae945ba847 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTiersFeatureSetTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTiersFeatureSetTests.java @@ -42,10 +42,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 a4e6961a4d15a..48e9e157aaf10 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; @@ -93,15 +93,15 @@ protected Collection> transportClientPlugins() { } 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 def96c8e8d25f..f11cdee88dbfb 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 @@ -474,6 +474,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 bc17a80b67532..6c9eec911b634 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 @@ -112,7 +112,6 @@ import java.util.function.Supplier; import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.index.mapper.MapperService.SINGLE_MAPPING_NAME; import static org.elasticsearch.xpack.core.ClientHelper.SEARCHABLE_SNAPSHOTS_ORIGIN; @@ -330,7 +329,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); @@ -379,8 +378,10 @@ public void onIndexModule(IndexModule indexModule) { @Override public List getIndexFoldersDeletionListeners() { - if (DiscoveryNode.isDataNode(settings)) { - return singletonList(new SearchableSnapshotIndexFoldersDeletionListener(cacheService::get, frozenCacheService::get)); + if (DiscoveryNode.canContainData(settings)) { + return org.elasticsearch.common.collect.List.of( + new SearchableSnapshotIndexFoldersDeletionListener(cacheService::get, frozenCacheService::get) + ); } return emptyList(); } diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/TransportRepositoryStatsAction.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/TransportRepositoryStatsAction.java index 8352636c2a82d..66ce74de7e6c6 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/TransportRepositoryStatsAction.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/TransportRepositoryStatsAction.java @@ -84,7 +84,7 @@ protected RepositoryStatsNodeResponse newNodeResponse(StreamInput in) throws IOE @Override protected RepositoryStatsNodeResponse nodeOperation(RepositoryStatsNodeRequest request) { SearchableSnapshots.ensureValidLicense(licenseState); - if (clusterService.localNode().isMasterNode() == false && clusterService.localNode().isDataNode() == false) { + if (clusterService.localNode().isMasterNode() == false && clusterService.localNode().canContainData() == false) { return new RepositoryStatsNodeResponse(clusterService.localNode(), RepositoryStats.EMPTY_STATS); } final Repository repository = repositoriesService.repository(request.getRepository()); 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..9d80dbfd07ccf 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 @@ -22,7 +22,6 @@ import org.elasticsearch.index.shard.IndexEventListener; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.shard.ShardId; -import org.elasticsearch.xpack.searchablesnapshots.store.SearchableSnapshotDirectory; import org.elasticsearch.index.translog.Translog; import org.elasticsearch.index.translog.TranslogException; import org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason; @@ -30,13 +29,14 @@ import org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshotsConstants; import org.elasticsearch.xpack.searchablesnapshots.cache.full.CacheService; import org.elasticsearch.xpack.searchablesnapshots.cache.shared.FrozenCacheService; +import org.elasticsearch.xpack.searchablesnapshots.store.SearchableSnapshotDirectory; import java.nio.file.Path; -import static org.elasticsearch.xpack.searchablesnapshots.store.SearchableSnapshotDirectory.unwrapDirectory; import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots.SNAPSHOT_INDEX_NAME_SETTING; import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots.SNAPSHOT_SNAPSHOT_ID_SETTING; import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshotsConstants.isSearchableSnapshotStore; +import static org.elasticsearch.xpack.searchablesnapshots.store.SearchableSnapshotDirectory.unwrapDirectory; public class SearchableSnapshotIndexEventListener implements IndexEventListener { @@ -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 db26924d6c1b5..7f8dc2b09fa1f 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 @@ -49,11 +49,11 @@ import org.elasticsearch.index.Index; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardPath; -import org.elasticsearch.xpack.searchablesnapshots.cache.common.CacheFile; -import org.elasticsearch.xpack.searchablesnapshots.cache.common.CacheKey; import org.elasticsearch.repositories.IndexId; import org.elasticsearch.snapshots.SnapshotId; import org.elasticsearch.xpack.searchablesnapshots.cache.common.ByteRange; +import org.elasticsearch.xpack.searchablesnapshots.cache.common.CacheFile; +import org.elasticsearch.xpack.searchablesnapshots.cache.common.CacheKey; import java.io.Closeable; import java.io.IOException; @@ -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 144080528d992..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,14 +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.Arrays; -import java.util.HashSet; import static org.elasticsearch.node.Node.NODE_NAME_SETTING; @@ -198,20 +195,10 @@ public void testDecay() throws IOException { } public void testCacheSizeDeprecatedOnNonFrozenNodes() { - DiscoveryNode.setAdditionalRoles( - new HashSet<>( - Arrays.asList( - 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/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/TransformPersistentTasksExecutor.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/TransformPersistentTasksExecutor.java index cc41ef7006168..5840078f6e107 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/TransformPersistentTasksExecutor.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/TransformPersistentTasksExecutor.java @@ -143,7 +143,7 @@ public PersistentTasksCustomMetadata.Assignment getAssignment(TransformTaskParam } public static boolean nodeCanRunThisTransformPre77(DiscoveryNode node, TransformTaskParams params, Map explain) { - if (node.isDataNode() == false) { + if (node.canContainData() == false) { if (explain != null) { explain.put(node.getId(), "not a data node"); } 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 a000c5ef3b2cc..22088fb785b6a 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 @@ -18,8 +18,8 @@ import org.elasticsearch.common.Priority; import org.elasticsearch.common.blobstore.BlobStore; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.discovery.DiscoverySettings; import org.elasticsearch.discovery.MasterNotDiscoveredException; @@ -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 82c1e17565d1e..c7aee15bb58f8 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 @@ -549,7 +549,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 2d2dab3727750..f377c5ec16fd8 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 @@ -203,7 +203,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