Search in sources :

Example 21 with TransactionException

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

the class PartitionedRegion method getDataRegionForRead.

@Override
public LocalRegion getDataRegionForRead(final KeyInfo keyInfo) {
    final Object entryKey = keyInfo.getKey();
    BucketRegion br;
    try {
        PartitionedRegionDataStore ds = getDataStore();
        if (ds == null) {
            throw new TransactionException(LocalizedStrings.PartitionedRegion_TX_ON_DATASTORE.toLocalizedString());
        }
        // TODO provide appropriate Operation and arg
        int bucketId = keyInfo.getBucketId();
        if (bucketId == KeyInfo.UNKNOWN_BUCKET) {
            bucketId = PartitionedRegionHelper.getHashKey(this, null, entryKey, keyInfo.getValue(), keyInfo.getCallbackArg());
            keyInfo.setBucketId(bucketId);
        }
        br = ds.getInitializedBucketWithKnownPrimaryForId(null, bucketId);
        if (keyInfo.isCheckPrimary()) {
            try {
                br.checkForPrimary();
            } catch (PrimaryBucketException pbe) {
                throw new TransactionDataRebalancedException(LocalizedStrings.PartitionedRegion_TRANSACTIONAL_DATA_MOVED_DUE_TO_REBALANCING.toLocalizedString(), pbe);
            }
        }
    } catch (RegionDestroyedException ignore) {
        // TODO: why is this purposely not wrapping the original cause?
        throw new TransactionDataNotColocatedException(LocalizedStrings.PartitionedRegion_KEY_0_NOT_COLOCATED_WITH_TRANSACTION.toLocalizedString(entryKey));
    } catch (ForceReattemptException ignore) {
        br = null;
    }
    return br;
}
Also used : TransactionException(org.apache.geode.cache.TransactionException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException)

Example 22 with TransactionException

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

the class PartitionedRegion method getFromBucket.

/**
   * @param requestingClient the client requesting the object, or null if not from a client
   * @param allowRetry if false then do not retry
   */
