Search in sources :

Example 11 with MemberGroup

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

Example 12 with MemberGroup

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

the class MemberGroupFactoryTest method testConfigMemberGroupFactoryCreateMemberGroups.

/**
 * When there is a matching {@link MemberGroupConfig} for a {@link Member}, it will be assigned to a {@link MemberGroup}.
 * <p>
 * In this test all members will have a matching configuration, so there will be 4 groups with 2 members each.
 */
@Test
public void testConfigMemberGroupFactoryCreateMemberGroups() {
    Collection<Member> members = createMembers();
    Collection<MemberGroupConfig> groupConfigs = createMemberGroupConfigs(true);
    MemberGroupFactory groupFactory = new ConfigMemberGroupFactory(groupConfigs);
    Collection<MemberGroup> memberGroups = groupFactory.createMemberGroups(members);
    assertEquals("Member Groups: " + String.valueOf(memberGroups), 4, memberGroups.size());
    for (MemberGroup memberGroup : memberGroups) {
        assertEquals("Member Group: " + String.valueOf(memberGroup), 2, memberGroup.size());
    }
}
Also used : MemberGroup(com.hazelcast.spi.partitiongroup.MemberGroup) Member(com.hazelcast.cluster.Member) MemberGroupConfig(com.hazelcast.config.MemberGroupConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 13 with MemberGroup

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

the class MemberGroupFactoryTest method testPlacementMetadataAwareMemberGroupFactoryCreateMemberGroups.

@Test
public void testPlacementMetadataAwareMemberGroupFactoryCreateMemberGroups() {
    MemberGroupFactory groupFactory = new PlacementAwareMemberGroupFactory();
    Collection<Member> members = createMembersWithPlacementAwareMetadata();
    Collection<MemberGroup> memberGroups = groupFactory.createMemberGroups(members);
    assertEquals("Member Groups: " + memberGroups, 3, memberGroups.size());
    for (MemberGroup memberGroup : memberGroups) {
        assertEquals("Member Group: " + memberGroup, 1, memberGroup.size());
    }
}
Also used : MemberGroup(com.hazelcast.spi.partitiongroup.MemberGroup) Member(com.hazelcast.cluster.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with MemberGroup

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

the class PartitionStateManager method initializePartitionAssignments.

/**
 * Arranges the partitions if:
 * <ul>
 * <li>this instance {@link NodeExtension#isStartCompleted()}</li>
 * <li>the cluster state allows migrations. See {@link ClusterState#isMigrationAllowed()}</li>
 * </ul>
 * This will also set the manager state to initialized (if not already) and invoke the
 * {@link DefaultPartitionReplicaInterceptor} for all changed replicas which
 * will cancel replica synchronizations and increase the partition state version.
 *
 * @param excludedMembers members which are to be excluded from the new layout
 * @return if the new partition was assigned
 * @throws HazelcastException if the partition state generator failed to arrange the partitions
 */
boolean initializePartitionAssignments(Set<Member> excludedMembers) {
    if (!isPartitionAssignmentAllowed()) {
        return false;
    }
    Collection<MemberGroup> memberGroups = createMemberGroups(excludedMembers);
    if (memberGroups.isEmpty()) {
        logger.warning("No member group is available to assign partition ownership...");
        return false;
    }
    logger.info("Initializing cluster partition table arrangement...");
    PartitionReplica[][] newState = partitionStateGenerator.arrange(memberGroups, partitions);
    if (newState.length != partitionCount) {
        throw new HazelcastException("Invalid partition count! " + "Expected: " + partitionCount + ", Actual: " + newState.length);
    }
    for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
        InternalPartitionImpl partition = partitions[partitionId];
        PartitionReplica[] replicas = newState[partitionId];
        partition.setReplicas(replicas);
    }
    ClusterState clusterState = node.getClusterService().getClusterState();
    if (!clusterState.isMigrationAllowed()) {
        // cluster state is either changed or locked, reset state back and fail.
        reset();
        logger.warning("Partitions can't be assigned since cluster-state= " + clusterState);
        return false;
    }
    setInitialized();
    return true;
}
Also used : MemberGroup(com.hazelcast.spi.partitiongroup.MemberGroup) ClusterState(com.hazelcast.cluster.ClusterState) HazelcastException(com.hazelcast.core.HazelcastException) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica)

