-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add a new node role 'cluster_manager' as the alternative for 'master' role and deprecate 'master' role #2424
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
Changes from 17 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,7 +390,7 @@ 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 == DiscoveryNodeRole.MASTER_ROLE || role == DiscoveryNodeRole.CLUSTER_MANAGER_ROLE) { | ||
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. Seems like we should have been using 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. Hi @reta, thanks a lot for your review! 👍👍 I will think about it and make the change. Since the original code was using 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. I updated in the commit 7a2a6b9, changed all the 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. 👍 |
||
out.writeEnum(LegacyRole.MASTER); | ||
} else if (role == DiscoveryNodeRole.DATA_ROLE) { | ||
out.writeEnum(LegacyRole.DATA); | ||
|
@@ -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); | ||
} | ||
|
||
/** | ||
|
@@ -577,8 +577,10 @@ public static Set<DiscoveryNodeRole> getPossibleRoles() { | |
|
||
public static void setAdditionalRoles(final Set<DiscoveryNodeRole> additionalRoles) { | ||
assert additionalRoles.stream().allMatch(r -> r.legacySetting() == null || r.legacySetting().isDeprecated()) : additionalRoles; | ||
final Map<String, DiscoveryNodeRole> roleNameToPossibleRoles = rolesToMap( | ||
Stream.concat(DiscoveryNodeRole.BUILT_IN_ROLES.stream(), additionalRoles.stream()) | ||
// TODO: Remove 'new HashMap<>()' and only keep 'rolesToMap(...)' after removing DiscoveryNodeRole.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> roleNameToPossibleRoles = new HashMap<>( | ||
rolesToMap(Stream.concat(DiscoveryNodeRole.BUILT_IN_ROLES.stream(), additionalRoles.stream())) | ||
); | ||
// collect the abbreviation names into a map to ensure that there are not any duplicate abbreviations | ||
final Map<String, DiscoveryNodeRole> roleNameAbbreviationToPossibleRoles = Collections.unmodifiableMap( | ||
|
@@ -591,15 +593,19 @@ public static void setAdditionalRoles(final Set<DiscoveryNodeRole> additionalRol | |
+ "], roles by name abbreviation [" | ||
+ roleNameAbbreviationToPossibleRoles | ||
+ "]"; | ||
roleMap = roleNameToPossibleRoles; | ||
// TODO: Remove this line after removing DiscoveryNodeRole.MASTER_ROLE | ||
roleNameToPossibleRoles.put(DiscoveryNodeRole.MASTER_ROLE.roleName(), DiscoveryNodeRole.MASTER_ROLE); | ||
// TODO: Remove 'Collections.unmodifiableMap()', and only keep 'roleNameToPossibleRoles', after removing MASTER_ROLE | ||
// because the map roleNameToPossibleRoles is supposed to be immutable. | ||
roleMap = Collections.unmodifiableMap(roleNameToPossibleRoles); | ||
} | ||
|
||
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 { | ||
|
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?
Uh oh!
There was an error while loading. Please reload this page.
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!