Skip to content

Commit

Permalink
Rename ClusterBlocks.hasGlobalBlock methods (#36941)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
tlrx committed Jan 7, 2019
1 parent e4030b8 commit 57c473c
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public TransportMainAction(Settings settings, ThreadPool threadPool, TransportSe
@Override
protected void doExecute(MainRequest request, ActionListener<MainResponse> listener) {
ClusterState clusterState = clusterService.state();
final boolean available = clusterState.getBlocks().hasGlobalBlock(RestStatus.SERVICE_UNAVAILABLE) == false;
final boolean available = clusterState.getBlocks().hasGlobalBlockWithStatus(RestStatus.SERVICE_UNAVAILABLE) == false;
listener.onResponse(
new MainResponse(nodeName, Version.CURRENT, clusterState.getClusterName(),
clusterState.metaData().clusterUUID(), Build.CURRENT, available));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.elasticsearch.cluster.block;

import com.carrotsearch.hppc.cursors.ObjectObjectCursor;

import org.elasticsearch.cluster.AbstractDiffable;
import org.elasticsearch.cluster.Diff;
import org.elasticsearch.cluster.metadata.IndexMetaData;
Expand Down Expand Up @@ -119,7 +118,7 @@ public boolean hasGlobalBlock(ClusterBlock block) {
return global.contains(block);
}

public boolean hasGlobalBlock(int blockId) {
public boolean hasGlobalBlockWithId(final int blockId) {
for (ClusterBlock clusterBlock : global) {
if (clusterBlock.id() == blockId) {
return true;
Expand All @@ -128,14 +127,14 @@ public boolean hasGlobalBlock(int blockId) {
return false;
}

public boolean hasGlobalBlock(ClusterBlockLevel level) {
public boolean hasGlobalBlockWithLevel(ClusterBlockLevel level) {
return global(level).size() > 0;
}

/**
* Is there a global block with the provided status?
*/
public boolean hasGlobalBlock(RestStatus status) {
public boolean hasGlobalBlockWithStatus(final RestStatus status) {
for (ClusterBlock clusterBlock : global) {
if (clusterBlock.status().equals(status)) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public ClusterStateHealth(final ClusterState clusterState, final String[] concre
}
}

if (clusterState.blocks().hasGlobalBlock(RestStatus.SERVICE_UNAVAILABLE)) {
if (clusterState.blocks().hasGlobalBlockWithStatus(RestStatus.SERVICE_UNAVAILABLE)) {
computeStatus = ClusterHealthStatus.RED;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ protected void rejoin(String reason) {

if (clusterState.nodes().getMasterNodeId() != null) {
// remove block if it already exists before adding new one
assert clusterState.blocks().hasGlobalBlock(discoverySettings.getNoMasterBlock().id()) == false :
assert clusterState.blocks().hasGlobalBlockWithId(discoverySettings.getNoMasterBlock().id()) == false :
"NO_MASTER_BLOCK should only be added by ZenDiscovery";
ClusterBlocks clusterBlocks = ClusterBlocks.builder().blocks(clusterState.blocks())
.addGlobalBlock(discoverySettings.getNoMasterBlock())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void testSimpleMinimumMasterNodes() throws Exception {

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

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

state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
assertThat(state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));
assertThat(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));
state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
assertThat(state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));
assertThat(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));

state = client().admin().cluster().prepareState().execute().actionGet().getState();
assertThat(state.nodes().getSize(), equalTo(2));
Expand All @@ -130,10 +130,10 @@ public void testSimpleMinimumMasterNodes() throws Exception {
internalCluster().stopCurrentMasterNode();
awaitBusy(() -> {
ClusterState clusterState = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
return clusterState.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID);
return clusterState.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID);
});
state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
assertThat(state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(true));
assertThat(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(true));
// verify that both nodes are still in the cluster state but there is no master
assertThat(state.nodes().getSize(), equalTo(2));
assertThat(state.nodes().getMasterNode(), equalTo(null));
Expand All @@ -146,9 +146,9 @@ public void testSimpleMinimumMasterNodes() throws Exception {
assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));

state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
assertThat(state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));
assertThat(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));
state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
assertThat(state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));
assertThat(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));

state = client().admin().cluster().prepareState().execute().actionGet().getState();
assertThat(state.nodes().getSize(), equalTo(2));
Expand All @@ -164,7 +164,7 @@ public void testSimpleMinimumMasterNodes() throws Exception {
internalCluster().stopRandomNonMasterNode();
assertBusy(() -> {
ClusterState state1 = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
assertThat(state1.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(true));
assertThat(state1.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(true));
});

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

state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
assertThat(state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));
assertThat(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));
state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
assertThat(state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));
assertThat(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));

state = client().admin().cluster().prepareState().execute().actionGet().getState();
assertThat(state.nodes().getSize(), equalTo(2));
Expand Down Expand Up @@ -208,7 +208,7 @@ public void testMultipleNodesShutdownNonMasterNodes() throws Exception {
assertBusy(() -> {
for (Client client : clients()) {
ClusterState state1 = client.admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
assertThat(state1.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(true));
assertThat(state1.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(true));
}
});

Expand Down Expand Up @@ -302,7 +302,7 @@ public void testDynamicUpdateMinimumMasterNodes() throws Exception {
private void assertNoMasterBlockOnAllNodes() throws InterruptedException {
Predicate<Client> hasNoMasterBlock = client -> {
ClusterState state = client.admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
return state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID);
return state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID);
};
assertTrue(awaitBusy(
() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void testNoMasterActions() throws Exception {
internalCluster().stopRandomDataNode();
assertBusy(() -> {
ClusterState state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
assertTrue(state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID));
assertTrue(state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID));
});

assertThrows(client().prepareGet("test", "type1", "1"),
Expand Down Expand Up @@ -197,7 +197,7 @@ public void testNoMasterActionsWriteMasterBlock() throws Exception {
internalCluster().stopRandomDataNode();
assertTrue(awaitBusy(() -> {
ClusterState state = client().admin().cluster().prepareState().setLocal(true).get().getState();
return state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID);
return state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID);
}
));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ void assertNoMaster(final String node, @Nullable final ClusterBlock expectedBloc
assertNull("node [" + node + "] still has [" + nodes.getMasterNode() + "] as master", nodes.getMasterNode());
if (expectedBlocks != null) {
for (ClusterBlockLevel level : expectedBlocks.levels()) {
assertTrue("node [" + node + "] does have level [" + level + "] in it's blocks", state.getBlocks().hasGlobalBlock
(level));
assertTrue("node [" + node + "] does have level [" + level + "] in it's blocks",
state.getBlocks().hasGlobalBlockWithLevel(level));
}
}
}, maxWaitTime.getMillis(), TimeUnit.MILLISECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,19 +292,19 @@ public ClusterState randomlyUpdateClusterState(ClusterState state,
Map<DiscoveryNode, IndicesClusterStateService> clusterStateServiceMap,
Supplier<MockIndicesService> indicesServiceSupplier) {
// randomly remove no_master blocks
if (randomBoolean() && state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID)) {
if (randomBoolean() && state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID)) {
state = ClusterState.builder(state).blocks(
ClusterBlocks.builder().blocks(state.blocks()).removeGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID)).build();
}

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

// if no_master block is in place, make no other cluster state changes
if (state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID)) {
if (state.blocks().hasGlobalBlockWithId(DiscoverySettings.NO_MASTER_BLOCK_ID)) {
return state;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private boolean setupIfElectedMaster(final ClusterState clusterState, final Map<
final boolean clusterStateChange) {
// we are on the elected master
// Check that there is nothing that could block metadata updates
if (clusterState.blocks().hasGlobalBlock(ClusterBlockLevel.METADATA_WRITE)) {
if (clusterState.blocks().hasGlobalBlockWithLevel(ClusterBlockLevel.METADATA_WRITE)) {
logger.debug("waiting until metadata writes are unblocked");
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void clusterChanged(ClusterChangedEvent event) {
// if there is no master node configured in the current state, this node should not try to trigger anything, but consider itself
// inactive. the same applies, if there is a cluster block that does not allow writes
if (Strings.isNullOrEmpty(event.state().nodes().getMasterNodeId()) ||
event.state().getBlocks().hasGlobalBlock(ClusterBlockLevel.WRITE)) {
event.state().getBlocks().hasGlobalBlockWithLevel(ClusterBlockLevel.WRITE)) {
configuration = INACTIVE;
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void clusterChanged(ClusterChangedEvent event) {
return;
}

if (event.state().getBlocks().hasGlobalBlock(ClusterBlockLevel.WRITE)) {
if (event.state().getBlocks().hasGlobalBlockWithLevel(ClusterBlockLevel.WRITE)) {
pauseExecution("write level cluster block");
return;
}
Expand Down

0 comments on commit 57c473c

Please sign in to comment.