当前位置:网站首页>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
边栏推荐
- 【无标题】
- Read PG in data warehouse in one article_ stat
- 迅为iTOP-IMX6ULL开发板Pinctrl和GPIO子系统实验-修改设备树文件
- TPG x AIDU|AI领军人才招募计划进行中!
- MongoDB内部的存储原理
- 服务器到服务器 (S2S) 事件 (Adjust)
- JS缓动动画原理教学(超细节)
- Day26 IP query items
- Analysis of DHCP dynamic host setting protocol
- Pay close attention to the work of safety production and make every effort to ensure the safety of people's lives and property
猜你喜欢

TPG x AIDU|AI领军人才招募计划进行中!

【无标题】

Per capita Swiss number series, Swiss number 4 generation JS reverse analysis

. Net ultimate productivity of efcore sub table sub database fully automated migration codefirst

Differences between MySQL storage engine MyISAM and InnoDB

Cinnamon Applet 入门

飞桨EasyDL实操范例:工业零件划痕自动识别

Introduction and basic use of stored procedures

Milkdown 控件图标

靠卖概念上市,认养一头牛能走多远?
随机推荐
My "troublesome" subordinates after 00: not bad for money, against leaders, and resist overtime
API query interface for free mobile phone number ownership
分屏bug 小记
Write it down once Net a new energy system thread surge analysis
《开源圆桌派》第十一期“冰与火之歌”——如何平衡开源与安全间的天然矛盾?
Shortcut key of Bash
Introduction and basic use of stored procedures
Differences between MySQL storage engine MyISAM and InnoDB
一文读懂数仓中的pg_stat
Unity build error: the name "editorutility" does not exist in the current context
Digital IC Design SPI
php——laravel缓存cache
MongoDB复制(副本集)总结
JNA learning notes 1: Concepts
Simple and easy-to-use code specification
Vscade editor esp32 header file wavy line does not jump completely solved
How did Guotai Junan Securities open an account? Is it safe to open an account?
【无标题】
Initialization script
Read PG in data warehouse in one article_ stat