Search in sources :

Example 11 with IgniteFutureTimeoutCheckedException

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

the class DataStreamerImpl method doFlush.

/**
     * Performs flush.
     *
     * @throws IgniteCheckedException If failed.
     */
private void doFlush() throws IgniteCheckedException {
    lastFlushTime = U.currentTimeMillis();
    List<IgniteInternalFuture> activeFuts0 = null;
    int doneCnt = 0;
    for (IgniteInternalFuture<?> f : activeFuts) {
        if (!f.isDone()) {
            if (activeFuts0 == null)
                activeFuts0 = new ArrayList<>((int) (activeFuts.size() * 1.2));
            activeFuts0.add(f);
        } else {
            f.get();
            doneCnt++;
        }
    }
    if (activeFuts0 == null || activeFuts0.isEmpty())
        return;
    while (true) {
        Queue<IgniteInternalFuture<?>> q = null;
        for (Buffer buf : bufMappings.values()) {
            IgniteInternalFuture<?> flushFut = buf.flush();
            if (flushFut != null) {
                if (q == null)
                    q = new ArrayDeque<>(bufMappings.size() * 2);
                q.add(flushFut);
            }
        }
        if (q != null) {
            assert !q.isEmpty();
            boolean err = false;
            long startTimeMillis = U.currentTimeMillis();
            for (IgniteInternalFuture fut = q.poll(); fut != null; fut = q.poll()) {
                try {
                    if (timeout == DFLT_UNLIMIT_TIMEOUT)
                        fut.get();
                    else {
                        long timeRemain = timeout - U.currentTimeMillis() + startTimeMillis;
                        if (timeRemain <= 0)
                            throw new IgniteDataStreamerTimeoutException("Data streamer exceeded timeout on flush.");
                        fut.get(timeRemain);
                    }
                } catch (IgniteClientDisconnectedCheckedException e) {
                    if (log.isDebugEnabled())
                        log.debug("Failed to flush buffer: " + e);
                    throw CU.convertToCacheException(e);
                } catch (IgniteFutureTimeoutCheckedException e) {
                    if (log.isDebugEnabled())
                        log.debug("Failed to flush buffer: " + e);
                    throw new IgniteDataStreamerTimeoutException("Data streamer exceeded timeout on flush.", e);
                } catch (IgniteCheckedException e) {
                    if (log.isDebugEnabled())
                        log.debug("Failed to flush buffer: " + e);
                    err = true;
                }
            }
            if (err)
                // Remaps needed - flush buffers.
                continue;
        }
        doneCnt = 0;
        for (int i = 0; i < activeFuts0.size(); i++) {
            IgniteInternalFuture f = activeFuts0.get(i);
            if (f == null)
                doneCnt++;
            else if (f.isDone()) {
                f.get();
                doneCnt++;
                activeFuts0.set(i, null);
            } else
                break;
        }
        if (doneCnt == activeFuts0.size())
            return;
    }
}
Also used : ArrayList(java.util.ArrayList) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ArrayDeque(java.util.ArrayDeque) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteDataStreamerTimeoutException(org.apache.ignite.IgniteDataStreamerTimeoutException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)

Example 12 with IgniteFutureTimeoutCheckedException

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

the class IgniteTxOriginatingNodeFailureAbstractSelfTest method testTxOriginatingNodeFails.

/**
     * @param keys Keys to update.
     * @param partial Flag indicating whether to simulate partial prepared state.
     * @throws Exception If failed.
     */
