use of org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector in project geode by apache.
the class PartitionedRegionLoadModelJUnitTest method testMoveLargeBucketsWithRedundancy.
/**
* Test to move buckets with some large buckets (to make sure there are no issues with buffer
* overflow); Makes sure that buckets and primaries are balanced
*/
@Test
public void testMoveLargeBucketsWithRedundancy() throws Exception {
PartitionedRegionLoadModel model = new PartitionedRegionLoadModel(bucketOperator, 2, 4, getAddressComparor(false), Collections.<InternalDistributedMember>emptySet(), null);
InternalDistributedMember member1 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 1);
InternalDistributedMember member2 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 2);
InternalDistributedMember member3 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 3);
InternalDistributedMember member4 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 4);
// Create some imbalanced nodes
long bigBucket = Integer.MAX_VALUE * 5L + 10L;
PartitionMemberInfoImpl details1 = buildDetails(member1, 500, Long.MAX_VALUE, new long[] { bigBucket, bigBucket, bigBucket, bigBucket }, new long[] { 1, 1, 0, 0 });
PartitionMemberInfoImpl details2 = buildDetails(member2, 500, Long.MAX_VALUE, new long[] { bigBucket, bigBucket, bigBucket, bigBucket }, new long[] { 0, 0, 1, 0 });
PartitionMemberInfoImpl details3 = buildDetails(member3, 500, Long.MAX_VALUE, new long[] { bigBucket, bigBucket, bigBucket, bigBucket }, new long[] { 0, 0, 0, 1 });
PartitionMemberInfoImpl details4 = buildDetails(member4, 500, Long.MAX_VALUE, new long[] { 0, 0, 0, 0 }, new long[] { 0, 0, 0, 0 });
model.addRegion("a", Arrays.asList(details1, details2, details3, details4), new FakeOfflineDetails(), true);
doMoves(new CompositeDirector(false, false, true, true), model);
assertEquals(Collections.emptyList(), bucketOperator.creates);
// One bucket should move from each member to member4
Set<Move> expectedMoves = new HashSet<Move>();
expectedMoves.add(new Move(member1, member4));
expectedMoves.add(new Move(member2, member4));
expectedMoves.add(new Move(member3, member4));
assertEquals(expectedMoves, new HashSet<Move>(bucketOperator.bucketMoves));
// We don't know how many primaries will move, because
// the move buckets algorithm could move the primary or
// it could move a redundant copy. But after we're done, we should
// only have one primary per member.
Set<PartitionMemberInfo> detailSet = model.getPartitionedMemberDetails("a");
for (PartitionMemberInfo member : detailSet) {
assertEquals(1, member.getPrimaryCount());
assertEquals(3, member.getBucketCount());
}
}
use of org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector in project geode by apache.
the class PartitionedRegionLoadModelJUnitTest method testRedundancySatisfactionEnforceRemoteIp.
@Test
public void testRedundancySatisfactionEnforceRemoteIp() throws Exception {
PartitionedRegionLoadModel model = new PartitionedRegionLoadModel(bucketOperator, 1, 3, getAddressComparor(true), Collections.<InternalDistributedMember>emptySet(), null);
InternalDistributedMember member1 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 1);
InternalDistributedMember member2 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 2);
// Create some buckets with low redundancy on members 1
PartitionMemberInfoImpl details1 = buildDetails(member1, 500, 500, new long[] { 30, 30, 30 }, new long[] { 1, 1, 1 });
PartitionMemberInfoImpl details2 = buildDetails(member2, 500, 500, new long[] { 0, 0, 0 }, new long[] { 0, 0, 0 });
model.addRegion("a", Arrays.asList(details1, details2), new FakeOfflineDetails(), true);
// we expect 0 moves, because we're enforcing that we can't create
// copies on the same IP.
assertEquals(0, doMoves(new CompositeDirector(true, true, false, false), model));
assertEquals(Collections.emptyList(), bucketOperator.creates);
}
use of org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector in project geode by apache.
the class PartitionedRegionLoadModelJUnitTest method testMovePrimariesWithFailures.
/**
* Test that we can move primaries if failures occur during the move. In this case member2 is bad,
* so primaries should move to member3 instead.
*/
@Test
public void testMovePrimariesWithFailures() throws Exception {
InternalDistributedMember member1 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 1);
final InternalDistributedMember member2 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 2);
InternalDistributedMember member3 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 3);
MyBucketOperator op = new MyBucketOperator() {
@Override
public boolean movePrimary(InternalDistributedMember source, InternalDistributedMember target, int bucketId) {
if (target.equals(member2)) {
return false;
}
return super.movePrimary(source, target, bucketId);
}
};
PartitionedRegionLoadModel model = new PartitionedRegionLoadModel(op, 2, 4, getAddressComparor(false), Collections.<InternalDistributedMember>emptySet(), null);
// Create some imbalanced primaries
PartitionMemberInfoImpl details1 = buildDetails(member1, 500, 500, new long[] { 1, 1, 1, 1 }, new long[] { 1, 1, 1, 1 });
PartitionMemberInfoImpl details2 = buildDetails(member2, 500, 500, new long[] { 1, 1, 1, 1 }, new long[] { 0, 0, 0, 0 });
PartitionMemberInfoImpl details3 = buildDetails(member3, 500, 500, new long[] { 1, 1, 1, 1 }, new long[] { 0, 0, 0, 0 });
model.addRegion("a", Arrays.asList(details1, details2, details3), new FakeOfflineDetails(), true);
assertEquals(8, doMoves(new CompositeDirector(false, false, false, true), model));
assertEquals(Collections.emptyList(), op.creates);
// Two of the primaries should move to member2
List<Move> expectedMoves = new ArrayList<Move>();
expectedMoves.add(new Move(member1, member3));
expectedMoves.add(new Move(member1, member3));
assertEquals(expectedMoves, op.primaryMoves);
}
use of org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector in project geode by apache.
the class PartitionedRegionLoadModelJUnitTest method testIncompleteColocation.
@Test
public void testIncompleteColocation() throws Exception {
PartitionedRegionLoadModel model = new PartitionedRegionLoadModel(bucketOperator, 1, 4, getAddressComparor(false), Collections.<InternalDistributedMember>emptySet(), null);
InternalDistributedMember member1 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 1);
InternalDistributedMember member2 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 2);
InternalDistributedMember member3 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 3);
// Create some buckets with low redundancy on member 1
PartitionMemberInfoImpl details1 = buildDetails(member1, 500, 500, new long[] { 1, 1, 1, 1 }, new long[] { 1, 1, 1, 1 });
PartitionMemberInfoImpl details2 = buildDetails(member2, 500, 500, new long[] { 0, 0, 0, 0 }, new long[] { 0, 0, 0, 0 });
PartitionMemberInfoImpl details3 = buildDetails(member3, 500, 500, new long[] { 1, 1, 0, 0 }, new long[] { 0, 0, 0, 0 });
model.addRegion("a", Arrays.asList(details1, details2, details3), new FakeOfflineDetails(), true);
model.addRegion("b", Arrays.asList(details1, details2, details3), new FakeOfflineDetails(), true);
model.addRegion("c", Arrays.asList(details1, details2), new FakeOfflineDetails(), true);
// Add a region which is not created on all of the members.
// Member 3 should not be considered a target for any moves.
assertEquals(6, doMoves(new CompositeDirector(true, true, false, true), model));
// Everything should be creatd on member2
Set<Create> expectedCreates = new HashSet<Create>();
expectedCreates.add(new Create(member2, 0));
expectedCreates.add(new Create(member2, 1));
expectedCreates.add(new Create(member2, 2));
expectedCreates.add(new Create(member2, 3));
assertEquals(expectedCreates, new HashSet(bucketOperator.creates));
Set<Move> expectedMoves = new HashSet<Move>();
expectedMoves.add(new Move(member1, member2));
expectedMoves.add(new Move(member1, member2));
assertEquals(expectedMoves, new HashSet(bucketOperator.primaryMoves));
}
use of org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector in project geode by apache.
the class PartitionedRegionLoadModelJUnitTest method testRedundancySatisfactionWithFailures.
/**
* Tests to make sure that redundancy satisfaction balances between nodes to ensure an even load.
*/
@Test
public void testRedundancySatisfactionWithFailures() throws Exception {
InternalDistributedMember member1 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 1);
final InternalDistributedMember member2 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 2);
InternalDistributedMember member3 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 3);
MyBucketOperator op = new MyBucketOperator() {
@Override
public void createRedundantBucket(InternalDistributedMember targetMember, int i, Map<String, Long> colocatedRegionBytes, Completion completion) {
if (targetMember.equals(member2)) {
completion.onFailure();
} else {
super.createRedundantBucket(targetMember, i, colocatedRegionBytes, completion);
}
}
};
PartitionedRegionLoadModel model = new PartitionedRegionLoadModel(op, 1, 4, getAddressComparor(false), Collections.<InternalDistributedMember>emptySet(), null);
// Create some buckets with low redundancy on member 1
PartitionMemberInfoImpl details1 = buildDetails(member1, 500, 500, new long[] { 1, 1, 1, 1 }, new long[] { 1, 1, 1, 1 });
PartitionMemberInfoImpl details2 = buildDetails(member2, 500, 500, new long[] { 0, 0, 0, 0 }, new long[] { 0, 0, 0, 0 });
PartitionMemberInfoImpl details3 = buildDetails(member3, 500, 500, new long[] { 0, 0, 0, 0 }, new long[] { 0, 0, 0, 0 });
model.addRegion("a", Arrays.asList(details1, details2, details3), new FakeOfflineDetails(), true);
// we expect 8 moves
assertEquals(8, doMoves(new CompositeDirector(true, true, false, false), model));
// The bucket creates should do all of the creates on member 3
// because member2 failed.
List<Create> expectedCreates = new ArrayList<Create>();
expectedCreates.add(new Create(member3, 0));
expectedCreates.add(new Create(member3, 1));
expectedCreates.add(new Create(member3, 2));
expectedCreates.add(new Create(member3, 3));
assertEquals(expectedCreates, op.creates);
}
Aggregations