Search in sources :

Example 1 with RaftNode

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);
}
Also used : NotLeaderException(com.hazelcast.cp.exception.NotLeaderException) RaftService(com.hazelcast.cp.internal.RaftService) CPGroupDestroyedException(com.hazelcast.cp.exception.CPGroupDestroyedException) RaftNode(com.hazelcast.cp.internal.raft.impl.RaftNode)

Example 2 with RaftNode

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;
}
Also used : RaftAlgorithmConfig(com.hazelcast.config.cp.RaftAlgorithmConfig) RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) RaftIntegration(com.hazelcast.cp.internal.raft.impl.RaftIntegration) RaftStateStore(com.hazelcast.cp.internal.raft.impl.persistence.RaftStateStore) RaftNode(com.hazelcast.cp.internal.raft.impl.RaftNode) RaftNodeImpl.newRaftNode(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl.newRaftNode) MigrationEndpoint(com.hazelcast.internal.partition.MigrationEndpoint) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint)

Example 3 with RaftNode

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();
}
Also used : ServiceInfo(com.hazelcast.spi.impl.servicemanager.ServiceInfo) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) ArrayList(java.util.ArrayList) RaftManagedService(com.hazelcast.cp.internal.datastructures.spi.RaftManagedService) RaftNode(com.hazelcast.cp.internal.raft.impl.RaftNode) RaftNodeImpl.newRaftNode(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl.newRaftNode) PartitionMigratingException(com.hazelcast.spi.exception.PartitionMigratingException) CPGroupDestroyedException(com.hazelcast.cp.exception.CPGroupDestroyedException) ExecutionException(java.util.concurrent.ExecutionException) CannotRemoveCPMemberException(com.hazelcast.cp.internal.exception.CannotRemoveCPMemberException) ResponseAlreadySentException(com.hazelcast.spi.exception.ResponseAlreadySentException)

Example 4 with RaftNode

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();
    }
}
Also used : PartitionOperationThread(com.hazelcast.spi.impl.operationexecutor.impl.PartitionOperationThread) CPPersistenceService(com.hazelcast.cp.internal.persistence.CPPersistenceService) RaftNode(com.hazelcast.cp.internal.raft.impl.RaftNode) RaftNodeImpl.newRaftNode(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl.newRaftNode)

Example 5 with RaftNode

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;
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) ArrayList(java.util.ArrayList) RaftNode(com.hazelcast.cp.internal.raft.impl.RaftNode) RaftNodeImpl.newRaftNode(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl.newRaftNode)

Aggregations

RaftNode (com.hazelcast.cp.internal.raft.impl.RaftNode)9 RaftNodeImpl.newRaftNode (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl.newRaftNode)6 CPGroupDestroyedException (com.hazelcast.cp.exception.CPGroupDestroyedException)3 NotLeaderException (com.hazelcast.cp.exception.NotLeaderException)2 RaftService (com.hazelcast.cp.internal.RaftService)2 CPPersistenceService (com.hazelcast.cp.internal.persistence.CPPersistenceService)2 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)2 PartitionOperationThread (com.hazelcast.spi.impl.operationexecutor.impl.PartitionOperationThread)2 ArrayList (java.util.ArrayList)2 RaftAlgorithmConfig (com.hazelcast.config.cp.RaftAlgorithmConfig)1 CPGroupId (com.hazelcast.cp.CPGroupId)1 RaftNodeAware (com.hazelcast.cp.internal.RaftNodeAware)1 RaftManagedService (com.hazelcast.cp.internal.datastructures.spi.RaftManagedService)1 CannotRemoveCPMemberException (com.hazelcast.cp.internal.exception.CannotRemoveCPMemberException)1 RaftIntegration (com.hazelcast.cp.internal.raft.impl.RaftIntegration)1 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)1 RaftStateStore (com.hazelcast.cp.internal.raft.impl.persistence.RaftStateStore)1 MigrationEndpoint (com.hazelcast.internal.partition.MigrationEndpoint)1 PartitionMigratingException (com.hazelcast.spi.exception.PartitionMigratingException)1 ResponseAlreadySentException (com.hazelcast.spi.exception.ResponseAlreadySentException)1