Search in sources :

Example 26 with GridCacheEntryRemovedException

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

the class GridNearTxLocal method loadMissing.

/**
     * @param cacheCtx Cache context.
     * @param keys Keys to load.
     * @param filter Filter.
     * @param ret Return value.
     * @param needReadVer Read version flag.
     * @param singleRmv {@code True} for single remove operation.
     * @param hasFilters {@code True} if filters not empty.
     * @param readThrough Read through flag.
     * @param retval Return value flag.
     * @param expiryPlc Expiry policy.
     * @return Load future.
     */
private IgniteInternalFuture<Void> loadMissing(final GridCacheContext cacheCtx, final AffinityTopologyVersion topVer, final Set<KeyCacheObject> keys, final CacheEntryPredicate[] filter, final GridCacheReturn ret, final boolean needReadVer, final boolean singleRmv, final boolean hasFilters, final boolean readThrough, final boolean retval, final boolean keepBinary, final boolean recovery, final ExpiryPolicy expiryPlc) {
    GridInClosure3<KeyCacheObject, Object, GridCacheVersion> c = new GridInClosure3<KeyCacheObject, Object, GridCacheVersion>() {

        @Override
        public void apply(KeyCacheObject key, @Nullable Object val, @Nullable GridCacheVersion loadVer) {
            if (log.isDebugEnabled())
                log.debug("Loaded value from remote node [key=" + key + ", val=" + val + ']');
            IgniteTxEntry e = entry(new IgniteTxKey(key, cacheCtx.cacheId()));
            assert e != null;
            if (needReadVer) {
                assert loadVer != null;
                e.entryReadVersion(singleRmv && val != null ? SER_READ_NOT_EMPTY_VER : loadVer);
            }
            if (singleRmv) {
                assert !hasFilters && !retval;
                assert val == null || Boolean.TRUE.equals(val) : val;
                ret.set(cacheCtx, null, val != null, keepBinary);
            } else {
                CacheObject cacheVal = cacheCtx.toCacheObject(val);
                if (e.op() == TRANSFORM) {
                    GridCacheVersion ver;
                    e.readValue(cacheVal);
                    try {
                        ver = e.cached().version();
                    } catch (GridCacheEntryRemovedException ex) {
                        assert optimistic() : e;
                        if (log.isDebugEnabled())
                            log.debug("Failed to get entry version: [msg=" + ex.getMessage() + ']');
                        ver = null;
                    }
                    addInvokeResult(e, cacheVal, ret, ver);
                } else {
                    boolean success;
                    if (hasFilters) {
                        success = isAll(e.context(), key, cacheVal, filter);
                        if (!success)
                            e.value(cacheVal, false, false);
                    } else
                        success = true;
                    ret.set(cacheCtx, cacheVal, success, keepBinary);
                }
            }
        }
    };
    return loadMissing(cacheCtx, topVer, readThrough, /*async*/
    true, keys, /*skipVals*/
    singleRmv, needReadVer, keepBinary, recovery, expiryPlc, c);
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) 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) Nullable(org.jetbrains.annotations.Nullable) GridInClosure3(org.apache.ignite.internal.util.lang.GridInClosure3) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 27 with GridCacheEntryRemovedException

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

the class GridNearTxLocal method localCacheLoadMissing.

/**
     * @param cacheCtx  Cache context.
     * @param readThrough Read through flag.
     * @param async if {@code True}, then loading will happen in a separate thread.
     * @param keys Keys.
     * @param skipVals Skip values flag.
     * @param needVer If {@code true} version is required for loaded values.
     * @param c Closure to be applied for loaded values.
     * @param expiryPlc Expiry policy.
     * @return Future with {@code True} value if loading took place.
     */
