Search in sources :

Example 1 with RaftStateStore

use of com.hazelcast.cp.internal.raft.impl.persistence.RaftStateStore 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 2 with RaftStateStore

use of com.hazelcast.cp.internal.raft.impl.persistence.RaftStateStore 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)

Example 3 with RaftStateStore

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

the class LocalRaftGroup method createNewRaftNode.

public RaftNodeImpl createNewRaftNode() {
    int oldSize = this.integrations.length;
    int newSize = oldSize + 1;
    RaftEndpoint[] endpoints = new RaftEndpoint[newSize];
    LocalRaftIntegration[] integrations = new LocalRaftIntegration[newSize];
    RaftNodeImpl[] nodes = new RaftNodeImpl[newSize];
    System.arraycopy(this.members, 0, endpoints, 0, oldSize);
    System.arraycopy(this.integrations, 0, integrations, 0, oldSize);
    System.arraycopy(this.nodes, 0, nodes, 0, oldSize);
    LocalRaftIntegration integration = createNewLocalRaftIntegration();
    createdNodeCount++;
    integrations[oldSize] = integration;
    RaftEndpoint endpoint = integration.getLocalEndpoint();
    endpoints[oldSize] = endpoint;
    RaftStateStore raftStateStore = raftStateStoreFactory.apply(endpoint, raftAlgorithmConfig);
    RaftNodeImpl node = newRaftNode(groupId, endpoint, asList(initialMembers), raftAlgorithmConfig, integration, raftStateStore);
    nodes[oldSize] = node;
    this.members = endpoints;
    this.integrations = integrations;
    this.nodes = nodes;
    node.start();
    initDiscovery();
    return node;
}
Also used : RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) RaftStateStore(com.hazelcast.cp.internal.raft.impl.persistence.RaftStateStore) NopRaftStateStore(com.hazelcast.cp.internal.raft.impl.persistence.NopRaftStateStore) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint)

Aggregations

RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)3 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)3 RaftStateStore (com.hazelcast.cp.internal.raft.impl.persistence.RaftStateStore)3 RaftAlgorithmConfig (com.hazelcast.config.cp.RaftAlgorithmConfig)2 RaftIntegration (com.hazelcast.cp.internal.raft.impl.RaftIntegration)2 MigrationEndpoint (com.hazelcast.internal.partition.MigrationEndpoint)2 CPPersistenceService (com.hazelcast.cp.internal.persistence.CPPersistenceService)1 RaftNode (com.hazelcast.cp.internal.raft.impl.RaftNode)1 RaftNodeImpl.newRaftNode (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl.newRaftNode)1 NopRaftStateStore (com.hazelcast.cp.internal.raft.impl.persistence.NopRaftStateStore)1 PartitionOperationThread (com.hazelcast.spi.impl.operationexecutor.impl.PartitionOperationThread)1