Search in sources :

Example 21 with IgniteInternalTx

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

the class GridCacheMapEntry method peek.

/**
 * {@inheritDoc}
 */
@Nullable
@Override
public CacheObject peek(@Nullable IgniteCacheExpiryPolicy plc) throws GridCacheEntryRemovedException, IgniteCheckedException {
    IgniteInternalTx tx = cctx.tm().localTx();
    AffinityTopologyVersion topVer = tx != null ? tx.topologyVersion() : cctx.affinity().affinityTopologyVersion();
    return peek(true, false, topVer, plc);
}
Also used : IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) Nullable(org.jetbrains.annotations.Nullable)

Example 22 with IgniteInternalTx

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

the class GridNearTxFinishFuture method finishOnePhase.

/**
 * @param commit Commit flag.
 */
private void finishOnePhase(boolean commit) {
    assert Thread.holdsLock(this);
    if (finishOnePhaseCalled)
        return;
    finishOnePhaseCalled = true;
    GridDistributedTxMapping locMapping = mappings.localMapping();
    if (locMapping != null) {
        // No need to send messages as transaction was already committed on remote node.
        // Finish local mapping only as we need send commit message to backups.
        IgniteInternalFuture<IgniteInternalTx> fut = cctx.tm().txHandler().finishColocatedLocal(commit, tx);
        // Add new future.
        if (fut != null)
            add(fut);
    }
}
Also used : IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) GridDistributedTxMapping(org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping)

Example 23 with IgniteInternalTx

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

the class GridNearTxFinishFuture method finish.

/**
 * @param miniId Mini future ID.
 * @param m Mapping.
 * @param commit Commit flag.
 */
