use of org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedSingleGetFuture in project ignite by apache.
the class GridDhtColocatedCache method getAsync.
/**
* {@inheritDoc}
*/
@Override
protected IgniteInternalFuture<V> getAsync(final K key, boolean forcePrimary, boolean skipTx, String taskName, final boolean deserializeBinary, final boolean skipVals, final boolean needVer) {
ctx.checkSecurity(SecurityPermission.CACHE_READ);
GridNearTxLocal tx = checkCurrentTx();
final CacheOperationContext opCtx = ctx.operationContextPerCall();
final boolean recovery = opCtx != null && opCtx.recovery();
final ReadRepairStrategy readRepairStrategy = opCtx != null ? opCtx.readRepairStrategy() : null;
// Get operation bypass Tx in Mvcc mode.
if (!ctx.mvccEnabled() && tx != null && !tx.implicit() && !skipTx) {
return asyncOp(tx, new AsyncOp<V>() {
@Override
public IgniteInternalFuture<V> op(GridNearTxLocal tx, AffinityTopologyVersion readyTopVer) {
IgniteInternalFuture<Map<Object, Object>> fut = tx.getAllAsync(ctx, readyTopVer, Collections.singleton(ctx.toCacheKeyObject(key)), deserializeBinary, skipVals, false, opCtx != null && opCtx.skipStore(), recovery, readRepairStrategy, needVer);
return fut.chain(new CX1<IgniteInternalFuture<Map<Object, Object>>, V>() {
@Override
public V applyx(IgniteInternalFuture<Map<Object, Object>> e) throws IgniteCheckedException {
Map<Object, Object> map = e.get();
assert map.isEmpty() || map.size() == 1 : map.size();
if (skipVals) {
Boolean val = map.isEmpty() ? false : (Boolean) F.firstValue(map);
return (V) (val);
}
return (V) F.firstValue(map);
}
});
}
}, opCtx, /*retry*/
false);
}
MvccSnapshot mvccSnapshot = null;
MvccQueryTracker mvccTracker = null;
if (ctx.mvccEnabled()) {
try {
if (tx != null)
mvccSnapshot = MvccUtils.requestSnapshot(tx);
else {
mvccTracker = MvccUtils.mvccTracker(ctx, null);
mvccSnapshot = mvccTracker.snapshot();
}
assert mvccSnapshot != null;
} catch (IgniteCheckedException ex) {
return new GridFinishedFuture<>(ex);
}
}
AffinityTopologyVersion topVer;
if (tx != null)
topVer = tx.topologyVersion();
else if (mvccTracker != null)
topVer = mvccTracker.topologyVersion();
else
topVer = ctx.affinity().affinityTopologyVersion();
if (readRepairStrategy != null) {
return new GridNearReadRepairCheckOnlyFuture(ctx, Collections.singleton(ctx.toCacheKeyObject(key)), readRepairStrategy, opCtx == null || !opCtx.skipStore(), taskName, deserializeBinary, recovery, skipVals ? null : expiryPolicy(opCtx != null ? opCtx.expiry() : null), skipVals, needVer, false, tx).single();
}
GridPartitionedSingleGetFuture fut = new GridPartitionedSingleGetFuture(ctx, ctx.toCacheKeyObject(key), topVer, opCtx == null || !opCtx.skipStore(), forcePrimary, taskName, deserializeBinary, skipVals ? null : expiryPolicy(opCtx != null ? opCtx.expiry() : null), skipVals, needVer, /*keepCacheObjects*/
false, opCtx != null && opCtx.recovery(), null, mvccSnapshot);
fut.init();
if (mvccTracker != null) {
final MvccQueryTracker mvccTracker0 = mvccTracker;
fut.listen(new CI1<IgniteInternalFuture<Object>>() {
@Override
public void apply(IgniteInternalFuture<Object> future) {
if (future.isDone())
mvccTracker0.onDone();
}
});
}
return (IgniteInternalFuture<V>) fut;
}
Aggregations