Search in sources :

Example 1 with ReadRepairStrategy

use of org.apache.ignite.cache.ReadRepairStrategy in project ignite by apache.

the class ConsistencyCommand method parseArguments.

/**
 * {@inheritDoc}
 */
@Override
public void parseArguments(CommandArgIterator argIter) {
    cmd = of(argIter.nextArg("Expected consistency action."));
    if (cmd == REPAIR) {
        String cacheName = null;
        int part = -1;
        ReadRepairStrategy strategy = null;
        while (argIter.hasNextArg()) {
            String arg = argIter.peekNextArg();
            if (CACHE.equals(arg) || PARTITION.equals(arg) || STRATEGY.equals(arg)) {
                arg = argIter.nextArg("Expected parameter key.");
                switch(arg) {
                    case CACHE:
                        cacheName = argIter.nextArg("Expected cache name.");
                        break;
                    case PARTITION:
                        part = argIter.nextNonNegativeIntArg("Expected partition.");
                        break;
                    case STRATEGY:
                        strategy = ReadRepairStrategy.fromString(argIter.nextArg("Expected strategy."));
                        break;
                    default:
                        throw new IllegalArgumentException("Illegal argument: " + arg);
                }
            } else
                break;
        }
        if (cacheName == null)
            throw new IllegalArgumentException("Cache name argument missed.");
        if (part == -1)
            throw new IllegalArgumentException("Partition argument missed.");
        if (strategy == null)
            throw new IllegalArgumentException("Strategy argument missed.");
        cmdArg = new VisorConsistencyRepairTaskArg(cacheName, part, strategy);
    } else if (cmd == STATUS)
        cmdArg = null;
    else
        throw new IllegalArgumentException("Unsupported operation.");
}
Also used : VisorConsistencyRepairTaskArg(org.apache.ignite.internal.visor.consistency.VisorConsistencyRepairTaskArg) ReadRepairStrategy(org.apache.ignite.cache.ReadRepairStrategy)

Example 2 with ReadRepairStrategy

use of org.apache.ignite.cache.ReadRepairStrategy 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 ReadRepairStrategy

use of org.apache.ignite.cache.ReadRepairStrategy in project ignite by apache.

