Search in sources :

Example 6 with GridCacheEntryRemovedException

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

the class GridDhtCacheAdapter method updateTtl.

/**
     * @param cache Cache.
     * @param keys Entries keys.
     * @param vers Entries versions.
     * @param ttl TTL.
     */
private void updateTtl(GridCacheAdapter<K, V> cache, List<KeyCacheObject> keys, List<GridCacheVersion> vers, long ttl) {
    assert !F.isEmpty(keys);
    assert keys.size() == vers.size();
    int size = keys.size();
    for (int i = 0; i < size; i++) {
        try {
            GridCacheEntryEx entry = null;
            try {
                while (true) {
                    try {
                        entry = cache.entryEx(keys.get(i));
                        entry.unswap(false);
                        entry.updateTtl(vers.get(i), ttl);
                        break;
                    } catch (GridCacheEntryRemovedException ignore) {
                        if (log.isDebugEnabled())
                            log.debug("Got removed entry: " + entry);
                    } catch (GridDhtInvalidPartitionException e) {
                        if (log.isDebugEnabled())
                            log.debug("Got GridDhtInvalidPartitionException: " + e);
                        break;
                    }
                }
            } finally {
                if (entry != null)
                    cache.context().evicts().touch(entry, AffinityTopologyVersion.NONE);
            }
        } catch (IgniteCheckedException e) {
            log.error("Failed to unswap entry.", e);
        }
    }
}
Also used : GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)

Example 7 with GridCacheEntryRemovedException

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

the class GridDhtTxLocalAdapter method mapExplicitLocks.

/**
     * Map explicit locks.
     */
