当前位置:网站首页>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 .
边栏推荐
- DOM node object + time node comprehensive case
- Web Authentication API兼容版本信息
- CVE-2021-3156 漏洞复现笔记
- The year of the tiger is coming. Come and make a wish. I heard that the wish will come true
- Use Zhiyun reader to translate statistical genetics books
- Make web content editable
- 消息队列:如何确保消息不会丢失
- 【oracle】简单的日期时间的格式化与排序问题
- 判断文件是否为DICOM文件
- How does mapbox switch markup languages?
猜你喜欢
什么是依赖注入(DI)
[JS component] custom select
得物客服一站式工作台卡顿优化之路
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
[论文阅读] Semi-supervised Left Atrium Segmentation with Mutual Consistency Training
《4》 Form
【js组件】自定义select
How Alibaba cloud's DPCA architecture works | popular science diagram
[paper reading] semi supervised left atrium segmentation with mutual consistency training
The 2022 China low / no code Market Research and model selection evaluation report was released
随机推荐
《5》 Table
Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting
Simple case of SSM framework
《4》 Form
拼多多商品详情接口、拼多多商品基本信息、拼多多商品属性接口
Unity让摄像机一直跟随在玩家后上方
论文阅读【Semantic Tag Augmented XlanV Model for Video Captioning】
Two person game based on bevy game engine and FPGA
消息队列:消息积压如何处理?
DOM node object + time node comprehensive case
拼多多新店如何获取免费流量,需要从哪些环节去优化,才能有效提升店内免费流量
Preliminary practice of niuke.com (9)
Educational Codeforces Round 22 B. The Golden Age
How does mapbox switch markup languages?
Taobao commodity details page API interface, Taobao commodity list API interface, Taobao commodity sales API interface, Taobao app details API interface, Taobao details API interface
Lombok插件
Lombok plug-in
Leetcode 1189 maximum number of "balloons" [map] the leetcode road of heroding
Design, configuration and points for attention of network specified source multicast (SSM) simulation using OPNET
How can project managers counter attack with NPDP certificates? Look here