Search in sources :

Example 6 with GridCompoundFuture

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

the class GridServiceProcessor method cancelAll.

/**
     * @return Future.
     */
@SuppressWarnings("unchecked")
public IgniteInternalFuture<?> cancelAll() {
    Iterator<Cache.Entry<Object, Object>> it = serviceEntries(ServiceDeploymentPredicate.INSTANCE);
    GridCompoundFuture res = null;
    while (it.hasNext()) {
        Cache.Entry<Object, Object> e = it.next();
        GridServiceDeployment dep = (GridServiceDeployment) e.getValue();
        if (res == null)
            res = new GridCompoundFuture<>();
        // Cancel each service separately.
        res.add(cancel(dep.configuration().getName()));
    }
    if (res != null) {
        res.markInitialized();
        return res;
    } else
        return new GridFinishedFuture<>();
}
Also used : GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) Cache(javax.cache.Cache) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache)

Example 7 with GridCompoundFuture

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

the class HadoopShuffleJob method flush.

/**
     * @return Future.
     */
@SuppressWarnings("unchecked")
public IgniteInternalFuture<?> flush() throws IgniteCheckedException {
    if (log.isDebugEnabled())
        log.debug("Flushing job " + job.id() + " on address " + locReduceAddr);
    flushed = true;
    if (totalReducerCnt == 0)
        return new GridFinishedFuture<>();
    if (!stripeMappers) {
        U.await(ioInitLatch);
        GridWorker snd0 = snd;
        if (snd0 != null) {
            if (log.isDebugEnabled())
                log.debug("Cancelling sender thread.");
            snd0.cancel();
            try {
                snd0.join();
                if (log.isDebugEnabled())
                    log.debug("Finished waiting for sending thread to complete on shuffle job flush: " + job.id());
            } catch (InterruptedException e) {
                throw new IgniteInterruptedCheckedException(e);
            }
        }
        // With flush.
        collectUpdatesAndSend(true);
        if (log.isDebugEnabled())
            log.debug("Finished sending collected updates to remote reducers: " + job.id());
    }
    GridCompoundFuture fut = new GridCompoundFuture<>();
    if (embedded) {
        boolean sent = false;
        for (Map.Entry<T, HadoopShuffleRemoteState> rmtStateEntry : remoteShuffleStates().entrySet()) {
            T dest = rmtStateEntry.getKey();
            HadoopShuffleRemoteState rmtState = rmtStateEntry.getValue();
            HadoopShuffleFinishRequest req = new HadoopShuffleFinishRequest(job.id(), rmtState.messageCount());
            io.apply(dest, req);
            if (log.isDebugEnabled())
                log.debug("Sent shuffle finish request [jobId=" + job.id() + ", dest=" + dest + ", req=" + req + ']');
            fut.add(rmtState.future());
            sent = true;
        }
        if (sent)
            fut.markInitialized();
        else
            return new GridFinishedFuture<>();
    } else {
        for (IgniteBiTuple<HadoopShuffleMessage, GridFutureAdapter<?>> tup : sentMsgs.values()) fut.add(tup.get2());
        fut.markInitialized();
        if (log.isDebugEnabled())
            log.debug("Collected futures to compound futures for flush: " + sentMsgs.size());
    }
    return fut;
}
Also used : GridWorker(org.apache.ignite.internal.util.worker.GridWorker) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) SHUFFLE_MAPPER_STRIPED_OUTPUT(org.apache.ignite.internal.processors.hadoop.HadoopJobProperty.SHUFFLE_MAPPER_STRIPED_OUTPUT) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 8 with GridCompoundFuture

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

the class GridDhtPreloader method request0.

/**
     * @param keys Keys to request.
     * @param topVer Topology version.
     * @return Future for request.
     */
