Search in sources :

Example 1 with GridNearReadRepairCheckOnlyFuture

use of org.apache.ignite.internal.processors.cache.distributed.near.consistency.GridNearReadRepairCheckOnlyFuture in project ignite by apache.

the class GridDhtColocatedCache method getAllAsync.

/**
 * {@inheritDoc}
 */
@Override
public IgniteInternalFuture<Map<K, V>> getAllAsync(@Nullable final Collection<? extends K> keys, boolean forcePrimary, boolean skipTx, String taskName, final boolean deserializeBinary, final boolean recovery, final ReadRepairStrategy readRepairStrategy, final boolean skipVals, final boolean needVer) {
    ctx.checkSecurity(SecurityPermission.CACHE_READ);
    if (F.isEmpty(keys))
        return new GridFinishedFuture<>(Collections.<K, V>emptyMap());
    warnIfUnordered(keys, BulkOperation.GET);
    GridNearTxLocal tx = checkCurrentTx();
    final CacheOperationContext opCtx = ctx.operationContextPerCall();
    if (!ctx.mvccEnabled() && tx != null && !tx.implicit() && !skipTx) {
        return asyncOp(tx, new AsyncOp<Map<K, V>>(keys) {

            /**
             * {@inheritDoc}
             */
            @Override
            public IgniteInternalFuture<Map<K, V>> op(GridNearTxLocal tx, AffinityTopologyVersion readyTopVer) {
                return tx.getAllAsync(ctx, readyTopVer, ctx.cacheKeysView(keys), deserializeBinary, skipVals, false, opCtx != null && opCtx.skipStore(), recovery, readRepairStrategy, needVer);
            }
        }, 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, ctx.cacheKeysView(keys), readRepairStrategy, opCtx == null || !opCtx.skipStore(), taskName, deserializeBinary, recovery, skipVals ? null : expiryPolicy(opCtx != null ? opCtx.expiry() : null), skipVals, needVer, false, tx).multi();
    }
    IgniteInternalFuture<Map<K, V>> fut = loadAsync(ctx.cacheKeysView(keys), opCtx == null || !opCtx.skipStore(), forcePrimary, topVer, taskName, deserializeBinary, recovery, skipVals ? null : expiryPolicy(opCtx != null ? opCtx.expiry() : null), skipVals, needVer, false, null, mvccSnapshot);
    if (mvccTracker != null) {
        final MvccQueryTracker mvccTracker0 = mvccTracker;
        fut.listen(new CI1<IgniteInternalFuture<Map<K, V>>>() {

            /**
             * {@inheritDoc}
             */
            @Override
            public void apply(IgniteInternalFuture<Map<K, V>> future) {
                if (future.isDone())
                    mvccTracker0.onDone();
            }
        });
    }
    return fut;
}
Also used : MvccSnapshot(org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshot) 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) 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) Map(java.util.Map) GridCacheConcurrentMap(org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap)

Example 2 with GridNearReadRepairCheckOnlyFuture

use of org.apache.ignite.internal.processors.cache.distributed.near.consistency.GridNearReadRepairCheckOnlyFuture in project ignite by apache.

the class GridNearTxLocal method loadMissing.

/**
 * @param cacheCtx Cache context.
 * @param readThrough Read through flag.
 * @param async if {@code True}, then loading will happen in a separate thread.
 * @param keys Keys.
 * @param skipVals Skip values flag.
 * @param needVer If {@code true} version is required for loaded values.
 * @param c Closure to be applied for loaded values.
 * @param readRepairStrategy Read Repair strategy.
 * @param expiryPlc Expiry policy.
 * @return Future with {@code True} value if loading took place.
 */
