I am researching the algorithm that hazelcast uses to find the master node in multicast way.First I find the function to find master node: com.hazelcast.cluster.MulticastJoiner.findMasterWithMulticast()
private Address findMasterWithMulticast() {
try {
if (logger.isFinestEnabled()) {
logger.finest("Searching for master node. Max tries: " + maxTryCount.get());
}
JoinRequest joinRequest = node.createJoinRequest();
while (node.isActive() && currentTryCount.incrementAndGet() <= maxTryCount.get()) {
joinRequest.setTryCount(currentTryCount.get());
node.multicastService.send(joinRequest);
if (node.getMasterAddress() == null) {
//noinspection BusyWait
Thread.sleep(PUBLISH_INTERVAL);
} else {
return node.getMasterAddress();
}
}
} catch (final Exception e) {
if (logger != null) {
logger.warning(e);
}
} finally {
currentTryCount.set(0);
}
return null;
}
what the function does is just sendding a joinRequest to other nodes in the same clusters. The function com.hazelcast.cluster.MulticastJoiner.onReceivedJoinRequest(JoinRequest) deals with the joinRequest.
public void onReceivedJoinRequest(JoinRequest joinRequest) {
if (joinRequest.getUuid().compareTo(node.localMember.getUuid()) < 0) {
maxTryCount.incrementAndGet();
}
}
It only increases the trycount.What does this mean?How the master node is selected?Wish your help.