Search in sources :

Example 36 with IgniteFutureTimeoutCheckedException

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

the class GridCachePartitionNotLoadedEventSelfTest method testMapPartitioned.

/**
 * @throws Exception If failed.
 */
@Test
public void testMapPartitioned() throws Exception {
    backupCnt = 0;
    IgniteEx crd = startGrid(0);
    startGrid(1);
    crd.cluster().baselineAutoAdjustEnabled(false);
    crd.cluster().active(true);
    final PartitionNotFullyLoadedListener lsnr = new PartitionNotFullyLoadedListener();
    grid(1).events().localListen(lsnr, EventType.EVT_CACHE_REBALANCE_PART_DATA_LOST);
    TestTcpCommunicationSpi.skipMsgType(ignite(0), GridDhtPartitionsFullMessage.class);
    IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            startGrid(2);
            return null;
        }
    });
    boolean timeout = false;
    try {
        fut.get(1, TimeUnit.SECONDS);
    } catch (IgniteFutureTimeoutCheckedException ignored) {
        timeout = true;
    }
    assert timeout;
    stopGrid(0, true);
    awaitPartitionMapExchange();
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return !lsnr.lostParts.isEmpty();
        }
    }, getTestTimeout());
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) CacheInvalidStateException(org.apache.ignite.internal.processors.cache.CacheInvalidStateException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 37 with IgniteFutureTimeoutCheckedException

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

the class IgniteCheckpointDirtyPagesForLowLoadTest method testManyCachesAndNotManyPuts.

/**
 * @throws Exception if failed.
 */
@Test
public void testManyCachesAndNotManyPuts() throws Exception {
    try {
        IgniteEx ignite = startGrid(0);
        ignite.active(true);
        log.info("Saving initial data to caches");
        for (int g = 0; g < GROUPS; g++) {
            for (int c = 0; c < CACHES_IN_GRP; c++) {
                ignite.cache("dummyCache" + c + "." + g).putAll(new TreeMap<Long, Long>() {

                    {
                        for (int j = 0; j < PARTS; j++) {
                            // to fill each partition cache with at least 1 element
                            put((long) j, (long) j);
                        }
                    }
                });
            }
        }
        GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) (ignite.context().cache().context().database());
        Collection<Integer> pageCntObserved = new ArrayList<>();
        boolean checkpointWithLowNumOfPagesFound = false;
        for (int i = 0; i < 20; i++) {
            Random random = new Random();
            // touch some entry
            int d = random.nextInt(PARTS) + PARTS;
            int cIdx = random.nextInt(CACHES_IN_GRP);
            int gIdx = random.nextInt(GROUPS);
            String fullname = "dummyCache" + cIdx + "." + gIdx;
            ignite.cache(fullname).put(d, d);
            if (log.isInfoEnabled())
                log.info("Put to cache [" + fullname + "] value " + d);
            long start = System.nanoTime();
            try {
                final int cpTimeout = 25000;
                db.wakeupForCheckpoint("").get(cpTimeout, TimeUnit.MILLISECONDS);
            } catch (IgniteFutureTimeoutCheckedException ignored) {
                long msPassed = U.millisSinceNanos(start);
                log.error("Timeout during waiting for checkpoint to start:" + " [" + msPassed + "] but checkpoint is not running");
                continue;
            }
            final int timeout = 5000;
            int currCpPages = waitForCurrentCheckpointPagesCounterUpdated(db, timeout);
            if (currCpPages < 0) {
                log.error("Timeout during waiting for checkpoint counter to be updated");
                continue;
            }
            pageCntObserved.add(currCpPages);
            log.info("Current CP pages: " + currCpPages);
            if (currCpPages < PARTS * GROUPS) {
                // reasonable number of pages in CP
                checkpointWithLowNumOfPagesFound = true;
                break;
            }
        }
        stopGrid(0);
        assertTrue("All checkpoints mark too much pages: " + pageCntObserved, checkpointWithLowNumOfPagesFound);
    } finally {
        stopAllGrids();
    }
}
Also used : GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) ArrayList(java.util.ArrayList) Random(java.util.Random) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 38 with IgniteFutureTimeoutCheckedException

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

the class GridExecutorService method invokeAny.

