Search in sources :

Example 26 with GridCacheReturn

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

the class GridLocalAtomicCache method updateAllInternal.

/**
     * Entry point for all public update methods (put, remove, invoke).
     *
     * @param op Operation.
     * @param keys Keys.
     * @param vals Values.
     * @param invokeArgs Optional arguments for EntryProcessor.
     * @param expiryPlc Expiry policy.
     * @param retval Return value required flag.
     * @param rawRetval Return {@code GridCacheReturn} instance.
     * @param filter Cache entry filter.
     * @param writeThrough Write through.
     * @param readThrough Read through.
     * @return Update result.
     * @throws IgniteCheckedException If failed.
     */
@SuppressWarnings("unchecked")
private Object updateAllInternal(GridCacheOperation op, Collection<? extends K> keys, @Nullable Iterable<?> vals, @Nullable Object[] invokeArgs, @Nullable ExpiryPolicy expiryPlc, boolean retval, boolean rawRetval, CacheEntryPredicate filter, boolean writeThrough, boolean readThrough, boolean keepBinary) throws IgniteCheckedException {
    if (keyCheck)
        validateCacheKeys(keys);
    if (op == DELETE)
        ctx.checkSecurity(SecurityPermission.CACHE_REMOVE);
    else
        ctx.checkSecurity(SecurityPermission.CACHE_PUT);
    String taskName = ctx.kernalContext().job().currentTaskName();
    GridCacheVersion ver = ctx.versions().next();
    UUID subjId = ctx.subjectIdPerCall(null);
    CacheEntryPredicate[] filters = CU.filterArray(filter);
    ctx.shared().database().ensureFreeSpace(ctx.memoryPolicy());
    if (writeThrough && keys.size() > 1) {
        return updateWithBatch(op, keys, vals, invokeArgs, expiryPlc, ver, filters, keepBinary, subjId, taskName);
    }
    Iterator<?> valsIter = vals != null ? vals.iterator() : null;
    IgniteBiTuple<Boolean, ?> res = null;
    CachePartialUpdateCheckedException err = null;
    boolean intercept = ctx.config().getInterceptor() != null;
    for (K key : keys) {
        if (key == null)
            throw new NullPointerException("Null key.");
        Object val = valsIter != null ? valsIter.next() : null;
        if (val == null && op != DELETE)
            throw new NullPointerException("Null value.");
        KeyCacheObject cacheKey = ctx.toCacheKeyObject(key);
        if (op == UPDATE)
            val = ctx.toCacheObject(val);
        else if (op == TRANSFORM)
            ctx.kernalContext().resource().inject(val, GridResourceIoc.AnnotationSet.ENTRY_PROCESSOR, ctx.name());
        while (true) {
            GridCacheEntryEx entry = null;
            try {
                entry = entryEx(cacheKey);
                GridTuple3<Boolean, Object, EntryProcessorResult<Object>> t = entry.innerUpdateLocal(ver, val == null ? DELETE : op, val, invokeArgs, writeThrough, readThrough, retval, keepBinary, expiryPlc, true, true, filters, intercept, subjId, taskName);
                if (op == TRANSFORM) {
                    if (t.get3() != null) {
                        Map<K, EntryProcessorResult> computedMap;
                        if (res == null) {
                            computedMap = U.newHashMap(keys.size());
                            res = new IgniteBiTuple<>(true, computedMap);
                        } else
                            computedMap = (Map<K, EntryProcessorResult>) res.get2();
                        computedMap.put(key, t.get3());
                    }
                } else if (res == null)
                    res = new T2(t.get1(), t.get2());
                // While.
                break;
            } catch (GridCacheEntryRemovedException ignored) {
                if (log.isDebugEnabled())
                    log.debug("Got removed entry while updating (will retry): " + key);
                entry = null;
            } catch (IgniteCheckedException e) {
                if (err == null)
                    err = partialUpdateException();
                err.add(F.asList(key), e);
                U.error(log, "Failed to update key : " + key, e);
                break;
            } finally {
                if (entry != null)
                    ctx.evicts().touch(entry, ctx.affinity().affinityTopologyVersion());
            }
        }
    }
    if (err != null)
        throw err;
    Object ret = res == null ? null : rawRetval ? new GridCacheReturn(ctx, true, keepBinary, res.get2(), res.get1()) : (retval || op == TRANSFORM) ? res.get2() : res.get1();
    if (op == TRANSFORM && ret == null)
        ret = Collections.emptyMap();
    return ret;
}
Also used : GridCacheReturn(org.apache.ignite.internal.processors.cache.GridCacheReturn) CachePartialUpdateCheckedException(org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) EntryProcessorResult(javax.cache.processor.EntryProcessorResult) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheEntryPredicate(org.apache.ignite.internal.processors.cache.CacheEntryPredicate) UUID(java.util.UUID) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) T2(org.apache.ignite.internal.util.typedef.T2) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 27 with GridCacheReturn

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

the class GridNearTxLocal method lockAllAsync.

/**
     * @param cacheCtx Cache context.
     * @param keys Keys.
     * @param retval Return value flag.
     * @param read Read flag.
     * @param createTtl Create ttl.
     * @param accessTtl Access ttl.
     * @param <K> Key type.
     * @param skipStore Skip store flag.
     * @param keepBinary Keep binary flag.
     * @return Future with respond.
     */
public <K> IgniteInternalFuture<GridCacheReturn> lockAllAsync(GridCacheContext cacheCtx, final Collection<? extends K> keys, boolean retval, boolean read, long createTtl, long accessTtl, boolean skipStore, boolean keepBinary) {
    assert pessimistic();
    try {
        checkValid();
    } catch (IgniteCheckedException e) {
        return new GridFinishedFuture<>(e);
    }
    final GridCacheReturn ret = new GridCacheReturn(localResult(), false);
    if (F.isEmpty(keys))
        return new GridFinishedFuture<>(ret);
    init();
    if (log.isDebugEnabled())
        log.debug("Before acquiring transaction lock on keys: " + keys);
    long timeout = remainingTime();
    if (timeout == -1)
        return new GridFinishedFuture<>(timeoutException());
    IgniteInternalFuture<Boolean> fut = cacheCtx.colocated().lockAllAsyncInternal(keys, timeout, this, isInvalidate(), read, retval, isolation, createTtl, accessTtl, CU.empty0(), skipStore, keepBinary);
    return new GridEmbeddedFuture<>(fut, new PLC1<GridCacheReturn>(ret, false) {

        @Override
        protected GridCacheReturn postLock(GridCacheReturn ret) {
            if (log.isDebugEnabled())
                log.debug("Acquired transaction lock on keys: " + keys);
            return ret;
        }
    });
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheReturn(org.apache.ignite.internal.processors.cache.GridCacheReturn) GridEmbeddedFuture(org.apache.ignite.internal.util.future.GridEmbeddedFuture)

Aggregations

GridCacheReturn (org.apache.ignite.internal.processors.cache.GridCacheReturn)27 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)18 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)12 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)12 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)11 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)11 CachePartialUpdateCheckedException (org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException)11 ArrayList (java.util.ArrayList)7 UUID (java.util.UUID)7 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)7 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)7 Map (java.util.Map)6 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)6 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)5 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)5 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 GridCacheOperation (org.apache.ignite.internal.processors.cache.GridCacheOperation)4 GridDhtCacheEntry (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry)4 GridDhtInvalidPartitionException (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException)4