the class GridDhtAtomicCache method getAsync.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteInternalFuture<V> getAsync(final K key, final boolean forcePrimary, final boolean skipTx, final String taskName, final boolean deserializeBinary, final boolean skipVals, final boolean needVer) {
    ctx.checkSecurity(SecurityPermission.CACHE_READ);
    CacheOperationContext opCtx = ctx.operationContextPerCall();
    final ExpiryPolicy expiryPlc = skipVals ? null : opCtx != null ? opCtx.expiry() : null;
    final boolean skipStore = opCtx != null && opCtx.skipStore();
    final boolean recovery = opCtx != null && opCtx.recovery();
    final ReadRepairStrategy readRepairStrategy = opCtx != null ? opCtx.readRepairStrategy() : null;
    return asyncOp(new CO<IgniteInternalFuture<V>>() {

        @Override
        public IgniteInternalFuture<V> apply() {
            return getAsync0(ctx.toCacheKeyObject(key), forcePrimary, taskName, deserializeBinary, recovery, readRepairStrategy, expiryPlc, skipVals, skipStore, needVer);
        }
    });
}
Also used : CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) IgniteCacheExpiryPolicy(org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ReadRepairStrategy(org.apache.ignite.cache.ReadRepairStrategy)

Example 4 with ReadRepairStrategy

use of org.apache.ignite.cache.ReadRepairStrategy in project ignite by apache.

the class GridCacheAdapter method containsKeyAsync.

/**
 * {@inheritDoc}
 */
@Override
public final IgniteInternalFuture<Boolean> containsKeyAsync(K key) {
    A.notNull(key, "key");
    CacheOperationContext opCtx = ctx.operationContextPerCall();
    IgniteInternalFuture fut = getAsync(key, /*force primary*/
    !ctx.config().isReadFromBackup(), /*skip tx*/
    false, /*task name*/
    null, /*deserialize binary*/
    false, /*skip values*/
    true, false);
    ReadRepairStrategy readRepairStrategy = opCtx != null ? opCtx.readRepairStrategy() : null;
    if (readRepairStrategy != null)
        return getWithRepairAsync(fut, (ks) -> repairAsync(ks, opCtx, true), () -> containsKeyAsync(key));
    return fut;
}
Also used : IgnitionEx(org.apache.ignite.internal.IgnitionEx) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) IgniteTxLocalAdapter(org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalAdapter) EntryProcessor(javax.cache.processor.EntryProcessor) GridSerializableMap(org.apache.ignite.internal.util.GridSerializableMap) MetricUtils.cacheMetricsRegistryName(org.apache.ignite.internal.processors.metric.impl.MetricUtils.cacheMetricsRegistryName) Map(java.util.Map) Cache(javax.cache.Cache) InvalidObjectException(java.io.InvalidObjectException) DFLT_ALLOW_ATOMIC_OPS_IN_TX(org.apache.ignite.internal.processors.cache.CacheOperationContext.DFLT_ALLOW_ATOMIC_OPS_IN_TX) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) IgniteKernal(org.apache.ignite.internal.IgniteKernal) TC_NO_FAILOVER(org.apache.ignite.internal.processors.task.GridTaskThreadContextKey.TC_NO_FAILOVER) ComputeJobContext(org.apache.ignite.compute.ComputeJobContext) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) Externalizable(java.io.Externalizable) IgniteTxTimeoutCheckedException(org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException) GridToStringExclude(org.apache.ignite.internal.util.tostring.GridToStringExclude) CIX2(org.apache.ignite.internal.util.typedef.CIX2) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CIX3(org.apache.ignite.internal.util.typedef.CIX3) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) Set(java.util.Set) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) READ_COMMITTED(org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED) ComputeTaskInternalFuture(org.apache.ignite.internal.ComputeTaskInternalFuture) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) Executors(java.util.concurrent.Executors) IgniteCache(org.apache.ignite.IgniteCache) GridCacheAffinityImpl(org.apache.ignite.internal.processors.cache.affinity.GridCacheAffinityImpl) GridCacheRawVersionedEntry(org.apache.ignite.internal.processors.cache.version.GridCacheRawVersionedEntry) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) PlatformCacheEntryFilter(org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFilter) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) ComputeJob(org.apache.ignite.compute.ComputeJob) EntryProcessorResult(javax.cache.processor.EntryProcessorResult) Affinity(org.apache.ignite.cache.affinity.Affinity) IgniteTxLocalEx(org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalEx) U(org.apache.ignite.internal.util.typedef.internal.U) Callable(java.util.concurrent.Callable) IgniteLogger(org.apache.ignite.IgniteLogger) IgniteDrDataStreamerCacheUpdater(org.apache.ignite.internal.processors.dr.IgniteDrDataStreamerCacheUpdater) SecurityPermission(org.apache.ignite.plugin.security.SecurityPermission) Supplier(java.util.function.Supplier) EntryProcessorException(javax.cache.processor.EntryProcessorException) ArrayList(java.util.ArrayList) ClusterNode(org.apache.ignite.cluster.ClusterNode) CI1(org.apache.ignite.internal.util.typedef.CI1) ComputeJobResult(org.apache.ignite.compute.ComputeJobResult) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) MvccUtils(org.apache.ignite.internal.processors.cache.mvcc.MvccUtils) S(org.apache.ignite.internal.util.typedef.internal.S) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) GridInternal(org.apache.ignite.internal.processors.task.GridInternal) C2(org.apache.ignite.internal.util.typedef.C2) C1(org.apache.ignite.internal.util.typedef.C1) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) A(org.apache.ignite.internal.util.typedef.internal.A) IOException(java.io.IOException) Ignite(org.apache.ignite.Ignite) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException) DataStreamerImpl(org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl) T2(org.apache.ignite.internal.util.typedef.T2) ObjectStreamException(java.io.ObjectStreamException) GridDhtCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) IgniteConsistencyViolationException(org.apache.ignite.internal.processors.cache.distributed.near.consistency.IgniteConsistencyViolationException) TransactionCheckedException(org.apache.ignite.internal.transactions.TransactionCheckedException) MvccSnapshot(org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshot) BROADCAST(org.apache.ignite.internal.GridClosureCallMode.BROADCAST) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridCacheDrInfo(org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo) CX1(org.apache.ignite.internal.util.typedef.CX1) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteExternalizableExpiryPolicy(org.apache.ignite.internal.processors.cache.distributed.IgniteExternalizableExpiryPolicy) SERIALIZABLE(org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE) SortedSet(java.util.SortedSet) ObjectOutput(java.io.ObjectOutput) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) DR_LOAD(org.apache.ignite.internal.processors.dr.GridDrType.DR_LOAD) ComputeJobResultPolicy(org.apache.ignite.compute.ComputeJobResultPolicy) X(org.apache.ignite.internal.util.typedef.X) OperationType(org.apache.ignite.internal.processors.performancestatistics.OperationType) GridPlainCallable(org.apache.ignite.internal.util.lang.GridPlainCallable) LoggerResource(org.apache.ignite.resources.LoggerResource) GridDhtTopologyFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture) CachePeekMode(org.apache.ignite.cache.CachePeekMode) IgniteOutClosure(org.apache.ignite.lang.IgniteOutClosure) IgniteThreadFactory(org.apache.ignite.thread.IgniteThreadFactory) Collection(java.util.Collection) IgniteException(org.apache.ignite.IgniteException) CacheEntry(org.apache.ignite.cache.CacheEntry) ReadRepairStrategy(org.apache.ignite.cache.ReadRepairStrategy) TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration) IgniteClusterEx(org.apache.ignite.internal.cluster.IgniteClusterEx) OPTIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC) OWNING(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState.OWNING) UUID(java.util.UUID) CI2(org.apache.ignite.internal.util.typedef.CI2) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) CacheMetricsMXBean(org.apache.ignite.mxbean.CacheMetricsMXBean) IgniteTxKey(org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey) CU(org.apache.ignite.internal.util.typedef.internal.CU) JobContextResource(org.apache.ignite.resources.JobContextResource) IGNITE_CACHE_RETRIES_COUNT(org.apache.ignite.IgniteSystemProperties.IGNITE_CACHE_RETRIES_COUNT) ObjectInput(java.io.ObjectInput) IgniteProductVersion(org.apache.ignite.lang.IgniteProductVersion) NotNull(org.jetbrains.annotations.NotNull) SortedMap(java.util.SortedMap) DataStreamerEntry(org.apache.ignite.internal.processors.datastreamer.DataStreamerEntry) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) DR_NONE(org.apache.ignite.internal.processors.dr.GridDrType.DR_NONE) ComputeTaskAdapter(org.apache.ignite.compute.ComputeTaskAdapter) AbstractSet(java.util.AbstractSet) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) HashMap(java.util.HashMap) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) IgniteFeatures(org.apache.ignite.internal.IgniteFeatures) Function(java.util.function.Function) LT(org.apache.ignite.internal.util.typedef.internal.LT) CacheInterceptor(org.apache.ignite.cache.CacheInterceptor) IgniteCallable(org.apache.ignite.lang.IgniteCallable) HashSet(java.util.HashSet) GridCompoundReadRepairFuture(org.apache.ignite.internal.processors.cache.distributed.near.consistency.GridCompoundReadRepairFuture) IgniteClosure(org.apache.ignite.lang.IgniteClosure) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) GPC(org.apache.ignite.internal.util.typedef.internal.GPC) IgniteClusterNode(org.apache.ignite.internal.managers.discovery.IgniteClusterNode) NoSuchElementException(java.util.NoSuchElementException) ExecutorService(java.util.concurrent.ExecutorService) TC_SUBGRID(org.apache.ignite.internal.processors.task.GridTaskThreadContextKey.TC_SUBGRID) F(org.apache.ignite.internal.util.typedef.F) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) IgniteTxHeuristicCheckedException(org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException) Iterator(java.util.Iterator) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Semaphore(java.util.concurrent.Semaphore) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) GridCloseableIterator(org.apache.ignite.internal.util.lang.GridCloseableIterator) TimeUnit(java.util.concurrent.TimeUnit) GridEmbeddedFuture(org.apache.ignite.internal.util.future.GridEmbeddedFuture) IgniteTransactionsEx(org.apache.ignite.internal.IgniteTransactionsEx) ComputeJobAdapter(org.apache.ignite.compute.ComputeJobAdapter) CacheMetrics(org.apache.ignite.cache.CacheMetrics) GridPlainRunnable(org.apache.ignite.internal.util.lang.GridPlainRunnable) Collections(java.util.Collections) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ReadRepairStrategy(org.apache.ignite.cache.ReadRepairStrategy)

Example 5 with ReadRepairStrategy

use of org.apache.ignite.cache.ReadRepairStrategy 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

ReadRepairStrategy (org.apache.ignite.cache.ReadRepairStrategy)7 Map (java.util.Map)5 HashMap (java.util.HashMap)4 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)4 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 Collections (java.util.Collections)3 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)3 ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)3 Ignite (org.apache.ignite.Ignite)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 CacheOperationContext (org.apache.ignite.internal.processors.cache.CacheOperationContext)3 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)3 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Set (java.util.Set)2 TreeMap (java.util.TreeMap)2