Starting with Hazelcast 3.7, the graceful shutdown of a Hazelcast member can be initiated at any time as follows:
hazelcastInstance.shutdown();
Once a Hazelcast member initiates a graceful shutdown, the data from the member that is shutting down is automatically migrated to the other nodes.
However, there is no such guarantee for termination.
The code snippet below terminates a member if isClusterSafe()
returns true, which means that there are no partitions being migrated and all backups are in sync at the time the method is called.
PartitionService partitionService = hazelcastInstance.getPartitionService();
if (partitionService.isClusterSafe()) {
hazelcastInstance.getLifecycleService().terminate();
}
The code snippet below terminates the local member if isLocalMemberSafe()
returns true, which means that all backups of partitions currently owned by this local member are in sync at the time the method is called.
PartitionService partitionService = hazelcastInstance.getPartitionService();
if (partitionService.isLocalMemberSafe()) {
hazelcastInstance.getLifecycleService().terminate();
}
Please keep in mind that these two code snippets are prone to race conditions. If member failures occur in the cluster after the safety condition check passes, termination of the local member can lead to data loss. For the safety of your data, we highly recommend you use the graceful shutdown API.
RELATED INFORMATION
Please refer to Safety Checking Cluster Members for more information.
Comments
0 comments
Article is closed for comments.