Skip to content

Commit

Permalink
Simplify node stopping call (#88547)
Browse files Browse the repository at this point in the history
There is no need to use stopRandomNode/namePredicate combination to stop a node by its name.
  • Loading branch information
idegtiarenko committed Jul 22, 2022
1 parent bd5e16d commit 584f7f2
Show file tree
Hide file tree
Showing 32 changed files with 85 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void testClearVotingTombstonesWaitingForRemoval() throws Exception {
final Response response = restClient.performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));
assertThat(response.getEntity().getContentLength(), is(0L));
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodeToWithdraw));
internalCluster().stopNode(nodeToWithdraw);
Response deleteResponse = restClient.performRequest(new Request("DELETE", "/_cluster/voting_config_exclusions"));
assertThat(deleteResponse.getStatusLine().getStatusCode(), is(200));
assertThat(deleteResponse.getEntity().getContentLength(), is(0L));
Expand All @@ -167,8 +167,8 @@ public void testRemoveTwoNodesAtOnce() throws Exception {
final Response response = restClient.performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));
assertThat(response.getEntity().getContentLength(), is(0L));
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodes.get(0)));
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodes.get(2)));
internalCluster().stopNode(nodes.get(0));
internalCluster().stopNode(nodes.get(2));
ensureStableCluster(1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsRequest;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.InternalTestCluster;
import org.elasticsearch.test.MockLogAppender;
import org.elasticsearch.test.junit.annotations.TestLogging;
import org.elasticsearch.transport.TcpTransport;
Expand Down Expand Up @@ -110,7 +109,7 @@ public void testConnectionLogging() throws IOException {
);

final String nodeName = internalCluster().startNode();
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodeName));
internalCluster().stopNode(nodeName);

appender.assertAllExpectationsMatched();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.InternalTestCluster;
import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser;
Expand Down Expand Up @@ -71,7 +70,7 @@ public void testUnassignedPrimaryWithExistingIndex() throws Exception {
prepareIndex(1, 0);

logger.info("--> stopping the node with the primary");
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(primaryNodeName()));
internalCluster().stopNode(primaryNodeName());
ensureStableCluster(1);
refreshClusterInfo();

Expand Down Expand Up @@ -150,7 +149,7 @@ public void testUnassignedReplicaDelayedAllocation() throws Exception {

prepareIndex(1, 1);
logger.info("--> stopping the node with the replica");
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(replicaNode().getName()));
internalCluster().stopNode(replicaNode().getName());
ensureStableCluster(2);
refreshClusterInfo();
assertBusy(() ->
Expand Down Expand Up @@ -291,8 +290,8 @@ public void testUnassignedReplicaWithPriorCopy() throws Exception {
logger.info("--> shutting down all nodes except the one that holds the primary");
Settings node0DataPathSettings = internalCluster().dataPathSettings(nodes.get(0));
Settings node1DataPathSettings = internalCluster().dataPathSettings(nodes.get(1));
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodes.get(0)));
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodes.get(1)));
internalCluster().stopNode(nodes.get(0));
internalCluster().stopNode(nodes.get(1));
ensureStableCluster(1);

logger.info("--> setting allocation filtering to only allow allocation on the currently running node");
Expand Down Expand Up @@ -1080,7 +1079,7 @@ public void testCannotAllocateStaleReplicaExplanation() throws Exception {
assertThat(primaryNodeName(), equalTo(primaryNode));

logger.info("--> stop node with the replica shard");
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(replicaNode));
internalCluster().stopNode(replicaNode);

final IndexMetadata.State indexState = randomIndexState();
if (indexState == IndexMetadata.State.OPEN) {
Expand All @@ -1102,7 +1101,7 @@ public void testCannotAllocateStaleReplicaExplanation() throws Exception {
}

logger.info("--> stop the node with the primary");
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(primaryNode));
internalCluster().stopNode(primaryNode);

