Search in sources :

Example 1 with PartitionedRegionDistributionException

use of org.apache.geode.cache.PartitionedRegionDistributionException in project geode by apache.

the class PartitionedRegion method tryToSendOnePutAllMessage.

public VersionedObjectList tryToSendOnePutAllMessage(PutAllPRMessage prMsg, InternalDistributedMember currentTarget) throws DataLocationException {
    boolean putResult = false;
    VersionedObjectList versions = null;
    final boolean isLocal = (this.localMaxMemory > 0) && currentTarget.equals(getMyId());
    if (isLocal) {
        // local
        // It might throw retry exception when one key failed
        // InternalDS has to be set for each msg
        prMsg.initMessage(this, null, false, null);
        putResult = prMsg.doLocalPutAll(this, this.getDistributionManager().getDistributionManagerId(), 0L);
        versions = prMsg.getVersions();
    } else {
        PutAllPRMessage.PutAllResponse response = (PutAllPRMessage.PutAllResponse) prMsg.send(currentTarget, this);
        PutAllPRMessage.PutAllResult pr = null;
        if (response != null) {
            this.prStats.incPartitionMessagesSent();
            try {
                pr = response.waitForResult();
                putResult = pr.returnValue;
                versions = pr.versions;
            } catch (RegionDestroyedException rde) {
                if (logger.isDebugEnabled()) {
                    logger.debug("prMsg.send: caught RegionDestroyedException", rde);
                }
                throw new RegionDestroyedException(toString(), getFullPath());
            } catch (CacheException ce) {
                // Fix for bug 36014
                throw new PartitionedRegionDistributionException("prMsg.send on " + currentTarget + " failed", ce);
            }
        } else {
            // follow the same behavior of putRemotely()
            putResult = true;
        }
    }
    if (!putResult) {
        // retry exception when msg failed in waitForResult()
        ForceReattemptException fre = new ForceReattemptException("false result in PutAllMessage.send - retrying");
        fre.setHash(0);
        throw fre;
    }
    return versions;
}
Also used : PutAllPRMessage(org.apache.geode.internal.cache.partitioned.PutAllPRMessage) CacheException(org.apache.geode.cache.CacheException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) PartitionedRegionDistributionException(org.apache.geode.cache.PartitionedRegionDistributionException)

Example 2 with PartitionedRegionDistributionException

use of org.apache.geode.cache.PartitionedRegionDistributionException in project geode by apache.

the class PartitionedRegion method putRemotely.

/**
   * Puts the key/value pair into the remote target that is managing the key's bucket.
   * 
   * @param recipient the member to receive the message
   * @param event the event prompting this action
   * @param ifNew the mysterious ifNew parameter
   * @param ifOld the mysterious ifOld parameter
   * @return whether the operation succeeded
   * @throws PrimaryBucketException if the remote bucket was not the primary
   * @throws ForceReattemptException if the peer is no longer available
   */
public boolean putRemotely(final DistributedMember recipient, final EntryEventImpl event, boolean ifNew, boolean ifOld, Object expectedOldValue, boolean requireOldValue) throws PrimaryBucketException, ForceReattemptException {
    // boolean forceAck = basicGetWriter() != null
    // || getDistributionAdvisor().adviseNetWrite().size() > 0;
    long eventTime = event.getEventTime(0L);
    PutMessage.PutResponse response = (PutMessage.PutResponse) PutMessage.send(recipient, this, event, eventTime, ifNew, ifOld, expectedOldValue, requireOldValue);
    PutResult pr = null;
    if (response != null) {
        this.prStats.incPartitionMessagesSent();
        try {
            pr = response.waitForResult();
            event.setOperation(pr.op);
            event.setVersionTag(pr.versionTag);
            if (requireOldValue) {
                event.setOldValue(pr.oldValue, true);
            }
            return pr.returnValue;
        } catch (RegionDestroyedException rde) {
            if (logger.isDebugEnabled()) {
                logger.debug("putRemotely: caught RegionDestroyedException", rde);
            }
            throw new RegionDestroyedException(toString(), getFullPath());
        } catch (TransactionException te) {
            throw te;
        } catch (CacheException ce) {
            // Fix for bug 36014
            throw new PartitionedRegionDistributionException(LocalizedStrings.PartitionedRegion_PUTTING_ENTRY_ON_0_FAILED.toLocalizedString(recipient), ce);
        }
    }
    // ???:ezoerner:20080728 why return true if response was null?
    return true;
}
Also used : TransactionException(org.apache.geode.cache.TransactionException) CacheException(org.apache.geode.cache.CacheException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) PartitionedRegionDistributionException(org.apache.geode.cache.PartitionedRegionDistributionException) PutResult(org.apache.geode.internal.cache.partitioned.PutMessage.PutResult) PutMessage(org.apache.geode.internal.cache.partitioned.PutMessage)

