Search in sources :

Example 16 with CacheOperationContext

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

the class GridLocalAtomicCache method removeAllAsync0.

/**
 * Entry point for public API remove methods.
 *
 * @param keys Keys to remove.
 * @param retval Return value required flag.
 * @param rawRetval Return {@code GridCacheReturn} instance.
 * @param filter Cache entry filter.
 * @return Completion future.
 */
private IgniteInternalFuture removeAllAsync0(@Nullable final Collection<? extends K> keys, final boolean retval, final boolean rawRetval, @Nullable final CacheEntryPredicate filter) {
    final boolean writeThrough = ctx.writeThrough();
    final boolean readThrough = ctx.readThrough();
    final ExpiryPolicy expiryPlc = expiryPerCall();
    CacheOperationContext opCtx = ctx.operationContextPerCall();
    final boolean keepBinary = opCtx != null && opCtx.isKeepBinary();
    return asyncOp(new GridPlainCallable<Object>() {

        @Override
        public Object call() throws Exception {
            return updateAllInternal(DELETE, keys, null, null, expiryPlc, retval, rawRetval, filter, writeThrough, readThrough, keepBinary);
        }
    });
}
Also used : CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) IgniteCacheExpiryPolicy(org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CachePartialUpdateCheckedException(org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheStorePartialUpdateException(org.apache.ignite.internal.processors.cache.CacheStorePartialUpdateException)

Example 17 with CacheOperationContext

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

the class GridLocalAtomicCache method put0.

/**
 * {@inheritDoc}
 */
@Override
protected boolean put0(K key, V val, CacheEntryPredicate filter) throws IgniteCheckedException {
    CacheOperationContext opCtx = ctx.operationContextPerCall();
    Boolean res = (Boolean) updateAllInternal(UPDATE, Collections.singleton(key), Collections.singleton(val), null, expiryPerCall(), false, false, filter, ctx.writeThrough(), ctx.readThrough(), opCtx != null && opCtx.isKeepBinary());
    assert res != null;
    return res;
}
Also used : CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext)

Example 18 with CacheOperationContext

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

the class GridLocalAtomicCache method removeAll0.

/**
 * {@inheritDoc}
 */
@Override
public void removeAll0(Collection<? extends K> keys) throws IgniteCheckedException {
    CacheOperationContext opCtx = ctx.operationContextPerCall();
    updateAllInternal(DELETE, keys, null, null, expiryPerCall(), false, false, null, ctx.writeThrough(), ctx.readThrough(), opCtx != null && opCtx.isKeepBinary());
}
Also used : CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext)

Example 19 with CacheOperationContext

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

the class GridLocalAtomicCache method getAllInternal.

/**
 * Entry point to all public API get methods.
 *
 * @param keys Keys to remove.
 * @param storeEnabled Store enabled flag.
 * @param taskName Task name.
 * @param deserializeBinary Deserialize binary .
 * @param skipVals Skip value flag.
 * @param needVer Need version.
 * @return Key-value map.
 * @throws IgniteCheckedException If failed.
 */
@SuppressWarnings("ConstantConditions")
private Map<K, V> getAllInternal(@Nullable Collection<? extends K> keys, boolean storeEnabled, String taskName, boolean deserializeBinary, boolean skipVals, boolean needVer) throws IgniteCheckedException {
    ctx.checkSecurity(SecurityPermission.CACHE_READ);
    if (F.isEmpty(keys))
        return Collections.emptyMap();
    CacheOperationContext opCtx = ctx.operationContextPerCall();
    Map<K, V> vals = U.newHashMap(keys.size());
    warnIfUnordered(keys, BulkOperation.GET);
    final IgniteCacheExpiryPolicy expiry = expiryPolicy(opCtx != null ? opCtx.expiry() : null);
    boolean success = true;
    boolean readNoEntry = ctx.readNoEntry(expiry, false);
    final boolean evt = !skipVals;
    ctx.shared().database().checkpointReadLock();
    try {
        for (K key : keys) {
            if (key == null)
                throw new NullPointerException("Null key.");
            KeyCacheObject cacheKey = ctx.toCacheKeyObject(key);
            boolean skipEntry = readNoEntry;
            if (readNoEntry) {
                CacheDataRow row = ctx.offheap().read(ctx, cacheKey);
                if (row != null) {
                    long expireTime = row.expireTime();
                    if (expireTime == 0 || expireTime > U.currentTimeMillis()) {
                        ctx.addResult(vals, cacheKey, row.value(), skipVals, false, deserializeBinary, true, null, row.version(), 0, 0, needVer, null);
                        if (ctx.statisticsEnabled() && !skipVals)
                            metrics0().onRead(true);
                        if (evt) {
                            ctx.events().readEvent(cacheKey, null, null, row.value(), taskName, !deserializeBinary);
                        }
                    } else
                        skipEntry = false;
                } else
                    success = false;
            }
            if (!skipEntry) {
                GridCacheEntryEx entry = null;
                while (true) {
                    try {
                        entry = entryEx(cacheKey);
                        if (entry != null) {
                            CacheObject v;
                            if (needVer) {
                                EntryGetResult res = entry.innerGetVersioned(null, null, /*update-metrics*/
                                false, /*event*/
                                evt, null, taskName, expiry, !deserializeBinary, null);
                                if (res != null) {
                                    ctx.addResult(vals, cacheKey, res, skipVals, false, deserializeBinary, true, needVer);
                                } else
                                    success = false;
                            } else {
                                v = entry.innerGet(null, null, /*read-through*/
                                false, /*update-metrics*/
                                true, /*event*/
                                evt, null, taskName, expiry, !deserializeBinary);
                                if (v != null) {
                                    ctx.addResult(vals, cacheKey, v, skipVals, false, deserializeBinary, true, null, 0, 0, null);
                                } else
                                    success = false;
                            }
                        }
                        // While.
                        break;
                    } catch (GridCacheEntryRemovedException ignored) {
                    // No-op, retry.
                    } finally {
                        if (entry != null)
                            entry.touch();
                    }
                    if (!success && storeEnabled)
                        break;
                }
            }
            if (!success) {
                if (!storeEnabled && ctx.statisticsEnabled() && !skipVals)
                    metrics0().onRead(false);
            }
        }
    } finally {
        ctx.shared().database().checkpointReadUnlock();
    }
    if (success || !storeEnabled)
        return vals;
    return getAllAsync(keys, null, opCtx == null || !opCtx.skipStore(), false, taskName, deserializeBinary, opCtx != null && opCtx.recovery(), null, /*force primary*/
    false, expiry, skipVals, needVer).get();
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) 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 20 with CacheOperationContext

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

the class GridLocalAtomicCache method putAll0.

/**
 * {@inheritDoc}
 */
@Override
protected void putAll0(Map<? extends K, ? extends V> m) throws IgniteCheckedException {
    CacheOperationContext opCtx = ctx.operationContextPerCall();
    updateAllInternal(UPDATE, m.keySet(), m.values(), null, expiryPerCall(), false, false, null, ctx.writeThrough(), ctx.readThrough(), opCtx != null && opCtx.isKeepBinary());
}
Also used : CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext)

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