hazelcast使用什么算法来找到主节点 [英] what algorithm hazelcast uses to find the master node

查看:286
本文介绍了hazelcast使用什么算法来找到主节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究hazelcast用于以多播方式查找主节点的算法.首先,我找到用于查找主节点的函数:com.hazelcast.cluster.MulticastJoiner.findMasterWithMulticast()

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;
}

该函数所做的只是将joinRequest发送到相同集群中的其他节点. com.hazelcast.cluster.MulticastJoiner.onReceivedJoinRequest(JoinRequest)函数处理joinRequest.

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();
    }
}

它只会增加trycount.这是什么意思?如何选择主节点?希望您的帮助.

It only increases the trycount.What does this mean?How the master node is selected?Wish your help.

推荐答案

在多播发现中,每个节点在启动加入过程之前都会计算自己的maxTryCount. maxTryCount是该特定节点将自己声明为主节点之前将发布的加入消息的最大数目.

In multicast discovery, each node calculates its own maxTryCount before join process is initiated. maxTryCount is the maximum number of join messages those will be published by that specific node, before declaring itself as master.

它是使用一些参数来计算的,例如多播超时,节点的IP地址和端口等.请参见

It's calculated using a few parameters such as multicast timeout, IP address and port of node etc. See MulticastJoiner.calculateTryCount(). So, main purpose here is each node (most probably) will have a different maximum try count.

此外,当节点收到加入请求时,如果纯在MulticastJoiner.onReceivedJoinRequest()内部定义的函数返回true:

Additionally, when a node receives join request, maxTryCount is incremented by 1 if the pure function defined inside MulticastJoiner.onReceivedJoinRequest() returns true:

joinRequest.getUuid().compareTo(node.localMember.getUuid()) < 0

这是为了使两侧的maxTryCount编号不同.

This is to diverge maxTryCount number on both sides.

一旦节点发布maxTryCount加入消息,然后它将自己声明为主节点(最旧的成员)并开始接受/响应加入请求.

Once a node publishes maxTryCount join messages, then it declares itself as master (oldest member) and starts to accept/respond join requests.

这篇关于hazelcast使用什么算法来找到主节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