Search in sources :

Example 1 with TransactionException

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

the class OpExecutorImpl method executeWithServerAffinity.

/**
   * execute the given op on the given server. If the server cannot be reached, sends a
   * TXFailoverOp, then retries the given op
   * 
   * @param loc the server to execute the op on
   * @param op the op to execute
   * @return the result of execution
   */
private Object executeWithServerAffinity(ServerLocation loc, Op op) {
    try {
        Object retVal = executeOnServer(loc, op, true, false);
        affinityRetryCount.set(0);
        return retVal;
    } catch (ServerConnectivityException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("caught exception while executing with affinity:{}", e.getMessage(), e);
        }
        if (!this.serverAffinityFailover || e instanceof ServerOperationException) {
            affinityRetryCount.set(0);
            throw e;
        }
        int retryCount = affinityRetryCount.get();
        if ((retryAttempts != -1 && retryCount >= retryAttempts) || retryCount > TX_RETRY_ATTEMPT) {
            // prevent
            // stack
            // overflow
            // fixes
            // bug
            // 46535
            affinityRetryCount.set(0);
            throw e;
        }
        affinityRetryCount.set(retryCount + 1);
    }
    this.affinityServerLocation.set(null);
    if (logger.isDebugEnabled()) {
        logger.debug("reset server affinity: attempting txFailover");
    }
    // send TXFailoverOp, so that new server can
    // do bootstrapping, then re-execute original op
    AbstractOp absOp = (AbstractOp) op;
    absOp.getMessage().setIsRetry();
    int transactionId = absOp.getMessage().getTransactionId();
    // so set it explicitly for TXFailoverOp
    try {
        TXFailoverOp.execute(this.pool, transactionId);
    } catch (TransactionException e) {
        // If this is the first operation in the transaction then
        // do not throw TransactionDataNodeHasDeparted back to the
        // user, re-try the op instead. fixes bug 44375. NOTE: TXFailoverOp
        // is sent even after first op, as it is not known if the first
        // operation has established a TXState already
        TXStateProxy txState = TXManagerImpl.getCurrentTXState();
        if (txState == null) {
            throw e;
        } else if (txState.operationCount() > 1) {
            throw e;
        }
    }
    if (op instanceof ExecuteRegionFunctionOpImpl) {
        op = new ExecuteRegionFunctionOpImpl((ExecuteRegionFunctionOpImpl) op, (byte) 1, /* isReExecute */
        new HashSet<String>());
        ((ExecuteRegionFunctionOpImpl) op).getMessage().setTransactionId(transactionId);
    } else if (op instanceof ExecuteFunctionOpImpl) {
        op = new ExecuteFunctionOpImpl((ExecuteFunctionOpImpl) op, (byte) 1);
        ((ExecuteFunctionOpImpl) op).getMessage().setTransactionId(transactionId);
    }
    return this.pool.execute(op);
}
Also used : ExecuteRegionFunctionOpImpl(org.apache.geode.cache.client.internal.ExecuteRegionFunctionOp.ExecuteRegionFunctionOpImpl) TransactionException(org.apache.geode.cache.TransactionException) TXStateProxy(org.apache.geode.internal.cache.TXStateProxy) ExecuteFunctionOpImpl(org.apache.geode.cache.client.internal.ExecuteFunctionOp.ExecuteFunctionOpImpl)

Example 2 with TransactionException

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

the class PartitionedRegion method getDataRegionForWrite.

@Override
public LocalRegion getDataRegionForWrite(KeyInfo keyInfo) {
    BucketRegion br = null;
    final Object entryKey = keyInfo.getKey();
    try {
        final int retryAttempts = calcRetry();
        // 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);
        }
        int count = 0;
        while (count <= retryAttempts) {
            try {
                PartitionedRegionDataStore ds = getDataStore();
                if (ds == null) {
                    throw new TransactionException(LocalizedStrings.PartitionedRegion_TX_ON_DATASTORE.toLocalizedString());
                }
                br = ds.getInitializedBucketWithKnownPrimaryForId(entryKey, bucketId);
                break;
            } catch (ForceReattemptException ignore) {
                // create a new bucket
                InternalDistributedMember member = createBucket(bucketId, 0, null);
                if (!getMyId().equals(member) && keyInfo.isCheckPrimary()) {
                    throw new PrimaryBucketException("Bucket " + bucketId + " is not primary. Current primary holder is " + member);
                }
                count++;
            }
        }
        Assert.assertTrue(br != null, "Could not create storage for Entry");
        if (keyInfo.isCheckPrimary()) {
            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));
    }
    return br;
}
Also used : TransactionException(org.apache.geode.cache.TransactionException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException)

