Narayana 事务回滚流程
当用户手动调用 connection.rollback() 回滚当前全局事务时,会走如下流程。
总体流程
遍历每个 resource执行 xa end;执行 xa rollback;
清理缓存
使用
TransactionManager transactionManager = jtaPropertyManager.getJTAEnvironmentBean().getTransactionManager();
// 开启事务
transactionManager.begin();
// 执行 sql 语句
// ...
// 回滚事务
transactionManager.rollback();
调用链路
com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#rollbackcom.arjuna.ats.arjuna.coordinator.BasicAction#status获取当前事务状态com.arjuna.ats.arjuna.AtomicAction#cancel回滚流程com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator#cancelcom.arjuna.ats.arjuna.coordinator.BasicAction#parentcom.arjuna.ats.arjuna.coordinator.BasicAction#Abort回滚流程com.arjuna.ats.arjuna.coordinator.BasicAction#checkIsCurrentcom.arjuna.ats.arjuna.coordinator.BasicAction#checkChildrencom.arjuna.ats.arjuna.coordinator.BasicAction#doAbortcom.arjuna.ats.arjuna.coordinator.RecordList#getFront遍历 record list 里的 resource 依次回滚com.arjuna.ats.arjuna.coordinator.AbstractRecord#getNextcom.arjuna.ats.arjuna.coordinator.BasicAction#doAbortresource1 执行回滚com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord#toStringcom.arjuna.ats.jta.xa.XidImple#toStringcom.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord#topLevelAbortcom.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord#toStringcom.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#getXAResourceStatecom.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord#endAssociationcom.arjuna.ats.jta.xa.XidImple#toStringcom.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#toStringcom.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction#toStringcom.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#toStringcom.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#endAssociationcom.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#getXAResourceStatecom.arjuna.ats.internal.jta.xa.TxInfo#getStatecom.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#doEndcom.zc.transaction.xa.SingleXACtrlResource#end执行 xa end 操作com.arjuna.ats.jta.xa.XidImple#getGlobalTransactionIdcom.arjuna.ats.jta.xa.XidImple#getBranchQualifiercom.arjuna.ats.jta.xa.XidImple#getFormatIdcom.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#setXAResourceStatecom.arjuna.ats.internal.jta.xa.TxInfo#setStatecom.zc.transaction.xa.SingleXACtrlResource#rollback执行 xa rollback 操作com.arjuna.ats.jta.xa.XidImple#toStringcom.arjuna.ats.jta.xa.XidImple#getGlobalTransactionIdcom.arjuna.ats.jta.xa.XidImple#getBranchQualifiercom.arjuna.ats.jta.xa.XidImple#getFormatIdcom.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord#removeConnectioncom.arjuna.ats.arjuna.coordinator.BasicAction#updateHeuristiccom.arjuna.ats.arjuna.StateManager#get_uidcom.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord#ordercom.arjuna.common.internal.util.propertyservice.BeanPopulator#getDefaultInstancecom.arjuna.ats.arjuna.common.CoreEnvironmentBean#getNodeIdentifiercom.arjuna.ats.arjuna.coordinator.BasicAction#doAbortresource2 执行回滚com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord#topLevelAbortresource2 执行相同的 xa end + xa rollback 操作com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#getXAResourceStatecom.arjuna.ats.internal.jta.xa.TxInfo#getStatecom.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord#endAssociationcom.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#endAssociationcom.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#getXAResourceStatecom.arjuna.ats.internal.jta.xa.TxInfo#getStatecom.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#doEndcom.zc.transaction.xa.SingleXACtrlResource#end执行xa endcom.zc.transaction.xa.SingleXACtrlResource#rollback执行 xa rollback......com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord#removeConnectioncom.arjuna.ats.arjuna.coordinator.BasicAction#updateHeuristiccom.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator#afterCompletioncom.arjuna.ats.arjuna.coordinator.TransactionReaper#transactionReapercom.arjuna.ats.arjuna.coordinator.TransactionReaper#remove事务超时监控缓存清理com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#removeTransaction事务缓存清理