Search in sources :

Example 41 with IgniteFutureTimeoutCheckedException

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

the class GridCachePartitionExchangeManager method onKernalStart.

/**
 * @param active Cluster state.
 * @param reconnect Reconnect flag.
 * @return Topology version of local join exchange if cluster is active.
 *         Topology version NONE if cluster is not active or reconnect.
 * @throws IgniteCheckedException If failed.
 */
public AffinityTopologyVersion onKernalStart(boolean active, boolean reconnect) throws IgniteCheckedException {
    for (ClusterNode n : cctx.discovery().remoteNodes()) cctx.versions().onReceived(n.id(), n.metrics().getLastDataVersion());
    DiscoveryLocalJoinData locJoin = cctx.discovery().localJoin();
    GridDhtPartitionsExchangeFuture fut = null;
    if (reconnect)
        reconnectExchangeFut = new GridFutureAdapter<>();
    if (active) {
        DiscoveryEvent discoEvt = locJoin.event();
        DiscoCache discoCache = locJoin.discoCache();
        GridDhtPartitionExchangeId exchId = initialExchangeId();
        fut = exchangeFuture(exchId, reconnect ? null : discoEvt, reconnect ? null : discoCache, null, null);
    } else if (reconnect)
        reconnectExchangeFut.onDone();
    new IgniteThread(cctx.igniteInstanceName(), exchWorker.name(), exchWorker).start();
    if (reconnect) {
        if (fut != null) {
            fut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {

                @Override
                public void apply(IgniteInternalFuture<AffinityTopologyVersion> fut) {
                    try {
                        fut.get();
                        for (CacheGroupContext grp : cctx.cache().cacheGroups()) grp.preloader().onInitialExchangeComplete(null);
                        reconnectExchangeFut.onDone();
                    } catch (IgniteCheckedException e) {
                        for (CacheGroupContext grp : cctx.cache().cacheGroups()) grp.preloader().onInitialExchangeComplete(e);
                        reconnectExchangeFut.onDone(e);
                    }
                }
            });
        }
    } else if (fut != null) {
        if (log.isDebugEnabled())
            log.debug("Beginning to wait on local exchange future: " + fut);
        boolean first = true;
        while (true) {
            try {
                fut.get(cctx.preloadExchangeTimeout());
                break;
            } catch (IgniteFutureTimeoutCheckedException ignored) {
                if (first) {
                    U.warn(log, "Failed to wait for initial partition map exchange. " + "Possible reasons are: " + U.nl() + "  ^-- Transactions in deadlock." + U.nl() + "  ^-- Long running transactions (ignore if this is the case)." + U.nl() + "  ^-- Unreleased explicit locks.");
                    first = false;
                } else
                    U.warn(log, "Still waiting for initial partition map exchange [fut=" + fut + ']');
            } catch (IgniteNeedReconnectException e) {
                throw e;
            } catch (Exception e) {
                if (fut.reconnectOnError(e))
                    throw new IgniteNeedReconnectException(cctx.localNode(), e);
                throw e;
            }
        }
        for (CacheGroupContext grp : cctx.cache().cacheGroups()) {
            if (locJoin.joinTopologyVersion().equals(grp.localStartVersion()))
                grp.preloader().onInitialExchangeComplete(null);
        }
        if (log.isDebugEnabled())
            log.debug("Finished waiting for initial exchange: " + fut.exchangeId());
        return fut.initialVersion();
    }
    return NONE;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) GridDhtPartitionExchangeId(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionExchangeId) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ClusterGroupEmptyException(org.apache.ignite.cluster.ClusterGroupEmptyException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteNeedReconnectException(org.apache.ignite.internal.IgniteNeedReconnectException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) IgniteThread(org.apache.ignite.thread.IgniteThread) DiscoveryLocalJoinData(org.apache.ignite.internal.managers.discovery.DiscoveryLocalJoinData) IgniteNeedReconnectException(org.apache.ignite.internal.IgniteNeedReconnectException)

Example 42 with IgniteFutureTimeoutCheckedException

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

the class GridContinuousProcessor method addNotification.

/**
 * @param nodeId ID of the node that started routine.
 * @param routineId Routine ID.
 * @param obj Notification object.
 * @param orderedTopic Topic for ordered notifications. If {@code null}, non-ordered message will be sent.
 * @param sync If {@code true} then waits for event acknowledgment.
 * @param msg If {@code true} then sent data is message.
 * @throws IgniteCheckedException In case of error.
 */
public void addNotification(UUID nodeId, final UUID routineId, @Nullable Object obj, @Nullable Object orderedTopic, boolean sync, boolean msg) throws IgniteCheckedException {
    assert nodeId != null;
    assert routineId != null;
    assert !msg || (obj instanceof Message || obj instanceof Collection) : obj;
    assert !nodeId.equals(ctx.localNodeId());
    if (processorStopped)
        return;
    final RemoteRoutineInfo info = rmtInfos.get(routineId);
    if (info != null) {
        assert info.interval == 0 || !sync;
        if (sync) {
            SyncMessageAckFuture fut = new SyncMessageAckFuture(nodeId);
            IgniteUuid futId = IgniteUuid.randomUuid();
            syncMsgFuts.put(futId, fut);
            try {
                sendNotification(nodeId, routineId, futId, obj instanceof Collection ? (Collection) obj : F.asList(obj), null, msg, null);
                info.hnd.onBatchAcknowledged(routineId, info.add(obj), ctx);
            } catch (IgniteCheckedException e) {
                syncMsgFuts.remove(futId);
                throw e;
            }
            while (true) {
                try {
                    fut.get(100, TimeUnit.MILLISECONDS);
                    break;
                } catch (IgniteFutureTimeoutCheckedException ignored) {
                    // in case left/fail event processing failed, hanged or delayed.
                    if (!ctx.discovery().alive(nodeId)) {
                        SyncMessageAckFuture fut0 = syncMsgFuts.remove(futId);
                        if (fut0 != null) {
                            ClusterTopologyCheckedException err = new ClusterTopologyCheckedException("Node left grid after receiving, but before processing the message [node=" + nodeId + "]");
                            fut0.onDone(err);
                        }
                        break;
                    }
                    LT.warn(log, "Failed to wait for ack message. [node=" + nodeId + ", routine=" + routineId + "]");
                }
            }
            assert fut.isDone() : "Future in not finished [fut= " + fut + "]";
        } else {
            final GridContinuousBatch batch = info.add(obj);
            if (batch != null) {
                CI1<IgniteException> ackC = new CI1<IgniteException>() {

                    @Override
                    public void apply(IgniteException e) {
                        if (e == null)
                            info.hnd.onBatchAcknowledged(routineId, batch, ctx);
                    }
                };
                sendNotification(nodeId, routineId, null, batch.collect(), orderedTopic, msg, ackC);
            }
        }
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Message(org.apache.ignite.plugin.extensions.communication.Message) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgniteException(org.apache.ignite.IgniteException) Collection(java.util.Collection) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) CI1(org.apache.ignite.internal.util.typedef.CI1) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 43 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 44 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 45 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)

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