Example 3 with PartitionedRegionDistributionException

use of org.apache.geode.cache.PartitionedRegionDistributionException in project geode by apache.

the class PartitionedRegion method invalidateInBucket.

/**
   * Invalidate the entry in the bucket identified by the key
   */
void invalidateInBucket(final EntryEventImpl event) throws EntryNotFoundException {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    final Integer bucketId = event.getKeyInfo().getBucketId();
    assert bucketId != KeyInfo.UNKNOWN_BUCKET;
    final InternalDistributedMember targetNode = getOrCreateNodeForBucketWrite(bucketId, null);
    final int retryAttempts = calcRetry();
    int count = 0;
    RetryTimeKeeper retryTime = null;
    InternalDistributedMember retryNode = targetNode;
    while (count <= retryAttempts) {
        // It's possible this is a GemFire thread e.g. ServerConnection
        // which got to this point because of a distributed system shutdown or
        // region closure which uses interrupt to break any sleep() or wait()
        // calls
        // e.g. waitForPrimary or waitForBucketRecovery
        checkShutdown();
        if (retryNode == null) {
            checkReadiness();
            if (retryTime == null) {
                retryTime = new RetryTimeKeeper(this.retryTimeout);
            }
            try {
                retryNode = getOrCreateNodeForBucketWrite(bucketId, retryTime);
            } catch (TimeoutException ignore) {
                if (getRegionAdvisor().isStorageAssignedForBucket(bucketId)) {
                    // bucket no longer exists
                    throw new EntryNotFoundException(LocalizedStrings.PartitionedRegion_ENTRY_NOT_FOUND_FOR_KEY_0.toLocalizedString(event.getKey()));
                }
                // fall out to failed exception
                break;
            }
            if (retryNode == null) {
                checkEntryNotFound(event.getKey());
            }
            continue;
        }
        final boolean isLocal = (this.localMaxMemory > 0) && retryNode.equals(getMyId());
        try {
            if (isLocal) {
                event.setInvokePRCallbacks(true);
                this.dataStore.invalidateLocally(bucketId, event);
            } else {
                invalidateRemotely(retryNode, bucketId, event);
            }
            return;
        } catch (ConcurrentCacheModificationException e) {
            if (isDebugEnabled) {
                logger.debug("invalidateInBucket: caught concurrent cache modification exception", e);
            }
            event.isConcurrencyConflict(true);
            if (isDebugEnabled) {
                logger.debug("ConcurrentCacheModificationException received for invalidateInBucket for bucketId: {}{}{} for event: {}  No reattampt is done, returning from here", getPRId(), BUCKET_ID_SEPARATOR, bucketId, event);
            }
            return;
        } catch (ForceReattemptException prce) {
            prce.checkKey(event.getKey());
            if (isDebugEnabled) {
                logger.debug("invalidateInBucket: retry attempt:{} of {}", count, retryAttempts, prce);
            }
            checkReadiness();
            InternalDistributedMember lastNode = retryNode;
            retryNode = getOrCreateNodeForBucketWrite(bucketId, retryTime);
            if (lastNode.equals(retryNode)) {
                if (retryTime == null) {
                    retryTime = new RetryTimeKeeper(this.retryTimeout);
                }
                if (retryTime.overMaximum()) {
                    break;
                }
                retryTime.waitToRetryNode();
            }
            event.setPossibleDuplicate(true);
        } catch (PrimaryBucketException notPrimary) {
            if (isDebugEnabled) {
                logger.debug("invalidateInBucket {} on Node {} not primary", notPrimary.getLocalizedMessage(), retryNode);
            }
            getRegionAdvisor().notPrimary(bucketId, retryNode);
            retryNode = getOrCreateNodeForBucketWrite(bucketId, retryTime);
        }
        count++;
        if (count == 1) {
            this.prStats.incInvalidateOpsRetried();
        }
        this.prStats.incInvalidateRetries();
        if (isDebugEnabled) {
            logger.debug("invalidateInBucket: Attempting to resend invalidate to node {} after {} failed attempts", retryNode, count);
        }
    }
    // while
    // No target was found
    PartitionedRegionDistributionException e = new PartitionedRegionDistributionException(LocalizedStrings.PartitionedRegion_NO_VM_AVAILABLE_FOR_INVALIDATE_IN_0_ATTEMPTS.toLocalizedString(// Fix for bug 36014
    count));
    if (!isDebugEnabled) {
        logger.warn(LocalizedMessage.create(LocalizedStrings.PartitionedRegion_NO_VM_AVAILABLE_FOR_INVALIDATE_IN_0_ATTEMPTS, count));
    } else {
        logger.warn(e.getMessage(), e);
    }
    throw e;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) PartitionedRegionDistributionException(org.apache.geode.cache.PartitionedRegionDistributionException) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) TimeoutException(org.apache.geode.cache.TimeoutException)

