Search in sources :

Example 1 with GridDhtTxFinishResponse

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

the class IgniteTxHandler method sendReply.

/**
     * Sends tx finish response to remote node, if response is requested.
     *
     * @param nodeId Node id that originated finish request.
     * @param req Request.
     * @param committed {@code True} if transaction committed on this node.
     * @param nearTxId Near tx version.
     */
private void sendReply(UUID nodeId, GridDhtTxFinishRequest req, boolean committed, GridCacheVersion nearTxId) {
    if (req.replyRequired() || req.checkCommitted()) {
        GridDhtTxFinishResponse res = new GridDhtTxFinishResponse(req.partition(), req.version(), req.futureId(), req.miniId());
        if (req.checkCommitted()) {
            res.checkCommitted(true);
            if (committed) {
                if (req.needReturnValue()) {
                    try {
                        GridCacheReturnCompletableWrapper wrapper = ctx.tm().getCommittedTxReturn(req.version());
                        if (wrapper != null)
                            res.returnValue(wrapper.fut().get());
                        else
                            assert !ctx.discovery().alive(nodeId) : nodeId;
                    } catch (IgniteCheckedException ignored) {
                        if (txFinishMsgLog.isDebugEnabled()) {
                            txFinishMsgLog.debug("Failed to gain entry processor return value. [txId=" + nearTxId + ", dhtTxId=" + req.version() + ", node=" + nodeId + ']');
                        }
                    }
                }
            } else {
                ClusterTopologyCheckedException cause = new ClusterTopologyCheckedException("Primary node left grid.");
                res.checkCommittedError(new IgniteTxRollbackCheckedException("Failed to commit transaction " + "(transaction has been rolled back on backup node): " + req.version(), cause));
            }
        }
        try {
            ctx.io().send(nodeId, res, req.policy());
            if (txFinishMsgLog.isDebugEnabled()) {
                txFinishMsgLog.debug("Sent dht tx finish response [txId=" + nearTxId + ", dhtTxId=" + req.version() + ", node=" + nodeId + ", checkCommitted=" + req.checkCommitted() + ']');
            }
        } catch (Throwable e) {
            // Double-check.
            if (ctx.discovery().node(nodeId) == null) {
                if (txFinishMsgLog.isDebugEnabled()) {
                    txFinishMsgLog.debug("Node left while send dht tx finish response [txId=" + nearTxId + ", dhtTxId=" + req.version() + ", node=" + nodeId + ']');
                }
            } else {
                U.error(log, "Failed to send finish response to node [txId=" + nearTxId + ", dhtTxId=" + req.version() + ", nodeId=" + nodeId + ", res=" + res + ']', e);
            }
            if (e instanceof Error)
                throw (Error) e;
        }
    } else {
        if (txFinishMsgLog.isDebugEnabled()) {
            txFinishMsgLog.debug("Skip send dht tx finish response [txId=" + nearTxId + ", dhtTxId=" + req.version() + ", node=" + nodeId + ']');
        }
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridDhtTxFinishResponse(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishResponse) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) GridCacheReturnCompletableWrapper(org.apache.ignite.internal.processors.cache.GridCacheReturnCompletableWrapper) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)1 GridCacheReturnCompletableWrapper (org.apache.ignite.internal.processors.cache.GridCacheReturnCompletableWrapper)1 GridDhtTxFinishResponse (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishResponse)1 IgniteTxRollbackCheckedException (org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException)1