Search in sources :

Example 11 with TraceSurroundings

use of org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings in project ignite by apache.

the class GridNearOptimisticTxPrepareFuture method onError.

/**
 * @param e Error.
 * @param discoThread {@code True} if executed from discovery thread.
 */
private void onError(Throwable e, boolean discoThread) {
    try (TraceSurroundings ignored = support(span)) {
        if (e instanceof IgniteTxTimeoutCheckedException) {
            onTimeout();
            return;
        }
        if (X.hasCause(e, ClusterTopologyCheckedException.class) || X.hasCause(e, ClusterTopologyException.class)) {
            if (tx.onePhaseCommit()) {
                tx.markForBackupCheck();
                onComplete();
                return;
            }
        }
        if (ERR_UPD.compareAndSet(this, null, e))
            onComplete();
    }
}
Also used : ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) IgniteTxTimeoutCheckedException(org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException) TraceSurroundings(org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 12 with TraceSurroundings

use of org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings in project ignite by apache.

the class GridNearOptimisticTxPrepareFuture method onTimeout.

/**
 */
private void onTimeout() {
    try (TraceSurroundings ignored = MTC.support(span)) {
        if (cctx.tm().deadlockDetectionEnabled()) {
            Set<IgniteTxKey> keys = null;
            if (keyLockFut != null)
                keys = new HashSet<>(keyLockFut.lockKeys);
            else {
                compoundsReadLock();
                try {
                    int size = futuresCountNoLock();
                    for (int i = 0; i < size; i++) {
                        IgniteInternalFuture fut = future(i);
                        if (isMini(fut) && !fut.isDone()) {
                            MiniFuture miniFut = (MiniFuture) fut;
                            Collection<IgniteTxEntry> entries = miniFut.mapping().entries();
                            keys = U.newHashSet(entries.size());
                            for (IgniteTxEntry entry : entries) keys.add(entry.txKey());
                            break;
                        }
                    }
                } finally {
                    compoundsReadUnlock();
                }
            }
            add(new GridEmbeddedFuture<>(new IgniteBiClosure<TxDeadlock, Exception, Object>() {

                @Override
                public GridNearTxPrepareResponse apply(TxDeadlock deadlock, Exception e) {
                    if (e != null)
                        U.warn(log, "Failed to detect deadlock.", e);
                    else {
                        e = new IgniteTxTimeoutCheckedException("Failed to acquire lock within provided timeout for " + "transaction [timeout=" + tx.timeout() + ", tx=" + CU.txString(tx) + ']', deadlock != null ? new TransactionDeadlockException(deadlock.toString(cctx)) : null);
                        if (!ERR_UPD.compareAndSet(GridNearOptimisticTxPrepareFuture.this, null, e) && err instanceof IgniteTxTimeoutCheckedException) {
                            err = e;
                        }
                    }
                    onDone(null, e);
                    return null;
                }
            }, cctx.tm().detectDeadlock(tx, keys)));
        } else {
            ERR_UPD.compareAndSet(this, null, new IgniteTxTimeoutCheckedException("Failed to acquire lock " + "within provided timeout for transaction [timeout=" + tx.timeout() + ", tx=" + tx + ']'));
            onComplete();
        }
    }
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) TransactionDeadlockException(org.apache.ignite.transactions.TransactionDeadlockException) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) TraceSurroundings(org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) IgniteTxTimeoutCheckedException(org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) TransactionDeadlockException(org.apache.ignite.transactions.TransactionDeadlockException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) IgniteBiClosure(org.apache.ignite.lang.IgniteBiClosure) IgniteTxKey(org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey) IgniteTxTimeoutCheckedException(org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException) HashSet(java.util.HashSet) TxDeadlock(org.apache.ignite.internal.processors.cache.transactions.TxDeadlock)

Example 13 with TraceSurroundings

use of org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings in project ignite by apache.

the class GridNearPessimisticTxPrepareFuture method prepare.

