2

Is Hazelcast always blocking in case initial.min.cluster.size is not reached? If not, under which situations is it not?


Details: I use the following code to initialize 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);

and get log messages like

debug: starting Hazel pullExternal from Hazelcluster with 1 members.

Does that definitely mean there was another member that has joined and left already? It does not look like that would be the case from the log files of the other instance. Hence I wonder whether there are situtations where hazelInst = Hazelcast.newHazelcastInstance(cfg); does not block even though it is the only instance in the hazelcast cluster.

DaveFar
  • 7,078
  • 4
  • 50
  • 90

1 Answers1

2

The newHazelcastInstance blocks till the clusters has the required number of members.

See the code below for how it is implemented:

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

If you set the logging on debug then perhaps you can see better what is happening. Member joining and leaving should already be visible under info.

DaveFar
  • 7,078
  • 4
  • 50
  • 90
pveentjer
  • 10,545
  • 3
  • 23
  • 40
  • 1
    Thanks for the fast and good answer, pveentjer. As always :) I wonder about your last sentence, however: `newHazelcastInstance` calls `awaitMinimalClusterSize`, which busywaits until at least initialMinClusterSize instances are present!? (But Thread.sleep might not block!?) – DaveFar Jun 28 '15 at 08:36
  • I didn't know if the call the newHazelcastInstance would block or if any later interaction with the cluster would block. I just verified; the call the newHazelcastInstance blocks till the clusters has the required size. – pveentjer Jun 28 '15 at 18:25
  • Thanks a lot, pveentjer :) – DaveFar Jun 28 '15 at 19:26