Skip to content

Commit 1b81ef6

Browse files
committed
Run TransportClusterStateAction on local node
This action solely needs the cluster state, it can run on any node.
1 parent 88996bc commit 1b81ef6

File tree

37 files changed

+117
-269
lines changed

37 files changed

+117
-269
lines changed

plugins/discovery-azure-classic/src/internalClusterTest/java/org/elasticsearch/discovery/azure/classic/AzureSimpleTests.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,7 @@ public void testOneNodeShouldRunUsingPrivateIp() {
2828

2929
final String node1 = internalCluster().startNode(settings);
3030
registerAzureNode(node1);
31-
assertNotNull(
32-
client().admin()
33-
.cluster()
34-
.prepareState(TEST_REQUEST_TIMEOUT)
35-
.setMasterNodeTimeout(TimeValue.timeValueSeconds(1))
36-
.get()
37-
.getState()
38-
.nodes()
39-
.getMasterNodeId()
40-
);
31+
assertNotNull(client().admin().cluster().prepareState(TimeValue.timeValueSeconds(1)).get().getState().nodes().getMasterNodeId());
4132

4233
// We expect having 1 node as part of the cluster, let's test that
4334
assertNumberOfNodes(1);
@@ -50,16 +41,7 @@ public void testOneNodeShouldRunUsingPublicIp() {
5041

5142
final String node1 = internalCluster().startNode(settings);
5243
registerAzureNode(node1);
53-
assertNotNull(
54-
client().admin()
55-
.cluster()
56-
.prepareState(TEST_REQUEST_TIMEOUT)
57-
.setMasterNodeTimeout(TimeValue.timeValueSeconds(1))
58-
.get()
59-
.getState()
60-
.nodes()
61-
.getMasterNodeId()
62-
);
44+
assertNotNull(client().admin().cluster().prepareState(TimeValue.timeValueSeconds(1)).get().getState().nodes().getMasterNodeId());
6345

6446
// We expect having 1 node as part of the cluster, let's test that
6547
assertNumberOfNodes(1);

plugins/discovery-azure-classic/src/internalClusterTest/java/org/elasticsearch/discovery/azure/classic/AzureTwoStartedNodesTests.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,12 @@ public void testTwoNodesShouldRunUsingPrivateOrPublicIp() {
3131
logger.info("--> start first node");
3232
final String node1 = internalCluster().startNode(settings);
3333
registerAzureNode(node1);
34-
assertNotNull(
35-
client().admin()
36-
.cluster()
37-
.prepareState(TEST_REQUEST_TIMEOUT)
38-
.setMasterNodeTimeout(TimeValue.timeValueSeconds(1))
39-
.get()
40-
.getState()
41-
.nodes()
42-
.getMasterNodeId()
43-
);
34+
assertNotNull(client().admin().cluster().prepareState(TimeValue.timeValueSeconds(1)).get().getState().nodes().getMasterNodeId());
4435

4536
logger.info("--> start another node");
4637
final String node2 = internalCluster().startNode(settings);
4738
registerAzureNode(node2);
48-
assertNotNull(
49-
client().admin()
50-
.cluster()
51-
.prepareState(TEST_REQUEST_TIMEOUT)
52-
.setMasterNodeTimeout(TimeValue.timeValueSeconds(1))
53-
.get()
54-
.getState()
55-
.nodes()
56-
.getMasterNodeId()
57-
);
39+
assertNotNull(client().admin().cluster().prepareState(TimeValue.timeValueSeconds(1)).get().getState().nodes().getMasterNodeId());
5840

5941
// We expect having 2 nodes as part of the cluster, let's test that
6042
assertNumberOfNodes(2);

plugins/discovery-gce/src/internalClusterTest/java/org/elasticsearch/discovery/gce/GceDiscoverTests.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ public void testJoin() {
6868

6969
ClusterStateResponse clusterStateResponse = client(masterNode).admin()
7070
.cluster()
71-
.prepareState(TEST_REQUEST_TIMEOUT)
72-
.setMasterNodeTimeout(TimeValue.timeValueSeconds(1))
71+
.prepareState(TimeValue.timeValueSeconds(1))
7372
.clear()
7473
.setNodes(true)
7574
.get();
@@ -80,11 +79,9 @@ public void testJoin() {
8079
registerGceNode(secondNode);
8180
clusterStateResponse = client(secondNode).admin()
8281
.cluster()
83-
.prepareState(TEST_REQUEST_TIMEOUT)
84-
.setMasterNodeTimeout(TimeValue.timeValueSeconds(1))
82+
.prepareState(TimeValue.timeValueSeconds(1))
8583
.clear()
8684
.setNodes(true)
87-
.setLocal(true)
8885
.get();
8986
assertNotNull(clusterStateResponse.getState().nodes().getMasterNodeId());
9087

rest-api-spec/src/main/resources/rest-api-spec/api/cluster.state.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@
6969
},
7070
"params":{
7171
"local":{
72+
"deprecated":true,
7273
"type":"boolean",
7374
"description":"Return local information, do not retrieve the state from master node (default: false)"
7475
},
7576
"master_timeout":{
7677
"type":"time",
77-
"description":"Specify timeout for connection to master"
78+
"description":"Timeout for waiting for new cluster state in case it is blocked"
7879
},
7980
"flat_settings":{
8081
"type":"boolean",

server/src/internalClusterTest/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateActionDisruptionIT.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,10 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
5050

5151
public void testNonLocalRequestAlwaysFindsMaster() throws Exception {
5252
runRepeatedlyWhileChangingMaster(() -> {
53-
final ClusterStateRequestBuilder clusterStateRequestBuilder = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT)
53+
final ClusterStateRequestBuilder clusterStateRequestBuilder = clusterAdmin().prepareState(TimeValue.timeValueMillis(100))
5454
.clear()
5555
.setNodes(true)
56-
.setBlocks(true)
57-
.setMasterNodeTimeout(TimeValue.timeValueMillis(100));
56+
.setBlocks(true);
5857
final ClusterStateResponse clusterStateResponse;
5958
try {
6059
clusterStateResponse = clusterStateRequestBuilder.get();
@@ -70,12 +69,10 @@ public void testLocalRequestAlwaysSucceeds() throws Exception {
7069
final String node = randomFrom(internalCluster().getNodeNames());
7170
final DiscoveryNodes discoveryNodes = client(node).admin()
7271
.cluster()
73-
.prepareState(TEST_REQUEST_TIMEOUT)
72+
.prepareState(TimeValue.timeValueMillis(100))
7473
.clear()
75-
.setLocal(true)
7674
.setNodes(true)
7775
.setBlocks(true)
78-
.setMasterNodeTimeout(TimeValue.timeValueMillis(100))
7976
.get()
8077
.getState()
8178
.nodes();
@@ -99,12 +96,11 @@ public void testNonLocalRequestAlwaysFindsMasterAndWaitsForMetadata() throws Exc
9996
final long waitForMetadataVersion = randomLongBetween(Math.max(1, metadataVersion - 3), metadataVersion + 5);
10097
final ClusterStateRequestBuilder clusterStateRequestBuilder = client(node).admin()
10198
.cluster()
102-
.prepareState(TEST_REQUEST_TIMEOUT)
99+
.prepareState(TimeValue.timeValueMillis(100))
103100
.clear()
104101
.setNodes(true)
105102
.setMetadata(true)
106103
.setBlocks(true)
107-
.setMasterNodeTimeout(TimeValue.timeValueMillis(100))
108104
.setWaitForTimeOut(TimeValue.timeValueMillis(100))
109105
.setWaitForMetadataVersion(waitForMetadataVersion);
110106
final ClusterStateResponse clusterStateResponse;
@@ -132,13 +128,11 @@ public void testLocalRequestWaitsForMetadata() throws Exception {
132128
final long waitForMetadataVersion = randomLongBetween(Math.max(1, metadataVersion - 3), metadataVersion + 5);
133129
final ClusterStateResponse clusterStateResponse = client(node).admin()
134130
.cluster()
135-
.prepareState(TEST_REQUEST_TIMEOUT)
131+
.prepareState(TimeValue.timeValueMillis(100))
136132
.clear()
137-
.setLocal(true)
138133
.setMetadata(true)
139134
.setBlocks(true)
140135
.setWaitForMetadataVersion(waitForMetadataVersion)
141-
.setMasterNodeTimeout(TimeValue.timeValueMillis(100))
142136
.setWaitForTimeOut(TimeValue.timeValueMillis(100))
143137
.get();
144138
if (clusterStateResponse.isWaitForTimedOut() == false) {

server/src/internalClusterTest/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void testTwoNodesNoMasterBlock() throws Exception {
6868
String node1Name = internalCluster().startNode(settings);
6969

7070
logger.info("--> should be blocked, no master...");
71-
ClusterState state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).setLocal(true).get().getState();
71+
ClusterState state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
7272
assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(true));
7373
assertThat(state.nodes().getSize(), equalTo(1)); // verify that we still see the local node in the cluster state
7474

@@ -81,9 +81,9 @@ public void testTwoNodesNoMasterBlock() throws Exception {
8181
.get();
8282
assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
8383

84-
state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).setLocal(true).get().getState();
84+
state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
8585
assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(false));
86-
state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).setLocal(true).get().getState();
86+
state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
8787
assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(false));
8888

8989
state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
@@ -124,11 +124,11 @@ public void testTwoNodesNoMasterBlock() throws Exception {
124124
internalCluster().stopNode(masterNode);
125125

126126
assertBusy(() -> {
127-
ClusterState clusterState = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).setLocal(true).get().getState();
127+
ClusterState clusterState = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
128128
assertTrue(clusterState.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID));
129129
});
130130

131-
state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).setLocal(true).get().getState();
131+
state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
132132
assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(true));
133133
// verify that both nodes are still in the cluster state but there is no master
134134
assertThat(state.nodes().getSize(), equalTo(2));
@@ -144,9 +144,9 @@ public void testTwoNodesNoMasterBlock() throws Exception {
144144
.get();
145145
assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
146146

147-
state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).setLocal(true).get().getState();
147+
state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
148148
assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(false));
149-
state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).setLocal(true).get().getState();
149+
state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
150150
assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(false));
151151

152152
state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
@@ -177,7 +177,7 @@ public void testTwoNodesNoMasterBlock() throws Exception {
177177
internalCluster().stopNode(otherNode);
178178

179179
assertBusy(() -> {
180-
ClusterState state1 = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).setLocal(true).get().getState();
180+
ClusterState state1 = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
181181
assertThat(state1.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(true));
182182
});
183183

@@ -192,9 +192,9 @@ public void testTwoNodesNoMasterBlock() throws Exception {
192192
.get();
193193
assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
194194

195-
state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).setLocal(true).get().getState();
195+
state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
196196
assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(false));
197-
state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).setLocal(true).get().getState();
197+
state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
198198
assertThat(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(false));
199199

