Search in sources :

Example 6 with ClusterTopologyException

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

the class CacheAffinityCallSelfTest method testAffinityCallNoServerNode.

/**
     * @throws Exception If failed.
     */
public void testAffinityCallNoServerNode() throws Exception {
    fail("https://issues.apache.org/jira/browse/IGNITE-1741");
    startGridsMultiThreaded(SRVS + 1);
    final Integer key = 1;
    final Ignite client = grid(SRVS);
    assertTrue(client.configuration().isClientMode());
    final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            for (int i = 0; i < SRVS; ++i) stopGrid(i, false);
            return null;
        }
    });
    try {
        while (!fut.isDone()) client.compute().affinityCall(CACHE_NAME, key, new CheckCallable(key, null));
    } catch (ClusterTopologyException e) {
        log.info("Expected error: " + e);
    } finally {
        stopAllGrids();
    }
}
Also used : Ignite(org.apache.ignite.Ignite) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException)

Example 7 with ClusterTopologyException

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

the class IgniteCacheNearRestartRollbackSelfTest method updateCache.

/**
     * Updates the cache or rollback the update.
     *
     * @param ignite Ignite instance to use.
     * @param newVal the new value to put to the entries
     * @param invoke whether to use invokeAll() or putAll()
     * @param rollback whether to rollback the changes or commit
     * @param keys Collection of keys to update.
     */
private void updateCache(Ignite ignite, int newVal, boolean invoke, boolean rollback, Set<Integer> keys) {
    final IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
    if (rollback) {
        while (true) {
            try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
                updateEntries(cache, newVal, invoke, keys);
                tx.rollback();
                break;
            } catch (CacheException e) {
                if (e.getCause() instanceof ClusterTopologyException) {
                    ClusterTopologyException topEx = (ClusterTopologyException) e.getCause();
                    topEx.retryReadyFuture().get();
                } else
                    throw e;
            } catch (ClusterTopologyException e) {
                IgniteFuture<?> fut = e.retryReadyFuture();
                fut.get();
            } catch (TransactionRollbackException ignore) {
            // Safe to retry right away.
            }
        }
    } else
        updateEntries(cache, newVal, invoke, keys);
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) CacheException(javax.cache.CacheException) IgniteFuture(org.apache.ignite.lang.IgniteFuture) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException)

Example 8 with ClusterTopologyException

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

the class IgniteClientReconnectMassiveShutdownTest method massiveServersShutdown.

/**
     * @param stopType How tp stop node.
     * @throws Exception If any error occurs.
     */
