Search in sources :

Example 1 with GridDhtTxAbstractEnlistFuture

use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxAbstractEnlistFuture in project ignite by apache.

the class GridNearTxAbstractEnlistFuture method init.

/**
 */
public void init() {
    if (timeout < 0) {
        // Time is out.
        onDone(timeoutException());
        return;
    } else if (timeout > 0)
        timeoutObj = new LockTimeoutObject();
    while (true) {
        IgniteInternalFuture<?> fut = tx.lockFuture();
        if (fut == GridDhtTxLocalAdapter.ROLLBACK_FUT) {
            onDone(tx.timedOut() ? tx.timeoutException() : tx.rollbackException());
            return;
        } else if (fut != null) {
            // Wait for previous future.
            assert fut instanceof GridNearTxAbstractEnlistFuture || fut instanceof GridDhtTxAbstractEnlistFuture : fut;
            // Terminate this future if parent future is terminated by rollback.
            if (!fut.isDone()) {
                fut.listen(new IgniteInClosure<IgniteInternalFuture>() {

                    @Override
                    public void apply(IgniteInternalFuture fut) {
                        if (fut.error() != null)
                            onDone(fut.error());
                    }
                });
            } else if (fut.error() != null)
                onDone(fut.error());
            break;
        } else if (tx.updateLockFuture(null, this))
            break;
    }
    boolean added = cctx.mvcc().addFuture(this);
    assert added : this;
    if (isDone()) {
        cctx.mvcc().removeFuture(futId);
        return;
    }
    try {
        tx.addActiveCache(cctx, false);
    } catch (IgniteCheckedException e) {
        onDone(e);
        return;
    }
    if (timeoutObj != null)
        cctx.time().addTimeoutObject(timeoutObj);
    // 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.system())
        topVer = cctx.tm().lockedTopologyVersion(threadId, tx);
    if (topVer != null)
        tx.topologyVersion(topVer);
    if (topVer == null)
        topVer = tx.topologyVersionSnapshot();
    if (topVer != null) {
        for (GridDhtTopologyFuture fut : cctx.shared().exchange().exchangeFutures()) {
            if (fut.exchangeDone() && fut.topologyVersion().equals(topVer)) {
                Throwable err = null;
                // Before cache validation, make sure that this topology future is already completed.
                try {
                    fut.get();
                } catch (IgniteCheckedException e) {
                    err = fut.error();
                }
                if (err == null)
                    err = fut.validateCache(cctx, false, false, null, null);
                if (err != null) {
                    onDone(err);
                    return;
                }
                break;
            }
        }
        if (this.topVer == null)
            this.topVer = topVer;
        map(true);
        return;
    }
    mapOnTopology();
}
Also used : GridDhtTopologyFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridDhtTxAbstractEnlistFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxAbstractEnlistFuture) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture)

Example 2 with GridDhtTxAbstractEnlistFuture

use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxAbstractEnlistFuture in project ignite by apache.

the class GridNearTxAbstractEnlistFuture method onDone.

/**
 * {@inheritDoc}
 */
@Override
public boolean onDone(@Nullable T res, @Nullable Throwable err, boolean cancelled) {
    if (!DONE_UPD.compareAndSet(this, 0, 1))
        return false;
    cctx.tm().txContext(tx);
    if (!cancelled && err == null)
        tx.clearLockFuture(this);
    else
        tx.setRollbackOnly();
    synchronized (this) {
        GridDhtTxAbstractEnlistFuture localFuture0 = localEnlistFuture;
        if (localFuture0 != null && (err != null || cancelled))
            localFuture0.onDone(cancelled ? new IgniteFutureCancelledCheckedException("Future was cancelled: " + localFuture0) : err);
        boolean done = super.onDone(res, err, cancelled);
        assert done;
        // Clean up.
        cctx.mvcc().removeVersionedFuture(this);
        if (timeoutObj != null)
            cctx.time().removeTimeoutObject(timeoutObj);
        return true;
    }
}
Also used : IgniteFutureCancelledCheckedException(org.apache.ignite.internal.IgniteFutureCancelledCheckedException) GridDhtTxAbstractEnlistFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxAbstractEnlistFuture)

