Search in sources :

Example 21 with IgniteTxEntry

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

the class GridDhtTxLocalAdapter method mapExplicitLocks.

/**
 * Map explicit locks.
 */
protected void mapExplicitLocks() {
    if (!mapped) {
        // Explicit locks may participate in implicit transactions only.
        if (!implicit()) {
            mapped = true;
            return;
        }
        Map<ClusterNode, List<GridDhtCacheEntry>> dhtEntryMap = null;
        Map<ClusterNode, List<GridDhtCacheEntry>> nearEntryMap = null;
        for (IgniteTxEntry e : allEntries()) {
            assert e.cached() != null;
            GridCacheContext cacheCtx = e.cached().context();
            if (cacheCtx.isNear())
                continue;
            if (e.cached().obsolete()) {
                GridCacheEntryEx cached = cacheCtx.cache().entryEx(e.key(), topologyVersion());
                e.cached(cached);
            }
            if (e.cached().detached() || e.cached().isLocal())
                continue;
            while (true) {
                try {
                    // Map explicit locks.
                    if (e.explicitVersion() != null && !e.explicitVersion().equals(xidVer)) {
                        if (dhtEntryMap == null)
                            dhtEntryMap = new GridLeanMap<>();
                        if (nearEntryMap == null)
                            nearEntryMap = new GridLeanMap<>();
                        cacheCtx.dhtMap((GridDhtCacheEntry) e.cached(), e.explicitVersion(), log, dhtEntryMap, nearEntryMap);
                    }
                    break;
                } catch (GridCacheEntryRemovedException ignore) {
                    GridCacheEntryEx cached = cacheCtx.cache().entryEx(e.key(), topologyVersion());
                    e.cached(cached);
                }
            }
        }
        if (!F.isEmpty(dhtEntryMap))
            addDhtNodeEntryMapping(dhtEntryMap);
        if (!F.isEmpty(nearEntryMap))
            addNearNodeEntryMapping(nearEntryMap);
        mapped = true;
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridLeanMap(org.apache.ignite.internal.util.GridLeanMap) List(java.util.List) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)

Example 22 with IgniteTxEntry

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

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

the class GridNearOptimisticSerializableTxPrepareFuture method onOwnerChanged.

/**
 * {@inheritDoc}
 */
@Override
public boolean onOwnerChanged(GridCacheEntryEx entry, GridCacheMvccCandidate owner) {
    if (log.isDebugEnabled())
        log.debug("Transaction future received owner changed callback: " + entry);
    if ((entry.context().isNear() || entry.context().isLocal()) && owner != null) {
        IgniteTxEntry txEntry = tx.entry(entry.txKey());
        if (txEntry != null) {
            if (entry.context().isLocal()) {
                GridCacheVersion serReadVer = txEntry.entryReadVersion();
                if (serReadVer != null) {
                    GridCacheContext ctx = entry.context();
                    while (true) {
                        try {
                            if (!entry.checkSerializableReadVersion(serReadVer)) {
                                Object key = entry.key().value(ctx.cacheObjectContext(), false);
                                IgniteTxOptimisticCheckedException err0 = new IgniteTxOptimisticCheckedException(S.toString("Failed to prepare transaction, read/write conflict", "key", key, true, "cache", ctx.name(), false));
                                ERR_UPD.compareAndSet(this, null, err0);
                            }
                            break;
                        } catch (GridCacheEntryRemovedException ignored) {
                            entry = ctx.cache().entryEx(entry.key(), tx.topologyVersion());
                            txEntry.cached(entry);
                        }
                    }
                }
            }
            if (keyLockFut != null)
                keyLockFut.onKeyLocked(entry.txKey());
            return true;
        }
    }
    return false;
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) IgniteTxOptimisticCheckedException(org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException)

Example 24 with IgniteTxEntry

use of org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry 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(), txNodes.size() == 1, 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 25 with IgniteTxEntry

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

the class GridNearOptimisticTxPrepareFuture method requestedKeys.

/**
 * @return Keys for which {@code MiniFuture} isn't completed.
 */
@SuppressWarnings("ForLoopReplaceableByForEach")
public Set<IgniteTxKey> requestedKeys() {
    synchronized (this) {
        int size = futuresCountNoLock();
        for (int i = 0; i < size; i++) {
            IgniteInternalFuture<GridNearTxPrepareResponse> fut = future(i);
            if (isMini(fut) && !fut.isDone()) {
                MiniFuture miniFut = (MiniFuture) fut;
                Collection<IgniteTxEntry> entries = miniFut.mapping().entries();
                Set<IgniteTxKey> keys = U.newHashSet(entries.size());
                for (IgniteTxEntry entry : entries) keys.add(entry.txKey());
                return keys;
            }
        }
    }
    return null;
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) IgniteTxKey(org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey)

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