Search in sources :

Example 46 with IgniteTxEntry

use of org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry 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;
    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 47 with IgniteTxEntry

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

the class IgniteCacheContainsKeyAbstractSelfTest method txContainsKey.

/**
     * Checks if transaction has given key enlisted.
     *
     * @param tx Transaction to check.
     * @param key Key to check.
     * @return {@code True} if key was enlisted.
     */
private boolean txContainsKey(Transaction tx, String key) {
    TransactionProxyImpl<String, Integer> proxy = (TransactionProxyImpl<String, Integer>) tx;
    IgniteInternalTx txEx = proxy.tx();
    IgniteTxEntry entry = txEx.entry(context(0).txKey(context(0).toCacheKeyObject(key)));
    return entry != null;
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) TransactionProxyImpl(org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl)

Aggregations

IgniteTxEntry (org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry)47 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)21 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)20 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)14 IgniteTxKey (org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey)13 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)13 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)12 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)12 GridDistributedTxMapping (org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping)11 ClusterNode (org.apache.ignite.cluster.ClusterNode)10 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)10 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)10 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)9 IgniteTxTimeoutCheckedException (org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ArrayList (java.util.ArrayList)5 GridCacheMvccCandidate (org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)5 IgniteTxOptimisticCheckedException (org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException)5 Collection (java.util.Collection)4