Narayana 事务 begin 流程

整体流程

1
2
3
4
5
检查事务状态
获取超时时间
创建事务对象
事务对象设置到 ThreadLocal 中,和当前线程绑定
插入事务测超时时间监控

使用 API

1
2
3
TransactionManager transactionManager = jtaPropertyManager.getJTAEnvironmentBean().getTransactionManager();
// 开启全局事务
transactionManager.begin();

调用链路

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
internal.jta.transaction.arjunacore.BaseTransaction#begin
开启事务
internal.jta.transaction.arjunacore.BaseTransaction#checkTransactionState
校验事务状态
jta.common.JTAEnvironmentBean#isXaTranscactionTimeoutEnabled
是否启用超时配置
internal.jta.transaction.arjunacore.TransactionImple#getTransaction
获取当前线程已经存在的全局事务
arjuna.coordinator.BasicAction#Current
internal.arjuna.thread.ThreadActionData#currentAction
internal.arjuna.thread.ThreadActionData#setup
如果当前事务存在,执行setup操作
arjuna.coordinator.TxControl#createTransactionStatusManager 静态代码块
创建 TransactionStatusManager
arjuna.recovery.TransactionStatusManager#start
启动事务状态管理
arjuna.recovery.TransactionStatusManager#getTsmServerSocket
创建 listener socket
arjuna.recovery.TransactionStatusManager#getListenerHostName
arjuna.common.RecoveryEnvironmentBean#getTransactionStatusManagerAddress
arjuna.utils.Utility#hostNameToInetAddress
arjuna.recovery.TransactionStatusManager#addService
arjuna.common.RecoveryEnvironmentBean#isTimeoutSocket
internal.arjuna.recovery.TransactionStatusManagerItem#createAndSave
创建 status manager item 并序列化保存
arjuna.utils.Utility#getProcessUid
创建 uid,由 hostInetAddr + pid + hash 组成
internal.arjuna.recovery.TransactionStatusManagerItem#saveThis
将 host+port 写出到存储日志
arjuna.state.OutputBuffer#initBuffer
arjuna.utils.Utility#hostInetAddr
arjuna.utils.Utility#getpid
arjuna.common.Uid#generateHash
internal.arjuna.recovery.TransactionStatusManagerItem#save_state
保存状态到磁盘
arjuna.state.OutputBuffer#packString
打包状态到 outputBuffer
internal.arjuna.recovery.TransactionStatusManagerItem#getStore
反射获取存储实例并初始化
internal.arjuna.objectstore.FileSystemStore#write_committed
写出buffer里的状态到文件存储
internal.arjuna.objectstore.FileSystemStore#write_state_internal
internal.arjuna.objectstore.ShadowingStore#write_state
写出状态到磁盘
internal.arjuna.objectstore.FileSystemStore#synchronousWrites
同步写,调用 sync 刷盘
internal.arjuna.objectstore.FileSystemStore#closeAndUnlock
解锁
internal.arjuna.objectstore.FileSystemStore#addToCache
写出结果缓存到内存
new TransactionImple(v)
创建事务对象
arjuna.AtomicAction#begin
开启事务
arjuna.coordinator.TwoPhaseCoordinator#start
arjuna.coordinator.BasicAction#Current
获取当前 BasicAction
arjuna.coordinator.TwoPhaseCoordinator#start
arjuna.coordinator.BasicAction#Begin
BasicAction 开启事务操作
arjuna.StateManager#get_uid
arjuna.coordinator.BasicAction#actionInitialise
arjuna.coordinator.ActionHierarchy#add
arjuna.coordinator.ActionManager#manager
arjuna.coordinator.ActionManager#put
internal.arjuna.thread.ThreadActionData#pushAction
缓存创建的 BasicAction 事务对象 到 当前线程
internal.jta.transaction.arjunacore.TransactionImple#putTransaction
缓存 TransactionImple 到 hashMap,key是uid