Search in sources :

Example 31 with RaftEndpoint

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

the class LocalRaftGroup method getLeaderEndpoint.

public RaftEndpoint getLeaderEndpoint() {
    RaftEndpoint leader = null;
    for (int i = 0; i < size(); i++) {
        if (integrations[i].isShutdown()) {
            continue;
        }
        RaftNodeImpl node = nodes[i];
        RaftEndpoint endpoint = getLeaderMember(node);
        if (leader == null) {
            leader = endpoint;
        } else if (!leader.equals(endpoint)) {
            throw new AssertionError("Group doesn't have a single leader endpoint yet!");
        }
    }
    return leader;
}
Also used : RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint)

Example 32 with RaftEndpoint

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

the class CandidateStateTest method test_grantVote_withMajority.

@Test
public void test_grantVote_withMajority() {
    for (int i = 0; i < majority; i++) {
        RaftEndpoint endpoint = newRaftMember(1000 + i);
        assertTrue(state.grantVote(endpoint));
    }
    assertEquals(majority, state.voteCount());
    assertTrue(state.isMajorityGranted());
}
Also used : RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 33 with RaftEndpoint

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

the class CandidateStateTest method test_grantVote_withoutMajority.

@Test
public void test_grantVote_withoutMajority() {
    RaftEndpoint endpoint = newRaftMember(1000);
    assertTrue(state.grantVote(endpoint));
    assertFalse(state.grantVote(endpoint));
    assertEquals(1, state.voteCount());
    assertFalse(state.isMajorityGranted());
}
Also used : RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 34 with RaftEndpoint

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

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

the class CPGroupSummary method readData.

@Override
public void readData(ObjectDataInput in) throws IOException {
    id = in.readObject();
    int initialMemberCount = in.readInt();
    Set<RaftEndpoint> initialMembers = new LinkedHashSet<RaftEndpoint>();
    for (int i = 0; i < initialMemberCount; i++) {
        RaftEndpoint member = in.readObject();
        initialMembers.add(member);
    }
    this.initialMembers = unmodifiableSet(initialMembers);
    int memberCount = in.readInt();
    members = new LinkedHashSet<CPMember>(memberCount);
    for (int i = 0; i < memberCount; i++) {
        CPMember member = in.readObject();
        members.add(member);
    }
    members = unmodifiableSet(members);
    status = CPGroupStatus.valueOf(in.readString());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) CPMember(com.hazelcast.cp.CPMember)

Aggregations

RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)57 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)14 QuickTest (com.hazelcast.test.annotation.QuickTest)14 Test (org.junit.Test)14 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)8 RaftState (com.hazelcast.cp.internal.raft.impl.state.RaftState)7 ArrayList (java.util.ArrayList)7 CPMember (com.hazelcast.cp.CPMember)6 RaftLog (com.hazelcast.cp.internal.raft.impl.log.RaftLog)6 UUID (java.util.UUID)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 CPGroupId (com.hazelcast.cp.CPGroupId)5 TestRaftEndpoint (com.hazelcast.cp.internal.raft.impl.testing.TestRaftEndpoint)5 LinkedHashSet (java.util.LinkedHashSet)4 LogEntry (com.hazelcast.cp.internal.raft.impl.log.LogEntry)3 CPSubsystemException (com.hazelcast.cp.exception.CPSubsystemException)2 NotLeaderException (com.hazelcast.cp.exception.NotLeaderException)2 CannotCreateRaftGroupException (com.hazelcast.cp.internal.exception.CannotCreateRaftGroupException)2 RaftStateStore (com.hazelcast.cp.internal.raft.impl.persistence.RaftStateStore)2 LeaderState (com.hazelcast.cp.internal.raft.impl.state.LeaderState)2