use of com.hazelcast.cp.internal.persistence.CPPersistenceService in project hazelcast by hazelcast.
the class RaftService method destroyRaftNode.
private void destroyRaftNode(RaftNode node, boolean removeRaftStateStore) {
RaftGroupId groupId = (RaftGroupId) node.getGroupId();
node.forceSetTerminatedStatus().whenCompleteAsync((v, t) -> {
nodes.remove(groupId, node);
removeNodeMetrics(groupId);
CPPersistenceService persistenceService = getCPPersistenceService();
try {
if (removeRaftStateStore && persistenceService.isEnabled()) {
persistenceService.removeRaftStateStore(groupId);
logger.info("RaftStateStore of RaftNode[" + groupId + "] is deleted.");
}
} catch (Exception e) {
logger.severe("Deletion of RaftStateStore of RaftNode[" + groupId + "] failed.", e);
}
});
}
use of com.hazelcast.cp.internal.persistence.CPPersistenceService in project hazelcast by hazelcast.
the class RaftService method terminateRaftNode.
public void terminateRaftNode(CPGroupId groupId, boolean groupDestroyed) {
if (destroyedGroupIds.contains(groupId) || !hasSameSeed(groupId)) {
return;
}
assert !(Thread.currentThread() instanceof PartitionOperationThread) : "Cannot terminate RaftNode of " + groupId + " in a partition thread!";
nodeLock.readLock().lock();
try {
if (destroyedGroupIds.contains(groupId)) {
return;
}
if (groupDestroyed) {
destroyedGroupIds.add(groupId);
}
terminatedRaftNodeGroupIds.add(groupId);
RaftNode node = nodes.get(groupId);
CPPersistenceService persistenceService = getCPPersistenceService();
if (node != null) {
destroyRaftNode(node, groupDestroyed);
logger.info("RaftNode[" + groupId + "] is destroyed.");
} else if (groupDestroyed && persistenceService.isEnabled()) {
persistenceService.removeRaftStateStore((RaftGroupId) groupId);
logger.info("RaftStateStore of RaftNode[" + groupId + "] is deleted.");
}
} finally {
nodeLock.readLock().unlock();
}
}
use of com.hazelcast.cp.internal.persistence.CPPersistenceService in project hazelcast by hazelcast.
the class RaftService method stepDownRaftNode.
public void stepDownRaftNode(CPGroupId groupId) {
if (terminatedRaftNodeGroupIds.contains(groupId) || !hasSameSeed(groupId)) {
return;
}
assert !(Thread.currentThread() instanceof PartitionOperationThread) : "Cannot step down RaftNode of " + groupId + " in a partition thread!";
nodeLock.readLock().lock();
try {
if (terminatedRaftNodeGroupIds.contains(groupId)) {
return;
}
CPPersistenceService persistenceService = getCPPersistenceService();
RaftNode node = nodes.get(groupId);
if (node != null && node.getStatus() == RaftNodeStatus.STEPPED_DOWN) {
terminatedRaftNodeGroupIds.add(groupId);
destroyRaftNode(node, true);
logger.fine("RaftNode[" + groupId + "] has stepped down.");
} else if (node == null && persistenceService.isEnabled()) {
persistenceService.removeRaftStateStore((RaftGroupId) groupId);
logger.info("RaftStateStore of RaftNode[" + groupId + "] is deleted.");
}
} finally {
nodeLock.readLock().unlock();
}
}
use of com.hazelcast.cp.internal.persistence.CPPersistenceService in project hazelcast by hazelcast.
the class RaftService method createRaftNode.
void createRaftNode(CPGroupId groupId, Collection<RaftEndpoint> members, RaftEndpoint localCPMember) {
assert !(Thread.currentThread() instanceof PartitionOperationThread) : "Cannot create RaftNode of " + groupId + " in a partition thread!";
if (nodes.containsKey(groupId) || !isStartCompleted() || !hasSameSeed(groupId)) {
return;
}
if (getLocalCPMember() == null) {
logger.warning("Not creating Raft node for " + groupId + " because local CP member is not initialized yet.");
return;
}
nodeLock.readLock().lock();
try {
if (destroyedGroupIds.contains(groupId)) {
logger.warning("Not creating RaftNode[" + groupId + "] since the CP group is already destroyed.");
return;
} else if (terminatedRaftNodeGroupIds.contains(groupId)) {
if (!nodeEngine.isRunning()) {
logger.fine("Not creating RaftNode[" + groupId + "] since the local CP member is already terminated.");
return;
}
}
int partitionId = getCPGroupPartitionId(groupId);
RaftIntegration integration = new NodeEngineRaftIntegration(nodeEngine, groupId, localCPMember, partitionId);
RaftAlgorithmConfig raftAlgorithmConfig = config.getRaftAlgorithmConfig();
CPPersistenceService persistenceService = getCPPersistenceService();
RaftStateStore stateStore = persistenceService.createRaftStateStore((RaftGroupId) groupId, null);
RaftNodeImpl node = newRaftNode(groupId, localCPMember, members, raftAlgorithmConfig, integration, stateStore);
if (nodes.putIfAbsent(groupId, node) == null) {
if (destroyedGroupIds.contains(groupId)) {
nodes.remove(groupId, node);
removeNodeMetrics(groupId);
logger.warning("Not creating RaftNode[" + groupId + "] since the CP group is already destroyed.");
return;
}
node.start();
logger.info("RaftNode[" + groupId + "] is created with " + members);
}
} finally {
nodeLock.readLock().unlock();
}
}
Aggregations