Search in sources :

Example 6 with PrimaryBucketException

use of org.apache.geode.internal.cache.PrimaryBucketException in project geode by apache.

the class InvalidateMessage method operateOnPartitionedRegion.

/**
   * This method is called upon receipt and make the desired changes to the PartitionedRegion Note:
   * It is very important that this message does NOT cause any deadlocks as the sender will wait
   * indefinitely for the acknowledgement
   * 
   * @throws EntryExistsException
   * @throws DataLocationException
   */
@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion r, long startTime) throws EntryExistsException, DataLocationException {
    InternalDistributedMember eventSender = originalSender;
    if (eventSender == null) {
        eventSender = getSender();
    }
    final Object key = getKey();
    @Released final EntryEventImpl event = EntryEventImpl.create(r, getOperation(), key, null, /* newValue */
    getCallbackArg(), false, /* originRemote - false to force distribution in buckets */
    eventSender, true, /* generateCallbacks */
    false);
    try {
        if (this.versionTag != null) {
            this.versionTag.replaceNullIDs(getSender());
            event.setVersionTag(this.versionTag);
        }
        if (this.bridgeContext != null) {
            event.setContext(this.bridgeContext);
        }
        // Assert.assertTrue(eventId != null); bug #47235: region invalidation doesn't send event ids
        event.setEventId(eventId);
        event.setPossibleDuplicate(this.posDup);
        PartitionedRegionDataStore ds = r.getDataStore();
        boolean sendReply = true;
        // boolean failed = false;
        event.setInvokePRCallbacks(!notificationOnly);
        if (!notificationOnly) {
            Assert.assertTrue(ds != null, "This process should have storage for an item in " + this.toString());
            try {
                Integer bucket = Integer.valueOf(PartitionedRegionHelper.getHashKey(event));
                event.setCausedByMessage(this);
                r.getDataView().invalidateOnRemote(event, true, /* invokeCallbacks */
                false);
                this.versionTag = event.getVersionTag();
                if (logger.isTraceEnabled(LogMarker.DM)) {
                    logger.trace(LogMarker.DM, "{} invalidateLocally in bucket: {}, key: {}", getClass().getName(), bucket, key);
                }
            } catch (DataLocationException e) {
                ((ForceReattemptException) e).checkKey(event.getKey());
                throw e;
            } catch (EntryNotFoundException eee) {
                // failed = true;
                if (logger.isDebugEnabled()) {
                    logger.debug("{}: operateOnRegion caught EntryNotFoundException {}", getClass().getName(), eee.getMessage(), eee);
                }
                sendReply(getSender(), getProcessorId(), dm, new ReplyException(eee), r, startTime);
                // this prevents us from acking later
                sendReply = false;
            } catch (PrimaryBucketException pbe) {
                sendReply(getSender(), getProcessorId(), dm, new ReplyException(pbe), r, startTime);
                return false;
            }
        } else {
            event.setRegion(r);
            event.setOriginRemote(true);
            if (this.versionTag != null) {
                this.versionTag.replaceNullIDs(getSender());
                event.setVersionTag(this.versionTag);
            }
            if (this.filterInfo != null) {
                event.setLocalFilterInfo(this.filterInfo.getFilterInfo(dm.getDistributionManagerId()));
            }
            r.invokeInvalidateCallbacks(EnumListenerEvent.AFTER_INVALIDATE, event, r.isInitialized());
        }
        return sendReply;
    } finally {
        event.release();
    }
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DataLocationException(org.apache.geode.internal.cache.DataLocationException) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 7 with PrimaryBucketException

use of org.apache.geode.internal.cache.PrimaryBucketException in project geode by apache.

the class PartitionedTXRegionStub method getEntry.

public Entry getEntry(KeyInfo keyInfo, boolean allowTombstones) {
    PartitionedRegion pr = (PartitionedRegion) region;
    try {
        Entry e = pr.getEntryRemotely((InternalDistributedMember) state.getTarget(), keyInfo.getBucketId(), keyInfo.getKey(), false, allowTombstones);
        trackBucketForTx(keyInfo);
        return e;
    } catch (EntryNotFoundException enfe) {
        return null;
    } catch (TransactionException e) {
        RuntimeException re = getTransactionException(keyInfo, e);
        re.initCause(e.getCause());
        throw re;
    } catch (PrimaryBucketException e) {
        RuntimeException re = getTransactionException(keyInfo, e);
        re.initCause(e);
        throw re;
    } catch (ForceReattemptException e) {
        RuntimeException re;
        if (isBucketNotFoundException(e)) {
            re = new TransactionDataRebalancedException(LocalizedStrings.PartitionedRegion_TRANSACTIONAL_DATA_MOVED_DUE_TO_REBALANCING.toLocalizedString());
        } else {
            re = new TransactionDataNodeHasDepartedException(LocalizedStrings.PartitionedRegion_TRANSACTION_DATA_NODE_0_HAS_DEPARTED_TO_PROCEED_ROLLBACK_THIS_TRANSACTION_AND_BEGIN_A_NEW_ONE.toLocalizedString(state.getTarget()));
        }
        re.initCause(e);
        waitToRetry();
        throw re;
    }
}
Also used : Entry(org.apache.geode.cache.Region.Entry) TransactionException(org.apache.geode.cache.TransactionException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) TransactionDataNodeHasDepartedException(org.apache.geode.cache.TransactionDataNodeHasDepartedException)

Example 8 with PrimaryBucketException

use of org.apache.geode.internal.cache.PrimaryBucketException in project geode by apache.

the class FunctionStreamingResultCollector method waitForCacheOrFunctionException.

/**
   * Waits for the response from the recipient
   * 
   * @throws CacheException if the recipient threw a cache exception during message processing
   * @throws ForceReattemptException if the recipient left the distributed system before the
   *         response was received.
   * @throws RegionDestroyedException if the peer has closed its copy of the region
   */
public boolean waitForCacheOrFunctionException(long timeout) throws CacheException, ForceReattemptException {
    boolean timedOut = false;
    try {
        if (timeout == 0) {
            waitForRepliesUninterruptibly();
            timedOut = true;
        } else {
            timedOut = waitForRepliesUninterruptibly(timeout);
        }
    } catch (ReplyException e) {
        removeMember(e.getSender(), true);
        Throwable t = e.getCause();
        if (t instanceof CacheException) {
            throw (CacheException) t;
        } else if (t instanceof RegionDestroyedException) {
            throw (RegionDestroyedException) t;
        } else if (t instanceof ForceReattemptException) {
            throw new ForceReattemptException("Peer requests reattempt", t);
        } else if (t instanceof PrimaryBucketException) {
            throw new PrimaryBucketException("Peer failed primary test", t);
        }
        if (t instanceof CancelException) {
            this.execution.failedNodes.add(e.getSender().getId());
            String msg = "PartitionResponse got remote CacheClosedException, throwing PartitionedRegionCommunicationException";
            logger.debug("{}, throwing ForceReattemptException", msg, t);
            throw (CancelException) t;
        }
        if (e.getCause() instanceof FunctionException) {
            throw (FunctionException) e.getCause();
        }
        e.handleAsUnexpected();
    }
    return timedOut;
}
Also used : ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) CacheException(org.apache.geode.cache.CacheException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) FunctionException(org.apache.geode.cache.execute.FunctionException) CancelException(org.apache.geode.CancelException) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 9 with PrimaryBucketException

