Skip to content

Commit

Permalink
Remove remaing references to legacy role settings
Browse files Browse the repository at this point in the history
The legacy node.ROLENAME settings were removed in 8.0 (elastic#71163), but
machine dependent heap still handles them. This commit cleans up the
heap settings determination to no longer look for these legacy settings.

relates elastic#85758
  • Loading branch information
rjernst committed Apr 11, 2022
1 parent 284cb8d commit 78ba704
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;

import static java.lang.Math.max;
Expand Down Expand Up @@ -90,15 +89,6 @@ private static List<String> options(int heapSize) {
* Parses role information from elasticsearch.yml and determines machine node role.
*/
static class NodeRoleParser {
private static final Set<String> LEGACY_ROLE_SETTINGS = Set.of(
"node.master",
"node.ingest",
"node.data",
"node.voting_only",
"node.ml",
"node.transform",
"node.remote_cluster_client"
);

@SuppressWarnings("unchecked")
public static MachineNodeRole parse(InputStream config) {
Expand All @@ -113,30 +103,24 @@ public static MachineNodeRole parse(InputStream config) {

if (root != null) {
Map<String, Object> map = flatten(root, null);

if (hasLegacySettings(map.keySet())) {
// We don't attempt to auto-determine heap if legacy role settings are used
return MachineNodeRole.UNKNOWN;
} else {
List<String> roles = null;
try {
if (map.containsKey("node.roles")) {
roles = (List<String>) map.get("node.roles");
}
} catch (ClassCastException ex) {
return MachineNodeRole.UNKNOWN;
List<String> roles = null;
try {
if (map.containsKey("node.roles")) {
roles = (List<String>) map.get("node.roles");
}
} catch (ClassCastException ex) {
return MachineNodeRole.UNKNOWN;
}

if (roles == null || roles.isEmpty()) {
// If roles are missing or empty (coordinating node) assume defaults and consider this a data node
return MachineNodeRole.DATA;
} else if (containsOnly(roles, "master")) {
return MachineNodeRole.MASTER_ONLY;
} else if (roles.contains("ml") && containsOnly(roles, "ml", "remote_cluster_client")) {
return MachineNodeRole.ML_ONLY;
} else {
return MachineNodeRole.DATA;
}
if (roles == null || roles.isEmpty()) {
// If roles are missing or empty (coordinating node) assume defaults and consider this a data node
return MachineNodeRole.DATA;
} else if (containsOnly(roles, "master")) {
return MachineNodeRole.MASTER_ONLY;
} else if (roles.contains("ml") && containsOnly(roles, "ml", "remote_cluster_client")) {
return MachineNodeRole.ML_ONLY;
} else {
return MachineNodeRole.DATA;
}
} else { // if the config is completely empty, then assume defaults and consider this a data node
return MachineNodeRole.DATA;
Expand Down Expand Up @@ -174,10 +158,6 @@ private static Map<String, Object> flatten(Map<String, Object> config, String pa
private static <T> boolean containsOnly(Collection<T> collection, T... items) {
return Arrays.asList(items).containsAll(collection);
}

private static boolean hasLegacySettings(Set<String> keys) {
return LEGACY_ROLE_SETTINGS.stream().anyMatch(keys::contains);
}
}

enum MachineNodeRole {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,6 @@ public void testDataNode() throws IOException {
assertThat(nodeRole, equalTo(DATA));
}

public void testLegacySettings() throws IOException {
MachineDependentHeap.MachineNodeRole nodeRole = parseConfig(sb -> sb.append("node.ml: true"));
assertThat(nodeRole, equalTo(UNKNOWN));

nodeRole = parseConfig(sb -> sb.append("node.master: true"));
assertThat(nodeRole, equalTo(UNKNOWN));

nodeRole = parseConfig(sb -> sb.append("node.data: false"));
assertThat(nodeRole, equalTo(UNKNOWN));

nodeRole = parseConfig(sb -> sb.append("node.ingest: false"));
assertThat(nodeRole, equalTo(UNKNOWN));
}

public void testYamlSyntax() throws IOException {
MachineDependentHeap.MachineNodeRole nodeRole = parseConfig(sb -> sb.append("""
node:
Expand Down

0 comments on commit 78ba704

Please sign in to comment.