protected void mapExplicitLocks() {
    if (!mapped) {
        // Explicit locks may participate in implicit transactions only.
        if (!implicit()) {
            mapped = true;
            return;
        }
        Map<ClusterNode, List<GridDhtCacheEntry>> dhtEntryMap = null;
        Map<ClusterNode, List<GridDhtCacheEntry>> nearEntryMap = null;
        for (IgniteTxEntry e : allEntries()) {
            assert e.cached() != null;
            GridCacheContext cacheCtx = e.cached().context();
            if (cacheCtx.isNear())
                continue;
            if (e.cached().obsolete()) {
                GridCacheEntryEx cached = cacheCtx.cache().entryEx(e.key(), topologyVersion());
                e.cached(cached);
            }
            if (e.cached().detached() || e.cached().isLocal())
                continue;
            while (true) {
                try {
                    // Map explicit locks.
                    if (e.explicitVersion() != null && !e.explicitVersion().equals(xidVer)) {
                        if (dhtEntryMap == null)
                            dhtEntryMap = new GridLeanMap<>();
                        if (nearEntryMap == null)
                            nearEntryMap = new GridLeanMap<>();
                        cacheCtx.dhtMap((GridDhtCacheEntry) e.cached(), e.explicitVersion(), log, dhtEntryMap, nearEntryMap);
                    }
                    break;
                } catch (GridCacheEntryRemovedException ignore) {
                    GridCacheEntryEx cached = cacheCtx.cache().entryEx(e.key(), topologyVersion());
                    e.cached(cached);
                }
            }
        }
        if (!F.isEmpty(dhtEntryMap))
            addDhtNodeEntryMapping(dhtEntryMap);
        if (!F.isEmpty(nearEntryMap))
            addNearNodeEntryMapping(nearEntryMap);
        mapped = true;
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridLeanMap(org.apache.ignite.internal.util.GridLeanMap) List(java.util.List) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)

Example 8 with GridCacheEntryRemovedException

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

the class GridDhtTxLocalAdapter method lockAllAsync.

/**
     * @param cacheCtx Cache context.
     * @param entries Entries to lock.
     * @param msgId Message ID.
     * @param read Read flag.
     * @param createTtl TTL for create operation.
     * @param accessTtl TTL for read operation.
     * @param needRetVal Return value flag.
     * @param skipStore Skip store flag.
     * @return Lock future.
     */
@SuppressWarnings("ForLoopReplaceableByForEach")
IgniteInternalFuture<GridCacheReturn> lockAllAsync(GridCacheContext cacheCtx, List<GridCacheEntryEx> entries, long msgId, final boolean read, final boolean needRetVal, long createTtl, long accessTtl, boolean skipStore, boolean keepBinary) {
    try {
        checkValid();
    } catch (IgniteCheckedException e) {
        return new GridFinishedFuture<>(e);
    }
    final GridCacheReturn ret = new GridCacheReturn(localResult(), false);
    if (F.isEmpty(entries))
        return new GridFinishedFuture<>(ret);
    init();
    onePhaseCommit(onePhaseCommit);
    try {
        Set<KeyCacheObject> skipped = null;
        AffinityTopologyVersion topVer = topologyVersion();
        GridDhtCacheAdapter dhtCache = cacheCtx.isNear() ? cacheCtx.near().dht() : cacheCtx.dht();
        // Enlist locks into transaction.
        for (int i = 0; i < entries.size(); i++) {
            GridCacheEntryEx entry = entries.get(i);
            KeyCacheObject key = entry.key();
            IgniteTxEntry txEntry = entry(entry.txKey());
            // First time access.
            if (txEntry == null) {
                GridDhtCacheEntry cached;
                while (true) {
                    try {
                        cached = dhtCache.entryExx(key, topVer);
                        cached.unswap(read);
                        break;
                    } catch (GridCacheEntryRemovedException ignore) {
                        if (log.isDebugEnabled())
                            log.debug("Get removed entry: " + key);
                    }
                }
                addActiveCache(dhtCache.context(), false);
                txEntry = addEntry(NOOP, null, null, null, cached, null, CU.empty0(), false, -1L, -1L, null, skipStore, keepBinary);
                if (read)
                    txEntry.ttl(accessTtl);
                txEntry.cached(cached);
                addReader(msgId, cached, txEntry, topVer);
            } else {
                if (skipped == null)
                    skipped = new GridLeanSet<>();
                skipped.add(key);
            }
        }
        assert pessimistic();
        Collection<KeyCacheObject> keys = F.viewReadOnly(entries, CU.entry2Key());
        // Acquire locks only after having added operation to the write set.
        // Otherwise, during rollback we will not know whether locks need
        // to be rolled back.
        // Loose all skipped and previously locked (we cannot reenter locks here).
        final Collection<KeyCacheObject> passedKeys = skipped != null ? F.view(keys, F0.notIn(skipped)) : keys;
        if (log.isDebugEnabled())
            log.debug("Lock keys: " + passedKeys);
        return obtainLockAsync(cacheCtx, ret, passedKeys, read, needRetVal, createTtl, accessTtl, skipStore, keepBinary);
    } catch (IgniteCheckedException e) {
        setRollbackOnly();
        return new GridFinishedFuture<>(e);
    }
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridCacheReturn(org.apache.ignite.internal.processors.cache.GridCacheReturn) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridLeanSet(org.apache.ignite.internal.util.GridLeanSet) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 9 with GridCacheEntryRemovedException

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

the class GridDhtTxPrepareFuture method addDhtValues.

/**
     * @param res Response being sent.
     */
private void addDhtValues(GridNearTxPrepareResponse res) {
    // Interceptor on near node needs old values to execute callbacks.
    if (!F.isEmpty(writes)) {
        for (IgniteTxEntry e : writes) {
            IgniteTxEntry txEntry = tx.entry(e.txKey());
            assert txEntry != null : "Missing tx entry for key [tx=" + tx + ", key=" + e.txKey() + ']';
            GridCacheContext cacheCtx = txEntry.context();
            while (true) {
                try {
                    GridCacheEntryEx entry = txEntry.cached();
                    GridCacheVersion dhtVer = entry.version();
                    CacheObject val0 = entry.valueBytes();
                    if (val0 != null)
                        res.addOwnedValue(txEntry.txKey(), dhtVer, val0);
                    break;
                } catch (GridCacheEntryRemovedException ignored) {
                    // Retry.
                    txEntry.cached(cacheCtx.cache().entryEx(txEntry.key(), tx.topologyVersion()));
                }
            }
        }
    }
    for (Map.Entry<IgniteTxKey, GridCacheVersion> ver : dhtVerMap.entrySet()) {
        IgniteTxEntry txEntry = tx.entry(ver.getKey());
        if (res.hasOwnedValue(ver.getKey()))
            continue;
        assert txEntry != null : ver;
        GridCacheContext cacheCtx = txEntry.context();
        while (true) {
            try {
                GridCacheEntryEx entry = txEntry.cached();
                GridCacheVersion dhtVer = entry.version();
                if (ver.getValue() == null || !ver.getValue().equals(dhtVer)) {
                    CacheObject val0 = entry.valueBytes();
                    res.addOwnedValue(txEntry.txKey(), dhtVer, val0);
                }
                break;
            } catch (GridCacheEntryRemovedException ignored) {
                // Retry.
                txEntry.cached(cacheCtx.cache().entryEx(txEntry.key(), tx.topologyVersion()));
            }
        }
    }
}
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) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) IgniteTxKey(org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey) Map(java.util.Map) HashMap(java.util.HashMap)

Example 10 with GridCacheEntryRemovedException

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

the class GridDistributedTxRemoteAdapter method doneRemote.

/**
     * Adds completed versions to an entry.
     *
     * @param txEntry Entry.
     * @param baseVer Base version for completed versions.
     * @param committedVers Completed versions relative to base version.
     * @param rolledbackVers Rolled back versions relative to base version.
     * @param pendingVers Pending versions.
     */
private void doneRemote(IgniteTxEntry txEntry, GridCacheVersion baseVer, Collection<GridCacheVersion> committedVers, Collection<GridCacheVersion> rolledbackVers, Collection<GridCacheVersion> pendingVers) {
    while (true) {
        GridDistributedCacheEntry entry = (GridDistributedCacheEntry) txEntry.cached();
        try {
            // Handle explicit locks.
            GridCacheVersion doneVer = txEntry.explicitVersion() != null ? txEntry.explicitVersion() : xidVer;
            entry.doneRemote(doneVer, baseVer, pendingVers, committedVers, rolledbackVers, isSystemInvalidate());
            break;
        } catch (GridCacheEntryRemovedException ignored) {
            assert entry.obsoleteVersion() != null;
            if (log.isDebugEnabled())
                log.debug("Replacing obsolete entry in remote transaction [entry=" + entry + ", tx=" + this + ']');
            // Replace the entry.
            txEntry.cached(txEntry.context().cache().entryEx(txEntry.key(), topologyVersion()));
        }
    }
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)

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