Example 3 with TransactionException

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

the class TXStateProxyImpl method getTransactionException.

private TransactionException getTransactionException(KeyInfo keyInfo, GemFireException e) {
    if (isRealDealLocal() && !buckets.isEmpty() && !buckets.containsKey(keyInfo.getBucketId())) {
        TransactionException ex = new TransactionDataNotColocatedException(LocalizedStrings.PartitionedRegion_KEY_0_NOT_COLOCATED_WITH_TRANSACTION.toLocalizedString(keyInfo.getKey()));
        ex.initCause(e.getCause());
        return ex;
    }
    Throwable ex = e;
    while (ex != null) {
        if (ex instanceof PrimaryBucketException) {
            return new TransactionDataRebalancedException(LocalizedStrings.PartitionedRegion_TRANSACTIONAL_DATA_MOVED_DUE_TO_REBALANCING.toLocalizedString());
        }
        ex = ex.getCause();
    }
    return (TransactionException) e;
}
Also used : TransactionException(org.apache.geode.cache.TransactionException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException)

Example 4 with TransactionException

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

the class FetchEntryMessage method operateOnPartitionedRegion.

@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion r, long startTime) throws ForceReattemptException {
    // FetchEntryMessage is used in refreshing client caches during interest list recovery,
    // so don't be too verbose or hydra tasks may time out
    PartitionedRegionDataStore ds = r.getDataStore();
    EntrySnapshot val;
    if (ds != null) {
        try {
            KeyInfo keyInfo = r.getKeyInfo(key);
            val = (EntrySnapshot) r.getDataView().getEntryOnRemote(keyInfo, r, true);
            r.getPrStats().endPartitionMessagesProcessing(startTime);
            FetchEntryReplyMessage.send(getSender(), getProcessorId(), val, dm, null);
        } catch (TransactionException tex) {
            FetchEntryReplyMessage.send(getSender(), getProcessorId(), null, dm, new ReplyException(tex));
        } catch (PRLocallyDestroyedException pde) {
            FetchEntryReplyMessage.send(getSender(), getProcessorId(), null, dm, new ReplyException(new ForceReattemptException(LocalizedStrings.FetchEntryMessage_ENCOUNTERED_PRLOCALLYDESTROYED.toLocalizedString(), pde)));
        } catch (EntryNotFoundException enfe) {
            FetchEntryReplyMessage.send(getSender(), getProcessorId(), null, dm, new ReplyException(LocalizedStrings.FetchEntryMessage_ENTRY_NOT_FOUND.toLocalizedString(), enfe));
        } catch (PrimaryBucketException pbe) {
            FetchEntryReplyMessage.send(getSender(), getProcessorId(), null, dm, new ReplyException(pbe));
        } catch (ForceReattemptException pbe) {
            pbe.checkKey(key);
            // Slightly odd -- we're marshalling the retry to the peer on another host...
            FetchEntryReplyMessage.send(getSender(), getProcessorId(), null, dm, new ReplyException(pbe));
        } catch (DataLocationException e) {
            FetchEntryReplyMessage.send(getSender(), getProcessorId(), null, dm, new ReplyException(e));
        }
    } else {
        throw new InternalGemFireError(LocalizedStrings.FetchEntryMessage_FETCHENTRYMESSAGE_MESSAGE_SENT_TO_WRONG_MEMBER.toLocalizedString());
    }
    // response
    return false;
}
Also used : TransactionException(org.apache.geode.cache.TransactionException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) DataLocationException(org.apache.geode.internal.cache.DataLocationException) KeyInfo(org.apache.geode.internal.cache.KeyInfo) 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) EntrySnapshot(org.apache.geode.internal.cache.EntrySnapshot) InternalGemFireError(org.apache.geode.InternalGemFireError)

Example 5 with TransactionException

use of org.apache.geode.cache.TransactionException 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)

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