Search in sources :

Example 1 with PartitionStateGenerator

use of com.hazelcast.internal.partition.PartitionStateGenerator in project hazelcast by hazelcast.

the class PartitionStateGeneratorTest method test.

private void test(MemberGroupFactory memberGroupFactory) throws Exception {
    PartitionStateGenerator generator = new PartitionStateGeneratorImpl();
    int maxSameHostCount = 3;
    int[] partitionCounts = new int[] { 271, 787, 1549, 3217 };
    int[] members = new int[] { 3, 6, 9, 10, 11, 17, 57, 100, 130, 77, 179, 93, 37, 26, 15, 5 };
    for (int partitionCount : partitionCounts) {
        int memberCount = members[0];
        List<Member> memberList = createMembers(memberCount, maxSameHostCount);
        Collection<MemberGroup> groups = memberGroupFactory.createMemberGroups(memberList);
        PartitionReplica[][] state = generator.arrange(groups, emptyPartitionArray(partitionCount));
        checkTestResult(state, groups, partitionCount);
        int previousMemberCount = memberCount;
        for (int j = 1; j < members.length; j++) {
            memberCount = members[j];
            if (partitionCount / memberCount < 10) {
                break;
            }
            if ((float) partitionCount / memberCount > 2) {
                if (previousMemberCount == 0) {
                    memberList = createMembers(memberCount, maxSameHostCount);
                } else if (memberCount > previousMemberCount) {
                    MemberImpl last = (MemberImpl) memberList.get(previousMemberCount - 1);
                    List<Member> extra = createMembers(last, (memberCount - previousMemberCount), maxSameHostCount);
                    memberList.addAll(extra);
                } else {
                    List<Member> removedMembers = memberList.subList(memberCount, memberList.size());
                    memberList = memberList.subList(0, memberCount);
                    remove(state, removedMembers);
                }
                groups = memberGroupFactory.createMemberGroups(memberList);
                state = generator.arrange(groups, toPartitionArray(state));
                checkTestResult(state, groups, partitionCount);
                previousMemberCount = memberCount;
            }
        }
    }
}
Also used : MemberGroup(com.hazelcast.spi.partitiongroup.MemberGroup) DefaultMemberGroup(com.hazelcast.internal.partition.membergroup.DefaultMemberGroup) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) PartitionStateGenerator(com.hazelcast.internal.partition.PartitionStateGenerator) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Member(com.hazelcast.cluster.Member)

Example 2 with PartitionStateGenerator

use of com.hazelcast.internal.partition.PartitionStateGenerator in project hazelcast by hazelcast.

the class PartitionStateGeneratorTest method testOnlyUnassignedArrangement.

@Test
public void testOnlyUnassignedArrangement() throws Exception {
    List<Member> memberList = createMembers(10, 1);
    MemberGroupFactory memberGroupFactory = new SingleMemberGroupFactory();
    Collection<MemberGroup> groups = memberGroupFactory.createMemberGroups(memberList);
    PartitionStateGenerator generator = new PartitionStateGeneratorImpl();
    PartitionReplica[][] state = generator.arrange(groups, emptyPartitionArray(100));
    // unassign some partitions entirely
    Collection<Integer> unassignedPartitions = new ArrayList<Integer>();
    for (int i = 0; i < state.length; i++) {
        if (i % 3 == 0) {
            state[i] = new PartitionReplica[InternalPartition.MAX_REPLICA_COUNT];
            unassignedPartitions.add(i);
        }
    }
    // unassign only backup replicas of some partitions
    for (int i = 0; i < state.length; i++) {
        if (i % 10 == 0) {
            Arrays.fill(state[i], 1, InternalPartition.MAX_REPLICA_COUNT, null);
        }
    }
    InternalPartition[] partitions = toPartitionArray(state);
    state = generator.arrange(groups, partitions, unassignedPartitions);
    for (int pid = 0; pid < state.length; pid++) {
        PartitionReplica[] addresses = state[pid];
        if (unassignedPartitions.contains(pid)) {
            for (PartitionReplica address : addresses) {
                assertNotNull(address);
            }
        } else {
            InternalPartition partition = partitions[pid];
            for (int replicaIx = 0; replicaIx < InternalPartition.MAX_REPLICA_COUNT; replicaIx++) {
                assertEquals(partition.getReplica(replicaIx), addresses[replicaIx]);
            }
        }
    }
}
Also used : PartitionStateGenerator(com.hazelcast.internal.partition.PartitionStateGenerator) ArrayList(java.util.ArrayList) InternalPartition(com.hazelcast.internal.partition.InternalPartition) ReadonlyInternalPartition(com.hazelcast.internal.partition.ReadonlyInternalPartition) MemberGroup(com.hazelcast.spi.partitiongroup.MemberGroup) DefaultMemberGroup(com.hazelcast.internal.partition.membergroup.DefaultMemberGroup) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) SingleMemberGroupFactory(com.hazelcast.internal.partition.membergroup.SingleMemberGroupFactory) Member(com.hazelcast.cluster.Member) ConfigMemberGroupFactory(com.hazelcast.internal.partition.membergroup.ConfigMemberGroupFactory) HostAwareMemberGroupFactory(com.hazelcast.internal.partition.membergroup.HostAwareMemberGroupFactory) SingleMemberGroupFactory(com.hazelcast.internal.partition.membergroup.SingleMemberGroupFactory) MemberGroupFactory(com.hazelcast.internal.partition.membergroup.MemberGroupFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Member (com.hazelcast.cluster.Member)2 PartitionStateGenerator (com.hazelcast.internal.partition.PartitionStateGenerator)2 DefaultMemberGroup (com.hazelcast.internal.partition.membergroup.DefaultMemberGroup)2 MemberGroup (com.hazelcast.spi.partitiongroup.MemberGroup)2 ArrayList (java.util.ArrayList)2 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)1 InternalPartition (com.hazelcast.internal.partition.InternalPartition)1 PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)1 ReadonlyInternalPartition (com.hazelcast.internal.partition.ReadonlyInternalPartition)1 ConfigMemberGroupFactory (com.hazelcast.internal.partition.membergroup.ConfigMemberGroupFactory)1 HostAwareMemberGroupFactory (com.hazelcast.internal.partition.membergroup.HostAwareMemberGroupFactory)1 MemberGroupFactory (com.hazelcast.internal.partition.membergroup.MemberGroupFactory)1 SingleMemberGroupFactory (com.hazelcast.internal.partition.membergroup.SingleMemberGroupFactory)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Test (org.junit.Test)1