private void finish(int miniId, GridDistributedTxMapping m, boolean commit) {
    ClusterNode n = m.primary();
    assert !m.empty() : m;
    CacheWriteSynchronizationMode syncMode = tx.syncMode();
    if (m.explicitLock())
        syncMode = FULL_SYNC;
    // Version to be added in completed versions on primary node.
    GridCacheVersion completedVer = !commit && tx.timeout() > 0 ? tx.xidVersion() : null;
    GridNearTxFinishRequest req = new GridNearTxFinishRequest(futId, tx.xidVersion(), tx.threadId(), commit, tx.isInvalidate(), tx.system(), tx.ioPolicy(), syncMode, m.explicitLock(), tx.storeEnabled(), tx.topologyVersion(), // Reuse 'baseVersion' to do not add new fields in message.
    completedVer, null, null, tx.size(), tx.subjectId(), tx.taskNameHash(), tx.activeCachesDeploymentEnabled());
    // If this is the primary node for the keys.
    if (n.isLocal()) {
        req.miniId(miniId);
        IgniteInternalFuture<IgniteInternalTx> fut = cctx.tm().txHandler().finish(n.id(), tx, req);
        // Add new future.
        if (fut != null && syncMode == FULL_SYNC)
            add(fut);
    } else {
        FinishMiniFuture fut = new FinishMiniFuture(miniId, m);
        req.miniId(fut.futureId());
        // Append new future.
        add(fut);
        if (tx.pessimistic())
            cctx.tm().beforeFinishRemote(n.id(), tx.threadId());
        try {
            cctx.io().send(n, req, tx.ioPolicy());
            if (msgLog.isDebugEnabled()) {
                msgLog.debug("Near finish fut, sent request [" + "txId=" + tx.nearXidVersion() + ", node=" + n.id() + ']');
            }
            boolean wait = syncMode != FULL_ASYNC;
            // If we don't wait for result, then mark future as done.
            if (!wait)
                fut.onDone();
        } catch (ClusterTopologyCheckedException ignored) {
            // Remove previous mapping.
            mappings.remove(m.primary().id());
            fut.onNodeLeft(n.id(), false);
        } catch (IgniteCheckedException e) {
            if (msgLog.isDebugEnabled()) {
                msgLog.debug("Near finish fut, failed to send request [" + "txId=" + tx.nearXidVersion() + ", node=" + n.id() + ", err=" + e + ']');
            }
            // Fail the whole thing.
            fut.onDone(e);
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 24 with IgniteInternalTx

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

the class GridNearLockFuture method map.

/**
 * Basically, future mapping consists from two parts. First, we must determine the topology version this future
 * will map on. Locking is performed within a user transaction, we must continue to map keys on the same
 * topology version as it started. If topology version is undefined, we get current topology future and wait
 * until it completes so the topology is ready to use.
 * <p/>
 * During the second part we map keys to primary nodes using topology snapshot we obtained during the first
 * part. Note that if primary node leaves grid, the future will fail and transaction will be rolled back.
 */
void map() {
    if (tx != null && tx.trackTimeout()) {
        if (!tx.removeTimeoutHandler()) {
            tx.finishFuture().listen(new IgniteInClosure<IgniteInternalFuture<IgniteInternalTx>>() {

                @Override
                public void apply(IgniteInternalFuture<IgniteInternalTx> fut) {
                    IgniteTxTimeoutCheckedException err = new IgniteTxTimeoutCheckedException("Failed to " + "acquire lock, transaction was rolled back on timeout [timeout=" + tx.timeout() + ", tx=" + tx + ']');
                    onError(err);
                    onComplete(false, false, false);
                }
            });
            return;
        }
    }
    if (timeout > 0) {
        timeoutObj = new LockTimeoutObject();
        cctx.time().addTimeoutObject(timeoutObj);
    }
    boolean added = cctx.mvcc().addFuture(this);
    assert added : this;
    // Obtain the topology version to use.
    long threadId = Thread.currentThread().getId();
    AffinityTopologyVersion topVer = cctx.mvcc().lastExplicitLockTopologyVersion(threadId);
    // If there is another system transaction in progress, use it's topology version to prevent deadlock.
    if (topVer == null && tx != null && tx.system())
        topVer = cctx.tm().lockedTopologyVersion(threadId, tx);
    if (topVer != null && tx != null)
        tx.topologyVersion(topVer);
    if (topVer == null && tx != null)
        topVer = tx.topologyVersionSnapshot();
    if (topVer != null) {
        for (GridDhtTopologyFuture fut : cctx.shared().exchange().exchangeFutures()) {
            if (fut.exchangeDone() && fut.topologyVersion().equals(topVer)) {
                Throwable err = fut.validateCache(cctx, recovery, read, null, keys);
                if (err != null) {
                    onDone(err);
                    return;
                }
                break;
            }
        }
        // Continue mapping on the same topology version as it was before.
        if (this.topVer == null)
            this.topVer = topVer;
        map(keys, false, true);
        markInitialized();
        return;
    }
    // Must get topology snapshot and map on that version.
    mapOnTopology(false);
}
Also used : GridDhtTopologyFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteTxTimeoutCheckedException(org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture)

Example 25 with IgniteInternalTx

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

the class GridCacheStoreManagerAdapter method loadFromStore.

/**
 * Loads data from persistent store.
 *
 * @param tx Cache transaction.
 * @param key Cache key.
 * @param convert Convert flag.
 * @return Loaded value, possibly <tt>null</tt>.
 * @throws IgniteCheckedException If data loading failed.
 */
@Nullable
private Object loadFromStore(@Nullable IgniteInternalTx tx, KeyCacheObject key, boolean convert) throws IgniteCheckedException {
    if (store != null) {
        if (key.internal())
            // Never load internal keys from store as they are never persisted.
            return null;
        Object storeKey = cctx.unwrapBinaryIfNeeded(key, !convertBinary());
        if (log.isDebugEnabled())
            log.debug(S.toString("Loading value from store for key", "key", storeKey, true));
        sessionInit0(tx, StoreOperation.READ, false);
        boolean threwEx = true;
        Object val = null;
        try {
            val = singleThreadGate.load(storeKey);
            threwEx = false;
        } catch (ClassCastException e) {
            handleClassCastException(e);
        } catch (CacheLoaderException e) {
            throw new IgniteCheckedException(e);
        } catch (Exception e) {
            throw new IgniteCheckedException(new CacheLoaderException(e));
        } finally {
            IgniteInternalTx tx0 = tx;
            if (tx0 != null && (tx0.dht() && tx0.local()))
                tx0 = null;
            sessionEnd0(tx0, threwEx);
        }
        if (log.isDebugEnabled())
            log.debug(S.toString("Loaded value from store", "key", key, true, "val", val, true));
        if (convert) {
            val = convert(val);
            return val;
        } else
            return val;
    }
    return null;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) CacheLoaderException(javax.cache.integration.CacheLoaderException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) CacheWriterException(javax.cache.integration.CacheWriterException) CacheLoaderException(javax.cache.integration.CacheLoaderException) NoSuchElementException(java.util.NoSuchElementException) CacheStorePartialUpdateException(org.apache.ignite.internal.processors.cache.CacheStorePartialUpdateException) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

IgniteInternalTx (org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx)34 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)10 IgniteTxTimeoutCheckedException (org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException)5 IgniteException (org.apache.ignite.IgniteException)4 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)4 IgniteTxManager (org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager)4 IgfsPath (org.apache.ignite.igfs.IgfsPath)3 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)3 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)3 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)3 TransactionProxyImpl (org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl)3 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)3 Nullable (org.jetbrains.annotations.Nullable)3 HashMap (java.util.HashMap)2 NoSuchElementException (java.util.NoSuchElementException)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 IgniteKernal (org.apache.ignite.internal.IgniteKernal)2 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)2 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)2