use of org.apache.ignite.internal.processors.cache.ReaderArguments in project ignite by apache.
the class GridDhtGetSingleFuture method getAsync.
/**
*
*/
@SuppressWarnings({ "unchecked", "IfMayBeConditional" })
private void getAsync() {
assert part != -1;
String taskName0 = cctx.kernalContext().job().currentTaskName();
if (taskName0 == null)
taskName0 = cctx.kernalContext().task().resolveTaskName(taskNameHash);
final String taskName = taskName0;
IgniteInternalFuture<Boolean> rdrFut = null;
ClusterNode readerNode = cctx.discovery().node(reader);
ReaderArguments readerArgs = null;
if (readerNode != null && !readerNode.isLocal() && cctx.discovery().cacheNearNode(readerNode, cctx.name())) {
while (true) {
GridDhtCacheEntry e = cache().entryExx(key, topVer);
try {
if (e.obsolete())
continue;
boolean addReader = (!e.deleted() && this.addRdr && !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.
rdrFut = addReader ? e.addReader(reader, msgId, topVer) : null;
break;
} catch (IgniteCheckedException err) {
onDone(err);
return;
} catch (GridCacheEntryRemovedException ignore) {
if (log.isDebugEnabled())
log.debug("Got removed entry when getting a DHT value: " + e);
} finally {
cctx.evicts().touch(e, topVer);
}
}
}
IgniteInternalFuture<Map<KeyCacheObject, EntryGetResult>> fut;
if (rdrFut == null || rdrFut.isDone()) {
fut = cache().getDhtAllAsync(Collections.singleton(key), readerArgs, readThrough, subjId, taskName, expiryPlc, skipVals, /*can remap*/
true, recovery);
} else {
final ReaderArguments args = readerArgs;
rdrFut.listen(new IgniteInClosure<IgniteInternalFuture<Boolean>>() {
@Override
public void apply(IgniteInternalFuture<Boolean> fut) {
Throwable e = fut.error();
if (e != null) {
onDone(e);
return;
}
IgniteInternalFuture<Map<KeyCacheObject, EntryGetResult>> fut0 = cache().getDhtAllAsync(Collections.singleton(key), args, readThrough, subjId, taskName, expiryPlc, skipVals, /*can remap*/
true, recovery);
fut0.listen(createGetFutureListener());
}
});
return;
}
if (fut.isDone())
onResult(fut);
else
fut.listen(createGetFutureListener());
}
use of org.apache.ignite.internal.processors.cache.ReaderArguments 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