当前位置:网站首页>Introduction to distributed transaction Seata
Introduction to distributed transaction Seata
2022-04-23 14:52:00 【Top high school students】
Seata What is it?
Seata Is an open source distributed transaction solution , Committed to providing high-performance and easy-to-use distributed transaction services .Seata Will provide users with AT、TCC、SAGA and XA Transaction mode , Create a one-stop distributed solution for users .
Seata The three characters of
stay Seata In the framework of , There are three characters :
TC (Transaction Coordinator) - A business coordinator
Maintain the state of global and branch transactions , Drive global transaction commit or rollback .
TM (Transaction Manager) - Transaction manager
Define the scope of the global transaction : Start global transaction 、 Commit or roll back global transactions .
RM (Resource Manager) - Explorer
Manage resources for branch transactions , And TC Talk to register branch transactions and report the status of branch transactions , And drive branch transaction commit or rollback .
among ,TC For separately deployed Server Server side ,TM and RM For embedded in the application Client client .
stay Seata in , The life cycle of a distributed transaction is as follows :

1.TM request TC Start a global transaction .TC Will generate a XID As the number of the global transaction .XID, It will propagate in the invocation link of microservices , Ensure that the subtransactions of multiple microservices are associated together . As soon as it enters the transaction method, it will generate XID , global_table Is the stored global transaction information .
![]()
2.RM request TC Register local transaction as branch transaction of global transaction , Through global transactions XID Association . When running the database operation method ,branch_table Storage transaction participant .
3.TM request TC tell XID Whether the corresponding global transaction is committed or rolled back .
4.TC drive RM We will XID Commit or roll back the corresponding local transaction .
Design thinking
AT The core of the pattern is no intrusion into the business , It's an improved two-stage submission , The design idea is shown in the figure
The first stage
Business data and rollback logging are committed in the same local transaction , Release local locks and connection resources . The core is to the business sql To analyze , convert to undolog, And put it in storage at the same time , How is this done ? First throw out a concept DataSourceProxy Proxy data sources , Through the name, you can basically guess what operation it is , Specific analysis will be made later

The second stage
Distributed transaction operation succeeded , be TC notice RM Delete asynchronously undolog

Distributed transaction operation failed ,TM towards TC Send rollback request ,RM Roger the coordinator TC Rollback request from , adopt XID and Branch ID Find the corresponding rollback log record , Generate reverse updates by rolling back records SQL And implement , To complete the rollback of the branch .

Overall execution process

Design highlights
Compared with other distributed transaction frameworks ,Seata There are several highlights of the architecture :
1. The application layer is based on SQL The analysis realizes automatic compensation , So as to minimize business intrusion .
2. In distributed transactions TC( A business coordinator ) Independent deployment , Responsible for the registration of affairs 、 Roll back .
3. Write isolation and read isolation are realized through global lock .
The problem is
Performance loss
One Update Of SQL, A global transaction is required xid obtain ( And TC Communications )、before image( analysis SQL, Query the database once )、after image( Query the database once )、insert undo log( Write a database )、before commit( And TC Communications , Judge lock conflict ), All these operations require a remote communication RPC, And it's synchronous . in addition undo log When writing blob The insertion performance of the field is also not high . Write each SQL It's going to cost so much , A rough estimate would increase 5 Times the response time .
Cost performance
For automatic compensation , All transactions need to be mirrored and persisted , But in the actual business scenario , This is the success rate , Or how many percentage of distributed transaction failures need to be rolled back ? Estimate according to the principle of 28 , in order to 20% The transaction is rolled back , Need to put 80% Increased response time for successful transactions 5 times , This cost is compared to whether it's worth letting the application develop a compensation transaction ?
Global lock , Hot data
comparison XA,Seata Although in a successful stage will release the database lock , But one stage is commit The determination of the front global lock also lengthens the occupation time of the data lock , The cost ratio is XA Of prepare How much lower needs to be tested according to the actual business scenario . The introduction of global locks enables isolation , But the problem is congestion , Reduce concurrency , Especially hot data , This problem will be more serious .
Rollback lock release time
comparison XA,Seata Although in a successful stage will release the database lock , But one stage is commit The determination of the front global lock also lengthens the occupation time of the data lock , The cost ratio is XA Of prepare How much lower needs to be tested according to the actual business scenario . The introduction of global locks enables isolation , But the problem is congestion , Reduce concurrency , Especially hot data , This problem will be more serious .
Rollback lock release time
Seata When rolling back , You need to delete the undo log, Then we can release TC Lock in memory , So if the second phase is rollback , It takes longer to release the lock .
The deadlock problem
Seata The introduction of global lock will increase the risk of deadlock , But if a deadlock occurs , Will keep retrying , Finally, wait for the global lock timeout , It's not elegant , It also extends the time of database lock possession .
版权声明
本文为[Top high school students]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231450328733.html
边栏推荐
- January 1, 1990 is Monday. Define the function date_ to_ Week (year, month, day), which realizes the function of returning the day of the week after inputting the year, month and day, such as date_ to
- Brute force of DVWA low -- > High
- 8.5 循环神经网络简洁实现
- thinkphp5+数据大屏展示效果
- UML project example -- UML diagram description of tiktok
- 2-Go变量操作
- MySQL error packet out of order
- LeetCode 练习——396. 旋转函数
- [jz46 translate numbers into strings]
- Find daffodils - for loop practice
猜你喜欢
随机推荐
ASEMI超快恢复二极管与肖特基二极管可以互换吗
eolink 如何助力遠程辦公
LeetCode151-颠倒字符串中的单词-字符串-模拟
Svn detailed use tutorial
脏读、不可重复读和幻读介绍
Epoll's et, lt working mode -- example program
Advanced application of I / O multiplexing: Processing TCP and UDP services at the same time
pnpm安装使用
LeetCode149-直线上最多的点数-数学-哈希表
Sword finger offer II 019 Delete at most one character to get palindrome (simple)
QT actual combat: Yunxi calendar
[NLP] HMM hidden Markov + Viterbi word segmentation
GIS数据处理-cesium中模型位置设置
One of the advanced applications of I / O reuse: non blocking connect -- implemented using select (or poll)
Using MATLAB programming to realize the steepest descent method to solve unconstrained optimization problems
SVN详细使用教程
capacitance
Set up an AI team in the game world and start the super parametric multi-agent "chaos fight"
go基础 反射
1990年1月1日是星期一,定义函数date_to_week(year,month,day),实现功能输入年月日后返回星期几,例如date_to_week(2020,11,1),返回:星期日。 提示:








