Search in sources :

Example 41 with CPMember

use of com.hazelcast.cp.CPMember in project hazelcast by hazelcast.

the class TimedMemberStateFactory method createMemberState.

private void createMemberState(MemberStateImpl memberState, Collection<StatisticsAwareService> services) {
    Node node = instance.node;
    final Collection<Client> clients = instance.node.clientEngine.getClients();
    final Set<ClientEndPointDTO> serializableClientEndPoints = createHashSet(clients.size());
    for (Client client : clients) {
        serializableClientEndPoints.add(new ClientEndPointDTO(client));
    }
    memberState.setClients(serializableClientEndPoints);
    memberState.setName(instance.getName());
    memberState.setUuid(node.getThisUuid());
    if (instance.getConfig().getCPSubsystemConfig().getCPMemberCount() == 0) {
        memberState.setCpMemberUuid(null);
    } else {
        CPMember localCPMember = instance.getCPSubsystem().getLocalCPMember();
        memberState.setCpMemberUuid(localCPMember != null ? localCPMember.getUuid() : null);
    }
    Address thisAddress = node.getThisAddress();
    memberState.setAddress(thisAddress.getHost() + ":" + thisAddress.getPort());
    memberState.setEndpoints(node.getLocalMember().getAddressMap());
    MemberPartitionStateImpl memberPartitionState = (MemberPartitionStateImpl) memberState.getMemberPartitionState();
    InternalPartitionService partitionService = node.getPartitionService();
    IPartition[] partitions = partitionService.getPartitions();
    List<Integer> partitionList = memberPartitionState.getPartitions();
    for (IPartition partition : partitions) {
        if (partition.isLocal()) {
            partitionList.add(partition.getPartitionId());
        }
    }
    memberPartitionState.setMemberStateSafe(memberStateSafe);
    memberState.setOperationStats(getOperationStats());
    createMemState(memberState, services);
    createNodeState(memberState);
    createHotRestartState(memberState);
    createClusterHotRestartStatus(memberState);
    memberState.setClientStats(getClientAttributes(node.getClientEngine().getClientStatistics()));
}
Also used : Address(com.hazelcast.cluster.Address) ClientEndPointDTO(com.hazelcast.internal.management.dto.ClientEndPointDTO) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Node(com.hazelcast.instance.impl.Node) CPMember(com.hazelcast.cp.CPMember) MemberPartitionStateImpl(com.hazelcast.internal.monitor.impl.MemberPartitionStateImpl) Client(com.hazelcast.client.Client) IPartition(com.hazelcast.internal.partition.IPartition)

Example 42 with CPMember

use of com.hazelcast.cp.CPMember in project hazelcast by hazelcast.

the class CPGroupRebalanceTest method test.

@Test
public void test() throws Exception {
    int groupSize = 5;
    int leadershipsPerMember = 10;
    int groupCount = groupSize * leadershipsPerMember;
    HazelcastInstance[] instances = newInstances(groupSize, groupSize, 0);
    waitUntilCPDiscoveryCompleted(instances);
    Collection<CPGroupId> groupIds = new ArrayList<>(groupCount);
    RaftInvocationManager invocationManager = getRaftInvocationManager(instances[0]);
    for (int i = 0; i < groupCount; i++) {
        RaftGroupId groupId = invocationManager.createRaftGroup("group-" + i).joinInternal();
        groupIds.add(groupId);
    }
    HazelcastInstance metadataLeader = getLeaderInstance(instances, getMetadataGroupId(instances[0]));
    Collection<CPMember> cpMembers = metadataLeader.getCPSubsystem().getCPSubsystemManagementService().getCPMembers().toCompletableFuture().get();
    // Assert eventually since during the test
    // a long pause can cause leadership change unexpectedly.
    assertTrueEventually(() -> {
        // Wait for leader election all groups
        for (CPGroupId groupId : groupIds) {
            waitAllForLeaderElection(instances, groupId);
        }
        rebalanceLeaderships(metadataLeader);
        Map<CPMember, Collection<CPGroupId>> leadershipsMap = getLeadershipsMap(metadataLeader, cpMembers);
        for (Entry<CPMember, Collection<CPGroupId>> entry : leadershipsMap.entrySet()) {
            int count = entry.getValue().size();
            assertEquals(leadershipsString(leadershipsMap), leadershipsPerMember, count);
        }
    });
}
Also used : ArrayList(java.util.ArrayList) CPMember(com.hazelcast.cp.CPMember) CPGroupId(com.hazelcast.cp.CPGroupId) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Collection(java.util.Collection) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 43 with CPMember