200200
state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
@@ -222,7 +222,7 @@ public void testThreeNodesNoMasterBlock() throws Exception {
222222

223223
assertBusy(() -> {
224224
for (Client client : clients()) {
225-
ClusterState state1 = client.admin().cluster().prepareState(TEST_REQUEST_TIMEOUT).setLocal(true).get().getState();
225+
ClusterState state1 = client.admin().cluster().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
226226
assertThat(state1.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(true));
227227
}
228228
});
@@ -272,7 +272,7 @@ public void testThreeNodesNoMasterBlock() throws Exception {
272272
logger.info("--> verify that there is no master anymore on remaining node");
273273
// spin here to wait till the state is set
274274
assertBusy(() -> {
275-
ClusterState st = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).setLocal(true).get().getState();
275+
ClusterState st = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
276276
assertThat(st.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID), equalTo(true));
277277
});
278278

server/src/internalClusterTest/java/org/elasticsearch/cluster/NoMasterNodeIT.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,7 @@ public void testNoMasterActions() throws Exception {
8585
final Client clientToMasterlessNode = client();
8686

8787
assertBusy(() -> {
88-
ClusterState state = clientToMasterlessNode.admin()
89-
.cluster()
90-
.prepareState(TEST_REQUEST_TIMEOUT)
91-
.setLocal(true)
92-
.get()
93-
.getState();
88+
ClusterState state = clientToMasterlessNode.admin().cluster().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
9489
assertTrue(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID));
9590
});
9691

