Search in sources :

Example 16 with ClusterTopologyException

use of org.apache.ignite.cluster.ClusterTopologyException in project ignite by apache.

the class GridTaskFailoverSelfTest method testFailover.

/**
     * @throws Exception If test failed.
     */
@SuppressWarnings("unchecked")
public void testFailover() throws Exception {
    Ignite ignite = startGrid();
    try {
        ignite.compute().localDeployTask(GridFailoverTestTask.class, GridFailoverTestTask.class.getClassLoader());
        ComputeTaskFuture<?> fut = ignite.compute().execute(GridFailoverTestTask.class.getName(), null);
        assert fut != null;
        fut.get();
        assert false : "Should never be reached due to exception thrown.";
    } catch (ClusterTopologyException e) {
        info("Received correct exception: " + e);
    } finally {
        stopGrid();
    }
}
Also used : Ignite(org.apache.ignite.Ignite) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException)

Example 17 with ClusterTopologyException

use of org.apache.ignite.cluster.ClusterTopologyException in project ignite by apache.

the class IgniteBinaryMetadataUpdateNodeRestartTest method testNodeRestart.

/**
     * @throws Exception If failed.
     */
public void testNodeRestart() throws Exception {
    for (int i = 0; i < 10; i++) {
        log.info("Iteration: " + i);
        client = false;
        startGridsMultiThreaded(SRVS);
        client = true;
        startGrid(SRVS);
        final AtomicBoolean stop = new AtomicBoolean();
        try {
            IgniteInternalFuture<?> restartFut = GridTestUtils.runAsync(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    while (!stop.get()) {
                        log.info("Start node.");
                        startGrid(SRVS + CLIENTS);
                        log.info("Stop node.");
                        stopGrid(SRVS + CLIENTS);
                    }
                    return null;
                }
            }, "restart-thread");
            final AtomicInteger idx = new AtomicInteger();
            IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

                @Override
                public Object call() throws Exception {
                    int threadIdx = idx.getAndIncrement();
                    int node = threadIdx % (SRVS + CLIENTS);
                    Ignite ignite = ignite(node);
                    log.info("Started thread: " + ignite.name());
                    Thread.currentThread().setName("update-thread-" + threadIdx + "-" + ignite.name());
                    IgniteCache<Object, Object> cache1 = ignite.cache(ATOMIC_CACHE);
                    IgniteCache<Object, Object> cache2 = ignite.cache(TX_CACHE);
                    ThreadLocalRandom rnd = ThreadLocalRandom.current();
                    while (!stop.get()) {
                        try {
                            cache1.put(new TestClass1(true), create(rnd.nextInt(20) + 1));
                            cache1.invoke(new TestClass1(true), new TestEntryProcessor(rnd.nextInt(20) + 1));
                            cache2.put(new TestClass1(true), create(rnd.nextInt(20) + 1));
                            cache2.invoke(new TestClass1(true), new TestEntryProcessor(rnd.nextInt(20) + 1));
                        } catch (CacheException | IgniteException e) {
                            log.info("Error: " + e);
                            if (X.hasCause(e, ClusterTopologyException.class)) {
                                ClusterTopologyException cause = X.cause(e, ClusterTopologyException.class);
                                if (cause.retryReadyFuture() != null)
                                    cause.retryReadyFuture().get();
                            }
                        }
                    }
                    return null;
                }
            }, 10, "update-thread");
            U.sleep(5_000);
            stop.set(true);
            restartFut.get();
            fut.get();
        } finally {
            stop.set(true);
            stopAllGrids();
        }
    }
}
Also used : IgniteCache(org.apache.ignite.IgniteCache) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) CacheException(javax.cache.CacheException) IgniteException(org.apache.ignite.IgniteException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Ignite(org.apache.ignite.Ignite) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException)

Example 18 with ClusterTopologyException

use of org.apache.ignite.cluster.ClusterTopologyException in project ignite by apache.

the class IgniteBenchmarkUtils method doInTransaction.

/**
     * @param igniteTx Ignite transaction.
     * @param txConcurrency Transaction concurrency.
     * @param clo Closure.
     * @return Result of closure execution.
     * @throws Exception If failed.
     */
public static <T> T doInTransaction(IgniteTransactions igniteTx, TransactionConcurrency txConcurrency, TransactionIsolation txIsolation, Callable<T> clo) throws Exception {
    while (true) {
        try (Transaction tx = igniteTx.txStart(txConcurrency, txIsolation)) {
            T res = clo.call();
            tx.commit();
            return res;
        } catch (CacheException e) {
            if (e.getCause() instanceof ClusterTopologyException) {
                ClusterTopologyException topEx = (ClusterTopologyException) e.getCause();
                topEx.retryReadyFuture().get();
            } else
                throw e;
        } catch (ClusterTopologyException e) {
            e.retryReadyFuture().get();
        } catch (TransactionRollbackException | TransactionOptimisticException ignore) {
        // Safe to retry right away.
        }
    }
}
Also used : TransactionOptimisticException(org.apache.ignite.transactions.TransactionOptimisticException) Transaction(org.apache.ignite.transactions.Transaction) CacheException(javax.cache.CacheException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException)

Example 19 with ClusterTopologyException

use of org.apache.ignite.cluster.ClusterTopologyException in project ignite by apache.

the class WebSessionFilter method handleCacheOperationException.

/**
     * Handles cache operation exception.
     * @param e Exception
     */
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
void handleCacheOperationException(Exception e) {
    IgniteFuture<?> retryFut = null;
    if (e instanceof IllegalStateException) {
        initCache();
        return;
    } else if (X.hasCause(e, IgniteClientDisconnectedException.class)) {
        IgniteClientDisconnectedException cause = X.cause(e, IgniteClientDisconnectedException.class);
        assert cause != null : e;
        retryFut = cause.reconnectFuture();
    } else if (X.hasCause(e, ClusterTopologyException.class)) {
        ClusterTopologyException cause = X.cause(e, ClusterTopologyException.class);
        assert cause != null : e;
        retryFut = cause.retryReadyFuture();
    }
    if (retryFut != null) {
        try {
            retryFut.get(retriesTimeout);
        } catch (IgniteException retryErr) {
            throw new IgniteException("Failed to wait for retry: " + retryErr);
        }
    }
}
Also used : IgniteException(org.apache.ignite.IgniteException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException)

Aggregations

ClusterTopologyException (org.apache.ignite.cluster.ClusterTopologyException)19 Ignite (org.apache.ignite.Ignite)9 IgniteException (org.apache.ignite.IgniteException)8 CacheException (javax.cache.CacheException)7 Transaction (org.apache.ignite.transactions.Transaction)6 HashMap (java.util.HashMap)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 UUID (java.util.UUID)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)3 IgniteClientDisconnectedCheckedException (org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)3 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)3 TransactionRollbackException (org.apache.ignite.transactions.TransactionRollbackException)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Random (java.util.Random)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2