Narayana事务恢复流程

Narayana 事务恢复流程

总体流程

恢复线程轮询
1.判断是否有任务要处理
2.若有任务要处理,则处理
    1.获取所有配置的 recovery modules
    2.遍历recovery modules,执行一阶段处理
        XARecoveryModule: 
            执行 XA recovery 命令从 RM 中获取 prepare 状态的 XID 数组并缓存
        AtomicActionRecoveryModule:
            从事务日志中,获取需要恢复的 XID 数组并缓存
    3.遍历recovery modules,执行二阶段处理
        AtomicActionRecoveryModule:
            1.根据状态判断是否需要执行二阶段的 commit 或 rollback
            2.清理事务 recovery 日志
        XARecoveryModule:
            再次尝试进行恢复

调用链路

com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery#run
    com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery#doInitialWait
    恢复线程启动的 delay 时间
    com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery#setStatus
    设置为 SCANNING 状态
    com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery#doWorkInternal
        com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery#getModules
        获取并遍历配置的恢复模块
        com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery#switchClassLoader
        设置上下文类加载器为RecoveryModule的classLoader,执行完毕再reset回来
        com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule#periodicWorkFirstPass
        AtomicActionRecoveryModule 第一阶段恢复
            com.arjuna.ats.arjuna.common.Uid#nullUid
            创建 Null Uid
            com.arjuna.ats.arjuna.objectstore.ObjectStore#allObjUids
            加载 /StateManager/BasicAction/TwoPhaseCoordinator/AtomicAction 下的所有 uids
                com.arjuna.ats.internal.arjuna.objectstore.FileSystemStore#allObjUids
                    com.arjuna.ats.internal.arjuna.objectstore.FileSystemStore#allObjUidsInternal
                        遍历日志文件,根据日志文件名序列化 uids
                        com.arjuna.ats.arjuna.state.InputObjectState#toString
                        com.arjuna.ats.arjuna.state.OutputBuffer#initBuffer
                        com.arjuna.ats.arjuna.utils.Utility#hostInetAddr
                        com.arjuna.ats.arjuna.utils.Utility#getpid
                            com.arjuna.ats.arjuna.utils.Utility#getProcess
                            com.arjuna.ats.internal.arjuna.utils.SocketProcessId#getpid
                        com.arjuna.ats.arjuna.common.Uid#getValue
                        com.arjuna.ats.arjuna.common.Uid#generateHash
                        com.arjuna.ats.arjuna.common.Uid#valid
                        com.arjuna.ats.internal.arjuna.objectstore.FileSystemStore.FileFilter#accept
                        过滤出目录下的所有日志文件
                        com.arjuna.ats.internal.arjuna.common.UidHelper#packInto
                        uid打包到outputBuffer里
                            com.arjuna.ats.arjuna.common.Uid#getBytes
                            com.arjuna.ats.arjuna.state.OutputBuffer#packBytes
                                com.arjuna.ats.arjuna.state.OutputBuffer#packInt
                                com.arjuna.ats.arjuna.state.OutputBuffer#realign
                        com.arjuna.ats.arjuna.state.OutputBuffer#buffer
                        com.arjuna.ats.arjuna.state.InputBuffer#setBuffer
                        将 OutputBuffer 设置到 InputBuffer 里
                            com.arjuna.ats.arjuna.state.InputBuffer#skipHeader
            com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule#processTransactions
            处理事务
                com.arjuna.ats.internal.arjuna.common.UidHelper#unpackFrom
                遍历 OutputBuffer,反序列化出 uids
                    com.arjuna.ats.arjuna.state.InputBuffer#unpackBytes
                        com.arjuna.ats.arjuna.state.InputBuffer#unpackInt
                        com.arjuna.ats.arjuna.state.InputBuffer#realign
                    com.arjuna.ats.arjuna.common.Uid#generateHash
        com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery#restoreClassLoader
        恢复线程上下文类加载器
        com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery#switchClassLoader
        com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule#periodicWorkFirstPass
        XARecoveryModule一阶段恢复
            com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule#periodicWorkFirstPass
                com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule#getScanState
                com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryResourceManagerImple#type
                com.arjuna.ats.arjuna.objectstore.ObjectStore#allObjUids
                com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule#resourceInitiatedRecovery
                com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule#resourceInitiatedRecoveryForRecoveryHelpers
                    transaction.xa.narayana.manager.DataSourceXAResourceRecoveryHelper#getXAResources
                        transaction.xa.narayana.manager.DataSourceXAResourceRecoveryHelper#connect
                            transaction.xa.narayana.manager.DataSourceXAResourceRecoveryHelper#getXaConnection
                            获取 xa connection
                com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule#xaRecoveryFirstPass
                执行 xa recovery 语句
                    com.arjuna.ats.internal.jta.recovery.arjunacore.NameScopedXAResource#getXaResource
                    transaction.xa.narayana.manager.DataSourceXAResourceRecoveryHelper#recover
                    com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule#getXidLogInfo
        com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery#restoreClassLoader
        com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery#doBackoffWait
        com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery#switchClassLoader
        com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule#periodicWorkSecondPass
        AtomicActionRecoveryModule 二阶段恢复
            com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule#processTransactionsStatus
            获取当前要恢复的事务状态
                com.arjuna.ats.internal.arjuna.objectstore.ShadowingStore#currentState
                    com.arjuna.ats.internal.arjuna.objectstore.ShadowingStore#genPathName
                    com.arjuna.ats.internal.arjuna.objectstore.FileSystemStore#exists
                        com.arjuna.ats.internal.arjuna.objectstore.FileSystemStore#addToCache
                    com.arjuna.ats.arjuna.objectstore.StateStatus#stateStatusString
                com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule#doRecoverTransaction
                事务恢复
                    com.arjuna.ats.arjuna.recovery.TransactionStatusConnectionManager#getTransactionStatus
                        com.arjuna.ats.arjuna.recovery.TransactionStatusConnectionManager#getRemoteTransactionStatus
                        com.arjuna.ats.arjuna.objectstore.StoreManager#getRecoveryStore
                            com.arjuna.ats.arjuna.objectstore.StoreManager#getActionStore
                        com.arjuna.ats.arjuna.recovery.ActionStatusService#getTransactionStatus
                            com.arjuna.ats.arjuna.common.Uid#generateHash
                            com.arjuna.ats.arjuna.recovery.ActionStatusService#getActionStatus
                                com.arjuna.ats.arjuna.coordinator.ActionManager#manager
                                com.arjuna.ats.arjuna.coordinator.ActionManager#get
                                    com.arjuna.ats.arjuna.common.Uid#hashCode
                                com.arjuna.ats.arjuna.recovery.ActionStatusService#getObjectStoreStatus
                                    com.arjuna.ats.internal.arjuna.objectstore.ShadowingStore#currentState
                                        com.arjuna.ats.internal.arjuna.objectstore.ShadowingStore#genPathName
                                            com.arjuna.ats.internal.arjuna.objectstore.FileSystemStore#genPathName
                                                com.arjuna.ats.internal.arjuna.objectstore.FileSystemStore#getStoreName
                                                com.arjuna.ats.arjuna.objectstore.ObjectStore#locateStore
                                                com.arjuna.ats.arjuna.common.Uid#fileStringForm
                                        com.arjuna.ats.arjuna.objectstore.StateStatus#stateStatusString
                                        从文件存储中获取事务状态
                    com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule#isTransactionInMidFlight
                    根据事务状态判断是否需要进行恢复
                    com.arjuna.ats.arjuna.coordinator.ActionStatus#stringForm
                    com.arjuna.ats.internal.arjuna.coordinator.CheckedActionFactoryImple#getCheckedAction
                    com.arjuna.ats.arjuna.coordinator.BasicAction#activate
                    com.arjuna.ats.arjuna.recovery.RecoverAtomicAction#replayPhase2
                    执行二阶段恢复
                        com.arjuna.ats.arjuna.StateManager#get_uid
                        com.arjuna.ats.arjuna.coordinator.BasicAction#phase2Commit
                        执行二阶段 commit 流程
                        com.arjuna.ats.arjuna.StateManager#get_uid
                        com.arjuna.ats.arjuna.common.Uid#toString
                            com.arjuna.ats.arjuna.common.Uid#stringForm
        com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery#restoreClassLoader
        com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery#switchClassLoader
        com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule#periodicWorkSecondPass
        XARecoveryModule 执行二阶段恢复
            com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule#getScanState
            com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule#transactionInitiatedRecovery
            com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule#bottomUpRecovery
                com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule#xaRecoverySecondPass
                    com.arjuna.ats.internal.jta.recovery.arjunacore.NameScopedXAResource#getXaResource
                    transaction.xa.narayana.manager.DataSourceXAResourceRecoveryHelper#recover
                        transaction.xa.narayana.manager.DataSourceXAResourceRecoveryHelper#getDelegate
                        transaction.xa.narayana.manager.DataSourceXAResourceRecoveryHelper#disconnect
                com.arjuna.ats.internal.jta.recovery.arjunacore.RecoveryXids#isStale
                    com.arjuna.ats.internal.jta.recovery.arjunacore.NameScopedXAResource#toString
            com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule#clearAllFailures
            com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule#setScanState
                com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule#getScanState
                    com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule.ScanStates#values
        com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery#restoreClassLoader

你可能感兴趣的:(Transaction,java,数据库,Narayana,分布式事务,Narayana源码,Narayana恢复)