private IgniteInternalFuture<Void> localCacheLoadMissing(final GridCacheContext cacheCtx, final AffinityTopologyVersion topVer, final boolean readThrough, boolean async, final Collection<KeyCacheObject> keys, boolean skipVals, boolean needVer, boolean keepBinary, boolean recovery, final ExpiryPolicy expiryPlc, final GridInClosure3<KeyCacheObject, Object, GridCacheVersion> c) {
    assert cacheCtx.isLocal() : cacheCtx.name();
    if (!readThrough || !cacheCtx.readThrough()) {
        for (KeyCacheObject key : keys) c.apply(key, null, SER_READ_EMPTY_ENTRY_VER);
        return new GridFinishedFuture<>();
    }
    try {
        IgniteCacheExpiryPolicy expiryPlc0 = optimistic() ? accessPolicy(cacheCtx, keys) : cacheCtx.cache().expiryPolicy(expiryPlc);
        Map<KeyCacheObject, GridCacheVersion> misses = null;
        for (KeyCacheObject key : keys) {
            while (true) {
                IgniteTxEntry txEntry = entry(cacheCtx.txKey(key));
                GridCacheEntryEx entry = txEntry == null ? cacheCtx.cache().entryEx(key) : txEntry.cached();
                if (entry == null)
                    continue;
                try {
                    EntryGetResult res = entry.innerGetVersioned(null, this, /*update-metrics*/
                    !skipVals, /*event*/
                    !skipVals, CU.subjectId(this, cctx), null, resolveTaskName(), expiryPlc0, txEntry == null ? keepBinary : txEntry.keepBinary(), null);
                    if (res == null) {
                        if (misses == null)
                            misses = new LinkedHashMap<>();
                        misses.put(key, entry.version());
                    } else
                        c.apply(key, skipVals ? true : res.value(), res.version());
                    break;
                } catch (GridCacheEntryRemovedException ignore) {
                    if (log.isDebugEnabled())
                        log.debug("Got removed entry, will retry: " + key);
                    if (txEntry != null)
                        txEntry.cached(cacheCtx.cache().entryEx(key, topologyVersion()));
                }
            }
        }
        if (misses != null) {
            final Map<KeyCacheObject, GridCacheVersion> misses0 = misses;
            cacheCtx.store().loadAll(this, misses.keySet(), new CI2<KeyCacheObject, Object>() {

                @Override
                public void apply(KeyCacheObject key, Object val) {
                    GridCacheVersion ver = misses0.remove(key);
                    assert ver != null : key;
                    if (val != null) {
                        CacheObject cacheVal = cacheCtx.toCacheObject(val);
                        while (true) {
                            GridCacheEntryEx entry = cacheCtx.cache().entryEx(key, topVer);
                            try {
                                cacheCtx.shared().database().ensureFreeSpace(cacheCtx.memoryPolicy());
                                EntryGetResult verVal = entry.versionedValue(cacheVal, ver, null, null, null);
                                if (log.isDebugEnabled()) {
                                    log.debug("Set value loaded from store into entry [" + "oldVer=" + ver + ", newVer=" + verVal.version() + ", entry=" + entry + ']');
                                }
                                ver = verVal.version();
                                break;
                            } catch (GridCacheEntryRemovedException ignore) {
                                if (log.isDebugEnabled())
                                    log.debug("Got removed entry, (will retry): " + entry);
                            } catch (IgniteCheckedException e) {
                                // Wrap errors (will be unwrapped).
                                throw new GridClosureException(e);
                            }
                        }
                    } else
                        ver = SER_READ_EMPTY_ENTRY_VER;
                    c.apply(key, val, ver);
                }
            });
            for (KeyCacheObject key : misses0.keySet()) c.apply(key, null, SER_READ_EMPTY_ENTRY_VER);
        }
        return new GridFinishedFuture<>();
    } catch (IgniteCheckedException e) {
        return new GridFinishedFuture<>(e);
    }
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) LinkedHashMap(java.util.LinkedHashMap) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) 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) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) IgniteCacheExpiryPolicy(org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy)

Example 28 with GridCacheEntryRemovedException

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

the class GridNearTxRemote method addEntry.

/**
     * @param cacheCtx Cache context.
     * @param key Key to add to read set.
     * @param op Operation.
     * @param val Value.
     * @param drVer Data center replication version.
     * @param skipStore Skip store flag.
     * @throws IgniteCheckedException If failed.
     * @return {@code True} if entry has been enlisted.
     */
