Search in sources :

Example 26 with GridCacheContext

use of org.apache.ignite.internal.processors.cache.GridCacheContext 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 27 with GridCacheContext

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

the class GridNearTxLocal method readyNearLock.

/**
     * @param txEntry TX entry.
     * @param dhtVer DHT version.
     * @param pendingVers Pending versions.
     * @param committedVers Committed versions.
     * @param rolledbackVers Rolled back versions.
     */
private void readyNearLock(IgniteTxEntry txEntry, GridCacheVersion dhtVer, Collection<GridCacheVersion> pendingVers, Collection<GridCacheVersion> committedVers, Collection<GridCacheVersion> rolledbackVers) {
    while (true) {
        GridCacheContext cacheCtx = txEntry.cached().context();
        assert cacheCtx.isNear();
        GridDistributedCacheEntry entry = (GridDistributedCacheEntry) txEntry.cached();
        try {
            // Handle explicit locks.
            GridCacheVersion explicit = txEntry.explicitVersion();
            if (explicit == null) {
                entry.readyNearLock(xidVer, dhtVer, committedVers, rolledbackVers, pendingVers);
            }
            break;
        } catch (GridCacheEntryRemovedException ignored) {
            assert entry.obsoleteVersion() != null;
            if (log.isDebugEnabled())
                log.debug("Replacing obsolete entry in remote transaction [entry=" + entry + ", tx=" + this + ']');
            // Replace the entry.
            txEntry.cached(txEntry.context().cache().entryEx(txEntry.key(), topologyVersion()));
        }
    }
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridDistributedCacheEntry(org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheEntry) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)

Example 28 with GridCacheContext

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

the class GridLocalCacheEntry method checkThreadChain.

/** {@inheritDoc} */
@Override
protected void checkThreadChain(GridCacheMvccCandidate owner) {
    assert !Thread.holdsLock(this);
    assert owner != null;
    assert owner.owner() || owner.used() : "Neither owner or used flags are set on ready local candidate: " + owner;
    if (owner.next() != null) {
        for (GridCacheMvccCandidate cand = owner.next(); cand != null; cand = cand.next()) {
            assert cand.local();
            // Allow next lock in the thread to proceed.
            if (!cand.used()) {
                GridCacheContext cctx0 = cand.parent().context();
                GridLocalCacheEntry e = (GridLocalCacheEntry) cctx0.cache().peekEx(cand.parent().key());
                // so we check for null.
                if (e != null)
                    e.recheck();
                break;
            }
        }
    }
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)

Example 29 with GridCacheContext

use of org.apache.ignite.internal.processors.cache.GridCacheContext 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)

Example 30 with GridCacheContext

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

the class GridNearSingleGetRequest method prepareMarshal.

/** {@inheritDoc} */
@Override
public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException {
    super.prepareMarshal(ctx);
    assert key != null;
    GridCacheContext cctx = ctx.cacheContext(cacheId);
    prepareMarshalCacheObject(key, cctx);
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext)

Aggregations

GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)121 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)27 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)20 ClusterNode (org.apache.ignite.cluster.ClusterNode)18 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)17 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)15 UUID (java.util.UUID)14 HashMap (java.util.HashMap)13 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)13 Map (java.util.Map)12 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)12 ArrayList (java.util.ArrayList)11 IgniteTxKey (org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey)11 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)10 IgniteTxEntry (org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry)10 List (java.util.List)9 IgniteException (org.apache.ignite.IgniteException)8 GridCacheEntryInfo (org.apache.ignite.internal.processors.cache.GridCacheEntryInfo)8 Ignite (org.apache.ignite.Ignite)7 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)7