use of com.hazelcast.cp.CPMember in project hazelcast by hazelcast.

the class CPMemberAddRemoveTest method when_newCPMemberIsAddedToTheMetadataGroupAfterRestart_newMemberCommitsMetadataGroupLogEntries.

@Test
public void when_newCPMemberIsAddedToTheMetadataGroupAfterRestart_newMemberCommitsMetadataGroupLogEntries() throws ExecutionException, InterruptedException {
    int nodeCount = 3;
    Config config = createConfig(nodeCount, nodeCount);
    HazelcastInstance[] instances = new HazelcastInstance[nodeCount];
    for (int i = 0; i < nodeCount; i++) {
        instances[i] = factory.newHazelcastInstance(config);
    }
    RaftGroupId initialMetadataGroupId = getMetadataGroupId(instances[0]);
    assertClusterSizeEventually(nodeCount, instances);
    waitUntilCPDiscoveryCompleted(instances);
    instances[0].getCPSubsystem().getCPSubsystemManagementService().getCPGroup(METADATA_CP_GROUP_NAME).toCompletableFuture().get();
    instances[1].getLifecycleService().terminate();
    instances[2].getLifecycleService().terminate();
    HazelcastInstance newInstance1 = factory.newHazelcastInstance(config);
    HazelcastInstance newInstance2 = factory.newHazelcastInstance(config);
    assertClusterSizeEventually(3, instances[0], newInstance1, newInstance2);
    instances[0].getCPSubsystem().getCPSubsystemManagementService().reset().toCompletableFuture().get();
    RaftGroupId newMetadataGroupId = getRaftService(instances[0]).getMetadataGroupId();
    assertTrue(newMetadataGroupId.getSeed() > initialMetadataGroupId.getSeed());
    assertEquals(newMetadataGroupId.getSeed(), getRaftService(newInstance1).getMetadataGroupId().getSeed());
    assertEquals(newMetadataGroupId.getSeed(), getRaftService(newInstance2).getMetadataGroupId().getSeed());
    instances[0].getCPSubsystem().getAtomicLong("long@group1").set(1);
    instances[0].getCPSubsystem().getAtomicLong("long@group2").set(2);
    instances[0].shutdown();
    HazelcastInstance newInstance3 = factory.newHazelcastInstance(config);
    newInstance3.getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
    CPGroup metadataGroup = newInstance1.getCPSubsystem().getCPSubsystemManagementService().getCPGroup(METADATA_CP_GROUP_NAME).toCompletableFuture().get();
    CPGroup group1 = newInstance1.getCPSubsystem().getCPSubsystemManagementService().getCPGroup("group1").toCompletableFuture().get();
    CPGroup group2 = newInstance1.getCPSubsystem().getCPSubsystemManagementService().getCPGroup("group2").toCompletableFuture().get();
    List<CPMember> cpMembers = new ArrayList<>(newInstance1.getCPSubsystem().getCPSubsystemManagementService().getCPMembers().toCompletableFuture().get());
    HazelcastInstance[] newInstances = new HazelcastInstance[] { newInstance1, newInstance2, newInstance3 };
    assertTrueEventually(() -> {
        long commitIndex = getCommitIndex(getLeaderNode(newInstances, getMetadataGroupId(newInstance1)));
        for (HazelcastInstance instance : Arrays.asList(newInstance1, newInstance2, newInstance3)) {
            assertEquals(newMetadataGroupId.getSeed(), getMetadataGroupId(instance).getSeed());
            RaftNodeImpl raftNode = getRaftNode(instance, getMetadataGroupId(instance));
            assertNotNull(raftNode);
            assertEquals(commitIndex, getCommitIndex(raftNode));
            CPGroup m = queryRaftGroupLocally(instance, metadataGroup.id());
            CPGroup g1 = queryRaftGroupLocally(instance, group1.id());
            CPGroup g2 = queryRaftGroupLocally(instance, group2.id());
            assertNotNull(m);
            assertNotNull(g1);
            assertNotNull(g2);
            assertArrayEquals(metadataGroup.members().toArray(new CPMember[0]), m.members().toArray(new CPMember[0]));
            assertArrayEquals(group1.members().toArray(new CPMember[0]), g1.members().toArray(new CPMember[0]));
            assertArrayEquals(group2.members().toArray(new CPMember[0]), g2.members().toArray(new CPMember[0]));
            List<CPMemberInfo> activeMembers = new ArrayList<>(getRaftService(instance).getMetadataGroupManager().getActiveMembers());
            assertEquals(cpMembers, activeMembers);
        }
    });
}
Also used : RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) TestHazelcastInstanceFactory.initOrCreateConfig(com.hazelcast.test.TestHazelcastInstanceFactory.initOrCreateConfig) Config(com.hazelcast.config.Config) ArrayList(java.util.ArrayList) CPMember(com.hazelcast.cp.CPMember) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 44 with CPMember