use of org.apache.geode.internal.cache.PrimaryBucketException in project geode by apache.

the class ParallelGatewaySenderQueue method destroyEventFromQueue.

private void destroyEventFromQueue(PartitionedRegion prQ, int bucketId, Object key) {
    boolean isPrimary = prQ.getRegionAdvisor().getBucketAdvisor(bucketId).isPrimary();
    BucketRegionQueue brq = getBucketRegionQueueByBucketId(prQ, bucketId);
    // before destroying a key from it
    try {
        if (brq != null) {
            brq.destroyKey(key);
        }
        stats.decQueueSize();
    } catch (EntryNotFoundException e) {
        if (!this.sender.isBatchConflationEnabled() && logger.isDebugEnabled()) {
            logger.debug("ParallelGatewaySenderQueue#remove: Got EntryNotFoundException while removing key {} for {} for bucket = {} for GatewaySender {}", key, this, bucketId, this.sender);
        }
    } catch (ForceReattemptException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Bucket :{} moved to other member", bucketId);
        }
    } catch (PrimaryBucketException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Primary bucket :{} moved to other member", bucketId);
        }
    } catch (RegionDestroyedException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Caught RegionDestroyedException attempting to remove key {} from bucket {} in {}", key, bucketId, prQ.getFullPath());
        }
    }
    addRemovedEvent(prQ, bucketId, key);
}
Also used : ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) BucketRegionQueue(org.apache.geode.internal.cache.BucketRegionQueue) AbstractBucketRegionQueue(org.apache.geode.internal.cache.AbstractBucketRegionQueue) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException)

