Search in sources :

Example 16 with IgniteInternalFuture

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

the class GridNearAtomicUpdateFuture method mapOnTopology.

/** {@inheritDoc} */
@Override
protected void mapOnTopology() {
    AffinityTopologyVersion topVer;
    if (cache.topology().stopping()) {
        completeFuture(null, new IgniteCheckedException("Failed to perform cache operation (cache is stopped): " + cache.name()), null);
        return;
    }
    GridDhtTopologyFuture fut = cache.topology().topologyVersionFuture();
    if (fut.isDone()) {
        Throwable err = fut.validateCache(cctx, recovery, false, null, keys);
        if (err != null) {
            completeFuture(null, err, null);
            return;
        }
        topVer = fut.topologyVersion();
    } else {
        assert !topLocked : this;
        fut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {

            @Override
            public void apply(IgniteInternalFuture<AffinityTopologyVersion> t) {
                cctx.kernalContext().closure().runLocalSafe(new Runnable() {

                    @Override
                    public void run() {
                        mapOnTopology();
                    }
                });
            }
        });
        return;
    }
    map(topVer, remapKeys);
}
Also used : GridDhtTopologyFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture)

Example 17 with IgniteInternalFuture

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

the class GridPartitionedSingleGetFuture method onNodeLeft.

/** {@inheritDoc} */
@Override
public boolean onNodeLeft(UUID nodeId) {
    if (!processResponse(nodeId))
        return false;
    if (canRemap) {
        final AffinityTopologyVersion updTopVer = new AffinityTopologyVersion(Math.max(topVer.topologyVersion() + 1, cctx.discovery().topologyVersion()));
        cctx.affinity().affinityReadyFuture(updTopVer).listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {

            @Override
            public void apply(IgniteInternalFuture<AffinityTopologyVersion> fut) {
                try {
                    fut.get();
                    remap(updTopVer);
                } catch (IgniteCheckedException e) {
                    onDone(e);
                }
            }
        });
    } else
        remap(topVer);
    return true;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture)

Example 18 with IgniteInternalFuture

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

the class GridDhtColocatedLockFuture method mapOnTopology.

/**
     * Acquires topology future and checks it completeness under the read lock. If it is not complete,
     * will asynchronously wait for it's completeness and then try again.
     *
     * @param remap Remap flag.
     * @param c Optional closure to run after map.
     */
private void mapOnTopology(final boolean remap, @Nullable final Runnable c) {
    // We must acquire topology snapshot from the topology version future.
    cctx.topology().readLock();
    try {
        if (cctx.topology().stopping()) {
            onDone(new IgniteCheckedException("Failed to perform cache operation (cache is stopped): " + cctx.name()));
            return;
        }
        GridDhtTopologyFuture fut = cctx.topologyVersionFuture();
        if (fut.isDone()) {
            Throwable err = fut.validateCache(cctx, recovery, read, null, keys);
            if (err != null) {
                onDone(err);
                return;
            }
            AffinityTopologyVersion topVer = fut.topologyVersion();
            if (remap) {
                if (tx != null)
                    tx.onRemap(topVer);
                synchronized (this) {
                    this.topVer = topVer;
                }
            } else {
                if (tx != null)
                    tx.topologyVersion(topVer);
                synchronized (this) {
                    if (this.topVer == null)
                        this.topVer = topVer;
                }
            }
            map(keys, remap, false);
            if (c != null)
                c.run();
            markInitialized();
        } else {
            fut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {

                @Override
                public void apply(IgniteInternalFuture<AffinityTopologyVersion> fut) {
                    try {
                        fut.get();
                        mapOnTopology(remap, c);
                    } catch (IgniteCheckedException e) {
                        onDone(e);
                    } finally {
                        cctx.shared().txContextReset();
                    }
                }
            });
        }
    } finally {
        cctx.topology().readUnlock();
    }
}
Also used : GridDhtTopologyFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture)

Example 19 with IgniteInternalFuture

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

the class GridDhtColocatedLockFuture method proceedMapping0.

/**
     * Gets next near lock mapping and either acquires dht locks locally or sends near lock request to
     * remote primary node.
     *
     * @throws IgniteCheckedException If mapping can not be completed.
     */
