Search in sources :

Example 16 with RaftNodeImpl

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

the class LocalRaftIntegration method send.

@Override
public boolean send(PreVoteRequest request, RaftEndpoint target) {
    assertNotEquals(localEndpoint, target);
    RaftNodeImpl node = nodes.get(target);
    if (node == null) {
        return false;
    }
    if (shouldDrop(request, target)) {
        return true;
    }
    node.handlePreVoteRequest(alterMessageIfNeeded(request, target));
    return true;
}
Also used : RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)

Example 17 with RaftNodeImpl

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

the class RaftService method completeFutures.

/**
 * Completes all futures registered with {@code indices}
 * in the CP group associated with {@code groupId}.
 *
 * @return {@code true} if the CP group exists, {@code false} otherwise.
 */
public boolean completeFutures(CPGroupId groupId, Collection<Entry<Long, Object>> results) {
    if (cpSubsystemEnabled) {
        RaftNodeImpl raftNode = (RaftNodeImpl) getRaftNode(groupId);
        if (raftNode == null) {
            return false;
        }
        for (Entry<Long, Object> result : results) {
            raftNode.completeFuture(result.getKey(), result.getValue());
        }
    } else {
        int partitionId = getCPGroupPartitionId(groupId);
        UnsafeModePartitionState unsafeModeState = unsafeModeStates[partitionId];
        for (Entry<Long, Object> result : results) {
            Operation op = unsafeModeState.removeWaitingOp(result.getKey());
            sendOperationResponse(op, result.getValue());
        }
    }
    return true;
}
Also used : RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) Operation(com.hazelcast.spi.impl.operationservice.Operation) MigrationEndpoint(com.hazelcast.internal.partition.MigrationEndpoint) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint)

Example 18 with RaftNodeImpl

use of com.hazelcast.cp.internal.raft.impl.RaftNodeImpl 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 19 with RaftNodeImpl

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

the class RaftService method completeFutures.

/**
 * Completes all futures registered with {@code indices}
 * in the CP group associated with {@code groupId}.
 *
 * @return {@code true} if the CP group exists, {@code false} otherwise.
 */
public boolean completeFutures(CPGroupId groupId, Collection<Long> indices, Object result) {
    if (cpSubsystemEnabled) {
        RaftNodeImpl raftNode = (RaftNodeImpl) getRaftNode(groupId);
        if (raftNode == null) {
            return false;
        }
        for (Long index : indices) {
            raftNode.completeFuture(index, result);
        }
    } else {
        int partitionId = getCPGroupPartitionId(groupId);
        UnsafeModePartitionState unsafeModeState = unsafeModeStates[partitionId];
        for (Long index : indices) {
            Operation op = unsafeModeState.removeWaitingOp(index);
            sendOperationResponse(op, result);
        }
    }
    return true;
}
Also used : RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) Operation(com.hazelcast.spi.impl.operationservice.Operation) MigrationEndpoint(com.hazelcast.internal.partition.MigrationEndpoint) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint)

Example 20 with RaftNodeImpl

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

RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)38 HazelcastInstance (com.hazelcast.core.HazelcastInstance)18 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)17 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)14 Test (org.junit.Test)14 CPGroupId (com.hazelcast.cp.CPGroupId)9 CPMember (com.hazelcast.cp.CPMember)9 CPGroup (com.hazelcast.cp.CPGroup)8 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)7 QuickTest (com.hazelcast.test.annotation.QuickTest)7 SlowTest (com.hazelcast.test.annotation.SlowTest)7 ArrayList (java.util.ArrayList)5 Config (com.hazelcast.config.Config)4 MigrationEndpoint (com.hazelcast.internal.partition.MigrationEndpoint)4 TestHazelcastInstanceFactory.initOrCreateConfig (com.hazelcast.test.TestHazelcastInstanceFactory.initOrCreateConfig)4 ResourceRegistry (com.hazelcast.cp.internal.datastructures.spi.blocking.ResourceRegistry)3 LogEntry (com.hazelcast.cp.internal.raft.impl.log.LogEntry)3 RaftStateStore (com.hazelcast.cp.internal.raft.impl.persistence.RaftStateStore)3 RestoreSnapshotOp (com.hazelcast.cp.internal.raftop.snapshot.RestoreSnapshotOp)3 List (java.util.List)3