Remove DiscoveryNodes#size in favour of existing DiscoveryNodes#getSize

This commit is contained in:
javanna 2016-03-30 15:08:34 +02:00 committed by Luca Cavanna
parent 131f5b0596
commit fc2e6d7ce0
14 changed files with 24 additions and 33 deletions

View File

@ -75,7 +75,7 @@ public class TransportClearScrollAction extends HandledTransportAction<ClearScro
int expectedOps = 0;
this.nodes = clusterState.nodes();
if (request.getScrollIds().size() == 1 && "_all".equals(request.getScrollIds().get(0))) {
expectedOps = nodes.size();
expectedOps = nodes.getSize();
} else {
for (String parsedScrollId : request.getScrollIds()) {
ScrollIdForNode[] context = parseScrollId(parsedScrollId).getContext();

View File

@ -91,7 +91,7 @@ public final class ClusterStateHealth implements Iterable<ClusterIndexHealth>, S
public ClusterStateHealth(ClusterState clusterState, String[] concreteIndices) {
RoutingTableValidation validation = clusterState.routingTable().validate(clusterState.metaData());
validationFailures = validation.failures();
numberOfNodes = clusterState.nodes().size();
numberOfNodes = clusterState.nodes().getSize();
numberOfDataNodes = clusterState.nodes().dataNodes().size();
for (String index : concreteIndices) {

View File

@ -101,7 +101,7 @@ public class MetaDataDeleteIndexService extends AbstractComponent {
metaDataBuilder.remove(indexName);
}
// wait for events from all nodes that it has been removed from their respective metadata...
int count = currentState.nodes().size();
int count = currentState.nodes().getSize();
// add the notifications that the store was deleted from *data* nodes
count += currentState.nodes().dataNodes().size();
final AtomicInteger counter = new AtomicInteger(count * indices.size());

View File

@ -96,22 +96,13 @@ public class DiscoveryNodes extends AbstractDiffable<DiscoveryNodes> implements
return localNodeId.equals(masterNodeId);
}
/**
* Get the number of known nodes
*
* @return number of nodes
*/
public int size() {
return nodes.size();
}
/**
* Get the number of known nodes
*
* @return number of nodes
*/
public int getSize() {
return size();
return nodes.size();
}
/**

View File

@ -125,7 +125,7 @@ public class PublishClusterStateAction extends AbstractComponent {
final boolean sendFullVersion;
try {
nodes = clusterChangedEvent.state().nodes();
nodesToPublishTo = new HashSet<>(nodes.size());
nodesToPublishTo = new HashSet<>(nodes.getSize());
DiscoveryNode localNode = nodes.localNode();
final int totalMasterNodes = nodes.masterNodes().size();
for (final DiscoveryNode node : nodes) {

View File

@ -68,7 +68,7 @@ public class TransportNodesActionTests extends ESTestCase {
PlainActionFuture<TestNodesResponse> listener = new PlainActionFuture<>();
action.new AsyncAction(null, request, listener).start();
Map<String, List<CapturingTransport.CapturedRequest>> capturedRequests = transport.getCapturedRequestsByTargetNodeAndClear();
int numNodes = clusterService.state().getNodes().size();
int numNodes = clusterService.state().getNodes().getSize();
// check a request was sent to the right number of nodes
assertEquals(numNodes, capturedRequests.size());
}

View File

@ -78,7 +78,7 @@ public class TransportClientRetryIT extends ESIntegTestCase {
transportClient.admin().cluster().state(clusterStateRequest, future);
clusterState = future.get().getState();
}
assertThat(clusterState.nodes().size(), greaterThanOrEqualTo(size - j));
assertThat(clusterState.nodes().getSize(), greaterThanOrEqualTo(size - j));
assertThat(transportClient.connectedNodes().size(), greaterThanOrEqualTo(size - j));
}
}

View File

@ -265,7 +265,7 @@ public class ClusterChangedEventTests extends ESTestCase {
builder.metaData(metaBuilder);
}
if (numNodesToRemove > 0) {
final int discoveryNodesSize = previousState.getNodes().size();
final int discoveryNodesSize = previousState.getNodes().getSize();
final DiscoveryNodes.Builder nodesBuilder = DiscoveryNodes.builder(previousState.getNodes());
for (int i = 0; i < numNodesToRemove && i < discoveryNodesSize; i++) {
nodesBuilder.remove(NODE_ID_PREFIX + i);

View File

@ -88,7 +88,7 @@ public class MinimumMasterNodesIT extends ESIntegTestCase {
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.nodes().size(), equalTo(1)); // verify that we still see the local node in the cluster state
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");
internalCluster().startNode(settings);
@ -102,7 +102,7 @@ public class MinimumMasterNodesIT extends ESIntegTestCase {
assertThat(state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));
state = client().admin().cluster().prepareState().execute().actionGet().getState();
assertThat(state.nodes().size(), equalTo(2));
assertThat(state.nodes().getSize(), equalTo(2));
assertThat(state.metaData().indices().containsKey("test"), equalTo(false));
createIndex("test");
@ -128,7 +128,7 @@ public class MinimumMasterNodesIT extends ESIntegTestCase {
});
state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
assertThat(state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(true));
assertThat(state.nodes().size(), equalTo(1)); // verify that we still see the local node in the cluster state
assertThat(state.nodes().getSize(), equalTo(1)); // verify that we still see the local node in the cluster state
logger.info("--> starting the previous master node again...");
internalCluster().startNode(settings);
@ -142,7 +142,7 @@ public class MinimumMasterNodesIT extends ESIntegTestCase {
assertThat(state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));
state = client().admin().cluster().prepareState().execute().actionGet().getState();
assertThat(state.nodes().size(), equalTo(2));
assertThat(state.nodes().getSize(), equalTo(2));
assertThat(state.metaData().indices().containsKey("test"), equalTo(true));
ensureGreen();
@ -174,7 +174,7 @@ public class MinimumMasterNodesIT extends ESIntegTestCase {
assertThat(state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(false));
state = client().admin().cluster().prepareState().execute().actionGet().getState();
assertThat(state.nodes().size(), equalTo(2));
assertThat(state.nodes().getSize(), equalTo(2));
assertThat(state.metaData().indices().containsKey("test"), equalTo(true));
logger.info("Running Cluster Health");
@ -217,7 +217,7 @@ public class MinimumMasterNodesIT extends ESIntegTestCase {
assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
state = client().admin().cluster().prepareState().execute().actionGet().getState();
assertThat(state.nodes().size(), equalTo(4));
assertThat(state.nodes().getSize(), equalTo(4));
createIndex("test");
NumShards numShards = getNumShards("test");
@ -252,7 +252,7 @@ public class MinimumMasterNodesIT extends ESIntegTestCase {
assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
state = client().admin().cluster().prepareState().execute().actionGet().getState();
assertThat(state.nodes().size(), equalTo(4));
assertThat(state.nodes().getSize(), equalTo(4));
// we prefer to elect up and running nodes
assertThat(state.nodes().masterNodeId(), not(isOneOf(newNodes)));

View File

@ -129,7 +129,7 @@ public class NodeConnectionsServiceTests extends ESTestCase {
private void assertConnectedExactlyToNodes(ClusterState state) {
assertConnected(state.nodes());
assertThat(transport.connectedNodes.size(), equalTo(state.nodes().size()));
assertThat(transport.connectedNodes.size(), equalTo(state.nodes().getSize()));
}
private void assertConnected(Iterable<DiscoveryNode> nodes) {

View File

@ -89,7 +89,7 @@ public class RandomAllocationDeciderTests extends ESAllocationTestCase {
ClusterState.Builder stateBuilder = ClusterState.builder(clusterState);
DiscoveryNodes.Builder newNodesBuilder = DiscoveryNodes.builder(clusterState.nodes());
if (clusterState.nodes().size() <= atMostNodes &&
if (clusterState.nodes().getSize() <= atMostNodes &&
(nodeIdCounter == 0 || (frequentNodes ? frequently() : rarely()))) {
int numNodes = scaledRandomIntBetween(1, 3);
for (int j = 0; j < numNodes; j++) {
@ -115,10 +115,10 @@ public class RandomAllocationDeciderTests extends ESAllocationTestCase {
}
}
logger.info("Fill up nodes such that every shard can be allocated");
if (clusterState.nodes().size() < maxNumReplicas) {
if (clusterState.nodes().getSize() < maxNumReplicas) {
ClusterState.Builder stateBuilder = ClusterState.builder(clusterState);
DiscoveryNodes.Builder newNodesBuilder = DiscoveryNodes.builder(clusterState.nodes());
for (int j = 0; j < (maxNumReplicas - clusterState.nodes().size()); j++) {
for (int j = 0; j < (maxNumReplicas - clusterState.nodes().getSize()); j++) {
logger.info("adding node [{}]", nodeIdCounter);
newNodesBuilder.put(newNode("NODE_" + (nodeIdCounter++)));
}
@ -149,7 +149,7 @@ public class RandomAllocationDeciderTests extends ESAllocationTestCase {
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.UNASSIGNED).size(), equalTo(0));
int shards = clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size();
assertThat(shards, equalTo(totalNumShards));
final int numNodes = clusterState.nodes().size();
final int numNodes = clusterState.nodes().getSize();
final int upperBound = (int) Math.round(((shards / numNodes) * 1.10));
final int lowerBound = (int) Math.round(((shards / numNodes) * 0.90));
for (int i = 0; i < nodeIdCounter; i++) {

View File

@ -401,7 +401,7 @@ public class DiscoveryWithServiceDisruptionsIT extends ESIntegTestCase {
// assert nodes are identical
try {
assertEquals("unequal versions", state.version(), nodeState.version());
assertEquals("unequal node count", state.nodes().size(), nodeState.nodes().size());
assertEquals("unequal node count", state.nodes().getSize(), nodeState.nodes().getSize());
assertEquals("different masters ", state.nodes().masterNodeId(), nodeState.nodes().masterNodeId());
assertEquals("different meta data version", state.metaData().version(), nodeState.metaData().version());
if (!state.routingTable().prettyPrint().equals(nodeState.routingTable().prettyPrint())) {
@ -1205,7 +1205,7 @@ public class DiscoveryWithServiceDisruptionsIT extends ESIntegTestCase {
for (String node : nodes) {
ClusterState state = getNodeClusterState(node);
String failMsgSuffix = "cluster_state:\n" + state.prettyPrint();
assertThat("wrong node count on [" + node + "]. " + failMsgSuffix, state.nodes().size(), equalTo(nodes.size()));
assertThat("wrong node count on [" + node + "]. " + failMsgSuffix, state.nodes().getSize(), equalTo(nodes.size()));
String otherMasterNodeName = state.nodes().masterNode() != null ? state.nodes().masterNode().getName() : null;
assertThat("wrong master on node [" + node + "]. " + failMsgSuffix, otherMasterNodeName, equalTo(masterNode));
}

View File

@ -92,7 +92,7 @@ public class ZenUnicastDiscoveryIT extends ESIntegTestCase {
DiscoveryNode masterDiscoNode = null;
for (String node : nodes) {
ClusterState state = internalCluster().client(node).admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
assertThat(state.nodes().size(), equalTo(currentNumNodes));
assertThat(state.nodes().getSize(), equalTo(currentNumNodes));
if (masterDiscoNode == null) {
masterDiscoNode = state.nodes().masterNode();
} else {

View File

@ -557,7 +557,7 @@ public class NodeJoinControllerTests extends ESTestCase {
for (DiscoveryNode node : expectedNodes) {
assertThat("missing " + node + "\n" + discoveryNodes.prettyPrint(), discoveryNodes.get(node.getId()), equalTo(node));
}
assertThat(discoveryNodes.size(), equalTo(expectedNodes.size()));
assertThat(discoveryNodes.getSize(), equalTo(expectedNodes.size()));
}
static class SimpleFuture extends BaseFuture<Void> {