Search in sources :

Example 46 with CacheOperationContext

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

the class GridDhtAtomicCache method updateAll0.

/**
 * Entry point for all public API put/transform methods.
 *
 * @param map Put map. Either {@code map}, {@code invokeMap} or {@code conflictPutMap} should be passed.
 * @param invokeMap Invoke map. Either {@code map}, {@code invokeMap} or {@code conflictPutMap} should be passed.
 * @param invokeArgs Optional arguments for EntryProcessor.
 * @param conflictPutMap Conflict put map.
 * @param conflictRmvMap Conflict remove map.
 * @param retval Return value required flag.
 * @param rawRetval Return {@code GridCacheReturn} instance.
 * @param async Async operation flag.
 * @return Completion future.
 */
@SuppressWarnings("ConstantConditions")
private IgniteInternalFuture updateAll0(@Nullable Map<? extends K, ? extends V> map, @Nullable Map<? extends K, ? extends EntryProcessor> invokeMap, @Nullable Object[] invokeArgs, @Nullable Map<KeyCacheObject, GridCacheDrInfo> conflictPutMap, @Nullable Map<KeyCacheObject, GridCacheVersion> conflictRmvMap, final boolean retval, final boolean rawRetval, final GridCacheOperation op, boolean async) {
    assert ctx.updatesAllowed();
    ctx.checkSecurity(SecurityPermission.CACHE_PUT);
    final CacheOperationContext opCtx = ctx.operationContextPerCall();
    if (opCtx != null && opCtx.hasDataCenterId()) {
        assert conflictPutMap == null : conflictPutMap;
        assert conflictRmvMap == null : conflictRmvMap;
        if (op == GridCacheOperation.TRANSFORM) {
            assert invokeMap != null : invokeMap;
            conflictPutMap = F.viewReadOnly((Map) invokeMap, new IgniteClosure<EntryProcessor, GridCacheDrInfo>() {

                @Override
                public GridCacheDrInfo apply(EntryProcessor o) {
                    return new GridCacheDrInfo(o, nextVersion(opCtx.dataCenterId()));
                }
            });
            invokeMap = null;
        } else if (op == GridCacheOperation.DELETE) {
            assert map != null : map;
            conflictRmvMap = F.viewReadOnly((Map) map, new IgniteClosure<V, GridCacheVersion>() {

                @Override
                public GridCacheVersion apply(V o) {
                    return nextVersion(opCtx.dataCenterId());
                }
            });
            map = null;
        } else {
            assert map != null : map;
            conflictPutMap = F.viewReadOnly((Map) map, new IgniteClosure<V, GridCacheDrInfo>() {

                @Override
                public GridCacheDrInfo apply(V o) {
                    return new GridCacheDrInfo(ctx.toCacheObject(o), nextVersion(opCtx.dataCenterId()));
                }
            });
            map = null;
        }
    }
    int taskNameHash = ctx.kernalContext().job().currentTaskNameHash();
    final GridNearAtomicUpdateFuture updateFut = new GridNearAtomicUpdateFuture(ctx, this, ctx.config().getWriteSynchronizationMode(), op, map != null ? map.keySet() : invokeMap != null ? invokeMap.keySet() : conflictPutMap != null ? conflictPutMap.keySet() : conflictRmvMap.keySet(), map != null ? map.values() : invokeMap != null ? invokeMap.values() : null, invokeArgs, (Collection) (conflictPutMap != null ? conflictPutMap.values() : null), conflictRmvMap != null ? conflictRmvMap.values() : null, retval, rawRetval, opCtx != null ? opCtx.expiry() : null, CU.filterArray(null), taskNameHash, opCtx != null && opCtx.skipStore(), opCtx != null && opCtx.isKeepBinary(), opCtx != null && opCtx.recovery(), opCtx != null && opCtx.noRetries() ? 1 : MAX_RETRIES);
    if (async) {
        return asyncOp(new CO<IgniteInternalFuture<Object>>() {

            @Override
            public IgniteInternalFuture<Object> apply() {
                updateFut.map();
                return updateFut;
            }
        });
    } else {
        updateFut.map();
        return updateFut;
    }
}
Also used : IgniteClosure(org.apache.ignite.lang.IgniteClosure) CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridCacheDrInfo(org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo) EntryProcessor(javax.cache.processor.EntryProcessor) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) GridCacheConcurrentMap(org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap) HashMap(java.util.HashMap)

Example 47 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 48 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 49 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 50 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)

Aggregations

CacheOperationContext (org.apache.ignite.internal.processors.cache.CacheOperationContext)86 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)33 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)29 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)29 Map (java.util.Map)27 IgniteCacheExpiryPolicy (org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy)23 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)21 ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)20 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)18 LinkedHashMap (java.util.LinkedHashMap)17 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)17 HashMap (java.util.HashMap)13 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)13 GridCacheConcurrentMap (org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap)12 ArrayList (java.util.ArrayList)11 CacheException (javax.cache.CacheException)11 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)11 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)11 IgniteTxRollbackCheckedException (org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException)11 IgniteTxTimeoutCheckedException (org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException)11