Skip to content

Commit a16f97f

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

File tree

34 files changed

+107
-241
lines changed

34 files changed

+107
-241
lines changed

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
@@ -67,8 +67,7 @@ public void testJoin() {
6767

6868
ClusterStateResponse clusterStateResponse = client(masterNode).admin()
6969
.cluster()
70-
.prepareState(TEST_REQUEST_TIMEOUT)
71-
.setMasterNodeTimeout(TimeValue.timeValueSeconds(1))
70+
.prepareState(TimeValue.timeValueSeconds(1))
7271
.clear()
7372
.setNodes(true)
7473
.get();
@@ -79,11 +78,9 @@ public void testJoin() {
7978
registerGceNode(secondNode);
8079
clusterStateResponse = client(secondNode).admin()
8180
.cluster()
82-
.prepareState(TEST_REQUEST_TIMEOUT)
83-
.setMasterNodeTimeout(TimeValue.timeValueSeconds(1))
81+
.prepareState(TimeValue.timeValueSeconds(1))
8482
.clear()
8583
.setNodes(true)
86-
.setLocal(true)
8784
.get();
8885
assertNotNull(clusterStateResponse.getState().nodes().getMasterNodeId());
8986

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: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
package org.elasticsearch.action.admin.cluster.state;
1010

1111
import org.elasticsearch.action.support.SubscribableListener;
12-
import org.elasticsearch.cluster.ClusterState;
1312
import org.elasticsearch.cluster.block.ClusterBlockException;
1413
import org.elasticsearch.cluster.coordination.ClusterBootstrapService;
1514
import org.elasticsearch.cluster.metadata.Metadata;
@@ -18,7 +17,6 @@
1817
import org.elasticsearch.cluster.service.ClusterService;
1918
import org.elasticsearch.common.settings.Settings;
2019
import org.elasticsearch.core.TimeValue;
21-
import org.elasticsearch.discovery.MasterNotDiscoveredException;
2220
import org.elasticsearch.gateway.GatewayService;
2321
import org.elasticsearch.plugins.Plugin;
2422
import org.elasticsearch.test.ESIntegTestCase;
@@ -47,34 +45,15 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
4745
return Collections.singletonList(MockTransportService.TestPlugin.class);
4846
}
4947

50-
public void testNonLocalRequestAlwaysFindsMaster() throws Exception {
51-
runRepeatedlyWhileChangingMaster(() -> {
52-
final ClusterStateRequestBuilder clusterStateRequestBuilder = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT)
53-
.clear()
54-
.setNodes(true)
55-
.setBlocks(true)
56-
.setMasterNodeTimeout(TimeValue.timeValueMillis(100));
57-
final ClusterStateResponse clusterStateResponse;
58-
try {
59-
clusterStateResponse = clusterStateRequestBuilder.get();
60-
} catch (MasterNotDiscoveredException e) {
61-
return; // ok, we hit the disconnected node
62-
}
63-
assertNotNull("should always contain a master node", clusterStateResponse.getState().nodes().getMasterNodeId());
64-
});
65-
}
66-
6748
public void testLocalRequestAlwaysSucceeds() throws Exception {
6849
runRepeatedlyWhileChangingMaster(() -> {
6950
final String node = randomFrom(internalCluster().getNodeNames());
7051
final DiscoveryNodes discoveryNodes = client(node).admin()
7152
.cluster()
72-
.prepareState(TEST_REQUEST_TIMEOUT)
53+
.prepareState(TimeValue.timeValueMillis(100))
7354
.clear()
74-
.setLocal(true)
7555
.setNodes(true)
7656
.setBlocks(true)
77-
.setMasterNodeTimeout(TimeValue.timeValueMillis(100))
7857
.get()
7958
.getState()
8059
.nodes();
@@ -87,39 +66,6 @@ public void testLocalRequestAlwaysSucceeds() throws Exception {
8766
});
8867
}
8968

90-
public void testNonLocalRequestAlwaysFindsMasterAndWaitsForMetadata() throws Exception {
91-
runRepeatedlyWhileChangingMaster(() -> {
92-
final String node = randomFrom(internalCluster().getNodeNames());
93-
final long metadataVersion = internalCluster().getInstance(ClusterService.class, node)
94-
.getClusterApplierService()
95-
.state()
96-
.metadata()
97-
.version();
98-
final long waitForMetadataVersion = randomLongBetween(Math.max(1, metadataVersion - 3), metadataVersion + 5);
99-
final ClusterStateRequestBuilder clusterStateRequestBuilder = client(node).admin()
100-
.cluster()
101-
.prepareState(TEST_REQUEST_TIMEOUT)
102-
.clear()
103-
.setNodes(true)
104-
.setMetadata(true)
105-
.setBlocks(true)
106-
.setMasterNodeTimeout(TimeValue.timeValueMillis(100))
107-
.setWaitForTimeOut(TimeValue.timeValueMillis(100))
108-
.setWaitForMetadataVersion(waitForMetadataVersion);
109-
final ClusterStateResponse clusterStateResponse;
110-
try {
111-
clusterStateResponse = clusterStateRequestBuilder.get();
112-
} catch (MasterNotDiscoveredException e) {
113-
return; // ok, we hit the disconnected node
114-
}
115-
if (clusterStateResponse.isWaitForTimedOut() == false) {
116-
final ClusterState state = clusterStateResponse.getState();
117-
assertNotNull("should always contain a master node", state.nodes().getMasterNodeId());
118-
assertThat("waited for metadata version", state.metadata().version(), greaterThanOrEqualTo(waitForMetadataVersion));
119-
}
120-
});
121-
}
122-
12369
public void testLocalRequestWaitsForMetadata() throws Exception {
12470
runRepeatedlyWhileChangingMaster(() -> {
12571
final String node = randomFrom(internalCluster().getNodeNames());
@@ -131,13 +77,11 @@ public void testLocalRequestWaitsForMetadata() throws Exception {
13177
final long waitForMetadataVersion = randomLongBetween(Math.max(1, metadataVersion - 3), metadataVersion + 5);
13278
final ClusterStateResponse clusterStateResponse = client(node).admin()
13379
.cluster()
134-
.prepareState(TEST_REQUEST_TIMEOUT)
80+
.prepareState(TimeValue.timeValueMillis(100))
13581
.clear()
136-
.setLocal(true)
13782
.setMetadata(true)
13883
.setBlocks(true)
13984
.setWaitForMetadataVersion(waitForMetadataVersion)
140-
.setMasterNodeTimeout(TimeValue.timeValueMillis(100))
14185
.setWaitForTimeOut(TimeValue.timeValueMillis(100))
14286
.get();
14387
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/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

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

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public void testBootstrapNotBootstrappedCluster() throws Exception {
138138
.build()
139139
);
140140
assertBusy(() -> {
141-
ClusterState state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).setLocal(true).get().getState();
141+
ClusterState state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
142142
assertTrue(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID));
143143
});
144144

@@ -243,13 +243,7 @@ public void test3MasterNodes2Failed() throws Exception {
243243

244244
logger.info("--> ensure NO_MASTER_BLOCK on data-only node");
245245
assertBusy(() -> {
246-
ClusterState state = internalCluster().client(dataNode)
247-
.admin()
248-
.cluster()
249-
.prepareState(TEST_REQUEST_TIMEOUT)
250-
.setLocal(true)
251-
.get()
252-
.getState();
246+
ClusterState state = internalCluster().client(dataNode).admin().cluster().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
253247
assertTrue(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID));
254248
});
255249

@@ -295,13 +289,7 @@ public void test3MasterNodes2Failed() throws Exception {
295289

296290
logger.info("--> ensure there is no NO_MASTER_BLOCK and unsafe-bootstrap is reflected in cluster state");
297291
assertBusy(() -> {
298-
ClusterState state = internalCluster().client(dataNode2)
299-
.admin()
300-
.cluster()
301-
.prepareState(TEST_REQUEST_TIMEOUT)
302-
.setLocal(true)
303-
.get()
304-
.getState();
292+
ClusterState state = internalCluster().client(dataNode2).admin().cluster().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
305293
assertFalse(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID));
306294
assertTrue(state.metadata().persistentSettings().getAsBoolean(UnsafeBootstrapMasterCommand.UNSAFE_BOOTSTRAP.getKey(), false));
307295
});
@@ -346,13 +334,7 @@ public void testNoInitialBootstrapAfterDetach() throws Exception {
346334
.build()
347335
);
348336

349-
ClusterState state = internalCluster().client()
350-
.admin()
351-
.cluster()
352-
.prepareState(TEST_REQUEST_TIMEOUT)
353-
.setLocal(true)
354-
.get()
355-
.getState();
337+
ClusterState state = internalCluster().client().admin().cluster().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
356338
assertTrue(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID));
357339

358340
internalCluster().stopNode(node);

server/src/internalClusterTest/java/org/elasticsearch/cluster/routing/allocation/ShardStateIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void testPrimaryFailureIncreasesTerm() throws Exception {
6666
protected void assertPrimaryTerms(long shard0Term, long shard1Term) {
6767
for (String node : internalCluster().getNodeNames()) {
6868
logger.debug("--> asserting primary terms terms on [{}]", node);
69-
ClusterState state = client(node).admin().cluster().prepareState(TEST_REQUEST_TIMEOUT).setLocal(true).get().getState();
69+
ClusterState state = client(node).admin().cluster().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
7070
IndexMetadata metadata = state.metadata().getProject().index("test");
7171
assertThat(metadata.primaryTerm(0), equalTo(shard0Term));
7272
assertThat(metadata.primaryTerm(1), equalTo(shard1Term));

server/src/internalClusterTest/java/org/elasticsearch/discovery/StableMasterDisruptionIT.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,7 @@ private String xContentToString(ChunkedToXContent xContent) throws IOException {
147147
private void ensureNoMaster(String node) throws Exception {
148148
assertBusy(
149149
() -> assertNull(
150-
client(node).admin()
151-
.cluster()
152-
.state(new ClusterStateRequest(TEST_REQUEST_TIMEOUT).local(true))
153-
.get()
154-
.getState()
155-
.nodes()
156-
.getMasterNode()
150+
client(node).admin().cluster().state(new ClusterStateRequest(TEST_REQUEST_TIMEOUT)).get().getState().nodes().getMasterNode()
157151
)
158152
);
159153
}

0 commit comments

Comments
 (0)