当前位置:网站首页>Seata两阶段提交AT详解
Seata两阶段提交AT详解
2022-07-26 04:57:00 【知识浅谈】
Seata两阶段提交
和传统2PC的模型类似,Seata定义了3个组件来协调分布式事务的处理过程
- Transaction Coordinator(TC):事务协调器,它是独立的中间件,需要独立部署运行,它维护全局事务的运行状态,接收TM指令发起的提交与回滚,负责与RM通信协调各各分支事务的提交或回滚。
- Transaction Manager(TM):事务管理器,TM需要嵌入和应用程序中工作,它负责开启一个全局事务,并最终向TC发起全局提交或全局回滚的指令。
- Resource Manager(RM):控制分支事务,负责分支注册,状态汇报,并接收事务协调器TC的指令,驱动分支(本地)事务的提交和回滚。
两阶段提交协议的演变:
一阶段:业务数据和回滚日志记录在同一个本地事务中提交,释放本地锁和连接资源。
二阶段:
提交异步化,非常快速地完成。
回滚通过一阶段的回滚日志进行反向补偿
新用户注册送积分列举Seata的分布式事务过程:

具体的执行流程如下:
1.用户服务的TM向TC申请开启一个全局事务,全局事务创建成功生成一个全局唯一的XID。
2.用户服务的RM向TC注册 分支事务,该分支事务在用户服务执行新增用户逻辑,并将其纳入XID对应全局事务的管辖。
3.用户服务执行分支事务,向用户表插入一条记录。
4.逻辑执行到远程调用积分服务时(XID在微服务调用链路的上下文中传播)。积分服务的RM向TC注册分支事务,该分支事务执行增加积分的逻辑,并将其纳入XID对应全局事务的管辖。
5.积分服务执行分支事务,向积分记录表插入一条记录,执行完毕后,返回用户服务。
6.用户服务分支事务执行完毕。
7.TM向TC发起针对XID的全局提交或回滚决议。
8.TC调度XID下管辖的全部分支事务完成提交或回滚事务请求。
Seata实现2PC与传统2PC的差别
- 架构层次方面,传统2PC方案的RM实际上是在数据库层,RM本质上就是数据库自身,通过XA协议实现,而Seata的RM是以jar包的形式作为中间件层部署在应用程序这一侧的。
- 两阶段提交方面,传统2PC无论第二阶段的决议是commit还是rollback,事务性资源的锁都要保持到Phase2完成才释放。而Seata的做法是在Phase1就将本地事务提交,这样可以省去Phase2持锁的时间,整体提高效率。
边栏推荐
猜你喜欢

AXI协议(5):AXI协议的burst机制

To study the trend of open source and gain insight into the future of the industry, stonedb community and the China Academy of communications and communications released the Research Report on the dev

UE4 displays text when it is close to the object, and disappears when it is far away

Authentication Encyclopedia (cookies, sessions, tokens, JWT, single sign on), in-depth understanding and understanding of authentication

Kubernetes advanced training camp scheduler

Array sort 2

UE4 switching of control rights of multiple roles

Spark Structured Streaming HelloWorld

Working principle and application of fast recovery diode

vector详解和迭代器失效问题
随机推荐
【语义分割】2018-DeeplabV3+ ECCV
Have you known several distribution methods of NFT? What are the advantages and disadvantages of different distribution methods?
webassembly 01基本资料
Autocomplete prevents the form from automatically filling in
Switch and router technology: dynamic routing protocol, rip routing protocol and OSPF routing protocol
Niuke-top101-bm32
Sliding window -- leetcode solution
data warehouse
Good at C (summer vacation daily question 6)
Yapi installation
[300 + selected interview questions from big companies continued to share] big data operation and maintenance sharp knife interview question column (VIII)
What points should be paid attention to in the selection of project management system?
Icml2022 | imitation learning by evaluating the professional knowledge of the presenter
3、 @requestmapping annotation
2022 Henan Mengxin League game (3): Henan University J - magic number
2022杭电多校第二场 A.Static Query on Tree(树剖)
Stm32fsmc extended SRAM
9、 File upload and download
Character function and string function (I)
What are the demand management software for small and medium-sized enterprises