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