/**
 * {@inheritDoc}
 */
@Override
public void prepare() {
    try (TraceSurroundings ignored = MTC.supportContinual(span = cctx.kernalContext().tracing().create(TX_NEAR_PREPARE, MTC.span()))) {
        if (!tx.state(PREPARING)) {
            if (tx.isRollbackOnly() || tx.setRollbackOnly()) {
                if (tx.remainingTime() == -1)
                    onDone(tx.timeoutException());
                else
                    onDone(tx.rollbackException());
            } else
                onDone(new IgniteCheckedException("Invalid transaction state for prepare " + "[state=" + tx.state() + ", tx=" + this + ']'));
            return;
        }
        try {
            tx.userPrepare(Collections.<IgniteTxEntry>emptyList());
            cctx.mvcc().addFuture(this);
            preparePessimistic();
        } catch (IgniteCheckedException e) {
            onDone(e);
        }
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) TraceSurroundings(org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings)

Example 14 with TraceSurroundings

use of org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings in project ignite by apache.

the class GridNearOptimisticSerializableTxPrepareFuture method onError.

/**
 * @param m Failed mapping.
 * @param e Error.
 */
private void onError(@Nullable GridDistributedTxMapping m, Throwable e) {
    try (TraceSurroundings ignored = MTC.support(span)) {
        if (X.hasCause(e, ClusterTopologyCheckedException.class) || X.hasCause(e, ClusterTopologyException.class)) {
            if (tx.onePhaseCommit()) {
                tx.markForBackupCheck();
                onComplete();
                return;
            }
        }
        if (e instanceof IgniteTxOptimisticCheckedException) {
            if (m != null)
                tx.removeMapping(m.primary().id());
        }
        prepareError(e);
    }
}
Also used : ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) TraceSurroundings(org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings) IgniteTxOptimisticCheckedException(org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 15 with TraceSurroundings

use of org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings in project ignite by apache.

the class GridNearOptimisticTxPrepareFutureAdapter method prepare.

/**
 * {@inheritDoc}
 */
@Override
public final void prepare() {
    try (TraceSurroundings ignored = MTC.supportContinual(span = cctx.kernalContext().tracing().create(TX_NEAR_PREPARE, MTC.span()))) {
        // Obtain the topology version to use.
        long threadId = Thread.currentThread().getId();
        AffinityTopologyVersion topVer = cctx.mvcc().lastExplicitLockTopologyVersion(threadId);
        // If there is another system transaction in progress, use it's topology version to prevent deadlock.
        if (topVer == null && tx.system()) {
            topVer = cctx.tm().lockedTopologyVersion(threadId, tx);
            if (topVer == null)
                topVer = tx.topologyVersionSnapshot();
        }
        if (topVer != null) {
            tx.topologyVersion(topVer);
            cctx.mvcc().addFuture(this);
            prepare0(false, true);
            return;
        }
        prepareOnTopology(false, null);
    }
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) TraceSurroundings(org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings)

Aggregations

TraceSurroundings (org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings)49 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)18 QueryCancelledException (org.apache.ignite.cache.query.QueryCancelledException)11 SQLException (java.sql.SQLException)10 IgniteException (org.apache.ignite.IgniteException)10 ArrayList (java.util.ArrayList)9 CacheException (javax.cache.CacheException)8 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)7 List (java.util.List)6 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)6 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)6 Collections.singletonList (java.util.Collections.singletonList)5 ClusterTopologyServerNotFoundException (org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)5 BatchUpdateException (java.sql.BatchUpdateException)4 CacheServerNotFoundException (org.apache.ignite.cache.CacheServerNotFoundException)4 QueryRetryException (org.apache.ignite.cache.query.QueryRetryException)4 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)4 IgniteClusterReadOnlyException (org.apache.ignite.internal.processors.cache.distributed.dht.IgniteClusterReadOnlyException)4 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)4 QueryContext (org.apache.ignite.internal.processors.query.h2.opt.QueryContext)4