Search in sources :

Example 1 with TransactionDeadlockException

use of org.apache.ignite.transactions.TransactionDeadlockException in project ignite by apache.

the class TxOptimisticDeadlockDetectionTest method doTestDeadlock.

/**
     * @throws Exception If failed.
     */
private void doTestDeadlock(final int txCnt, final boolean loc, boolean lockPrimaryFirst, final boolean clientTx, final IgniteClosure<Integer, Object> transformer) throws Exception {
    log.info(">>> Test deadlock [txCnt=" + txCnt + ", loc=" + loc + ", lockPrimaryFirst=" + lockPrimaryFirst + ", clientTx=" + clientTx + ", transformer=" + transformer.getClass().getName() + ']');
    TestCommunicationSpi.init(txCnt);
    final AtomicInteger threadCnt = new AtomicInteger();
    final CyclicBarrier barrier = new CyclicBarrier(txCnt);
    final AtomicReference<TransactionDeadlockException> deadlockErr = new AtomicReference<>();
    final List<List<Integer>> keySets = generateKeys(txCnt, loc, !lockPrimaryFirst);
    final Set<Integer> involvedKeys = new GridConcurrentHashSet<>();
    final Set<Integer> involvedLockedKeys = new GridConcurrentHashSet<>();
    final Set<IgniteInternalTx> involvedTxs = new GridConcurrentHashSet<>();
    IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(new Runnable() {

        @Override
        public void run() {
            int threadNum = threadCnt.incrementAndGet();
            Ignite ignite = loc ? ignite(0) : ignite(clientTx ? threadNum - 1 + txCnt : threadNum - 1);
            IgniteCache<Object, Integer> cache = ignite.cache(CACHE_NAME);
            List<Integer> keys = keySets.get(threadNum - 1);
            int txTimeout = 500 + txCnt * 100;
            try (Transaction tx = ignite.transactions().txStart(OPTIMISTIC, REPEATABLE_READ, txTimeout, 0)) {
                IgniteInternalTx tx0 = ((TransactionProxyImpl) tx).tx();
                involvedTxs.add(tx0);
                Integer key = keys.get(0);
                involvedKeys.add(key);
                Object k;
                log.info(">>> Performs put [node=" + ((IgniteKernal) ignite).localNode().id() + ", tx=" + tx.xid() + ", key=" + transformer.apply(key) + ']');
                cache.put(transformer.apply(key), 0);
                involvedLockedKeys.add(key);
                barrier.await();
                key = keys.get(1);
                ClusterNode primaryNode = ((IgniteCacheProxy) cache).context().affinity().primaryByKey(key, NONE);
                List<Integer> primaryKeys = primaryKeys(grid(primaryNode).cache(CACHE_NAME), 5, key + (100 * threadNum));
                Map<Object, Integer> entries = new HashMap<>();
                involvedKeys.add(key);
                entries.put(transformer.apply(key), 0);
                for (Integer i : primaryKeys) {
                    involvedKeys.add(i);
                    entries.put(transformer.apply(i), 1);
                    k = transformer.apply(i + 13);
                    involvedKeys.add(i + 13);
                    entries.put(k, 2);
                }
                log.info(">>> Performs put [node=" + ((IgniteKernal) ignite).localNode().id() + ", tx=" + tx.xid() + ", entries=" + entries + ']');
                cache.putAll(entries);
                tx.commit();
            } catch (Throwable e) {
                log.info("Expected exception: " + e);
                e.printStackTrace(System.out);
                // At least one stack trace should contain TransactionDeadlockException.
                if (hasCause(e, TransactionTimeoutException.class) && hasCause(e, TransactionDeadlockException.class)) {
                    if (deadlockErr.compareAndSet(null, cause(e, TransactionDeadlockException.class))) {
                        log.info("At least one stack trace should contain " + TransactionDeadlockException.class.getSimpleName());
                        e.printStackTrace(System.out);
                    }
                }
            }
        }
    }, loc ? 2 : txCnt, "tx-thread");
    try {
        fut.get();
    } catch (IgniteCheckedException e) {
        U.error(null, "Unexpected exception", e);
        fail();
    }
    U.sleep(1000);
    TransactionDeadlockException deadlockE = deadlockErr.get();
    assertNotNull("Failed to detect deadlock", deadlockE);
    boolean fail = false;
    // Check transactions, futures and entry locks state.
    for (int i = 0; i < NODES_CNT * 2; i++) {
        Ignite ignite = ignite(i);
        int cacheId = ((IgniteCacheProxy) ignite.cache(CACHE_NAME)).context().cacheId();
        GridCacheSharedContext<Object, Object> cctx = ((IgniteKernal) ignite).context().cache().context();
        IgniteTxManager txMgr = cctx.tm();
        Collection<IgniteInternalTx> activeTxs = txMgr.activeTransactions();
        for (IgniteInternalTx tx : activeTxs) {
            Collection<IgniteTxEntry> entries = tx.allEntries();
            for (IgniteTxEntry entry : entries) {
                if (entry.cacheId() == cacheId) {
                    fail = true;
                    U.error(log, "Transaction still exists: " + "\n" + tx.xidVersion() + "\n" + tx.nearXidVersion() + "\n nodeId=" + cctx.localNodeId() + "\n tx=" + tx);
                }
            }
        }
        Collection<IgniteInternalFuture<?>> futs = txMgr.deadlockDetectionFutures();
        assertTrue(futs.isEmpty());
        GridCacheAdapter<Object, Integer> intCache = internalCache(i, CACHE_NAME);
        GridCacheConcurrentMap map = intCache.map();
        for (Integer key : involvedKeys) {
            Object key0 = transformer.apply(key);
            KeyCacheObject keyCacheObj = intCache.context().toCacheKeyObject(key0);
            GridCacheMapEntry entry = map.getEntry(keyCacheObj);
            if (entry != null)
                assertNull("Entry still has locks " + entry, entry.mvccAllLocal());
        }
    }
    if (fail)
        fail("Some transactions still exist");
    // Check deadlock report
    String msg = deadlockE.getMessage();
    for (IgniteInternalTx tx : involvedTxs) assertTrue(msg.contains("[txId=" + tx.xidVersion() + ", nodeId=" + tx.nodeId() + ", threadId=" + tx.threadId() + ']'));
    for (Integer key : involvedKeys) {
        if (involvedLockedKeys.contains(key))
            assertTrue(msg.contains("[key=" + transformer.apply(key) + ", cache=" + CACHE_NAME + ']'));
        else
            assertFalse(msg.contains("[key=" + transformer.apply(key)));
    }
}
Also used : TransactionDeadlockException(org.apache.ignite.transactions.TransactionDeadlockException) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) List(java.util.List) ArrayList(java.util.ArrayList) Ignite(org.apache.ignite.Ignite) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridCacheConcurrentMap(org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap) IgniteCache(org.apache.ignite.IgniteCache) AtomicReference(java.util.concurrent.atomic.AtomicReference) CyclicBarrier(java.util.concurrent.CyclicBarrier) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Transaction(org.apache.ignite.transactions.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridCacheMapEntry(org.apache.ignite.internal.processors.cache.GridCacheMapEntry) Map(java.util.Map) GridCacheConcurrentMap(org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap) HashMap(java.util.HashMap)

Example 2 with TransactionDeadlockException

use of org.apache.ignite.transactions.TransactionDeadlockException in project ignite by apache.

the class TxPessimisticDeadlockDetectionTest method doTestDeadlock.

/**
     * @throws Exception If failed.
     */
private void doTestDeadlock(final int txCnt, final boolean loc, boolean lockPrimaryFirst, final boolean clientTx, final IgniteClosure<Integer, Object> transformer) throws Exception {
    log.info(">>> Test deadlock [txCnt=" + txCnt + ", loc=" + loc + ", lockPrimaryFirst=" + lockPrimaryFirst + ", clientTx=" + clientTx + ", transformer=" + transformer.getClass().getName() + ']');
    final AtomicInteger threadCnt = new AtomicInteger();
    final CyclicBarrier barrier = new CyclicBarrier(txCnt);
    final AtomicReference<TransactionDeadlockException> deadlockErr = new AtomicReference<>();
    final List<List<Integer>> keySets = generateKeys(txCnt, loc, !lockPrimaryFirst);
    final Set<Integer> involvedKeys = new GridConcurrentHashSet<>();
    final Set<Integer> involvedLockedKeys = new GridConcurrentHashSet<>();
    final Set<IgniteInternalTx> involvedTxs = new GridConcurrentHashSet<>();
    IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(new Runnable() {

        @Override
        public void run() {
            int threadNum = threadCnt.incrementAndGet();
            Ignite ignite = loc ? ignite(0) : ignite(clientTx ? threadNum - 1 + txCnt : threadNum - 1);
            IgniteCache<Object, Integer> cache = ignite.cache(CACHE_NAME);
            List<Integer> keys = keySets.get(threadNum - 1);
            int txTimeout = 500 + txCnt * 100;
            try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, txTimeout, 0)) {
                involvedTxs.add(((TransactionProxyImpl) tx).tx());
                Integer key = keys.get(0);
                involvedKeys.add(key);
                Object k;
                log.info(">>> Performs put [node=" + ((IgniteKernal) ignite).localNode() + ", tx=" + tx + ", key=" + transformer.apply(key) + ']');
                cache.put(transformer.apply(key), 0);
                involvedLockedKeys.add(key);
                barrier.await();
                key = keys.get(1);
                ClusterNode primaryNode = ((IgniteCacheProxy) cache).context().affinity().primaryByKey(key, NONE);
                List<Integer> primaryKeys = primaryKeys(grid(primaryNode).cache(CACHE_NAME), 5, key + (100 * threadNum));
                Map<Object, Integer> entries = new HashMap<>();
                involvedKeys.add(key);
                entries.put(transformer.apply(key), 0);
                for (Integer i : primaryKeys) {
                    involvedKeys.add(i);
                    entries.put(transformer.apply(i), 1);
                    k = transformer.apply(i + 13);
                    involvedKeys.add(i + 13);
                    entries.put(k, 2);
                }
                log.info(">>> Performs put [node=" + ((IgniteKernal) ignite).localNode() + ", tx=" + tx + ", entries=" + entries + ']');
                cache.putAll(entries);
                tx.commit();
            } catch (Throwable e) {
                // At least one stack trace should contain TransactionDeadlockException.
                if (hasCause(e, TransactionTimeoutException.class) && hasCause(e, TransactionDeadlockException.class)) {
                    if (deadlockErr.compareAndSet(null, cause(e, TransactionDeadlockException.class)))
                        U.error(log, "At least one stack trace should contain " + TransactionDeadlockException.class.getSimpleName(), e);
                }
            }
        }
    }, loc ? 2 : txCnt, "tx-thread");
    try {
        fut.get();
    } catch (IgniteCheckedException e) {
        U.error(null, "Unexpected exception", e);
        fail();
    }
    U.sleep(1000);
    TransactionDeadlockException deadlockE = deadlockErr.get();
    assertNotNull(deadlockE);
    boolean fail = false;
    // Check transactions, futures and entry locks state.
    for (int i = 0; i < NODES_CNT * 2; i++) {
        Ignite ignite = ignite(i);
        int cacheId = ((IgniteCacheProxy) ignite.cache(CACHE_NAME)).context().cacheId();
        GridCacheSharedContext<Object, Object> cctx = ((IgniteKernal) ignite).context().cache().context();
        IgniteTxManager txMgr = cctx.tm();
        Collection<IgniteInternalTx> activeTxs = txMgr.activeTransactions();
        for (IgniteInternalTx tx : activeTxs) {
            Collection<IgniteTxEntry> entries = tx.allEntries();
            for (IgniteTxEntry entry : entries) {
                if (entry.cacheId() == cacheId) {
                    fail = true;
                    U.error(log, "Transaction still exists: " + "\n" + tx.xidVersion() + "\n" + tx.nearXidVersion() + "\n nodeId=" + cctx.localNodeId() + "\n tx=" + tx);
                }
            }
        }
        Collection<IgniteInternalFuture<?>> futs = txMgr.deadlockDetectionFutures();
        assertTrue(futs.isEmpty());
        GridCacheAdapter<Object, Integer> intCache = internalCache(i, CACHE_NAME);
        GridCacheConcurrentMap map = intCache.map();
        for (Integer key : involvedKeys) {
            Object key0 = transformer.apply(key);
            KeyCacheObject keyCacheObj = intCache.context().toCacheKeyObject(key0);
            GridCacheMapEntry entry = map.getEntry(keyCacheObj);
            if (entry != null)
                assertNull("Entry still has locks " + entry, entry.mvccAllLocal());
        }
    }
    if (fail)
        fail("Some transactions still exist");
    // Check deadlock report
    String msg = deadlockE.getMessage();
    for (IgniteInternalTx tx : involvedTxs) assertTrue(msg.contains("[txId=" + tx.xidVersion() + ", nodeId=" + tx.nodeId() + ", threadId=" + tx.threadId() + ']'));
    for (Integer key : involvedKeys) {
        if (involvedLockedKeys.contains(key))
            assertTrue(msg.contains("[key=" + transformer.apply(key) + ", cache=" + CACHE_NAME + ']'));
        else
            assertFalse(msg.contains("[key=" + transformer.apply(key)));
    }
}
Also used : TransactionDeadlockException(org.apache.ignite.transactions.TransactionDeadlockException) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ArrayList(java.util.ArrayList) List(java.util.List) Ignite(org.apache.ignite.Ignite) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridCacheConcurrentMap(org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap) IgniteCache(org.apache.ignite.IgniteCache) AtomicReference(java.util.concurrent.atomic.AtomicReference) CyclicBarrier(java.util.concurrent.CyclicBarrier) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Transaction(org.apache.ignite.transactions.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridCacheMapEntry(org.apache.ignite.internal.processors.cache.GridCacheMapEntry) HashMap(java.util.HashMap) Map(java.util.Map) GridCacheConcurrentMap(org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap)

Example 3 with TransactionDeadlockException

use of org.apache.ignite.transactions.TransactionDeadlockException in project ignite by apache.

the class PlatformCache method convertException.

/**
 * {@inheritDoc}
 */
@Override
public Exception convertException(Exception e) {
    if (e instanceof CachePartialUpdateException)
        return new PlatformCachePartialUpdateException((CachePartialUpdateCheckedException) e.getCause(), platformCtx, keepBinary);
    if (e instanceof CachePartialUpdateCheckedException)
        return new PlatformCachePartialUpdateException((CachePartialUpdateCheckedException) e, platformCtx, keepBinary);
    if (e.getCause() instanceof EntryProcessorException)
        return (Exception) e.getCause();
    TransactionDeadlockException deadlockException = X.cause(e, TransactionDeadlockException.class);
    if (deadlockException != null)
        return deadlockException;
    TransactionTimeoutException timeoutException = X.cause(e, TransactionTimeoutException.class);
    if (timeoutException != null)
        return timeoutException;
    return super.convertException(e);
}
Also used : TransactionDeadlockException(org.apache.ignite.transactions.TransactionDeadlockException) EntryProcessorException(javax.cache.processor.EntryProcessorException) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) CachePartialUpdateException(org.apache.ignite.cache.CachePartialUpdateException) CachePartialUpdateCheckedException(org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException)

