Skip to content

Commit 6347461

Browse files
authored
Rename ClusterBlocks.hasGlobalBlock methods (#36941)
As suggested in #36775, this pull request renames the following methods: ClusterBlocks.hasGlobalBlock(int) ClusterBlocks.hasGlobalBlock(RestStatus) ClusterBlocks.hasGlobalBlock(ClusterBlockLevel) to something that better reflects the property of the ClusterBlock that is searched for: ClusterBlocks.hasGlobalBlockWithId(int) ClusterBlocks.hasGlobalBlockWithStatus(RestStatus) ClusterBlocks.hasGlobalBlockWithLevel(ClusterBlockLevel)
1 parent 31c33fd commit 6347461

File tree

12 files changed

+31
-32
lines changed

12 files changed

+31
-32
lines changed

server/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.elasticsearch.cluster.block;
2121

2222
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
23-
2423
import org.elasticsearch.cluster.AbstractDiffable;
2524
import org.elasticsearch.cluster.Diff;
2625
import org.elasticsearch.cluster.metadata.IndexMetaData;
@@ -119,7 +118,7 @@ public boolean hasGlobalBlock(ClusterBlock block) {
119118
return global.contains(block);
120119
}
121120

122-
public boolean hasGlobalBlock(int blockId) {
121+
public boolean hasGlobalBlockWithId(final int blockId) {
123122
for (ClusterBlock clusterBlock : global) {
124123
if (clusterBlock.id() == blockId) {
125124
return true;
@@ -128,14 +127,14 @@ public boolean hasGlobalBlock(int blockId) {
128127
return false;
129128
}
130129

131-
public boolean hasGlobalBlock(ClusterBlockLevel level) {
130+
public boolean hasGlobalBlockWithLevel(ClusterBlockLevel level) {
132131
return global(level).size() > 0;
133132
}
134133

135134
/**
136135
* Is there a global block with the provided status?
137136
*/
138-
public boolean hasGlobalBlock(RestStatus status) {
137+
public boolean hasGlobalBlockWithStatus(final RestStatus status) {
139138
for (ClusterBlock clusterBlock : global) {
140139
if (clusterBlock.status().equals(status)) {
141140
return true;

server/src/main/java/org/elasticsearch/cluster/coordination/Coordinator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ public void invariant() {
575575
assert peerFinder.getCurrentTerm() == getCurrentTerm();
576576
assert followersChecker.getFastResponseState().term == getCurrentTerm() : followersChecker.getFastResponseState();
577577
assert followersChecker.getFastResponseState().mode == getMode() : followersChecker.getFastResponseState();
578-
assert (applierState.nodes().getMasterNodeId() == null) == applierState.blocks().hasGlobalBlock(NO_MASTER_BLOCK_ID);
578+
assert (applierState.nodes().getMasterNodeId() == null) == applierState.blocks().hasGlobalBlockWithId(NO_MASTER_BLOCK_ID);
579579
assert preVoteCollector.getPreVoteResponse().equals(getPreVoteResponse())
580580
: preVoteCollector + " vs " + getPreVoteResponse();
581581

@@ -839,7 +839,7 @@ ClusterState getStateForMasterService() {
839839
private ClusterState clusterStateWithNoMasterBlock(ClusterState clusterState) {
840840
if (clusterState.nodes().getMasterNodeId() != null) {
841841
// remove block if it already exists before adding new one
842-
assert clusterState.blocks().hasGlobalBlock(NO_MASTER_BLOCK_ID) == false :
842+
assert clusterState.blocks().hasGlobalBlockWithId(NO_MASTER_BLOCK_ID) == false :
843843
"NO_MASTER_BLOCK should only be added by Coordinator";
844844
final ClusterBlocks clusterBlocks = ClusterBlocks.builder().blocks(clusterState.blocks()).addGlobalBlock(
845845
discoverySettings.getNoMasterBlock()).build();

server/src/main/java/org/elasticsearch/cluster/health/ClusterStateHealth.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public ClusterStateHealth(final ClusterState clusterState, final String[] concre
100100
}
101101
}
102102

103-
if (clusterState.blocks().hasGlobalBlock(RestStatus.SERVICE_UNAVAILABLE)) {
103+
if (clusterState.blocks().hasGlobalBlockWithStatus(RestStatus.SERVICE_UNAVAILABLE)) {
104104
computeStatus = ClusterHealthStatus.RED;
105105
}
106106

server/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ protected void rejoin(String reason) {
910910

911911
if (clusterState.nodes().getMasterNodeId() != null) {
912912
// remove block if it already exists before adding new one
913-
assert clusterState.blocks().hasGlobalBlock(discoverySettings.getNoMasterBlock().id()) == false :
913+
assert clusterState.blocks().hasGlobalBlockWithId(discoverySettings.getNoMasterBlock().id()) == false :
914914
"NO_MASTER_BLOCK should only be added by ZenDiscovery";
915915
ClusterBlocks clusterBlocks = ClusterBlocks.builder().blocks(clusterState.blocks())
916916
.addGlobalBlock(discoverySettings.getNoMasterBlock())

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void testSimpleMinimumMasterNodes() throws Exception {
9191

9292
logger.info("--> should be blocked, no master...");
9393
ClusterState state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
94-
assertThat(state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(true));
94+
assertThat(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(true));
9595
assertThat(state.nodes().getSize(), equalTo(1)); // verify that we still see the local node in the cluster state
9696

9797
logger.info("--> start second node, cluster should be formed");
@@ -102,9 +102,9 @@ public void testSimpleMinimumMasterNodes() throws Exception {
102102
assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
103103

104104
state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
105-
assertThat(state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));
105+
assertThat(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));
106106
state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
107-
assertThat(state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));
107+
assertThat(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));
108108

109109
state = client().admin().cluster().prepareState().execute().actionGet().getState();
110110
assertThat(state.nodes().getSize(), equalTo(2));
@@ -131,10 +131,10 @@ public void testSimpleMinimumMasterNodes() throws Exception {
131131
internalCluster().stopCurrentMasterNode();
132132
awaitBusy(() -> {
133133
ClusterState clusterState = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
134-
return clusterState.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID);
134+
return clusterState.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID);
135135
});
136136
state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
137-
assertThat(state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(true));
137+
assertThat(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(true));
138138
// verify that both nodes are still in the cluster state but there is no master
139139
assertThat(state.nodes().getSize(), equalTo(2));
140140
assertThat(state.nodes().getMasterNode(), equalTo(null));
@@ -147,9 +147,9 @@ public void testSimpleMinimumMasterNodes() throws Exception {
147147
assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
148148

149149
state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
150-
assertThat(state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));
150+
assertThat(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));
151151
state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
152-
assertThat(state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));
152+
assertThat(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));
153153

154154
state = client().admin().cluster().prepareState().execute().actionGet().getState();
155155
assertThat(state.nodes().getSize(), equalTo(2));
@@ -165,7 +165,7 @@ public void testSimpleMinimumMasterNodes() throws Exception {
165165
internalCluster().stopRandomNonMasterNode();
166166
assertBusy(() -> {
167167
ClusterState state1 = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
168-
assertThat(state1.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(true));
168+
assertThat(state1.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(true));
169169
});
170170

171171
logger.info("--> starting the previous master node again...");
@@ -177,9 +177,9 @@ public void testSimpleMinimumMasterNodes() throws Exception {
177177
assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
178178

179179
state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
180-
assertThat(state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));
180+
assertThat(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));
181181
state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
182-
assertThat(state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));
182+
assertThat(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));
183183

184184
state = client().admin().cluster().prepareState().execute().actionGet().getState();
185185
assertThat(state.nodes().getSize(), equalTo(2));
@@ -209,7 +209,7 @@ public void testMultipleNodesShutdownNonMasterNodes() throws Exception {
209209
assertBusy(() -> {
210210
for (Client client : clients()) {
211211
ClusterState state1 = client.admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
212-
assertThat(state1.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(true));
212+
assertThat(state1.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(true));
213213
}
214214
});
215215

@@ -303,7 +303,7 @@ public void testDynamicUpdateMinimumMasterNodes() throws Exception {
303303
private void assertNoMasterBlockOnAllNodes() throws InterruptedException {
304304
Predicate<Client> hasNoMasterBlock = client -> {
305305
ClusterState state = client.admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
306-
return state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID);
306+
return state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID);
307307
};
308308
assertTrue(awaitBusy(
309309
() -> {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public Settings onNodeStopped(String nodeName) throws Exception {
8686

8787
assertBusy(() -> {
8888
ClusterState state = remainingClient.admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
89-
assertTrue(state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID));
89+
assertTrue(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID));
9090
});
9191

9292
assertThrows(remainingClient.prepareGet("test", "type1", "1"),
@@ -223,7 +223,7 @@ public Settings onNodeStopped(String nodeName) throws Exception {
223223

224224
assertTrue(awaitBusy(() -> {
225225
ClusterState state = remainingClient.admin().cluster().prepareState().setLocal(true).get().getState();
226-
return state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID);
226+
return state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID);
227227
}
228228
));
229229

server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,12 +1246,12 @@ void stabilise(long stabilisationDurationMillis) {
12461246
assertThat(nodeId + " has correct master", clusterNode.getLastAppliedClusterState().nodes().getMasterNode(),
12471247
equalTo(leader.getLocalNode()));
12481248
assertThat(nodeId + " has no NO_MASTER_BLOCK",
1249-
clusterNode.getLastAppliedClusterState().blocks().hasGlobalBlock(NO_MASTER_BLOCK_ID), equalTo(false));
1249+
clusterNode.getLastAppliedClusterState().blocks().hasGlobalBlockWithId(NO_MASTER_BLOCK_ID), equalTo(false));
12501250
} else {
12511251
assertThat(nodeId + " is not following " + leaderId, clusterNode.coordinator.getMode(), is(CANDIDATE));
12521252
assertThat(nodeId + " has no master", clusterNode.getLastAppliedClusterState().nodes().getMasterNode(), nullValue());
12531253
assertThat(nodeId + " has NO_MASTER_BLOCK",
1254-
clusterNode.getLastAppliedClusterState().blocks().hasGlobalBlock(NO_MASTER_BLOCK_ID), equalTo(true));
1254+
clusterNode.getLastAppliedClusterState().blocks().hasGlobalBlockWithId(NO_MASTER_BLOCK_ID), equalTo(true));
12551255
assertFalse(nodeId + " is not in the applied state on " + leaderId,
12561256
leader.getLastAppliedClusterState().getNodes().nodeExists(nodeId));
12571257
}

server/src/test/java/org/elasticsearch/discovery/AbstractDisruptionTestCase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ void assertNoMaster(final String node, @Nullable final ClusterBlock expectedBloc
172172
assertNull("node [" + node + "] still has [" + nodes.getMasterNode() + "] as master", nodes.getMasterNode());
173173
if (expectedBlocks != null) {
174174
for (ClusterBlockLevel level : expectedBlocks.levels()) {
175-
assertTrue("node [" + node + "] does have level [" + level + "] in it's blocks", state.getBlocks().hasGlobalBlock
176-
(level));
175+
assertTrue("node [" + node + "] does have level [" + level + "] in it's blocks",
176+
state.getBlocks().hasGlobalBlockWithLevel(level));
177177
}
178178
}
179179
}, maxWaitTime.getMillis(), TimeUnit.MILLISECONDS);

server/src/test/java/org/elasticsearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,19 +292,19 @@ public ClusterState randomlyUpdateClusterState(ClusterState state,
292292
Map<DiscoveryNode, IndicesClusterStateService> clusterStateServiceMap,
293293
Supplier<MockIndicesService> indicesServiceSupplier) {
294294
// randomly remove no_master blocks
295-
if (randomBoolean() && state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID)) {
295+
if (randomBoolean() && state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID)) {
296296
state = ClusterState.builder(state).blocks(
297297
ClusterBlocks.builder().blocks(state.blocks()).removeGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID)).build();
298298
}
299299

300300
// randomly add no_master blocks
301-
if (rarely() && state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID) == false) {
301+
if (rarely() && state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID) == false) {
302302
ClusterBlock block = randomBoolean() ? DiscoverySettings.NO_MASTER_BLOCK_ALL : DiscoverySettings.NO_MASTER_BLOCK_WRITES;
303303
state = ClusterState.builder(state).blocks(ClusterBlocks.builder().blocks(state.blocks()).addGlobalBlock(block)).build();
304304
}
305305

306306
// if no_master block is in place, make no other cluster state changes
307-
if (state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID)) {
307+
if (state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID)) {
308308
return state;
309309
}
310310

x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ private boolean setupIfElectedMaster(final ClusterState clusterState, final Map<
251251
final boolean clusterStateChange) {
252252
// we are on the elected master
253253
// Check that there is nothing that could block metadata updates
254-
if (clusterState.blocks().hasGlobalBlock(ClusterBlockLevel.METADATA_WRITE)) {
254+
if (clusterState.blocks().hasGlobalBlockWithLevel(ClusterBlockLevel.METADATA_WRITE)) {
255255
logger.debug("waiting until metadata writes are unblocked");
256256
return false;
257257
}

0 commit comments

Comments
 (0)