initial.min.cluster.size 的行为

Behavior of initial.min.cluster.size

如果未达到 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: starting Hazel pullExternal from Hazelcluster with 1 members.

是不是肯定有其他成员加入又离开了?从另一个实例的日志文件来看,情况似乎并非如此。因此,我想知道是否存在 hazelInst = Hazelcast.newHazelcastInstance(cfg); 不阻塞的情况,即使它是 hazelcast 集群中的唯一实例。

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

如果您将日志记录设置为调试,那么也许您可以更清楚地看到发生了什么。成员加入和离开应该已经在信息下可见。