private Object getFromBucket(final InternalDistributedMember targetNode, int bucketId, final Object key, final Object aCallbackArgument, boolean disableCopyOnRead, boolean preferCD, ClientProxyMembershipID requestingClient, EntryEventImpl clientEvent, boolean returnTombstones, boolean allowRetry) {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    final int retryAttempts = calcRetry();
    Object obj;
    // retry the get remotely until it finds the right node managing the bucket
    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);
            }
            retryNode = getNodeForBucketReadOrLoad(bucketId);
            // No storage found for bucket, early out preventing hot loop, bug 36819
            if (retryNode == null) {
                checkShutdown();
                return null;
            }
            continue;
        }
        final boolean isLocal = this.localMaxMemory > 0 && retryNode.equals(getMyId());
        try {
            if (isLocal) {
                obj = this.dataStore.getLocally(bucketId, key, aCallbackArgument, disableCopyOnRead, preferCD, requestingClient, clientEvent, returnTombstones, false);
            } else {
                if (this.haveCacheLoader) {
                    /* MergeGemXDHDFSToGFE -readoing from local bucket was disabled in GemXD */
                    if (null != (obj = getFromLocalBucket(bucketId, key, aCallbackArgument, disableCopyOnRead, preferCD, requestingClient, clientEvent, returnTombstones))) {
                        return obj;
                    }
                }
                obj = getRemotely(retryNode, bucketId, key, aCallbackArgument, preferCD, requestingClient, clientEvent, returnTombstones);
                // TODO: there should be better way than this one
                String name = Thread.currentThread().getName();
                if (name.startsWith("ServerConnection") && !getMyId().equals(retryNode)) {
                    setNetworkHopType(bucketId, (InternalDistributedMember) retryNode);
                }
            }
            return obj;
        } catch (PRLocallyDestroyedException pde) {
            if (isDebugEnabled) {
                logger.debug("getFromBucket Encountered PRLocallyDestroyedException", pde);
            }
            checkReadiness();
            if (allowRetry) {
                retryNode = getNodeForBucketReadOrLoad(bucketId);
            } else {
                // Only transactions set allowRetry to false,
                // fail the transaction here as region is destroyed.
                Throwable cause = pde.getCause();
                if (cause != null && cause instanceof RegionDestroyedException) {
                    throw (RegionDestroyedException) cause;
                } else {
                    // set the cause to RegionDestroyedException.
                    throw new RegionDestroyedException(toString(), getFullPath());
                }
            }
        } catch (ForceReattemptException prce) {
            prce.checkKey(key);
            checkReadiness();
            if (allowRetry) {
                InternalDistributedMember lastNode = retryNode;
                if (isDebugEnabled) {
                    logger.debug("getFromBucket: retry attempt: {} of {}", count, retryAttempts, prce);
                }
                retryNode = getNodeForBucketReadOrLoad(bucketId);
                if (lastNode.equals(retryNode)) {
                    if (retryTime == null) {
                        retryTime = new RetryTimeKeeper(this.retryTimeout);
                    }
                    if (retryTime.overMaximum()) {
                        break;
                    }
                    if (isDebugEnabled) {
                        logger.debug("waiting to retry node {}", retryNode);
                    }
                    retryTime.waitToRetryNode();
                }
            } else {
                // with transaction
                if (prce instanceof BucketNotFoundException) {
                    throw new TransactionDataRebalancedException(LocalizedStrings.PartitionedRegion_TRANSACTIONAL_DATA_MOVED_DUE_TO_REBALANCING.toLocalizedString(key), prce);
                }
                Throwable cause = prce.getCause();
                if (cause instanceof PrimaryBucketException) {
                    throw (PrimaryBucketException) cause;
                } else if (cause instanceof TransactionDataRebalancedException) {
                    throw (TransactionDataRebalancedException) cause;
                } else if (cause instanceof RegionDestroyedException) {
                    throw new TransactionDataRebalancedException(LocalizedStrings.PartitionedRegion_TRANSACTIONAL_DATA_MOVED_DUE_TO_REBALANCING.toLocalizedString(key), cause);
                } else {
                    // Should not see it currently, added to be protected against future changes.
                    throw new TransactionException("Failed to get key: " + key, prce);
                }
            }
        } catch (PrimaryBucketException notPrimary) {
            if (allowRetry) {
                if (isDebugEnabled) {
                    logger.debug("getFromBucket: {} on Node {} not primary", notPrimary.getLocalizedMessage(), retryNode);
                }
                getRegionAdvisor().notPrimary(bucketId, retryNode);
                retryNode = getNodeForBucketReadOrLoad(bucketId);
            } else {
                throw notPrimary;
            }
        }
        // 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.incGetOpsRetried();
        }
        this.prStats.incGetRetries();
        if (isDebugEnabled) {
            logger.debug("getFromBucket: Attempting to resend get to node {} after {} failed attempts", retryNode, count);
        }
    }
    // While
    // Fix for bug 36014
    PartitionedRegionDistributionException e = null;
    if (logger.isDebugEnabled()) {
        e = new PartitionedRegionDistributionException(LocalizedStrings.PartitionRegion_NO_VM_AVAILABLE_FOR_GET_IN_0_ATTEMPTS.toLocalizedString(count));
    }
    logger.warn(LocalizedMessage.create(LocalizedStrings.PartitionRegion_NO_VM_AVAILABLE_FOR_GET_IN_0_ATTEMPTS, count), e);
    return null;
}
Also used : RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) TransactionException(org.apache.geode.cache.TransactionException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException) PartitionedRegionDistributionException(org.apache.geode.cache.PartitionedRegionDistributionException)

Example 23 with TransactionException

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

the class PeerTXStateStub method afterCompletion.

@Override
public void afterCompletion(int status) {
    RemoteCommitResponse response = JtaAfterCompletionMessage.send(this.proxy.getCache(), this.proxy.getTxId().getUniqId(), getOriginatingMember(), status, this.target);
    try {
        this.proxy.getTxMgr().setTXState(null);
        this.commitMessage = response.waitForResponse();
        if (logger.isDebugEnabled()) {
            logger.debug("afterCompletion received commit response of {}", this.commitMessage);
        }
    } catch (Exception e) {
        throw new TransactionException(e);
    // TODO throw a better exception
    } finally {
        cleanup();
    }
}
Also used : RemoteCommitResponse(org.apache.geode.internal.cache.TXRemoteCommitMessage.RemoteCommitResponse) TransactionException(org.apache.geode.cache.TransactionException) ReliableReplyException(org.apache.geode.distributed.internal.ReliableReplyException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) TransactionException(org.apache.geode.cache.TransactionException) CommitConflictException(org.apache.geode.cache.CommitConflictException) ReplyException(org.apache.geode.distributed.internal.ReplyException) TransactionInDoubtException(org.apache.geode.cache.TransactionInDoubtException) CancelException(org.apache.geode.CancelException)

Example 24 with TransactionException

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

the class PartitionedTXRegionStub method containsValueForKey.

