Skip to content

Commit ff2d5be

Browse files
author
Tianli Feng
authored
Load the deprecated master role in a dedicated method instead of in setAdditionalRoles() (#4582)
Signed-off-by: Tianli Feng <ftianli@amazon.com>
1 parent 54f8fdd commit ff2d5be

File tree

6 files changed

+21
-14
lines changed

6 files changed

+21
-14
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
5454
- Add DecommissionService and helper to execute awareness attribute decommissioning ([#4084](https://github.com/opensearch-project/OpenSearch/pull/4084))
5555
- Further simplification of the ZIP publication implementation ([#4360](https://github.com/opensearch-project/OpenSearch/pull/4360))
5656
- Relax visibility of the HTTP_CHANNEL_KEY and HTTP_SERVER_CHANNEL_KEY to make it possible for the plugins to access associated Netty4HttpChannel / Netty4HttpServerChannel instance ([#4638](https://github.com/opensearch-project/OpenSearch/pull/4638))
57+
- Load the deprecated master role in a dedicated method instead of in setAdditionalRoles() ([#4582](https://github.com/opensearch-project/OpenSearch/pull/4582))
5758

5859
### Deprecated
5960

server/src/main/java/org/opensearch/cluster/node/DiscoveryNode.java

+12-5
Original file line numberDiff line numberDiff line change
@@ -616,11 +616,18 @@ public static void setAdditionalRoles(final Set<DiscoveryNodeRole> additionalRol
616616
+ "], roles by name abbreviation ["
617617
+ roleNameAbbreviationToPossibleRoles
618618
+ "]";
619-
// TODO: Remove the Map 'roleNameToPossibleRolesWithMaster' and let 'roleMap = roleNameToPossibleRoles', after removing MASTER_ROLE.
620-
// It's used to allow CLUSTER_MANAGER_ROLE that introduced in 2.0, having the same abbreviation name with MASTER_ROLE.
621-
final Map<String, DiscoveryNodeRole> roleNameToPossibleRolesWithMaster = new HashMap<>(roleNameToPossibleRoles);
622-
roleNameToPossibleRolesWithMaster.put(DiscoveryNodeRole.MASTER_ROLE.roleName(), DiscoveryNodeRole.MASTER_ROLE);
623-
roleMap = Collections.unmodifiableMap(roleNameToPossibleRolesWithMaster);
619+
roleMap = roleNameToPossibleRoles;
620+
}
621+
622+
/**
623+
* Load the deprecated {@link DiscoveryNodeRole#MASTER_ROLE}.
624+
* Master role is not added into BUILT_IN_ROLES, because {@link #setAdditionalRoles(Set)} check role name abbreviation duplication,
625+
* and CLUSTER_MANAGER_ROLE has the same abbreviation name with MASTER_ROLE.
626+
*/
627+
public static void setDeprecatedMasterRole() {
628+
final Map<String, DiscoveryNodeRole> modifiableRoleMap = new HashMap<>(roleMap);
629+
modifiableRoleMap.put(DiscoveryNodeRole.MASTER_ROLE.roleName(), DiscoveryNodeRole.MASTER_ROLE);
630+
roleMap = Collections.unmodifiableMap(modifiableRoleMap);
624631
}
625632

626633
public static Set<String> getPossibleRoleNames() {

server/src/main/java/org/opensearch/node/Node.java

+2
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,8 @@ protected Node(
429429
.collect(Collectors.toSet());
430430
DiscoveryNode.setAdditionalRoles(additionalRoles);
431431

432+
DiscoveryNode.setDeprecatedMasterRole();
433+
432434
/*
433435
* Create the environment based on the finalized view of the settings. This is to ensure that components get the same setting
434436
* values, no matter they ask for them from.

server/src/test/java/org/opensearch/cluster/node/DiscoveryNodeRoleSettingTests.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ public void testIsIngestNode() {
5656
}
5757

5858
public void testIsMasterNode() {
59-
// It's used to add MASTER_ROLE into 'roleMap', because MASTER_ROLE is removed from DiscoveryNodeRole.BUILT_IN_ROLES in 2.0.
60-
DiscoveryNode.setAdditionalRoles(Collections.emptySet());
59+
DiscoveryNode.setDeprecatedMasterRole();
6160
runRoleTest(DiscoveryNode::isClusterManagerNode, DiscoveryNodeRole.MASTER_ROLE);
6261
}
6362

server/src/test/java/org/opensearch/cluster/node/DiscoveryNodeTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ public void testDiscoveryNodeIsRemoteClusterClientUnset() {
176176
}
177177

178178
// Added in 2.0 temporarily, validate the MASTER_ROLE is in the list of known roles.
179-
// MASTER_ROLE was removed from BUILT_IN_ROLES and is imported by setAdditionalRoles(),
179+
// MASTER_ROLE was removed from BUILT_IN_ROLES and is imported by setDeprecatedMasterRole(),
180180
// as a workaround for making the new CLUSTER_MANAGER_ROLE has got the same abbreviation 'm'.
181181
// The test validate this behavior.
182-
public void testSetAdditionalRolesCanAddDeprecatedMasterRole() {
183-
DiscoveryNode.setAdditionalRoles(Collections.emptySet());
182+
public void testSetDeprecatedMasterRoleCanAddMasterRole() {
183+
DiscoveryNode.setDeprecatedMasterRole();
184184
assertTrue(DiscoveryNode.getPossibleRoleNames().contains(DiscoveryNodeRole.MASTER_ROLE.roleName()));
185185
}
186186

server/src/test/java/org/opensearch/node/NodeRoleSettingsTests.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ public class NodeRoleSettingsTests extends OpenSearchTestCase {
2626
* Remove the test after removing MASTER_ROLE.
2727
*/
2828
public void testClusterManagerAndMasterRoleCanNotCoexist() {
29-
// It's used to add MASTER_ROLE into 'roleMap', because MASTER_ROLE is removed from DiscoveryNodeRole.BUILT_IN_ROLES in 2.0.
30-
DiscoveryNode.setAdditionalRoles(Collections.emptySet());
29+
DiscoveryNode.setDeprecatedMasterRole();
3130
Settings roleSettings = Settings.builder().put(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), "cluster_manager, master").build();
3231
Exception exception = expectThrows(IllegalArgumentException.class, () -> NodeRoleSettings.NODE_ROLES_SETTING.get(roleSettings));
3332
assertThat(exception.getMessage(), containsString("[master, cluster_manager] can not be assigned together to a node"));
@@ -49,8 +48,7 @@ public void testClusterManagerAndDataNodeRoles() {
4948
* Remove the test after removing MASTER_ROLE.
5049
*/
5150
public void testMasterRoleDeprecationMessage() {
52-
// It's used to add MASTER_ROLE into 'roleMap', because MASTER_ROLE is removed from DiscoveryNodeRole.BUILT_IN_ROLES in 2.0.
53-
DiscoveryNode.setAdditionalRoles(Collections.emptySet());
51+
DiscoveryNode.setDeprecatedMasterRole();
5452
Settings roleSettings = Settings.builder().put(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), "master").build();
5553
assertEquals(Collections.singletonList(DiscoveryNodeRole.MASTER_ROLE), NodeRoleSettings.NODE_ROLES_SETTING.get(roleSettings));
5654
assertWarnings(DiscoveryNodeRole.MASTER_ROLE_DEPRECATION_MESSAGE);

0 commit comments

Comments
 (0)