Search in sources :

Example 6 with RaftNode

use of com.hazelcast.cp.internal.raft.impl.RaftNode 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();
    }
}
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 7 with RaftNode

use of com.hazelcast.cp.internal.raft.impl.RaftNode in project hazelcast by hazelcast.

the class RaftService method getOrInitRaftNode.

public RaftNode getOrInitRaftNode(CPGroupId groupId) {
    RaftNode node = nodes.get(groupId);
    if (node == null && isStartCompleted() && isDiscoveryCompleted() && !destroyedGroupIds.contains(groupId) && !terminatedRaftNodeGroupIds.contains(groupId)) {
        logger.fine("RaftNode[" + groupId + "] does not exist. Asking to the METADATA CP group...");
        nodeEngine.getExecutionService().execute(CP_SUBSYSTEM_EXECUTOR, new InitializeRaftNodeTask(groupId));
    }
    return node;
}
Also used : RaftNode(com.hazelcast.cp.internal.raft.impl.RaftNode) RaftNodeImpl.newRaftNode(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl.newRaftNode)

Example 8 with RaftNode

use of com.hazelcast.cp.internal.raft.impl.RaftNode in project hazelcast by hazelcast.

the class MetadataRaftGroupManager method isMetadataGroupLeader.

// could return stale information
boolean isMetadataGroupLeader() {
    CPMemberInfo localCPMember = getLocalCPMember();
    if (localCPMember == null) {
        return false;
    }
    RaftNode raftNode = raftService.getRaftNode(getMetadataGroupId());
    return raftNode != null && !raftNode.isTerminatedOrSteppedDown() && localCPMember.toRaftEndpoint().equals(raftNode.getLeader());
}
Also used : RaftNode(com.hazelcast.cp.internal.raft.impl.RaftNode)

Example 9 with RaftNode

use of com.hazelcast.cp.internal.raft.impl.RaftNode in project hazelcast by hazelcast.

the class RaftQueryOp method run.

@Override
public final void run() {
    RaftService service = getService();
    RaftNode raftNode = service.getRaftNode(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;
    }
    if (op instanceof RaftNodeAware) {
        ((RaftNodeAware) op).setRaftNode(raftNode);
    }
    raftNode.query(op, queryPolicy).whenCompleteAsync(this, CALLER_RUNS);
}
Also used : RaftNodeAware(com.hazelcast.cp.internal.RaftNodeAware) 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)

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