Search in sources :

Example 1 with MemberGroup

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

the class PartitionStateGeneratorImpl method createNodeGroups.

private Queue<NodeGroup> createNodeGroups(Collection<MemberGroup> memberGroups) {
    Queue<NodeGroup> nodeGroups = new LinkedList<>();
    if (memberGroups == null || memberGroups.isEmpty()) {
        return nodeGroups;
    }
    for (MemberGroup memberGroup : memberGroups) {
        NodeGroup nodeGroup;
        if (memberGroup.size() == 0) {
            continue;
        }
        if (memberGroup instanceof SingleMemberGroup || memberGroup.size() == 1) {
            nodeGroup = new SingleNodeGroup();
            Member next = memberGroup.iterator().next();
            nodeGroup.addNode(PartitionReplica.from(next));
        } else {
            nodeGroup = new DefaultNodeGroup();
            Iterator<Member> iter = memberGroup.iterator();
            while (iter.hasNext()) {
                Member next = iter.next();
                nodeGroup.addNode(PartitionReplica.from(next));
            }
        }
        nodeGroups.add(nodeGroup);
    }
    return nodeGroups;
}
Also used : MemberGroup(com.hazelcast.spi.partitiongroup.MemberGroup) SingleMemberGroup(com.hazelcast.internal.partition.membergroup.SingleMemberGroup) SingleMemberGroup(com.hazelcast.internal.partition.membergroup.SingleMemberGroup) Member(com.hazelcast.cluster.Member) LinkedList(java.util.LinkedList)

Example 2 with MemberGroup

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

the class PlacementAwareMemberGroupFactory method createInternalMemberGroups.

@Override
protected Set<MemberGroup> createInternalMemberGroups(Collection<? extends Member> allMembers) {
    Map<String, MemberGroup> groups = createHashMap(allMembers.size());
    for (Member member : allMembers) {
        String placementInfo = member.getAttribute(PartitionGroupMetaData.PARTITION_GROUP_PLACEMENT);
        if (placementInfo == null) {
            throw new IllegalArgumentException("Not enough metadata information is provided. " + "A group name indicating the placement group must be provided with " + "PLACEMENT_AWARE partition group.");
        }
        MemberGroup group = groups.get(placementInfo);
        if (group == null) {
            group = new DefaultMemberGroup();
            groups.put(placementInfo, 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 3 with MemberGroup

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

the class ZoneAwareMemberGroupFactory method createInternalMemberGroups.

@Override
protected Set<MemberGroup> createInternalMemberGroups(Collection<? extends Member> allMembers) {
    Map<String, MemberGroup> groups = createHashMap(allMembers.size());
    for (Member member : allMembers) {
        final String zoneInfo = member.getAttribute(PartitionGroupMetaData.PARTITION_GROUP_ZONE);
        if (zoneInfo == null) {
            throw new IllegalArgumentException("Not enough metadata information is provided. " + "Availability zone information must be provided with ZONE_AWARE partition group.");
        }
        MemberGroup group = groups.get(zoneInfo);
        if (group == null) {
            group = new DefaultMemberGroup();
            groups.put(zoneInfo, 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 4 with MemberGroup

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

the class PartitionStateManager method updateMemberGroupsSize.

void updateMemberGroupsSize() {
    final Collection<MemberGroup> groups = createMemberGroups();
    int size = 0;
    for (MemberGroup group : groups) {
        if (group.size() > 0) {
            size++;
        }
    }
    memberGroupsSize = size;
}
Also used : MemberGroup(com.hazelcast.spi.partitiongroup.MemberGroup)

Example 5 with MemberGroup

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

the class BackupSafeMemberGroupFactory method createMemberGroups.

@Override
public final Collection<MemberGroup> createMemberGroups(Collection<? extends Member> members) {
    Collection<MemberGroup> groups = createInternalMemberGroups(members);
    if (groups.size() == 1 && members.size() > 1) {
        // If there are more than one members and just one group
        // then split members into two groups to guarantee at least the first backup.
        MemberGroup group1 = groups.iterator().next();
        MemberGroup group2 = new DefaultMemberGroup();
        int sizePerGroup = group1.size() / 2;
        Iterator<Member> iter = group1.iterator();
        while (group2.size() < sizePerGroup && iter.hasNext()) {
            group2.addMember(iter.next());
            iter.remove();
        }
        groups.add(group2);
    }
    return groups;
}
Also used : MemberGroup(com.hazelcast.spi.partitiongroup.MemberGroup) 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