/**
 * {@inheritDoc}
 * <p>
 * Note, for compilation with JDK 1.6 necessary to change method signature
 * (note the {@code &lt;? extends T&gt;} clause).
 * <pre name="code" class="java">
 *     ...
 *     public &lt;T&gt; T invokeAny(Collection&lt;? extends Callable&lt;T&gt;&gt; tasks, long timeout, TimeUnit unit)
 *         throws InterruptedException, ExecutionException, TimeoutException {
 *     }
 *     ...
 * </pre>
 */
@Override
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
    A.notNull(tasks, "tasks != null");
    A.ensure(!tasks.isEmpty(), "!tasks.isEmpty()");
    A.ensure(timeout >= 0, "timeout >= 0");
    A.notNull(unit, "unit != null");
    long startNanos = System.nanoTime();
    timeout = TimeUnit.MILLISECONDS.convert(timeout, unit);
    // Prevent overflow.
    if (timeout <= 0)
        timeout = Long.MAX_VALUE;
    checkShutdown();
    Collection<IgniteInternalFuture<T>> taskFuts = new ArrayList<>();
    for (Callable<T> cmd : tasks) {
        // Execute task with predefined timeout.
        IgniteInternalFuture<T> fut;
        ctx.gateway().readLock();
        try {
            fut = ctx.closure().callAsync(BALANCE, cmd, prj.nodes());
        } finally {
            ctx.gateway().readUnlock();
        }
        taskFuts.add(fut);
    }
    T res = null;
    boolean isInterrupted = false;
    boolean isResRcvd = false;
    int errCnt = 0;
    for (IgniteInternalFuture<T> fut : taskFuts) {
        long passedMillis = U.millisSinceNanos(startNanos);
        boolean cancel = false;
        if (!isInterrupted && !isResRcvd && passedMillis < timeout) {
            try {
                res = fut.get(timeout - passedMillis);
                isResRcvd = true;
                // Cancel next tasks (avoid current task cancellation below in loop).
                continue;
            } catch (IgniteFutureTimeoutCheckedException ignored) {
                if (log.isDebugEnabled())
                    log.debug("Timeout occurred during getting task result: " + fut);
                cancel = true;
            } catch (IgniteCheckedException e) {
                // Note: that execution may be interrupted on remote node. Possible bug.
                if (e.getCause() instanceof InterruptedException)
                    isInterrupted = true;
                else
                    errCnt++;
            }
        }
        // Cancel active task if any task interrupted, timeout elapsed or received task result before.
        if ((isInterrupted || isResRcvd || cancel) && !fut.isDone())
            cancelFuture(fut);
    }
    // Throw exception if any task wait was interrupted.
    if (isInterrupted)
        throw new InterruptedException("Got interrupted while waiting for tasks invocation.");
    // per executor service contract.
    if (!isResRcvd && taskFuts.size() == errCnt)
        throw new ExecutionException("Failed to get any task completion.", null);
    // throw timeout exception per executor service contract.
    if (!isResRcvd)
        throw new TimeoutException("Timeout occurred during tasks invocation.");
    return res;
}
Also used : ArrayList(java.util.ArrayList) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 39 with IgniteFutureTimeoutCheckedException

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

the class CacheObjectBinaryProcessorImpl method metadata.

/**
 * {@inheritDoc}
 */
