use of org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Move in project geode by apache.
the class ExplicitMoveDirector method nextStep.
@Override
public boolean nextStep() {
Bucket bucket = model.getBuckets()[bucketId];
Member sourceMember = model.getMember(source);
Member targetMember = model.getMember(target);
if (sourceMember == null) {
throw new IllegalStateException(LocalizedStrings.PERCENTAGE_MOVE_DIRECTORY_SOURCE_NOT_DATA_STORE.toLocalizedString(model.getName(), source));
}
if (targetMember == null) {
throw new IllegalStateException(LocalizedStrings.PERCENTAGE_MOVE_DIRECTORY_TARGET_NOT_DATA_STORE.toLocalizedString(model.getName(), target));
}
if (bucket == null) {
throw new IllegalStateException("The bucket for key " + key + ", bucket " + bucketId + ", region " + model.getName() + " does not exist");
}
if (!bucket.getMembersHosting().contains(sourceMember)) {
throw new IllegalStateException("The bucket for key " + key + ", bucket " + bucketId + ", region " + model.getName() + " is not hosted by " + source + ". Members hosting: " + bucket.getMembersHosting());
}
RefusalReason reason = targetMember.willAcceptBucket(bucket, sourceMember, model.enforceUniqueZones());
if (reason.willAccept()) {
if (!model.moveBucket(new Move(sourceMember, targetMember, bucket))) {
// Double check to see if the source or destination have left the DS
Set allMembers = ds.getDistributionManager().getDistributionManagerIdsIncludingAdmin();
if (!allMembers.contains(sourceMember)) {
throw new IllegalStateException(LocalizedStrings.PERCENTAGE_MOVE_DIRECTORY_SOURCE_NOT_DATA_STORE.toLocalizedString(model.getName(), source));
}
if (!allMembers.contains(targetMember)) {
throw new IllegalStateException(LocalizedStrings.PERCENTAGE_MOVE_DIRECTORY_TARGET_NOT_DATA_STORE.toLocalizedString(model.getName(), target));
}
throw new IllegalStateException("Unable to move bucket " + bucket + " from " + sourceMember + " to " + targetMember);
}
} else {
throw new IllegalStateException("Unable to move bucket for " + model.getName() + ". " + reason.formatMessage(sourceMember, targetMember, bucket));
}
return false;
}
use of org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Move in project geode by apache.
the class MoveBuckets method moveBuckets.
/**
* Move a single bucket from one member to another.
*
* @return true if we could move the bucket
*/
private boolean moveBuckets() {
Move bestMove = model.findBestBucketMove();
if (bestMove == null) {
return false;
}
model.moveBucket(bestMove);
return true;
}
use of org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Move in project geode by apache.
the class MovePrimariesFPR method makeFPRPrimaryForThisNode.
/**
* Move all primary from other to this
*/
private void makeFPRPrimaryForThisNode() {
PartitionedRegion partitionedRegion = model.getPartitionedRegion();
List<FixedPartitionAttributesImpl> FPAs = partitionedRegion.getFixedPartitionAttributesImpl();
InternalDistributedMember targetId = partitionedRegion.getDistributionManager().getId();
Member target = model.getMember(targetId);
for (Bucket bucket : model.getBuckets()) {
if (bucket != null) {
for (FixedPartitionAttributesImpl fpa : FPAs) {
if (fpa.hasBucket(bucket.getId()) && fpa.isPrimary()) {
Member source = bucket.getPrimary();
if (source != target) {
// HACK: In case we don't know who is Primary at this time
// we just set source as target too for stat purposes
source = (source == null || source == model.INVALID_MEMBER) ? target : source;
if (logger.isDebugEnabled()) {
logger.debug("PRLM#movePrimariesForFPR: For Bucket#{}, moving primary from source {} to target {}", bucket.getId(), bucket.getPrimary(), target);
}
boolean successfulMove = model.movePrimary(new Move(source, target, bucket));
// We have to move the primary otherwise there is some problem!
Assert.assertTrue(successfulMove, " Fixed partitioned region not able to move the primary!");
if (successfulMove) {
if (logger.isDebugEnabled()) {
logger.debug("PRLM#movePrimariesForFPR: For Bucket#{}, moved primary from source {} to target {}", bucket.getId(), bucket.getPrimary(), target);
}
bucket.setPrimary(target, bucket.getPrimaryLoad());
}
}
}
}
}
}
}
use of org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Move in project geode by apache.
the class RemoveOverRedundancy method removeOverRedundancy.
/**
* Remove copies of buckets that have more than the expected number of redundant copies.
*/
private boolean removeOverRedundancy() {
Move bestMove = null;
BucketRollup first = null;
while (bestMove == null) {
if (model.getOverRedundancyBuckets().isEmpty()) {
return false;
}
first = model.getOverRedundancyBuckets().first();
bestMove = model.findBestRemove(first);
if (bestMove == null) {
if (logger.isDebugEnabled()) {
logger.debug("Skipping overredundancy bucket {} because couldn't find a member to remove from?", first);
}
model.ignoreOverRedundancyBucket(first);
}
}
Member targetMember = bestMove.getTarget();
model.remoteOverRedundancyBucket(first, targetMember);
return true;
}
use of org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Move in project geode by apache.
the class SatisfyRedundancy method satisfyRedundancy.
/**
* Try to satisfy redundancy for a single bucket.
*
* @return true if we actually created a bucket somewhere.
*/
private boolean satisfyRedundancy() {
Move bestMove = null;
BucketRollup first = null;
while (bestMove == null) {
if (model.getLowRedundancyBuckets().isEmpty()) {
return false;
}
first = model.getLowRedundancyBuckets().first();
bestMove = model.findBestTarget(first, true);
if (bestMove == null && !model.enforceUniqueZones()) {
bestMove = model.findBestTarget(first, false);
}
if (bestMove == null) {
if (logger.isDebugEnabled()) {
logger.debug("Skipping low redundancy bucket {} because no member will accept it", first);
}
model.ignoreLowRedundancyBucket(first);
}
}
model.createRedundantBucket(first, bestMove.getTarget());
return true;
}
Aggregations