Search in sources :

Example 16 with PartitionedRegionLoadModel

use of org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel 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 17 with PartitionedRegionLoadModel

use of org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel 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)

Example 18 with PartitionedRegionLoadModel

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

the class PartitionedRegionRebalanceOp method executeFPA.

/**
   * For FPR we will creatd buckets and make primaries as specified by FixedPartitionAttributes. We
   * have to just create buckets and make primaries for the local node.
   * 
   * @return the details of the rebalance.
   */
public Set<PartitionRebalanceInfo> executeFPA() {
    if (logger.isDebugEnabled()) {
        logger.debug("Rebalancing buckets for fixed partitioned region {}", this.targetRegion);
    }
    long start = System.nanoTime();
    InternalCache cache = leaderRegion.getCache();
    InternalResourceManager resourceManager = InternalResourceManager.getInternalResourceManager(cache);
    InternalResourceManager.getResourceObserver().recoveryStarted(targetRegion);
    try {
        if (!checkAndSetColocatedRegions()) {
            return Collections.emptySet();
        }
        // If I am a datastore of a FixedPartition, I will be hosting bucket so no
        // need of redundancy check.
        // No need to attach listener as well, we know that we are just creating bucket
        // for primary and secondary. We are not creating extra bucket for any of peers
        // who goes down.
        PartitionedRegionLoadModel model = null;
        Map<PartitionedRegion, InternalPRInfo> detailsMap = fetchDetails(cache);
        BucketOperatorWrapper operator = getBucketOperator(detailsMap);
        model = buildModel(operator, detailsMap, resourceManager);
        for (PartitionRebalanceDetailsImpl details : operator.getDetailSet()) {
            details.setPartitionMemberDetailsBefore(model.getPartitionedMemberDetails(details.getRegionPath()));
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Rebalancing FPR {} Model:{}\n", leaderRegion, model);
        }
        director.initialize(model);
        // This will perform all of the required operations.
        director.nextStep();
        if (logger.isDebugEnabled()) {
            logger.debug("Rebalancing FPR {} complete. Model:{}\n", leaderRegion, model);
        }
        long end = System.nanoTime();
        for (PartitionRebalanceDetailsImpl details : operator.getDetailSet()) {
            if (!simulate) {
                details.setTime(end - start);
            }
            details.setPartitionMemberDetailsAfter(model.getPartitionedMemberDetails(details.getRegionPath()));
        }
        return Collections.<PartitionRebalanceInfo>unmodifiableSet(operator.getDetailSet());
    } finally {
        try {
            InternalResourceManager.getResourceObserver().recoveryFinished(targetRegion);
        } catch (Exception e) {
            logger.debug(LocalizedMessage.create(LocalizedStrings.PartitionedRegionRebalanceOp_ERROR_IN_RESOURCE_OBSERVER), e);
        }
    }
}
Also used : PartitionedRegionLoadModel(org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) PartitionRebalanceInfo(org.apache.geode.cache.partition.PartitionRebalanceInfo) InternalCache(org.apache.geode.internal.cache.InternalCache) BucketOperatorWrapper(org.apache.geode.internal.cache.partitioned.rebalance.BucketOperatorWrapper) PartitionRebalanceDetailsImpl(org.apache.geode.internal.cache.control.PartitionRebalanceDetailsImpl) CancelException(org.apache.geode.CancelException) InternalResourceManager(org.apache.geode.internal.cache.control.InternalResourceManager)

Example 19 with PartitionedRegionLoadModel

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

the class PartitionedRegionLoadModelJUnitTest method testColocationIgnoreEnforceLocalMaxMemory.

/**
   * Test that each region indivually honors it's enforce local max memory flag.
   */
@Test
public void testColocationIgnoreEnforceLocalMaxMemory() 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 });
    model.addRegion("a", Arrays.asList(details1, details2), new FakeOfflineDetails(), true);
    // Member 2 has a lmm of 2, so it should only accept 2 buckets
    PartitionMemberInfoImpl bDetails1 = buildDetails(member1, 2, 2, new long[] { 1, 1, 1, 1 }, new long[] { 1, 1, 1, 1 });
    PartitionMemberInfoImpl bDetails2 = buildDetails(member2, 2, 2, new long[] { 0, 0, 0, 0 }, new long[] { 0, 0, 0, 0 });
    model.addRegion("b", Arrays.asList(bDetails1, bDetails2), new FakeOfflineDetails(), false);
    assertEquals(6, doMoves(new CompositeDirector(true, true, false, true), model));
    // Everything should be created 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)

Example 20 with PartitionedRegionLoadModel

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

the class PartitionedRegionLoadModelJUnitTest method testMoveBucketsWithWeights.

/**
   * Test to make sure that we honor the weight of a node while moving buckets.
   */
@Test
public void testMoveBucketsWithWeights() throws Exception {
    PartitionedRegionLoadModel model = new PartitionedRegionLoadModel(bucketOperator, 0, 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);
    // Create some imbalanced nodes
    PartitionMemberInfoImpl details1 = buildDetails(member1, 250, 250, 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 });
    model.addRegion("a", Arrays.asList(details1, details2), new FakeOfflineDetails(), true);
    assertEquals(4, doMoves(new CompositeDirector(false, false, true, true), model));
    assertEquals(Collections.emptyList(), bucketOperator.creates);
    assertEquals(Collections.emptyList(), bucketOperator.primaryMoves);
    // Four of the buckets should move to member2, because
    // member2 has twice the weight as member1.
    List<Move> expectedMoves = new ArrayList<Move>();
    expectedMoves.add(new Move(member1, member2));
    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) 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