private void massiveServersShutdown(final StopType stopType) throws Exception {
    clientMode = false;
    startGridsMultiThreaded(GRID_CNT);
    clientMode = true;
    startGridsMultiThreaded(GRID_CNT, CLIENT_GRID_CNT);
    final AtomicBoolean done = new AtomicBoolean();
    // Starting a cache dynamically.
    Ignite client = grid(GRID_CNT);
    assertTrue(client.configuration().isClientMode());
    final CacheConfiguration<String, Integer> cfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
    cfg.setCacheMode(PARTITIONED);
    cfg.setAtomicityMode(TRANSACTIONAL);
    cfg.setBackups(2);
    IgniteCache<String, Integer> cache = client.getOrCreateCache(cfg);
    assertNotNull(cache);
    HashMap<String, Integer> put = new HashMap<>();
    // Load some data.
    for (int i = 0; i < 10_000; i++) put.put(String.valueOf(i), i);
    cache.putAll(put);
    // Preparing client nodes and starting cache operations from them.
    final BlockingQueue<Integer> clientIdx = new LinkedBlockingQueue<>();
    for (int i = GRID_CNT; i < GRID_CNT + CLIENT_GRID_CNT; i++) clientIdx.add(i);
    final CountDownLatch latch = new CountDownLatch(CLIENT_GRID_CNT);
    IgniteInternalFuture<?> clientsFut = multithreadedAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            try {
                int idx = clientIdx.take();
                Ignite ignite = grid(idx);
                Thread.currentThread().setName("client-thread-" + ignite.name());
                assertTrue(ignite.configuration().isClientMode());
                IgniteCache<String, Integer> cache = ignite.getOrCreateCache(cfg);
                assertNotNull(cache);
                IgniteTransactions txs = ignite.transactions();
                Random rand = new Random();
                latch.countDown();
                while (!done.get()) {
                    try (Transaction tx = txs.txStart(PESSIMISTIC, REPEATABLE_READ)) {
                        cache.put(String.valueOf(rand.nextInt(10_000)), rand.nextInt(50_000));
                        tx.commit();
                    } catch (ClusterTopologyException ex) {
                        ex.retryReadyFuture().get();
                    } catch (IgniteException | CacheException e) {
                        if (X.hasCause(e, IgniteClientDisconnectedException.class)) {
                            IgniteClientDisconnectedException cause = X.cause(e, IgniteClientDisconnectedException.class);
                            assert cause != null;
                            cause.reconnectFuture().get();
                        } else if (X.hasCause(e, ClusterTopologyException.class)) {
                            ClusterTopologyException cause = X.cause(e, ClusterTopologyException.class);
                            assert cause != null;
                            cause.retryReadyFuture().get();
                        } else
                            throw e;
                    }
                }
                return null;
            } catch (Throwable e) {
                log.error("Unexpected error: " + e, e);
                throw e;
            }
        }
    }, CLIENT_GRID_CNT, "client-thread");
    try {
        if (!latch.await(30, SECONDS)) {
            log.warning("Failed to wait for for clients start.");
            U.dumpThreads(log);
            fail("Failed to wait for for clients start.");
        }
        // Killing a half of server nodes.
        final int srvsToKill = GRID_CNT / 2;
        final BlockingQueue<Integer> victims = new LinkedBlockingQueue<>();
        for (int i = 0; i < srvsToKill; i++) victims.add(i);
        final BlockingQueue<Integer> assassins = new LinkedBlockingQueue<>();
        for (int i = srvsToKill; i < GRID_CNT; i++) assassins.add(i);
        IgniteInternalFuture<?> srvsShutdownFut = multithreadedAsync(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                Thread.sleep(5_000);
                Ignite assassin = grid(assassins.take());
                assertFalse(assassin.configuration().isClientMode());
                Ignite victim = grid(victims.take());
                assertFalse(victim.configuration().isClientMode());
                log.info("Kill node [node=" + victim.name() + ", from=" + assassin.name() + ']');
                switch(stopType) {
                    case CLOSE:
                        victim.close();
                        break;
                    case FAIL_EVENT:
                        UUID nodeId = victim.cluster().localNode().id();
                        assassin.configuration().getDiscoverySpi().failNode(nodeId, null);
                        break;
                    case SIMULATE_FAIL:
                        ((TcpDiscoverySpi) victim.configuration().getDiscoverySpi()).simulateNodeFailure();
                        break;
                    default:
                        fail();
                }
                return null;
            }
        }, assassins.size(), "kill-thread");
        srvsShutdownFut.get();
        Thread.sleep(15_000);
        done.set(true);
        clientsFut.get();
        awaitPartitionMapExchange();
        for (int k = 0; k < 10_000; k++) {
            String key = String.valueOf(k);
            Object val = cache.get(key);
            for (int i = srvsToKill; i < GRID_CNT; i++) assertEquals(val, ignite(i).cache(DEFAULT_CACHE_NAME).get(key));
        }
    } finally {
        done.set(true);
    }
}
Also used : HashMap(java.util.HashMap) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) IgniteTransactions(org.apache.ignite.IgniteTransactions) Random(java.util.Random) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteCache(org.apache.ignite.IgniteCache) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) CacheException(javax.cache.CacheException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteException(org.apache.ignite.IgniteException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Transaction(org.apache.ignite.transactions.Transaction) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException)

Example 9 with ClusterTopologyException

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

the class GridCommonAbstractTest method doInTransaction.

/**
     * @param ignite Ignite instance.
     * @param concurrency Transaction concurrency.
     * @param isolation Transaction isolation.
     * @param clo Closure.
     * @return Result of closure execution.
     * @throws Exception If failed.
     */
protected static <T> T doInTransaction(Ignite ignite, TransactionConcurrency concurrency, TransactionIsolation isolation, Callable<T> clo) throws Exception {
    while (true) {
        try (Transaction tx = ignite.transactions().txStart(concurrency, isolation)) {
            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) {
            IgniteFuture<?> fut = e.retryReadyFuture();
            fut.get();
        } catch (TransactionRollbackException ignore) {
        // Safe to retry right away.
        }
    }
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) LT(org.apache.ignite.internal.util.typedef.internal.LT) CacheException(javax.cache.CacheException) IgniteFuture(org.apache.ignite.lang.IgniteFuture) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException)

Example 10 with ClusterTopologyException

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

the class IgniteComputeTopologyExceptionTest method testCorrectException.

/**
     * @throws Exception If failed.
     */
public void testCorrectException() throws Exception {
    Ignite ignite = ignite(0);
    IgniteCompute comp = ignite.compute(ignite.cluster().forRemotes()).withNoFailover();
    stopGrid(1);
    try {
        comp.call(new IgniteCallable<Object>() {

            @Override
            public Object call() throws Exception {
                fail("Should not be called.");
                return null;
            }
        });
        fail();
    } catch (ClusterTopologyException e) {
        log.info("Expected exception: " + e);
    }
}
Also used : Ignite(org.apache.ignite.Ignite) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) IgniteCompute(org.apache.ignite.IgniteCompute) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) 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