Search in sources :

Example 11 with IgniteTxRollbackCheckedException

use of org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException 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)

Example 12 with IgniteTxRollbackCheckedException

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

the class IgniteTxHandler method startNearRemoteTx.

/**
     * Called while processing dht tx prepare request.
     *
     * @param ldr Loader.
     * @param nodeId Sender node ID.
     * @param req Request.
     * @return Remote transaction.
     * @throws IgniteCheckedException If failed.
     */
@Nullable
public GridNearTxRemote startNearRemoteTx(ClassLoader ldr, UUID nodeId, GridDhtTxPrepareRequest req) throws IgniteCheckedException {
    if (!F.isEmpty(req.nearWrites())) {
        GridNearTxRemote tx = ctx.tm().nearTx(req.version());
        if (tx == null) {
            tx = new GridNearTxRemote(ctx, req.topologyVersion(), ldr, nodeId, req.nearNodeId(), req.version(), null, req.system(), req.policy(), req.concurrency(), req.isolation(), req.isInvalidate(), req.timeout(), req.nearWrites(), req.txSize(), req.subjectId(), req.taskNameHash());
            tx.writeVersion(req.writeVersion());
            if (!tx.empty()) {
                tx = ctx.tm().onCreated(null, tx);
                if (tx == null || !ctx.tm().onStarted(tx))
                    throw new IgniteTxRollbackCheckedException("Attempt to start a completed transaction: " + tx);
            }
        } else
            tx.addEntries(ldr, req.nearWrites());
        tx.ownedVersions(req.owned());
        // Prepare prior to reordering, so the pending locks added
        // in prepare phase will get properly ordered as well.
        tx.prepareRemoteTx();
        if (req.last())
            tx.state(PREPARED);
        return tx;
    }
    return null;
}
Also used : IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) GridNearTxRemote(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxRemote) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

IgniteTxRollbackCheckedException (org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException)12 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)4 Nullable (org.jetbrains.annotations.Nullable)4 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)3 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)3 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)3 GridNearTxRemote (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxRemote)3 IgniteTxKey (org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey)3 IgniteTxOptimisticCheckedException (org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException)3 IgniteTxTimeoutCheckedException (org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException)3 IGNITE_CACHE_RETRIES_COUNT (org.apache.ignite.IgniteSystemProperties.IGNITE_CACHE_RETRIES_COUNT)2 BROADCAST (org.apache.ignite.internal.GridClosureCallMode.BROADCAST)2 GridCacheReturnCompletableWrapper (org.apache.ignite.internal.processors.cache.GridCacheReturnCompletableWrapper)2 GridDistributedCacheEntry (org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheEntry)2 GridNearTxLocal (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)2 IgniteTxEntry (org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry)2 IgniteTxHeuristicCheckedException (org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException)2 GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)2 ArrayList (java.util.ArrayList)1