private void proceedMapping0() throws IgniteCheckedException {
    GridNearLockMapping map;
    synchronized (this) {
        map = mappings.poll();
    }
    // If there are no more mappings to process, complete the future.
    if (map == null)
        return;
    final GridNearLockRequest req = map.request();
    final Collection<KeyCacheObject> mappedKeys = map.distributedKeys();
    final ClusterNode node = map.node();
    if (filter != null && filter.length != 0)
        req.filter(filter, cctx);
    if (node.isLocal())
        lockLocally(mappedKeys, req.topologyVersion());
    else {
        final MiniFuture fut = new MiniFuture(node, mappedKeys, ++miniId);
        req.miniId(fut.futureId());
        // Append new future.
        add(fut);
        IgniteInternalFuture<?> txSync = null;
        if (inTx())
            txSync = cctx.tm().awaitFinishAckAsync(node.id(), tx.threadId());
        if (txSync == null || txSync.isDone()) {
            try {
                cctx.io().send(node, req, cctx.ioPolicy());
                if (msgLog.isDebugEnabled()) {
                    msgLog.debug("Collocated lock fut, sent request [txId=" + lockVer + ", inTx=" + inTx() + ", node=" + node.id() + ']');
                }
            } catch (ClusterTopologyCheckedException ex) {
                assert fut != null;
                fut.onResult(ex);
            }
        } else {
            txSync.listen(new CI1<IgniteInternalFuture<?>>() {

                @Override
                public void apply(IgniteInternalFuture<?> t) {
                    try {
                        cctx.io().send(node, req, cctx.ioPolicy());
                        if (msgLog.isDebugEnabled()) {
                            msgLog.debug("Collocated lock fut, sent request [txId=" + lockVer + ", inTx=" + inTx() + ", node=" + node.id() + ']');
                        }
                    } catch (ClusterTopologyCheckedException ex) {
                        assert fut != null;
                        fut.onResult(ex);
                    } catch (IgniteCheckedException e) {
                        if (msgLog.isDebugEnabled()) {
                            msgLog.debug("Collocated lock fut, failed to send request [txId=" + lockVer + ", inTx=" + inTx() + ", node=" + node.id() + ", err=" + e + ']');
                        }
                        onError(e);
                    }
                }
            });
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridNearLockMapping(org.apache.ignite.internal.processors.cache.distributed.near.GridNearLockMapping) GridNearLockRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearLockRequest) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 20 with IgniteInternalFuture

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

the class GridDhtPreloader method processAffinityAssignmentRequest.

/**
     * @param node Node.
     * @param req Request.
     */
private void processAffinityAssignmentRequest(final ClusterNode node, final GridDhtAffinityAssignmentRequest req) {
    final AffinityTopologyVersion topVer = req.topologyVersion();
    if (log.isDebugEnabled())
        log.debug("Processing affinity assignment request [node=" + node + ", req=" + req + ']');
    cctx.affinity().affinityReadyFuture(req.topologyVersion()).listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {

        @Override
        public void apply(IgniteInternalFuture<AffinityTopologyVersion> fut) {
            if (log.isDebugEnabled())
                log.debug("Affinity is ready for topology version, will send response [topVer=" + topVer + ", node=" + node + ']');
            AffinityAssignment assignment = cctx.affinity().assignment(topVer);
            GridDhtAffinityAssignmentResponse res = new GridDhtAffinityAssignmentResponse(req.futureId(), cctx.cacheId(), topVer, assignment.assignment());
            if (cctx.affinity().affinityCache().centralizedAffinityFunction()) {
                assert assignment.idealAssignment() != null;
                res.idealAffinityAssignment(assignment.idealAssignment());
            }
            try {
                cctx.io().send(node, res, AFFINITY_POOL);
            } catch (IgniteCheckedException e) {
                U.error(log, "Failed to send affinity assignment response to remote node [node=" + node + ']', e);
            }
        }
    });
}
Also used : AffinityAssignment(org.apache.ignite.internal.processors.affinity.AffinityAssignment) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridDhtAffinityAssignmentResponse(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtAffinityAssignmentResponse) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture)

Aggregations

IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)178 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)88 Ignite (org.apache.ignite.Ignite)43 ArrayList (java.util.ArrayList)39 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)34 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)32 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)23 IgniteException (org.apache.ignite.IgniteException)23 Callable (java.util.concurrent.Callable)22 ClusterNode (org.apache.ignite.cluster.ClusterNode)22 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)22 Map (java.util.Map)21 IgniteCache (org.apache.ignite.IgniteCache)21 HashMap (java.util.HashMap)19 UUID (java.util.UUID)19 CountDownLatch (java.util.concurrent.CountDownLatch)18 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)16 CacheException (javax.cache.CacheException)14 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)14 IgniteKernal (org.apache.ignite.internal.IgniteKernal)14