当前位置:网站首页>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
边栏推荐
- PCIe X1 插槽的主要用途是什么?
- 8.5 循环神经网络简洁实现
- 《JVM系列》 第七章 -- 字节码执行引擎
- 【NLP】HMM隐马尔可夫+维特比分词
- Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
- Realization of four data flow modes of grpc based on Multilingual Communication
- Daily question - leetcode396 - rotation function - recursion
- pnpm安装使用
- Do (local scope), initializer, memory conflict, swift pointer, inout, unsafepointer, unsafebitcast, success
- 压缩映射定理
猜你喜欢
ASEMI整流模块MDQ100-16在智能开关电源中的作用
线程同步、生命周期
Explain TCP's three handshakes in detail
capacitance
Interviewer: let's talk about the process of class loading and the mechanism of class loading (parental delegation mechanism)
We reference My97DatePicker to realize the use of time plug-in
1 - first knowledge of go language
电容
详解TCP的三次握手
Sword finger offer II 019 Delete at most one character to get palindrome (simple)
随机推荐
Leetcode162 - find peak - dichotomy - array
2-Go变量操作
epoll 的EPOLLONESHOT 事件———实例程序
SQL中HAVING和WHERE的区别
Unity_ Code mode add binding button click event
你还不知道责任链模式的使用场景吗?
8.3 语言模型与数据集
When splicing HQL, the new field does not appear in the construction method
The difference between having and where in SQL
封面和标题中的关键词怎么写?做自媒体为什么视频没有播放量
【Proteus仿真】自动量程(范围<10V)切换数字电压表
Redis主从同步
The art of automation
First acquaintance with STL
Leetcode exercise - 396 Rotation function
Sqlserver transaction and lock problem
1 - first knowledge of go language
[servlet] detailed explanation of servlet (use + principle)
Daily question - leetcode396 - rotation function - recursion
Frame synchronization implementation