Example 4 with TransactionDeadlockException

use of org.apache.ignite.transactions.TransactionDeadlockException 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 5 with TransactionDeadlockException

use of org.apache.ignite.transactions.TransactionDeadlockException in project ignite by apache.

the class TxOptimisticDeadlockDetectionTest method doTestDeadlock.

/**
 * @throws Exception If failed.
 */
private void doTestDeadlock(final int txCnt, boolean lockPrimaryFirst, final boolean clientTx, Object startKey, boolean txOnPrimary) throws Exception {
    log.info(">>> Test deadlock [txCnt=" + txCnt + ", lockPrimaryFirst=" + lockPrimaryFirst + ", clientTx=" + clientTx + ", startKey=" + startKey + ", txOnPrimary=" + txOnPrimary + ']');
    TestCommunicationSpi.init(txCnt);
    final AtomicInteger threadCnt = new AtomicInteger();
    final AtomicReference<TransactionDeadlockException> deadlockErr = new AtomicReference<>();
    final List<List<Object>> keySets = generateKeys(txCnt, startKey, !lockPrimaryFirst, txOnPrimary);
    final Set<Object> involvedKeys = new GridConcurrentHashSet<>();
    final Set<Object> involvedLockedKeys = new GridConcurrentHashSet<>();
    final Set<IgniteInternalTx> involvedTxs = new GridConcurrentHashSet<>();
    IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(new Runnable() {

        @Override
        public void run() {
            int threadNum = threadCnt.incrementAndGet();
            Ignite ignite = ignite(clientTx ? threadNum - 1 + txCnt : threadNum - 1);
            IgniteCache<Object, Integer> cache = ignite.cache(CACHE_NAME).withAllowAtomicOpsInTx();
            List<Object> keys = keySets.get(threadNum - 1);
            int txTimeout = 1000 + txCnt * 200;
            try (Transaction tx = ignite.transactions().txStart(OPTIMISTIC, REPEATABLE_READ, txTimeout, 0)) {
                IgniteInternalTx tx0 = ((TransactionProxyImpl) tx).tx();
                involvedTxs.add(tx0);
                Object key = keys.get(0);
                involvedKeys.add(key);
                Object k;
                log.info(">>> Performs put [node=" + ((IgniteKernal) ignite).localNode().id() + ", tx=" + tx.xid() + ", key=" + key + ']');
                cache.put(key, 0);
                involvedLockedKeys.add(key);
                key = keys.get(1);
                ClusterNode primaryNode = ((IgniteCacheProxy) cache).context().affinity().primaryByKey(key, NONE);
                List<Object> primaryKeys = primaryKeys(grid(primaryNode).cache(CACHE_NAME), 5, incrementKey(key, (100 * threadNum)));
                Map<Object, Integer> entries = new LinkedHashMap<>();
                involvedKeys.add(key);
                for (Object o : primaryKeys) {
                    involvedKeys.add(o);
                    entries.put(o, 1);
                    k = incrementKey(o, 13);
                    involvedKeys.add(k);
                    entries.put(k, 2);
                }
                entries.put(key, 0);
                log.info(">>> Performs put [node=" + ((IgniteKernal) ignite).localNode().id() + ", tx=" + tx.xid() + ", entries=" + entries + ']');
                cache.putAll(entries);
                tx.commit();
            } catch (Throwable e) {
                log.info("Expected exception: " + e);
                String stackTrace = X.getFullStackTrace(e);
                log.info(stackTrace);
                assertTrue("DeadlockDetection hasn't executed at " + (threadNum - 1) + " node.", stackTrace.contains(TxDeadlockDetection.class.getName()));
                // At least one stack trace should contain TransactionDeadlockException.
                if (hasCause(e, TransactionTimeoutException.class) && hasCause(e, TransactionDeadlockException.class)) {
                    if (deadlockErr.compareAndSet(null, cause(e, TransactionDeadlockException.class))) {
                        log.info("At least one stack trace should contain " + TransactionDeadlockException.class.getSimpleName());
                        e.printStackTrace(System.out);
                    }
                }
            }
        }
    }, txCnt, "tx-thread");
    try {
        fut.get();
    } catch (IgniteCheckedException e) {
        U.error(null, "Unexpected exception", e);
        fail();
    }
    U.sleep(1000);
    TransactionDeadlockException deadlockE = deadlockErr.get();
    assertNotNull("Failed to detect deadlock", deadlockE);
    checkAllTransactionsCompleted(involvedKeys, NODES_CNT * 2, CACHE_NAME);
    // Check deadlock report
    String msg = deadlockE.getMessage();
    for (IgniteInternalTx tx : involvedTxs) assertTrue(msg.contains("[txId=" + tx.xidVersion() + ", nodeId=" + tx.nodeId() + ", threadId=" + tx.threadId() + ']'));
    for (Object key : involvedKeys) {
        if (involvedLockedKeys.contains(key))
            assertTrue(msg.contains("[key=" + key + ", cache=" + CACHE_NAME + ']'));
        else
            assertFalse(msg.contains("[key=" + key));
    }
}
Also used : TransactionDeadlockException(org.apache.ignite.transactions.TransactionDeadlockException) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ArrayList(java.util.ArrayList) List(java.util.List) Ignite(org.apache.ignite.Ignite) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCache(org.apache.ignite.IgniteCache) AtomicReference(java.util.concurrent.atomic.AtomicReference) Transaction(org.apache.ignite.transactions.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

TransactionDeadlockException (org.apache.ignite.transactions.TransactionDeadlockException)11 TransactionTimeoutException (org.apache.ignite.transactions.TransactionTimeoutException)11 Ignite (org.apache.ignite.Ignite)8 Transaction (org.apache.ignite.transactions.Transaction)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 IgniteCache (org.apache.ignite.IgniteCache)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)6 IgniteKernal (org.apache.ignite.internal.IgniteKernal)6 CyclicBarrier (java.util.concurrent.CyclicBarrier)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 GridConcurrentHashSet (org.apache.ignite.internal.util.GridConcurrentHashSet)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 LinkedHashMap (java.util.LinkedHashMap)2 CacheException (javax.cache.CacheException)2