Search in sources :

Example 6 with GridDistributedTxMapping

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

the class GridNearOptimisticSerializableTxPrepareFuture method createRequest.

/**
     * @param txNodes Tx nodes.
     * @param fut Future.
     * @param timeout Timeout.
     * @param reads Read entries.
     * @param writes Write entries.
     * @return Request.
     */
private GridNearTxPrepareRequest createRequest(Map<UUID, Collection<UUID>> txNodes, MiniFuture fut, long timeout, Collection<IgniteTxEntry> reads, Collection<IgniteTxEntry> writes) {
    GridDistributedTxMapping m = fut.mapping();
    GridNearTxPrepareRequest req = new GridNearTxPrepareRequest(futId, tx.topologyVersion(), tx, timeout, reads, writes, m.hasNearCacheEntries(), txNodes, m.last(), tx.onePhaseCommit(), tx.needReturnValue() && tx.implicit(), tx.implicitSingle(), m.explicitLock(), tx.subjectId(), tx.taskNameHash(), m.clientFirst(), tx.activeCachesDeploymentEnabled());
    for (IgniteTxEntry txEntry : writes) {
        if (txEntry.op() == TRANSFORM)
            req.addDhtVersion(txEntry.txKey(), null);
    }
    req.miniId(fut.futureId());
    return req;
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridDistributedTxMapping(org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping)

Example 7 with GridDistributedTxMapping

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

the class GridNearTxLocal method addSingleEntryMapping.

/**
     * @param map Mapping.
     * @param entry Entry.
     */
void addSingleEntryMapping(GridDistributedTxMapping map, IgniteTxEntry entry) {
    ClusterNode n = map.primary();
    GridDistributedTxMapping m = new GridDistributedTxMapping(n);
    mappings.put(m);
    if (map.explicitLock())
        m.markExplicitLock();
    m.add(entry);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDistributedTxMapping(org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping)

Example 8 with GridDistributedTxMapping

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

the class GridNearTxLocal method markExplicit.

/**
     * @param nodeId Node ID to mark with explicit lock.
     * @return {@code True} if mapping was found.
     */
public boolean markExplicit(UUID nodeId) {
    explicitLock = true;
    GridDistributedTxMapping m = mappings.get(nodeId);
    if (m != null) {
        m.markExplicitLock();
        return true;
    }
    return false;
}
Also used : GridDistributedTxMapping(org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping)

Example 9 with GridDistributedTxMapping

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

the class GridNearTxLocal method addKeyMapping.

/**
     * Adds key mapping to dht mapping.
     *
     * @param key Key to add.
     * @param node Node this key mapped to.
     */
public void addKeyMapping(IgniteTxKey key, ClusterNode node) {
    GridDistributedTxMapping m = mappings.get(node.id());
    if (m == null)
        mappings.put(m = new GridDistributedTxMapping(node));
    IgniteTxEntry txEntry = entry(key);
    assert txEntry != null;
    txEntry.nodeId(node.id());
    m.add(txEntry);
    if (log.isDebugEnabled())
        log.debug("Added mappings to transaction [locId=" + cctx.localNodeId() + ", key=" + key + ", node=" + node + ", tx=" + this + ']');
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridDistributedTxMapping(org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping)

Example 10 with GridDistributedTxMapping

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

the class GridNearPessimisticTxPrepareFuture method preparePessimistic.

/**
     *
     */
private void preparePessimistic() {
    Map<UUID, GridDistributedTxMapping> mappings = new HashMap<>();
    AffinityTopologyVersion topVer = tx.topologyVersion();
    GridDhtTxMapping txMapping = new GridDhtTxMapping();
    boolean hasNearCache = false;
    for (IgniteTxEntry txEntry : tx.allEntries()) {
        txEntry.clearEntryReadVersion();
        GridCacheContext cacheCtx = txEntry.context();
        if (cacheCtx.isNear())
            hasNearCache = true;
        List<ClusterNode> nodes;
        if (!cacheCtx.isLocal()) {
            GridDhtPartitionTopology top = cacheCtx.topology();
            nodes = top.nodes(cacheCtx.affinity().partition(txEntry.key()), topVer);
        } else
            nodes = cacheCtx.affinity().nodesByKey(txEntry.key(), topVer);
        assert !nodes.isEmpty();
        ClusterNode primary = nodes.get(0);
        GridDistributedTxMapping nodeMapping = mappings.get(primary.id());
        if (nodeMapping == null)
            mappings.put(primary.id(), nodeMapping = new GridDistributedTxMapping(primary));
        txEntry.nodeId(primary.id());
        nodeMapping.add(txEntry);
        txMapping.addMapping(nodes);
    }
    tx.transactionNodes(txMapping.transactionNodes());
    if (!hasNearCache)
        checkOnePhase(txMapping);
    long timeout = tx.remainingTime();
    if (timeout == -1) {
        onDone(new IgniteTxTimeoutCheckedException("Transaction timed out and was rolled back: " + tx));
        return;
    }
    int miniId = 0;
    Map<UUID, Collection<UUID>> txNodes = txMapping.transactionNodes();
    for (final GridDistributedTxMapping m : mappings.values()) {
        final ClusterNode primary = m.primary();
        if (primary.isLocal()) {
            if (m.hasNearCacheEntries() && m.hasColocatedCacheEntries()) {
                GridNearTxPrepareRequest nearReq = createRequest(txMapping.transactionNodes(), m, timeout, m.nearEntriesReads(), m.nearEntriesWrites());
                prepareLocal(nearReq, m, ++miniId, true);
                GridNearTxPrepareRequest colocatedReq = createRequest(txNodes, m, timeout, m.colocatedEntriesReads(), m.colocatedEntriesWrites());
                prepareLocal(colocatedReq, m, ++miniId, false);
            } else {
                GridNearTxPrepareRequest req = createRequest(txNodes, m, timeout, m.reads(), m.writes());
                prepareLocal(req, m, ++miniId, m.hasNearCacheEntries());
            }
        } else {
            GridNearTxPrepareRequest req = createRequest(txNodes, m, timeout, m.reads(), m.writes());
            final MiniFuture fut = new MiniFuture(m, ++miniId);
            req.miniId(fut.futureId());
            add(fut);
            try {
                cctx.io().send(primary, req, tx.ioPolicy());
                if (msgLog.isDebugEnabled()) {
                    msgLog.debug("Near pessimistic prepare, sent request [txId=" + tx.nearXidVersion() + ", node=" + primary.id() + ']');
                }
            } catch (ClusterTopologyCheckedException e) {
                e.retryReadyFuture(cctx.nextAffinityReadyFuture(topVer));
                fut.onNodeLeft(e);
            } catch (IgniteCheckedException e) {
                if (msgLog.isDebugEnabled()) {
                    msgLog.debug("Near pessimistic prepare, failed send request [txId=" + tx.nearXidVersion() + ", node=" + primary.id() + ", err=" + e + ']');
                }
                fut.onError(e);
                break;
            }
        }
    }
    markInitialized();
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) HashMap(java.util.HashMap) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology) GridDistributedTxMapping(org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridDhtTxMapping(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxMapping) Collection(java.util.Collection) IgniteTxTimeoutCheckedException(org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException) UUID(java.util.UUID) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

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