Search in sources :

Example 1 with TransactionTimeoutException

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

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

the class IgniteTxConfigCacheSelfTest method checkExplicitTxTimeout.

/**
 * Success if explicit tx fails.
 *
 * @param cache Cache name.
 * @param ignite Ignite instance.
 * @throws Exception If failed.
 */
protected void checkExplicitTxTimeout(final IgniteCache<Object, Object> cache, final Ignite ignite) throws Exception {
    try (final Transaction tx = ignite.transactions().txStart()) {
        assert tx != null;
        cache.put("key0", "val0");
        sleepForTxFailure();
        cache.put("key", "val");
        fail("Timeout exception must be thrown");
    } catch (CacheException e) {
        assert e.getCause() instanceof TransactionTimeoutException;
    }
    assertNull(ignite.transactions().tx());
    assert !cache.containsKey("key0");
    assert !cache.containsKey("key");
    // New transaction must succeed.
    try (final Transaction tx = ignite.transactions().txStart()) {
        cache.put("key", "val");
        tx.commit();
    }
    assert cache.containsKey("key");
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) CacheException(javax.cache.CacheException) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException)

Example 3 with TransactionTimeoutException

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

the class GridNearOptimisticTxPrepareFuture method prepare0.

/**
 * Initializes future.
 *
 * @param remap Remap flag.
 * @param topLocked {@code True} if thread already acquired lock preventing topology change.
 */
@Override
protected void prepare0(boolean remap, boolean topLocked) {
    try {
        boolean txStateCheck = remap ? tx.state() == PREPARING : tx.state(PREPARING);
        if (!txStateCheck) {
            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;
        }
        IgniteTxEntry singleWrite = tx.singleWrite();
        if (singleWrite != null)
            prepareSingle(singleWrite, topLocked, remap);
        else
            prepare(tx.writeEntries(), topLocked, remap);
        markInitialized();
    } catch (TransactionTimeoutException e) {
        onError(e, false);
    }
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException)

Example 4 with TransactionTimeoutException

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

the class IgniteCacheQueryNodeRestartSelfTest2 method testRestarts.

/**
 * @throws Exception If failed.
 */