Example 4 with PartitionedRegionDistributionException

use of org.apache.geode.cache.PartitionedRegionDistributionException in project geode by apache.

the class PartitionedRegion method containsKeyInBucket.

boolean containsKeyInBucket(final InternalDistributedMember targetNode, final Integer bucketIdInt, final Object key, boolean valueCheck) {
    final int retryAttempts = calcRetry();
    if (logger.isDebugEnabled()) {
        logger.debug("containsKeyInBucket: {}{} ({}) from: {} bucketId={}", (valueCheck ? "ValueForKey key=" : "Key key="), key, key.hashCode(), targetNode, bucketStringForLogs(bucketIdInt));
    }
    boolean ret;
    int count = 0;
    RetryTimeKeeper retryTime = null;
    InternalDistributedMember retryNode = targetNode;
    while (count <= retryAttempts) {
        // Every continuation should check for DM cancellation
        if (retryNode == null) {
            checkReadiness();
            if (retryTime == null) {
                retryTime = new RetryTimeKeeper(this.retryTimeout);
            }
            if (retryTime.overMaximum()) {
                break;
            }
            retryNode = getOrCreateNodeForBucketRead(bucketIdInt);
            // No storage found for bucket, early out preventing hot loop, bug 36819
            if (retryNode == null) {
                // Prefer closed style exceptions over empty result
                checkShutdown();
                return false;
            }
            continue;
        }
        // retryNode != null
        try {
            final boolean loc = retryNode.equals(getMyId());
            if (loc) {
                if (valueCheck) {
                    ret = this.dataStore.containsValueForKeyLocally(bucketIdInt, key);
                } else {
                    ret = this.dataStore.containsKeyLocally(bucketIdInt, key);
                }
            } else {
                if (valueCheck) {
                    ret = containsValueForKeyRemotely(retryNode, bucketIdInt, key);
                } else {
                    ret = containsKeyRemotely(retryNode, bucketIdInt, key);
                }
            }
            return ret;
        } catch (PRLocallyDestroyedException pde) {
            if (logger.isDebugEnabled()) {
                logger.debug("containsKeyInBucket: Encountered PRLocallyDestroyedException", pde);
            }
            checkReadiness();
        } catch (ForceReattemptException prce) {
            prce.checkKey(key);
            if (logger.isDebugEnabled()) {
                logger.debug("containsKeyInBucket: retry attempt:{} of {}", count, retryAttempts, prce);
            }
            checkReadiness();
            InternalDistributedMember lastNode = retryNode;
            retryNode = getOrCreateNodeForBucketRead(bucketIdInt);
            if (lastNode.equals(retryNode)) {
                if (retryTime == null) {
                    retryTime = new RetryTimeKeeper(this.retryTimeout);
                }
                if (retryTime.overMaximum()) {
                    break;
                }
                retryTime.waitToRetryNode();
            }
        } catch (PrimaryBucketException notPrimary) {
            if (logger.isDebugEnabled()) {
                logger.debug("containsKeyInBucket {} on Node {} not primary", notPrimary.getLocalizedMessage(), retryNode);
            }
            getRegionAdvisor().notPrimary(bucketIdInt, retryNode);
            retryNode = getOrCreateNodeForBucketRead(bucketIdInt);
        } catch (RegionDestroyedException rde) {
            if (!rde.getRegionFullPath().equals(getFullPath())) {
                throw new RegionDestroyedException(toString(), getFullPath(), rde);
            }
        }
        // It's possible this is a GemFire thread e.g. ServerConnection
        // which got to this point because of a distributed system shutdown or
        // region closure which uses interrupt to break any sleep() or wait()
        // calls
        // e.g. waitForPrimary
        checkShutdown();
        count++;
        if (count == 1) {
            this.prStats.incContainsKeyValueOpsRetried();
        }
        this.prStats.incContainsKeyValueRetries();
    }
    StringId msg = null;
    if (valueCheck) {
        msg = LocalizedStrings.PartitionedRegion_NO_VM_AVAILABLE_FOR_CONTAINS_VALUE_FOR_KEY_IN_1_ATTEMPTS;
    } else {
        msg = LocalizedStrings.PartitionedRegion_NO_VM_AVAILABLE_FOR_CONTAINS_KEY_IN_1_ATTEMPTS;
    }
    Integer countInteger = count;
    // Fix for bug 36014
    PartitionedRegionDistributionException e = null;
    if (logger.isDebugEnabled()) {
        e = new PartitionedRegionDistributionException(msg.toLocalizedString(countInteger));
    }
    logger.warn(LocalizedMessage.create(msg, countInteger), e);
    return false;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) StringId(org.apache.geode.i18n.StringId) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException) PartitionedRegionDistributionException(org.apache.geode.cache.PartitionedRegionDistributionException)