public boolean addEntry(GridCacheContext cacheCtx, IgniteTxKey key, GridCacheOperation op, CacheObject val, @Nullable GridCacheVersion drVer, boolean skipStore, boolean keepBinary) throws IgniteCheckedException {
    checkInternal(key);
    GridNearCacheEntry cached = cacheCtx.near().peekExx(key.key());
    try {
        if (cached == null) {
            evicted.add(key);
            return false;
        } else {
            cached.unswap();
            CacheObject peek = cached.peek(null);
            if (peek == null && cached.evictInternal(xidVer, null, false)) {
                cached.context().cache().removeIfObsolete(key.key());
                evicted.add(key);
                return false;
            } else {
                IgniteTxEntry txEntry = new IgniteTxEntry(cacheCtx, this, op, val, -1L, -1L, cached, drVer, skipStore, keepBinary);
                txState.addWriteEntry(key, txEntry);
                return true;
            }
        }
    } catch (GridCacheEntryRemovedException ignore) {
        evicted.add(key);
        if (log.isDebugEnabled())
            log.debug("Got removed entry when adding reads to remote transaction (will ignore): " + cached);
        return false;
    }
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject)

Example 29 with GridCacheEntryRemovedException

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

the class GridLocalLockFuture method addEntries.

/**
     * @param keys Keys.
     * @return {@code False} in case of error.
     * @throws IgniteCheckedException If failed.
     */
public boolean addEntries(Collection<KeyCacheObject> keys) throws IgniteCheckedException {
    for (KeyCacheObject key : keys) {
        while (true) {
            GridLocalCacheEntry entry = null;
            try {
                entry = cache.entryExx(key);
                entry.unswap(false);
                if (!cctx.isAll(entry, filter)) {
                    onFailed();
                    return false;
                }
                // Removed exception may be thrown here.
                GridCacheMvccCandidate cand = addEntry(entry);
                if (cand == null && isDone())
                    return false;
                break;
            } catch (GridCacheEntryRemovedException ignored) {
                if (log.isDebugEnabled())
                    log.debug("Got removed entry in lockAsync(..) method (will retry): " + entry);
            }
        }
    }
    if (timeout > 0) {
        timeoutObj = new LockTimeoutObject();
        cctx.time().addTimeoutObject(timeoutObj);
    }
    return true;
}
Also used : GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)

Example 30 with GridCacheEntryRemovedException

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

the class GridNearTransactionalCache method clearLocks.

/**
     * @param nodeId Node ID.
     * @param req Request.
     */
@SuppressWarnings({ "RedundantTypeArguments" })
public void clearLocks(UUID nodeId, GridDhtUnlockRequest req) {
    assert nodeId != null;
    GridCacheVersion obsoleteVer = ctx.versions().next();
    List<KeyCacheObject> keys = req.nearKeys();
    if (keys != null) {
        AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
        for (KeyCacheObject key : keys) {
            while (true) {
                GridDistributedCacheEntry entry = peekExx(key);
                try {
                    if (entry != null) {
                        entry.doneRemote(req.version(), req.version(), null, req.committedVersions(), req.rolledbackVersions(), /*system invalidate*/
                        false);
                        // we are about to remove.
                        if (entry.removeLock(req.version())) {
                            if (log.isDebugEnabled())
                                log.debug("Removed lock [lockId=" + req.version() + ", key=" + key + ']');
                            // Try to evict near entry dht-mapped locally.
                            evictNearEntry(entry, obsoleteVer, topVer);
                        } else {
                            if (log.isDebugEnabled())
                                log.debug("Received unlock request for unknown candidate " + "(added to cancelled locks set): " + req);
                        }
                        ctx.evicts().touch(entry, topVer);
                    } else if (log.isDebugEnabled())
                        log.debug("Received unlock request for entry that could not be found: " + req);
                    break;
                } catch (GridCacheEntryRemovedException ignored) {
                    if (log.isDebugEnabled())
                        log.debug("Received remove lock request for removed entry (will retry) [entry=" + entry + ", req=" + req + ']');
                }
            }
        }
    }
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridDistributedCacheEntry(org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheEntry) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Aggregations

GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)77 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)53 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)46 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)38 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)38 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)36 ClusterNode (org.apache.ignite.cluster.ClusterNode)19 IgniteTxEntry (org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry)18 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)17 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)15 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)14 GridDhtInvalidPartitionException (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException)14 ArrayList (java.util.ArrayList)13 EntryGetResult (org.apache.ignite.internal.processors.cache.EntryGetResult)13 GridCacheOperation (org.apache.ignite.internal.processors.cache.GridCacheOperation)12 IgniteTxKey (org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey)12 Map (java.util.Map)10 GridDistributedCacheEntry (org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheEntry)10 UUID (java.util.UUID)9 GridCacheReturn (org.apache.ignite.internal.processors.cache.GridCacheReturn)9