一开始io.seata.tm.api.TransactionalTemplate#beginTransaction,向seata申请xid,执行完之后,global_table
然后执行
jdbcTemplate.update("update buy_flow_require set create_org_name=? where id=14034",name);
先去执行本地sql,io.seata.rm.datasource.exec.AbstractDMLBaseExecutor#executeAutoCommitFalse,然后执行prepareUndoLog生成undo_log
最后执行connectionProxy.commit();,先去register,带着xid向seata申请branch_id
向seata注册申请branch_id后
然后flushUnDoLogs,写入undo_log,并且undo_log和本地sql一起提交
最后提交全局事务,向seate发起rpc请求
最后seata向所有的rm发启动提交事务请求(删除undo_log)
rm收到了请求
向ASYNC_COMMIT_BUFFER放一个Phase2Context
io.seata.rm.datasource.AsyncWorker会异步从ASYNC_COMMIT_BUFFER队列poll,
然后删除undo_log
如果是回滚分支的话,他是同步操作,不会像commit那样(把向ASYNC_COMMIT_BUFFER放一个Phase2Context,然后response给TC,使得TC删除global_table,branch_table,lock_table,然后异步删除undo_log),而是等本地回滚成功后在向TC响应
可以参考: