Search in sources :

Example 1 with GridDhtTxFinishFuture

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

the class GridNearTxLocal method commitAsyncLocal.

/**
 * Commits local part of colocated transaction.
 *
 * @return Commit future.
 */
public IgniteInternalFuture<IgniteInternalTx> commitAsyncLocal() {
    if (log.isDebugEnabled())
        log.debug("Committing colocated tx locally: " + this);
    IgniteInternalFuture<?> prep = prepFut;
    // Do not create finish future if there are no remote nodes.
    if (F.isEmpty(dhtMap) && F.isEmpty(nearMap)) {
        if (prep != null)
            return (IgniteInternalFuture<IgniteInternalTx>) prep;
        return new GridFinishedFuture<IgniteInternalTx>(this);
    }
    final GridDhtTxFinishFuture fut = new GridDhtTxFinishFuture<>(cctx, this, true);
    cctx.mvcc().addFuture(fut, fut.futureId());
    if (prep == null || prep.isDone()) {
        assert prep != null || optimistic();
        IgniteCheckedException err = null;
        try {
            if (prep != null)
                // Check for errors of a parent future.
                prep.get();
        } catch (IgniteCheckedException e) {
            err = e;
            U.error(log, "Failed to prepare transaction: " + this, e);
        }
        if (err != null)
            fut.rollbackOnError(err);
        else
            fut.finish(true);
    } else
        prep.listen(new CI1<IgniteInternalFuture<?>>() {

            @Override
            public void apply(IgniteInternalFuture<?> f) {
                IgniteCheckedException err = null;
                try {
                    // Check for errors of a parent future.
                    f.get();
                } catch (IgniteCheckedException e) {
                    err = e;
                    U.error(log, "Failed to prepare transaction: " + this, e);
                }
                if (err != null)
                    fut.rollbackOnError(err);
                else
                    fut.finish(true);
            }
        });
    return fut;
}
Also used : GridDhtTxFinishFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) CI1(org.apache.ignite.internal.util.typedef.CI1) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture)

Example 2 with GridDhtTxFinishFuture

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

the class IgniteTxHandler method processDhtTxFinishResponse.

/**
 * @param nodeId Node ID.
 * @param res Response.
 */
private void processDhtTxFinishResponse(UUID nodeId, GridDhtTxFinishResponse res) {
    assert nodeId != null;
    assert res != null;
    if (res.checkCommitted()) {
        GridNearTxFinishFuture fut = (GridNearTxFinishFuture) ctx.mvcc().<IgniteInternalTx>future(res.futureId());
        if (fut == null) {
            if (txFinishMsgLog.isDebugEnabled()) {
                txFinishMsgLog.debug("Failed to find future for dht finish check committed response [txId=null" + ", dhtTxId=" + res.xid() + ", node=" + nodeId + ", res=" + res + ']');
            }
            return;
        } else if (txFinishMsgLog.isDebugEnabled()) {
            txFinishMsgLog.debug("Received dht finish check committed response [txId=" + fut.tx().nearXidVersion() + ", dhtTxId=" + res.xid() + ", node=" + nodeId + ']');
        }
        fut.onResult(nodeId, res);
    } else {
        GridDhtTxFinishFuture fut = (GridDhtTxFinishFuture) ctx.mvcc().<IgniteInternalTx>future(res.futureId());
        if (fut == null) {
            if (txFinishMsgLog.isDebugEnabled()) {
                txFinishMsgLog.debug("Failed to find future for dht finish response [txId=null" + ", dhtTxId=" + res.xid() + ", node=" + nodeId + ", res=" + res);
            }
            return;
        } else if (txFinishMsgLog.isDebugEnabled()) {
            txFinishMsgLog.debug("Received dht finish response [txId=" + fut.tx().nearXidVersion() + ", dhtTxId=" + res.xid() + ", node=" + nodeId + ']');
        }
        fut.onResult(nodeId, res);
    }
}
Also used : GridDhtTxFinishFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishFuture) GridNearTxFinishFuture(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishFuture)

Example 3 with GridDhtTxFinishFuture

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

the class GridNearTxLocal method rollbackAsyncLocal.

/**
 * Rolls back local part of colocated transaction.
 *
 * @return Commit future.
 */
public IgniteInternalFuture<IgniteInternalTx> rollbackAsyncLocal() {
    if (log.isDebugEnabled())
        log.debug("Rolling back colocated tx locally: " + this);
    final GridDhtTxFinishFuture fut = new GridDhtTxFinishFuture<>(cctx, this, false);
    cctx.mvcc().addFuture(fut, fut.futureId());
    IgniteInternalFuture<?> prep = prepFut;
    if (prep == null || prep.isDone()) {
        try {
            if (prep != null)
                prep.get();
        } catch (IgniteCheckedException e) {
            if (log.isDebugEnabled())
                log.debug("Failed to prepare transaction during rollback (will ignore) [tx=" + this + ", msg=" + e.getMessage() + ']');
        }
        fut.finish(false);
    } else
        prep.listen(new CI1<IgniteInternalFuture<?>>() {

            @Override
            public void apply(IgniteInternalFuture<?> f) {
                try {
                    // Check for errors of a parent future.
                    f.get();
                } catch (IgniteCheckedException e) {
                    log.debug("Failed to prepare transaction during rollback (will ignore) [tx=" + this + ", msg=" + e.getMessage() + ']');
                }
                fut.finish(false);
            }
        });
    return fut;
}
Also used : GridDhtTxFinishFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CI1(org.apache.ignite.internal.util.typedef.CI1) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture)

Aggregations

GridDhtTxFinishFuture (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishFuture)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)2 CI1 (org.apache.ignite.internal.util.typedef.CI1)2 GridNearTxFinishFuture (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishFuture)1 IgniteInternalTx (org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx)1 GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)1