Narayana事务回滚流程

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#rollback
    com.arjuna.ats.arjuna.coordinator.BasicAction#status
    获取当前事务状态
    com.arjuna.ats.arjuna.AtomicAction#cancel
    回滚流程
        com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator#cancel
            com.arjuna.ats.arjuna.coordinator.BasicAction#parent
            com.arjuna.ats.arjuna.coordinator.BasicAction#Abort
            回滚流程
                com.arjuna.ats.arjuna.coordinator.BasicAction#checkIsCurrent
                com.arjuna.ats.arjuna.coordinator.BasicAction#checkChildren
                com.arjuna.ats.arjuna.coordinator.BasicAction#doAbort
                    com.arjuna.ats.arjuna.coordinator.RecordList#getFront
                    遍历 record list 里的 resource 依次回滚
                        com.arjuna.ats.arjuna.coordinator.AbstractRecord#getNext
                    com.arjuna.ats.arjuna.coordinator.BasicAction#doAbort
                    resource1 执行回滚
                        com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord#toString
                            com.arjuna.ats.jta.xa.XidImple#toString
                        com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord#topLevelAbort
                            com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord#toString
                            com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#getXAResourceState
                            com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord#endAssociation
                                com.arjuna.ats.jta.xa.XidImple#toString
                                com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#toString
                                com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction#toString
                                com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#toString
                                com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#endAssociation
                                    com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#getXAResourceState
                                        com.arjuna.ats.internal.jta.xa.TxInfo#getState
                                    com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#doEnd
                                        com.zc.transaction.xa.SingleXACtrlResource#end
                                        执行 xa end 操作
                                            com.arjuna.ats.jta.xa.XidImple#getGlobalTransactionId
                                            com.arjuna.ats.jta.xa.XidImple#getBranchQualifier
                                            com.arjuna.ats.jta.xa.XidImple#getFormatId
                                        com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#setXAResourceState
                                            com.arjuna.ats.internal.jta.xa.TxInfo#setState
                            com.zc.transaction.xa.SingleXACtrlResource#rollback
                            执行 xa rollback 操作
                                com.arjuna.ats.jta.xa.XidImple#toString
                                com.arjuna.ats.jta.xa.XidImple#getGlobalTransactionId
                                com.arjuna.ats.jta.xa.XidImple#getBranchQualifier
                                com.arjuna.ats.jta.xa.XidImple#getFormatId
                            com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord#removeConnection
                        com.arjuna.ats.arjuna.coordinator.BasicAction#updateHeuristic
                        com.arjuna.ats.arjuna.StateManager#get_uid
                        com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord#order
                            com.arjuna.common.internal.util.propertyservice.BeanPopulator#getDefaultInstance
                        com.arjuna.ats.arjuna.common.CoreEnvironmentBean#getNodeIdentifier
                    com.arjuna.ats.arjuna.coordinator.BasicAction#doAbort
                    resource2 执行回滚
                        com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord#topLevelAbort
                            resource2 执行相同的 xa end + xa rollback 操作
                            com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#getXAResourceState
                                com.arjuna.ats.internal.jta.xa.TxInfo#getState
                            com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord#endAssociation
                                com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#endAssociation
                                    com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#getXAResourceState
                                        com.arjuna.ats.internal.jta.xa.TxInfo#getState
                                    com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#doEnd
                                        com.zc.transaction.xa.SingleXACtrlResource#end
                                        执行xa end
                            com.zc.transaction.xa.SingleXACtrlResource#rollback
                            执行 xa rollback
                            ......
                            com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord#removeConnection
                        com.arjuna.ats.arjuna.coordinator.BasicAction#updateHeuristic
            com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator#afterCompletion
        com.arjuna.ats.arjuna.coordinator.TransactionReaper#transactionReaper
        com.arjuna.ats.arjuna.coordinator.TransactionReaper#remove
        事务超时监控缓存清理
    com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple#removeTransaction
    事务缓存清理

你可能感兴趣的:(Transaction,java,transaction,分布式事务,Narayana实现,分布式事务源码,Narayana)