use of com.hazelcast.cp.CPMember in project hazelcast by hazelcast.

the class CPMemberAddRemoveTest method testRemoveMemberFromMajorityLostRaftGroup.

@Test
public void testRemoveMemberFromMajorityLostRaftGroup() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = newInstances(3, 3, 0);
    waitAllForLeaderElection(instances, getMetadataGroupId(instances[0]));
    CPGroupId groupId = getRaftInvocationManager(instances[0]).createRaftGroup("test", 2).get();
    getRaftInvocationManager(instances[0]).invoke(groupId, new DummyOp()).get();
    RaftNodeImpl groupLeaderRaftNode = getLeaderNode(instances, groupId);
    CPGroup group = instances[0].getCPSubsystem().getCPSubsystemManagementService().getCPGroup(groupId.getName()).toCompletableFuture().get();
    CPMember[] groupMembers = group.members().toArray(new CPMember[0]);
    CPMember crashedMember = groupMembers[0].getUuid().equals(groupLeaderRaftNode.getLocalMember().getUuid()) ? groupMembers[1] : groupMembers[0];
    HazelcastInstance runningInstance = (getAddress(instances[0])).equals(crashedMember.getAddress()) ? instances[1] : instances[0];
    RaftInvocationManager invocationManager = getRaftInvocationManager(runningInstance);
    factory.getInstance(crashedMember.getAddress()).getLifecycleService().terminate();
    // from now on, "test" group lost the majority
    // we triggered removal of the crashed member but we won't be able to commit to the "test" group
    CompletableFuture<Void> f = runningInstance.getCPSubsystem().getCPSubsystemManagementService().removeCPMember(crashedMember.getUuid()).toCompletableFuture();
    // wait until RaftCleanupHandler kicks in and appends ApplyRaftGroupMembersCmd to the leader of the "test" group
    assertTrueEventually(() -> assertTrue(getLastLogOrSnapshotEntry(groupLeaderRaftNode).operation() instanceof UpdateRaftGroupMembersCmd));
    // force-destroy the raft group.
    // Now, the pending membership change in the "test" group will fail and we will fix it in the metadata group.
    runningInstance.getCPSubsystem().getCPSubsystemManagementService().forceDestroyCPGroup(groupId.getName()).toCompletableFuture().get();
    f.get();
    MembershipChangeSchedule schedule = invocationManager.<MembershipChangeSchedule>query(getMetadataGroupId(runningInstance), new GetMembershipChangeScheduleOp(), LINEARIZABLE).get();
    assertNull(schedule);
}
Also used : RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) GetMembershipChangeScheduleOp(com.hazelcast.cp.internal.raftop.metadata.GetMembershipChangeScheduleOp) CPMember(com.hazelcast.cp.CPMember) CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) UpdateRaftGroupMembersCmd(com.hazelcast.cp.internal.raft.impl.command.UpdateRaftGroupMembersCmd) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 45 with CPMember

