Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace master in server test classes
Browse files Browse the repository at this point in the history
Signed-off-by: Tianli Feng <[email protected]>
Tianli Feng committed Feb 17, 2022
1 parent 1e42576 commit 9026aed
Showing 13 changed files with 120 additions and 102 deletions.
Original file line number Diff line number Diff line change
@@ -204,9 +204,9 @@ public void runRepeatedlyWhileChangingMaster(Runnable runnable) throws Exception
String value = "none";
while (shutdown.get() == false) {
value = "none".equals(value) ? "all" : "none";
final String nonMasterNode = randomValueOtherThan(masterName, () -> randomFrom(internalCluster().getNodeNames()));
final String nonClusterManagerNode = randomValueOtherThan(masterName, () -> randomFrom(internalCluster().getNodeNames()));
assertAcked(
client(nonMasterNode).admin()
client(nonClusterManagerNode).admin()
.cluster()
.prepareUpdateSettings()
.setPersistentSettings(Settings.builder().put(CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), value))
@@ -235,8 +235,8 @@ public void runRepeatedlyWhileChangingMaster(Runnable runnable) throws Exception
}

assertBusy(() -> {
final String nonMasterNode = randomValueOtherThan(masterName, () -> randomFrom(internalCluster().getNodeNames()));
final String claimedMasterName = internalCluster().getMasterName(nonMasterNode);
final String nonClusterManagerNode = randomValueOtherThan(masterName, () -> randomFrom(internalCluster().getNodeNames()));
final String claimedMasterName = internalCluster().getMasterName(nonClusterManagerNode);
assertThat(claimedMasterName, not(equalTo(masterName)));
});

Original file line number Diff line number Diff line change
@@ -309,11 +309,11 @@ public void testThreeNodesNoMasterBlock() throws Exception {
assertHitCount(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(), 100);
}

List<String> nonMasterNodes = new ArrayList<>(
List<String> nonClusterManagerNodes = new ArrayList<>(
Sets.difference(Sets.newHashSet(internalCluster().getNodeNames()), Collections.singleton(internalCluster().getMasterName()))
);
Settings nonMasterDataPathSettings1 = internalCluster().dataPathSettings(nonMasterNodes.get(0));
Settings nonMasterDataPathSettings2 = internalCluster().dataPathSettings(nonMasterNodes.get(1));
Settings nonMasterDataPathSettings1 = internalCluster().dataPathSettings(nonClusterManagerNodes.get(0));
Settings nonMasterDataPathSettings2 = internalCluster().dataPathSettings(nonClusterManagerNodes.get(1));
internalCluster().stopRandomNonMasterNode();
internalCluster().stopRandomNonMasterNode();

Original file line number Diff line number Diff line change
@@ -340,26 +340,26 @@ public void testRejoinDocumentExistsInAllShardCopies() throws Exception {
// simulate handling of sending shard failure during an isolation
public void testSendingShardFailure() throws Exception {
List<String> nodes = startCluster(3);
String masterNode = internalCluster().getMasterName();
List<String> nonMasterNodes = nodes.stream().filter(node -> !node.equals(masterNode)).collect(Collectors.toList());
String nonMasterNode = randomFrom(nonMasterNodes);
String clusterManagerNode = internalCluster().getMasterName();
List<String> nonClusterManagerNodes = nodes.stream().filter(node -> !node.equals(clusterManagerNode)).collect(Collectors.toList());
String nonClusterManagerNode = randomFrom(nonClusterManagerNodes);
assertAcked(
prepareCreate("test").setSettings(
Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 3).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 2)
)
);
ensureGreen();
String nonMasterNodeId = internalCluster().clusterService(nonMasterNode).localNode().getId();
String nonClusterManagerNodeId = internalCluster().clusterService(nonClusterManagerNode).localNode().getId();

// fail a random shard
ShardRouting failedShard = randomFrom(
clusterService().state().getRoutingNodes().node(nonMasterNodeId).shardsWithState(ShardRoutingState.STARTED)
clusterService().state().getRoutingNodes().node(nonClusterManagerNodeId).shardsWithState(ShardRoutingState.STARTED)
);
ShardStateAction service = internalCluster().getInstance(ShardStateAction.class, nonMasterNode);
ShardStateAction service = internalCluster().getInstance(ShardStateAction.class, nonClusterManagerNode);
CountDownLatch latch = new CountDownLatch(1);
AtomicBoolean success = new AtomicBoolean();

String isolatedNode = randomBoolean() ? masterNode : nonMasterNode;
String isolatedNode = randomBoolean() ? clusterManagerNode : nonClusterManagerNode;
TwoPartitions partitions = isolateNode(isolatedNode);
// we cannot use the NetworkUnresponsive disruption type here as it will swallow the "shard failed" request, calling neither
// onSuccess nor onFailure on the provided listener.
@@ -387,10 +387,10 @@ public void onFailure(Exception e) {
}
);

