javahazelcastsubsystemcapatomic-long

How to use AtomicLong on Hazelcast CP Subsystem with just 2 Hazelcast cluster nodes?


I am updating to latest Hazelcast version [3.12] and I am facing problem to obtain a instance of AtomicLong. The new version, HZ introduces the concept of CAP Theorem, to grant Consistency and Partition Tolerance, but he problem is the CP subsystem must have at least 3 members.

Config config = new Config();
config.getCPSubsystemConfig().setCPMemberCount(3);
config.getCPSubsystemConfig().setGroupSize(3);

HazelcastInstance instance1 = Hazelcast.newHazelcastInstance(config);

How can I configure the CP Subsystem to provides me an instance of atomicLong with just two hazelcast nodes?

If I start my application with just one node, the follow message is printed:

MetadataRaftGroupManager.log:65 [127.0.0.1]:6000 [dev] [3.12] CP Subsystem is waiting for 3 members to join the cluster. Current member count: 1

I will have just two nodes, so, the CP Subsystem doesn't allow me to use an atomicLong because it will waits for ever for at leats 3 nodes..

The version 3.11 I just called hazelcast.getAtomicLong("count"). How can I handle with this?


Solution

  • In 3.12, The CP subsystem cannot be configured to operate with fewer than 3 nodes, because this would sacrifice the "consistency" which is the entire purpose of the CP subsystem under some failure scenarios (network partitioning). [EDIT: See new comment below regarding 4.0 and later behavior]

    You can still use the 3.11 APIs, so the code you have from your 3.11 implementation will continue to work. Although the 3.11 APIs are marked deprecated, they are not removed or disabled; the deprecation is a warning that the APIs are known to be vulnerable to consistency issues in a split brain scenario. Some application code is tolerant of such issues and the vulnerability isn't a concern; if your application is not tolerant of a potential consistency issue with the atomic long then adding an additional node in order to migrate to the CP implementation will be required.