Search in sources :

Example 1 with IgniteTxHeuristicCheckedException

use of org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException in project ignite by apache.

the class GridCacheAdapter method syncOp.

/**
 * @param op Cache operation.
 * @param <T> Return type.
 * @return Operation result.
 * @throws IgniteCheckedException If operation failed.
 */
@SuppressWarnings({ "ErrorNotRethrown", "AssignmentToCatchBlockParameter" })
@Nullable
private <T> T syncOp(SyncOp<T> op) throws IgniteCheckedException {
    checkJta();
    awaitLastFut();
    GridNearTxLocal tx = checkCurrentTx();
    if (tx == null || tx.implicit()) {
        TransactionConfiguration tCfg = CU.transactionConfiguration(ctx, ctx.kernalContext().config());
        CacheOperationContext opCtx = ctx.operationContextPerCall();
        int retries = opCtx != null && opCtx.noRetries() ? 1 : MAX_RETRIES;
        for (int i = 0; i < retries; i++) {
            tx = ctx.tm().newTx(true, op.single(), ctx.systemTx() ? ctx : null, ctx.mvccEnabled() ? PESSIMISTIC : OPTIMISTIC, ctx.mvccEnabled() ? REPEATABLE_READ : READ_COMMITTED, tCfg.getDefaultTxTimeout(), !ctx.skipStore(), ctx.mvccEnabled(), 0, null, false);
            assert tx != null;
            try {
                T t = op.op(tx);
                assert tx.done() : "Transaction is not done: " + tx;
                return t;
            } catch (IgniteInterruptedCheckedException | IgniteTxHeuristicCheckedException | NodeStoppingException | IgniteConsistencyViolationException e) {
                throw e;
            } catch (IgniteCheckedException e) {
                if (!(e instanceof IgniteTxRollbackCheckedException)) {
                    try {
                        tx.rollback();
                        if (!(e instanceof TransactionCheckedException))
                            e = new IgniteTxRollbackCheckedException("Transaction has been rolled back: " + tx.xid(), e);
                    } catch (IgniteCheckedException | AssertionError | RuntimeException e1) {
                        U.error(log, "Failed to rollback transaction (cache may contain stale locks): " + CU.txString(tx), e1);
                        if (e != e1)
                            e.addSuppressed(e1);
                    }
                }
                if (X.hasCause(e, ClusterTopologyCheckedException.class) && i != retries - 1) {
                    ClusterTopologyCheckedException topErr = e.getCause(ClusterTopologyCheckedException.class);
                    if (!(topErr instanceof ClusterTopologyServerNotFoundException)) {
                        AffinityTopologyVersion topVer = tx.topologyVersion();
                        assert topVer != null && topVer.topologyVersion() > 0 : tx;
                        AffinityTopologyVersion awaitVer = new AffinityTopologyVersion(topVer.topologyVersion() + 1, 0);
                        ctx.shared().exchange().affinityReadyFuture(awaitVer).get();
                        continue;
                    }
                }
                throw e;
            } catch (RuntimeException e) {
                try {
                    tx.rollback();
                } catch (IgniteCheckedException | AssertionError | RuntimeException e1) {
                    U.error(log, "Failed to rollback transaction " + CU.txString(tx), e1);
                }
                throw e;
            } finally {
                ctx.tm().resetContext();
                if (ctx.isNear())
                    ctx.near().dht().context().tm().resetContext();
            }
        }
        // Should not happen.
        throw new IgniteCheckedException("Failed to perform cache operation (maximum number of retries exceeded).");
    } else
        return op.op(tx);
}
Also used : TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) IgniteTxHeuristicCheckedException(org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BROADCAST(org.apache.ignite.internal.GridClosureCallMode.BROADCAST) IGNITE_CACHE_RETRIES_COUNT(org.apache.ignite.IgniteSystemProperties.IGNITE_CACHE_RETRIES_COUNT) LT(org.apache.ignite.internal.util.typedef.internal.LT) TransactionCheckedException(org.apache.ignite.internal.transactions.TransactionCheckedException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) IgniteConsistencyViolationException(org.apache.ignite.internal.processors.cache.distributed.near.consistency.IgniteConsistencyViolationException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with IgniteTxHeuristicCheckedException

use of org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException in project ignite by apache.

the class GridDistributedTxRemoteAdapter method commitRemoteTx.

/**
 * {@inheritDoc}
 */
@Override
public final void commitRemoteTx() throws IgniteCheckedException {
    if (optimistic())
        state(PREPARED);
    if (!state(COMMITTING)) {
        TransactionState state = state();
        // If other thread is doing commit, then no-op.
        if (state == COMMITTING || state == COMMITTED)
            return;
        if (log.isDebugEnabled())
            log.debug("Failed to set COMMITTING transaction state (will rollback): " + this);
        setRollbackOnly();
        if (!isSystemInvalidate())
            throw new IgniteCheckedException("Invalid transaction state for commit [state=" + state + ", tx=" + this + ']');
        rollbackRemoteTx();
        return;
    }
    try {
        commitIfLocked();
    } catch (IgniteTxHeuristicCheckedException e) {
        // Treat heuristic exception as critical.
        cctx.kernalContext().failure().process(new FailureContext(FailureType.CRITICAL_ERROR, e));
        throw e;
    }
}
Also used : TransactionState(org.apache.ignite.transactions.TransactionState) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) FailureContext(org.apache.ignite.failure.FailureContext) IgniteTxHeuristicCheckedException(org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteTxHeuristicCheckedException (org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException)2 IGNITE_CACHE_RETRIES_COUNT (org.apache.ignite.IgniteSystemProperties.IGNITE_CACHE_RETRIES_COUNT)1 TransactionConfiguration (org.apache.ignite.configuration.TransactionConfiguration)1 FailureContext (org.apache.ignite.failure.FailureContext)1 BROADCAST (org.apache.ignite.internal.GridClosureCallMode.BROADCAST)1 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)1 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)1 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)1 ClusterTopologyServerNotFoundException (org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)1 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)1 GridNearTxLocal (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)1 IgniteConsistencyViolationException (org.apache.ignite.internal.processors.cache.distributed.near.consistency.IgniteConsistencyViolationException)1 IgniteTxRollbackCheckedException (org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException)1 TransactionCheckedException (org.apache.ignite.internal.transactions.TransactionCheckedException)1 LT (org.apache.ignite.internal.util.typedef.internal.LT)1 TransactionState (org.apache.ignite.transactions.TransactionState)1 Nullable (org.jetbrains.annotations.Nullable)1