Narayana 事务恢复流程

总体流程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
恢复线程轮询
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:
再次尝试进行恢复

调用链路

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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