Search in sources :

Example 51 with IgniteTxEntry

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

the class GridNearOptimisticTxPrepareFuture method prepare.

/**
 * @param writes Write entries.
 * @param topLocked {@code True} if thread already acquired lock preventing topology change.
 * @param remap Remap flag.
 */
private void prepare(Iterable<IgniteTxEntry> writes, boolean topLocked, boolean remap) {
    AffinityTopologyVersion topVer = tx.topologyVersion();
    assert topVer.topologyVersion() > 0;
    txMapping = new GridDhtTxMapping();
    Map<Object, GridDistributedTxMapping> map = new HashMap<>();
    // Assign keys to primary nodes.
    GridDistributedTxMapping cur = null;
    Queue<GridDistributedTxMapping> mappings = new ArrayDeque<>();
    boolean hasNearCache = false;
    for (IgniteTxEntry write : writes) {
        write.clearEntryReadVersion();
        GridDistributedTxMapping updated = map(write, topVer, cur, topLocked, remap);
        if (updated == null)
            // an exception occurred while transaction mapping, stop further processing
            break;
        if (write.context().isNear())
            hasNearCache = true;
        if (cur != updated) {
            mappings.offer(updated);
            updated.last(true);
            ClusterNode primary = updated.primary();
            assert !primary.isLocal() || !cctx.kernalContext().clientNode() || write.context().isLocal();
            // Minor optimization to not create MappingKey: on client node can not have mapping for local node.
            Object key = cctx.kernalContext().clientNode() ? primary.id() : new MappingKey(primary.id(), primary.isLocal() && updated.hasNearCacheEntries());
            GridDistributedTxMapping prev = map.put(key, updated);
            if (prev != null)
                prev.last(false);
            if (updated.primary().isLocal()) {
                if (write.context().isNear())
                    tx.nearLocallyMapped(true);
                else if (write.context().isColocated())
                    tx.colocatedLocallyMapped(true);
            }
            cur = updated;
        }
    }
    if (isDone()) {
        if (log.isDebugEnabled())
            log.debug("Abandoning (re)map because future is done: " + this);
        return;
    }
    if (keyLockFut != null)
        keyLockFut.onAllKeysAdded();
    tx.addEntryMapping(mappings);
    cctx.mvcc().recheckPendingLocks();
    tx.transactionNodes(txMapping.transactionNodes());
    if (!hasNearCache)
        checkOnePhase(txMapping);
    proceedPrepare(mappings);
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) ClusterNode(org.apache.ignite.cluster.ClusterNode) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) HashMap(java.util.HashMap) GridDhtTxMapping(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxMapping) GridDistributedTxMapping(org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping) ArrayDeque(java.util.ArrayDeque)

Aggregations

IgniteTxEntry (org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry)51 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)23 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)14 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)14 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)8 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 IgniteTxOptimisticCheckedException (org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException)6 Collection (java.util.Collection)5 GridCacheMvccCandidate (org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)5