Search in sources :

Example 6 with IgniteTxTimeoutCheckedException

use of org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException in project ignite by apache.

the class GridDhtTxLocal method prepareAsync.

/**
     * Prepares next batch of entries in dht transaction.
     *
     * @param reads Read entries.
     * @param writes Write entries.
     * @param verMap Version map.
     * @param msgId Message ID.
     * @param nearMiniId Near mini future ID.
     * @param txNodes Transaction nodes mapping.
     * @param last {@code True} if this is last prepare request.
     * @return Future that will be completed when locks are acquired.
     */
public final IgniteInternalFuture<GridNearTxPrepareResponse> prepareAsync(@Nullable Collection<IgniteTxEntry> reads, @Nullable Collection<IgniteTxEntry> writes, Map<IgniteTxKey, GridCacheVersion> verMap, long msgId, int nearMiniId, Map<UUID, Collection<UUID>> txNodes, boolean last) {
    // In optimistic mode prepare still can be called explicitly from salvageTx.
    GridDhtTxPrepareFuture fut = prepFut;
    long timeout = remainingTime();
    if (fut == null) {
        init();
        // Future must be created before any exception can be thrown.
        if (!PREP_FUT_UPD.compareAndSet(this, null, fut = new GridDhtTxPrepareFuture(cctx, this, timeout, nearMiniId, verMap, last, needReturnValue()))) {
            GridDhtTxPrepareFuture f = prepFut;
            assert f.nearMiniId() == nearMiniId : "Wrong near mini id on existing future " + "[futMiniId=" + f.nearMiniId() + ", miniId=" + nearMiniId + ", fut=" + f + ']';
            if (timeout == -1)
                f.onError(timeoutException());
            return chainOnePhasePrepare(f);
        }
    } else {
        assert fut.nearMiniId() == nearMiniId : "Wrong near mini id on existing future " + "[futMiniId=" + fut.nearMiniId() + ", miniId=" + nearMiniId + ", fut=" + fut + ']';
        // Prepare was called explicitly.
        return chainOnePhasePrepare(fut);
    }
    if (state() != PREPARING) {
        if (!state(PREPARING)) {
            if (state() == PREPARED && isSystemInvalidate())
                fut.complete();
            if (setRollbackOnly()) {
                if (timeout == -1)
                    fut.onError(new IgniteTxTimeoutCheckedException("Transaction timed out and was rolled back: " + this));
                else
                    fut.onError(new IgniteCheckedException("Invalid transaction state for prepare [state=" + state() + ", tx=" + this + ']'));
            } else
                fut.onError(new IgniteTxRollbackCheckedException("Invalid transaction state for prepare [state=" + state() + ", tx=" + this + ']'));
            return fut;
        }
    }
    try {
        if (reads != null) {
            for (IgniteTxEntry e : reads) addEntry(msgId, e);
        }
        if (writes != null) {
            for (IgniteTxEntry e : writes) addEntry(msgId, e);
        }
        userPrepare(null);
        // Make sure to add future before calling prepare on it.
        cctx.mvcc().addFuture(fut);
        if (isSystemInvalidate())
            fut.complete();
        else
            fut.prepare(reads, writes, txNodes);
    } catch (IgniteTxTimeoutCheckedException | IgniteTxOptimisticCheckedException e) {
        fut.onError(e);
    } catch (IgniteCheckedException e) {
        setRollbackOnly();
        fut.onError(new IgniteTxRollbackCheckedException("Failed to prepare transaction: " + this, e));
        try {
            rollbackDhtLocal();
        } catch (IgniteTxOptimisticCheckedException e1) {
            if (log.isDebugEnabled())
                log.debug("Failed optimistically to prepare transaction [tx=" + this + ", e=" + e1 + ']');
            fut.onError(e);
        } catch (IgniteCheckedException e1) {
            U.error(log, "Failed to rollback transaction: " + this, e1);
        }
    }
    return chainOnePhasePrepare(fut);
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteTxTimeoutCheckedException(org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) IgniteTxOptimisticCheckedException(org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException)

Example 7 with IgniteTxTimeoutCheckedException

use of org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException in project ignite by apache.

the class GridNearTxLocal method prepareAsyncLocal.

/**
     * Prepares next batch of entries in dht transaction.
     *
     * @param reads Read entries.
     * @param writes Write entries.
     * @param txNodes Transaction nodes mapping.
     * @param last {@code True} if this is last prepare request.
     * @return Future that will be completed when locks are acquired.
     */
@SuppressWarnings("TypeMayBeWeakened")
public IgniteInternalFuture<GridNearTxPrepareResponse> prepareAsyncLocal(@Nullable Collection<IgniteTxEntry> reads, @Nullable Collection<IgniteTxEntry> writes, Map<UUID, Collection<UUID>> txNodes, boolean last) {
    long timeout = remainingTime();
    if (state() != PREPARING) {
        if (timeout == -1)
            return new GridFinishedFuture<>(new IgniteTxTimeoutCheckedException("Transaction timed out: " + this));
        setRollbackOnly();
        return new GridFinishedFuture<>(new IgniteCheckedException("Invalid transaction state for prepare [state=" + state() + ", tx=" + this + ']'));
    }
    if (timeout == -1)
        return new GridFinishedFuture<>(timeoutException());
    init();
    GridDhtTxPrepareFuture fut = new GridDhtTxPrepareFuture(cctx, this, timeout, 0, Collections.<IgniteTxKey, GridCacheVersion>emptyMap(), last, needReturnValue() && implicit());
    try {
        userPrepare((serializable() && optimistic()) ? F.concat(false, writes, reads) : writes);
        // Make sure to add future before calling prepare on it.
        cctx.mvcc().addFuture(fut);
        if (isSystemInvalidate())
            fut.complete();
        else
            fut.prepare(reads, writes, txNodes);
    } catch (IgniteTxTimeoutCheckedException | IgniteTxOptimisticCheckedException e) {
        fut.onError(e);
    } catch (IgniteCheckedException e) {
        setRollbackOnly();
        fut.onError(new IgniteTxRollbackCheckedException("Failed to prepare transaction: " + this, e));
        try {
            rollback();
        } catch (IgniteTxOptimisticCheckedException e1) {
            if (log.isDebugEnabled())
                log.debug("Failed optimistically to prepare transaction [tx=" + this + ", e=" + e1 + ']');
            fut.onError(e);
        } catch (IgniteCheckedException e1) {
            U.error(log, "Failed to rollback transaction: " + this, e1);
        }
    }
    return chainOnePhasePrepare(fut);
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteTxTimeoutCheckedException(org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) GridDhtTxPrepareFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareFuture) IgniteTxOptimisticCheckedException(org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 IgniteTxTimeoutCheckedException (org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException)7 IgniteTxEntry (org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry)4 IgniteTxRollbackCheckedException (org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException)4 UUID (java.util.UUID)2 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)2 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)2 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)2 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)2 IgniteTxOptimisticCheckedException (org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException)2 TransactionState (org.apache.ignite.transactions.TransactionState)2 TransactionTimeoutException (org.apache.ignite.transactions.TransactionTimeoutException)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Duration (javax.cache.expiry.Duration)1 ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 ClusterTopologyException (org.apache.ignite.cluster.ClusterTopologyException)1 StorageException (org.apache.ignite.internal.pagemem.wal.StorageException)1