Search in sources :

Example 16 with EntryGetResult

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

the class GridNearTxLocal method enlistWriteEntry.

/**
     * @param cacheCtx Cache context.
     * @param cacheKey Key.
     * @param val Value.
     * @param entryProcessor Entry processor.
     * @param invokeArgs Optional arguments for EntryProcessor.
     * @param expiryPlc Explicitly specified expiry policy for entry.
     * @param retval Return value flag.
     * @param lockOnly Lock only flag.
     * @param filter Filter.
     * @param drVer DR version.
     * @param drTtl DR ttl.
     * @param drExpireTime DR expire time.
     * @param ret Return value.
     * @param enlisted Enlisted keys collection.
     * @param skipStore Skip store flag.
     * @param singleRmv {@code True} for single remove operation.
     * @param hasFilters {@code True} if filters not empty.
     * @param needVal {@code True} if value is needed.
     * @param needReadVer {@code True} if need read entry version.
     * @return {@code True} if entry value should be loaded.
     * @throws IgniteCheckedException If failed.
     */
private boolean enlistWriteEntry(GridCacheContext cacheCtx, @Nullable AffinityTopologyVersion entryTopVer, final KeyCacheObject cacheKey, @Nullable final Object val, @Nullable final EntryProcessor<?, ?, ?> entryProcessor, @Nullable final Object[] invokeArgs, @Nullable final ExpiryPolicy expiryPlc, final boolean retval, final boolean lockOnly, final CacheEntryPredicate[] filter, final GridCacheVersion drVer, final long drTtl, long drExpireTime, final GridCacheReturn ret, @Nullable final Collection<KeyCacheObject> enlisted, boolean skipStore, boolean singleRmv, boolean hasFilters, final boolean needVal, boolean needReadVer, boolean keepBinary, boolean recovery) throws IgniteCheckedException {
    boolean loadMissed = false;
    final boolean rmv = val == null && entryProcessor == null;
    IgniteTxKey txKey = cacheCtx.txKey(cacheKey);
    IgniteTxEntry txEntry = entry(txKey);
    // First time access.
    if (txEntry == null) {
        while (true) {
            GridCacheEntryEx entry = entryEx(cacheCtx, txKey, entryTopVer != null ? entryTopVer : topologyVersion());
            try {
                entry.unswap(false);
                // Check if lock is being explicitly acquired by the same thread.
                if (!implicit && cctx.kernalContext().config().isCacheSanityCheckEnabled() && entry.lockedByThread(threadId, xidVer)) {
                    throw new IgniteCheckedException("Cannot access key within transaction if lock is " + "externally held [key=" + CU.value(cacheKey, cacheCtx, false) + ", entry=" + entry + ", xidVer=" + xidVer + ", threadId=" + threadId + ", locNodeId=" + cctx.localNodeId() + ']');
                }
                CacheObject old = null;
                GridCacheVersion readVer = null;
                if (optimistic() && !implicit()) {
                    try {
                        if (needReadVer) {
                            EntryGetResult res = primaryLocal(entry) ? entry.innerGetVersioned(null, this, /*metrics*/
                            retval, /*events*/
                            retval, CU.subjectId(this, cctx), entryProcessor, resolveTaskName(), null, keepBinary, null) : null;
                            if (res != null) {
                                old = res.value();
                                readVer = res.version();
                            }
                        } else {
                            old = entry.innerGet(null, this, /*read through*/
                            false, /*metrics*/
                            retval, /*events*/
                            retval, CU.subjectId(this, cctx), entryProcessor, resolveTaskName(), null, keepBinary);
                        }
                    } catch (ClusterTopologyCheckedException e) {
                        entry.context().evicts().touch(entry, topologyVersion());
                        throw e;
                    }
                } else
                    old = entry.rawGet();
                final GridCacheOperation op = lockOnly ? NOOP : rmv ? DELETE : entryProcessor != null ? TRANSFORM : old != null ? UPDATE : CREATE;
                if (old != null && hasFilters && !filter(entry.context(), cacheKey, old, filter)) {
                    ret.set(cacheCtx, old, false, keepBinary);
                    if (!readCommitted()) {
                        if (optimistic() && serializable()) {
                            txEntry = addEntry(op, old, entryProcessor, invokeArgs, entry, expiryPlc, filter, true, drTtl, drExpireTime, drVer, skipStore, keepBinary);
                        } else {
                            txEntry = addEntry(READ, old, null, null, entry, null, CU.empty0(), false, -1L, -1L, null, skipStore, keepBinary);
                        }
                        txEntry.markValid();
                        if (needReadVer) {
                            assert readVer != null;
                            txEntry.entryReadVersion(singleRmv ? SER_READ_NOT_EMPTY_VER : readVer);
                        }
                    }
                    if (readCommitted())
                        cacheCtx.evicts().touch(entry, topologyVersion());
                    // While.
                    break;
                }
                txEntry = addEntry(op, cacheCtx.toCacheObject(val), entryProcessor, invokeArgs, entry, expiryPlc, filter, true, drTtl, drExpireTime, drVer, skipStore, keepBinary);
                if (enlisted != null)
                    enlisted.add(cacheKey);
                if (!pessimistic() && !implicit()) {
                    txEntry.markValid();
                    if (old == null) {
                        if (needVal)
                            loadMissed = true;
                        else {
                            assert !implicit() || !transform : this;
                            assert txEntry.op() != TRANSFORM : txEntry;
                            if (retval)
                                ret.set(cacheCtx, null, true, keepBinary);
                            else
                                ret.success(true);
                        }
                    } else {
                        if (needReadVer) {
                            assert readVer != null;
                            txEntry.entryReadVersion(singleRmv ? SER_READ_NOT_EMPTY_VER : readVer);
                        }
                        if (retval && !transform)
                            ret.set(cacheCtx, old, true, keepBinary);
                        else {
                            if (txEntry.op() == TRANSFORM) {
                                GridCacheVersion ver;
                                try {
                                    ver = entry.version();
                                } catch (GridCacheEntryRemovedException ex) {
                                    assert optimistic() : txEntry;
                                    if (log.isDebugEnabled())
                                        log.debug("Failed to get entry version " + "[err=" + ex.getMessage() + ']');
                                    ver = null;
                                }
                                addInvokeResult(txEntry, old, ret, ver);
                            } else
                                ret.success(true);
                        }
                    }
                } else // Pessimistic.
                {
                    if (retval && !transform)
                        ret.set(cacheCtx, old, true, keepBinary);
                    else
                        ret.success(true);
                }
                // While.
                break;
            } catch (GridCacheEntryRemovedException ignore) {
                if (log.isDebugEnabled())
                    log.debug("Got removed entry in transaction putAll0 method: " + entry);
            }
        }
    } else {
        if (entryProcessor == null && txEntry.op() == TRANSFORM)
            throw new IgniteCheckedException("Failed to enlist write value for key (cannot have update value in " + "transaction after EntryProcessor is applied): " + CU.value(cacheKey, cacheCtx, false));
        GridCacheEntryEx entry = txEntry.cached();
        CacheObject v = txEntry.value();
        boolean del = txEntry.op() == DELETE && rmv;
        if (!del) {
            if (hasFilters && !filter(entry.context(), cacheKey, v, filter)) {
                ret.set(cacheCtx, v, false, keepBinary);
                return loadMissed;
            }
            GridCacheOperation op = rmv ? DELETE : entryProcessor != null ? TRANSFORM : v != null ? UPDATE : CREATE;
            txEntry = addEntry(op, cacheCtx.toCacheObject(val), entryProcessor, invokeArgs, entry, expiryPlc, filter, true, drTtl, drExpireTime, drVer, skipStore, keepBinary);
            if (enlisted != null)
                enlisted.add(cacheKey);
            if (txEntry.op() == TRANSFORM) {
                GridCacheVersion ver;
                try {
                    ver = entry.version();
                } catch (GridCacheEntryRemovedException e) {
                    assert optimistic() : txEntry;
                    if (log.isDebugEnabled())
                        log.debug("Failed to get entry version: [msg=" + e.getMessage() + ']');
                    ver = null;
                }
                addInvokeResult(txEntry, txEntry.value(), ret, ver);
            }
        }
        if (!pessimistic()) {
            txEntry.markValid();
            if (retval && !transform)
                ret.set(cacheCtx, v, true, keepBinary);
            else
                ret.success(true);
        }
    }
    return loadMissed;
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) EntryGetResult(org.apache.ignite.internal.processors.cache.EntryGetResult) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) IgniteTxKey(org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridCacheOperation(org.apache.ignite.internal.processors.cache.GridCacheOperation) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 17 with EntryGetResult

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

the class GridNearTxLocal method processLoaded.

/**
     * @param key Key.
     * @param val Value.
     * @param needVer If {@code true} version is required for loaded values.
     * @param skipVals Skip values flag.
     * @param c Closure.
     */
private void processLoaded(KeyCacheObject key, @Nullable Object val, boolean needVer, boolean skipVals, GridInClosure3<KeyCacheObject, Object, GridCacheVersion> c) {
    if (val != null) {
        Object v;
        GridCacheVersion ver;
        if (needVer) {
            EntryGetResult getRes = (EntryGetResult) val;
            v = getRes.value();
            ver = getRes.version();
        } else {
            v = val;
            ver = null;
        }
        if (skipVals && v == Boolean.FALSE)
            c.apply(key, null, IgniteTxEntry.SER_READ_EMPTY_ENTRY_VER);
        else
            c.apply(key, v, ver);
    } else
        c.apply(key, null, IgniteTxEntry.SER_READ_EMPTY_ENTRY_VER);
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) EntryGetResult(org.apache.ignite.internal.processors.cache.EntryGetResult) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Aggregations

EntryGetResult (org.apache.ignite.internal.processors.cache.EntryGetResult)17 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)17 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)15 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)14 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)12 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)10 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)10 IgniteCacheExpiryPolicy (org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy)5 CacheDataRow (org.apache.ignite.internal.processors.cache.database.CacheDataRow)5 Map (java.util.Map)4 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)4 IgniteTxEntry (org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry)4 GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)3 GridCacheEntryInfo (org.apache.ignite.internal.processors.cache.GridCacheEntryInfo)3 GridDhtInvalidPartitionException (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException)3 IgniteTxKey (org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey)3 GridClosureException (org.apache.ignite.internal.util.lang.GridClosureException)3 LinkedHashMap (java.util.LinkedHashMap)2