Search in sources :

Example 31 with CacheOperationContext

use of org.apache.ignite.internal.processors.cache.CacheOperationContext 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 32 with CacheOperationContext

use of org.apache.ignite.internal.processors.cache.CacheOperationContext in project ignite by apache.

the class GridDhtAtomicCache method createSingleUpdateFuture.

/**
 * Craete future for single key-val pair update.
 *
 * @param key Key.
 * @param val Value.
 * @param proc Processor.
 * @param invokeArgs Invoke arguments.
 * @param retval Return value flag.
 * @param filter Filter.
 * @return Future.
 */
private GridNearAtomicAbstractUpdateFuture createSingleUpdateFuture(K key, @Nullable V val, @Nullable EntryProcessor proc, @Nullable Object[] invokeArgs, boolean retval, @Nullable CacheEntryPredicate filter) {
    CacheOperationContext opCtx = ctx.operationContextPerCall();
    GridCacheOperation op;
    Object val0;
    if (val != null) {
        op = UPDATE;
        val0 = val;
    } else if (proc != null) {
        op = TRANSFORM;
        val0 = proc;
    } else {
        op = DELETE;
        val0 = null;
    }
    GridCacheDrInfo conflictPutVal = null;
    GridCacheVersion conflictRmvVer = null;
    if (opCtx != null && opCtx.hasDataCenterId()) {
        Byte dcId = opCtx.dataCenterId();
        assert dcId != null;
        if (op == UPDATE) {
            conflictPutVal = new GridCacheDrInfo(ctx.toCacheObject(val), nextVersion(dcId));
            val0 = null;
        } else if (op == GridCacheOperation.TRANSFORM) {
            conflictPutVal = new GridCacheDrInfo(proc, nextVersion(dcId));
            val0 = null;
        } else
            conflictRmvVer = nextVersion(dcId);
    }
    CacheEntryPredicate[] filters = CU.filterArray(filter);
    if (conflictPutVal == null && conflictRmvVer == null) {
        return new GridNearAtomicSingleUpdateFuture(ctx, this, ctx.config().getWriteSynchronizationMode(), op, key, val0, invokeArgs, retval, false, opCtx != null ? opCtx.expiry() : null, filters, ctx.kernalContext().job().currentTaskNameHash(), opCtx != null && opCtx.skipStore(), opCtx != null && opCtx.isKeepBinary(), opCtx != null && opCtx.recovery(), opCtx != null && opCtx.noRetries() ? 1 : MAX_RETRIES);
    } else {
        return new GridNearAtomicUpdateFuture(ctx, this, ctx.config().getWriteSynchronizationMode(), op, Collections.singletonList(key), val0 != null ? Collections.singletonList(val0) : null, invokeArgs, conflictPutVal != null ? Collections.singleton(conflictPutVal) : null, conflictRmvVer != null ? Collections.singleton(conflictRmvVer) : null, retval, false, opCtx != null ? opCtx.expiry() : null, filters, ctx.kernalContext().job().currentTaskNameHash(), opCtx != null && opCtx.skipStore(), opCtx != null && opCtx.isKeepBinary(), opCtx != null && opCtx.recovery(), opCtx != null && opCtx.noRetries() ? 1 : MAX_RETRIES);
    }
}
Also used : GridCacheDrInfo(org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) CacheEntryPredicate(org.apache.ignite.internal.processors.cache.CacheEntryPredicate) GridCacheOperation(org.apache.ignite.internal.processors.cache.GridCacheOperation)

Example 33 with CacheOperationContext

use of org.apache.ignite.internal.processors.cache.CacheOperationContext in project ignite by apache.

the class GridDhtAtomicCache method invokeAll0.

/**
 * @param async Async operation flag.
 * @param keys Keys.
 * @param entryProcessor Entry processor.
 * @param args Entry processor arguments.
 * @return Future.
 */
private <T> IgniteInternalFuture<Map<K, EntryProcessorResult<T>>> invokeAll0(boolean async, Set<? extends K> keys, final EntryProcessor<K, V, T> entryProcessor, Object... args) {
    A.notNull(keys, "keys", entryProcessor, "entryProcessor");
    final boolean statsEnabled = ctx.statisticsEnabled();
    final long start = statsEnabled ? System.nanoTime() : 0L;
    Map<? extends K, EntryProcessor> invokeMap = F.viewAsMap(keys, new C1<K, EntryProcessor>() {

        @Override
        public EntryProcessor apply(K k) {
            return entryProcessor;
        }
    });
    CacheOperationContext opCtx = ctx.operationContextPerCall();
    final boolean keepBinary = opCtx != null && opCtx.isKeepBinary();
    IgniteInternalFuture<Map<K, EntryProcessorResult<T>>> resFut = updateAll0(null, invokeMap, args, null, null, false, false, TRANSFORM, async);
    return resFut.chain(new CX1<IgniteInternalFuture<Map<K, EntryProcessorResult<T>>>, Map<K, EntryProcessorResult<T>>>() {

        @Override
        public Map<K, EntryProcessorResult<T>> applyx(IgniteInternalFuture<Map<K, EntryProcessorResult<T>>> fut) throws IgniteCheckedException {
            Map<Object, EntryProcessorResult> resMap = (Map) fut.get();
            if (statsEnabled)
                metrics0().addInvokeTimeNanos(System.nanoTime() - start);
            return ctx.unwrapInvokeResult(resMap, keepBinary);
        }
    });
}
Also used : CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) EntryProcessor(javax.cache.processor.EntryProcessor) EntryProcessorResult(javax.cache.processor.EntryProcessorResult) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IGNITE_ATOMIC_DEFERRED_ACK_TIMEOUT(org.apache.ignite.IgniteSystemProperties.IGNITE_ATOMIC_DEFERRED_ACK_TIMEOUT) EVT_CACHE_OBJECT_PUT(org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_PUT) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) GridCacheConcurrentMap(org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap) HashMap(java.util.HashMap)

