当前位置:网站首页>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 .
边栏推荐
- Mybaits multi table query (joint query, nested query)
- Digital innovation driven guide
- Cve-2021-3156 vulnerability recurrence notes
- Leetcode: maximum number of "balloons"
- Taobao store release API interface (New), Taobao oauth2.0 store commodity API interface, Taobao commodity release API interface, Taobao commodity launch API interface, a complete set of launch store i
- 论文阅读【Semantic Tag Augmented XlanV Model for Video Captioning】
- [JS component] custom select
- Mybaits之多表查询(联合查询、嵌套查询)
- Batch size setting skills
- SAP webservice 测试出现404 Not found Service cannot be reached
猜你喜欢
Paper reading [MM21 pre training for video understanding challenge:video captioning with pre training techniqu]
[PM products] what is cognitive load? How to adjust cognitive load reasonably?
[JS component] date display.
集群、分布式、微服务的区别和介绍
Getting started with DES encryption
什么是消息队列?
基于 hugging face 预训练模型的实体识别智能标注方案:生成doccano要求json格式
What is dependency injection (DI)
Leakage relay jd1-100
Mysql database learning (8) -- MySQL content supplement
随机推荐
Where is NPDP product manager certification sacred?
消息队列:如何确保消息不会丢失
说一说MVCC多版本并发控制器?
[JS component] custom select
判断文件是否为DICOM文件
[binary tree] binary tree path finding
Mysql database learning (7) -- a brief introduction to pymysql
Make web content editable
Flinksql 读写pgsql
JVM (19) -- bytecode and class loading (4) -- talk about class loader again
Most commonly used high number formula
[PM products] what is cognitive load? How to adjust cognitive load reasonably?
Flink SQL realizes reading and writing redis and dynamically generates hset key
[论文阅读] Semi-supervised Left Atrium Segmentation with Mutual Consistency Training
拼多多新店如何获取免费流量,需要从哪些环节去优化,才能有效提升店内免费流量
基于NCF的多模块协同实例
Educational Codeforces Round 22 B. The Golden Age
Differences and introduction of cluster, distributed and microservice
JVM(二十) -- 性能监控与调优(一) -- 概述
Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game