当前位置:网站首页>Distributed transaction
Distributed transaction
2022-06-30 18:42:00 【Hua Weiyun】
Distributed transactions - Theory Chapter
What is a distributed transaction
Distributed transaction means that the operation of transaction is located on different nodes , Therefore, remote cooperation between services is needed to complete transaction operations , In this kind of distributed system environment, different services cooperate with each other remotely through the network to complete the transaction, which is called distributed transaction , It mainly refers to multiple cross service transactions contained in a transaction webservice.
Distributed transaction theory -CAP&BASE
CAP
Consistency( Uniformity ): Users access any node in the distributed system , The data obtained must be consistent . Availability( Usability ): The user accesses any healthy node in the cluster , Must be able to get a response , Instead of timeout or rejection , Even if there are unhealthy nodes , Other healthy nodes should also respond . Partition tolerance ( Partition tolerance ): Some nodes in the distributed system lose connection with other nodes due to network failure or other reasons , Form a separate partition , When partitions appear in the cluster , The whole system should also continue to provide external services .

BASE
BASE It can be said to be a kind of neutralization and softening of usability and strong consistency .
Basically Available ( Basic available ): When a distributed system fails , Partial loss of availability is allowed , That is to ensure that the core is available . Soft State( Soft state ): In a certain amount of time , An intermediate state... Is allowed , Such as temporary inconsistency . Eventually Consistent( Final consistency ): Although strong consistency cannot be guaranteed , But at the end of the soft state , Finally, the data is consistent .
Distributed transaction processing scheme
XA The protocol consists of a two-phase commit (2PC)

The first stage
stay XA The first phase of distributed transactions , The node that acts as the transaction coordinator will first send Prepare request .
After receiving Prepare After the request , Each participant node will update the data related to the transaction , write in Undo Log and Redo Log. If the participant performs successfully , Do not commit the transaction for the time being , Instead, it returns... To the transaction coordination node “ complete ” news .
When the transaction coordinator receives a return message from all participants , The whole distributed transaction will enter the second phase .
The second stage
stay XA The second phase of distributed transactions , If the transaction coordination node has received all the data before, it will return in a positive direction , Then it will issue... To all transaction participants Commit request .
Receive Commit After the request , The transaction participant nodes will commit their own local transactions , And release the lock resource . When the local transaction is committed , Will return to the transaction coordinator “ complete ” news .
When the transaction coordinator receives the “ complete ” feedback , The whole distributed transaction is completed .
Add Three stage commit (3PC) Two implementations : In the first step, one more CanCommit Stage , First, ask whether there are conditions for submission , The two-step submission step above will be performed only after the confirmation is returned , Added a timeout , If some participants are commit I haven't received any from the coordinator for a certain period of time commit, Automatic local submission .
Inferiority
A single point of failure : The transaction coordinator is the whole XA The core of the model , Once the transaction coordinator node fails , Participants cannot receive commit or rollback notification , Participants will never be able to complete the transaction . Inconsistencies caused by missing messages : Second stage , If there is a local network problem , Some transaction participants received a commit message , Another part of the transaction participants did not receive the commit message , This leads to data inconsistency between nodes . 3pc That solved the problemPerformance issues : If multiple participants , Partially completed , Partially incomplete , Do not submit until the unfinished work is completed , So the performance has a certain impact .
Seata A two-step solution to


TCC Solution

Try: Try Phases are generally used to lock a resource , Set a ready state or freeze some data .
Confirm: according to Try Implementation of phase ,Confirm There are two cases : Ideally , all Try All executed successfully , Execute the... Of each service Confirm Logic ; If confirm Execution failure , retry , Artificial intervention , By default, the execution must be successful . Some services Try Execution failure , Then execute the third stage ——Cancel.
Cancel If Try Stage execution exception , Will execute Cancel Stage , The execution of this stage is to put try The locked resources of the phase are released . The default is successful execution , Unsuccessful manual intervention .
MQ Message queuing ensures final consistency

Recommended articles
interviewer : Let's talk about congestion control
interviewer : Have you known about seckill system solutions
interviewer :JMM Let's talk about ?
interviewer : Young man , Distributed database ID Solutions understand ?
边栏推荐
- C# Winform程序界面优化实例
- 又一篇CVPR 2022论文被指抄袭,平安保险研究者控诉IBM苏黎世团队
- Do you write API documents or code first?
- Rhai 脚本引擎的简单应用示例
- 程序员女友给我做了一个疲劳驾驶检测
- The secondary menu of the magic article system v5.4.0 supports the optimization of form display
- Force deduction solution summary 1175- prime number arrangement
- 剑指 Offer 16. 数值的整数次方
- 【云驻共创】Huawei iConnect使能物联终端一触即联
- uni-app进阶之内嵌应用【day14】
猜你喜欢

Multipass中文文档-设置图形界面

How to solve the lock-in read-only alarm of AutoCAD Chinese language?

清华只能排第3?2022软科中国大学AI专业排名发布

Deep understanding of JVM (II) - memory structure (II)

Dependencies tool to view exe and DLL dependencies

漏洞复现----35、uWSGI PHP 目录遍历漏洞 (CVE-2018-7490)

电子元器件行业在线采购系统精准匹配采购需求,撬动电子产业数字化发展

Merged binary tree of leetcode

英飞凌--GTM架构-Generic Timer Module

ForkJoinPool
随机推荐
Design of online shopping mall based on SSH
深度学习编译器的理解
VScode 状态条 StatusBar
Classic problem of leetcode dynamic programming (I)
Tsinghua only ranks third? 2022 release of AI major ranking of Chinese Universities of soft science
Tide - 基于 async-std 的 Rust-web 框架
Deep understanding of JVM (V) - garbage collection (II)
If you want to learn software testing, you must see series, 2022 software testing engineer's career development
C# Winform程序界面优化实例
Vs Code treeview TreeView
麻烦问下 Flink支持同步数据到 sqlserver么
MySQL cannot find mysql Temporary solution of sock file
MySQL n'a pas pu trouver MySQL. Solution temporaire pour le fichier Sock
Optimize with netcorebeauty Net core independent deployment directory structure
Vulnerability recurrence ----37. Apache unomi Remote Code Execution Vulnerability (cve-2020-13942)
LRN local response normalization
剑指 Offer 16. 数值的整数次方
MySQL找不到mysql.sock文件的臨時解
MySQL找不到mysql.sock文件的临时解
NFT挖矿游GameFi链游系统开发搭建