Search in sources :

Example 1 with Move

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;
}
Also used : Set(java.util.Set) Bucket(org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Bucket) Move(org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Move) RefusalReason(org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.RefusalReason) Member(org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Member) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember)

Example 2 with Move

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;
}
Also used : Move(org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Move)

Example 3 with Move

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());
                        }
                    }
                }
            }
        }
    }
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Bucket(org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Bucket) Move(org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Move) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Member(org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Member) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) FixedPartitionAttributesImpl(org.apache.geode.internal.cache.FixedPartitionAttributesImpl)

Example 4 with Move

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;
}
Also used : Move(org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Move) BucketRollup(org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.BucketRollup) Member(org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Member)

Example 5 with Move

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;
}
Also used : Move(org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Move) BucketRollup(org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.BucketRollup)

Aggregations

Move (org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Move)8 Member (org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Member)5 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)3 Bucket (org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Bucket)3 BucketRollup (org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.BucketRollup)3 DistributedMember (org.apache.geode.distributed.DistributedMember)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 FixedPartitionAttributesImpl (org.apache.geode.internal.cache.FixedPartitionAttributesImpl)1 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)1 RefusalReason (org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.RefusalReason)1