当前位置:网站首页>Distributed transaction and at mode principle of Seata
Distributed transaction and at mode principle of Seata
2022-07-26 00:43:00 【Minor Wang Zhi】
Catalog
1. Distributed transactions
In a distributed system architecture , Complex businesses require cross database operations , To ensure the global transaction consistency, we need to solve the distributed transaction problem .
1.1 XA standard
XA Specification , Three roles are defined :AP Applications 、RM Explorer ( database )、TM Transaction manager .XA The specification defines RM-TM Communication interface .
1.2 2PC Two-phase commit
2PC and XA Norms are not necessarily linked , however 2PC The pattern is right XA An abstract implementation and optimization of the specification .2PC Altogether 2 Stages : Pre submission and commit.
1. TM Inform each RM Prepare to commit their local transactions .
1. TM Follow the steps 1 each RM The result of the feedback will be submitted in advance to decide whether to release commit The order of .
2PC There are several serious problems :
- The blocking delay is large .
- TM A single point of failure .
- Global data inconsistency , In stage two ,TM It's down commit operation , But only a part RM received commit, Some did not receive , There is a problem of inconsistency .
1.3 3PC Three stage commit
3PC yes 2PC Improved version , But there is no essential difference , and 2PC The difference is :
- The timeout mechanism is introduced , stay TM and RM There is a timeout mechanism .
- stay 2PC Withholding and payment of commit A preparatory stage is interspersed in the middle , therefore 3PC Yes 3 Stages :CanCommit、PreCommit、Commit.
1.4 TCC
Try-Confirm-Cancel, In essence, it is also a two-stage submission agreement for business service ,TCC Altogether 3 A step , The first stage requires the application to reserve resources , When all participants try The interfaces all worked , Then the transaction manager will commit the transaction confirm, Otherwise to cancel Rollback resource release .TCC Of try In the stage, it is generally necessary to take a pre snapshot of resources to record the changes of transaction data , Subsequent consistency alignment operations are performed based on this record when committing or rolling back .
1.5 Flexible business
Flexible transactions refer to services that are basically available 、 Soft state / Intermediate state 、 Final agreement ; The core idea is that strong consistency cannot be guaranteed in a distributed environment , Instead, make some compromises based on your own business scenarios . Common flexible transaction solutions are : Best effort notification 、 compensate 、 Final consistency / Asynchronously ensures 、 Two stage submission .
2.Seata
Seata It is an Alibaba open source distributed transaction resolution framework . It supports AT、TCC、Saga、XA Multiple modes .Seata There are three roles in our organizational structure :
- TC(Transaction Coordinator) Transaction coordinator : Maintain the information of global transactions and branch transactions , Control the commit or rollback of global transactions ,TC It is a service that needs to be deployed independently , and TM and RM It's a client The client depends on the project .
- TM(Transaction Manager) Transaction manager : The opening of global transactions and the definition of boundaries .
- RM(Resource Manager) Explorer : Management of local branch transactions , Responsible for and TC Interact and report transaction status , Perform specific commit or rollback .

3.Seata AT Pattern ( Main stream )
Seata Support multiple distributed transaction modes , The official main push is AT Pattern ,AT Patterns are non intrusive 、 Similar to automation implicit TCC Pattern .AT The mode is divided into 2 Stages :
- Business data and undoLog Record in the same transaction and commit , Then release the local lock and connect resources .
- If you need to submit , Asynchronous commit . If you need to roll back , Local execution undoLog Reverse compensation .



3.1 AT The advantages of patterns
- Automated agents DataSource, Automation realizes the compensation logic , Reduce business code intrusion .
- TC Introduction of transaction coordinator , Simplified some transaction control logic .
- The isolation of distributed transactions ensures the implementation of write isolation and read isolation through global locks and local locks .
One stage local transaction Commit You need to get it before Global transaction lock ;
If the global lock is not obtained, the local transaction cannot be committed , There is a time limit for trying to obtain a global lock , If the threshold is exceeded, the rollback of the local transaction is executed .
3.2 AT The inadequacy of the model
- performance , Many times are involved in the transaction RPC Remote calls and various SQL Parsing and snapshot dropping .
- For the isolation of hot data, there are performance problems .
- Because the lock mechanism is introduced , May cause deadlock , Although there is a timeout , But it still has an impact on performance .
边栏推荐
- How much data can a list store?
- What is Web3 game?
- HOOPS Exchange助力混合计算流体动力学软件搭建3D格式导入读取功能 | 客户案例
- Mwec: a new Chinese word discovery method based on multi semantic word vector
- Tarjan 求强连通分量 O(n+m) ,缩点
- [array creation in numpy]
- 【计算一个字符串和另一个字符串相等的次数】
- Hcip day 13
- hyperf使用之curd
- Compile openfoam solver with cmake
猜你喜欢

Curd used by hyperf

SQL server failed to send mail, prompting that the recipient must be specified

GOM and GEE engine black screen does not display the interface, and the solution of equipping map monsters

Hcip - republish

hcia综合实验

实战演练 | 查找在给定时间范围内购买超过 N 件商品的客户

hyperf使用之curd

LCA 三种姿势(倍增,Tarjan+并查集,树链剖分)
![[IJCAI 2022] parameter efficient large model sparse training method, which greatly reduces the resources required for sparse training](/img/56/7a49f9c825d88a31b980a5fae50951.png)
[IJCAI 2022] parameter efficient large model sparse training method, which greatly reduces the resources required for sparse training

Find and locate commands
随机推荐
【NumPy中数组创建】
P4047 [JSOI2010]部落划分
C#从入门到精通(三)
Private cloud disk setup
PC website realizes wechat code scanning login function (II)
从另一个角度告诉你单元测试的意义
[oops framework] interface management
生物JC UVSSA复合物缓解MYC驱动的转录压⼒ English
D3D计算着色器入门
【计算一个字符串和另一个字符串相等的次数】
Verilog语法基础HDL Bits训练 05
JMeter/IDEA中引用jar包json-path.jar的坎坷之路
[redis] ③ data elimination strategy, pipeline command, publish and subscribe
Semaphore
Research on visualization method of technology topic map based on clustering information
Verilog grammar basics HDL bits training 06
Seretod2022 track1 code analysis - task-based dialogue system challenge for semi supervised and reinforcement learning
分布式事务和Seata的AT模式原理
参数解析器HandlerMethodArgumentResolver分析与实战
GOM and GEE engine black screen does not display the interface, and the solution of equipping map monsters