use of com.hazelcast.cp.CPMember in project hazelcast by hazelcast.

the class CPMemberAddRemoveTest method testMetadataGroupReinitializationAfterLostMajority.

@Test
public void testMetadataGroupReinitializationAfterLostMajority() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = newInstances(3, 3, 1);
    long groupIdSeed = getRaftService(instances[0]).getMetadataGroupManager().getGroupIdSeed();
    RaftGroupId groupId = getRaftInvocationManager(instances[0]).createRaftGroup(CPGroup.DEFAULT_GROUP_NAME).get();
    IAtomicLong long1 = instances[0].getCPSubsystem().getAtomicLong("proxy");
    sleepAtLeastMillis(10);
    instances[1].getLifecycleService().terminate();
    instances[2].getLifecycleService().terminate();
    assertClusterSizeEventually(2, instances[3]);
    HazelcastInstance[] newInstances = new HazelcastInstance[3];
    newInstances[0] = instances[0];
    newInstances[1] = instances[3];
    Config config = createConfig(3, 3);
    newInstances[2] = factory.newHazelcastInstance(config);
    assertClusterSizeEventually(3, newInstances);
    newInstances[0].getCPSubsystem().getCPSubsystemManagementService().reset().toCompletableFuture().get();
    waitUntilCPDiscoveryCompleted(newInstances);
    long newGroupIdSeed = getRaftService(newInstances[0]).getMetadataGroupManager().getGroupIdSeed();
    RaftGroupId newGroupId = getRaftInvocationManager(instances[0]).createRaftGroup(CPGroup.DEFAULT_GROUP_NAME).get();
    assertThat(newGroupIdSeed, greaterThan(groupIdSeed));
    assertThat(newGroupId.getSeed(), greaterThan(groupId.getSeed()));
    try {
        long1.incrementAndGet();
        fail();
    } catch (CPGroupDestroyedException ignored) {
    }
    IAtomicLong long2 = newInstances[2].getCPSubsystem().getAtomicLong("proxy");
    long2.incrementAndGet();
    assertTrueEventually(() -> {
        CPGroupSummary group = queryRaftGroupLocally(newInstances[2], getMetadataGroupId(newInstances[2]));
        assertNotNull(group);
        Collection<CPMember> endpoints = group.members();
        for (HazelcastInstance instance : newInstances) {
            Member localMember = instance.getCluster().getLocalMember();
            assertThat(new CPMemberInfo(localMember), isIn(endpoints));
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) TestHazelcastInstanceFactory.initOrCreateConfig(com.hazelcast.test.TestHazelcastInstanceFactory.initOrCreateConfig) Config(com.hazelcast.config.Config) CPGroupDestroyedException(com.hazelcast.cp.exception.CPGroupDestroyedException) IAtomicLong(com.hazelcast.cp.IAtomicLong) Member(com.hazelcast.cluster.Member) CPMember(com.hazelcast.cp.CPMember) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

CPMember (com.hazelcast.cp.CPMember)57 HazelcastInstance (com.hazelcast.core.HazelcastInstance)40 Test (org.junit.Test)38 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)27 SlowTest (com.hazelcast.test.annotation.SlowTest)27 CPGroup (com.hazelcast.cp.CPGroup)17 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)16 CPGroupId (com.hazelcast.cp.CPGroupId)14 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)11 QuickTest (com.hazelcast.test.annotation.QuickTest)11 ArrayList (java.util.ArrayList)11 Config (com.hazelcast.config.Config)10 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)10 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)7 GetActiveCPMembersOp (com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp)6 JsonArray (com.hazelcast.internal.json.JsonArray)6 JsonObject (com.hazelcast.internal.json.JsonObject)6 TestHazelcastInstanceFactory.initOrCreateConfig (com.hazelcast.test.TestHazelcastInstanceFactory.initOrCreateConfig)6 CPSubsystemManagementService (com.hazelcast.cp.CPSubsystemManagementService)4 JsonValue (com.hazelcast.internal.json.JsonValue)4