Example 34 with CacheOperationContext

use of org.apache.ignite.internal.processors.cache.CacheOperationContext in project ignite by apache.

the class GridDhtAtomicCache method getAllAsyncInternal.

/**
 * @param keys Keys.
 * @param forcePrimary Force primary flag.
 * @param taskName Task name.
 * @param deserializeBinary Deserialize binary flag.
 * @param readRepairStrategy Read Repair strategy.
 * @param skipVals Skip values flag.
 * @param needVer Need version flag.
 * @param asyncOp Async operation flag.
 * @return Future.
 */
private IgniteInternalFuture<Map<K, V>> getAllAsyncInternal(@Nullable final Collection<? extends K> keys, final boolean forcePrimary, final String taskName, final boolean deserializeBinary, final boolean recovery, final ReadRepairStrategy readRepairStrategy, final boolean skipVals, final boolean needVer, boolean asyncOp) {
    ctx.checkSecurity(SecurityPermission.CACHE_READ);
    if (F.isEmpty(keys))
        return new GridFinishedFuture<>(Collections.<K, V>emptyMap());
    warnIfUnordered(keys, BulkOperation.GET);
    CacheOperationContext opCtx = ctx.operationContextPerCall();
    final ExpiryPolicy expiryPlc = skipVals ? null : opCtx != null ? opCtx.expiry() : null;
    final boolean skipStore = opCtx != null && opCtx.skipStore();
    if (asyncOp) {
        return asyncOp(new CO<IgniteInternalFuture<Map<K, V>>>() {

            @Override
            public IgniteInternalFuture<Map<K, V>> apply() {
                return getAllAsync0(ctx.cacheKeysView(keys), forcePrimary, taskName, deserializeBinary, recovery, readRepairStrategy, expiryPlc, skipVals, skipStore, needVer);
            }
        });
    } else {
        return getAllAsync0(ctx.cacheKeysView(keys), 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)

Example 35 with CacheOperationContext

use of org.apache.ignite.internal.processors.cache.CacheOperationContext in project ignite by apache.

the class GridDhtColocatedLockFuture method mapAsPrimary.

/**
 * Tries to map this future in assumption that local node is primary for all keys passed in.
 * If node is not primary for one of the keys, then mapping is reverted and full remote mapping is performed.
 *
 * @param keys Keys to lock.
 * @param topVer Topology version.
 * @return {@code True} if all keys were mapped locally, {@code false} if full mapping should be performed.
 * @throws IgniteCheckedException If key cannot be added to mapping.
 */
private boolean mapAsPrimary(Collection<KeyCacheObject> keys, AffinityTopologyVersion topVer) throws IgniteCheckedException {
    // Assign keys to primary nodes.
    Collection<KeyCacheObject> distributedKeys = new ArrayList<>(keys.size());
    boolean explicit = false;
    for (KeyCacheObject key : keys) {
        if (!cctx.affinity().primaryByKey(cctx.localNode(), key, topVer)) {
            // Remove explicit locks added so far.
            for (KeyCacheObject k : keys) cctx.mvcc().removeExplicitLock(threadId, cctx.txKey(k), lockVer);
            return false;
        }
        explicit |= addLocalKey(key, topVer, distributedKeys);
        if (isDone())
            return true;
    }
    if (tx != null) {
        if (explicit)
            tx.markExplicit(cctx.localNodeId());
        tx.colocatedLocallyMapped(true);
    }
    if (!distributedKeys.isEmpty()) {
        if (tx != null) {
            for (KeyCacheObject key : distributedKeys) tx.addKeyMapping(cctx.txKey(key), cctx.localNode());
        }
        lockLocally(distributedKeys, topVer);
    }
    GridDhtPartitionsExchangeFuture lastFinishedFut = cctx.shared().exchange().lastFinishedFuture();
    CacheOperationContext opCtx = cctx.operationContextPerCall();
    CacheInvalidStateException validateCacheE = lastFinishedFut.validateCache(cctx, opCtx != null && opCtx.recovery(), read, null, keys);
    if (validateCacheE != null)
        onDone(validateCacheE);
    return true;
}
Also used : GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) ArrayList(java.util.ArrayList) CacheInvalidStateException(org.apache.ignite.internal.processors.cache.CacheInvalidStateException) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Aggregations

CacheOperationContext (org.apache.ignite.internal.processors.cache.CacheOperationContext)48 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)18 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)17 Map (java.util.Map)16 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)16 IgniteCacheExpiryPolicy (org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy)13 ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)12 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)12 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)11 LinkedHashMap (java.util.LinkedHashMap)9 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)9 HashMap (java.util.HashMap)7 GridCacheConcurrentMap (org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap)7 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)7 ArrayList (java.util.ArrayList)6 CacheException (javax.cache.CacheException)6 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)6 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)6 GridCacheReturn (org.apache.ignite.internal.processors.cache.GridCacheReturn)5 GridTimeoutObject (org.apache.ignite.internal.processors.timeout.GridTimeoutObject)5