@SuppressWarnings({ "unchecked", "RedundantCast" })
private GridDhtFuture<Object> request0(Collection<KeyCacheObject> keys, AffinityTopologyVersion topVer) {
    final GridDhtForceKeysFuture<?, ?> fut = new GridDhtForceKeysFuture<>(cctx, topVer, keys, this);
    IgniteInternalFuture<?> topReadyFut = cctx.affinity().affinityReadyFuturex(topVer);
    if (startFut.isDone() && topReadyFut == null)
        fut.init();
    else {
        if (topReadyFut == null)
            startFut.listen(new CI1<IgniteInternalFuture<?>>() {

                @Override
                public void apply(IgniteInternalFuture<?> syncFut) {
                    cctx.kernalContext().closure().runLocalSafe(new GridPlainRunnable() {

                        @Override
                        public void run() {
                            fut.init();
                        }
                    });
                }
            });
        else {
            GridCompoundFuture<Object, Object> compound = new GridCompoundFuture<>();
            compound.add((IgniteInternalFuture<Object>) startFut);
            compound.add((IgniteInternalFuture<Object>) topReadyFut);
            compound.markInitialized();
            compound.listen(new CI1<IgniteInternalFuture<?>>() {

                @Override
                public void apply(IgniteInternalFuture<?> syncFut) {
                    fut.init();
                }
            });
        }
    }
    return (GridDhtFuture) fut;
}
Also used : GridDhtFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtFuture) CI1(org.apache.ignite.internal.util.typedef.CI1) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridPlainRunnable(org.apache.ignite.internal.util.lang.GridPlainRunnable) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture)

Example 9 with GridCompoundFuture

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

the class GridDhtTxPrepareFuture method forceRebalanceKeys.

/**
     * @param keysMap Keys to request.
     * @return Keys request future.
     */
private IgniteInternalFuture<Object> forceRebalanceKeys(Map<Integer, Collection<KeyCacheObject>> keysMap) {
    if (F.isEmpty(keysMap))
        return null;
    GridCompoundFuture<Object, Object> compFut = null;
    IgniteInternalFuture<Object> lastForceFut = null;
    for (Map.Entry<Integer, Collection<KeyCacheObject>> entry : keysMap.entrySet()) {
        if (lastForceFut != null && compFut == null) {
            compFut = new GridCompoundFuture();
            compFut.add(lastForceFut);
        }
        int cacheId = entry.getKey();
        Collection<KeyCacheObject> keys = entry.getValue();
        lastForceFut = cctx.cacheContext(cacheId).preloader().request(keys, tx.topologyVersion());
        if (compFut != null && lastForceFut != null)
            compFut.add(lastForceFut);
    }
    if (compFut != null) {
        compFut.markInitialized();
        return compFut;
    } else
        return lastForceFut;
}
Also used : Collection(java.util.Collection) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) Map(java.util.Map) HashMap(java.util.HashMap) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 10 with GridCompoundFuture

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

the class GridDhtGetFuture method getAsync.

/**
     * @param keys Keys to get.
     * @return Future for local get.
     */
