Search in sources :

Example 6 with MemberGroup

use of com.hazelcast.spi.partitiongroup.MemberGroup in project hazelcast by hazelcast.

the class ConfigMemberGroupFactory method createInternalMemberGroups.

@Override
protected Set<MemberGroup> createInternalMemberGroups(Collection<? extends Member> members) {
    Map<Integer, MemberGroup> memberGroups = new HashMap<Integer, MemberGroup>();
    for (Member member : members) {
        String host = ((MemberImpl) member).getAddress().getHost();
        for (Entry<Integer, MemberGroupConfig> entry : memberGroupConfigMap.entrySet()) {
            Collection<String> interfaces = entry.getValue().getInterfaces();
            boolean match;
            if (AddressUtil.isIpAddress(host)) {
                match = AddressUtil.matchAnyInterface(host, interfaces);
            } else {
                match = AddressUtil.matchAnyDomain(host, interfaces);
            }
            if (match) {
                MemberGroup group = memberGroups.get(entry.getKey());
                if (group == null) {
                    group = new DefaultMemberGroup();
                    memberGroups.put(entry.getKey(), group);
                }
                group.addMember(member);
                break;
            }
        }
    }
    return new HashSet<MemberGroup>(memberGroups.values());
}
Also used : MemberGroup(com.hazelcast.spi.partitiongroup.MemberGroup) MapUtil.createLinkedHashMap(com.hazelcast.internal.util.MapUtil.createLinkedHashMap) HashMap(java.util.HashMap) Member(com.hazelcast.cluster.Member) MemberGroupConfig(com.hazelcast.config.MemberGroupConfig) HashSet(java.util.HashSet)

Example 7 with MemberGroup

use of com.hazelcast.spi.partitiongroup.MemberGroup in project hazelcast by hazelcast.

the class NodeAwareMemberGroupFactory method createInternalMemberGroups.

@Override
protected Set<MemberGroup> createInternalMemberGroups(Collection<? extends Member> allMembers) {
    Map<String, MemberGroup> groups = createHashMap(allMembers.size());
    for (Member member : allMembers) {
        final String nodeInfo = member.getAttribute(PartitionGroupMetaData.PARTITION_GROUP_NODE);
        if (nodeInfo == null) {
            throw new IllegalArgumentException("Not enough metadata information is provided. " + "Node name information must be provided with NODE_AWARE partition group.");
        }
        MemberGroup group = groups.get(nodeInfo);
        if (group == null) {
            group = new DefaultMemberGroup();
            groups.put(nodeInfo, group);
        }
        group.addMember(member);
    }
    return new HashSet<>(groups.values());
}
Also used : MemberGroup(com.hazelcast.spi.partitiongroup.MemberGroup) Member(com.hazelcast.cluster.Member) HashSet(java.util.HashSet)

Example 8 with MemberGroup

use of com.hazelcast.spi.partitiongroup.MemberGroup in project hazelcast by hazelcast.

the class DiscoverySpiTest method testSPIAwareMemberGroupFactoryCreateMemberGroups.

@Test
public void testSPIAwareMemberGroupFactoryCreateMemberGroups() throws Exception {
    String xmlFileName = "test-hazelcast-discovery-spi-metadata.xml";
    Config config = getDiscoverySPIConfig(xmlFileName, false);
    // we create this instance in order to fully create Node
    HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
    Node node = getNode(hazelcastInstance);
    assertNotNull(node);
    MemberGroupFactory groupFactory = new SPIAwareMemberGroupFactory(node.getDiscoveryService());
    Collection<Member> members = createMembers();
    Collection<MemberGroup> memberGroups = groupFactory.createMemberGroups(members);
    assertEquals("Member Groups: " + String.valueOf(memberGroups), 2, memberGroups.size());
    for (MemberGroup memberGroup : memberGroups) {
        assertEquals("Member Group: " + String.valueOf(memberGroup), 2, memberGroup.size());
    }
    hazelcastInstance.shutdown();
}
Also used : MemberGroup(com.hazelcast.spi.partitiongroup.MemberGroup) DefaultMemberGroup(com.hazelcast.internal.partition.membergroup.DefaultMemberGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AwsConfig(com.hazelcast.config.AwsConfig) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) MulticastConfig(com.hazelcast.config.MulticastConfig) JoinConfig(com.hazelcast.config.JoinConfig) Config(com.hazelcast.config.Config) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) InterfacesConfig(com.hazelcast.config.InterfacesConfig) Node(com.hazelcast.instance.impl.Node) Accessors.getNode(com.hazelcast.test.Accessors.getNode) SPIAwareMemberGroupFactory(com.hazelcast.internal.partition.membergroup.SPIAwareMemberGroupFactory) Member(com.hazelcast.cluster.Member) SPIAwareMemberGroupFactory(com.hazelcast.internal.partition.membergroup.SPIAwareMemberGroupFactory) MemberGroupFactory(com.hazelcast.internal.partition.membergroup.MemberGroupFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with MemberGroup

use of com.hazelcast.spi.partitiongroup.MemberGroup 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 10 with MemberGroup

use of com.hazelcast.spi.partitiongroup.MemberGroup 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)

Aggregations

MemberGroup (com.hazelcast.spi.partitiongroup.MemberGroup)23 Member (com.hazelcast.cluster.Member)20 QuickTest (com.hazelcast.test.annotation.QuickTest)10 Test (org.junit.Test)10 DefaultMemberGroup (com.hazelcast.internal.partition.membergroup.DefaultMemberGroup)6 MemberGroupFactory (com.hazelcast.internal.partition.membergroup.MemberGroupFactory)5 HashSet (java.util.HashSet)5 PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)4 Address (com.hazelcast.cluster.Address)3 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)3 MemberGroupConfig (com.hazelcast.config.MemberGroupConfig)3 Node (com.hazelcast.instance.impl.Node)3 Collection (java.util.Collection)3 ClusterState (com.hazelcast.cluster.ClusterState)2 AwsConfig (com.hazelcast.config.AwsConfig)2 Config (com.hazelcast.config.Config)2 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)2 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)2 InterfacesConfig (com.hazelcast.config.InterfacesConfig)2 JoinConfig (com.hazelcast.config.JoinConfig)2