if (isolatedNode.equals(nonMasterNode)) {
assertNoMaster(nonMasterNode);
if (isolatedNode.equals(nonClusterManagerNode)) {
assertNoMaster(nonClusterManagerNode);
} else {
ensureStableCluster(2, nonMasterNode);
ensureStableCluster(2, nonClusterManagerNode);
}

// heal the partition
Original file line number Diff line number Diff line change
@@ -201,31 +201,31 @@ public void testElectMasterWithLatestVersion() throws Exception {
public void testNodeNotReachableFromMaster() throws Exception {
startCluster(3);

String masterNode = internalCluster().getMasterName();
String nonMasterNode = null;
while (nonMasterNode == null) {
nonMasterNode = randomFrom(internalCluster().getNodeNames());
if (nonMasterNode.equals(masterNode)) {
nonMasterNode = null;
String clusterManagerNode = internalCluster().getMasterName();
String nonClusterManagerNode = null;
while (nonClusterManagerNode == null) {
nonClusterManagerNode = randomFrom(internalCluster().getNodeNames());
if (nonClusterManagerNode.equals(clusterManagerNode)) {
nonClusterManagerNode = null;
}
}

logger.info("blocking request from master [{}] to [{}]", masterNode, nonMasterNode);
logger.info("blocking request from master [{}] to [{}]", clusterManagerNode, nonClusterManagerNode);
MockTransportService masterTransportService = (MockTransportService) internalCluster().getInstance(
TransportService.class,
masterNode
clusterManagerNode
);
if (randomBoolean()) {
masterTransportService.addUnresponsiveRule(internalCluster().getInstance(TransportService.class, nonMasterNode));
masterTransportService.addUnresponsiveRule(internalCluster().getInstance(TransportService.class, nonClusterManagerNode));
} else {
masterTransportService.addFailToSendNoConnectRule(internalCluster().getInstance(TransportService.class, nonMasterNode));
masterTransportService.addFailToSendNoConnectRule(internalCluster().getInstance(TransportService.class, nonClusterManagerNode));
}

logger.info("waiting for [{}] to be removed from cluster", nonMasterNode);
ensureStableCluster(2, masterNode);
logger.info("waiting for [{}] to be removed from cluster", nonClusterManagerNode);
ensureStableCluster(2, clusterManagerNode);

logger.info("waiting for [{}] to have no master", nonMasterNode);
assertNoMaster(nonMasterNode);
logger.info("waiting for [{}] to have no master", nonClusterManagerNode);
assertNoMaster(nonClusterManagerNode);

logger.info("healing partition and checking cluster reforms");
masterTransportService.clearAllRules();
Original file line number Diff line number Diff line change
@@ -71,33 +71,40 @@ public class MasterDisruptionIT extends AbstractDisruptionTestCase {
public void testMasterNodeGCs() throws Exception {
List<String> nodes = startCluster(3);

String oldMasterNode = internalCluster().getMasterName();
String oldClusterManagerNode = internalCluster().getMasterName();
// a very long GC, but it's OK as we remove the disruption when it has had an effect
SingleNodeDisruption masterNodeDisruption = new IntermittentLongGCDisruption(random(), oldMasterNode, 100, 200, 30000, 60000);
SingleNodeDisruption masterNodeDisruption = new IntermittentLongGCDisruption(
random(),
oldClusterManagerNode,
100,
200,
30000,
60000
);
internalCluster().setDisruptionScheme(masterNodeDisruption);
masterNodeDisruption.startDisrupting();

Set<String> oldNonMasterNodesSet = new HashSet<>(nodes);
oldNonMasterNodesSet.remove(oldMasterNode);
Set<String> oldNonClusterManagerNodesSet = new HashSet<>(nodes);
oldNonClusterManagerNodesSet.remove(oldClusterManagerNode);

List<String> oldNonMasterNodes = new ArrayList<>(oldNonMasterNodesSet);
List<String> oldNonClusterManagerNodes = new ArrayList<>(oldNonClusterManagerNodesSet);

logger.info("waiting for nodes to de-elect master [{}]", oldMasterNode);
for (String node : oldNonMasterNodesSet) {
assertDifferentMaster(node, oldMasterNode);
logger.info("waiting for nodes to de-elect master [{}]", oldClusterManagerNode);
for (String node : oldNonClusterManagerNodesSet) {
assertDifferentMaster(node, oldClusterManagerNode);
}

logger.info("waiting for nodes to elect a new master");
ensureStableCluster(2, oldNonMasterNodes.get(0));
ensureStableCluster(2, oldNonClusterManagerNodes.get(0));

// restore GC
masterNodeDisruption.stopDisrupting();
final TimeValue waitTime = new TimeValue(DISRUPTION_HEALING_OVERHEAD.millis() + masterNodeDisruption.expectedTimeToHeal().millis());
ensureStableCluster(3, waitTime, false, oldNonMasterNodes.get(0));
ensureStableCluster(3, waitTime, false, oldNonClusterManagerNodes.get(0));

// make sure all nodes agree on master
String newMaster = internalCluster().getMasterName();
assertThat(newMaster, not(equalTo(oldMasterNode)));
assertThat(newMaster, not(equalTo(oldClusterManagerNode)));
assertMaster(newMaster, nodes);
}

Original file line number Diff line number Diff line change
@@ -459,11 +459,11 @@ public void testShardActiveElsewhereDoesNotDeleteAnother() throws Exception {
public void testShardActiveElseWhere() throws Exception {
List<String> nodes = internalCluster().startNodes(2);

final String masterNode = internalCluster().getMasterName();
final String nonMasterNode = nodes.get(0).equals(masterNode) ? nodes.get(1) : nodes.get(0);
final String clusterManagerNode = internalCluster().getMasterName();
final String nonClusterManagerNode = nodes.get(0).equals(clusterManagerNode) ? nodes.get(1) : nodes.get(0);

final String masterId = internalCluster().clusterService(masterNode).localNode().getId();
final String nonMasterId = internalCluster().clusterService(nonMasterNode).localNode().getId();
final String clusterManagerId = internalCluster().clusterService(clusterManagerNode).localNode().getId();
final String nonClusterManagerId = internalCluster().clusterService(nonClusterManagerNode).localNode().getId();

final int numShards = scaledRandomIntBetween(2, 10);
assertAcked(
@@ -476,14 +476,14 @@ public void testShardActiveElseWhere() throws Exception {
waitNoPendingTasksOnAll();
ClusterStateResponse stateResponse = client().admin().cluster().prepareState().get();
final Index index = stateResponse.getState().metadata().index("test").getIndex();
RoutingNode routingNode = stateResponse.getState().getRoutingNodes().node(nonMasterId);
RoutingNode routingNode = stateResponse.getState().getRoutingNodes().node(nonClusterManagerId);
final int[] node2Shards = new int[routingNode.numberOfOwningShards()];
int i = 0;
for (ShardRouting shardRouting : routingNode) {
node2Shards[i] = shardRouting.shardId().id();
i++;
}
logger.info("Node [{}] has shards: {}", nonMasterNode, Arrays.toString(node2Shards));
logger.info("Node [{}] has shards: {}", nonClusterManagerNode, Arrays.toString(node2Shards));

// disable relocations when we do this, to make sure the shards are not relocated from node2
// due to rebalancing, and delete its content
@@ -496,14 +496,14 @@ public void testShardActiveElseWhere() throws Exception {
)
.get();

ClusterApplierService clusterApplierService = internalCluster().getInstance(ClusterService.class, nonMasterNode)
ClusterApplierService clusterApplierService = internalCluster().getInstance(ClusterService.class, nonClusterManagerNode)
.getClusterApplierService();
ClusterState currentState = clusterApplierService.state();
IndexRoutingTable.Builder indexRoutingTableBuilder = IndexRoutingTable.builder(index);
for (int j = 0; j < numShards; j++) {
indexRoutingTableBuilder.addIndexShard(
new IndexShardRoutingTable.Builder(new ShardId(index, j)).addShard(
TestShardRouting.newShardRouting("test", j, masterId, true, ShardRoutingState.STARTED)
TestShardRouting.newShardRouting("test", j, clusterManagerId, true, ShardRoutingState.STARTED)
).build()
);
}
@@ -528,7 +528,7 @@ public void onFailure(String source, Exception e) {
waitNoPendingTasksOnAll();
logger.info("Checking if shards aren't removed");
for (int shard : node2Shards) {
assertShardExists(nonMasterNode, index, shard);
assertShardExists(nonClusterManagerNode, index, shard);
}
}

Original file line number Diff line number Diff line change
@@ -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(),
@@ -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(
@@ -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"
Original file line number Diff line number Diff line change
@@ -108,12 +108,12 @@ public void testAll() {
assertThat(discoveryNodes.resolveNodes(new String[0]), arrayContainingInAnyOrder(allNodes));
assertThat(discoveryNodes.resolveNodes("_all"), arrayContainingInAnyOrder(allNodes));

final String[] nonMasterNodes = StreamSupport.stream(discoveryNodes.getNodes().values().spliterator(), false)
final String[] nonClusterManagerNodes = StreamSupport.stream(discoveryNodes.getNodes().values().spliterator(), false)
.map(n -> n.value)
.filter(n -> n.isMasterNode() == false)
.map(DiscoveryNode::getId)
.toArray(String[]::new);
assertThat(discoveryNodes.resolveNodes("_all", "master:false"), arrayContainingInAnyOrder(nonMasterNodes));
assertThat(discoveryNodes.resolveNodes("_all", "master:false"), arrayContainingInAnyOrder(nonClusterManagerNodes));

assertThat(discoveryNodes.resolveNodes("master:false", "_all"), arrayContainingInAnyOrder(allNodes));
}
Original file line number Diff line number Diff line change
@@ -190,7 +190,7 @@ public void testLogsFullConnectionFailureAfterSuccessfulHandshake() throws Excep
}
}

public void testDoesNotConnectToNonMasterNode() throws InterruptedException {
public void testDoesNotConnectToNonClusterManagerNode() throws InterruptedException {
remoteNode = new DiscoveryNode("remote-node", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
discoveryAddress = getDiscoveryAddress();
remoteClusterName = "local-cluster";
Original file line number Diff line number Diff line change
@@ -336,16 +336,16 @@ public void testDoesNotAddUnreachableNodesFromUnicastHostsList() {
}

public void testDoesNotAddNonMasterEligibleNodesFromUnicastHostsList() {
final DiscoveryNode nonMasterNode = new DiscoveryNode(
final DiscoveryNode nonClusterManagerNode = new DiscoveryNode(
"node-from-hosts-list",
buildNewFakeTransportAddress(),
emptyMap(),
emptySet(),
Version.CURRENT
);

providedAddresses.add(nonMasterNode.getAddress());
transportAddressConnector.addReachableNode(nonMasterNode);
providedAddresses.add(nonClusterManagerNode.getAddress());
transportAddressConnector.addReachableNode(nonClusterManagerNode);

peerFinder.activate(lastAcceptedNodes);
runAllRunnableTasks();
Original file line number Diff line number Diff line change
@@ -566,10 +566,10 @@ public void testEnsureNoShardDataOrIndexMetadata() throws IOException {
verifyFailsOnMetadata(noDataNoMasterSettings, indexPath);

// build settings using same path.data as original but without master role
Settings noMasterSettings = nonMasterNode(settings);
Settings noClusterManagerSettings = nonMasterNode(settings);

// test that we can create master=false env regardless of data.
newNodeEnvironment(noMasterSettings).close();
newNodeEnvironment(noClusterManagerSettings).close();

// test that we can create data=true, master=true env. Also remove state dir to leave only shard data for following asserts
try (NodeEnvironment env = newNodeEnvironment(settings)) {
Loading

0 comments on commit 9026aed

Please sign in to comment.