二、branch transaction
2022-05-17 20:19:09 2 举报
AI智能生成
seata源码解析--分支事务注册、提交、回滚
作者其他创作
大纲/内容
springboot自动配置类SeataAutoConfiguration
RM添加如下配置:seata:
enabled: true
enable-auto-data-source-proxy: true
enabled: true
enable-auto-data-source-proxy: true
SeataDataSourceBeanPostProcessor
该类实现接口BeanPostProcessor
实现方法postProcessAfterInitialization,对原生的DataSOurce生成代理类:DataSourceProxy
SeataDataSourceBeanPostProcessor#proxyDataSource(Object originBean),改方法中生成一个数据源的代理类:DataSourceProxy,并缓存到dataSourceProxyMap中
DataSourceProxy
继承类AbstractDataSourceProxy
实现接口DataSource
实现接口Resource
getConnection(String username, String password),返回对象:ConnectionProxy
ConnectionProxy#ConnectionProxy(DataSourceProxy dataSourceProxy, Connection targetConnection)
AbstractConnectionProxy#AbstractConnectionProxy(DataSourceProxy dataSourceProxy, Connection targetConnection)
AbstractConnectionProxy#createStatement()
StatementProxy
AbstractConnectionProxy#prepareStatement(String sql)
PreparedStatementProxy
ConnectionProxy#commit(),提交事务
ConnectionProxy#doCommit()
// 在全局事务中,执行全局事务提交
ConnectionProxy# processGlobalTransactionCommit();
ConnectionProxy# processGlobalTransactionCommit();
ConnectionProxy#register():
ConnectionProxy#recognizeLockKeyConflictException(TransactionException te, String lockKeys)recognizeLockKeyConflictException(TransactionException te, String lockKeys)
持久化前置镜像、后置镜像
AbstractUndoLogManager#flushUndoLogs(ConnectionProxy cp)
protected abstract void insertUndoLogWithNormal(String xid, long branchId, String rollbackCtx, byte[] undoLogContent,
Connection conn) throws SQLException;
抽象方法,由子类实现
Connection conn) throws SQLException;
抽象方法,由子类实现
ConnectionProxy#report(boolean commitDone)
AbstractResourceManager#branchReport(BranchType branchType, String xid, long branchId, BranchStatus status, String applicationData)使用RmRpcClient向TC服务端
// 获取到了全局锁
ConnectionProxy#processLocalCommitWithGlobalLocks();
ConnectionProxy#processLocalCommitWithGlobalLocks();
// 普通事务提交
ConnectionProxy#targetConnection.commit();
ConnectionProxy#targetConnection.commit();
DataSourceProxy dataSourceProxy = DataSourceProxyHolder.get().putDataSource((DataSource) originBean);
DataSourceProxyHolder#putDataSource(DataSource dataSource)
return this.dataSourceProxyMap.computeIfAbsent(dataSource, DataSourceProxy::new);
调用父类的构造方法AbstractDataSourceProxy#DataSourceProxy(DataSource targetDataSource, String resourceGroupId)
调用父类构造方法:AbstractDataSourceProxy#AbstractDataSourceProxy(DataSource targetDataSource)
DataSourceProxy#init(DataSource dataSource, String resourceGroupId)
实习方法postProcessBeforeInitialization
收藏
收藏
0 条评论
下一页