Search in sources :

Example 81 with GridCacheEntryRemovedException

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

the class GridNearTxPrepareFutureAdapter method onPrepareResponse.

/**
 * @param m Mapping.
 * @param res Response.
 * @param updateMapping Update mapping flag.
 */
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
final void onPrepareResponse(GridDistributedTxMapping m, GridNearTxPrepareResponse res, boolean updateMapping) {
    if (res == null)
        return;
    assert res.error() == null : res;
    if (tx.onePhaseCommit() && !res.onePhaseCommit())
        tx.onePhaseCommit(false);
    UUID nodeId = m.primary().id();
    for (Map.Entry<IgniteTxKey, CacheVersionedValue> entry : res.ownedValues().entrySet()) {
        IgniteTxEntry txEntry = tx.entry(entry.getKey());
        assert txEntry != null;
        GridCacheContext cacheCtx = txEntry.context();
        while (true) {
            try {
                if (cacheCtx.isNear()) {
                    GridNearCacheEntry nearEntry = (GridNearCacheEntry) txEntry.cached();
                    CacheVersionedValue tup = entry.getValue();
                    nearEntry.resetFromPrimary(tup.value(), tx.xidVersion(), tup.version(), nodeId, tx.topologyVersion());
                } else if (txEntry.cached().detached()) {
                    GridDhtDetachedCacheEntry detachedEntry = (GridDhtDetachedCacheEntry) txEntry.cached();
                    CacheVersionedValue tup = entry.getValue();
                    detachedEntry.resetFromPrimary(tup.value(), tx.xidVersion());
                }
                break;
            } catch (GridCacheEntryRemovedException ignored) {
                // Retry.
                txEntry.cached(cacheCtx.cache().entryEx(txEntry.key(), tx.topologyVersion()));
            }
        }
    }
    tx.implicitSingleResult(res.returnValue());
    for (IgniteTxKey key : res.filterFailedKeys()) {
        IgniteTxEntry txEntry = tx.entry(key);
        assert txEntry != null : "Missing tx entry for write key: " + key;
        txEntry.op(NOOP);
        assert txEntry.context() != null;
        ExpiryPolicy expiry = txEntry.context().expiryForTxEntry(txEntry);
        if (expiry != null)
            txEntry.ttl(CU.toTtl(expiry.getExpiryForAccess()));
    }
    if (!m.empty()) {
        // This step is very important as near and DHT versions grow separately.
        cctx.versions().onReceived(nodeId, res.dhtVersion());
        if (updateMapping && m.hasNearCacheEntries()) {
            GridCacheVersion writeVer = res.writeVersion();
            if (writeVer == null)
                writeVer = res.dhtVersion();
            // Register DHT version.
            m.dhtVersion(res.dhtVersion(), writeVer);
            GridDistributedTxMapping map = tx.mappings().get(nodeId);
            if (map != null)
                map.dhtVersion(res.dhtVersion(), writeVer);
            tx.readyNearLocks(m, res.pending(), res.committedVersions(), res.rolledbackVersions());
        }
    }
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridDhtDetachedCacheEntry(org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtDetachedCacheEntry) GridDistributedTxMapping(org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) IgniteTxKey(org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey) UUID(java.util.UUID) Map(java.util.Map)

Example 82 with GridCacheEntryRemovedException

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

the class GridNearTxRemote method addEntry.

/**
 * @param entry Entry to enlist.
 * @throws IgniteCheckedException If failed.
 * @return {@code True} if entry was enlisted.
 */
private boolean addEntry(IgniteTxEntry entry) throws IgniteCheckedException {
    checkInternal(entry.txKey());
    GridCacheContext cacheCtx = entry.context();
    if (!cacheCtx.isNear())
        cacheCtx = cacheCtx.dht().near().context();
    GridNearCacheEntry cached = cacheCtx.near().peekExx(entry.key());
    if (cached == null) {
        evicted.add(entry.txKey());
        return false;
    } else {
        try {
            cached.unswap();
            CacheObject val = cached.peek(null);
            if (val == null && cached.evictInternal(xidVer, null, false)) {
                evicted.add(entry.txKey());
                return false;
            } else {
                // Initialize cache entry.
                entry.cached(cached);
                txState.addWriteEntry(entry.txKey(), entry);
                addExplicit(entry);
                return true;
            }
        } catch (GridCacheEntryRemovedException ignore) {
            evicted.add(entry.txKey());
            if (log.isDebugEnabled())
                log.debug("Got removed entry when adding to remote transaction (will ignore): " + cached);
            return false;
        }
    }
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject)

Example 83 with GridCacheEntryRemovedException

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

the class GridNearOptimisticSerializableTxPrepareFuture method map.

/**
 * @param entry Transaction entry.
 * @param topVer Topology version.
 * @param curMapping Current mapping.
 * @param txMapping Mapping.
 * @param remap Remap flag.
 * @param topLocked Topology locked flag.
 */
private void map(IgniteTxEntry entry, AffinityTopologyVersion topVer, Map<UUID, GridDistributedTxMapping> curMapping, GridDhtTxMapping txMapping, boolean remap, boolean topLocked) {
    GridCacheContext cacheCtx = entry.context();
    List<ClusterNode> nodes = cacheCtx.isLocal() ? cacheCtx.affinity().nodesByKey(entry.key(), topVer) : cacheCtx.topology().nodes(cacheCtx.affinity().partition(entry.key()), topVer);
    if (F.isEmpty(nodes)) {
        onDone(new ClusterTopologyServerNotFoundException("Failed to map keys to nodes " + "(partition is not mapped to any node) [key=" + entry.key() + ", partition=" + cacheCtx.affinity().partition(entry.key()) + ", topVer=" + topVer + ']'));
        return;
    }
    txMapping.addMapping(nodes);
    ClusterNode primary = F.first(nodes);
    assert primary != null;
    if (log.isDebugEnabled()) {
        log.debug("Mapped key to primary node [key=" + entry.key() + ", part=" + cacheCtx.affinity().partition(entry.key()) + ", primary=" + U.toShortString(primary) + ", topVer=" + topVer + ']');
    }
    // Must re-initialize cached entry while holding topology lock.
    if (cacheCtx.isNear())
        entry.cached(cacheCtx.nearTx().entryExx(entry.key(), topVer));
    else if (!cacheCtx.isLocal())
        entry.cached(cacheCtx.colocated().entryExx(entry.key(), topVer, true));
    else
        entry.cached(cacheCtx.local().entryEx(entry.key(), topVer));
    if (!remap && (cacheCtx.isNear() || cacheCtx.isLocal())) {
        if (entry.explicitVersion() == null) {
            if (keyLockFut == null) {
                keyLockFut = new KeyLockFuture();
                add(keyLockFut);
            }
            keyLockFut.addLockKey(entry.txKey());
        }
    }
    GridDistributedTxMapping cur = curMapping.get(primary.id());
    if (cur == null) {
        cur = new GridDistributedTxMapping(primary);
        curMapping.put(primary.id(), cur);
        cur.clientFirst(!topLocked && cctx.kernalContext().clientNode());
        cur.last(true);
    }
    if (primary.isLocal()) {
        if (cacheCtx.isNear())
            tx.nearLocallyMapped(true);
        else if (cacheCtx.isColocated())
            tx.colocatedLocallyMapped(true);
    }
    cur.add(entry);
    if (entry.explicitVersion() != null) {
        tx.markExplicit(primary.id());
        cur.markExplicitLock();
    }
    entry.nodeId(primary.id());
    if (cacheCtx.isNear()) {
        while (true) {
            try {
                GridNearCacheEntry cached = (GridNearCacheEntry) entry.cached();
                cached.dhtNodeId(tx.xidVersion(), primary.id());
                break;
            } catch (GridCacheEntryRemovedException ignore) {
                entry.cached(cacheCtx.near().entryEx(entry.key(), topVer));
            }
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) GridDistributedTxMapping(org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)

Example 84 with GridCacheEntryRemovedException

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

the class IgniteCacheExpiryPolicyAbstractTest method checkTtl.

/**
 * @param key Key.
 * @param ttl TTL.
 * @param wait If {@code true} waits for ttl update.
 * @throws Exception If failed.
 */
private void checkTtl(Object key, final long ttl, boolean wait) throws Exception {
    boolean found = false;
    for (int i = 0; i < gridCount(); i++) {
        IgniteKernal grid = (IgniteKernal) grid(i);
        GridCacheAdapter<Object, Object> cache = grid.context().cache().internalCache(DEFAULT_CACHE_NAME);
        if (cache.context().isNear())
            cache = cache.context().near().dht();
        while (true) {
            try {
                GridCacheEntryEx e = cache.entryEx(key);
                if (e != null && e.deleted()) {
                    assertEquals(0, e.ttl());
                    assertFalse("Invalid entry [e=" + e + ", node=" + i + ']', cache.affinity().isPrimaryOrBackup(grid.localNode(), key));
                    continue;
                }
                if (e == null)
                    assertTrue("Not found " + key, !cache.affinity().isPrimaryOrBackup(grid.localNode(), key));
                else {
                    e.unswap();
                    found = true;
                    if (ttl > 0)
                        assertTrue(e.expireTime() > 0);
                    else
                        assertEquals(0, e.expireTime());
                }
                break;
            } catch (GridCacheEntryRemovedException ignore) {
            // Retry.
            } catch (GridDhtInvalidPartitionException ignore) {
                // No need to check.
                break;
            }
        }
    }
    assertTrue(found);
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)

Aggregations

GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)84 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)56 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)50 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)40 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)40 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)40 ClusterNode (org.apache.ignite.cluster.ClusterNode)19 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)18 IgniteTxEntry (org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry)18 GridDhtInvalidPartitionException (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException)17 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)16 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)16 ArrayList (java.util.ArrayList)14 EntryGetResult (org.apache.ignite.internal.processors.cache.EntryGetResult)14 GridCacheOperation (org.apache.ignite.internal.processors.cache.GridCacheOperation)13 GridDhtCacheEntry (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry)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 GridTimeoutObject (org.apache.ignite.internal.processors.timeout.GridTimeoutObject)10