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); 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. * Can this node become master or not.
*/ */
public boolean isMasterNode() { 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); dataNodesBuilder.put(nodeEntry.key, nodeEntry.value);
minNonClientNodeVersion = Version.smallest(minNonClientNodeVersion, nodeEntry.value.version()); minNonClientNodeVersion = Version.smallest(minNonClientNodeVersion, nodeEntry.value.version());
} }
if (nodeEntry.value.masterNode()) { if (nodeEntry.value.isMasterNode()) {
masterNodesBuilder.put(nodeEntry.key, nodeEntry.value); masterNodesBuilder.put(nodeEntry.key, nodeEntry.value);
minNonClientNodeVersion = Version.smallest(minNonClientNodeVersion, nodeEntry.value.version()); minNonClientNodeVersion = Version.smallest(minNonClientNodeVersion, nodeEntry.value.version());
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -118,7 +118,7 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL
Set<Index> relevantIndices = Collections.emptySet(); Set<Index> relevantIndices = Collections.emptySet();
boolean success = true; 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 // 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) { if (previousMetaData == null) {
try { try {
// we determine if or if not we write meta data on data only nodes by looking at the shard routing // 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; Set<Index> relevantIndices;
if (isDataOnlyNode(state)) { if (isDataOnlyNode(state)) {
relevantIndices = getRelevantIndicesOnDataOnlyNode(state, previousState, previouslyWrittenIndices); relevantIndices = getRelevantIndicesOnDataOnlyNode(state, previousState, previouslyWrittenIndices);
} else if (state.nodes().localNode().masterNode() == true) { } else if (state.nodes().localNode().isMasterNode() == true) {
relevantIndices = getRelevantIndicesForMasterEligibleNode(state); relevantIndices = getRelevantIndicesForMasterEligibleNode(state);
} else { } else {
relevantIndices = Collections.emptySet(); relevantIndices = Collections.emptySet();
@ -188,7 +188,7 @@ public class GatewayMetaState extends AbstractComponent implements ClusterStateL
protected static boolean isDataOnlyNode(ClusterState state) { 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() + "]"); 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 // 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 // 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()); final IndexMetaData idxMeta = clusterState.metaData().index(index.getName());

View File

@ -154,7 +154,7 @@ public class RepositoriesService extends AbstractComponent implements ClusterSta
@Override @Override
public boolean mustAck(DiscoveryNode discoveryNode) { public boolean mustAck(DiscoveryNode discoveryNode) {
return discoveryNode.masterNode(); return discoveryNode.isMasterNode();
} }
}); });
} }
@ -205,7 +205,7 @@ public class RepositoriesService extends AbstractComponent implements ClusterSta
@Override @Override
public boolean mustAck(DiscoveryNode discoveryNode) { public boolean mustAck(DiscoveryNode discoveryNode) {
// Since operation occurs only on masters, it's enough that only master-eligible nodes acked // 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); DiscoveryNode prevNode = sortedNodes.get(0);
for (int i = 1; i < sortedNodes.size(); i++) { for (int i = 1; i < sortedNodes.size(); i++) {
DiscoveryNode node = sortedNodes.get(i); DiscoveryNode node = sortedNodes.get(i);
if (!prevNode.masterNode()) { if (!prevNode.isMasterNode()) {
assertFalse(node.masterNode()); assertFalse(node.isMasterNode());
} else if (node.masterNode()) { } else if (node.isMasterNode()) {
assertTrue(prevNode.getId().compareTo(node.getId()) < 0); assertTrue(prevNode.getId().compareTo(node.getId()) < 0);
} }
prevNode = node; prevNode = node;
@ -83,7 +83,7 @@ public class ElectMasterServiceTests extends ESTestCase {
int master_nodes = 0; int master_nodes = 0;
for (DiscoveryNode node : nodes) { for (DiscoveryNode node : nodes) {
if (node.masterNode()) { if (node.isMasterNode()) {
master_nodes++; master_nodes++;
} }
} }
@ -99,7 +99,7 @@ public class ElectMasterServiceTests extends ESTestCase {
} else { } else {
assertNotNull(master); assertNotNull(master);
for (DiscoveryNode node : nodes) { for (DiscoveryNode node : nodes) {
if (node.masterNode()) { if (node.isMasterNode()) {
assertTrue(master.getId().compareTo(node.getId()) <= 0); assertTrue(master.getId().compareTo(node.getId()) <= 0);
} }
} }