Search in sources :

Example 1 with CreateRaftGroupOp

use of com.hazelcast.cp.internal.raftop.metadata.CreateRaftGroupOp in project hazelcast by hazelcast.

the class RaftInvocationManager method invokeCreateRaftGroup.

private void invokeCreateRaftGroup(String groupName, int groupSize, long groupIndex, List<RaftEndpoint> members, InternalCompletableFuture<RaftGroupId> resultFuture) {
    InternalCompletableFuture<CPGroupSummary> f = invoke(raftService.getMetadataGroupId(), new CreateRaftGroupOp(groupName, members, groupIndex));
    f.whenCompleteAsync((group, t) -> {
        if (t == null) {
            resultFuture.complete((RaftGroupId) group.id());
            triggerRaftNodeCreation(group);
        } else {
            if (t instanceof CannotCreateRaftGroupException) {
                logger.fine("Could not create CP group: " + groupName + " with members: " + members + " and group index: " + groupIndex, t.getCause());
                invokeGetMembersToCreateRaftGroup(groupName, groupSize, resultFuture);
                return;
            }
            resultFuture.completeExceptionally(t);
        }
    });
}
Also used : CannotCreateRaftGroupException(com.hazelcast.cp.internal.exception.CannotCreateRaftGroupException) CreateRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.CreateRaftGroupOp)

Example 2 with CreateRaftGroupOp

use of com.hazelcast.cp.internal.raftop.metadata.CreateRaftGroupOp in project hazelcast by hazelcast.

the class MetadataRaftGroupTest method when_raftGroupIsCreated_onNonMetadataMembers_thenLeaderShouldBeElected.

@Test
public void when_raftGroupIsCreated_onNonMetadataMembers_thenLeaderShouldBeElected() throws ExecutionException, InterruptedException {
    int metadataGroupSize = 3;
    int otherRaftGroupSize = 2;
    instances = newInstances(metadataGroupSize + otherRaftGroupSize, metadataGroupSize, 0);
    HazelcastInstance leaderInstance = getLeaderInstance(instances, getMetadataGroupId(instances[0]));
    RaftService raftService = getRaftService(leaderInstance);
    Collection<CPMemberInfo> allEndpoints = raftService.getMetadataGroupManager().getActiveMembers();
    assertTrueEventually(() -> assertNotNull(raftService.getMetadataGroupManager().getGroup(getMetadataGroupId(leaderInstance))));
    CPGroup metadataGroup = raftService.getMetadataGroupManager().getGroup(getMetadataGroupId(leaderInstance));
    Collection<CPMemberInfo> endpoints = new HashSet<>(otherRaftGroupSize);
    for (CPMemberInfo endpoint : allEndpoints) {
        if (!metadataGroup.members().contains(endpoint)) {
            endpoints.add(endpoint);
        }
    }
    assertEquals(otherRaftGroupSize, endpoints.size());
    List<RaftEndpoint> groupEndpoints = new ArrayList<>();
    for (CPMemberInfo member : endpoints) {
        groupEndpoints.add(member.toRaftEndpoint());
    }
    RaftOp op = new CreateRaftGroupOp("test", groupEndpoints, RandomPicker.getInt(Integer.MAX_VALUE));
    InternalCompletableFuture<CPGroupSummary> f = raftService.getInvocationManager().invoke(getMetadataGroupId(leaderInstance), op);
    f.whenCompleteAsync((group, t) -> {
        if (t == null) {
            raftService.getInvocationManager().triggerRaftNodeCreation(group);
        }
    });
    CPGroupId groupId = f.get().id();
    for (HazelcastInstance instance : instances) {
        if (endpoints.contains(instance.getCPSubsystem().getLocalCPMember())) {
            assertTrueEventually(() -> {
                RaftNodeImpl raftNode = getRaftNode(instance, groupId);
                assertNotNull(raftNode);
                assertNotNull("Leader is null on " + raftNode, getLeaderMember(raftNode));
            });
        }
    }
}
Also used : RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) ArrayList(java.util.ArrayList) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CreateRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.CreateRaftGroupOp) HashSet(java.util.HashSet) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

CreateRaftGroupOp (com.hazelcast.cp.internal.raftop.metadata.CreateRaftGroupOp)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 CPGroup (com.hazelcast.cp.CPGroup)1 CPGroupId (com.hazelcast.cp.CPGroupId)1 CannotCreateRaftGroupException (com.hazelcast.cp.internal.exception.CannotCreateRaftGroupException)1 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)1 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1