Remove DiscoveryNode#masterNode in favour of existing DiscoveryNode#isMasterNode

This commit is contained in:
javanna 2016-03-30 14:52:39 +02:00 committed by Luca Cavanna
parent dfeb9379ab
commit 41039a6431
10 changed files with 21 additions and 28 deletions

View File

@ -249,18 +249,11 @@ public class DiscoveryNode implements Writeable<DiscoveryNode>, ToXContent {
return roles.contains(Role.DATA);
}
/**
* Can this node become master or not.
*/
public boolean masterNode() {
return roles.contains(Role.MASTER);
}
/**
* Can this node become master or not.
*/
public boolean isMasterNode() {
return masterNode();
return roles.contains(Role.MASTER);
}
/**

View File

@ -679,7 +679,7 @@ public class DiscoveryNodes extends AbstractDiffable<DiscoveryNodes> implements
dataNodesBuilder.put(nodeEntry.key, nodeEntry.value);
minNonClientNodeVersion = Version.smallest(minNonClientNodeVersion, nodeEntry.value.version());
}
if (nodeEntry.value.masterNode()) {
if (nodeEntry.value.isMasterNode()) {
masterNodesBuilder.put(nodeEntry.key, nodeEntry.value);
minNonClientNodeVersion = Version.smallest(minNonClientNodeVersion, nodeEntry.value.version());
}

View File

@ -106,7 +106,7 @@ public class LocalDiscovery extends AbstractLifecycleComponent<Discovery> implem
LocalDiscovery firstMaster = null;
for (LocalDiscovery localDiscovery : clusterGroup.members()) {
if (localDiscovery.localNode().masterNode()) {
if (localDiscovery.localNode().isMasterNode()) {
firstMaster = localDiscovery;
break;
}
@ -193,7 +193,7 @@ public class LocalDiscovery extends AbstractLifecycleComponent<Discovery> implem
LocalDiscovery firstMaster = null;
for (LocalDiscovery localDiscovery : clusterGroup.members()) {
if (localDiscovery.localNode().masterNode()) {
if (localDiscovery.localNode().isMasterNode()) {
firstMaster = localDiscovery;
break;
}

View File

@ -863,7 +863,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent<Discovery> implemen
Set<DiscoveryNode> activeNodes = new HashSet<>();
// nodes discovered who has previously been part of the cluster and do not ping for the very first time
Set<DiscoveryNode> joinedOnceActiveNodes = new HashSet<>();
if (localNode.masterNode()) {
if (localNode.isMasterNode()) {
activeNodes.add(localNode);
long joinsCounter = clusterJoinsCounter.get();
if (joinsCounter > 0) {

View File

@ -73,7 +73,7 @@ public class ElectMasterService extends AbstractComponent {
}
int count = 0;
for (DiscoveryNode node : nodes) {
if (node.masterNode()) {
if (node.isMasterNode()) {
count++;
}
}
@ -136,7 +136,7 @@ public class ElectMasterService extends AbstractComponent {
// clean non master nodes
for (Iterator<DiscoveryNode> it = possibleNodes.iterator(); it.hasNext(); ) {
DiscoveryNode node = it.next();
if (!node.masterNode()) {
if (!node.isMasterNode()) {
it.remove();
}
}
@ -148,10 +148,10 @@ public class ElectMasterService extends AbstractComponent {
@Override
public int compare(DiscoveryNode o1, DiscoveryNode o2) {
if (o1.masterNode() && !o2.masterNode()) {
if (o1.isMasterNode() && !o2.isMasterNode()) {
return -1;
}
if (!o1.masterNode() && o2.masterNode()) {
if (!o1.isMasterNode() && o2.isMasterNode()) {
return 1;
}
return o1.getId().compareTo(o2.getId());

View File

@ -70,7 +70,7 @@ public class GatewayAllocator extends AbstractComponent {
boolean cleanCache = false;
DiscoveryNode localNode = event.state().nodes().localNode();
if (localNode != null) {
if (localNode.masterNode() == true && event.localNodeMaster() == false) {
if (localNode.isMasterNode() == true && event.localNodeMaster() == false) {
cleanCache = true;
}
} else {

View File

@ -118,7 +118,7 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL
Set<Index> relevantIndices = Collections.emptySet();
boolean success = true;
// write the state if this node is a master eligible node or if it is a data node and has shards allocated on it
if (state.nodes().localNode().masterNode() || state.nodes().localNode().isDataNode()) {
if (state.nodes().localNode().isMasterNode() || state.nodes().localNode().isDataNode()) {
if (previousMetaData == null) {
try {
// we determine if or if not we write meta data on data only nodes by looking at the shard routing
@ -178,7 +178,7 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL
Set<Index> relevantIndices;
if (isDataOnlyNode(state)) {
relevantIndices = getRelevantIndicesOnDataOnlyNode(state, previousState, previouslyWrittenIndices);
} else if (state.nodes().localNode().masterNode() == true) {
} else if (state.nodes().localNode().isMasterNode() == true) {
relevantIndices = getRelevantIndicesForMasterEligibleNode(state);
} else {
relevantIndices = Collections.emptySet();
@ -188,7 +188,7 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL
protected static boolean isDataOnlyNode(ClusterState state) {
return ((state.nodes().localNode().masterNode() == false) && state.nodes().localNode().isDataNode());
return ((state.nodes().localNode().isMasterNode() == false) && state.nodes().localNode().isDataNode());
}
/**

View File

@ -535,7 +535,7 @@ public class IndicesService extends AbstractLifecycleComponent<IndicesService> i
throw new IllegalStateException("Can't delete index store for [" + index.getName() + "] - it's still part of the indices service [" + localUUid + "] [" + metaData.getIndexUUID() + "]");
}
if (clusterState.metaData().hasIndex(index.getName()) && (clusterState.nodes().localNode().masterNode() == true)) {
if (clusterState.metaData().hasIndex(index.getName()) && (clusterState.nodes().localNode().isMasterNode() == true)) {
// we do not delete the store if it is a master eligible node and the index is still in the cluster state
// because we want to keep the meta data for indices around even if no shards are left here
final IndexMetaData idxMeta = clusterState.metaData().index(index.getName());

View File

@ -154,7 +154,7 @@ public class RepositoriesService extends AbstractComponent implements ClusterSta
@Override
public boolean mustAck(DiscoveryNode discoveryNode) {
return discoveryNode.masterNode();
return discoveryNode.isMasterNode();
}
});
}
@ -205,7 +205,7 @@ public class RepositoriesService extends AbstractComponent implements ClusterSta
@Override
public boolean mustAck(DiscoveryNode discoveryNode) {
// Since operation occurs only on masters, it's enough that only master-eligible nodes acked
return discoveryNode.masterNode();
return discoveryNode.isMasterNode();
}
});
}

View File

@ -65,9 +65,9 @@ public class ElectMasterServiceTests extends ESTestCase {
DiscoveryNode prevNode = sortedNodes.get(0);
for (int i = 1; i < sortedNodes.size(); i++) {
DiscoveryNode node = sortedNodes.get(i);
if (!prevNode.masterNode()) {
assertFalse(node.masterNode());
} else if (node.masterNode()) {
if (!prevNode.isMasterNode()) {
assertFalse(node.isMasterNode());
} else if (node.isMasterNode()) {
assertTrue(prevNode.getId().compareTo(node.getId()) < 0);
}
prevNode = node;
@ -83,7 +83,7 @@ public class ElectMasterServiceTests extends ESTestCase {
int master_nodes = 0;
for (DiscoveryNode node : nodes) {
if (node.masterNode()) {
if (node.isMasterNode()) {
master_nodes++;
}
}
@ -99,7 +99,7 @@ public class ElectMasterServiceTests extends ESTestCase {
} else {
assertNotNull(master);
for (DiscoveryNode node : nodes) {
if (node.masterNode()) {
if (node.isMasterNode()) {
assertTrue(master.getId().compareTo(node.getId()) <= 0);
}
}