Search in sources :

Example 1 with IgniteBiClosure

use of org.apache.ignite.lang.IgniteBiClosure in project ignite by apache.

the class GridNearOptimisticTxPrepareFuture method onTimeout.

/**
     *
     */
@SuppressWarnings("ForLoopReplaceableByForEach")
private void onTimeout() {
    if (cctx.tm().deadlockDetectionEnabled()) {
        Set<IgniteTxKey> keys = null;
        if (keyLockFut != null)
            keys = new HashSet<>(keyLockFut.lockKeys);
        else {
            synchronized (this) {
                int size = futuresCountNoLock();
                for (int i = 0; i < size; i++) {
                    IgniteInternalFuture<GridNearTxPrepareResponse> 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;
                    }
                }
            }
        }
        add(new GridEmbeddedFuture<>(new IgniteBiClosure<TxDeadlock, Exception, GridNearTxPrepareResponse>() {

            @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=" + tx + ']', deadlock != null ? new TransactionDeadlockException(deadlock.toString(cctx)) : null);
                }
                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) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) IgniteTxTimeoutCheckedException(org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) TransactionDeadlockException(org.apache.ignite.transactions.TransactionDeadlockException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) 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 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)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 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