use of com.hazelcast.cp.internal.raft.impl.RaftNode in project hazelcast by hazelcast.
the class RaftReplicateOp method run.
@Override
public final void run() {
RaftService service = getService();
RaftNode raftNode = service.getOrInitRaftNode(groupId);
if (raftNode == null) {
if (service.isRaftGroupDestroyed(groupId)) {
sendResponse(new CPGroupDestroyedException(groupId));
} else {
sendResponse(new NotLeaderException(groupId, service.getLocalCPEndpoint(), null));
}
return;
} else if (raftNode.getStatus() == RaftNodeStatus.STEPPED_DOWN) {
sendResponse(new NotLeaderException(groupId, service.getLocalCPEndpoint(), null));
getNodeEngine().getExecutionService().execute(CP_SUBSYSTEM_EXECUTOR, () -> service.stepDownRaftNode(groupId));
return;
}
replicate(raftNode).whenCompleteAsync(this, CALLER_RUNS);
}
use of com.hazelcast.cp.internal.raft.impl.RaftNode 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.RaftNode in project hazelcast by hazelcast.
the class RaftService method resetLocalRaftState.
private void resetLocalRaftState() {
// node.forceSetTerminatedStatus() will trigger RaftNodeLifecycleAwareService.onRaftGroupDestroyed()
// which will attempt to acquire the read lock on nodeLock. In order to prevent it, we first
// add group ids into destroyedGroupIds to short-cut RaftNodeLifecycleAwareService.onRaftGroupDestroyed()
List<InternalCompletableFuture> futures = new ArrayList<>(nodes.size());
destroyedGroupIds.addAll(nodes.keySet());
for (RaftNode node : nodes.values()) {
InternalCompletableFuture f = node.forceSetTerminatedStatus();
futures.add(f);
}
for (InternalCompletableFuture future : futures) {
try {
future.get();
} catch (Exception e) {
logger.warning(e);
}
}
nodes.clear();
for (ServiceInfo serviceInfo : nodeEngine.getServiceInfos(RaftRemoteService.class)) {
if (serviceInfo.getService() instanceof RaftManagedService) {
((RaftManagedService) serviceInfo.getService()).onCPSubsystemRestart();
}
}
nodeMetrics.clear();
missingMembers.clear();
invocationManager.reset();
}
use of com.hazelcast.cp.internal.raft.impl.RaftNode 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.raft.impl.RaftNode in project hazelcast by hazelcast.
the class RaftService method getLeadedGroups.
public Collection<CPGroupId> getLeadedGroups() {
Collection<CPGroupId> groupIds = new ArrayList<>();
RaftEndpoint localEndpoint = getLocalCPEndpoint();
for (RaftNode raftNode : nodes.values()) {
if (CPGroup.METADATA_CP_GROUP_NAME.equals(raftNode.getGroupId().getName())) {
// Ignore metadata group
continue;
}
RaftEndpoint leader = raftNode.getLeader();
if (leader != null && leader.equals(localEndpoint)) {
groupIds.add(raftNode.getGroupId());
}
}
return groupIds;
}
Aggregations