Search in sources :

Example 1 with CPPersistenceService

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);
        }
    });
}
Also used : CPPersistenceService(com.hazelcast.cp.internal.persistence.CPPersistenceService) 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 2 with CPPersistenceService

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();
    }
}
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 3 with CPPersistenceService

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();
    }
}
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 4 with CPPersistenceService

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();
    }
}
Also used : RaftAlgorithmConfig(com.hazelcast.config.cp.RaftAlgorithmConfig) PartitionOperationThread(com.hazelcast.spi.impl.operationexecutor.impl.PartitionOperationThread) CPPersistenceService(com.hazelcast.cp.internal.persistence.CPPersistenceService) 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) MigrationEndpoint(com.hazelcast.internal.partition.MigrationEndpoint) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint)

Aggregations

CPPersistenceService (com.hazelcast.cp.internal.persistence.CPPersistenceService)4 PartitionOperationThread (com.hazelcast.spi.impl.operationexecutor.impl.PartitionOperationThread)3 RaftNode (com.hazelcast.cp.internal.raft.impl.RaftNode)2 RaftNodeImpl.newRaftNode (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl.newRaftNode)2 RaftAlgorithmConfig (com.hazelcast.config.cp.RaftAlgorithmConfig)1 CPGroupDestroyedException (com.hazelcast.cp.exception.CPGroupDestroyedException)1 CannotRemoveCPMemberException (com.hazelcast.cp.internal.exception.CannotRemoveCPMemberException)1 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)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 ExecutionException (java.util.concurrent.ExecutionException)1