Search in sources :

Example 11 with CompositeDirector

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

the class PartitionedRegionLoadModelJUnitTest method doManyColocatedRegionsTest.

private void doManyColocatedRegionsTest(int colocatedRegions) throws Exception {
    PartitionedRegionLoadModel model = new PartitionedRegionLoadModel(bucketOperator, 1, 5, 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, 200, 200, new long[] { 30, 23, 28, 30, 23 }, new long[] { 1, 1, 1, 0, 0 });
    PartitionMemberInfoImpl details2 = buildDetails(member2, 200, 200, new long[] { 30, 23, 28, 30, 23 }, new long[] { 0, 0, 0, 1, 1 });
    PartitionMemberInfoImpl details3 = buildDetails(member3, 200, 200, new long[] { 0, 0, 0, 0, 0 }, new long[] { 0, 0, 0, 0, 0 });
    model.addRegion("primary", Arrays.asList(details1, details2, details3), new FakeOfflineDetails(), true);
    for (int i = 0; i < colocatedRegions; i++) {
        model.addRegion("colocated" + i, Arrays.asList(details1, details2, details3), new FakeOfflineDetails(), true);
    }
    // we expect 3 moves
    assertEquals(4, doMoves(new CompositeDirector(true, true, true, true), model));
}
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)

Example 12 with CompositeDirector

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

the class PartitionedRegionLoadModelJUnitTest method testMoveBuckets.

/**
   * Very basic test of moving buckets. Creates two nodes and four buckets, with buckets only on one
   * node. Half of the buckets should move to the other node.
   */
@Test
public void testMoveBuckets() throws Exception {
    PartitionedRegionLoadModel model = new PartitionedRegionLoadModel(bucketOperator, 0, 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);
    // Create some imbalanced nodes
    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 });
    model.addRegion("a", Arrays.asList(details1, details2), new FakeOfflineDetails(), true);
    assertEquals(2, doMoves(new CompositeDirector(false, false, true, true), model));
    assertEquals(Collections.emptyList(), bucketOperator.creates);
    assertEquals(Collections.emptyList(), bucketOperator.primaryMoves);
    // Two of the buckets should move to member2
    List<Move> expectedMoves = new ArrayList<Move>();
    expectedMoves.add(new Move(member1, member2));
    expectedMoves.add(new Move(member1, member2));
    assertEquals(expectedMoves, bucketOperator.bucketMoves);
}
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 13 with CompositeDirector

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

the class PartitionedRegionLoadModelJUnitTest method testRedundancySatisfactionDoNotEnforceLocalMaxMemory.

/**
   * This test makes sure we ignore the size limit if requested
   */
@Test
public void testRedundancySatisfactionDoNotEnforceLocalMaxMemory() throws Exception {
    PartitionedRegionLoadModel model = new PartitionedRegionLoadModel(bucketOperator, 2, 3, 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);
    // A member with 1 bucket with low redundancy, but it is too big to copy anywhere
    PartitionMemberInfoImpl details1 = buildDetails(member1, 50, 50, new long[] { 30, 0, 0 }, new long[] { 1, 0, 0 });
    // A member with 2 buckets with low redundancy that can be copied
    PartitionMemberInfoImpl details2 = buildDetails(member2, 40, 40, new long[] { 0, 10, 10 }, new long[] { 0, 1, 1 });
    model.addRegion("a", Arrays.asList(details1, details2), new FakeOfflineDetails(), false);
    // we expect 2 moves
    assertEquals(3, doMoves(new CompositeDirector(true, true, false, false), model));
    List<Create> expectedCreates = new ArrayList<Create>();
    expectedCreates.add(new Create(member2, 0));
    expectedCreates.add(new Create(member1, 1));
    expectedCreates.add(new Create(member1, 2));
    assertEquals(expectedCreates, bucketOperator.creates);
    Set<PartitionMemberInfo> afterDetails = model.getPartitionedMemberDetails("a");
    assertEquals(afterDetails.size(), 2);
    for (PartitionMemberInfo member : afterDetails) {
        if (member.getDistributedMember().equals(member1)) {
            assertEquals(details1.getConfiguredMaxMemory(), member.getConfiguredMaxMemory());
        } else {
            assertEquals(details2.getConfiguredMaxMemory(), member.getConfiguredMaxMemory());
        }
    }
}
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) 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 14 with CompositeDirector

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

the class PartitionedRegionLoadModelJUnitTest method testRedundancySatisfactionBalanced.

/**
   * Tests to make sure that redundancy satisfaction balances between nodes to ensure an even load.
   */
@Test
public void testRedundancySatisfactionBalanced() 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[] { 0, 0, 0, 0 }, new long[] { 0, 0, 0, 0 });
    model.addRegion("a", Arrays.asList(details1, details2, details3), new FakeOfflineDetails(), true);
    // we expect 4 moves
    assertEquals(4, doMoves(new CompositeDirector(true, true, false, false), model));
    // The bucket creates should alternate between members
    // so that the load is balanced.
    List<Create> expectedCreates = new ArrayList<Create>();
    expectedCreates.add(new Create(member2, 0));
    expectedCreates.add(new Create(member3, 1));
    expectedCreates.add(new Create(member2, 2));
    expectedCreates.add(new Create(member3, 3));
    assertEquals(expectedCreates, bucketOperator.creates);
}
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 15 with CompositeDirector

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

the class PartitionedRegionLoadModelJUnitTest method testRebalancingWithOfflineMembers.

@Test
public void testRebalancingWithOfflineMembers() throws Exception {
    PartitionedRegionLoadModel model = new PartitionedRegionLoadModel(bucketOperator, 1, 6, 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);
    PartitionMemberInfoImpl details1 = buildDetails(member1, 480, 480, new long[] { 1, 1, 1, 1, 1, 1 }, new long[] { 1, 1, 1, 1, 1, 1 });
    PartitionMemberInfoImpl details2 = buildDetails(member2, 480, 480, new long[] { 0, 0, 0, 0, 0, 0 }, new long[] { 0, 0, 0, 0, 0, 0 });
    // Each bucket has an offline member
    Set<PersistentMemberID> o = Collections.singleton(new PersistentMemberID());
    Set<PersistentMemberID> x = Collections.emptySet();
    final OfflineMemberDetailsImpl offlineDetails = new OfflineMemberDetailsImpl(new Set[] { o, o, o, o, o, o });
    model.addRegion("primary", Arrays.asList(details1, details2), offlineDetails, true);
    assertEquals(3, doMoves(new CompositeDirector(true, true, true, true), model));
    List<Move> expectedMoves = new ArrayList<Move>();
    expectedMoves.add(new Move(member1, member2));
    expectedMoves.add(new Move(member1, member2));
    expectedMoves.add(new Move(member1, member2));
    assertEquals(expectedMoves, bucketOperator.bucketMoves);
}
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) PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

CompositeDirector (org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector)35 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)33 PartitionedRegionLoadModel (org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel)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)7 Map (java.util.Map)2 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)2 Completion (org.apache.geode.internal.cache.partitioned.rebalance.BucketOperator.Completion)2 PersistentMemberID (org.apache.geode.internal.cache.persistence.PersistentMemberID)2 Ignore (org.junit.Ignore)2 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 Random (java.util.Random)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 CancelException (org.apache.geode.CancelException)1 CacheClosedException (org.apache.geode.cache.CacheClosedException)1 PartitionedRegionStorageException (org.apache.geode.cache.PartitionedRegionStorageException)1