Search in sources :

Example 1 with RefusalReason

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

Aggregations

Set (java.util.Set)1 DistributedMember (org.apache.geode.distributed.DistributedMember)1 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 Bucket (org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Bucket)1 Member (org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Member)1 Move (org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.Move)1 RefusalReason (org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel.RefusalReason)1