initial.min.cluster.size的行为

时间:2015-06-27 13:37:18

标签: distributed distributed-computing hazelcast

如果未达到initial.min.cluster.size,Hazelcast是否始终会阻止?如果没有,在哪种情况下不是?

详细说明: 我使用以下代码初始化hazelcast:

Config cfg = new Config();  
cfg.setProperty("hazelcast.initial.min.cluster.size",Integer.
    toString(minimumInitialMembersInHazelCluster));  //2 in this case
cfg.getGroupConfig().setName(clusterName);

NetworkConfig network = cfg.getNetworkConfig();
JoinConfig join = network.getJoin();
join.getMulticastConfig().setEnabled(false);
join.getTcpIpConfig().addMember("192.168.0.1").addMember("192.168.0.2").
    addMember("192.168.0.3").addMember("192.168.0.4").
    addMember("192.168.0.5").addMember("192.168.0.6").
    addMember("192.168.0.7").setRequiredMember(null).setEnabled(true);  
network.getInterfaces().setEnabled(true).addInterface("192.168.0.*");
join.getMulticastConfig().setMulticastTimeoutSeconds(MCSOCK_TIMEOUT/100);           
hazelInst = Hazelcast.newHazelcastInstance(cfg);
distrDischargedTTGs = hazelInst.getList(clusterName);

并获取

等日志消息
  

debug:从Hazelcluster开始使用1个成员的Hazel pullExternal。

这是否意味着还有另一位成员加入并离开了?它看起来不像其他实例的日志文件那样。因此,我想知道是否存在hazelInst = Hazelcast.newHazelcastInstance(cfg);未阻止的情况,即使它是淡褐色聚类中唯一的实例。

1 个答案:

答案 0 :(得分:2)

newHazelcastInstance阻止群集拥有所需的成员数量。

请参阅以下代码了解其实施方式:

private static void awaitMinimalClusterSize(HazelcastInstanceImpl hazelcastInstance, Node node, boolean firstMember)
        throws InterruptedException {

    final int initialMinClusterSize = node.groupProperties.INITIAL_MIN_CLUSTER_SIZE.getInteger();
    while (node.getClusterService().getSize() < initialMinClusterSize) {
        try {
            hazelcastInstance.logger.info("HazelcastInstance waiting for cluster size of " + initialMinClusterSize);
            //noinspection BusyWait
            Thread.sleep(TimeUnit.SECONDS.toMillis(1));
        } catch (InterruptedException ignored) {
        }
    }
    if (initialMinClusterSize > 1) {
        if (firstMember) {
            node.partitionService.firstArrangement();
        } else {
            Thread.sleep(TimeUnit.SECONDS.toMillis(3));
        }
        hazelcastInstance.logger.info("HazelcastInstance starting after waiting for cluster size of "
                + initialMinClusterSize);
    }
}

如果您设置登录调试,那么也许您可以更好地了解正在发生的事情。会员加入和离开应该已经在信息下可见。