Search in sources :

Example 1 with GridDhtDetachedCacheEntry

use of org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtDetachedCacheEntry in project ignite by apache.

the class GridNearTxPrepareFutureAdapter method onPrepareResponse.

/**
 * @param m Mapping.
 * @param res Response.
 * @param updateMapping Update mapping flag.
 */
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.queryUpdate() || !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)

Aggregations

Map (java.util.Map)1 UUID (java.util.UUID)1 ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)1 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)1 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)1 GridDistributedTxMapping (org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping)1 GridDhtDetachedCacheEntry (org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtDetachedCacheEntry)1 IgniteTxEntry (org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry)1 IgniteTxKey (org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey)1 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)1