public boolean containsValueForKey(KeyInfo keyInfo) {
    PartitionedRegion pr = (PartitionedRegion) region;
    try {
        boolean retVal = pr.containsValueForKeyRemotely((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)

Example 25 with TransactionException

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

the class PartitionedTXRegionStub method postPutAll.

/**
   * Create PutAllPRMsgs for each bucket, and send them.
   * 
   * @param putallO DistributedPutAllOperation object.
   */
public void postPutAll(DistributedPutAllOperation putallO, VersionedObjectList successfulPuts, LocalRegion r) throws TransactionException {
    if (r.getCache().isCacheAtShutdownAll()) {
        throw new CacheClosedException("Cache is shutting down");
    }
    PartitionedRegion pr = (PartitionedRegion) r;
    final long startTime = PartitionedRegionStats.startTime();
    // build all the msgs by bucketid
    HashMap prMsgMap = putallO.createPRMessages();
    PutAllPartialResult partialKeys = new PutAllPartialResult(putallO.putAllDataSize);
    // this is rebuilt by this method
    successfulPuts.clear();
    Iterator itor = prMsgMap.entrySet().iterator();
    while (itor.hasNext()) {
        Map.Entry mapEntry = (Map.Entry) itor.next();
        Integer bucketId = (Integer) mapEntry.getKey();
        PutAllPRMessage prMsg = (PutAllPRMessage) mapEntry.getValue();
        pr.checkReadiness();
        try {
            VersionedObjectList versions = sendMsgByBucket(bucketId, prMsg, pr);
            // prMsg.saveKeySet(partialKeys);
            partialKeys.addKeysAndVersions(versions);
            successfulPuts.addAll(versions);
        } catch (PutAllPartialResultException pre) {
            // sendMsgByBucket applied partial keys
            partialKeys.consolidate(pre.getResult());
        } catch (Exception ex) {
            // If failed at other exception
            @Released EntryEventImpl firstEvent = prMsg.getFirstEvent(pr);
            try {
                partialKeys.saveFailedKey(firstEvent.getKey(), ex);
            } finally {
                firstEvent.release();
            }
        }
    }
    pr.prStats.endPutAll(startTime);
    if (partialKeys.hasFailure()) {
        pr.getCache().getLoggerI18n().info(LocalizedStrings.Region_PutAll_Applied_PartialKeys_0_1, new Object[] { pr.getFullPath(), partialKeys });
        if (putallO.isBridgeOperation()) {
            if (partialKeys.getFailure() instanceof CancelException) {
                throw (CancelException) partialKeys.getFailure();
            } else {
                throw new PutAllPartialResultException(partialKeys);
            }
        } else {
            if (partialKeys.getFailure() instanceof RuntimeException) {
                throw (RuntimeException) partialKeys.getFailure();
            } else {
                throw new RuntimeException(partialKeys.getFailure());
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) PutAllPartialResult(org.apache.geode.internal.cache.PutAllPartialResultException.PutAllPartialResult) CacheClosedException(org.apache.geode.cache.CacheClosedException) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) TransactionException(org.apache.geode.cache.TransactionException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) CacheClosedException(org.apache.geode.cache.CacheClosedException) TransactionDataNodeHasDepartedException(org.apache.geode.cache.TransactionDataNodeHasDepartedException) DataLocationException(org.apache.geode.internal.cache.DataLocationException) CancelException(org.apache.geode.CancelException) PutAllPartialResultException(org.apache.geode.internal.cache.PutAllPartialResultException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) BucketNotFoundException(org.apache.geode.internal.cache.BucketNotFoundException) PutAllPartialResultException(org.apache.geode.internal.cache.PutAllPartialResultException) Entry(org.apache.geode.cache.Region.Entry) PutAllPRMessage(org.apache.geode.internal.cache.partitioned.PutAllPRMessage) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Iterator(java.util.Iterator) CancelException(org.apache.geode.CancelException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

TransactionException (org.apache.geode.cache.TransactionException)31 TransactionDataRebalancedException (org.apache.geode.cache.TransactionDataRebalancedException)12 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)11 TransactionDataNotColocatedException (org.apache.geode.cache.TransactionDataNotColocatedException)9 ForceReattemptException (org.apache.geode.internal.cache.ForceReattemptException)9 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)9 PrimaryBucketException (org.apache.geode.internal.cache.PrimaryBucketException)9 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)7 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)7 LowMemoryException (org.apache.geode.cache.LowMemoryException)6 DistributedMember (org.apache.geode.distributed.DistributedMember)6 InternalCache (org.apache.geode.internal.cache.InternalCache)6 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)5 CacheWriterException (org.apache.geode.cache.CacheWriterException)5 UnsupportedOperationInTransactionException (org.apache.geode.cache.UnsupportedOperationInTransactionException)5 IOException (java.io.IOException)4 RollbackException (javax.transaction.RollbackException)4 CancelException (org.apache.geode.CancelException)4 CacheClosedException (org.apache.geode.cache.CacheClosedException)4 CommitConflictException (org.apache.geode.cache.CommitConflictException)4