use of com.hazelcast.cp.internal.raft.impl.RaftIntegration in project hazelcast by hazelcast.
the class RaftService method restoreRaftNode.
public RaftNodeImpl restoreRaftNode(RaftGroupId groupId, RestoredRaftState restoredState, LogFileStructure logFileStructure) {
int partitionId = getCPGroupPartitionId(groupId);
RaftIntegration integration = new NodeEngineRaftIntegration(nodeEngine, groupId, restoredState.localEndpoint(), partitionId);
RaftAlgorithmConfig raftAlgorithmConfig = config.getRaftAlgorithmConfig();
RaftStateStore stateStore = getCPPersistenceService().createRaftStateStore(groupId, logFileStructure);
RaftNodeImpl node = RaftNodeImpl.restoreRaftNode(groupId, restoredState, raftAlgorithmConfig, integration, stateStore);
// no need to lock here...
RaftNode prev = nodes.putIfAbsent(groupId, node);
checkState(prev == null, "Could not restore " + groupId + " because its Raft node already exists!");
node.start();
logger.info("RaftNode[" + groupId + "] is restored.");
return node;
}
use of com.hazelcast.cp.internal.raft.impl.RaftIntegration 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