当前位置:网站首页>Distributed transaction solution
Distributed transaction solution
2022-07-07 13:19:00 【log. Info (Xiao Lu)】
We all know that traditional local affairs pass Spring Of @Transactional Can be realized
When we place an order Change order status , Inventory deduction is written in one method , adopt @Transactional You can rollback or commit local transactions

But with the development of our business , Our meeting, library and table are separated , Now a complete database is split into multiple databases , An order payment operation is designed to 2 Operations One is Payment order update state , One is to reduce inventory , Now operate in a method 2 Databases This scenario Use @Tr Is it done

What should we do in such a scenario , This is just a distributed transaction across databases
Single system cross database Transactions are also distributed transactions , Because it's time to use @Transactional It can't help us solve cross database transactions , At this time, submit the agreement in two stages
The two-phase commit protocol has a role division A transaction coordinator and participant will be abstracted ,
Where is our cross database problem , Order payment we want to achieve results That is, the order status is changed to paid , reduce stock , We hope this 2 Operations either succeed at the same time Or fail at the same time , This is a whole business
If transactions are not used, the order status may be changed successfully , But inventory deduction failed
There are many reasons for the failure of inventory deduction For example, inventory is not enough to reduce , The inventory is suspended , This will cause 2 Side transactions are inconsistent , Generally speaking, in case of transaction inconsistency, the first step is to change the status to payment succeeded Second parts Inventory reduction failed

We introduce a two-phase commit protocol to help us solve this cross database transaction , We will first introduce the transaction manager ( Intermediate coordinator ), Then the first step is that I finish sql But I don't submit I just told the intermediate coordinator about the result , After the intermediate coordinator receives it , If all this succeeds , The transaction manager normally notifies all libraries to commit transactions
In the first stage, there is a professional term called pre submission , you sql If you don't submit after execution, it is called pre submission , He didn't really land in the database , Just tell the Resource Coordinator the result of the execution , Lock resources
If the first stage 2 All stages are successful The transaction manager notifies all databases To commit a transaction
There is an error report in the first stage The second stage is to do rollback operation This is the bottom idea of two-stage submission

The transaction manager notifies each transaction in the second phase commit/rollback, Can this happen
I succeeded in notifying the order warehouse
I failed to notify the inventory
I can't feel it either 100% To solve the problem of distributed transactions
Distributed transactions cannot 100% solve . During the second stage of notification, some nodes may fail to notify due to network reasons . Only try to improve the probability of success This will trigger the retry mechanism , Or SMS notification
The corresponding operation and maintenance personnel shall be compensated
If you don't have to commit in two stages . The most likely situation is that you execute the order and change the status correctly
Inventory reduction failed during the second operation , Can our two-stage submission solve this problem
situation
Our two-phase commit protocol greatly improves the probability of transaction commit
边栏推荐
- 我那“不好惹”的00后下属:不差钱,怼领导,抵制加班
- 自定义线程池拒绝策略
- Storage principle inside mongodb
- Realbasicvsr test pictures and videos
- 聊聊伪共享
- Write it down once Net a new energy system thread surge analysis
- API query interface for free mobile phone number ownership
- QQ的药,腾讯的票
- 一文读懂数仓中的pg_stat
- [etc.] what are the security objectives and implementation methods that cloud computing security expansion requires to focus on?
猜你喜欢

存储过程的介绍与基本使用

LED light of single chip microcomputer learning notes

MATLAB中polarscatter函数使用

“新红旗杯”桌面应用创意大赛2022

COSCon'22 社区召集令来啦!Open the World,邀请所有社区一起拥抱开源,打开新世界~

centso7 openssl 报错Verify return code: 20 (unable to get local issuer certificate)

我那“不好惹”的00后下属:不差钱,怼领导,抵制加班
![[untitled]](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[untitled]

Sed of three swordsmen in text processing

Vscade editor esp32 header file wavy line does not jump completely solved
随机推荐
error LNK2019: 无法解析的外部符号
Enterprise custom form engine solution (XII) -- experience code directory structure
Star Enterprise Purdue technology layoffs: Tencent Sequoia was a shareholder who raised more than 1billion
我那“不好惹”的00后下属:不差钱,怼领导,抵制加班
QQ medicine, Tencent ticket
DETR介绍
【等保】云计算安全扩展要求关注的安全目标和实现方式区分原则有哪些?
php——laravel缓存cache
Japanese government and enterprise employees got drunk and lost 460000 information USB flash drives. They publicly apologized and disclosed password rules
靠卖概念上市,认养一头牛能走多远?
Per capita Swiss number series, Swiss number 4 generation JS reverse analysis
记一次 .NET 某新能源系统 线程疯涨 分析
RealBasicVSR测试图片、视频
Cinnamon 任务栏网速
[untitled]
Ogre入门尝鲜
Awk of three swordsmen in text processing
Introduce six open source protocols in detail (instructions for programmers)
leecode3. 无重复字符的最长子串
存储过程的介绍与基本使用