@Nullable
@Override
public BinaryType metadata(final int typeId, final int schemaId) {
    BinaryMetadataHolder holder = metadataLocCache.get(typeId);
    if (ctx.clientNode()) {
        if (holder == null || !holder.metadata().hasSchema(schemaId)) {
            if (log.isDebugEnabled())
                log.debug("Waiting for client metadata update" + " [typeId=" + typeId + ", schemaId=" + schemaId + ", pendingVer=" + (holder == null ? "NA" : holder.pendingVersion()) + ", acceptedVer=" + (holder == null ? "NA" : holder.acceptedVersion()) + ']');
            try {
                transport.requestUpToDateMetadata(typeId).get();
            } catch (IgniteCheckedException ignored) {
            // No-op.
            }
            holder = metadataLocCache.get(typeId);
            IgniteFuture<?> reconnectFut0 = reconnectFut;
            if (holder == null && reconnectFut0 != null)
                throw new IgniteClientDisconnectedException(reconnectFut0, "Client node disconnected.");
            if (log.isDebugEnabled())
                log.debug("Finished waiting for client metadata update" + " [typeId=" + typeId + ", schemaId=" + schemaId + ", pendingVer=" + (holder == null ? "NA" : holder.pendingVersion()) + ", acceptedVer=" + (holder == null ? "NA" : holder.acceptedVersion()) + ']');
        }
    } else {
        if (holder != null && IgniteThread.current() instanceof IgniteDiscoveryThread)
            return holder.metadata().wrap(binaryCtx);
        else if (holder != null && (holder.pendingVersion() - holder.acceptedVersion() > 0)) {
            if (log.isDebugEnabled())
                log.debug("Waiting for metadata update" + " [typeId=" + typeId + ", schemaId=" + schemaId + ", pendingVer=" + holder.pendingVersion() + ", acceptedVer=" + holder.acceptedVersion() + ']');
            long t0 = System.nanoTime();
            GridFutureAdapter<MetadataUpdateResult> fut = transport.awaitMetadataUpdate(typeId, holder.pendingVersion());
            try {
                fut.get();
            } catch (IgniteCheckedException e) {
                log.error("Failed to wait for metadata update [typeId=" + typeId + ", schemaId=" + schemaId + ']', e);
            }
            if (log.isDebugEnabled())
                log.debug("Finished waiting for metadata update" + " [typeId=" + typeId + ", waitTime=" + NANOSECONDS.convert(System.nanoTime() - t0, MILLISECONDS) + "ms" + ", schemaId=" + schemaId + ", pendingVer=" + holder.pendingVersion() + ", acceptedVer=" + holder.acceptedVersion() + ']');
            holder = metadataLocCache.get(typeId);
        } else if (holder == null || !holder.metadata().hasSchema(schemaId)) {
            // Last resort waiting.
            U.warn(log, "Schema is missing while no metadata updates are in progress " + "(will wait for schema update within timeout defined by " + IGNITE_WAIT_SCHEMA_UPDATE + " system property)" + " [typeId=" + typeId + ", missingSchemaId=" + schemaId + ", pendingVer=" + (holder == null ? "NA" : holder.pendingVersion()) + ", acceptedVer=" + (holder == null ? "NA" : holder.acceptedVersion()) + ", binMetaUpdateTimeout=" + waitSchemaTimeout + ']');
            long t0 = System.nanoTime();
            GridFutureAdapter<?> fut = transport.awaitSchemaUpdate(typeId, schemaId);
            try {
                fut.get(waitSchemaTimeout);
            } catch (IgniteFutureTimeoutCheckedException e) {
                log.error("Timed out while waiting for schema update [typeId=" + typeId + ", schemaId=" + schemaId + ']');
            } catch (IgniteCheckedException ignored) {
            // No-op.
            }
            holder = metadataLocCache.get(typeId);
            if (log.isDebugEnabled() && holder != null && holder.metadata().hasSchema(schemaId))
                log.debug("Found the schema after wait" + " [typeId=" + typeId + ", waitTime=" + NANOSECONDS.convert(System.nanoTime() - t0, MILLISECONDS) + "ms" + ", schemaId=" + schemaId + ", pendingVer=" + holder.pendingVersion() + ", acceptedVer=" + holder.acceptedVersion() + ']');
        }
    }
    if (holder != null && metadataFileStore != null) {
        try {
            metadataFileStore.waitForWriteCompletion(typeId, holder.pendingVersion());
        } catch (IgniteCheckedException e) {
            log.warning("Failed to wait for metadata write operation for [typeId=" + typeId + ", typeVer=" + holder.acceptedVersion() + ']', e);
            return null;
        }
    }
    return holder != null ? holder.metadata().wrap(binaryCtx) : null;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) IgniteDiscoveryThread(org.apache.ignite.spi.discovery.IgniteDiscoveryThread) Nullable(org.jetbrains.annotations.Nullable)

Example 40 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;
    flushAllThreadsBufs();
    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) {
        if (disconnectErr != null)
            throw disconnectErr;
        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 (X.cause(e, IgniteClusterReadOnlyException.class) != null)
                        throw e;
                }
            }
            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)

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