@Ignore("https://issues.apache.org/jira/browse/IGNITE-10917")
@Test
public void testRestarts() throws Exception {
    int duration = 90 * 1000;
    int qryThreadNum = 4;
    // 4 + 2 = 6 nodes
    int restartThreadsNum = 2;
    final int nodeLifeTime = 2 * 1000;
    final int logFreq = 10;
    startGridsMultiThreaded(GRID_CNT);
    final AtomicIntegerArray locks = new AtomicIntegerArray(GRID_CNT);
    fillCaches();
    final List<List<?>> pRes = grid(0).cache("pu").query(new SqlFieldsQuery(PARTITIONED_QRY)).getAll();
    Thread.sleep(3000);
    assertEquals(pRes, grid(0).cache("pu").query(new SqlFieldsQuery(PARTITIONED_QRY)).getAll());
    final List<List<?>> rRes = grid(0).cache("co").query(new SqlFieldsQuery(REPLICATED_QRY)).getAll();
    assertFalse(pRes.isEmpty());
    assertFalse(rRes.isEmpty());
    final AtomicInteger qryCnt = new AtomicInteger();
    final AtomicBoolean qrysDone = new AtomicBoolean();
    IgniteInternalFuture<?> fut1 = multithreadedAsync(new CAX() {

        @Override
        public void applyx() throws IgniteCheckedException {
            final GridRandom rnd = new GridRandom();
            while (!qrysDone.get()) {
                int g;
                do {
                    g = rnd.nextInt(locks.length());
                } while (!locks.compareAndSet(g, 0, 1));
                try {
                    final IgniteEx grid = grid(g);
                    if (rnd.nextBoolean()) {
                        // Partitioned query.
                        final IgniteCache<?, ?> cache = grid.cache("pu");
                        final SqlFieldsQuery qry = new SqlFieldsQuery(PARTITIONED_QRY);
                        boolean smallPageSize = rnd.nextBoolean();
                        if (smallPageSize)
                            qry.setPageSize(3);
                        final IgniteCache<Integer, Company> co = grid.cache("co");
                        try {
                            runQuery(grid, new Runnable() {

                                @Override
                                public void run() {
                                    if (rnd.nextBoolean())
                                        // Get lock run test with open transaction.
                                        co.get(rnd.nextInt(COMPANY_CNT));
                                    assertEquals(pRes, cache.query(qry).getAll());
                                }
                            });
                        } catch (CacheException e) {
                            // Interruptions are expected here.
                            if (e.getCause() instanceof IgniteInterruptedCheckedException || e.getCause() instanceof InterruptedException || e.getCause() instanceof ClusterTopologyException || e.getCause() instanceof TransactionTimeoutException || e.getCause() instanceof TransactionException)
                                continue;
                            if (e.getCause() instanceof QueryCancelledException)
                                fail("Retry is expected");
                            if (!smallPageSize)
                                U.error(grid.log(), "On large page size must retry.", e);
                            assertTrue("On large page size must retry.", smallPageSize);
                            boolean failedOnRemoteFetch = false;
                            boolean failedOnInterruption = false;
                            for (Throwable th = e; th != null; th = th.getCause()) {
                                if (th instanceof InterruptedException) {
                                    failedOnInterruption = true;
                                    break;
                                }
                                if (!(th instanceof CacheException))
                                    continue;
                                if (th.getMessage() != null && th.getMessage().startsWith("Failed to fetch data from node:")) {
                                    failedOnRemoteFetch = true;
                                    break;
                                }
                            }
                            // Interruptions are expected here.
                            if (failedOnInterruption)
                                continue;
                            if (!failedOnRemoteFetch) {
                                U.error(grid.log(), "Must fail inside of GridResultPage.fetchNextPage or subclass.", e);
                                fail("Must fail inside of GridResultPage.fetchNextPage or subclass.");
                            }
                        }
                    } else {
                        // Replicated query.
                        IgniteCache<?, ?> cache = grid.cache("co");
                        assertEquals(rRes, cache.query(new SqlFieldsQuery(REPLICATED_QRY)).getAll());
                    }
                } finally {
                    // Clearing lock in final handler to avoid endless loop if exception is thrown.
                    locks.set(g, 0);
                    int c = qryCnt.incrementAndGet();
                    if (c % logFreq == 0)
                        info("Executed queries: " + c);
                }
            }
        }
    }, qryThreadNum, "query-thread");
    final AtomicInteger restartCnt = new AtomicInteger();
    final AtomicBoolean restartsDone = new AtomicBoolean();
    IgniteInternalFuture<?> fut2 = multithreadedAsync(new Callable<Object>() {

        @SuppressWarnings({ "BusyWait" })
        @Override
        public Object call() throws Exception {
            GridRandom rnd = new GridRandom();
            while (!restartsDone.get()) {
                int g;
                do {
                    g = rnd.nextInt(locks.length());
                } while (!locks.compareAndSet(g, 0, -1));
                try {
                    log.info("Stop node: " + g);
                    stopGrid(g);
                    Thread.sleep(rnd.nextInt(nodeLifeTime));
                    log.info("Start node: " + g);
                    startGrid(g);
                    Thread.sleep(rnd.nextInt(nodeLifeTime));
                } finally {
                    locks.set(g, 0);
                    int c = restartCnt.incrementAndGet();
                    if (c % logFreq == 0)
                        info("Node restarts: " + c);
                }
            }
            return true;
        }
    }, restartThreadsNum, "restart-thread");
    Thread.sleep(duration);
    info("Stopping..");
    restartsDone.set(true);
    try {
        fut2.get(20_000);
    } catch (IgniteFutureTimeoutCheckedException e) {
        U.dumpThreads(log);
        fail("Stopping restarts timeout.");
    }
    info("Restarts stopped.");
    qrysDone.set(true);
    // Query thread can stuck in next page waiting loop because all nodes are left.
    try {
        fut1.get(5_000);
    } catch (IgniteFutureTimeoutCheckedException ignored) {
        fut1.cancel();
    }
    info("Queries stopped.");
}
Also used : CacheException(javax.cache.CacheException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridRandom(org.apache.ignite.internal.util.GridRandom) TransactionException(org.apache.ignite.transactions.TransactionException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) List(java.util.List) AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray) IgniteCache(org.apache.ignite.IgniteCache) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) CacheException(javax.cache.CacheException) TransactionException(org.apache.ignite.transactions.TransactionException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) IgniteEx(org.apache.ignite.internal.IgniteEx) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) CAX(org.apache.ignite.internal.util.typedef.CAX) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException) Ignore(org.junit.Ignore) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with TransactionTimeoutException

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

the class TxRollbackOnTimeoutTest method testTimeoutOnPrimaryDhtNode0.

/**
 * @param prim Primary node.
 * @param conc Concurrency.
 * @param isolation Isolation.
 *
 * @throws Exception If failed.
 */
private void testTimeoutOnPrimaryDhtNode0(final Ignite prim, final TransactionConcurrency conc, final TransactionIsolation isolation) throws Exception {
    log.info("concurrency=" + conc + ", isolation=" + isolation);
    // Force timeout on primary DHT node by blocking DHT prepare response.
    toggleBlocking(GridDhtTxPrepareResponse.class, prim, true);
    final int val = 0;
    try {
        multithreaded(new Runnable() {

            @Override
            public void run() {
                try (Transaction txOpt = prim.transactions().txStart(conc, isolation, 300, 1)) {
                    prim.cache(CACHE_NAME).put(val, val);
                    txOpt.commit();
                }
            }
        }, 1, "tx-async-thread");
        fail();
    } catch (TransactionTimeoutException e) {
    // Expected.
    }
    toggleBlocking(GridDhtTxPrepareResponse.class, prim, false);
    AffinityTopologyVersion topVer = new AffinityTopologyVersion(GRID_CNT + 1, 0);
    for (Ignite ignite : G.allGrids()) ((IgniteEx) ignite).context().cache().context().partitionReleaseFuture(topVer).get(10_000);
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) Ignite(org.apache.ignite.Ignite)

Aggregations

TransactionTimeoutException (org.apache.ignite.transactions.TransactionTimeoutException)8 CacheException (javax.cache.CacheException)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 Transaction (org.apache.ignite.transactions.Transaction)4 TransactionDeadlockException (org.apache.ignite.transactions.TransactionDeadlockException)4 Ignite (org.apache.ignite.Ignite)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IgniteException (org.apache.ignite.IgniteException)2 ClusterTopologyException (org.apache.ignite.cluster.ClusterTopologyException)2 IgniteFutureTimeoutCheckedException (org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)2 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Random (java.util.Random)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1