Example 10 with PrimaryBucketException

use of org.apache.geode.internal.cache.PrimaryBucketException in project geode by apache.

the class PartitionedTXRegionStub method containsKey.

public boolean containsKey(KeyInfo keyInfo) {
    PartitionedRegion pr = (PartitionedRegion) region;
    try {
        boolean retVal = pr.containsKeyRemotely((InternalDistributedMember) state.getTarget(), keyInfo.getBucketId(), keyInfo.getKey());
        trackBucketForTx(keyInfo);
        return retVal;
    } catch (TransactionException e) {
        RuntimeException re = getTransactionException(keyInfo, e);
        re.initCause(e.getCause());
        throw re;
    } catch (PrimaryBucketException e) {
        RuntimeException re = getTransactionException(keyInfo, e);
        re.initCause(e);
        throw re;
    } catch (ForceReattemptException e) {
        if (isBucketNotFoundException(e)) {
            RuntimeException re = getTransactionException(keyInfo, e);
            re.initCause(e);
            throw re;
        }
        waitToRetry();
        RuntimeException re = new TransactionDataNodeHasDepartedException(LocalizedStrings.PartitionedRegion_TRANSACTION_DATA_NODE_0_HAS_DEPARTED_TO_PROCEED_ROLLBACK_THIS_TRANSACTION_AND_BEGIN_A_NEW_ONE.toLocalizedString(state.getTarget()));
        re.initCause(e);
        throw re;
    }
}
Also used : TransactionException(org.apache.geode.cache.TransactionException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) TransactionDataNodeHasDepartedException(org.apache.geode.cache.TransactionDataNodeHasDepartedException)

Aggregations

PrimaryBucketException (org.apache.geode.internal.cache.PrimaryBucketException)18 ForceReattemptException (org.apache.geode.internal.cache.ForceReattemptException)11 TransactionException (org.apache.geode.cache.TransactionException)8 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)7 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)6 ReplyException (org.apache.geode.distributed.internal.ReplyException)6 PartitionedRegionDataStore (org.apache.geode.internal.cache.PartitionedRegionDataStore)6 TransactionDataNodeHasDepartedException (org.apache.geode.cache.TransactionDataNodeHasDepartedException)5 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)4 EntryEventImpl (org.apache.geode.internal.cache.EntryEventImpl)4 InternalGemFireError (org.apache.geode.InternalGemFireError)3 CacheClosedException (org.apache.geode.cache.CacheClosedException)3 Region (org.apache.geode.cache.Region)3 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)3 TransactionDataRebalancedException (org.apache.geode.cache.TransactionDataRebalancedException)3 DataLocationException (org.apache.geode.internal.cache.DataLocationException)3 Released (org.apache.geode.internal.offheap.annotations.Released)3 IOException (java.io.IOException)2 CacheWriterException (org.apache.geode.cache.CacheWriterException)2 RegionFunctionContext (org.apache.geode.cache.execute.RegionFunctionContext)2