use of org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Move in project geode by apache.
the class PercentageMoveDirector method nextStep.
@Override
public boolean nextStep() {
Member targetMember = model.getMember(target);
Member sourceMember = model.getMember(source);
if (targetMember == null) {
throw new IllegalStateException(LocalizedStrings.PERCENTAGE_MOVE_DIRECTORY_TARGET_NOT_DATA_STORE.toLocalizedString(model.getName(), target));
}
if (targetMember.equals(sourceMember)) {
throw new IllegalStateException(LocalizedStrings.PERCENTAGE_MOVE_TARGET_SAME_AS_SOURCE.toLocalizedString(model.getName(), target));
}
// if there is no largest bucket that we can move, we are done.
if (orderedBuckets.isEmpty()) {
return false;
}
// Take the largest bucket, and try to move that.
Bucket bucket = orderedBuckets.last();
float load = bucket.getLoad();
// See if we can move this bucket to the taret node.
if (targetMember.willAcceptBucket(bucket, sourceMember, model.enforceUniqueZones()).willAccept()) {
if (model.moveBucket(new Move(sourceMember, targetMember, bucket))) {
// If we had a successful move, decrement the load we should move.
loadToMove -= load;
// Remove all of the remaining buckets that are to big to move.
// TODO - this could be O(log(n)), rather an O(n)
Iterator<Bucket> itr = orderedBuckets.descendingIterator();
while (itr.hasNext()) {
Bucket next = itr.next();
if (next.getLoad() > loadToMove) {
itr.remove();
} else {
break;
}
}
}
}
// In any case, remove the bucket from the list of buckets we'll try to move.
orderedBuckets.remove(bucket);
return true;
}
use of org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Move in project geode by apache.
the class SatisfyRedundancyFPR method createFPRBucketsForThisNode.
public void createFPRBucketsForThisNode() {
final Map<BucketRollup, Move> moves = new HashMap<BucketRollup, Move>();
for (BucketRollup bucket : model.getLowRedundancyBuckets()) {
Move move = model.findBestTargetForFPR(bucket, true);
if (move == null && !model.enforceUniqueZones()) {
move = model.findBestTargetForFPR(bucket, false);
}
if (move != null) {
moves.put(bucket, move);
} else {
if (logger.isDebugEnabled()) {
logger.debug("Skipping low redundancy bucket {} because no member will accept it", bucket);
}
}
}
// are different, there will not be any contention for lock
for (Map.Entry<BucketRollup, Move> bucketMove : moves.entrySet()) {
BucketRollup bucket = bucketMove.getKey();
Move move = bucketMove.getValue();
Member targetMember = move.getTarget();
model.createRedundantBucket(bucket, targetMember);
}
model.waitForOperations();
}
use of org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Move in project geode by apache.
the class MovePrimaries method movePrimaries.
/**
* Move a single primary from one member to another
*
* @return if we are able to move a primary.
*/
private boolean movePrimaries() {
Move bestMove = model.findBestPrimaryMove();
if (bestMove == null) {
return false;
}
model.movePrimary(bestMove);
return true;
}
Aggregations