Skip to content

Commit

Permalink
Resolve compile error
Browse files Browse the repository at this point in the history
Signed-off-by: Tianli Feng <ftianli@amazon.com>
  • Loading branch information
Tianli Feng committed May 15, 2022
1 parent fd5ad03 commit d41b1ed
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public void testAbdicateAfterVotingConfigExclusionAdded() throws ExecutionExcept
internalCluster().startNodes(2);
final String originalClusterManager = internalCluster().getMasterName();

logger.info("--> excluding cluster-manager node {}", originalMaster);
client().execute(AddVotingConfigExclusionsAction.INSTANCE, new AddVotingConfigExclusionsRequest(originalMaster)).get();
logger.info("--> excluding cluster-manager node {}", originalClusterManager);
client().execute(AddVotingConfigExclusionsAction.INSTANCE, new AddVotingConfigExclusionsRequest(originalClusterManager)).get();
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).get();
assertNotEquals(originalMaster, internalCluster().getMasterName());
assertNotEquals(originalClusterManager, internalCluster().getMasterName());
}

public void testElectsNodeNotInVotingConfiguration() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ public void testNoShardRelocationsOccurWhenElectedMasterNodeFails() throws Excep
assertBusy(() -> {
String current = internalCluster().getMasterName();
assertThat(current, notNullValue());
assertThat(current, not(equalTo(oldMaster)));
assertThat(current, not(equalTo(oldClusterManager)));
});
ensureSearchable("test");

r = client().admin().indices().prepareRecoveries("test").get();
int numRecoveriesAfterNewClusterManager = r.shardRecoveryStates().get("test").size();
assertThat(numRecoveriesAfterNewMaster, equalTo(numRecoveriesBeforeNewMaster));
assertThat(numRecoveriesAfterNewClusterManager, equalTo(numRecoveriesBeforeNewClusterManager));
}

public void testHandleNodeJoin_incompatibleClusterState() throws InterruptedException, ExecutionException, TimeoutException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public void testDoNotAllowStaleReplicasToBePromotedToPrimary() throws Exception
.get()
);
ensureGreen();
final Settings inSyncDataPathSettings = createStaleReplicaScenario(master);
final Settings inSyncDataPathSettings = createStaleReplicaScenario(clusterManager);