private IgniteInternalFuture<Void> loadMissing(final GridCacheContext cacheCtx, AffinityTopologyVersion topVer, boolean readThrough, boolean async, final Collection<KeyCacheObject> keys, final boolean skipVals, final boolean needVer, boolean keepBinary, boolean recovery, ReadRepairStrategy readRepairStrategy, final ExpiryPolicy expiryPlc, final GridInClosure3<KeyCacheObject, Object, GridCacheVersion> c) {
    IgniteCacheExpiryPolicy expiryPlc0 = optimistic() ? accessPolicy(cacheCtx, keys) : cacheCtx.cache().expiryPolicy(expiryPlc);
    if (cacheCtx.isNear()) {
        return cacheCtx.nearTx().txLoadAsync(this, topVer, keys, readThrough, needVer || !cacheCtx.config().isReadFromBackup() || (optimistic() && serializable() && readThrough), /*deserializeBinary*/
        false, recovery, expiryPlc0, skipVals, needVer).chain(new C1<IgniteInternalFuture<Map<Object, Object>>, Void>() {

            @Override
            public Void apply(IgniteInternalFuture<Map<Object, Object>> f) {
                try {
                    Map<Object, Object> map = f.get();
                    processLoaded(map, keys, needVer, c);
                    return null;
                } catch (Exception e) {
                    setRollbackOnly();
                    throw new GridClosureException(e);
                }
            }
        });
    } else if (cacheCtx.isColocated()) {
        if (readRepairStrategy != null) {
            return new GridNearReadRepairCheckOnlyFuture(cacheCtx, keys, readRepairStrategy, readThrough, taskName, false, recovery, expiryPlc0, skipVals, needVer, true, this).multi().chain((fut) -> {
                try {
                    Map<Object, Object> map = fut.get();
                    processLoaded(map, keys, needVer, c);
                    return null;
                } catch (IgniteConsistencyViolationException e) {
                    for (KeyCacheObject key : keys) // Will be recreated after repair.
                    txState().removeEntry(cacheCtx.txKey(key));
                    throw new GridClosureException(e);
                } catch (Exception e) {
                    setRollbackOnly();
                    throw new GridClosureException(e);
                }
            });
        }
        if (keys.size() == 1) {
            final KeyCacheObject key = F.first(keys);
            return cacheCtx.colocated().loadAsync(key, readThrough, needVer || !cacheCtx.config().isReadFromBackup() || (optimistic() && serializable() && readThrough), topVer, resolveTaskName(), /*deserializeBinary*/
            false, expiryPlc0, skipVals, needVer, /*keepCacheObject*/
            true, recovery, null, label()).chain(new C1<IgniteInternalFuture<Object>, Void>() {

                @Override
                public Void apply(IgniteInternalFuture<Object> f) {
                    try {
                        Object val = f.get();
                        processLoaded(key, val, needVer, skipVals, c);
                        return null;
                    } catch (Exception e) {
                        setRollbackOnly();
                        throw new GridClosureException(e);
                    }
                }
            });
        } else {
            return cacheCtx.colocated().loadAsync(keys, readThrough, needVer || !cacheCtx.config().isReadFromBackup() || (optimistic() && serializable() && readThrough), topVer, resolveTaskName(), /*deserializeBinary*/
            false, recovery, expiryPlc0, skipVals, needVer, /*keepCacheObject*/
            true, label(), null).chain(new C1<IgniteInternalFuture<Map<Object, Object>>, Void>() {

                @Override
                public Void apply(IgniteInternalFuture<Map<Object, Object>> f) {
                    try {
                        Map<Object, Object> map = f.get();
                        processLoaded(map, keys, needVer, c);
                        return null;
                    } catch (Exception e) {
                        setRollbackOnly();
                        throw new GridClosureException(e);
                    }
                }
            });
        }
    } else {
        assert cacheCtx.isLocal();
        return localCacheLoadMissing(cacheCtx, topVer, readThrough, async, keys, skipVals, needVer, keepBinary, recovery, expiryPlc, c);
    }
}
Also used : GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) GridDistributedTxMapping(org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping) EVT_CACHE_OBJECT_READ(org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_READ) EntryProcessor(javax.cache.processor.EntryProcessor) Map(java.util.Map) Cache(javax.cache.Cache) IgniteCacheExpiryPolicy(org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy) DELETE(org.apache.ignite.internal.processors.cache.GridCacheOperation.DELETE) GridStringBuilder(org.apache.ignite.internal.util.GridStringBuilder) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) SER_READ_NOT_EMPTY_VER(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry.SER_READ_NOT_EMPTY_VER) IgniteTxTimeoutCheckedException(org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException) GridToStringExclude(org.apache.ignite.internal.util.tostring.GridToStringExclude) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) MvccSnapshotFuture(org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshotFuture) MvccProcessor(org.apache.ignite.internal.processors.cache.mvcc.MvccProcessor) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Set(java.util.Set) GridCacheVersionedFuture(org.apache.ignite.internal.processors.cache.GridCacheVersionedFuture) GridDhtTxLocalAdapter(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxLocalAdapter) MTC(org.apache.ignite.internal.processors.tracing.MTC) TransactionProxy(org.apache.ignite.internal.processors.cache.transactions.TransactionProxy) TX_NEAR_ENLIST_READ(org.apache.ignite.internal.processors.tracing.SpanType.TX_NEAR_ENLIST_READ) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) EntryGetResult(org.apache.ignite.internal.processors.cache.EntryGetResult) GridDhtDetachedCacheEntry(org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtDetachedCacheEntry) U(org.apache.ignite.internal.util.typedef.internal.U) SecurityPermission(org.apache.ignite.plugin.security.SecurityPermission) GridNearReadRepairCheckOnlyFuture(org.apache.ignite.internal.processors.cache.distributed.near.consistency.GridNearReadRepairCheckOnlyFuture) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) COMMITTING(org.apache.ignite.transactions.TransactionState.COMMITTING) ClusterNode(org.apache.ignite.cluster.ClusterNode) CI1(org.apache.ignite.internal.util.typedef.CI1) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) MvccUtils(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils) S(org.apache.ignite.internal.util.typedef.internal.S) C2(org.apache.ignite.internal.util.typedef.C2) IgniteTxManager(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager) C1(org.apache.ignite.internal.util.typedef.C1) PREPARED(org.apache.ignite.transactions.TransactionState.PREPARED) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) MvccCoordinator(org.apache.ignite.internal.processors.cache.mvcc.MvccCoordinator) IgniteTxOptimisticCheckedException(org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException) COMMITTED(org.apache.ignite.transactions.TransactionState.COMMITTED) PREPARING(org.apache.ignite.transactions.TransactionState.PREPARING) IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridNearReadRepairFuture(org.apache.ignite.internal.processors.cache.distributed.near.consistency.GridNearReadRepairFuture) AtomicLong(java.util.concurrent.atomic.AtomicLong) IgniteConsistencyViolationException(org.apache.ignite.internal.processors.cache.distributed.near.consistency.IgniteConsistencyViolationException) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) MvccSnapshot(org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshot) CacheEntryPredicate(org.apache.ignite.internal.processors.cache.CacheEntryPredicate) GridDistributedCacheEntry(org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheEntry) GridCacheDrInfo(org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo) CX1(org.apache.ignite.internal.util.typedef.CX1) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) TRANSFORM(org.apache.ignite.internal.processors.cache.GridCacheOperation.TRANSFORM) GridInvokeValue(org.apache.ignite.internal.processors.cache.distributed.dht.GridInvokeValue) UNKNOWN(org.apache.ignite.transactions.TransactionState.UNKNOWN) TransactionProxyRollbackOnlyImpl(org.apache.ignite.internal.processors.cache.transactions.TransactionProxyRollbackOnlyImpl) CREATE(org.apache.ignite.internal.processors.cache.GridCacheOperation.CREATE) TX_NEAR_ENLIST_WRITE(org.apache.ignite.internal.processors.tracing.SpanType.TX_NEAR_ENLIST_WRITE) GridDhtTxPrepareFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareFuture) GridInClosure3(org.apache.ignite.internal.util.lang.GridInClosure3) AtomicReferenceFieldUpdater(java.util.concurrent.atomic.AtomicReferenceFieldUpdater) Collection(java.util.Collection) ReadRepairStrategy(org.apache.ignite.cache.ReadRepairStrategy) UUID(java.util.UUID) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) TransactionProxyImpl(org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl) Instant(java.time.Instant) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CI2(org.apache.ignite.internal.util.typedef.CI2) GridCacheOperation(org.apache.ignite.internal.processors.cache.GridCacheOperation) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) Nullable(org.jetbrains.annotations.Nullable) NOOP(org.apache.ignite.internal.processors.cache.GridCacheOperation.NOOP) IgniteTxKey(org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey) CU(org.apache.ignite.internal.util.typedef.internal.CU) ACTIVE(org.apache.ignite.transactions.TransactionState.ACTIVE) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridDhtCacheEntry(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry) ROLLING_BACK(org.apache.ignite.transactions.TransactionState.ROLLING_BACK) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) GridCacheReturn(org.apache.ignite.internal.processors.cache.GridCacheReturn) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) HashMap(java.util.HashMap) IgniteBiClosure(org.apache.ignite.lang.IgniteBiClosure) SER_READ_EMPTY_ENTRY_VER(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry.SER_READ_EMPTY_ENTRY_VER) HashSet(java.util.HashSet) IgniteClosure(org.apache.ignite.lang.IgniteClosure) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) CacheException(javax.cache.CacheException) UpdateSourceIterator(org.apache.ignite.internal.processors.query.UpdateSourceIterator) GridLeanMap(org.apache.ignite.internal.util.GridLeanMap) F(org.apache.ignite.internal.util.typedef.F) Iterator(java.util.Iterator) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) ROLLED_BACK(org.apache.ignite.transactions.TransactionState.ROLLED_BACK) UPDATE(org.apache.ignite.internal.processors.cache.GridCacheOperation.UPDATE) MARKED_ROLLBACK(org.apache.ignite.transactions.TransactionState.MARKED_ROLLBACK) MvccCoordinatorChangeAware(org.apache.ignite.internal.processors.cache.mvcc.MvccCoordinatorChangeAware) GridEmbeddedFuture(org.apache.ignite.internal.util.future.GridEmbeddedFuture) TransactionState(org.apache.ignite.transactions.TransactionState) GridDhtTxFinishFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishFuture) CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) EnlistOperation(org.apache.ignite.internal.processors.query.EnlistOperation) GridPlainRunnable(org.apache.ignite.internal.util.lang.GridPlainRunnable) Collections(java.util.Collections) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) READ(org.apache.ignite.internal.processors.cache.GridCacheOperation.READ) TraceSurroundings(org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) IgniteTxTimeoutCheckedException(org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteTxOptimisticCheckedException(org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException) IgniteConsistencyViolationException(org.apache.ignite.internal.processors.cache.distributed.near.consistency.IgniteConsistencyViolationException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) CacheException(javax.cache.CacheException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) C1(org.apache.ignite.internal.util.typedef.C1) GridNearReadRepairCheckOnlyFuture(org.apache.ignite.internal.processors.cache.distributed.near.consistency.GridNearReadRepairCheckOnlyFuture) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) IgniteConsistencyViolationException(org.apache.ignite.internal.processors.cache.distributed.near.consistency.IgniteConsistencyViolationException) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) GridLeanMap(org.apache.ignite.internal.util.GridLeanMap) IgniteCacheExpiryPolicy(org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 3 with GridNearReadRepairCheckOnlyFuture

use of org.apache.ignite.internal.processors.cache.distributed.near.consistency.GridNearReadRepairCheckOnlyFuture in project ignite by apache.

the class GridDhtAtomicCache method getAsync0.

/**
 * Entry point to all public API single get methods.
 *
 * @param key Key.
 * @param forcePrimary Force primary flag.
 * @param taskName Task name.
 * @param deserializeBinary Deserialize binary flag.
 * @param readRepairStrategy Read Repair strategy.
 * @param expiryPlc Expiry policy.
 * @param skipVals Skip values flag.
 * @param skipStore Skip store flag.
 * @param needVer Need version.
 * @return Get future.
 */
private IgniteInternalFuture<V> getAsync0(KeyCacheObject key, boolean forcePrimary, String taskName, boolean deserializeBinary, boolean recovery, ReadRepairStrategy readRepairStrategy, @Nullable ExpiryPolicy expiryPlc, boolean skipVals, boolean skipStore, boolean needVer) {
    AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
    IgniteCacheExpiryPolicy expiry = skipVals ? null : expiryPolicy(expiryPlc);
    if (readRepairStrategy != null) {
        return new GridNearReadRepairCheckOnlyFuture(ctx, Collections.singleton(ctx.toCacheKeyObject(key)), readRepairStrategy, !skipStore, taskName, deserializeBinary, recovery, expiry, skipVals, needVer, false, null).single();
    }
    GridPartitionedSingleGetFuture fut = new GridPartitionedSingleGetFuture(ctx, key, topVer, !skipStore, forcePrimary, taskName, deserializeBinary, expiry, skipVals, needVer, false, recovery, null, null);
    fut.init();
    return (IgniteInternalFuture<V>) fut;
}
Also used : GridNearReadRepairCheckOnlyFuture(org.apache.ignite.internal.processors.cache.distributed.near.consistency.GridNearReadRepairCheckOnlyFuture) GridPartitionedSingleGetFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedSingleGetFuture) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCacheExpiryPolicy(org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy)

