Search in sources :

Example 51 with MemberImpl

use of com.hazelcast.cluster.impl.MemberImpl in project hazelcast by hazelcast.

the class PartitionStateGeneratorTest method checkTestResult.

private void checkTestResult(PartitionReplica[][] state, Collection<MemberGroup> groups, int partitionCount) {
    Iterator<MemberGroup> iter = groups.iterator();
    while (iter.hasNext()) {
        if (iter.next().size() == 0) {
            iter.remove();
        }
    }
    int replicaCount = Math.min(groups.size(), InternalPartition.MAX_REPLICA_COUNT);
    Map<MemberGroup, GroupPartitionState> groupPartitionStates = new HashMap<MemberGroup, GroupPartitionState>();
    Set<PartitionReplica> set = new HashSet<PartitionReplica>();
    int avgPartitionPerGroup = partitionCount / groups.size();
    for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
        PartitionReplica[] replicas = state[partitionId];
        for (int i = 0; i < replicaCount; i++) {
            PartitionReplica owner = replicas[i];
            assertNotNull(owner);
            assertFalse("Duplicate owner of partition: " + partitionId, set.contains(owner));
            set.add(owner);
            MemberGroup group = null;
            for (MemberGroup g : groups) {
                if (g.hasMember(new MemberImpl(owner.address(), VERSION, true, owner.uuid()))) {
                    group = g;
                    break;
                }
            }
            assertNotNull(group);
            GroupPartitionState groupState = groupPartitionStates.get(group);
            if (groupState == null) {
                groupState = new GroupPartitionState();
                groupState.group = group;
                groupPartitionStates.put(group, groupState);
            }
            groupState.groupPartitions[i].add(partitionId);
            groupState.getNodePartitions(owner)[i].add(partitionId);
        }
        set.clear();
    }
    for (GroupPartitionState groupState : groupPartitionStates.values()) {
        for (Map.Entry<PartitionReplica, Set<Integer>[]> entry : groupState.nodePartitionsMap.entrySet()) {
            Collection<Integer>[] partitions = entry.getValue();
            for (int i = 0; i < replicaCount; i++) {
                int avgPartitionPerNode = groupState.groupPartitions[i].size() / groupState.nodePartitionsMap.size();
                int count = partitions[i].size();
                isInAllowedRange(count, avgPartitionPerNode, i, entry.getKey(), groups, partitionCount);
            }
        }
        Collection<Integer>[] partitions = groupState.groupPartitions;
        for (int i = 0; i < replicaCount; i++) {
            int count = partitions[i].size();
            isInAllowedRange(count, avgPartitionPerGroup, i, groupState.group, groups, partitionCount);
        }
    }
    printTable(groupPartitionStates, replicaCount);
}
Also used : HashMap(java.util.HashMap) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) MemberGroup(com.hazelcast.spi.partitiongroup.MemberGroup) DefaultMemberGroup(com.hazelcast.internal.partition.membergroup.DefaultMemberGroup) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 52 with MemberImpl

use of com.hazelcast.cluster.impl.MemberImpl 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 53 with MemberImpl

use of com.hazelcast.cluster.impl.MemberImpl in project hazelcast by hazelcast.

the class PartitionStateGeneratorTest method createMembers.

private static List<Member> createMembers(MemberImpl startAfter, int memberCount, int maxSameHostCount) throws Exception {
    Random rand = new Random();
    final byte[] ip = new byte[] { 10, 10, 0, 0 };
    if (startAfter != null) {
        Address address = startAfter.getAddress();
        byte[] startIp = address.getInetAddress().getAddress();
        if ((0xff & startIp[3]) < 255) {
            ip[2] = startIp[2];
            ip[3] = (byte) (startIp[3] + 1);
        } else {
            ip[2] = (byte) (startIp[2] + 1);
            ip[3] = 0;
        }
    }
    int count = 0;
    int port = 5700;
    List<Member> members = new ArrayList<Member>();
    int sameHostCount = rand.nextInt(maxSameHostCount) + 1;
    for (int i = 0; i < memberCount; i++) {
        if (count == sameHostCount) {
            ip[3] = ++ip[3];
            count = 0;
            port = 5700;
            sameHostCount = rand.nextInt(maxSameHostCount) + 1;
        }
        count++;
        port++;
        MemberImpl m = new MemberImpl(new Address(InetAddress.getByAddress(new byte[] { ip[0], ip[1], ip[2], ip[3] }), port), VERSION, false, UuidUtil.newUnsecureUUID());
        members.add(m);
        if ((0xff & ip[3]) == 255) {
            ip[2] = ++ip[2];
        }
    }
    return members;
}
Also used : Random(java.util.Random) Address(com.hazelcast.cluster.Address) InetAddress(java.net.InetAddress) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) ArrayList(java.util.ArrayList) Member(com.hazelcast.cluster.Member)