@SuppressWarnings({ "unchecked", "IfMayBeConditional" })
private IgniteInternalFuture<Collection<GridCacheEntryInfo>> getAsync(final Map<KeyCacheObject, Boolean> keys) {
    if (F.isEmpty(keys))
        return new GridFinishedFuture<Collection<GridCacheEntryInfo>>(Collections.<GridCacheEntryInfo>emptyList());
    String taskName0 = cctx.kernalContext().job().currentTaskName();
    if (taskName0 == null)
        taskName0 = cctx.kernalContext().task().resolveTaskName(taskNameHash);
    final String taskName = taskName0;
    GridCompoundFuture<Boolean, Boolean> txFut = null;
    ClusterNode readerNode = cctx.discovery().node(reader);
    ReaderArguments readerArgs = null;
    if (readerNode != null && !readerNode.isLocal() && cctx.discovery().cacheNearNode(readerNode, cctx.name())) {
        for (Map.Entry<KeyCacheObject, Boolean> k : keys.entrySet()) {
            while (true) {
                GridDhtCacheEntry e = cache().entryExx(k.getKey(), topVer);
                try {
                    if (e.obsolete())
                        continue;
                    boolean addReader = (!e.deleted() && k.getValue() && !skipVals);
                    if (addReader) {
                        e.unswap(false);
                        // we have to add reader again later.
                        if (readerArgs == null)
                            readerArgs = new ReaderArguments(reader, msgId, topVer);
                    }
                    // Register reader. If there are active transactions for this entry,
                    // then will wait for their completion before proceeding.
                    // TODO: IGNITE-3498:
                    // TODO: What if any transaction we wait for actually removes this entry?
                    // TODO: In this case seems like we will be stuck with untracked near entry.
                    // TODO: To fix, check that reader is contained in the list of readers once
                    // TODO: again after the returned future completes - if not, try again.
                    IgniteInternalFuture<Boolean> f = addReader ? e.addReader(reader, msgId, topVer) : null;
                    if (f != null) {
                        if (txFut == null)
                            txFut = new GridCompoundFuture<>(CU.boolReducer());
                        txFut.add(f);
                    }
                    break;
                } catch (IgniteCheckedException err) {
                    return new GridFinishedFuture<>(err);
                } catch (GridCacheEntryRemovedException ignore) {
                    if (log.isDebugEnabled())
                        log.debug("Got removed entry when getting a DHT value: " + e);
                } finally {
                    cctx.evicts().touch(e, topVer);
                }
            }
        }
        if (txFut != null)
            txFut.markInitialized();
    }
    IgniteInternalFuture<Map<KeyCacheObject, EntryGetResult>> fut;
    if (txFut == null || txFut.isDone()) {
        fut = cache().getDhtAllAsync(keys.keySet(), readerArgs, readThrough, subjId, taskName, expiryPlc, skipVals, /*can remap*/
        true, recovery);
    } else {
        final ReaderArguments args = readerArgs;
        // If we are here, then there were active transactions for some entries
        // when we were adding the reader. In that case we must wait for those
        // transactions to complete.
        fut = new GridEmbeddedFuture<>(txFut, new C2<Boolean, Exception, IgniteInternalFuture<Map<KeyCacheObject, EntryGetResult>>>() {

            @Override
            public IgniteInternalFuture<Map<KeyCacheObject, EntryGetResult>> apply(Boolean b, Exception e) {
                if (e != null)
                    throw new GridClosureException(e);
                return cache().getDhtAllAsync(keys.keySet(), args, readThrough, subjId, taskName, expiryPlc, skipVals, /*can remap*/
                true, recovery);
            }
        });
    }
    if (fut.isDone()) {
        if (fut.error() != null)
            onDone(fut.error());
        else
            return new GridFinishedFuture<>(toEntryInfos(fut.result()));
    }
    return new GridEmbeddedFuture<>(new C2<Map<KeyCacheObject, EntryGetResult>, Exception, Collection<GridCacheEntryInfo>>() {

        @Override
        public Collection<GridCacheEntryInfo> apply(Map<KeyCacheObject, EntryGetResult> map, Exception e) {
            if (e != null) {
                onDone(e);
                return Collections.emptyList();
            } else
                return toEntryInfos(map);
        }
    }, fut);
}
Also used : GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) C2(org.apache.ignite.internal.util.typedef.C2) GridEmbeddedFuture(org.apache.ignite.internal.util.future.GridEmbeddedFuture) ReaderArguments(org.apache.ignite.internal.processors.cache.ReaderArguments) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) EntryGetResult(org.apache.ignite.internal.processors.cache.EntryGetResult) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridCacheEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheEntryInfo) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) Collection(java.util.Collection) Map(java.util.Map)

Aggregations

GridCompoundFuture (org.apache.ignite.internal.util.future.GridCompoundFuture)15 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)6 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)3 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)2 GridDhtTxRemote (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxRemote)2 GridNearTxRemote (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxRemote)2 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 List (java.util.List)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1