Example 5 with PartitionedRegionDistributionException

use of org.apache.geode.cache.PartitionedRegionDistributionException in project geode by apache.

the class PartitionedRegion method sendInvalidateRegionMessage.

private void sendInvalidateRegionMessage(RegionEventImpl event) {
    final int retryAttempts = calcRetry();
    Throwable thr = null;
    int count = 0;
    while (count <= retryAttempts) {
        try {
            count++;
            Set recipients = getRegionAdvisor().adviseDataStore();
            ReplyProcessor21 response = InvalidatePartitionedRegionMessage.send(recipients, this, event);
            response.waitForReplies();
            thr = null;
            break;
        } catch (ReplyException e) {
            thr = e;
            if (!this.isClosed && !this.isDestroyed) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Invalidating partitioned region caught exception", e);
                }
            }
        } catch (InterruptedException e) {
            thr = e;
            if (!cache.getCancelCriterion().isCancelInProgress()) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Invalidating partitioned region caught exception", e);
                }
            }
        }
    }
    if (thr != null) {
        PartitionedRegionDistributionException e = new PartitionedRegionDistributionException(LocalizedStrings.PartitionedRegion_INVALIDATING_REGION_CAUGHT_EXCEPTION.toLocalizedString(count));
        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage(), e);
        }
        throw e;
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ResultsSet(org.apache.geode.cache.query.internal.ResultsSet) PartitionedRegionDistributionException(org.apache.geode.cache.PartitionedRegionDistributionException) ReplyException(org.apache.geode.distributed.internal.ReplyException) ReplyProcessor21(org.apache.geode.distributed.internal.ReplyProcessor21)

Aggregations

PartitionedRegionDistributionException (org.apache.geode.cache.PartitionedRegionDistributionException)9 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)5 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 CacheException (org.apache.geode.cache.CacheException)3 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)3 PRLocallyDestroyedException (org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException)3 TimeoutException (org.apache.geode.cache.TimeoutException)2 TransactionException (org.apache.geode.cache.TransactionException)2 VersionedObjectList (org.apache.geode.internal.cache.tier.sockets.VersionedObjectList)2 ConcurrentCacheModificationException (org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 TransactionDataRebalancedException (org.apache.geode.cache.TransactionDataRebalancedException)1 ResultsSet (org.apache.geode.cache.query.internal.ResultsSet)1 ReplyException (org.apache.geode.distributed.internal.ReplyException)1 ReplyProcessor21 (org.apache.geode.distributed.internal.ReplyProcessor21)1 StringId (org.apache.geode.i18n.StringId)1 PutAllPRMessage (org.apache.geode.internal.cache.partitioned.PutAllPRMessage)1 PutMessage (org.apache.geode.internal.cache.partitioned.PutMessage)1