Search in sources :

Example 31 with PartitionReplica

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

the class MigrationCommitServiceTest method testFailedShiftDownMigration.

private void testFailedShiftDownMigration(int partitionId, int replicaIndexToClear, int oldReplicaIndex, int newReplicaIndex) throws Exception {
    PartitionReplica destination = clearReplicaIndex(partitionId, replicaIndexToClear);
    MigrationInfo migration = createShiftDownMigration(partitionId, oldReplicaIndex, newReplicaIndex, destination);
    migrateWithFailure(migration);
    assertMigrationSourceRollback(migration);
    assertMigrationDestinationRollback(migration);
    assertPartitionDataAfterMigrations();
}
Also used : MigrationInfo(com.hazelcast.internal.partition.MigrationInfo) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica)

Example 32 with PartitionReplica

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

the class MigrationCommitServiceTest method testPartitionBackupCopyCommit.

@Test
public void testPartitionBackupCopyCommit() throws Exception {
    PartitionReplica destination = clearReplicaIndex(PARTITION_ID_TO_MIGRATE, NODE_COUNT - 1);
    MigrationInfo migration = createCopyMigration(PARTITION_ID_TO_MIGRATE, NODE_COUNT - 1, destination);
    migrateWithSuccess(migration);
    assertMigrationDestinationCommit(migration);
    assertPartitionDataAfterMigrations();
}
Also used : MigrationInfo(com.hazelcast.internal.partition.MigrationInfo) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 33 with PartitionReplica

use of com.hazelcast.internal.partition.PartitionReplica 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 34 with PartitionReplica

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

the class PartitionStateGeneratorTest method printTable.

private static void printTable(Map<MemberGroup, GroupPartitionState> groupPartitionStates, int replicaCount) {
    if (!PRINT_STATE) {
        return;
    }
    System.out.printf("%-20s", "Owner");
    for (int i = 0; i < replicaCount; i++) {
        System.out.printf("%-5s", "R-" + i);
    }
    System.out.printf("%5s%n", "Total");
    System.out.println("_______________________________________________________________");
    System.out.println();
    int k = 1;
    for (GroupPartitionState groupState : groupPartitionStates.values()) {
        System.out.printf("%-20s%n", "MemberGroup[" + (k++) + "]");
        for (Map.Entry<PartitionReplica, Set<Integer>[]> entry : groupState.nodePartitionsMap.entrySet()) {
            int total = 0;
            Address address = entry.getKey().address();
            System.out.printf("%-20s", address.getHost() + ":" + address.getPort());
            Collection<Integer>[] partitions = entry.getValue();
            for (int i = 0; i < replicaCount; i++) {
                int count = partitions[i].size();
                System.out.printf("%-5s", count);
                total += partitions[i].size();
            }
            System.out.printf("%-5s%n", total);
        }
        if (groupState.group.size() > 1) {
            System.out.printf("%-20s", "Total");
            int total = 0;
            Collection<Integer>[] partitions = groupState.groupPartitions;
            for (int i = 0; i < replicaCount; i++) {
                int count = partitions[i].size();
                System.out.printf("%-5s", count);
                total += partitions[i].size();
            }
            System.out.printf("%-5s%n", total);
        }
        System.out.println("---------------------------------------------------------------");
        System.out.println();
    }
    System.out.println();
    System.out.println();
}
Also used : Address(com.hazelcast.cluster.Address) InetAddress(java.net.InetAddress) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map)

Example 35 with PartitionReplica

use of com.hazelcast.internal.partition.PartitionReplica 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

PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)103 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)51 QuickTest (com.hazelcast.test.annotation.QuickTest)51 Test (org.junit.Test)51 Address (com.hazelcast.cluster.Address)44 InternalPartition (com.hazelcast.internal.partition.InternalPartition)17 MigrationInfo (com.hazelcast.internal.partition.MigrationInfo)17 ArrayList (java.util.ArrayList)10 Member (com.hazelcast.cluster.Member)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)7 PartitionTableView (com.hazelcast.internal.partition.PartitionTableView)6 ReadonlyInternalPartition (com.hazelcast.internal.partition.ReadonlyInternalPartition)6 ClusterState (com.hazelcast.cluster.ClusterState)5 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)5 NodeEngine (com.hazelcast.spi.impl.NodeEngine)4 Operation (com.hazelcast.spi.impl.operationservice.Operation)4 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)3 MemberLeftException (com.hazelcast.core.MemberLeftException)3 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)3