Search in sources :

Example 1 with TxDeadlock

use of org.apache.ignite.internal.processors.cache.transactions.TxDeadlock 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)

Aggregations

HashSet (java.util.HashSet)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 ClusterTopologyException (org.apache.ignite.cluster.ClusterTopologyException)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)1 ClusterTopologyServerNotFoundException (org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)1 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)1 IgniteTxEntry (org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry)1 IgniteTxKey (org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey)1 TxDeadlock (org.apache.ignite.internal.processors.cache.transactions.TxDeadlock)1 TraceSurroundings (org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings)1 IgniteTxRollbackCheckedException (org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException)1 IgniteTxTimeoutCheckedException (org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException)1 IgniteBiClosure (org.apache.ignite.lang.IgniteBiClosure)1 TransactionDeadlockException (org.apache.ignite.transactions.TransactionDeadlockException)1 TransactionTimeoutException (org.apache.ignite.transactions.TransactionTimeoutException)1