Example 3 with GridDhtTxAbstractEnlistFuture

use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxAbstractEnlistFuture in project ignite by apache.

the class GridNearTxEnlistFuture method enlistLocal.

/**
 * Enlist batch of entries to the transaction on local node.
 *
 * @param batchId Id of a batch mini-future.
 * @param nodeId Node id.
 * @param batch Batch.
 */
private void enlistLocal(int batchId, UUID nodeId, Batch batch) throws IgniteCheckedException {
    Collection<Object> rows = batch.rows();
    GridDhtTxEnlistFuture fut = new GridDhtTxEnlistFuture(nodeId, lockVer, mvccSnapshot, threadId, futId, batchId, tx, remainingTime(), cctx, rows, it.operation(), filter, needRes, keepBinary);
    updateLocalFuture(fut);
    fut.listen(new CI1<IgniteInternalFuture<GridCacheReturn>>() {

        @Override
        public void apply(IgniteInternalFuture<GridCacheReturn> fut) {
            try {
                clearLocalFuture((GridDhtTxAbstractEnlistFuture) fut);
                GridNearTxEnlistResponse res = fut.error() == null ? createResponse(fut) : null;
                if (checkResponse(nodeId, res, fut.error()))
                    sendNextBatches(nodeId);
            } catch (IgniteCheckedException e) {
                checkResponse(nodeId, null, e);
            } finally {
                CU.unwindEvicts(cctx);
            }
        }
    });
    fut.init();
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheReturn(org.apache.ignite.internal.processors.cache.GridCacheReturn) GridDhtTxAbstractEnlistFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxAbstractEnlistFuture) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridDhtTxEnlistFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxEnlistFuture) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture)

Example 4 with GridDhtTxAbstractEnlistFuture

use of org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxAbstractEnlistFuture in project ignite by apache.

the class GridNearTxQueryResultsEnlistFuture method enlistLocal.

/**
 * Enlist batch of entries to the transaction on local node.
 *
 * @param batchId Id of a batch mini-future.
 * @param nodeId Node id.
 * @param batch Batch.
 */
private void enlistLocal(int batchId, UUID nodeId, Batch batch) throws IgniteCheckedException {
    Collection<Object> rows = batch.rows();
    GridDhtTxQueryResultsEnlistFuture fut = new GridDhtTxQueryResultsEnlistFuture(nodeId, lockVer, mvccSnapshot, threadId, futId, batchId, tx, remainingTime(), cctx, rows, it.operation());
    updateLocalFuture(fut);
    fut.listen(new CI1<IgniteInternalFuture<Long>>() {

        @Override
        public void apply(IgniteInternalFuture<Long> fut) {
            assert fut.error() != null || fut.result() != null : fut;
            try {
                clearLocalFuture((GridDhtTxAbstractEnlistFuture) fut);
                GridNearTxQueryResultsEnlistResponse res = fut.error() == null ? createResponse(fut) : null;
                if (checkResponse(nodeId, res, fut.error()))
                    sendNextBatches(nodeId);
            } catch (IgniteCheckedException e) {
                checkResponse(nodeId, null, e);
            } finally {
                CU.unwindEvicts(cctx);
            }
        }
    });
    fut.init();
}
Also used : GridDhtTxQueryResultsEnlistFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxQueryResultsEnlistFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridDhtTxAbstractEnlistFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxAbstractEnlistFuture) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture)

Aggregations

GridDhtTxAbstractEnlistFuture (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxAbstractEnlistFuture)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)3 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)2 IgniteFutureCancelledCheckedException (org.apache.ignite.internal.IgniteFutureCancelledCheckedException)1 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)1 GridCacheReturn (org.apache.ignite.internal.processors.cache.GridCacheReturn)1 GridDhtTopologyFuture (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture)1 GridDhtTxEnlistFuture (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxEnlistFuture)1 GridDhtTxQueryResultsEnlistFuture (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxQueryResultsEnlistFuture)1 IgniteInClosure (org.apache.ignite.lang.IgniteInClosure)1