protected void testTxOriginatingNodeFails(Collection<Integer> keys, final boolean partial) throws Exception {
    assertFalse(keys.isEmpty());
    final Collection<IgniteKernal> grids = new ArrayList<>();
    ClusterNode txNode = grid(originatingNode()).localNode();
    for (int i = 1; i < gridCount(); i++) grids.add((IgniteKernal) grid(i));
    final Map<Integer, String> map = new HashMap<>();
    final String initVal = "initialValue";
    for (Integer key : keys) {
        grid(originatingNode()).cache(DEFAULT_CACHE_NAME).put(key, initVal);
        map.put(key, String.valueOf(key));
    }
    Map<Integer, Collection<ClusterNode>> nodeMap = new HashMap<>();
    info("Node being checked: " + grid(1).localNode().id());
    for (Integer key : keys) {
        Collection<ClusterNode> nodes = new ArrayList<>();
        nodes.addAll(grid(1).affinity(DEFAULT_CACHE_NAME).mapKeyToPrimaryAndBackups(key));
        nodes.remove(txNode);
        nodeMap.put(key, nodes);
    }
    info("Starting optimistic tx " + "[values=" + map + ", topVer=" + (grid(1)).context().discovery().topologyVersion() + ']');
    if (partial)
        ignoreMessages(grid(1).localNode().id(), ignoreMessageClass());
    final Ignite txIgniteNode = G.ignite(txNode.id());
    GridTestUtils.runAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            IgniteCache<Integer, String> cache = txIgniteNode.cache(DEFAULT_CACHE_NAME);
            assertNotNull(cache);
            TransactionProxyImpl tx = (TransactionProxyImpl) txIgniteNode.transactions().txStart();
            GridNearTxLocal txEx = tx.tx();
            assertTrue(txEx.optimistic());
            cache.putAll(map);
            try {
                txEx.prepareNearTxLocal().get(3, TimeUnit.SECONDS);
            } catch (IgniteFutureTimeoutCheckedException ignored) {
                info("Failed to wait for prepare future completion: " + partial);
            }
            return null;
        }
    }).get();
    info("Stopping originating node " + txNode);
    G.stop(G.ignite(txNode.id()).name(), true);
    info("Stopped grid, waiting for transactions to complete.");
    boolean txFinished = GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            for (IgniteKernal g : grids) {
                GridCacheSharedContext<Object, Object> ctx = g.context().cache().context();
                int txNum = ctx.tm().idMapSize();
                if (txNum != 0)
                    return false;
            }
            return true;
        }
    }, 10000);
    assertTrue(txFinished);
    info("Transactions finished.");
    for (Map.Entry<Integer, Collection<ClusterNode>> e : nodeMap.entrySet()) {
        final Integer key = e.getKey();
        final String val = map.get(key);
        assertFalse(e.getValue().isEmpty());
        for (ClusterNode node : e.getValue()) {
            compute(G.ignite(node.id()).cluster().forNode(node)).call(new IgniteCallable<Void>() {

                /** */
                @IgniteInstanceResource
                private Ignite ignite;

                @Override
                public Void call() throws Exception {
                    IgniteCache<Integer, String> cache = ignite.cache(DEFAULT_CACHE_NAME);
                    assertNotNull(cache);
                    assertEquals(partial ? initVal : val, cache.localPeek(key));
                    return null;
                }
            });
        }
    }
    for (Map.Entry<Integer, String> e : map.entrySet()) {
        for (Ignite g : G.allGrids()) {
            UUID locNodeId = g.cluster().localNode().id();
            assertEquals("Check failed for node: " + locNodeId, partial ? initVal : e.getValue(), g.cache(DEFAULT_CACHE_NAME).get(e.getKey()));
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) Callable(java.util.concurrent.Callable) IgniteCallable(org.apache.ignite.lang.IgniteCallable) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteCache(org.apache.ignite.IgniteCache) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteException(org.apache.ignite.IgniteException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) TransactionProxyImpl(org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl)

Aggregations

IgniteFutureTimeoutCheckedException (org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)12 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)4 ArrayList (java.util.ArrayList)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 CacheException (javax.cache.CacheException)3 Ignite (org.apache.ignite.Ignite)3 IgniteCache (org.apache.ignite.IgniteCache)3 UUID (java.util.UUID)2 AtomicIntegerArray (java.util.concurrent.atomic.AtomicIntegerArray)2 IgniteException (org.apache.ignite.IgniteException)2 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 IgniteClientDisconnectedCheckedException (org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)2 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)2 IgniteKernal (org.apache.ignite.internal.IgniteKernal)2 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)2 GridRandom (org.apache.ignite.internal.util.GridRandom)2 ArrayDeque (java.util.ArrayDeque)1