Example 4 with GridNearReadRepairCheckOnlyFuture

use of org.apache.ignite.internal.processors.cache.distributed.near.consistency.GridNearReadRepairCheckOnlyFuture in project ignite by apache.

the class GridDhtAtomicCache method getAllAsync0.

/**
 * Entry point to all public API get methods.
 *
 * @param keys Keys.
 * @param forcePrimary Force primary flag.
 * @param taskName Task name.
 * @param deserializeBinary Deserialize binary flag.
 * @param expiryPlc Expiry policy.
 * @param skipVals Skip values flag.
 * @param skipStore Skip store flag.
 * @param needVer Need version.
 * @return Get future.
 */
private IgniteInternalFuture<Map<K, V>> getAllAsync0(@Nullable Collection<KeyCacheObject> keys, boolean forcePrimary, String taskName, boolean deserializeBinary, boolean recovery, ReadRepairStrategy readRepairStrategy, @Nullable ExpiryPolicy expiryPlc, boolean skipVals, boolean skipStore, boolean needVer) {
    AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
    final IgniteCacheExpiryPolicy expiry = skipVals ? null : expiryPolicy(expiryPlc);
    final boolean evt = !skipVals;
    if (readRepairStrategy != null) {
        return new GridNearReadRepairCheckOnlyFuture(ctx, ctx.cacheKeysView(keys), readRepairStrategy, !skipStore, taskName, deserializeBinary, recovery, expiry, skipVals, needVer, false, null).multi();
    }
    // Optimisation: try to resolve value locally and escape 'get future' creation.
    if (!forcePrimary && ctx.config().isReadFromBackup() && ctx.affinityNode() && ctx.group().topology().lostPartitions().isEmpty()) {
        ctx.shared().database().checkpointReadLock();
        try {
            Map<K, V> locVals = U.newHashMap(keys.size());
            boolean success = true;
            boolean readNoEntry = ctx.readNoEntry(expiry, false);
            // Optimistically expect that all keys are available locally (avoid creation of get future).
            for (KeyCacheObject key : keys) {
                if (readNoEntry) {
                    CacheDataRow row = ctx.offheap().read(ctx, key);
                    if (row != null) {
                        long expireTime = row.expireTime();
                        if (expireTime == 0 || expireTime > U.currentTimeMillis()) {
                            ctx.addResult(locVals, key, row.value(), skipVals, false, deserializeBinary, true, null, row.version(), 0, 0, needVer, U.deploymentClassLoader(ctx.kernalContext(), U.contextDeploymentClassLoaderId(ctx.kernalContext())));
                            if (evt) {
                                ctx.events().readEvent(key, null, null, row.value(), taskName, !deserializeBinary);
                            }
                        } else
                            success = false;
                    } else
                        success = false;
                } else {
                    GridCacheEntryEx entry = null;
                    while (true) {
                        try {
                            entry = entryEx(key);
                            // If our DHT cache do has value, then we peek it.
                            if (entry != null) {
                                boolean isNew = entry.isNewLocked();
                                EntryGetResult getRes = null;
                                CacheObject v = null;
                                GridCacheVersion ver = null;
                                if (needVer) {
                                    getRes = entry.innerGetVersioned(null, null, /*update-metrics*/
                                    false, /*event*/
                                    evt, null, taskName, expiry, true, null);
                                    if (getRes != null) {
                                        v = getRes.value();
                                        ver = getRes.version();
                                    }
                                } else {
                                    v = entry.innerGet(null, null, /*read-through*/
                                    false, /*update-metrics*/
                                    false, /*event*/
                                    evt, null, taskName, expiry, !deserializeBinary);
                                }
                                // Entry was not in memory or in swap, so we remove it from cache.
                                if (v == null) {
                                    if (isNew && entry.markObsoleteIfEmpty(nextVersion()))
                                        removeEntry(entry);
                                    success = false;
                                } else {
                                    ctx.addResult(locVals, key, v, skipVals, false, deserializeBinary, true, getRes, ver, 0, 0, needVer, U.deploymentClassLoader(ctx.kernalContext(), U.contextDeploymentClassLoaderId(ctx.kernalContext())));
                                }
                            } else
                                success = false;
                            // While.
                            break;
                        } catch (GridCacheEntryRemovedException ignored) {
                        // No-op, retry.
                        } catch (GridDhtInvalidPartitionException ignored) {
                            success = false;
                            // While.
                            break;
                        } finally {
                            if (entry != null)
                                entry.touch();
                        }
                    }
                }
                if (!success)
                    break;
                else if (!skipVals && ctx.statisticsEnabled())
                    metrics0().onRead(true);
            }
            if (success) {
                sendTtlUpdateRequest(expiry);
                return new GridFinishedFuture<>(locVals);
            }
        } catch (IgniteCheckedException e) {
            return new GridFinishedFuture<>(e);
        } finally {
            ctx.shared().database().checkpointReadUnlock();
        }
    }
    if (expiry != null)
        expiry.reset();
    // Either reload or not all values are available locally.
    GridPartitionedGetFuture<K, V> fut = new GridPartitionedGetFuture<>(ctx, keys, !skipStore, forcePrimary, taskName, deserializeBinary, recovery, expiry, skipVals, needVer, false, null, null, null);
    fut.init(topVer);
    return fut;
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException) GridPartitionedGetFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedGetFuture) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) GridNearReadRepairCheckOnlyFuture(org.apache.ignite.internal.processors.cache.distributed.near.consistency.GridNearReadRepairCheckOnlyFuture) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) EntryGetResult(org.apache.ignite.internal.processors.cache.EntryGetResult) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) IgniteCacheExpiryPolicy(org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 5 with GridNearReadRepairCheckOnlyFuture

use of org.apache.ignite.internal.processors.cache.distributed.near.consistency.GridNearReadRepairCheckOnlyFuture 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

AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)5 GridNearReadRepairCheckOnlyFuture (org.apache.ignite.internal.processors.cache.distributed.near.consistency.GridNearReadRepairCheckOnlyFuture)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)4 Map (java.util.Map)3 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)3 CacheOperationContext (org.apache.ignite.internal.processors.cache.CacheOperationContext)3 MvccSnapshot (org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshot)3 ReadRepairStrategy (org.apache.ignite.cache.ReadRepairStrategy)2 EntryGetResult (org.apache.ignite.internal.processors.cache.EntryGetResult)2 GridCacheConcurrentMap (org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap)2 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)2 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)2 IgniteCacheExpiryPolicy (org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy)2 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)2 GridPartitionedSingleGetFuture (org.apache.ignite.internal.processors.cache.distributed.dht.GridPartitionedSingleGetFuture)2 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1