logger.info("--> starting node that reuses data folder with the up-to-date primary shard");
internalCluster().startDataOnlyNode(inSyncDataPathSettings);
Expand Down Expand Up @@ -674,7 +674,7 @@ public void testPrimaryReplicaResyncFailed() throws Exception {
ensureGreen();
String timeout = randomFrom("0s", "1s", "2s");
assertAcked(
client(master).admin()
client(clusterManager).admin()
.cluster()
.prepareUpdateSettings()
.setTransientSettings(Settings.builder().put("cluster.routing.allocation.enable", "none"))
Expand Down Expand Up @@ -703,7 +703,7 @@ public void testPrimaryReplicaResyncFailed() throws Exception {
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(oldPrimary));
// Checks that we fails replicas in one side but not mark them as stale.
assertBusy(() -> {
ClusterState state = client(master).admin().cluster().prepareState().get().getState();
ClusterState state = client(clusterManager).admin().cluster().prepareState().get().getState();
final IndexShardRoutingTable shardRoutingTable = state.routingTable().shardRoutingTable(shardId);
final String newPrimaryNode = state.getRoutingNodes().node(shardRoutingTable.primary.currentNodeId()).node().getName();
assertThat(newPrimaryNode, not(equalTo(oldPrimary)));
Expand All @@ -715,7 +715,7 @@ public void testPrimaryReplicaResyncFailed() throws Exception {
assertThat(state.metadata().index("test").inSyncAllocationIds(shardId.id()), hasSize(numberOfReplicas + 1));
}, 1, TimeUnit.MINUTES);
assertAcked(
client(master).admin()
client(clusterManager).admin()
.cluster()
.prepareUpdateSettings()
.setTransientSettings(Settings.builder().put("cluster.routing.allocation.enable", "all"))
Expand All @@ -725,7 +725,7 @@ public void testPrimaryReplicaResyncFailed() throws Exception {
partition.ensureHealthy(internalCluster());
logger.info("--> stop disrupting network and re-enable allocation");
assertBusy(() -> {
ClusterState state = client(master).admin().cluster().prepareState().get().getState();
ClusterState state = client(clusterManager).admin().cluster().prepareState().get().getState();
assertThat(state.routingTable().shardRoutingTable(shardId).activeShards(), hasSize(numberOfReplicas));
assertThat(state.metadata().index("test").inSyncAllocationIds(shardId.id()), hasSize(numberOfReplicas + 1));
for (String node : replicaNodes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ public void testElectMasterWithLatestVersion() throws Exception {
}
internalCluster().clearDisruptionScheme();
ensureStableCluster(3);
final String preferredMasterName = internalCluster().getMasterName();
final DiscoveryNode preferredClusterManager = internalCluster().clusterService(preferredMasterName).localNode();
final String preferredClusterManagerName = internalCluster().getMasterName();
final DiscoveryNode preferredClusterManager = internalCluster().clusterService(preferredClusterManagerName).localNode();

logger.info("--> preferred cluster-manager is {}", preferredMaster);
logger.info("--> preferred cluster-manager is {}", preferredClusterManager);
final Set<String> nonPreferredNodes = new HashSet<>(nodes);
nonPreferredNodes.remove(preferredMasterName);
nonPreferredNodes.remove(preferredClusterManagerName);
final ServiceDisruptionScheme isolatePreferredClusterManager = isolateMasterDisruption(NetworkDisruption.DISCONNECT);
internalCluster().setDisruptionScheme(isolatePreferredMaster);
isolatePreferredMaster.startDisrupting();
internalCluster().setDisruptionScheme(isolatePreferredClusterManager);
isolatePreferredClusterManager.startDisrupting();

client(randomFrom(nonPreferredNodes)).admin()
.indices()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public void testMasterNodeGCs() throws Exception {

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,22 @@ private void testFollowerCheckerAfterMasterReelection(NetworkLinkDisruptionType

final String clusterManager = internalCluster().getMasterName();
final List<String> nonMasters = Arrays.stream(internalCluster().getNodeNames())
.filter(n -> master.equals(n) == false)
.filter(n -> clusterManager.equals(n) == false)
.collect(Collectors.toList());
final String isolatedNode = randomFrom(nonMasters);
final String otherNode = nonMasters.get(nonMasters.get(0).equals(isolatedNode) ? 1 : 0);

logger.info("--> isolating [{}]", isolatedNode);

final NetworkDisruption networkDisruption = new NetworkDisruption(
new TwoPartitions(singleton(isolatedNode), Sets.newHashSet(master, otherNode)),
new TwoPartitions(singleton(isolatedNode), Sets.newHashSet(clusterManager, otherNode)),
networkLinkDisruptionType
);
setDisruptionScheme(networkDisruption);
networkDisruption.startDisrupting();

logger.info("--> waiting for cluster-manager to remove it");
ensureStableCluster(2, master);
ensureStableCluster(2, clusterManager);
ensureNoMaster(isolatedNode);

networkDisruption.stopDisrupting();
Expand All @@ -205,14 +205,14 @@ public void testStaleMasterNotHijackingMajority() throws Exception {
ensureStableCluster(3);

// Save the current cluster-manager node as old cluster-manager node, because that node will get frozen
final String oldMasterNode = internalCluster().getMasterName();
final String oldClusterManagerNode = internalCluster().getMasterName();

// Simulating a painful gc by suspending all threads for a long time on the current elected cluster-manager node.
SingleNodeDisruption masterNodeDisruption = new LongGCDisruption(random(), oldMasterNode);
SingleNodeDisruption clusterManagerNodeDisruption = new LongGCDisruption(random(), oldClusterManagerNode);

// Save the majority side
final List<String> majoritySide = new ArrayList<>(nodes);
majoritySide.remove(oldMasterNode);
majoritySide.remove(oldClusterManagerNode);

// Keeps track of the previous and current cluster-manager when a cluster-manager node transition took place on each node on the
// majority side:
Expand All @@ -222,30 +222,30 @@ public void testStaleMasterNotHijackingMajority() throws Exception {
internalCluster().getInstance(ClusterService.class, node).addListener(event -> {
DiscoveryNode previousClusterManager = event.previousState().nodes().getMasterNode();
DiscoveryNode currentClusterManager = event.state().nodes().getMasterNode();
if (!Objects.equals(previousMaster, currentMaster)) {
if (!Objects.equals(previousClusterManager, currentClusterManager)) {
logger.info(
"--> node {} received new cluster state: {} \n and had previous cluster state: {}",
node,
event.state(),
event.previousState()
);
String previousClusterManagerNodeName = previousClusterManager != null ? previousMaster.getName() : null;
String currentMasterNodeName = currentClusterManager != null ? currentMaster.getName() : null;
String previousClusterManagerNodeName = previousClusterManager != null ? previousClusterManager.getName() : null;
String currentMasterNodeName = currentClusterManager != null ? currentClusterManager.getName() : null;
masters.get(node).add(new Tuple<>(previousClusterManagerNodeName, currentMasterNodeName));
}
});
}

final CountDownLatch oldMasterNodeSteppedDown = new CountDownLatch(1);
internalCluster().getInstance(ClusterService.class, oldMasterNode).addListener(event -> {
internalCluster().getInstance(ClusterService.class, oldClusterManagerNode).addListener(event -> {
if (event.state().nodes().getMasterNodeId() == null) {
oldMasterNodeSteppedDown.countDown();
}
});

internalCluster().setDisruptionScheme(masterNodeDisruption);
logger.info("--> freezing node [{}]", oldMasterNode);
masterNodeDisruption.startDisrupting();
internalCluster().setDisruptionScheme(clusterManagerNodeDisruption);
logger.info("--> freezing node [{}]", oldClusterManagerNode);
clusterManagerNodeDisruption.startDisrupting();

// Wait for majority side to elect a new master
assertBusy(() -> {
Expand All @@ -260,7 +260,7 @@ public void testStaleMasterNotHijackingMajority() throws Exception {
// once the old cluster-manager node un-freezes it gets executed. The old cluster-manager node will send this update + the cluster
// state where it is
// flagged as cluster-manager to the other nodes that follow the new master. These nodes should ignore this update.
internalCluster().getInstance(ClusterService.class, oldMasterNode)
internalCluster().getInstance(ClusterService.class, oldClusterManagerNode)
.submitStateUpdateTask("sneaky-update", new ClusterStateUpdateTask(Priority.IMMEDIATE) {
@Override
public ClusterState execute(ClusterState currentState) {
Expand All @@ -278,20 +278,25 @@ public void onFailure(String source, Exception e) {
logger.info("--> new detected cluster-manager node [{}]", newMasterNode);

// Stop disruption
logger.info("--> unfreezing node [{}]", oldMasterNode);
masterNodeDisruption.stopDisrupting();
logger.info("--> unfreezing node [{}]", oldClusterManagerNode);
clusterManagerNodeDisruption.stopDisrupting();

oldMasterNodeSteppedDown.await(30, TimeUnit.SECONDS);
logger.info("--> [{}] stepped down as master", oldMasterNode);
logger.info("--> [{}] stepped down as master", oldClusterManagerNode);
ensureStableCluster(3);

assertThat(masters.size(), equalTo(2));
for (Map.Entry<String, List<Tuple<String, String>>> entry : masters.entrySet()) {
String nodeName = entry.getKey();
List<Tuple<String, String>> transitions = entry.getValue();
assertTrue(
"[" + nodeName + "] should not apply state from old cluster-manager [" + oldMasterNode + "] but it did: " + transitions,
transitions.stream().noneMatch(t -> oldMasterNode.equals(t.v2()))
"["
+ nodeName
+ "] should not apply state from old cluster-manager ["
+ oldClusterManagerNode
+ "] but it did: "
+ transitions,
transitions.stream().noneMatch(t -> oldClusterManagerNode.equals(t.v2()))
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private void assertIndexMetadataLoads(final String snapshot, final String index,

private CountingMockRepository getCountingMockRepository() {
String clusterManager = internalCluster().getMasterName();
RepositoriesService repositoriesService = internalCluster().getInstance(RepositoriesService.class, master);
RepositoriesService repositoriesService = internalCluster().getInstance(RepositoriesService.class, clusterManager);
Repository repository = repositoriesService.repository("repository");
assertThat(repository, instanceOf(CountingMockRepository.class));
return (CountingMockRepository) repository;
Expand Down

0 comments on commit d41b1ed

Please sign in to comment.