Skip to content

Commit f0c13e1

Browse files
author
Tianli Feng
committed
Load the deprecated master role in a dedicated method instead of in setAdditionalRoles()
Signed-off-by: Tianli Feng <ftianli@amazon.com>
1 parent 3ca749f commit f0c13e1

File tree

6 files changed

+21
-14
lines changed

6 files changed

+21
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
4444
- [Segment Replication] Update replicas to commit SegmentInfos instead of relying on SIS files from primary shards. ([#4402](https://github.com/opensearch-project/OpenSearch/pull/4402))
4545
- [CCR] Add getHistoryOperationsFromTranslog method to fetch the history snapshot from translogs ([#3948](https://github.com/opensearch-project/OpenSearch/pull/3948))
4646
- [Remote Store] Change behaviour in replica recovery for remote translog enabled indices ([#4318](https://github.com/opensearch-project/OpenSearch/pull/4318))
47+
- Load the deprecated master role in a dedicated method instead of in setAdditionalRoles() ([#4582](https://github.com/opensearch-project/OpenSearch/pull/4582))
4748

4849
### Deprecated
4950

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

Lines changed: 12 additions & 5 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 4 deletions
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)