-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a new node role 'cluster_manager' as the alternative for 'master' role and deprecate 'master' role #2424
Changes from 54 commits
344998c
0396a4a
77520c8
085f07f
d9aec73
02f8f86
573380f
bd395af
83460f4
0940b41
41806f0
11c4ff5
8cc54e3
f06766e
70c8f4a
e8e2e30
46098cd
73b4652
d1acef0
812aa39
d15e44f
0189e86
14ef7c5
06fdf74
10247a2
8817b73
010fd29
eda18db
8f9ab2b
22567a4
4e0b27c
6d08a78
8ca3a9f
4c0e5f4
4fa904f
d1ee0c6
a4b7b72
dafc3b7
4fd23e6
7a2a6b9
83a3c73
e4404d7
b5837b7
ebb1c45
0dadd68
6845cdd
f818ea1
5847ae0
14124bd
ef70fe9
a2661a8
47961ce
f59a27b
90f143a
69c3795
87e5048
f57741d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,7 +94,7 @@ public static boolean hasRole(final Settings settings, final DiscoveryNodeRole r | |
} | ||
|
||
public static boolean isMasterNode(Settings settings) { | ||
return hasRole(settings, DiscoveryNodeRole.MASTER_ROLE); | ||
return hasRole(settings, DiscoveryNodeRole.MASTER_ROLE) || hasRole(settings, DiscoveryNodeRole.CLUSTER_MANAGER_ROLE); | ||
} | ||
|
||
/** | ||
|
@@ -343,7 +343,7 @@ public DiscoveryNode(StreamInput in) throws IOException { | |
final LegacyRole legacyRole = in.readEnum(LegacyRole.class); | ||
switch (legacyRole) { | ||
case MASTER: | ||
roles.add(DiscoveryNodeRole.MASTER_ROLE); | ||
roles.add(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE); | ||
break; | ||
case DATA: | ||
roles.add(DiscoveryNodeRole.DATA_ROLE); | ||
|
@@ -390,11 +390,11 @@ public void writeTo(StreamOutput out) throws IOException { | |
.collect(Collectors.toList()); | ||
out.writeVInt(rolesToWrite.size()); | ||
for (final DiscoveryNodeRole role : rolesToWrite) { | ||
if (role == DiscoveryNodeRole.MASTER_ROLE) { | ||
if (role.isClusterManager()) { | ||
out.writeEnum(LegacyRole.MASTER); | ||
} else if (role == DiscoveryNodeRole.DATA_ROLE) { | ||
} else if (role.equals(DiscoveryNodeRole.DATA_ROLE)) { | ||
out.writeEnum(LegacyRole.DATA); | ||
} else if (role == DiscoveryNodeRole.INGEST_ROLE) { | ||
} else if (role.equals(DiscoveryNodeRole.INGEST_ROLE)) { | ||
out.writeEnum(LegacyRole.INGEST); | ||
} | ||
} | ||
|
@@ -456,7 +456,7 @@ public boolean isDataNode() { | |
* Can this node become master or not. | ||
*/ | ||
public boolean isMasterNode() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isMasterNode -> isClusterManager? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (please see the above comment 😁) |
||
return roles.contains(DiscoveryNodeRole.MASTER_ROLE); | ||
return roles.contains(DiscoveryNodeRole.MASTER_ROLE) || roles.contains(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE); | ||
} | ||
|
||
/** | ||
|
@@ -591,15 +591,19 @@ public static void setAdditionalRoles(final Set<DiscoveryNodeRole> additionalRol | |
+ "], roles by name abbreviation [" | ||
+ roleNameAbbreviationToPossibleRoles | ||
+ "]"; | ||
roleMap = roleNameToPossibleRoles; | ||
// TODO: Remove the Map 'roleNameToPossibleRolesWithMaster' and let 'roleMap = roleNameToPossibleRoles', after removing MASTER_ROLE. | ||
// It's used to allow CLUSTER_MANAGER_ROLE that introduced in 2.0, having the same abbreviation name with MASTER_ROLE. | ||
final Map<String, DiscoveryNodeRole> roleNameToPossibleRolesWithMaster = new HashMap<>(roleNameToPossibleRoles); | ||
roleNameToPossibleRolesWithMaster.put(DiscoveryNodeRole.MASTER_ROLE.roleName(), DiscoveryNodeRole.MASTER_ROLE); | ||
roleMap = Collections.unmodifiableMap(roleNameToPossibleRolesWithMaster); | ||
} | ||
|
||
public static Set<String> getPossibleRoleNames() { | ||
return roleMap.keySet(); | ||
} | ||
|
||
/** | ||
* Enum that holds all the possible roles that that a node can fulfill in a cluster. | ||
* Enum that holds all the possible roles that a node can fulfill in a cluster. | ||
* Each role has its name and a corresponding abbreviation used by cat apis. | ||
*/ | ||
private enum LegacyRole { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,13 +34,16 @@ | |
|
||
import org.opensearch.LegacyESVersion; | ||
import org.opensearch.Version; | ||
import org.opensearch.common.logging.DeprecationLogger; | ||
import org.opensearch.common.settings.Setting; | ||
import org.opensearch.common.settings.Setting.Property; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.transport.RemoteClusterService; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Objects; | ||
import java.util.SortedSet; | ||
import java.util.TreeSet; | ||
|
@@ -50,6 +53,10 @@ | |
*/ | ||
public abstract class DiscoveryNodeRole implements Comparable<DiscoveryNodeRole> { | ||
|
||
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(DiscoveryNodeRole.class); | ||
public static final String MASTER_ROLE_DEPRECATION_MESSAGE = | ||
"Assigning [master] role in setting [node.roles] is deprecated. To promote inclusive language, please use [cluster_manager] role instead."; | ||
|
||
private final String roleName; | ||
|
||
/** | ||
|
@@ -129,6 +136,13 @@ public DiscoveryNodeRole getCompatibilityRole(Version nodeVersion) { | |
return this; | ||
} | ||
|
||
/** | ||
* Validate the role is compatible with the other roles in the list, when assigning the list of roles to a node. | ||
* An {@link IllegalArgumentException} is expected to be thrown, if the role can't coexist with the other roles. | ||
* @param roles A {@link List} of {@link DiscoveryNodeRole} that a node is going to have. | ||
*/ | ||
public void validateRole(List<DiscoveryNodeRole> roles) {}; | ||
|
||
@Override | ||
public final boolean equals(Object o) { | ||
if (this == o) return true; | ||
|
@@ -193,15 +207,60 @@ public Setting<Boolean> legacySetting() { | |
|
||
/** | ||
* Represents the role for a master-eligible node. | ||
* @deprecated As of 2.0, because promoting inclusive language, replaced by {@link #CLUSTER_MANAGER_ROLE} | ||
*/ | ||
@Deprecated | ||
public static final DiscoveryNodeRole MASTER_ROLE = new DiscoveryNodeRole("master", "m") { | ||
|
||
@Override | ||
public Setting<Boolean> legacySetting() { | ||
// copy the setting here so we can mark it private in org.opensearch.node.Node | ||
// As of 2.0, set the default value to 'false', so that MASTER_ROLE isn't added as a default value of NODE_ROLES_SETTING | ||
return Setting.boolSetting("node.master", false, Property.Deprecated, Property.NodeScope); | ||
} | ||
|
||
@Override | ||
public void validateRole(List<DiscoveryNodeRole> roles) { | ||
deprecationLogger.deprecate("node_role_master", MASTER_ROLE_DEPRECATION_MESSAGE); | ||
} | ||
|
||
}; | ||
|
||
/** | ||
* Represents the role for a cluster-manager-eligible node. | ||
*/ | ||
public static final DiscoveryNodeRole CLUSTER_MANAGER_ROLE = new DiscoveryNodeRole("cluster_manager", "m") { | ||
|
||
@Override | ||
public Setting<Boolean> legacySetting() { | ||
// copy the setting here so we can mark it private in org.opensearch.node.Node | ||
return Setting.boolSetting("node.master", true, Property.Deprecated, Property.NodeScope); | ||
} | ||
|
||
@Override | ||
public DiscoveryNodeRole getCompatibilityRole(Version nodeVersion) { | ||
if (nodeVersion.onOrAfter(Version.V_2_0_0)) { | ||
return this; | ||
} else { | ||
return DiscoveryNodeRole.MASTER_ROLE; | ||
} | ||
} | ||
|
||
@Override | ||
public void validateRole(List<DiscoveryNodeRole> roles) { | ||
if (roles.contains(DiscoveryNodeRole.MASTER_ROLE)) { | ||
throw new IllegalArgumentException( | ||
String.format( | ||
Locale.ROOT, | ||
"The two roles [%s, %s] can not be assigned together to a node. %s", | ||
DiscoveryNodeRole.MASTER_ROLE.roleName(), | ||
DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(), | ||
MASTER_ROLE_DEPRECATION_MESSAGE | ||
) | ||
); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @andrross Thanks for your opinion to not allow "master" role and "cluster_manager" role coexisting. 👍 😄 It's achieved by adding a method validateRole() to allow defining different validation rule for each role, to check the compatibility with the other roles in the setting |
||
|
||
}; | ||
|
||
public static final DiscoveryNodeRole REMOTE_CLUSTER_CLIENT_ROLE = new DiscoveryNodeRole("remote_cluster_client", "r") { | ||
|
@@ -223,7 +282,7 @@ public Setting<Boolean> legacySetting() { | |
* The built-in node roles. | ||
*/ | ||
public static SortedSet<DiscoveryNodeRole> BUILT_IN_ROLES = Collections.unmodifiableSortedSet( | ||
new TreeSet<>(Arrays.asList(DATA_ROLE, INGEST_ROLE, MASTER_ROLE, REMOTE_CLUSTER_CLIENT_ROLE)) | ||
new TreeSet<>(Arrays.asList(DATA_ROLE, INGEST_ROLE, CLUSTER_MANAGER_ROLE, REMOTE_CLUSTER_CLIENT_ROLE)) | ||
); | ||
|
||
/** | ||
|
@@ -262,4 +321,13 @@ public Setting<Boolean> legacySetting() { | |
|
||
} | ||
|
||
/** | ||
* Check if the role is {@link #CLUSTER_MANAGER_ROLE} or {@link #MASTER_ROLE}. | ||
* @deprecated As of 2.0, because promoting inclusive language. MASTER_ROLE is deprecated. | ||
* @return true if the node role is{@link #CLUSTER_MANAGER_ROLE} or {@link #MASTER_ROLE} | ||
*/ | ||
@Deprecated | ||
public boolean isClusterManager() { | ||
return this.equals(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE) || this.equals(DiscoveryNodeRole.MASTER_ROLE); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isMasterNode -> isClusterManager?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Such method is published into Maven as Java API (https://opensearch.org/javadocs/1.2.4/OpenSearch/server/build/docs/javadoc/org/opensearch/cluster/node/DiscoveryNode.html#isMasterNode()), so I'm not going to change the name soon, in case any plugins or clients are using the method, though maybe no other software using it 😅.
I think the normal way is to deprecate this method and create new method aside, but it will be a huge work to deprecate all the methods/classes with the mane "master", so I'm planning to rename them in place in next major version.
Of course, I think there is an option to choose a few common used methods to follow the normal deprecation path. I haven't got a decision which method to rename in place, and which to create alternative method aside.
There is a discussion in the PR #2453, you could take a look at. Renaming the Java APIs is tracked in issue #1684
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecating isMaster in favour of isClusterManager sounds like a plan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will mark it in an issue and deprecate it another PR. Thank you!