Search in sources :

Example 61 with IgniteFutureTimeoutCheckedException

use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project gridgain by gridgain.

the class CacheGetReadFromBackupFailoverTest method testFailover.

/**
 * @throws Exception If failed.
 */
@Test
public void testFailover() throws Exception {
    Ignite ignite = ignite(0);
    ignite.cluster().active(true);
    ThreadLocalRandom rnd = ThreadLocalRandom.current();
    try (IgniteDataStreamer<Object, Object> stmr = ignite.dataStreamer(TX_CACHE)) {
        for (int i = 0; i < KEYS_CNT; i++) stmr.addData(i, rnd.nextLong());
    }
    try (IgniteDataStreamer<Object, Object> stmr = ignite.dataStreamer(ATOMIC_CACHE)) {
        for (int i = 0; i < KEYS_CNT; i++) stmr.addData(i, rnd.nextLong());
    }
    AtomicInteger idx = new AtomicInteger(-1);
    AtomicInteger successGet = new AtomicInteger();
    IgniteInternalFuture fut = GridTestUtils.runAsync(() -> {
        ThreadLocalRandom rnd0 = ThreadLocalRandom.current();
        while (!stop.get()) {
            Ignite ig = null;
            while (ig == null) {
                int n = rnd0.nextInt(gridCount());
                if (idx.get() != n) {
                    try {
                        ig = ignite(n);
                    } catch (IgniteIllegalStateException e) {
                    // No-op.
                    }
                }
            }
            try {
                if (rnd.nextBoolean()) {
                    ig.cache(TX_CACHE).get(rnd0.nextLong(KEYS_CNT));
                    ig.cache(ATOMIC_CACHE).get(rnd0.nextLong(KEYS_CNT));
                } else {
                    ig.cache(TX_CACHE).getAll(rnd.longs(16, 0, KEYS_CNT).boxed().collect(Collectors.toSet()));
                    ig.cache(ATOMIC_CACHE).getAll(rnd.longs(16, 0, KEYS_CNT).boxed().collect(Collectors.toSet()));
                }
                successGet.incrementAndGet();
            } catch (CacheException e) {
                if (!X.hasCause(e, NodeStoppingException.class) && !X.hasCause(e, "Grid is in invalid state to perform this operation.", IgniteCheckedException.class))
                    throw e;
            }
        }
    }, "load-thread");
    long startTime = System.currentTimeMillis();
    while (System.currentTimeMillis() - startTime < 30 * 1000L) {
        int idx0 = idx.get();
        if (idx0 >= 0)
            startGrid(idx0);
        U.sleep(500);
        int next = rnd.nextInt(gridCount());
        idx.set(next);
        stopGrid(next);
        U.sleep(500);
    }
    stop.set(true);
    while (true) {
        try {
            fut.get(10_000);
            break;
        } catch (IgniteFutureTimeoutCheckedException e) {
            for (Ignite i : G.allGrids()) {
                IgniteEx ex = (IgniteEx) i;
                log.info(">>>> " + ex.context().localNodeId());
                GridCacheMvccManager mvcc = ex.context().cache().context().mvcc();
                for (GridCacheFuture<?> fut0 : mvcc.activeFutures()) {
                    log.info("activeFut - " + fut0);
                }
                for (GridCacheFuture<?> fut0 : mvcc.atomicFutures()) {
                    log.info("atomicFut - " + fut0);
                }
            }
        }
    }
    Assert.assertTrue(String.valueOf(successGet.get()), successGet.get() > 50);
    Throwable e = err.get();
    if (e != null) {
        log.error("Test failed", e);
        fail("Test failed");
    }
}
Also used : GridCacheMvccManager(org.apache.ignite.internal.processors.cache.GridCacheMvccManager) CacheException(javax.cache.CacheException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteIllegalStateException(org.apache.ignite.IgniteIllegalStateException) GridCacheFuture(org.apache.ignite.internal.processors.cache.GridCacheFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 62 with IgniteFutureTimeoutCheckedException

use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project gridgain by gridgain.

the class GridFutureAdapterSelfTest method checkChaining.

/**
 * @param exec Executor for chain callback.
 * @throws Exception If failed.
 */
@SuppressWarnings("ErrorNotRethrown")
private void checkChaining(ExecutorService exec) throws Exception {
    final CX1<IgniteInternalFuture<Object>, Object> passThrough = new CX1<IgniteInternalFuture<Object>, Object>() {

        @Override
        public Object applyx(IgniteInternalFuture<Object> f) throws IgniteCheckedException {
            return f.get();
        }
    };
    GridFutureAdapter<Object> fut = new GridFutureAdapter<>();
    IgniteInternalFuture<Object> chain = exec != null ? fut.chain(passThrough, exec) : fut.chain(passThrough);
    assertFalse(fut.isDone());
    assertFalse(chain.isDone());
    try {
        chain.get(20);
        fail("Expects timeout exception.");
    } catch (IgniteFutureTimeoutCheckedException e) {
        info("Expected timeout exception: " + e.getMessage());
    }
    fut.onDone("result");
    assertEquals("result", exec == null ? chain.get(1) : chain.get());
    // Test exception re-thrown.
    fut = new GridFutureAdapter<>();
    chain = exec != null ? fut.chain(passThrough, exec) : fut.chain(passThrough);
    fut.onDone(new ClusterGroupEmptyCheckedException("test exception"));
    try {
        chain.get();
        fail("Expects failed with exception.");
    } catch (ClusterGroupEmptyCheckedException e) {
        info("Expected exception: " + e.getMessage());
    }
    // Test error re-thrown.
    fut = new GridFutureAdapter<>();
    chain = exec != null ? fut.chain(passThrough, exec) : fut.chain(passThrough);
    try {
        fut.onDone(new StackOverflowError("test error"));
        if (exec == null)
            fail("Expects failed with error.");
    } catch (StackOverflowError e) {
        info("Expected error: " + e.getMessage());
    }
    try {
        chain.get();
        fail("Expects failed with error.");
    } catch (StackOverflowError e) {
        info("Expected error: " + e.getMessage());
    }
}
Also used : ClusterGroupEmptyCheckedException(org.apache.ignite.internal.cluster.ClusterGroupEmptyCheckedException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) CX1(org.apache.ignite.internal.util.typedef.CX1)

Example 63 with IgniteFutureTimeoutCheckedException

use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project gridgain by gridgain.

the class IgnitePersistentStoreDataStructuresTest method testSequenceAfterAutoactivation.

/**
 * @throws Exception If failed.
 */
@Test
public void testSequenceAfterAutoactivation() throws Exception {
    final String seqName = "testSequence";
    autoActivationEnabled = true;
    Ignite ignite = startGrids(2);
    ignite.cluster().active(true);
    ignite.atomicSequence(seqName, 0, true);
    stopAllGrids(true);
    final Ignite node = startGrids(2);
    IgniteInternalFuture fut = GridTestUtils.runAsync(() -> {
        while (true) {
            try {
                // Should not hang.
                node.atomicSequence(seqName, 0, false);
                break;
            } catch (IgniteException e) {
                // Can fail on not yet activated cluster. Retry until success.
                assertTrue(e.getMessage().contains("Can not perform the operation because the cluster is inactive"));
            }
        }
    });
    try {
        fut.get(10, TimeUnit.SECONDS);
    } catch (IgniteFutureTimeoutCheckedException e) {
        fut.cancel();
        fail("Ignite was stuck on getting the atomic sequence after autoactivation.");
    }
}
Also used : IgniteException(org.apache.ignite.IgniteException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) Ignite(org.apache.ignite.Ignite) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 64 with IgniteFutureTimeoutCheckedException

use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project gridgain by gridgain.

the class TxRecoveryWithConcurrentRollbackTest method testRecoveryNotBreakingTxAtomicityOnNearFail.

/**
 * The test enforces specific order in messages processing during concurrent tx rollback and tx recovery due to
 * node left.
 * <p>
 * Expected result: both DHT transactions produces same COMMITTED state on tx finish.
 */
@Test
public void testRecoveryNotBreakingTxAtomicityOnNearFail() throws Exception {
    backups = 1;
    persistence = false;
    final IgniteEx node0 = startGrids(3);
    node0.cluster().active(true);
    final Ignite client = startGrid("client");
    final IgniteCache<Object, Object> cache = client.cache(DEFAULT_CACHE_NAME);
    final List<Integer> g0Keys = primaryKeys(grid(0).cache(DEFAULT_CACHE_NAME), 100);
    final List<Integer> g1Keys = primaryKeys(grid(1).cache(DEFAULT_CACHE_NAME), 100);
    final List<Integer> g2BackupKeys = backupKeys(grid(2).cache(DEFAULT_CACHE_NAME), 100, 0);
    Integer k1 = null;
    Integer k2 = null;
    for (Integer key : g2BackupKeys) {
        if (g0Keys.contains(key))
            k1 = key;
        else if (g1Keys.contains(key))
            k2 = key;
        if (k1 != null && k2 != null)
            break;
    }
    assertNotNull(k1);
    assertNotNull(k2);
    List<IgniteInternalTx> txs0 = null;
    List<IgniteInternalTx> txs1 = null;
    CountDownLatch stripeBlockLatch = new CountDownLatch(1);
    int[] stripeHolder = new int[1];
    try (final Transaction tx = client.transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
        cache.put(k1, Boolean.TRUE);
        cache.put(k2, Boolean.TRUE);
        TransactionProxyImpl p = (TransactionProxyImpl) tx;
        p.tx().prepare(true);
        txs0 = txs(grid(0));
        txs1 = txs(grid(1));
        List<IgniteInternalTx> txs2 = txs(grid(2));
        assertTrue(txs0.size() == 1);
        assertTrue(txs1.size() == 1);
        assertTrue(txs2.size() == 2);
        // Prevent recovery request for grid1 tx branch to go to grid0.
        spi(grid(1)).blockMessages(GridCacheTxRecoveryRequest.class, grid(0).name());
        // Prevent finish(false) request processing on node0.
        spi(client).blockMessages(GridNearTxFinishRequest.class, grid(0).name());
        int stripe = U.safeAbs(p.tx().xidVersion().hashCode());
        stripeHolder[0] = stripe;
        // Blocks stripe processing for rollback request on node1.
        grid(1).context().pools().getStripedExecutorService().execute(stripe, () -> U.awaitQuiet(stripeBlockLatch));
        // Dummy task to ensure msg is processed.
        grid(1).context().pools().getStripedExecutorService().execute(stripe, () -> {
        });
        runAsync(() -> {
            spi(client).waitForBlocked();
            client.close();
            return null;
        });
        tx.rollback();
        fail();
    } catch (Exception ignored) {
    // Expected.
    }
    // Wait until tx0 is committed by recovery on node0.
    assertNotNull(txs0);
    try {
        txs0.get(0).finishFuture().get(3_000);
    } catch (IgniteFutureTimeoutCheckedException e) {
        // If timeout happens recovery message from g0 to g1 is mapped to the same stripe as near finish request.
        // We will complete latch to allow sequential processing.
        stripeBlockLatch.countDown();
        // Wait until sequential processing is finished.
        assertTrue("sequential processing", GridTestUtils.waitForCondition(() -> grid(1).context().pools().getStripedExecutorService().queueSize(stripeHolder[0]) == 0, 5_000));
        // Unblock recovery message from g1 to g0 because tx is in RECOVERY_FINISH state and waits for recovery end.
        spi(grid(1)).stopBlock();
        txs0.get(0).finishFuture().get();
        txs1.get(0).finishFuture().get();
        final TransactionState s1 = txs0.get(0).state();
        final TransactionState s2 = txs1.get(0).state();
        assertEquals(s1, s2);
        return;
    }
    // Release rollback request processing, triggering an attempt to rollback the transaction during recovery.
    stripeBlockLatch.countDown();
    // Wait until finish message is processed.
    assertTrue("concurrent processing", GridTestUtils.waitForCondition(() -> grid(1).context().pools().getStripedExecutorService().queueSize(stripeHolder[0]) == 0, 5_000));
    // Proceed with recovery on grid1 -> grid0. Tx0 is committed so tx1 also should be committed.
    spi(grid(1)).stopBlock();
    assertNotNull(txs1);
    txs1.get(0).finishFuture().get();
    final TransactionState s1 = txs0.get(0).state();
    final TransactionState s2 = txs1.get(0).state();
    assertEquals(s1, s2);
}
Also used : TransactionState(org.apache.ignite.transactions.TransactionState) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 65 with IgniteFutureTimeoutCheckedException

use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project gridgain by gridgain.

the class TxPartitionCounterStateConsistencyTest method testPartitionConsistencyCancelledRebalanceCoordinatorIsDemander.

/**
 * Tests reproduces the problem: if coordinator is a demander after activation and supplier has left, new
 * rebalance will finish and cause no partition inconsistencies.
 *
 * @throws Exception If failed.
 */
@Test
public void testPartitionConsistencyCancelledRebalanceCoordinatorIsDemander() throws Exception {
    backups = 2;
    Ignite crd = startGrids(SERVER_NODES);
    crd.cluster().active(true);
    int[] primaryParts = crd.affinity(DEFAULT_CACHE_NAME).primaryPartitions(crd.cluster().localNode());
    IgniteCache<Object, Object> cache = crd.cache(DEFAULT_CACHE_NAME);
    List<Integer> p1Keys = partitionKeys(cache, primaryParts[0], 2, 0);
    assertTrue(crd.affinity(DEFAULT_CACHE_NAME).isPrimary(crd.cluster().localNode(), p1Keys.get(0)));
    final String primName = crd.name();
    cache.put(p1Keys.get(0), 0);
    cache.put(p1Keys.get(1), 1);
    forceCheckpoint();
    List<Ignite> backups = Arrays.asList(grid(1), grid(2));
    assertFalse(backups.contains(crd));
    final String demanderName = backups.get(0).name();
    stopGrid(true, demanderName);
    // Create counters delta.
    cache.remove(p1Keys.get(1));
    stopAllGrids();
    crd = startNodeWithBlockingSupplying(0);
    startGrid(1);
    startNodeWithBlockingSupplying(2);
    TestRecordingCommunicationSpi spi0 = TestRecordingCommunicationSpi.spi(crd);
    TestRecordingCommunicationSpi spi2 = TestRecordingCommunicationSpi.spi(ignite(2));
    IgniteInternalFuture fut = GridTestUtils.runAsync(() -> {
        try {
            GridTestUtils.waitForCondition(() -> spi0.hasBlockedMessages() || spi2.hasBlockedMessages(), 10_000);
            // Stop before supplying rebalance. New rebalance must start with second backup as supplier
            // doing full rebalance.
            stopGrid(primName);
            spi2.stopBlock();
        } catch (Exception e) {
            fail();
        }
    });
    try {
        fut.get(10_000);
    } catch (IgniteFutureTimeoutCheckedException e) {
        for (Ignite ignite : G.allGrids()) {
            final PartitionUpdateCounter cntr = counter(primaryParts[0], ignite.name());
            log.info("Node: " + ignite.name() + ", cntr=" + cntr);
        }
        assertPartitionsSame(idleVerify(crd, DEFAULT_CACHE_NAME));
        fail("Rebalancing is expected");
    }
    awaitPartitionMapExchange();
    assertPartitionsSame(idleVerify(grid(demanderName), DEFAULT_CACHE_NAME));
}
Also used : PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) CacheInvalidStateException(org.apache.ignite.internal.processors.cache.CacheInvalidStateException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) Ignite(org.apache.ignite.Ignite) Test(org.junit.Test)

Aggregations

IgniteFutureTimeoutCheckedException (org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)74 Test (org.junit.Test)38 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)34 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)31 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)29 Ignite (org.apache.ignite.Ignite)18 IgniteEx (org.apache.ignite.internal.IgniteEx)17 IgniteException (org.apache.ignite.IgniteException)16 ArrayList (java.util.ArrayList)14 Transaction (org.apache.ignite.transactions.Transaction)14 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 Map (java.util.Map)10 CacheException (javax.cache.CacheException)10 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)10 CountDownLatch (java.util.concurrent.CountDownLatch)8 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)8 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 ClusterNode (org.apache.ignite.cluster.ClusterNode)7