@@ -249,12 +244,7 @@ public void testNoMasterActionsWriteMasterBlock() throws Exception {
249244
final Client clientToMasterlessNode = client();
250245

251246
assertBusy(() -> {
252-
ClusterState state = clientToMasterlessNode.admin()
253-
.cluster()
254-
.prepareState(TEST_REQUEST_TIMEOUT)
255-
.setLocal(true)
256-
.get()
257-
.getState();
247+
ClusterState state = clientToMasterlessNode.admin().cluster().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
258248
assertTrue(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID));
259249
});
260250

@@ -348,7 +338,7 @@ public void testNoMasterActionsMetadataWriteMasterBlock() throws Exception {
348338

349339
assertBusy(() -> {
350340
for (String node : nodesWithShards) {
351-
ClusterState state = client(node).admin().cluster().prepareState(TEST_REQUEST_TIMEOUT).setLocal(true).get().getState();
341+
ClusterState state = client(node).admin().cluster().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
352342
assertTrue(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID));
353343
}
354344
});

server/src/internalClusterTest/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,7 @@ public void testSimpleOnlyMasterNodeElection() throws IOException {
3737
logger.info("--> start data node / non master node");
3838
internalCluster().startNode(Settings.builder().put(dataOnlyNode()).put("discovery.initial_state_timeout", "1s"));
3939
try {
40-
assertThat(
41-
clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT)
42-
.setMasterNodeTimeout(TimeValue.timeValueMillis(100))
43-
.get()
44-
.getState()
45-
.nodes()
46-
.getMasterNodeId(),
47-
nullValue()
48-
);
40+
assertThat(clusterAdmin().prepareState(TimeValue.timeValueMillis(100)).get().getState().nodes().getMasterNodeId(), nullValue());
4941
fail("should not be able to find master");
5042
} catch (MasterNotDiscoveredException e) {
5143
// all is well, no master elected
@@ -82,15 +74,7 @@ public void testSimpleOnlyMasterNodeElection() throws IOException {
8274
internalCluster().stopCurrentMasterNode();
8375

8476
try {
85-
assertThat(
86-
clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT)
87-
.setMasterNodeTimeout(TimeValue.timeValueMillis(100))
88-
.get()
89-
.getState()
90-
.nodes()
91-
.getMasterNodeId(),
92-
nullValue()
93-
);
77+
assertThat(clusterAdmin().prepareState(TimeValue.timeValueMillis(100)).get().getState().nodes().getMasterNodeId(), nullValue());
9478
fail("should not be able to find master");
9579
} catch (MasterNotDiscoveredException e) {
9680
// all is well, no master elected
@@ -131,15 +115,7 @@ public void testElectOnlyBetweenMasterNodes() throws Exception {
131115
logger.info("--> start data node / non master node");
132116
internalCluster().startNode(Settings.builder().put(dataOnlyNode()).put("discovery.initial_state_timeout", "1s"));
133117
try {
134-
assertThat(
135-
clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT)
136-
.setMasterNodeTimeout(TimeValue.timeValueMillis(100))
137-
.get()
138-
.getState()
139-
.nodes()
140-
.getMasterNodeId(),
141-
nullValue()
142-
);
118+
assertThat(clusterAdmin().prepareState(TimeValue.timeValueMillis(100)).get().getState().nodes().getMasterNodeId(), nullValue());
143119
fail("should not be able to find master");
144120
} catch (MasterNotDiscoveredException e) {
145121
// all is well, no master elected

server/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/InitialClusterStateIT.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,7 @@ protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
3434

3535
private static void assertClusterUuid(boolean expectCommitted, String expectedValue) {
3636
for (String nodeName : internalCluster().getNodeNames()) {
37-
final Metadata metadata = client(nodeName).admin()
38-
.cluster()
39-
.prepareState(TEST_REQUEST_TIMEOUT)
40-
.setLocal(true)
41-
.get()
42-
.getState()
43-
.metadata();
37+
final Metadata metadata = client(nodeName).admin().cluster().prepareState(TEST_REQUEST_TIMEOUT).get().getState().metadata();
4438
assertEquals(expectCommitted, metadata.clusterUUIDCommitted());
4539
assertEquals(expectedValue, metadata.clusterUUID());
4640

0 commit comments

Comments
 (0)