logger.info("--> restart the node with the stale replica");
String restartedNode = internalCluster().startDataOnlyNode(replicaDataPathSettings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.elasticsearch.tasks.TaskInfo;
import org.elasticsearch.tasks.TaskManager;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.InternalTestCluster;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.SendRequestTransportException;
import org.elasticsearch.transport.Transport;
Expand Down Expand Up @@ -294,7 +293,7 @@ public void testCancelOrphanedTasks() throws Exception {
client(nodeWithRootTask).execute(TransportTestAction.ACTION, rootRequest);
allowPartialRequest(rootRequest);
try {
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodeWithRootTask));
internalCluster().stopNode(nodeWithRootTask);
assertBusy(() -> {
for (TransportService transportService : internalCluster().getInstances(TransportService.class)) {
for (CancellableTask task : transportService.getTaskManager().getCancellableTasks().values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.elasticsearch.index.shard.IndexShard;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.InternalTestCluster;
import org.elasticsearch.test.VersionUtils;
import org.elasticsearch.xcontent.XContentType;

Expand Down Expand Up @@ -668,7 +667,7 @@ public void testShrinkThenSplitWithFailedNode() throws Exception {
ensureGreen();

final int nodeCount = cluster().size();
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(shrinkNode));
internalCluster().stopNode(shrinkNode);
ensureStableCluster(nodeCount - 1);

// demonstrate that the index.routing.allocation.initial_recovery setting from the shrink doesn't carry over into the split index,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.plugins.PluginsService;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.InternalTestCluster;
import org.elasticsearch.test.transport.MockTransportService;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.Transport;
Expand Down Expand Up @@ -224,7 +223,7 @@ public void testRetryOnStoppedTransportService() throws Exception {
throw new AssertionError(e);
}
});
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(primary));
internalCluster().stopNode(primary);

assertTrue(doneLatch.await(10, TimeUnit.SECONDS));
if (response.get() instanceof Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.test.ESIntegTestCase.Scope;
import org.elasticsearch.test.InternalTestCluster;
import org.elasticsearch.test.disruption.NetworkDisruption;
import org.elasticsearch.test.transport.MockTransportService;

Expand Down Expand Up @@ -133,7 +132,7 @@ public void testTwoNodesNoMasterBlock() throws Exception {
client().execute(AddVotingConfigExclusionsAction.INSTANCE, new AddVotingConfigExclusionsRequest(otherNode)).get();
logger.info("--> stop master node, no master block should appear");
Settings masterDataPathSettings = internalCluster().dataPathSettings(masterNode);
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(masterNode));
internalCluster().stopNode(masterNode);

assertBusy(() -> {
ClusterState clusterState = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
Expand Down Expand Up @@ -186,7 +185,7 @@ public void testTwoNodesNoMasterBlock() throws Exception {
client().execute(AddVotingConfigExclusionsAction.INSTANCE, new AddVotingConfigExclusionsRequest(masterNode)).get();
logger.info("--> stop non-master node, no master block should appear");
Settings otherNodeDataPathSettings = internalCluster().dataPathSettings(otherNode);
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(otherNode));
internalCluster().stopNode(otherNode);

assertBusy(() -> {
ClusterState state1 = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.test.ESIntegTestCase.Scope;
import org.elasticsearch.test.InternalTestCluster;

import java.io.IOException;

Expand Down Expand Up @@ -258,7 +257,7 @@ public void testElectOnlyBetweenMasterNodes() throws Exception {
equalTo(nextMasterEligableNodeName)
);
});
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(masterNodeName));
internalCluster().stopNode(masterNodeName);
assertThat(
internalCluster().nonMasterClient()
.admin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.test.ESIntegTestCase.Scope;
import org.elasticsearch.test.InternalTestCluster;
import org.elasticsearch.test.MockLogAppender;

import java.nio.file.Path;
Expand Down Expand Up @@ -247,7 +246,7 @@ public void testDelayWithALargeAmountOfShards() throws Exception {
ensureGreen(TimeValue.timeValueMinutes(1));

logger.info("--> stopping node1");
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(node_1));
internalCluster().stopNode(node_1);

// This might run slowly on older hardware
ensureGreen(TimeValue.timeValueMinutes(2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ public void test3MasterNodes2Failed() throws Exception {
Settings dataNodeDataPathSettings = internalCluster().dataPathSettings(dataNode);

logger.info("--> stop 2nd and 3d master eligible node");
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(masterNodes.get(1)));
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(masterNodes.get(2)));
internalCluster().stopNode(masterNodes.get(1));
internalCluster().stopNode(masterNodes.get(2));

logger.info("--> ensure NO_MASTER_BLOCK on data-only node");
assertBusy(() -> {
Expand All @@ -262,7 +262,7 @@ public void test3MasterNodes2Failed() throws Exception {

logger.info("--> stop 1st master-eligible node and data-only node");
NodeEnvironment nodeEnvironment = internalCluster().getAnyMasterNodeInstance(NodeEnvironment.class);
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(masterNodes.get(0)));
internalCluster().stopNode(masterNodes.get(0));
assertBusy(() -> internalCluster().getInstance(GatewayMetaState.class, dataNode).allPendingAsyncStatesWritten());
internalCluster().stopRandomDataNode();

Expand Down Expand Up @@ -351,7 +351,7 @@ public void testNoInitialBootstrapAfterDetach() throws Exception {
ClusterState state = internalCluster().client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
assertTrue(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID));

internalCluster().stopRandomNode(InternalTestCluster.nameFilter(node));
internalCluster().stopNode(node);
}

public void testCanRunUnsafeBootstrapAfterErroneousDetachWithoutLoosingMetadata() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.elasticsearch.test.DummyShardLock;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.InternalSettingsPlugin;
import org.elasticsearch.test.InternalTestCluster;
import org.elasticsearch.test.transport.MockTransportService;

import java.io.IOException;
Expand Down Expand Up @@ -98,13 +97,13 @@ public void testFailedRecoveryOnAllocateStalePrimaryRequiresAnotherAllocateStale

Settings node1DataPathSettings = internalCluster().dataPathSettings(node1);
Settings node2DataPathSettings = internalCluster().dataPathSettings(node2);
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(node1));
internalCluster().stopNode(node1);

// index more docs to node2 that marks node1 as stale
int numExtraDocs = indexDocs(indexName, "foo", "bar2");
assertHitCount(client(node2).prepareSearch(indexName).setQuery(matchAllQuery()).get(), numDocs + numExtraDocs);

internalCluster().stopRandomNode(InternalTestCluster.nameFilter(node2));
internalCluster().stopNode(node2);

// create fake corrupted marker on node1
putFakeCorruptionMarker(indexSettings, shardId, indexPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.InternalTestCluster;

import java.util.Collections;
import java.util.List;
Expand All @@ -39,7 +38,7 @@ public void testNoDelayedTimeout() throws Exception {
).get();
ensureGreen("test");
indexRandomData();
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(findNodeWithShard()));
internalCluster().stopNode(findNodeWithShard());
assertThat(client().admin().cluster().prepareHealth().get().getDelayedUnassignedShards(), equalTo(0));
ensureGreen("test");
}
Expand All @@ -62,7 +61,7 @@ public void testDelayedAllocationNodeLeavesAndComesBack() throws Exception {
indexRandomData();
String nodeWithShard = findNodeWithShard();
Settings nodeWithShardDataPathSettings = internalCluster().dataPathSettings(nodeWithShard);
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodeWithShard));
internalCluster().stopNode(nodeWithShard);
assertBusy(
() -> assertThat(
client().admin().cluster().prepareState().all().get().getState().getRoutingNodes().unassigned().size() > 0,
Expand All @@ -88,7 +87,7 @@ public void testDelayedAllocationTimesOut() throws Exception {
).get();
ensureGreen("test");
indexRandomData();
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(findNodeWithShard()));
internalCluster().stopNode(findNodeWithShard());
ensureGreen("test");
internalCluster().startNode();
// do a second round with longer delay to make sure it happens
Expand All @@ -101,7 +100,7 @@ public void testDelayedAllocationTimesOut() throws Exception {
)
.get()
);
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(findNodeWithShard()));
internalCluster().stopNode(findNodeWithShard());
ensureGreen("test");
}

Expand All @@ -120,7 +119,7 @@ public void testDelayedAllocationChangeWithSettingTo100ms() throws Exception {
).get();
ensureGreen("test");
indexRandomData();
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(findNodeWithShard()));
internalCluster().stopNode(findNodeWithShard());
assertBusy(
() -> assertThat(
client().admin().cluster().prepareState().all().get().getState().getRoutingNodes().unassigned().size() > 0,
Expand Down Expand Up @@ -156,7 +155,7 @@ public void testDelayedAllocationChangeWithSettingTo0() throws Exception {
).get();
ensureGreen("test");
indexRandomData();
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(findNodeWithShard()));
internalCluster().stopNode(findNodeWithShard());
assertBusy(
() -> assertThat(
client().admin().cluster().prepareState().all().get().getState().getRoutingNodes().unassigned().size() > 0,
Expand Down

0 comments on commit 584f7f2

Please sign in to comment.