Search in sources :

Example 6 with CacheEntryPredicate

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

the class GridNearAtomicFullUpdateRequest method prepareMarshal.

/**
 * {@inheritDoc}
 */
@Override
public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException {
    super.prepareMarshal(ctx);
    GridCacheContext cctx = ctx.cacheContext(cacheId);
    if (expiryPlc != null && expiryPlcBytes == null)
        expiryPlcBytes = CU.marshal(cctx, new IgniteExternalizableExpiryPolicy(expiryPlc));
    prepareMarshalCacheObjects(keys, cctx);
    if (filter != null) {
        boolean hasFilter = false;
        for (CacheEntryPredicate p : filter) {
            if (p != null) {
                hasFilter = true;
                p.prepareMarshal(cctx);
            }
        }
        if (!hasFilter)
            filter = null;
    }
    if (op == TRANSFORM) {
        // force addition of deployment info for entry processors if P2P is enabled globally.
        if (!addDepInfo && ctx.deploymentEnabled())
            addDepInfo = true;
        if (entryProcessorsBytes == null)
            entryProcessorsBytes = marshalCollection(entryProcessors, cctx);
        if (invokeArgsBytes == null)
            invokeArgsBytes = marshalInvokeArguments(invokeArgs, cctx);
    } else
        prepareMarshalCacheObjects(vals, cctx);
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IgniteExternalizableExpiryPolicy(org.apache.ignite.internal.processors.cache.distributed.IgniteExternalizableExpiryPolicy) CacheEntryPredicate(org.apache.ignite.internal.processors.cache.CacheEntryPredicate)

Example 7 with CacheEntryPredicate

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

the class GridNearAtomicFullUpdateRequest method finishUnmarshal.

/**
 * {@inheritDoc}
 */
@Override
public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException {
    super.finishUnmarshal(ctx, ldr);
    GridCacheContext cctx = ctx.cacheContext(cacheId);
    if (expiryPlcBytes != null && expiryPlc == null)
        expiryPlc = U.unmarshal(ctx, expiryPlcBytes, U.resolveClassLoader(ldr, ctx.gridConfig()));
    finishUnmarshalCacheObjects(keys, cctx, ldr);
    if (filter != null) {
        for (CacheEntryPredicate p : filter) {
            if (p != null)
                p.finishUnmarshal(cctx, ldr);
        }
    }
    if (op == TRANSFORM) {
        if (entryProcessors == null)
            entryProcessors = unmarshalCollection(entryProcessorsBytes, ctx, ldr);
        if (invokeArgs == null)
            invokeArgs = unmarshalInvokeArguments(invokeArgsBytes, ctx, ldr);
    } else
        finishUnmarshalCacheObjects(vals, cctx, ldr);
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) CacheEntryPredicate(org.apache.ignite.internal.processors.cache.CacheEntryPredicate)

Example 8 with CacheEntryPredicate

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

the class IgniteTxEntry method marshal.

/**
 * @param ctx Context.
 * @param transferExpiry {@code True} if expire policy should be marshalled.
 * @throws IgniteCheckedException If failed.
 */
public void marshal(GridCacheSharedContext<?, ?> ctx, boolean transferExpiry) throws IgniteCheckedException {
    if (filters != null) {
        for (CacheEntryPredicate p : filters) {
            if (p != null)
                p.prepareMarshal(this.ctx);
        }
    }
    // Do not serialize filters if they are null.
    if (transformClosBytes == null && entryProcessorsCol != null)
        transformClosBytes = CU.marshal(this.ctx, entryProcessorsCol);
    if (transferExpiry)
        transferExpiryPlc = expiryPlc != null && expiryPlc != this.ctx.expiry();
    key.prepareMarshal(context().cacheObjectContext());
    val.marshal(context());
    if (transferExpiryPlc) {
        if (expiryPlcBytes == null)
            expiryPlcBytes = CU.marshal(this.ctx, new IgniteExternalizableExpiryPolicy(expiryPlc));
    } else
        expiryPlcBytes = null;
}
Also used : CacheEntryPredicate(org.apache.ignite.internal.processors.cache.CacheEntryPredicate) IgniteExternalizableExpiryPolicy(org.apache.ignite.internal.processors.cache.distributed.IgniteExternalizableExpiryPolicy)

Example 9 with CacheEntryPredicate

use of org.apache.ignite.internal.processors.cache.CacheEntryPredicate 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);
    IgniteBiTuple<Boolean, ?> res = null;
    CachePartialUpdateCheckedException err = null;
    ctx.shared().database().checkpointReadLock();
    try {
        ctx.shared().database().ensureFreeSpace(ctx.dataRegion());
        if (writeThrough && keys.size() > 1) {
            return updateWithBatch(op, keys, vals, invokeArgs, expiryPlc, ver, filters, keepBinary, subjId, taskName);
        }
        Iterator<?> valsIter = vals != null ? vals.iterator() : 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);
                ctx.validateKeyAndValue(cacheKey, (CacheObject) 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());
                }
            }
        }
    } finally {
        ctx.shared().database().checkpointReadUnlock();
    }
    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) LinkedHashMap(java.util.LinkedHashMap) T2(org.apache.ignite.internal.util.typedef.T2) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 10 with CacheEntryPredicate

use of org.apache.ignite.internal.processors.cache.CacheEntryPredicate 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), ctx.versions().next(dcId));
            val0 = null;
        } else if (op == GridCacheOperation.TRANSFORM) {
            conflictPutVal = new GridCacheDrInfo(proc, ctx.versions().next(dcId));
            val0 = null;
        } else
            conflictRmvVer = ctx.versions().next(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.subjectIdPerCall(null, opCtx), 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.subjectIdPerCall(null, opCtx), 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)

Aggregations

CacheEntryPredicate (org.apache.ignite.internal.processors.cache.CacheEntryPredicate)10 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)4 GridCacheReturn (org.apache.ignite.internal.processors.cache.GridCacheReturn)4 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)3 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)3 CacheOperationContext (org.apache.ignite.internal.processors.cache.CacheOperationContext)3 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)3 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)3 IgniteTxRollbackCheckedException (org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException)3 GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)3 GridClosureException (org.apache.ignite.internal.util.lang.GridClosureException)3 ArrayList (java.util.ArrayList)2 CacheException (javax.cache.CacheException)2 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)2 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)2 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)2 IgniteExternalizableExpiryPolicy (org.apache.ignite.internal.processors.cache.distributed.IgniteExternalizableExpiryPolicy)2 IgniteTxOptimisticCheckedException (org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException)2