Example 54 with MemberImpl

use of com.hazelcast.cluster.impl.MemberImpl in project hazelcast by hazelcast.

the class MemberGroupFactoryTest method createMembersWithNoMetadata.

private Collection<Member> createMembersWithNoMetadata() {
    Collection<Member> members = new HashSet<Member>();
    members.add(new MemberImpl(new Address("192.192.0.1", fakeAddress, 5701), VERSION, false));
    members.add(new MemberImpl(new Address("192.192.0.1", fakeAddress, 5702), VERSION, false));
    members.add(new MemberImpl(new Address("192.168.3.101", fakeAddress, 5701), VERSION, false));
    return members;
}
Also used : Address(com.hazelcast.cluster.Address) InetAddress(java.net.InetAddress) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) Member(com.hazelcast.cluster.Member) HashSet(java.util.HashSet)

Example 55 with MemberImpl

use of com.hazelcast.cluster.impl.MemberImpl in project hazelcast by hazelcast.

the class MemberGroupFactoryTest method createMembersWithNodeAwareMetadata.

private Collection<Member> createMembersWithNodeAwareMetadata() {
    Collection<Member> members = new HashSet<Member>();
    MemberImpl member1 = new MemberImpl(new Address("192.192.0.1", fakeAddress, 5701), VERSION, true);
    member1.setAttribute(PartitionGroupMetaData.PARTITION_GROUP_NODE, "kubernetes-node-f0bbd602-f7cw");
    MemberImpl member2 = new MemberImpl(new Address("192.192.0.2", fakeAddress, 5701), VERSION, true);
    member2.setAttribute(PartitionGroupMetaData.PARTITION_GROUP_NODE, "kubernetes-node-f0bbd602-hgdl");
    MemberImpl member3 = new MemberImpl(new Address("192.192.0.3", fakeAddress, 5701), VERSION, true);
    member3.setAttribute(PartitionGroupMetaData.PARTITION_GROUP_NODE, "kubernetes-node-f0bbd602-0zjs");
    members.add(member1);
    members.add(member2);
    members.add(member3);
    return members;
}
Also used : Address(com.hazelcast.cluster.Address) InetAddress(java.net.InetAddress) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) Member(com.hazelcast.cluster.Member) HashSet(java.util.HashSet)

Aggregations

MemberImpl (com.hazelcast.cluster.impl.MemberImpl)123 Address (com.hazelcast.cluster.Address)41 Test (org.junit.Test)37 QuickTest (com.hazelcast.test.annotation.QuickTest)34 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)32 Member (com.hazelcast.cluster.Member)21 HazelcastInstance (com.hazelcast.core.HazelcastInstance)16 UUID (java.util.UUID)14 ArrayList (java.util.ArrayList)10 MemberInfo (com.hazelcast.internal.cluster.MemberInfo)9 HashMap (java.util.HashMap)9 InetAddress (java.net.InetAddress)8 HashSet (java.util.HashSet)8 ClusterService (com.hazelcast.internal.cluster.ClusterService)7 Config (com.hazelcast.config.Config)6 Future (java.util.concurrent.Future)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 StaticMemberNodeContext (com.hazelcast.instance.StaticMemberNodeContext)4 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)4 MembersUpdateOp (com.hazelcast.internal.cluster.impl.operations.MembersUpdateOp)4