Search in sources :

Example 1 with Member

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

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

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

the class PercentageMoveDirector method initialize.

@Override
public void initialize(PartitionedRegionLoadModel model) {
    Member sourceMember = model.getMember(source);
    if (sourceMember == null) {
        throw new IllegalStateException(LocalizedStrings.PERCENTAGE_MOVE_DIRECTORY_SOURCE_NOT_DATA_STORE.toLocalizedString(model.getName(), source));
    }
    // Figure out how much load we are moving, based on the percentage.
    float sourceLoad = sourceMember.getTotalLoad();
    loadToMove = sourceLoad * percentage / 100;
    membershipChanged(model);
}
Also used : 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 4 with Member

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

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

Aggregations

Member (org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Member)7 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)5 Move (org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Move)5 DistributedMember (org.apache.geode.distributed.DistributedMember)4 Bucket (org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Bucket)4 BucketRollup (org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.BucketRollup)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