Example 15 with MemberGroup

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

the class PartitionStateManager method createMemberGroups.

private Collection<MemberGroup> createMemberGroups(final Set<Member> excludedMembers) {
    MemberSelector exclude = member -> !excludedMembers.contains(member);
    final MemberSelector selector = MemberSelectors.and(DATA_MEMBER_SELECTOR, exclude);
    final Collection<Member> members = node.getClusterService().getMembers(selector);
    return memberGroupFactory.createMemberGroups(members);
}
Also used : Address(com.hazelcast.cluster.Address) NodeExtension(com.hazelcast.instance.impl.NodeExtension) Member(com.hazelcast.cluster.Member) MemberGroupFactoryFactory(com.hazelcast.internal.partition.membergroup.MemberGroupFactoryFactory) PARTITIONS_METRIC_PARTITION_REPLICA_STATE_MANAGER_LOCAL_PARTITION_COUNT(com.hazelcast.internal.metrics.MetricDescriptorConstants.PARTITIONS_METRIC_PARTITION_REPLICA_STATE_MANAGER_LOCAL_PARTITION_COUNT) PARTITIONS_METRIC_PARTITION_REPLICA_STATE_MANAGER_STAMP(com.hazelcast.internal.metrics.MetricDescriptorConstants.PARTITIONS_METRIC_PARTITION_REPLICA_STATE_MANAGER_STAMP) ConcurrentMap(java.util.concurrent.ConcurrentMap) ClusterService(com.hazelcast.internal.cluster.ClusterService) PartitionTableView(com.hazelcast.internal.partition.PartitionTableView) DATA_MEMBER_SELECTOR(com.hazelcast.cluster.memberselector.MemberSelectors.DATA_MEMBER_SELECTOR) ILogger(com.hazelcast.logging.ILogger) PARTITIONS_METRIC_PARTITION_REPLICA_STATE_MANAGER_PARTITION_COUNT(com.hazelcast.internal.metrics.MetricDescriptorConstants.PARTITIONS_METRIC_PARTITION_REPLICA_STATE_MANAGER_PARTITION_COUNT) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) MemberGroup(com.hazelcast.spi.partitiongroup.MemberGroup) HazelcastException(com.hazelcast.core.HazelcastException) PartitionReplicaInterceptor(com.hazelcast.internal.partition.PartitionReplicaInterceptor) InternalPartition(com.hazelcast.internal.partition.InternalPartition) Probe(com.hazelcast.internal.metrics.Probe) Collection(java.util.Collection) MemberGroupFactory(com.hazelcast.internal.partition.membergroup.MemberGroupFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PARTITIONS_METRIC_PARTITION_REPLICA_STATE_MANAGER_ACTIVE_PARTITION_COUNT(com.hazelcast.internal.metrics.MetricDescriptorConstants.PARTITIONS_METRIC_PARTITION_REPLICA_STATE_MANAGER_ACTIVE_PARTITION_COUNT) Set(java.util.Set) UUID(java.util.UUID) PARTITIONS_METRIC_PARTITION_REPLICA_STATE_MANAGER_MEMBER_GROUP_SIZE(com.hazelcast.internal.metrics.MetricDescriptorConstants.PARTITIONS_METRIC_PARTITION_REPLICA_STATE_MANAGER_MEMBER_GROUP_SIZE) ReadonlyInternalPartition(com.hazelcast.internal.partition.ReadonlyInternalPartition) Node(com.hazelcast.instance.impl.Node) MemberSelector(com.hazelcast.cluster.MemberSelector) ClusterState(com.hazelcast.cluster.ClusterState) MemberSelectors(com.hazelcast.cluster.memberselector.MemberSelectors) PartitionStateGenerator(com.hazelcast.internal.partition.PartitionStateGenerator) Collections(java.util.Collections) PartitionStampUtil.calculateStamp(com.hazelcast.internal.partition.PartitionStampUtil.calculateStamp) MemberSelector(com.hazelcast.cluster.MemberSelector) 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