当前位置:网站首页>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
边栏推荐
- Brute force of DVWA low -- > High
- Frame synchronization implementation
- 1990年1月1日是星期一,定义函数date_to_week(year,month,day),实现功能输入年月日后返回星期几,例如date_to_week(2020,11,1),返回:星期日。 提示:
- What is the main purpose of PCIe X1 slot?
- 冰冰学习笔记:一步一步带你实现顺序表
- 牛客网数据库SQL实战详细剖析(26-30)
- Want to be an architect? Tamping the foundation is the most important
- UML项目实例——抖音的UML图描述
- LeetCode153-寻找旋转排序数组中的最小值-数组-二分查找
- Alexnet model
猜你喜欢
机器学习之逻辑回归(Logistic Regression)原理讲解和实例应用,果断收藏
1n5408-asemi rectifier diode
1 - first knowledge of go language
UML project example -- UML diagram description of tiktok
【JZ46 把数字翻译成字符串】
Borui data and F5 jointly build the full data chain DNA of financial technology from code to user
Mds55-16-asemi rectifier module mds55-16
LeetCode167-两数之和II-双指针-二分-数组-查找
Vous ne connaissez pas encore les scénarios d'utilisation du modèle de chaîne de responsabilité?
电容
随机推荐
SQLSERVER事物与锁的问题
Borui data and F5 jointly build the full data chain DNA of financial technology from code to user
MDS55-16-ASEMI整流模块MDS55-16
Using MATLAB programming to realize the steepest descent method to solve unconstrained optimization problems
Redis主从同步
Provided by Chengdu control panel design_ It's detailed_ Introduction to the definition, compilation and quotation of single chip microcomputer program header file
Detailed explanation of C language knowledge points -- first knowledge of C language [1]
QT actual combat: Yunxi calendar
【STC8G2K64S4】比较器介绍以及比较器掉电检测示例程序
Is asemi ultrafast recovery diode interchangeable with Schottky diode
3、 Gradient descent solution θ
机器学习之逻辑回归(Logistic Regression)原理讲解和实例应用,果断收藏
Find daffodils - for loop practice
Vous ne connaissez pas encore les scénarios d'utilisation du modèle de chaîne de responsabilité?
Flink DataStream 类型系统 TypeInformation
Alexnet model
Alexnet model
分享 20 个不容错过的 ES6 的技巧
Epoll's et, lt working mode -- example program
帧同步 实现