Search in sources :

Example 1 with PersistentMembershipView

use of org.apache.geode.internal.cache.persistence.PersistentMembershipView in project geode by apache.

the class ProxyBucketRegion method checkBucketRedundancyBeforeGrab.

public boolean checkBucketRedundancyBeforeGrab(InternalDistributedMember moveSource, boolean replaceOfflineData) {
    int redundancy = getBucketAdvisor().getBucketRedundancy();
    // Skip any checks if this is a colocated bucket. We need to create
    // the colocated bucket if we managed to create the parent bucket. There are
    // race conditions where the parent region may know that a member is no longer
    // hosting the bucket, but the child region doesn't know that yet.
    PartitionedRegion colocatedRegion = ColocationHelper.getColocatedRegion(this.partitionedRegion);
    if (colocatedRegion != null) {
        return true;
    }
    // sure the bucket isn't completely offline
    if (!replaceOfflineData || redundancy == -1) {
        BucketPersistenceAdvisor persistAdvisor = getPersistenceAdvisor();
        if (persistAdvisor != null) {
            // any offline buckets should be empty
            if (!persistAdvisor.wasHosting() && advisor.getHadPrimary()) {
                final PersistentMembershipView membershipView = persistAdvisor.getMembershipView();
                if (membershipView == null) {
                    // Refuse to create the bucket if that is the case.
                    if (logger.isDebugEnabled()) {
                        logger.debug("grabFreeBucket: Can't create bucket because persistence is not yet initialized {}{}{}", this.partitionedRegion.getPRId(), PartitionedRegion.BUCKET_ID_SEPARATOR, bid);
                    }
                    return false;
                }
                Set<PersistentMemberID> offlineMembers = membershipView.getOfflineMembers();
                if (logger.isDebugEnabled()) {
                    logger.debug("We didn't host the bucket. Checking redundancy level before creating the bucket. Redundancy={} offline members={}", redundancy, offlineMembers);
                }
                if (offlineMembers != null && !offlineMembers.isEmpty() && redundancy == -1) {
                    // If there are offline members, and no online members, throw
                    // an exception indicating that we can't create the bucket.
                    String message = LocalizedStrings.PartitionedRegionDataStore_DATA_OFFLINE_MESSAGE.toLocalizedString(partitionedRegion.getFullPath(), bid, offlineMembers);
                    throw new PartitionOfflineException((Set) offlineMembers, message);
                } else {
                    // an extra copy of the bucket.
                    if (offlineMembers != null) {
                        redundancy += offlineMembers.size();
                    }
                }
            }
        }
    }
    if (moveSource == null) {
        if (redundancy >= this.partitionedRegion.getRedundantCopies()) {
            if (logger.isDebugEnabled()) {
                logger.debug("grabFreeBucket: Bucket already meets redundancy level bucketId={}{}{}", this.partitionedRegion.getPRId(), PartitionedRegion.BUCKET_ID_SEPARATOR, bid);
            }
            return false;
        }
    }
    // is a bucket move, we allow the source to be on the same host.
    if (!PartitionedRegionBucketMgmtHelper.bucketIsAllowedOnThisHost(this, moveSource)) {
        if (logger.isDebugEnabled()) {
            logger.debug("grabFreeBucket: Bucket can't be recovered because we're enforcing that the bucket host must be unique {}{}{}", this.partitionedRegion.getPRId(), PartitionedRegion.BUCKET_ID_SEPARATOR, bid);
        }
        return false;
    }
    return true;
}
Also used : PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) PersistentMembershipView(org.apache.geode.internal.cache.persistence.PersistentMembershipView) PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID)

Aggregations

PartitionOfflineException (org.apache.geode.cache.persistence.PartitionOfflineException)1 PersistentMemberID (org.apache.geode.internal.cache.persistence.PersistentMemberID)1 PersistentMembershipView (org.apache.geode.internal.cache.persistence.PersistentMembershipView)1