Skip to content

Commit

Permalink
Replace internal usages of 'master' terminology in server/src/test di…
Browse files Browse the repository at this point in the history
…rectory

Signed-off-by: Tianli Feng <ftianli@amazon.com>
  • Loading branch information
Tianli Feng committed Mar 19, 2022
1 parent e0f7706 commit 6b0ce71
Show file tree
Hide file tree
Showing 21 changed files with 156 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ public void testClusterHealth() throws IOException {
assertThat(clusterHealth.getActiveShardsPercent(), is(allOf(greaterThanOrEqualTo(0.0), lessThanOrEqualTo(100.0))));
}

public void testClusterHealthVerifyMasterNodeDiscovery() throws IOException {
public void testClusterHealthVerifyClusterManagerNodeDiscovery() throws IOException {
DiscoveryNode localNode = new DiscoveryNode("node", OpenSearchTestCase.buildNewFakeTransportAddress(), Version.CURRENT);
// set the node information to verify master_node discovery in ClusterHealthResponse
// set the node information to verify cluster_manager_node discovery in ClusterHealthResponse
ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))
.nodes(DiscoveryNodes.builder().add(localNode).localNodeId(localNode.getId()).masterNodeId(localNode.getId()))
.build();
Expand Down Expand Up @@ -150,7 +150,7 @@ private void assertClusterHealth(ClusterHealthResponse clusterHealth) {
}

