Search in sources :

Example 36 with GridFutureAdapter

use of org.apache.ignite.internal.util.future.GridFutureAdapter in project ignite by apache.

the class DistributedMetaStorageImpl method prepareWriteFuture.

/**
 * This method will perform some preliminary checks before starting write or cas operation.
 * It also updates {@link #updateFuts} in case if everything's ok.
 *
 * Tricky part is exception handling from "isSupported" method. It can be thrown by
 * {@code ZookeeperDiscoveryImpl#checkState()} method, but we can't just leave it as is.
 * There are components that rely on distributed metastorage throwing {@link NodeStoppingException}.
 *
 * @return Future that must be returned immediately or {@code null}.
 * @throws IgniteCheckedException If cluster can't perform this update.
 */
private GridFutureAdapter<Boolean> prepareWriteFuture(String key, UUID reqId) throws IgniteCheckedException {
    boolean supported;
    try {
        supported = isSupported(ctx);
    } catch (Exception e) {
        if (X.hasCause(e, IgniteSpiException.class) && e.getMessage() != null && e.getMessage().contains("Node stopped.")) {
            GridFutureAdapter<Boolean> fut = new GridFutureAdapter<>();
            fut.onDone(nodeStoppingException());
            return fut;
        }
        throw e;
    }
    if (!supported)
        throw new IgniteCheckedException(NOT_SUPPORTED_MSG);
    GridFutureAdapter<Boolean> fut = new GridFutureAdapter<>();
    updateFutsStopLock.readLock().lock();
    try {
        if (stopped) {
            fut.onDone(nodeStoppingException());
            return fut;
        }
        updateFuts.put(reqId, fut);
    } finally {
        updateFutsStopLock.readLock().unlock();
    }
    return fut;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException)

Example 37 with GridFutureAdapter

use of org.apache.ignite.internal.util.future.GridFutureAdapter 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 38 with GridFutureAdapter

use of org.apache.ignite.internal.util.future.GridFutureAdapter in project ignite by apache.

the class GridCacheMapEntry method mvccLock.

/**
 * {@inheritDoc}
 */
@Override
public GridCacheUpdateTxResult mvccLock(GridDhtTxLocalAdapter tx, MvccSnapshot mvccVer) throws GridCacheEntryRemovedException, IgniteCheckedException {
    assert tx != null;
    assert mvccVer != null;
    final boolean valid = valid(tx.topologyVersion());
    final GridCacheVersion newVer;
    WALPointer logPtr = null;
    lockEntry();
    try {
        checkObsolete();
        newVer = tx.writeVersion();
        assert newVer != null : "Failed to get write version for tx: " + tx;
        assert tx.local();
        MvccUpdateResult res = cctx.offheap().mvccLock(this, mvccVer);
        assert res != null;
        if (res.resultType() == ResultType.VERSION_MISMATCH)
            throw serializationError();
        else if (res.resultType() == ResultType.LOCKED) {
            unlockEntry();
            MvccVersion lockVer = res.resultVersion();
            GridFutureAdapter<GridCacheUpdateTxResult> resFut = new GridFutureAdapter<>();
            IgniteInternalFuture<?> lockFut = cctx.kernalContext().coordinators().waitForLock(cctx, mvccVer, lockVer);
            lockFut.listen(new MvccAcquireLockListener(tx, this, mvccVer, resFut));
            return new GridCacheUpdateTxResult(false, resFut);
        }
    } finally {
        if (lockedByCurrentThread()) {
            unlockEntry();
            cctx.evicts().touch(this);
        }
    }
    onUpdateFinished(0L);
    return new GridCacheUpdateTxResult(valid, logPtr);
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) MvccVersion(org.apache.ignite.internal.processors.cache.mvcc.MvccVersion) MvccUpdateResult(org.apache.ignite.internal.processors.cache.tree.mvcc.data.MvccUpdateResult) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)

Example 39 with GridFutureAdapter

use of org.apache.ignite.internal.util.future.GridFutureAdapter in project ignite by apache.

the class GridEventConsumeHandler method p2pUnmarshal.

/**
 * {@inheritDoc}
 */
@Override
public void p2pUnmarshal(UUID nodeId, GridKernalContext ctx) throws IgniteCheckedException {
    assert nodeId != null;
    assert ctx != null;
    assert ctx.config().isPeerClassLoadingEnabled();
    if (filterBytes != null) {
        try {
            GridDeployment dep = ctx.deploy().getGlobalDeployment(depInfo.deployMode(), clsName, clsName, depInfo.userVersion(), nodeId, depInfo.classLoaderId(), depInfo.participants(), null);
            if (dep == null)
                throw new IgniteDeploymentCheckedException("Failed to obtain deployment for class: " + clsName);
            filter = U.unmarshal(ctx, filterBytes, U.resolveClassLoader(dep.classLoader(), ctx.config()));
            ((GridFutureAdapter) p2pUnmarshalFut).onDone();
        } catch (IgniteCheckedException e) {
            ((GridFutureAdapter) p2pUnmarshalFut).onDone(e);
            throw e;
        } catch (ExceptionInInitializerError e) {
            ((GridFutureAdapter) p2pUnmarshalFut).onDone(e);
            throw new IgniteCheckedException("Failed to unmarshal deployable object.", e);
        }
    }
}
Also used : GridDeployment(org.apache.ignite.internal.managers.deployment.GridDeployment) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter)

Example 40 with GridFutureAdapter

use of org.apache.ignite.internal.util.future.GridFutureAdapter in project ignite by apache.

the class GridKernalGatewayImpl method onDisconnected.

/**
 * {@inheritDoc}
 */
@Override
public GridFutureAdapter<?> onDisconnected() {
    if (state.get() == GridKernalState.DISCONNECTED) {
        assert reconnectFut != null;
        return (GridFutureAdapter<?>) reconnectFut.internalFuture();
    }
    GridFutureAdapter<?> fut = new GridFutureAdapter<>();
    reconnectFut = new IgniteFutureImpl<>(fut);
    if (!state.compareAndSet(GridKernalState.STARTED, GridKernalState.DISCONNECTED)) {
        ((GridFutureAdapter<?>) reconnectFut.internalFuture()).onDone(new IgniteCheckedException("Node stopped."));
        return null;
    }
    return fut;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter)

Aggregations

GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)110 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)59 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)34 IgniteException (org.apache.ignite.IgniteException)23 ArrayList (java.util.ArrayList)21 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)21 List (java.util.List)20 UUID (java.util.UUID)20 ClusterNode (org.apache.ignite.cluster.ClusterNode)20 IgniteEx (org.apache.ignite.internal.IgniteEx)20 HashMap (java.util.HashMap)19 Map (java.util.Map)19 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)18 Test (org.junit.Test)18 Nullable (org.jetbrains.annotations.Nullable)17 Ignite (org.apache.ignite.Ignite)15 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)15 HashSet (java.util.HashSet)14 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 T2 (org.apache.ignite.internal.util.typedef.T2)13