当前位置:网站首页>2pc of distributed transaction solution
2pc of distributed transaction solution
2022-07-07 05:40:00 【Qin Tian】
Catalog
3、 ... and 、2pc Solution Seata
2、Seata The implementation process of
Four 、Seata With the traditional 2PC difference
XA It's a distributed transaction protocol , from Tuxedo Put forward .XA It's roughly divided into two parts : Transaction manager and local resource manager . The local resource manager is usually implemented by database , such as Oracle、DB2 These commercial databases are all implemented XA Interface , The transaction manager is the global scheduler , Responsible for the submission and rollback of local resources .
One 、 What is? 2PC
2PC I.e. two phase submission agreement , The whole transaction process is divided into two stages , Preparation stage (Prepare phase)、 Submission phase (commit phase),2 It means two stages ,P It means the preparation stage ,C It's the submission phase .
- Preparation stage (Prepare phase): The transaction manager sends... To each participant Prepare news , Each database participant performs transactions locally , And write the local Undo/Redo journal , The transaction is not committed at this time .(Undo Log is to record the data before modification , For database rollback ,Redo Log is to record the modified data , Used to write data files after committing transactions );
- Submission phase (commit phase): If the transaction manager receives an execution failure or timeout message from the participant , Send a rollback directly to each participant (Rollback) news ; otherwise , Send submit (Commit) news ; The participant performs commit or rollback operations according to the instructions of the transaction manager , And release the lock resources used in transaction processing .
Be careful : Lock resources must be released at the last stage .
Successful cases :
failures :
Two 、2pc Solution XA
2PC Two phase submission , Also known as XA Transactions,MySQL from 5.5 Version starting support ,SQL Server 2005 Start supporting ,Oracle 7 Start supporting , Its advantage is consistency , The disadvantage is reduced availability .
2PC Of The traditional solution is at the database level Realized , Such as Oracle、MySQL All support 2PC agreement , In order to unify standards and reduce unnecessary docking costs in the industry , Standardized processing models and interface standards need to be developed , International Open Standards Organization Open Group The distributed transaction processing model is defined DTP(Distributed Transaction Processing Reference Model).
Whole 2PC There are three roles involved in the transaction flow of AP、RM、TM.
AP Refers to the use of 2PC Applications for distributed transactions ;
RM refer to Explorer , It controls branch transactions ;
TM refer to Transaction manager , It controls the whole global transaction .
1、 stay Preparation stage RM Perform actual business operations , But don't commit the transaction , Resource locking ;
2、 stay Submission phase TM Will accept RM In the preparation stage of the implementation of the reply , As long as there is any one RM Execution failure ,TM Will inform all RM Perform a rollback operation , otherwise ,TM All will be informed RM Commit the transaction . Commit phase end resource lock release .
XA The problem of the plan :
- Need local database support XA agreement .
- The resource lock needs to wait until the end of two phases to release , Poor performance .
3、 ... and 、2pc Solution Seata
1、seata Design idea
Seata One of the design goals is to be non intrusive to the business , Therefore, there is no invasion from the business 2PC The plan begins , In tradition 2PC On the basis of evolution , And solve 2PC The problem with the program .
Seata hold A distributed transaction is understood as a global transaction containing several branch transactions . The responsibility of the global affairs is to coordinate the branch affairs under its jurisdiction to reach an agreement , Or submit it together successfully , Or fail to roll back together . Besides , Usually the branch transaction itself is a local transaction of a relational database , The diagram below shows the relationship between global transaction and branch transaction :
With the traditional 2PC The model of is similar to ,Seata Defined 3 A component to protocol the processing of distributed transactions :
- ransaction Coordinator (TC): Transaction coordinator , It's independent middleware , need Independent deployment function , It maintains the running state of global transactions , receive TM Instruction initiate global transaction commit and rollback , Responsible for working with RM Communication coordinates the commit or rollback of individual branch transactions .
- Transaction Manager (TM): Transaction manager ,TM Need to work embedded in the application , It is responsible for Start a global transaction , And finally to TC An instruction to initiate a global commit or global rollback .
- Resource Manager (RM): Control branch transactions , Responsible for branch registration 、 Status report , And receive the transaction coordinator TC Instructions , Drive branch ( Local ) Transaction commit and rollback .
2、Seata The implementation process of
(1) User service TM towards TC Request to open a global transaction , The global transaction is created successfully and Generate a globally unique XID.
(2) User service RM towards TC register Branch business , The branch transaction performs the new user logic in the user service , And include it in XID Jurisdiction corresponding to global transaction .
(3) The user service performs branch transactions , Insert a record into the user table .
(4) When the logic is executed to call the integration service remotely ( XID Propagate in the context of the microservice call link ). Points service RM towards TC Register branch transactions , This branch transaction performs the logic of increasing integral , And include it in XID Jurisdiction corresponding to global transaction .
(5) The points service performs branch transactions , Insert a record into the score sheet , After execution , Return to user service .
(6) User service branch transaction execution completed .
(7) TM towards TC Launch against XID The global commit or rollback resolution for .
(8) TC Dispatch XID All branch affairs under the jurisdiction of Complete the commit or rollback request .
Four 、Seata With the traditional 2PC difference
1、 Architecture level , Tradition 2PC Of the plan RM It's actually in the Database layer ,RM Essentially, it's the database itself , adopt XA Protocol implementation , and Seata Of RM In order to jar The package is deployed as the middleware layer On the application side .
2、 Two phase submission , Tradition 2PC No matter the resolution of the second stage is commit still rollback, The locks of transactional resources should be kept to Phase2 Release when finished . and Seata The way to do this is to Phase1 Commit local transaction , So we can save it Phase2 Time to hold lock , whole Increase of efficiency .
边栏推荐
- [paper reading] semi supervised left atrium segmentation with mutual consistency training
- Use, configuration and points for attention of network layer protocol (taking QoS as an example) when using OPNET for network simulation
- Vector and class copy constructors
- Differences and introduction of cluster, distributed and microservice
- Make web content editable
- 常用消息队列有哪些?
- Where is NPDP product manager certification sacred?
- Jhok-zbg2 leakage relay
- The navigation bar changes colors according to the route
- JVM(十九) -- 字节码与类的加载(四) -- 再谈类的加载器
猜你喜欢
[JS component] custom select
《2022中国低/无代码市场研究及选型评估报告》发布
Digital innovation driven guide
Phenomenon analysis when Autowired annotation is used for list
Dj-zbs2 leakage relay
[论文阅读] Semi-supervised Left Atrium Segmentation with Mutual Consistency Training
Use, configuration and points for attention of network layer protocol (taking QoS as an example) when using OPNET for network simulation
集群、分布式、微服务的区别和介绍
Cve-2021-3156 vulnerability recurrence notes
sql查询:将下一行减去上一行,并做相应的计算
随机推荐
bat 批示处理详解
AIDL 与Service
Writing process of the first paper
1.AVL树:左右旋-bite
Flink SQL realizes reading and writing redis and dynamically generates hset key
"Multimodal" concept
淘宝商品详情页API接口、淘宝商品列表API接口,淘宝商品销量API接口,淘宝APP详情API接口,淘宝详情API接口
一条 update 语句的生命经历
SAP ABAP BDC(批量数据通信)-018
How Alibaba cloud's DPCA architecture works | popular science diagram
JVM(十九) -- 字节码与类的加载(四) -- 再谈类的加载器
The 2022 China low / no code Market Research and model selection evaluation report was released
高级程序员必知必会,一文详解MySQL主从同步原理,推荐收藏
集群、分布式、微服务的区别和介绍
Life experience of an update statement
MySQL数据库学习(7) -- pymysql简单介绍
High voltage leakage relay bld-20
Design, configuration and points for attention of network arbitrary source multicast (ASM) simulation using OPNET
JVM (XX) -- performance monitoring and tuning (I) -- Overview
[reading of the paper] a multi branch hybrid transformer network for channel terminal cell segmentation