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<>();
}
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;
}
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;
}
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;
}
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);
}
Aggregations