Search in sources :

Example 26 with PartitionedRegionLoadModel

use of org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel in project geode by apache.

the class PartitionedRegionLoadModelJUnitTest method testRedundancySatisfactionWithAsyncFailures.

/**
   * Test that redundancy satisfation can handle asynchronous failures and complete the job
   * correctly.
   */
@Test
public void testRedundancySatisfactionWithAsyncFailures() throws Exception {
    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);
    BucketOperatorWithFailures operator = new BucketOperatorWithFailures();
    operator.addBadMember(member2);
    bucketOperator = operator;
    PartitionedRegionLoadModel model = new PartitionedRegionLoadModel(bucketOperator, 1, 6, getAddressComparor(false), Collections.<InternalDistributedMember>emptySet(), null);
    PartitionMemberInfoImpl details1 = buildDetails(member1, 500, 500, new long[] { 1, 1, 1, 1, 1, 1 }, new long[] { 1, 1, 1, 1, 1, 1 });
    PartitionMemberInfoImpl details2 = buildDetails(member2, 500, 500, new long[] { 0, 0, 0, 0, 0, 0 }, new long[] { 0, 0, 0, 0, 0, 0 });
    PartitionMemberInfoImpl details3 = buildDetails(member3, 500, 500, new long[] { 0, 0, 0, 0, 0, 0 }, new long[] { 0, 0, 0, 0, 0, 0 });
    model.addRegion("a", Arrays.asList(details1, details2, details3), new FakeOfflineDetails(), true);
    Set<PartitionMemberInfo> details = model.getPartitionedMemberDetails("a");
    assertEquals(3, details.size());
    // TODO - make some assertions about what's in the details
    // we expect 6 moves (3 of these will fail)
    assertEquals(6, doMoves(new CompositeDirector(true, true, false, false), model));
    assertEquals(3, bucketOperator.creates.size());
    for (Completion completion : operator.pendingSuccesses) {
        completion.onSuccess();
    }
    for (Completion completion : operator.pendingFailures) {
        completion.onFailure();
    }
    // Now the last two moves will get reattempted to a new location (because the last location
    // failed)
    assertEquals(3, doMoves(new CompositeDirector(true, true, false, false), model));
    List<Create> expectedCreates = new ArrayList<Create>();
    expectedCreates.add(new Create(member3, 1));
    expectedCreates.add(new Create(member3, 3));
    expectedCreates.add(new Create(member3, 5));
    expectedCreates.add(new Create(member3, 0));
    expectedCreates.add(new Create(member3, 2));
    expectedCreates.add(new Create(member3, 4));
    assertEquals(expectedCreates, bucketOperator.creates);
}
Also used : PartitionedRegionLoadModel(org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel) Completion(org.apache.geode.internal.cache.partitioned.rebalance.BucketOperator.Completion) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) PartitionMemberInfo(org.apache.geode.cache.partition.PartitionMemberInfo) ArrayList(java.util.ArrayList) CompositeDirector(org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 27 with PartitionedRegionLoadModel

use of org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel 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());
    }
}
Also used : PartitionedRegionLoadModel(org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) PartitionMemberInfo(org.apache.geode.cache.partition.PartitionMemberInfo) CompositeDirector(org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector) HashSet(java.util.HashSet) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 28 with PartitionedRegionLoadModel

use of org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel 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);
}
Also used : PartitionedRegionLoadModel(org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) CompositeDirector(org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 29 with PartitionedRegionLoadModel

use of org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel 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);
}
Also used : PartitionedRegionLoadModel(org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ArrayList(java.util.ArrayList) CompositeDirector(org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 30 with PartitionedRegionLoadModel

use of org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel 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));
}
Also used : PartitionedRegionLoadModel(org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) CompositeDirector(org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector) HashSet(java.util.HashSet) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

PartitionedRegionLoadModel (org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel)36 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)34 CompositeDirector (org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector)33 UnitTest (org.apache.geode.test.junit.categories.UnitTest)32 Test (org.junit.Test)32 ArrayList (java.util.ArrayList)19 HashSet (java.util.HashSet)9 PartitionMemberInfo (org.apache.geode.cache.partition.PartitionMemberInfo)8 Map (java.util.Map)3 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)3 CancelException (org.apache.geode.CancelException)2 PartitionRebalanceInfo (org.apache.geode.cache.partition.PartitionRebalanceInfo)2 InternalCache (org.apache.geode.internal.cache.InternalCache)2 InternalResourceManager (org.apache.geode.internal.cache.control.InternalResourceManager)2 PartitionRebalanceDetailsImpl (org.apache.geode.internal.cache.control.PartitionRebalanceDetailsImpl)2 Completion (org.apache.geode.internal.cache.partitioned.rebalance.BucketOperator.Completion)2 BucketOperatorWrapper (org.apache.geode.internal.cache.partitioned.rebalance.BucketOperatorWrapper)2 PersistentMemberID (org.apache.geode.internal.cache.persistence.PersistentMemberID)2 Ignore (org.junit.Ignore)2 IOException (java.io.IOException)1