Search in sources :

Example 1 with IgniteFutureTimeoutCheckedException

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

the class GridCacheQueryFutureAdapter method onTimeout.

/**
 * {@inheritDoc}
 */
@Override
public void onTimeout() {
    try {
        cancelQuery();
        onDone(new IgniteFutureTimeoutCheckedException("Query timed out."));
    } catch (IgniteCheckedException e) {
        onDone(e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)

Example 2 with IgniteFutureTimeoutCheckedException

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

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(), "exchange-worker", 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 3 with IgniteFutureTimeoutCheckedException

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

the class GridDhtPartitionsExchangeFuture method waitPartitionRelease.

/**
 * The main purpose of this method is to wait for all ongoing updates (transactional and atomic), initiated on
 * the previous topology version, to finish to prevent inconsistencies during rebalancing and to prevent two
 * different simultaneous owners of the same lock.
 * Also, this method can be used to wait for tx recovery only in case of PME-free switch.
 *
 * @param latchId Distributed latch Id.
 * @param distributed If {@code true} then node should wait for partition release completion on all other nodes.
 * @param doRollback If {@code true} tries to rollback transactions which lock partitions. Avoids unnecessary calls
 *      of {@link org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager#rollbackOnTopologyChange}
 *
 * @throws IgniteCheckedException If failed.
 */
private void waitPartitionRelease(String latchId, boolean distributed, boolean doRollback) throws IgniteCheckedException {
    Latch releaseLatch = null;
    IgniteInternalFuture<?> partReleaseFut;
    cctx.exchange().exchangerBlockingSectionBegin();
    try {
        // Wait for other nodes only on first phase.
        if (distributed)
            releaseLatch = cctx.exchange().latch().getOrCreate(latchId, initialVersion());
        partReleaseFut = context().exchangeFreeSwitch() && isBaselineNodeFailed() ? cctx.partitionRecoveryFuture(initialVersion(), firstDiscoEvt.eventNode()) : cctx.partitionReleaseFuture(initialVersion());
        // Assign to class variable so it will be included into toString() method.
        this.partReleaseFut = partReleaseFut;
    } finally {
        cctx.exchange().exchangerBlockingSectionEnd();
    }
    if (log.isTraceEnabled())
        log.trace("Before waiting for partition release future: " + this);
    int dumpCnt = 0;
    long nextDumpTime = 0;
    IgniteConfiguration cfg = cctx.gridConfig();
    long waitStartNanos = System.nanoTime();
    long waitTimeout = 2 * cfg.getNetworkTimeout();
    boolean txRolledBack = !doRollback;
    while (true) {
        // Read txTimeoutOnPME from configuration after every iteration.
        long curTimeout = cfg.getTransactionConfiguration().getTxTimeoutOnPartitionMapExchange();
        cctx.exchange().exchangerBlockingSectionBegin();
        try {
            // This avoids unnecessary waiting for rollback.
            partReleaseFut.get(curTimeout > 0 && !txRolledBack ? Math.min(curTimeout, waitTimeout) : waitTimeout, TimeUnit.MILLISECONDS);
            break;
        } catch (IgniteFutureTimeoutCheckedException ignored) {
            // Print pending transactions and locks that might have led to hang.
            if (nextDumpTime <= U.currentTimeMillis()) {
                dumpPendingObjects(partReleaseFut, curTimeout <= 0 && !txRolledBack);
                nextDumpTime = U.currentTimeMillis() + nextDumpTimeout(dumpCnt++, waitTimeout);
            }
            long passedMillis = U.millisSinceNanos(waitStartNanos);
            if (!txRolledBack && curTimeout > 0 && passedMillis >= curTimeout) {
                txRolledBack = true;
                cctx.tm().rollbackOnTopologyChange(initialVersion());
            }
        } catch (IgniteCheckedException e) {
            U.warn(log, "Unable to await partitions release future", e);
            throw e;
        } finally {
            cctx.exchange().exchangerBlockingSectionEnd();
        }
    }
    long waitEndNanos = System.nanoTime();
    if (log.isInfoEnabled()) {
        long waitTime = U.nanosToMillis(waitEndNanos - waitStartNanos);
        String futInfo = RELEASE_FUTURE_DUMP_THRESHOLD > 0 && waitTime > RELEASE_FUTURE_DUMP_THRESHOLD ? partReleaseFut.toString() : "NA";
        String mode = distributed ? "DISTRIBUTED" : "LOCAL";
        if (log.isInfoEnabled())
            log.info("Finished waiting for partition release future [topVer=" + exchangeId().topologyVersion() + ", waitTime=" + waitTime + "ms, futInfo=" + futInfo + ", mode=" + mode + "]");
    }
    if (!context().exchangeFreeSwitch()) {
        IgniteInternalFuture<?> locksFut = cctx.mvcc().finishLocks(exchId.topologyVersion());
        nextDumpTime = 0;
        dumpCnt = 0;
        while (true) {
            cctx.exchange().exchangerBlockingSectionBegin();
            try {
                locksFut.get(50, TimeUnit.MILLISECONDS);
                break;
            } catch (IgniteFutureTimeoutCheckedException ignored) {
                if (nextDumpTime <= U.currentTimeMillis()) {
                    U.warn(log, "Failed to wait for locks release future. " + "Dumping pending objects that might be the cause: " + cctx.localNodeId());
                    U.warn(log, "Locked keys:");
                    for (IgniteTxKey key : cctx.mvcc().lockedKeys()) U.warn(log, "Locked key: " + key);
                    for (IgniteTxKey key : cctx.mvcc().nearLockedKeys()) U.warn(log, "Locked near key: " + key);
                    Map<IgniteTxKey, Collection<GridCacheMvccCandidate>> locks = cctx.mvcc().unfinishedLocks(exchId.topologyVersion());
                    for (Map.Entry<IgniteTxKey, Collection<GridCacheMvccCandidate>> e : locks.entrySet()) U.warn(log, "Awaited locked entry [key=" + e.getKey() + ", mvcc=" + e.getValue() + ']');
                    nextDumpTime = U.currentTimeMillis() + nextDumpTimeout(dumpCnt++, waitTimeout);
                    if (getBoolean(IGNITE_THREAD_DUMP_ON_EXCHANGE_TIMEOUT, false))
                        U.dumpThreads(log);
                }
                // Sometimes FinishLockFuture is not rechecked causing frozen PME.
                // Will recheck every 50 milliseconds.
                cctx.mvcc().recheckPendingLocks();
            } finally {
                cctx.exchange().exchangerBlockingSectionEnd();
            }
        }
        timeBag.finishGlobalStage("Wait partitions release [latch=" + latchId + "]");
    }
    if (releaseLatch == null) {
        assert !distributed : "Partitions release latch must be initialized in distributed mode.";
        return;
    }
    releaseLatch.countDown();
    // For compatibility with old version where joining nodes are not waiting for latch.
    if (localJoinExchange() && !cctx.exchange().latch().canSkipJoiningNodes(initialVersion()))
        return;
    try {
        String troubleshootingHint;
        if (crd.isLocal())
            troubleshootingHint = "Some nodes have not sent acknowledgement for latch completion. " + "It's possible due to unfinishined atomic updates, transactions " + "or not released explicit locks on that nodes. " + "Please check logs for errors on nodes with ids reported in latch `pendingAcks` collection";
        else
            troubleshootingHint = "For more details please check coordinator node logs [crdNode=" + crd.toString() + "]";
        while (true) {
            try {
                cctx.exchange().exchangerBlockingSectionBegin();
                try {
                    releaseLatch.await(waitTimeout, TimeUnit.MILLISECONDS);
                } finally {
                    cctx.exchange().exchangerBlockingSectionEnd();
                }
                if (log.isInfoEnabled())
                    log.info("Finished waiting for partitions release latch: " + releaseLatch);
                break;
            } catch (IgniteFutureTimeoutCheckedException ignored) {
                U.warn(log, "Unable to await partitions release latch within timeout. " + troubleshootingHint + " [latch=" + releaseLatch + "]");
                // Try to resend ack.
                releaseLatch.countDown();
            }
        }
    } catch (IgniteCheckedException e) {
        U.warn(log, "Stop waiting for partitions release latch: " + e.getMessage());
    }
    timeBag.finishGlobalStage("Wait partitions release latch [latch=" + latchId + "]");
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Latch(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.latch.Latch) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) IgniteTxKey(org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)

Example 4 with IgniteFutureTimeoutCheckedException

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

the class CheckpointTimeoutLock method checkpointReadLock.

/**
 * Gets the checkpoint read lock. While this lock is held, checkpoint thread will not acquireSnapshotWorker memory
 * state.
 *
 * @throws IgniteException If failed.
 */
public void checkpointReadLock() {
    if (checkpointReadWriteLock.isWriteLockHeldByCurrentThread())
        return;
    long timeout = checkpointReadLockTimeout;
    long start = U.currentTimeMillis();
    boolean interrupted = false;
    try {
        for (; ; ) {
            try {
                if (timeout > 0 && (U.currentTimeMillis() - start) >= timeout)
                    failCheckpointReadLock();
                try {
                    if (timeout > 0) {
                        if (!checkpointReadWriteLock.tryReadLock(timeout - (U.currentTimeMillis() - start), TimeUnit.MILLISECONDS))
                            failCheckpointReadLock();
                    } else
                        checkpointReadWriteLock.readLock();
                } catch (InterruptedException e) {
                    interrupted = true;
                    continue;
                }
                if (stop) {
                    checkpointReadWriteLock.readUnlock();
                    throw new IgniteException(new NodeStoppingException("Failed to perform cache update: node is stopping."));
                }
                if (checkpointReadWriteLock.getReadHoldCount() > 1 || safeToUpdatePageMemories() || checkpointer.runner() == null)
                    break;
                else {
                    CheckpointProgress pages = checkpointer.scheduleCheckpoint(0, "too many dirty pages");
                    checkpointReadWriteLock.readUnlock();
                    if (timeout > 0 && U.currentTimeMillis() - start >= timeout)
                        failCheckpointReadLock();
                    try {
                        pages.futureFor(LOCK_RELEASED).getUninterruptibly();
                    } catch (IgniteFutureTimeoutCheckedException e) {
                        failCheckpointReadLock();
                    } catch (IgniteCheckedException e) {
                        throw new IgniteException("Failed to wait for checkpoint begin.", e);
                    }
                }
            } catch (CheckpointReadLockTimeoutException e) {
                log.error(e.getMessage(), e);
                timeout = 0;
            }
        }
    } finally {
        if (interrupted)
            Thread.currentThread().interrupt();
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) IgniteException(org.apache.ignite.IgniteException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)

Example 5 with IgniteFutureTimeoutCheckedException

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

the class GridFunc method awaitAll.

/**
 * Awaits for all futures to complete and optionally reduces all results into one.
 *
 * @param timeout Timeout for waiting ({@code 0} for forever).
 * @param rdc Optional reducer. If not {@code null}, then results will be reduced into one.
 * @param futs List of futures to wait for.
 * @param <T> Return type of the futures.
 * @param <R> Return type of the reducer.
 * @return Reduced result if reducer is provided, {@code null} otherwise.
 * @throws IgniteCheckedException If any of the futures failed.
 */
@Deprecated
@Nullable
public static <T, R> R awaitAll(long timeout, @Nullable IgniteReducer<T, R> rdc, @Nullable Collection<IgniteInternalFuture<T>> futs) throws IgniteCheckedException {
    if (futs == null || futs.isEmpty())
        return null;
    long end = timeout == 0 ? Long.MAX_VALUE : U.currentTimeMillis() + timeout;
    // Overflow.
    if (end < 0)
        end = Long.MAX_VALUE;
    // concurrently while this method is in progress.
    for (IgniteInternalFuture<T> fut : futs) {
        T t;
        if (timeout > 0) {
            long left = end - U.currentTimeMillis();
            if (left <= 0 && !fut.isDone())
                throw new IgniteFutureTimeoutCheckedException("Timed out waiting for all futures: " + futs);
            if (fut.isDone() && left < 0)
                left = 0;
            t = fut.get(left);
        } else
            t = fut.get();
        if (rdc != null)
            rdc.collect(t);
    }
    return rdc == null ? null : rdc.reduce();
}
Also used : LT(org.apache.ignite.internal.util.typedef.internal.LT) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

IgniteFutureTimeoutCheckedException (org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)37 Test (org.junit.Test)18 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)17 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)14 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)14 Ignite (org.apache.ignite.Ignite)9 IgniteException (org.apache.ignite.IgniteException)8 IgniteEx (org.apache.ignite.internal.IgniteEx)8 ArrayList (java.util.ArrayList)7 Transaction (org.apache.ignite.transactions.Transaction)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 Map (java.util.Map)5 CacheException (javax.cache.CacheException)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)4 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)4 Collection (java.util.Collection)3