Search in sources :

Example 6 with GridPartitionedSingleGetFuture

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;
}
Also used : MvccSnapshot(org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshot) GridPartitionedSingleGetFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedSingleGetFuture) CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ReadRepairStrategy(org.apache.ignite.cache.ReadRepairStrategy) MvccQueryTracker(org.apache.ignite.internal.processors.cache.mvcc.MvccQueryTracker) GridNearReadRepairCheckOnlyFuture(org.apache.ignite.internal.processors.cache.distributed.near.consistency.GridNearReadRepairCheckOnlyFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) CX1(org.apache.ignite.internal.util.typedef.CX1) Map(java.util.Map) GridCacheConcurrentMap(org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap)

Aggregations

GridPartitionedSingleGetFuture (org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedSingleGetFuture)6 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)4 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)4 Map (java.util.Map)2 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)2 CacheOperationContext (org.apache.ignite.internal.processors.cache.CacheOperationContext)2 GridCacheConcurrentMap (org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap)2 IgniteCacheExpiryPolicy (org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy)2 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)2 GridNearTxLocal (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)2 GridNearReadRepairCheckOnlyFuture (org.apache.ignite.internal.processors.cache.distributed.near.consistency.GridNearReadRepairCheckOnlyFuture)2 CX1 (org.apache.ignite.internal.util.typedef.CX1)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 ReadRepairStrategy (org.apache.ignite.cache.ReadRepairStrategy)1 MvccQueryTracker (org.apache.ignite.internal.processors.cache.mvcc.MvccQueryTracker)1 MvccSnapshot (org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshot)1