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();
}
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();
}
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);
}
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();
}
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]);
}
}
}
}
Aggregations