Skip to content
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

[2.x] Load the deprecated master role in a dedocated method instead of in setAdditionalRoles() #4653

Merged
merged 3 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [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))
- Change the version to remove deprecated code of adding node name into log pattern of log4j property file ([#4569](https://github.com/opensearch-project/OpenSearch/pull/4569))
- Update to Apache Lucene 9.4.0 ([#4661](https://github.com/opensearch-project/OpenSearch/pull/4661))
- Load the deprecated master role in a dedicated method instead of in setAdditionalRoles() ([#4582](https://github.com/opensearch-project/OpenSearch/pull/4582))

### Deprecated

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,11 +616,18 @@ public static void setAdditionalRoles(final Set<DiscoveryNodeRole> additionalRol
+ "], roles by name abbreviation ["
+ roleNameAbbreviationToPossibleRoles
+ "]";
// 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);
roleMap = roleNameToPossibleRoles;
}

/**
* Load the deprecated {@link DiscoveryNodeRole#MASTER_ROLE}.
* Master role is not added into BUILT_IN_ROLES, because {@link #setAdditionalRoles(Set)} check role name abbreviation duplication,
* and CLUSTER_MANAGER_ROLE has the same abbreviation name with MASTER_ROLE.
*/
public static void setDeprecatedMasterRole() {
final Map<String, DiscoveryNodeRole> modifiableRoleMap = new HashMap<>(roleMap);
modifiableRoleMap.put(DiscoveryNodeRole.MASTER_ROLE.roleName(), DiscoveryNodeRole.MASTER_ROLE);
roleMap = Collections.unmodifiableMap(modifiableRoleMap);
}

public static Set<String> getPossibleRoleNames() {
Expand Down
2 changes: 2 additions & 0 deletions server/src/main/java/org/opensearch/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ protected Node(
.collect(Collectors.toSet());
DiscoveryNode.setAdditionalRoles(additionalRoles);

DiscoveryNode.setDeprecatedMasterRole();

/*
* Create the environment based on the finalized view of the settings. This is to ensure that components get the same setting
* values, no matter they ask for them from.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public void testIsIngestNode() {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ public void testDiscoveryNodeIsRemoteClusterClientUnset() {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public class NodeRoleSettingsTests extends OpenSearchTestCase {
* Remove the test after removing MASTER_ROLE.
*/
public void testClusterManagerAndMasterRoleCanNotCoexist() {
// It's used to add MASTER_ROLE into 'roleMap', because MASTER_ROLE is removed from DiscoveryNodeRole.BUILT_IN_ROLES in 2.0.
DiscoveryNode.setAdditionalRoles(Collections.emptySet());
DiscoveryNode.setDeprecatedMasterRole();
Settings roleSettings = Settings.builder().put(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), "cluster_manager, master").build();
Exception exception = expectThrows(IllegalArgumentException.class, () -> NodeRoleSettings.NODE_ROLES_SETTING.get(roleSettings));
assertThat(exception.getMessage(), containsString("[master, cluster_manager] can not be assigned together to a node"));
Expand All @@ -49,8 +48,7 @@ public void testClusterManagerAndDataNodeRoles() {
* Remove the test after removing MASTER_ROLE.
*/
public void testMasterRoleDeprecationMessage() {
// It's used to add MASTER_ROLE into 'roleMap', because MASTER_ROLE is removed from DiscoveryNodeRole.BUILT_IN_ROLES in 2.0.
DiscoveryNode.setAdditionalRoles(Collections.emptySet());
DiscoveryNode.setDeprecatedMasterRole();
Settings roleSettings = Settings.builder().put(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), "master").build();
assertEquals(Collections.singletonList(DiscoveryNodeRole.MASTER_ROLE), NodeRoleSettings.NODE_ROLES_SETTING.get(roleSettings));
assertWarnings(DiscoveryNodeRole.MASTER_ROLE_DEPRECATION_MESSAGE);
Expand Down