Search in sources :

Example 1 with GridDistributedTxMapping

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

the class GridDhtTxFinishFuture method finish.

/**
     * @param commit Commit flag.
     * @param dhtMap DHT map.
     * @param nearMap Near map.
     * @return {@code True} in case there is at least one synchronous {@code MiniFuture} to wait for.
     */
private boolean finish(boolean commit, Map<UUID, GridDistributedTxMapping> dhtMap, Map<UUID, GridDistributedTxMapping> nearMap) {
    if (tx.onePhaseCommit())
        return false;
    boolean sync = tx.syncMode() == FULL_SYNC;
    if (tx.explicitLock())
        sync = true;
    boolean res = false;
    int miniId = 0;
    // Create mini futures.
    for (GridDistributedTxMapping dhtMapping : dhtMap.values()) {
        ClusterNode n = dhtMapping.primary();
        assert !n.isLocal();
        GridDistributedTxMapping nearMapping = nearMap.get(n.id());
        if (dhtMapping.empty() && nearMapping != null && nearMapping.empty())
            // Nothing to send.
            continue;
        MiniFuture fut = new MiniFuture(++miniId, dhtMapping, nearMapping);
        // Append new future.
        add(fut);
        Collection<Long> updCntrs = new ArrayList<>(dhtMapping.entries().size());
        for (IgniteTxEntry e : dhtMapping.entries()) updCntrs.add(e.updateCounter());
        GridDhtTxFinishRequest req = new GridDhtTxFinishRequest(tx.nearNodeId(), futId, fut.futureId(), tx.topologyVersion(), tx.xidVersion(), tx.commitVersion(), tx.threadId(), tx.isolation(), commit, tx.isInvalidate(), tx.system(), tx.ioPolicy(), tx.isSystemInvalidate(), sync ? FULL_SYNC : tx.syncMode(), tx.completedBase(), tx.committedVersions(), tx.rolledbackVersions(), tx.pendingVersions(), tx.size(), tx.subjectId(), tx.taskNameHash(), tx.activeCachesDeploymentEnabled(), updCntrs, false, false);
        req.writeVersion(tx.writeVersion() != null ? tx.writeVersion() : tx.xidVersion());
        try {
            cctx.io().send(n, req, tx.ioPolicy());
            if (msgLog.isDebugEnabled()) {
                msgLog.debug("DHT finish fut, sent request dht [txId=" + tx.nearXidVersion() + ", dhtTxId=" + tx.xidVersion() + ", node=" + n.id() + ']');
            }
            if (sync)
                res = true;
            else
                fut.onDone();
        } catch (IgniteCheckedException e) {
            // Fail the whole thing.
            if (e instanceof ClusterTopologyCheckedException)
                fut.onNodeLeft((ClusterTopologyCheckedException) e);
            else {
                if (msgLog.isDebugEnabled()) {
                    msgLog.debug("DHT finish fut, failed to send request dht [txId=" + tx.nearXidVersion() + ", dhtTxId=" + tx.xidVersion() + ", node=" + n.id() + ", err=" + e + ']');
                }
                fut.onResult(e);
            }
        }
    }
    for (GridDistributedTxMapping nearMapping : nearMap.values()) {
        if (!dhtMap.containsKey(nearMapping.primary().id())) {
            if (nearMapping.empty())
                // Nothing to send.
                continue;
            MiniFuture fut = new MiniFuture(++miniId, null, nearMapping);
            // Append new future.
            add(fut);
            GridDhtTxFinishRequest req = new GridDhtTxFinishRequest(tx.nearNodeId(), futId, fut.futureId(), tx.topologyVersion(), tx.xidVersion(), tx.commitVersion(), tx.threadId(), tx.isolation(), commit, tx.isInvalidate(), tx.system(), tx.ioPolicy(), tx.isSystemInvalidate(), sync ? FULL_SYNC : tx.syncMode(), tx.completedBase(), tx.committedVersions(), tx.rolledbackVersions(), tx.pendingVersions(), tx.size(), tx.subjectId(), tx.taskNameHash(), tx.activeCachesDeploymentEnabled(), false, false);
            req.writeVersion(tx.writeVersion());
            try {
                cctx.io().send(nearMapping.primary(), req, tx.ioPolicy());
                if (msgLog.isDebugEnabled()) {
                    msgLog.debug("DHT finish fut, sent request near [txId=" + tx.nearXidVersion() + ", dhtTxId=" + tx.xidVersion() + ", node=" + nearMapping.primary().id() + ']');
                }
                if (sync)
                    res = true;
                else
                    fut.onDone();
            } catch (IgniteCheckedException e) {
                // Fail the whole thing.
                if (e instanceof ClusterTopologyCheckedException)
                    fut.onNodeLeft((ClusterTopologyCheckedException) e);
                else {
                    if (msgLog.isDebugEnabled()) {
                        msgLog.debug("DHT finish fut, failed to send request near [txId=" + tx.nearXidVersion() + ", dhtTxId=" + tx.xidVersion() + ", node=" + nearMapping.primary().id() + ", err=" + e + ']');
                    }
                    fut.onResult(e);
                }
            }
        }
    }
    return res;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridDistributedTxMapping(org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping) ArrayList(java.util.ArrayList) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 2 with GridDistributedTxMapping

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

the class GridDhtTxLocalAdapter method removeMapping.

/**
     * @param nodeId Node ID.
     * @param entry Entry to remove.
     * @param map Map to remove from.
     * @return {@code True} if was removed.
     */
private boolean removeMapping(UUID nodeId, @Nullable GridCacheEntryEx entry, Map<UUID, GridDistributedTxMapping> map) {
    if (entry != null) {
        if (log.isDebugEnabled())
            log.debug("Removing mapping for entry [nodeId=" + nodeId + ", entry=" + entry + ']');
        IgniteTxEntry txEntry = entry(entry.txKey());
        if (txEntry == null)
            return false;
        GridDistributedTxMapping m = map.get(nodeId);
        boolean ret = m != null && m.removeEntry(txEntry);
        if (m != null && m.empty())
            map.remove(nodeId);
        return ret;
    } else
        return map.remove(nodeId) != null;
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridDistributedTxMapping(org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping)

Example 3 with GridDistributedTxMapping

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

the class GridDhtTxLocalAdapter method addMapping.

/**
     * @param mappings Entry mappings.
     * @param dst Transaction mappings.
     */
private void addMapping(Map<ClusterNode, List<GridDhtCacheEntry>> mappings, Map<UUID, GridDistributedTxMapping> dst) {
    for (Map.Entry<ClusterNode, List<GridDhtCacheEntry>> mapping : mappings.entrySet()) {
        ClusterNode n = mapping.getKey();
        GridDistributedTxMapping m = dst.get(n.id());
        List<GridDhtCacheEntry> entries = mapping.getValue();
        for (GridDhtCacheEntry entry : entries) {
            IgniteTxEntry txEntry = entry(entry.txKey());
            if (txEntry != null) {
                if (m == null)
                    dst.put(n.id(), m = new GridDistributedTxMapping(n));
                m.add(txEntry);
            }
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridDistributedTxMapping(org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping) List(java.util.List) Map(java.util.Map) GridLeanMap(org.apache.ignite.internal.util.GridLeanMap)

Example 4 with GridDistributedTxMapping

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

the class GridNearOptimisticTxPrepareFuture method prepareSingle.

/**
     * @param write Write.
     * @param topLocked {@code True} if thread already acquired lock preventing topology change.
     * @param remap Remap flag.
     */
private void prepareSingle(IgniteTxEntry write, boolean topLocked, boolean remap) {
    write.clearEntryReadVersion();
    AffinityTopologyVersion topVer = tx.topologyVersion();
    assert topVer.topologyVersion() > 0;
    txMapping = new GridDhtTxMapping();
    GridDistributedTxMapping mapping = map(write, topVer, null, topLocked, remap);
    if (mapping.primary().isLocal()) {
        if (write.context().isNear())
            tx.nearLocallyMapped(true);
        else if (write.context().isColocated())
            tx.colocatedLocallyMapped(true);
    }
    if (isDone()) {
        if (log.isDebugEnabled())
            log.debug("Abandoning (re)map because future is done: " + this);
        return;
    }
    if (keyLockFut != null)
        keyLockFut.onAllKeysAdded();
    tx.addSingleEntryMapping(mapping, write);
    cctx.mvcc().recheckPendingLocks();
    mapping.last(true);
    tx.transactionNodes(txMapping.transactionNodes());
    if (!write.context().isNear())
        checkOnePhase(txMapping);
    assert !(mapping.hasColocatedCacheEntries() && mapping.hasNearCacheEntries()) : mapping;
    proceedPrepare(mapping, null);
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridDhtTxMapping(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxMapping) GridDistributedTxMapping(org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping)

Example 5 with GridDistributedTxMapping

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

the class GridNearOptimisticTxPrepareFuture method map.

/**
     * @param entry Transaction entry.
     * @param topVer Topology version.
     * @param cur Current mapping.
     * @param topLocked {@code True} if thread already acquired lock preventing topology change.
     * @param remap Remap flag.
     * @return Mapping.
     */
private GridDistributedTxMapping map(IgniteTxEntry entry, AffinityTopologyVersion topVer, @Nullable GridDistributedTxMapping cur, boolean topLocked, boolean remap) {
    GridCacheContext cacheCtx = entry.context();
    List<ClusterNode> nodes;
    GridCacheEntryEx cached0 = entry.cached();
    if (cached0.isDht())
        nodes = cacheCtx.topology().nodes(cached0.partition(), topVer);
    else
        nodes = cacheCtx.isLocal() ? cacheCtx.affinity().nodesByKey(entry.key(), topVer) : cacheCtx.topology().nodes(cacheCtx.affinity().partition(entry.key()), topVer);
    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 (cacheCtx.isNear() || cacheCtx.isLocal()) {
        if (entry.explicitVersion() == null && !remap) {
            if (keyLockFut == null) {
                keyLockFut = new KeyLockFuture();
                add(keyLockFut);
            }
            keyLockFut.addLockKey(entry.txKey());
        }
    }
    if (cur == null || !cur.primary().id().equals(primary.id()) || (primary.isLocal() && cur.hasNearCacheEntries() != cacheCtx.isNear())) {
        boolean clientFirst = cur == null && !topLocked && cctx.kernalContext().clientNode();
        cur = new GridDistributedTxMapping(primary);
        cur.clientFirst(clientFirst);
    }
    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));
            }
        }
    }
    return cur;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridDistributedTxMapping(org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)

Aggregations

GridDistributedTxMapping (org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping)23 ClusterNode (org.apache.ignite.cluster.ClusterNode)12 IgniteTxEntry (org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry)11 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 UUID (java.util.UUID)5 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)5 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)4 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)4 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)4 GridDhtTxMapping (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxMapping)4 HashMap (java.util.HashMap)3 Collection (java.util.Collection)2 Map (java.util.Map)2 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)2 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)2 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)1 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)1