public void testVersionCompatibleSerialization() throws IOException {
boolean hasDiscoveredMaster = false;
boolean hasDiscoveredClusterManager = false;
int indicesSize = randomInt(20);
Map<String, ClusterIndexHealth> indices = new HashMap<>(indicesSize);
if ("indices".equals(level) || "shards".equals(level)) {
Expand All @@ -167,12 +167,12 @@ public void testVersionCompatibleSerialization() throws IOException {
randomInt(100),
randomInt(100),
randomInt(100),
hasDiscoveredMaster,
hasDiscoveredClusterManager,
randomDoubleBetween(0d, 100d, true),
randomFrom(ClusterHealthStatus.values()),
indices
);
// Create the Cluster Health Response object with discovered master as false,
// Create the Cluster Health Response object with discovered cluster manager as false,
// to verify serialization puts default value for the field
ClusterHealthResponse clusterHealth = new ClusterHealthResponse(
"test-cluster",
Expand Down Expand Up @@ -209,7 +209,7 @@ public void testVersionCompatibleSerialization() throws IOException {
StreamInput in_gt_7_0 = out_gt_1_0.bytes().streamInput();
in_gt_7_0.setVersion(new_version);
clusterHealth = ClusterHealthResponse.readResponseFrom(in_gt_7_0);
assertThat(clusterHealth.hasDiscoveredMaster(), Matchers.equalTo(hasDiscoveredMaster));
assertThat(clusterHealth.hasDiscoveredMaster(), Matchers.equalTo(hasDiscoveredClusterManager));
}

ClusterHealthResponse maybeSerialize(ClusterHealthResponse clusterHealth) throws IOException {
Expand All @@ -222,7 +222,7 @@ ClusterHealthResponse maybeSerialize(ClusterHealthResponse clusterHealth) throws
return clusterHealth;
}

public void testParseFromXContentWithDiscoveredMasterField() throws IOException {
public void testParseFromXContentWithDiscoveredClusterManagerField() throws IOException {
try (
XContentParser parser = JsonXContent.jsonXContent.createParser(
NamedXContentRegistry.EMPTY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,12 @@ public void onFailure(Exception e) {
for (int i = 1; i < testNodes.length; i++) {
discoveryNodes[i - 1] = testNodes[i].discoveryNode();
}
DiscoveryNode master = discoveryNodes[0];
DiscoveryNode clusterManager = discoveryNodes[0];
for (int i = 1; i < testNodes.length; i++) {
// Notify only nodes that should remain in the cluster
setState(
testNodes[i].clusterService,
ClusterStateCreationUtils.state(testNodes[i].discoveryNode(), master, discoveryNodes)
ClusterStateCreationUtils.state(testNodes[i].discoveryNode(), clusterManager, discoveryNodes)
);
}
if (randomBoolean()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ public static void connectNodes(TestNode... nodes) {
for (int i = 0; i < nodes.length; i++) {
discoveryNodes[i] = nodes[i].discoveryNode();
}
DiscoveryNode master = discoveryNodes[0];
DiscoveryNode clusterManager = discoveryNodes[0];
for (TestNode node : nodes) {
setState(node.clusterService, ClusterStateCreationUtils.state(node.discoveryNode(), master, discoveryNodes));
setState(node.clusterService, ClusterStateCreationUtils.state(node.discoveryNode(), clusterManager, discoveryNodes));
}
for (TestNode nodeA : nodes) {
for (TestNode nodeB : nodes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,21 +374,21 @@ public void testRequestsAreNotSentToFailedMaster() {
Request request = new Request(new String[] { TEST_INDEX });
PlainActionFuture<Response> listener = new PlainActionFuture<>();

DiscoveryNode masterNode = clusterService.state().nodes().getMasterNode();
DiscoveryNode clusterManagerNode = clusterService.state().nodes().getMasterNode();
DiscoveryNodes.Builder builder = DiscoveryNodes.builder(clusterService.state().getNodes());
builder.remove(masterNode.getId());
builder.remove(clusterManagerNode.getId());

setState(clusterService, ClusterState.builder(clusterService.state()).nodes(builder));

action.new AsyncAction(null, request, listener).start();

Map<String, List<CapturingTransport.CapturedRequest>> capturedRequests = transport.getCapturedRequestsByTargetNodeAndClear();

// the master should not be in the list of nodes that requests were sent to
// the cluster manager should not be in the list of nodes that requests were sent to
ShardsIterator shardIt = clusterService.state().routingTable().allShards(new String[] { TEST_INDEX });
Set<String> set = new HashSet<>();
for (ShardRouting shard : shardIt) {
if (!shard.currentNodeId().equals(masterNode.getId())) {
if (!shard.currentNodeId().equals(clusterManagerNode.getId())) {
set.add(shard.currentNodeId());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,11 @@ public void testDelegateToFailingMaster() throws ExecutionException, Interrupted
boolean failsWithConnectTransportException = randomBoolean();
boolean rejoinSameMaster = failsWithConnectTransportException && randomBoolean();
Request request = new Request().masterNodeTimeout(TimeValue.timeValueSeconds(failsWithConnectTransportException ? 60 : 0));
DiscoveryNode masterNode = this.remoteNode;
DiscoveryNode clusterManagerNode = this.remoteNode;
setState(
clusterService,
// use a random base version so it can go down when simulating a restart.
ClusterState.builder(ClusterStateCreationUtils.state(localNode, masterNode, allNodes)).version(randomIntBetween(0, 10))
ClusterState.builder(ClusterStateCreationUtils.state(localNode, clusterManagerNode, allNodes)).version(randomIntBetween(0, 10))
);

PlainActionFuture<Response> listener = new PlainActionFuture<>();
Expand All @@ -439,7 +439,9 @@ public void testDelegateToFailingMaster() throws ExecutionException, Interrupted
if (rejoinSameMaster) {
transport.handleRemoteError(
capturedRequest.requestId,
randomBoolean() ? new ConnectTransportException(masterNode, "Fake error") : new NodeClosedException(masterNode)
randomBoolean()
? new ConnectTransportException(clusterManagerNode, "Fake error")
: new NodeClosedException(clusterManagerNode)
);
assertFalse(listener.isDone());
if (randomBoolean()) {
Expand All @@ -452,15 +454,19 @@ public void testDelegateToFailingMaster() throws ExecutionException, Interrupted
// reset the same state to increment a version simulating a join of an existing node
// simulating use being disconnected
final DiscoveryNodes.Builder nodesBuilder = DiscoveryNodes.builder(clusterService.state().nodes());
nodesBuilder.masterNodeId(masterNode.getId());
nodesBuilder.masterNodeId(clusterManagerNode.getId());
setState(clusterService, ClusterState.builder(clusterService.state()).nodes(nodesBuilder));
} else {
// simulate master restart followed by a state recovery - this will reset the cluster state version
final DiscoveryNodes.Builder nodesBuilder = DiscoveryNodes.builder(clusterService.state().nodes());
nodesBuilder.remove(masterNode);
masterNode = new DiscoveryNode(masterNode.getId(), masterNode.getAddress(), masterNode.getVersion());
nodesBuilder.add(masterNode);
nodesBuilder.masterNodeId(masterNode.getId());
nodesBuilder.remove(clusterManagerNode);
clusterManagerNode = new DiscoveryNode(
clusterManagerNode.getId(),
clusterManagerNode.getAddress(),
clusterManagerNode.getVersion()
);
nodesBuilder.add(clusterManagerNode);
nodesBuilder.masterNodeId(clusterManagerNode.getId());
final ClusterState.Builder builder = ClusterState.builder(clusterService.state()).nodes(nodesBuilder);
setState(clusterService, builder.version(0));
}
Expand All @@ -472,7 +478,7 @@ public void testDelegateToFailingMaster() throws ExecutionException, Interrupted
assertThat(capturedRequest.request, equalTo(request));
assertThat(capturedRequest.action, equalTo("internal:testAction"));
} else if (failsWithConnectTransportException) {
transport.handleRemoteError(capturedRequest.requestId, new ConnectTransportException(masterNode, "Fake error"));
transport.handleRemoteError(capturedRequest.requestId, new ConnectTransportException(clusterManagerNode, "Fake error"));
assertFalse(listener.isDone());
setState(clusterService, ClusterStateCreationUtils.state(localNode, localNode, allNodes));
assertTrue(listener.isDone());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,16 @@ private static class TestShardStateAction extends ShardStateAction {
super(clusterService, transportService, allocationService, rerouteService, THREAD_POOL);
}

private Runnable onBeforeWaitForNewMasterAndRetry;
private Runnable onBeforeWaitForNewClusterManagerAndRetry;

public void setOnBeforeWaitForNewMasterAndRetry(Runnable onBeforeWaitForNewMasterAndRetry) {
this.onBeforeWaitForNewMasterAndRetry = onBeforeWaitForNewMasterAndRetry;
this.onBeforeWaitForNewClusterManagerAndRetry = onBeforeWaitForNewMasterAndRetry;
}

private Runnable onAfterWaitForNewMasterAndRetry;
private Runnable onAfterWaitForNewClusterManagerAndRetry;

public void setOnAfterWaitForNewMasterAndRetry(Runnable onAfterWaitForNewMasterAndRetry) {
this.onAfterWaitForNewMasterAndRetry = onAfterWaitForNewMasterAndRetry;
this.onAfterWaitForNewClusterManagerAndRetry = onAfterWaitForNewMasterAndRetry;
}

@Override
Expand All @@ -132,9 +132,9 @@ protected void waitForNewMasterAndRetry(
ActionListener<Void> listener,
Predicate<ClusterState> changePredicate
) {
onBeforeWaitForNewMasterAndRetry.run();
onBeforeWaitForNewClusterManagerAndRetry.run();
super.waitForNewMasterAndRetry(actionName, observer, request, listener, changePredicate);
onAfterWaitForNewMasterAndRetry.run();
onAfterWaitForNewClusterManagerAndRetry.run();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public void testDescriptionOnUnhealthyNodes() {
is("this node is unhealthy: unhealthy-info")
);

final DiscoveryNode masterNode = new DiscoveryNode(
final DiscoveryNode clusterManagerNode = new DiscoveryNode(
"local",
buildNewFakeTransportAddress(),
emptyMap(),
Expand All @@ -292,7 +292,7 @@ public void testDescriptionOnUnhealthyNodes() {
);
clusterState = ClusterState.builder(ClusterName.DEFAULT)
.version(12L)
.nodes(DiscoveryNodes.builder().add(masterNode).localNodeId(masterNode.getId()))
.nodes(DiscoveryNodes.builder().add(clusterManagerNode).localNodeId(clusterManagerNode.getId()))
.build();

assertThat(
Expand Down Expand Up @@ -818,8 +818,8 @@ public void testDescriptionAfterBootstrapping() {
)
);

final DiscoveryNode otherMasterNode = new DiscoveryNode("other-master", buildNewFakeTransportAddress(), Version.CURRENT);
final DiscoveryNode otherNonMasterNode = new DiscoveryNode(
final DiscoveryNode otherClusterManagerNode = new DiscoveryNode("other-master", buildNewFakeTransportAddress(), Version.CURRENT);
final DiscoveryNode otherNonClusterManagerNode = new DiscoveryNode(
"other-non-master",
buildNewFakeTransportAddress(),
emptyMap(),
Expand All @@ -833,7 +833,13 @@ public void testDescriptionAfterBootstrapping() {

String[] configNodeIds = new String[] { "n1", "n2" };
final ClusterState stateWithOtherNodes = ClusterState.builder(ClusterName.DEFAULT)
.nodes(DiscoveryNodes.builder().add(localNode).localNodeId(localNode.getId()).add(otherMasterNode).add(otherNonMasterNode))
.nodes(
DiscoveryNodes.builder()
.add(localNode)
.localNodeId(localNode.getId())
.add(otherClusterManagerNode)
.add(otherNonClusterManagerNode)
)
.metadata(
Metadata.builder()
.coordinationMetadata(
Expand Down Expand Up @@ -864,13 +870,13 @@ public void testDescriptionAfterBootstrapping() {
+ "discovery will continue using [] from hosts providers and ["
+ localNode
+ ", "
+ otherMasterNode
+ otherClusterManagerNode
+ "] from last-known cluster state; node term 0, last-accepted version 0 in term 0",

"master not discovered or elected yet, an election requires two nodes with ids [n1, n2], "
+ "have discovered [] which is not a quorum; "
+ "discovery will continue using [] from hosts providers and ["
+ otherMasterNode
+ otherClusterManagerNode
+ ", "
+ localNode
+ "] from last-known cluster state; node term 0, last-accepted version 0 in term 0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public void testUpdatesNodeWithNewRoles() throws Exception {

final JoinTaskExecutor joinTaskExecutor = new JoinTaskExecutor(Settings.EMPTY, allocationService, logger, rerouteService, null);

final DiscoveryNode masterNode = new DiscoveryNode(UUIDs.base64UUID(), buildNewFakeTransportAddress(), Version.CURRENT);
final DiscoveryNode clusterManagerNode = new DiscoveryNode(UUIDs.base64UUID(), buildNewFakeTransportAddress(), Version.CURRENT);

final DiscoveryNode actualNode = new DiscoveryNode(UUIDs.base64UUID(), buildNewFakeTransportAddress(), Version.CURRENT);
final DiscoveryNode bwcNode = new DiscoveryNode(
Expand All @@ -183,7 +183,13 @@ public void testUpdatesNodeWithNewRoles() throws Exception {
actualNode.getVersion()
);
final ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT)
.nodes(DiscoveryNodes.builder().add(masterNode).localNodeId(masterNode.getId()).masterNodeId(masterNode.getId()).add(bwcNode))
.nodes(
DiscoveryNodes.builder()
.add(clusterManagerNode)
.localNodeId(clusterManagerNode.getId())
.masterNodeId(clusterManagerNode.getId())
.add(bwcNode)
)
.build();

final ClusterStateTaskExecutor.ClusterTasksResult<JoinTaskExecutor.Task> result = joinTaskExecutor.execute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@

public class NoMasterBlockServiceTests extends OpenSearchTestCase {

private NoMasterBlockService noMasterBlockService;
private NoMasterBlockService noClusterManagerBlockService;
private ClusterSettings clusterSettings;

private void createService(Settings settings) {
clusterSettings = new ClusterSettings(settings, BUILT_IN_CLUSTER_SETTINGS);
noMasterBlockService = new NoMasterBlockService(settings, clusterSettings);
noClusterManagerBlockService = new NoMasterBlockService(settings, clusterSettings);
}

private void assertDeprecatedWarningEmitted() {
Expand All @@ -61,22 +61,22 @@ private void assertDeprecatedWarningEmitted() {

public void testBlocksWritesByDefault() {
createService(Settings.EMPTY);
assertThat(noMasterBlockService.getNoMasterBlock(), sameInstance(NO_MASTER_BLOCK_WRITES));
assertThat(noClusterManagerBlockService.getNoMasterBlock(), sameInstance(NO_MASTER_BLOCK_WRITES));
}

public void testBlocksWritesIfConfiguredBySetting() {
createService(Settings.builder().put(NO_CLUSTER_MANAGER_BLOCK_SETTING.getKey(), "write").build());
assertThat(noMasterBlockService.getNoMasterBlock(), sameInstance(NO_MASTER_BLOCK_WRITES));
assertThat(noClusterManagerBlockService.getNoMasterBlock(), sameInstance(NO_MASTER_BLOCK_WRITES));
}

public void testBlocksAllIfConfiguredBySetting() {
createService(Settings.builder().put(NO_CLUSTER_MANAGER_BLOCK_SETTING.getKey(), "all").build());
assertThat(noMasterBlockService.getNoMasterBlock(), sameInstance(NO_MASTER_BLOCK_ALL));
assertThat(noClusterManagerBlockService.getNoMasterBlock(), sameInstance(NO_MASTER_BLOCK_ALL));
}

public void testBlocksMetadataWritesIfConfiguredBySetting() {
createService(Settings.builder().put(NO_CLUSTER_MANAGER_BLOCK_SETTING.getKey(), "metadata_write").build());
assertThat(noMasterBlockService.getNoMasterBlock(), sameInstance(NO_MASTER_BLOCK_METADATA_WRITES));
assertThat(noClusterManagerBlockService.getNoMasterBlock(), sameInstance(NO_MASTER_BLOCK_METADATA_WRITES));
}

public void testRejectsInvalidSetting() {
Expand All @@ -88,12 +88,12 @@ public void testRejectsInvalidSetting() {

public void testSettingCanBeUpdated() {
createService(Settings.builder().put(NO_CLUSTER_MANAGER_BLOCK_SETTING.getKey(), "all").build());
assertThat(noMasterBlockService.getNoMasterBlock(), sameInstance(NO_MASTER_BLOCK_ALL));
assertThat(noClusterManagerBlockService.getNoMasterBlock(), sameInstance(NO_MASTER_BLOCK_ALL));

clusterSettings.applySettings(Settings.builder().put(NO_CLUSTER_MANAGER_BLOCK_SETTING.getKey(), "write").build());
assertThat(noMasterBlockService.getNoMasterBlock(), sameInstance(NO_MASTER_BLOCK_WRITES));
assertThat(noClusterManagerBlockService.getNoMasterBlock(), sameInstance(NO_MASTER_BLOCK_WRITES));

clusterSettings.applySettings(Settings.builder().put(NO_CLUSTER_MANAGER_BLOCK_SETTING.getKey(), "metadata_write").build());
assertThat(noMasterBlockService.getNoMasterBlock(), sameInstance(NO_MASTER_BLOCK_METADATA_WRITES));
assertThat(noClusterManagerBlockService.getNoMasterBlock(), sameInstance(NO_MASTER_BLOCK_METADATA_WRITES));
}
}
Loading

0 comments on commit 6b0ce71

Please sign in to comment.