Skip to content

Commit 8b47610

Browse files
Remove 'cluster_manager' role attachment when using 'node.master' deprecated setting (#6331) (#6853)
`cluster_manager` role no longer configures the legacy `node.master` setting. Using `node.master: true` configures both cluster_manager and master role to a node which is not correct, only one of them should be assigned Allowing only one of the both roles to be attached instead of both - 'master' which is deprecated - since both the legacy setting `node.master` and `master` role are deprecated - so we need to keep the initial behavior only with deprecated roles and settings. (cherry picked from commit 5f89081) Signed-off-by: Sandesh Kumar <[email protected]>
1 parent 8356d2b commit 8b47610

File tree

6 files changed

+165
-28
lines changed

6 files changed

+165
-28
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1616
- [Remote Store] Integrate remote segment store in peer recovery flow ([#6664](https://github.com/opensearch-project/OpenSearch/pull/6664))
1717
- [Segment Replication] Add new cluster setting to set replication strategy by default for all indices in cluster. ([#6791](https://github.com/opensearch-project/OpenSearch/pull/6791))
1818
- Enable sort optimization for all NumericTypes ([#6464](https://github.com/opensearch-project/OpenSearch/pull/6464)
19+
- Remove 'cluster_manager' role attachment when using 'node.master' deprecated setting ([#6331](https://github.com/opensearch-project/OpenSearch/pull/6331))
1920

2021
### Dependencies
2122
- Bump `org.apache.logging.log4j:log4j-core` from 2.18.0 to 2.20.0 ([#6490](https://github.com/opensearch-project/OpenSearch/pull/6490))

server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/stats/ClusterStatsIT.java

+140-17
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.opensearch.Version;
3636
import org.opensearch.action.admin.cluster.health.ClusterHealthResponse;
3737
import org.opensearch.action.admin.cluster.node.stats.NodeStats;
38+
import org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest;
3839
import org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse;
3940
import org.opensearch.client.Requests;
4041
import org.opensearch.cluster.health.ClusterHealthStatus;
@@ -54,6 +55,7 @@
5455
import java.util.Collections;
5556
import java.util.HashMap;
5657
import java.util.HashSet;
58+
import java.util.Locale;
5759
import java.util.Map;
5860
import java.util.Set;
5961
import java.util.concurrent.ExecutionException;
@@ -83,14 +85,7 @@ private void waitForNodes(int numNodes) {
8385
public void testNodeCounts() {
8486
int total = 1;
8587
internalCluster().startNode();
86-
Map<String, Integer> expectedCounts = new HashMap<>();
87-
expectedCounts.put(DiscoveryNodeRole.DATA_ROLE.roleName(), 1);
88-
expectedCounts.put(DiscoveryNodeRole.MASTER_ROLE.roleName(), 1);
89-
expectedCounts.put(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(), 1);
90-
expectedCounts.put(DiscoveryNodeRole.INGEST_ROLE.roleName(), 1);
91-
expectedCounts.put(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName(), 1);
92-
expectedCounts.put(DiscoveryNodeRole.SEARCH_ROLE.roleName(), 0);
93-
expectedCounts.put(ClusterStatsNodes.Counts.COORDINATING_ONLY, 0);
88+
Map<String, Integer> expectedCounts = getExpectedCounts(1, 1, 1, 1, 1, 0, 0);
9489
int numNodes = randomIntBetween(1, 5);
9590

9691
ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();
@@ -147,25 +142,21 @@ public void testNodeCounts() {
147142
}
148143

149144
// Validate assigning value "master" to setting "node.roles" can get correct count in Node Stats response after MASTER_ROLE deprecated.
150-
public void testNodeCountsWithDeprecatedMasterRole() {
145+
public void testNodeCountsWithDeprecatedMasterRole() throws ExecutionException, InterruptedException {
151146
int total = 1;
152147
Settings settings = Settings.builder()
153148
.putList(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), Collections.singletonList(DiscoveryNodeRole.MASTER_ROLE.roleName()))
154149
.build();
155150
internalCluster().startNode(settings);
156151
waitForNodes(total);
157152

158-
Map<String, Integer> expectedCounts = new HashMap<>();
159-
expectedCounts.put(DiscoveryNodeRole.DATA_ROLE.roleName(), 0);
160-
expectedCounts.put(DiscoveryNodeRole.MASTER_ROLE.roleName(), 1);
161-
expectedCounts.put(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(), 1);
162-
expectedCounts.put(DiscoveryNodeRole.INGEST_ROLE.roleName(), 0);
163-
expectedCounts.put(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName(), 0);
164-
expectedCounts.put(DiscoveryNodeRole.SEARCH_ROLE.roleName(), 0);
165-
expectedCounts.put(ClusterStatsNodes.Counts.COORDINATING_ONLY, 0);
153+
Map<String, Integer> expectedCounts = getExpectedCounts(0, 1, 1, 0, 0, 0, 0);
166154

167155
ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();
168156
assertCounts(response.getNodesStats().getCounts(), total, expectedCounts);
157+
158+
Set<String> expectedRoles = Set.of(DiscoveryNodeRole.MASTER_ROLE.roleName());
159+
assertEquals(expectedRoles, getNodeRoles(0));
169160
}
170161

171162
private static void incrementCountForRole(String role, Map<String, Integer> counts) {
@@ -322,4 +313,136 @@ public void testFieldTypes() {
322313
}
323314
}
324315
}
316+
317+
public void testNodeRolesWithMasterLegacySettings() throws ExecutionException, InterruptedException {
318+
int total = 1;
319+
Settings legacyMasterSettings = Settings.builder()
320+
.put("node.master", true)
321+
.put("node.data", false)
322+
.put("node.ingest", false)
323+
.build();
324+
325+
internalCluster().startNodes(legacyMasterSettings);
326+
waitForNodes(total);
327+
328+
Map<String, Integer> expectedCounts = getExpectedCounts(0, 1, 1, 0, 1, 0, 0);
329+
330+
ClusterStatsResponse clusterStatsResponse = client().admin().cluster().prepareClusterStats().get();
331+
assertCounts(clusterStatsResponse.getNodesStats().getCounts(), total, expectedCounts);
332+
333+
Set<String> expectedRoles = Set.of(
334+
DiscoveryNodeRole.MASTER_ROLE.roleName(),
335+
DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName()
336+
);
337+
assertEquals(expectedRoles, getNodeRoles(0));
338+
}
339+
340+
public void testNodeRolesWithClusterManagerRole() throws ExecutionException, InterruptedException {
341+
int total = 1;
342+
Settings clusterManagerNodeRoleSettings = Settings.builder()
343+
.put(
344+
"node.roles",
345+
String.format(
346+
Locale.ROOT,
347+
"%s, %s",
348+
DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(),
349+
DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName()
350+
)
351+
)
352+
.build();
353+
354+
internalCluster().startNodes(clusterManagerNodeRoleSettings);
355+
waitForNodes(total);
356+
357+
Map<String, Integer> expectedCounts = getExpectedCounts(0, 1, 1, 0, 1, 0, 0);
358+
359+
ClusterStatsResponse clusterStatsResponse = client().admin().cluster().prepareClusterStats().get();
360+
assertCounts(clusterStatsResponse.getNodesStats().getCounts(), total, expectedCounts);
361+
362+
Set<String> expectedRoles = Set.of(
363+
DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(),
364+
DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName()
365+
);
366+
assertEquals(expectedRoles, getNodeRoles(0));
367+
}
368+
369+
public void testNodeRolesWithSeedDataNodeLegacySettings() throws ExecutionException, InterruptedException {
370+
int total = 1;
371+
Settings legacySeedDataNodeSettings = Settings.builder()
372+
.put("node.master", true)
373+
.put("node.data", true)
374+
.put("node.ingest", false)
375+
.build();
376+
377+
internalCluster().startNodes(legacySeedDataNodeSettings);
378+
waitForNodes(total);
379+
380+
Map<String, Integer> expectedRoleCounts = getExpectedCounts(1, 1, 1, 0, 1, 0, 0);
381+
382+
ClusterStatsResponse clusterStatsResponse = client().admin().cluster().prepareClusterStats().get();
383+
assertCounts(clusterStatsResponse.getNodesStats().getCounts(), total, expectedRoleCounts);
384+
385+
Set<String> expectedRoles = Set.of(
386+
DiscoveryNodeRole.MASTER_ROLE.roleName(),
387+
DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName(),
388+
DiscoveryNodeRole.DATA_ROLE.roleName()
389+
);
390+
assertEquals(expectedRoles, getNodeRoles(0));
391+
}
392+
393+
public void testNodeRolesWithDataNodeLegacySettings() throws ExecutionException, InterruptedException {
394+
int total = 2;
395+
Settings legacyDataNodeSettings = Settings.builder()
396+
.put("node.master", false)
397+
.put("node.data", true)
398+
.put("node.ingest", false)
399+
.build();
400+
401+
// can't start data-only node without assigning cluster-manager
402+
internalCluster().startClusterManagerOnlyNodes(1);
403+
internalCluster().startNodes(legacyDataNodeSettings);
404+
waitForNodes(total);
405+
406+
Map<String, Integer> expectedRoleCounts = getExpectedCounts(1, 1, 1, 0, 1, 0, 0);
407+
408+
ClusterStatsResponse clusterStatsResponse = client().admin().cluster().prepareClusterStats().get();
409+
assertCounts(clusterStatsResponse.getNodesStats().getCounts(), total, expectedRoleCounts);
410+
411+
Set<Set<String>> expectedNodesRoles = Set.of(
412+
Set.of(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName()),
413+
Set.of(DiscoveryNodeRole.DATA_ROLE.roleName(), DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName())
414+
);
415+
assertEquals(expectedNodesRoles, Set.of(getNodeRoles(0), getNodeRoles(1)));
416+
}
417+
418+
private Map<String, Integer> getExpectedCounts(
419+
int dataRoleCount,
420+
int masterRoleCount,
421+
int clusterManagerRoleCount,
422+
int ingestRoleCount,
423+
int remoteClusterClientRoleCount,
424+
int searchRoleCount,
425+
int coordinatingOnlyCount
426+
) {
427+
Map<String, Integer> expectedCounts = new HashMap<>();
428+
expectedCounts.put(DiscoveryNodeRole.DATA_ROLE.roleName(), dataRoleCount);
429+
expectedCounts.put(DiscoveryNodeRole.MASTER_ROLE.roleName(), masterRoleCount);
430+
expectedCounts.put(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(), clusterManagerRoleCount);
431+
expectedCounts.put(DiscoveryNodeRole.INGEST_ROLE.roleName(), ingestRoleCount);
432+
expectedCounts.put(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName(), remoteClusterClientRoleCount);
433+
expectedCounts.put(DiscoveryNodeRole.SEARCH_ROLE.roleName(), searchRoleCount);
434+
expectedCounts.put(ClusterStatsNodes.Counts.COORDINATING_ONLY, coordinatingOnlyCount);
435+
return expectedCounts;
436+
}
437+
438+
private Set<String> getNodeRoles(int nodeNumber) throws ExecutionException, InterruptedException {
439+
NodesStatsResponse nodesStatsResponse = client().admin().cluster().nodesStats(new NodesStatsRequest()).get();
440+
return nodesStatsResponse.getNodes()
441+
.get(nodeNumber)
442+
.getNode()
443+
.getRoles()
444+
.stream()
445+
.map(DiscoveryNodeRole::roleName)
446+
.collect(Collectors.toSet());
447+
}
325448
}

server/src/internalClusterTest/java/org/opensearch/cluster/node/DiscoveryNodeRoleIT.java

+16
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@
4646
import java.util.List;
4747
import java.util.Set;
4848

49+
import static org.hamcrest.Matchers.startsWith;
4950
import static org.opensearch.test.NodeRoles.addRoles;
51+
import static org.opensearch.test.NodeRoles.onlyRole;
5052
import static org.opensearch.test.NodeRoles.removeRoles;
5153
import static org.hamcrest.Matchers.hasItem;
5254
import static org.hamcrest.Matchers.hasSize;
@@ -126,4 +128,18 @@ private void runTestNodeHasAdditionalRole(final Settings settings) {
126128
assertThat(response.getNodes().get(0).getNode().getRoles(), matcher);
127129
}
128130

131+
public void testStartNodeWithClusterManagerRoleAndMasterSetting() {
132+
final Settings settings = Settings.builder()
133+
.put("node.master", randomBoolean())
134+
.put(onlyRole(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE))
135+
.build();
136+
137+
final IllegalArgumentException e1 = expectThrows(
138+
IllegalArgumentException.class,
139+
() -> DiscoveryNode.getRolesFromSettings(settings)
140+
);
141+
assertThat(e1.getMessage(), startsWith("can not explicitly configure node roles and use legacy role setting"));
142+
final IllegalArgumentException e2 = expectThrows(IllegalArgumentException.class, () -> internalCluster().startNodes(settings));
143+
assertThat(e2.getMessage(), startsWith("can not explicitly configure node roles and use legacy role setting"));
144+
}
129145
}

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,7 @@ public static Set<DiscoveryNodeRole> getRolesFromSettings(final Settings setting
287287
validateLegacySettings(settings, roleMap);
288288
return Collections.unmodifiableSet(new HashSet<>(NODE_ROLES_SETTING.get(settings)));
289289
} else {
290-
return roleMap.values()
291-
.stream()
292-
.filter(s -> s.legacySetting() != null && s.legacySetting().get(settings))
293-
.collect(Collectors.toSet());
290+
return roleMap.values().stream().filter(s -> s.isEnabledByDefault(settings)).collect(Collectors.toSet());
294291
}
295292
}
296293

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
import org.opensearch.LegacyESVersion;
3636
import org.opensearch.Version;
37+
import org.opensearch.common.Booleans;
3738
import org.opensearch.common.logging.DeprecationLogger;
3839
import org.opensearch.common.settings.Setting;
3940
import org.opensearch.common.settings.Setting.Property;
@@ -245,8 +246,8 @@ public void validateRole(List<DiscoveryNodeRole> roles) {
245246

246247
@Override
247248
public Setting<Boolean> legacySetting() {
248-
// copy the setting here so we can mark it private in org.opensearch.node.Node
249-
return Setting.boolSetting("node.master", true, Property.Deprecated, Property.NodeScope);
249+
// 'cluster_manager' role should not configure legacy setting since deprecated 'master' role is supported till OS 2.x
250+
return null;
250251
}
251252

252253
@Override
@@ -273,6 +274,10 @@ public void validateRole(List<DiscoveryNodeRole> roles) {
273274
}
274275
}
275276

277+
@Override
278+
public boolean isEnabledByDefault(final Settings settings) {
279+
return Booleans.isBoolean(settings.get("node.master")) == false;
280+
}
276281
};
277282

278283
public static final DiscoveryNodeRole REMOTE_CLUSTER_CLIENT_ROLE = new DiscoveryNodeRole("remote_cluster_client", "r") {

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

-5
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ public void testIsMasterNode() {
6060
runRoleTest(DiscoveryNode::isClusterManagerNode, DiscoveryNodeRole.MASTER_ROLE);
6161
}
6262

63-
public void testIsClusterManagerNode() {
64-
runRoleTest(DiscoveryNode::isClusterManagerNode, DiscoveryNodeRole.CLUSTER_MANAGER_ROLE);
65-
}
66-
6763
public void testIsRemoteClusterClient() {
6864
runRoleTest(DiscoveryNode::isRemoteClusterClient, DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE);
6965
}
@@ -96,5 +92,4 @@ private void runRoleTest(final Predicate<Settings> predicate, final DiscoveryNod
9692
assertThat(e.getMessage(), startsWith("can not explicitly configure node roles and use legacy role setting"));
9793
assertNoDeprecationWarnings();
9894
}
99-
10095
}

0 commit comments

Comments
 (0)