Search in sources :

Example 1 with NodeResponse

use of org.apache.geode.internal.cache.partitioned.ManageBucketMessage.NodeResponse in project geode by apache.

the class PRHARedundancyProvider method createBucketOnMember.

/**
   * Creates bucket with ID bucketId on targetNode.
   * 
   * @param bucketId
   * @param targetNMember
   * @param newBucketSize
   * @param forceCreation inform the targetMember it must attempt host the bucket, appropriately
   *        ignoring it's maximums
   * @return a response object
   */
public ManageBucketRsp createBucketOnMember(final int bucketId, final InternalDistributedMember targetNMember, final int newBucketSize, boolean forceCreation) {
    if (logger.isDebugEnabled()) {
        logger.debug("createBucketOnMember for bucketId={} member: {}{}", this.prRegion.bucketStringForLogs(bucketId), targetNMember, (forceCreation ? " forced" : ""));
    }
    if (!(targetNMember.equals(this.prRegion.getMyId()))) {
        // final StoppableReentrantReadWriteLock.StoppableReadLock isClosingReadLock;
        PartitionProfile pp = this.prRegion.getRegionAdvisor().getPartitionProfile(targetNMember);
        if (pp != null) {
        // isClosingReadLock = pp.getIsClosingReadLock(
        // this.prRegion.getCancelCriterion());
        } else {
            return ManageBucketRsp.NO;
        }
        try {
            // isClosingReadLock.lock(); // Grab the read lock, preventing any region closures
            // on this remote Node until this bucket is fully published, forcing the closing
            // Node to recognize any pre-natal buckets.
            NodeResponse response = ManageBucketMessage.send(targetNMember, this.prRegion, bucketId, newBucketSize, forceCreation);
            if (response.waitForAcceptance()) {
                if (logger.isDebugEnabled()) {
                    logger.debug("createBucketOnMember: Bucket creation succeed for bucketId={} on member = {}", this.prRegion.bucketStringForLogs(bucketId), targetNMember);
                }
                // lockList.add(isClosingReadLock);
                return ManageBucketRsp.YES;
            } else {
                if (logger.isDebugEnabled()) {
                    logger.debug("createBucketOnMember: Bucket creation failed for bucketId={} on member = {}", this.prRegion.bucketStringForLogs(bucketId), targetNMember);
                }
                // isClosingReadLock.unlock();
                return response.rejectedDueToInitialization() ? ManageBucketRsp.NO_INITIALIZING : ManageBucketRsp.NO;
            }
        } catch (PartitionOfflineException e) {
            throw e;
        } catch (VirtualMachineError err) {
            SystemFailure.initiateFailure(err);
            // now, so don't let this thread continue.
            throw err;
        } catch (Throwable e) {
            // Whenever you catch Error or Throwable, you must also
            // catch VirtualMachineError (see above). However, there is
            // _still_ a possibility that you are dealing with a cascading
            // error condition, so you also need to check to see if the JVM
            // is still usable:
            SystemFailure.checkFailure();
            if (e instanceof CancelException || (e.getCause() != null && (e.getCause() instanceof CancelException))) {
                // no need to log exceptions caused by cache closure
                return ManageBucketRsp.CLOSED;
            } else if (e instanceof ForceReattemptException) {
            // no log needed see bug 37569
            } else {
                logger.warn(LocalizedMessage.create(LocalizedStrings.PRHARedundancyProvider_EXCEPTION_CREATING_PARTITION_ON__0, targetNMember), e);
            }
            // isClosingReadLock.unlock();
            return ManageBucketRsp.NO;
        }
    } else {
        final PartitionedRegionDataStore prDS = this.prRegion.getDataStore();
        boolean bucketManaged = prDS != null && prDS.handleManageBucketRequest(bucketId, newBucketSize, this.prRegion.getMyId(), forceCreation);
        if (!bucketManaged) {
            if (logger.isDebugEnabled()) {
                logger.debug("createBucketOnMember: Local data store not able to accommodate the data for bucketId={}", this.prRegion.bucketStringForLogs(bucketId));
            }
        }
        return ManageBucketRsp.valueOf(bucketManaged);
    }
}
Also used : PartitionProfile(org.apache.geode.internal.cache.partitioned.RegionAdvisor.PartitionProfile) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) NodeResponse(org.apache.geode.internal.cache.partitioned.ManageBucketMessage.NodeResponse) CancelException(org.apache.geode.CancelException)

Aggregations

CancelException (org.apache.geode.CancelException)1 PartitionOfflineException (org.apache.geode.cache.persistence.PartitionOfflineException)1 NodeResponse (org.apache.geode.internal.cache.partitioned.ManageBucketMessage.NodeResponse)1 PartitionProfile (org.apache.geode.internal.cache.partitioned.RegionAdvisor.PartitionProfile)1