当前位置:网站首页>MySQL XA distributed transaction
MySQL XA distributed transaction
2022-06-29 15:47:00 【Listen to the years】
Due to the splitting of various businesses of the system , Split multiple business services to different servers , Formed microservices . And in the actual production environment , We always encounter scenarios that require multiple microservices to jointly provide services , We also need to ensure that each microservice has the four characteristics of transactions ( Atomicity 、 Uniformity 、 Isolation, 、 persistence ). A typical scenario involves placing an order 3 A service ( Member services 、 Order service 、 Goods and services ). While placing an order , We need to ensure the successful creation of orders and the correct reduction of commodity inventory .
thus , I did some data preparation , Discover that distributed transactions can be used , What I am familiar with is tcc, But specifically tcc How is the underlying implementation of , I don't know , But I'll try again mysql The solution to this problem is found in the official documents of . namely XA Business .
About XA Please click here to explain the details of the transaction
Here are my tests , First we open two by command mysql Connect , And prepare the test table .
The above is my test data . I will use this data to test XA Business .
First step :client1 Create a xa Business
xa start "mysql_xa_1";
update users set nickname='tanyong123' where id=1;
update users set versionId = 22 where id=1;
xa end "mysql_xa_1";
xa prepare "mysql_xa_1";
among mysql_xa_1 It's a business id, We always have to make sure that things id Uniqueness , Not to be repeated 
I found that I have successfully created here ,
The second step : establish client2 Verify that the data has been persisted to the file layer
Check what I just performed sql Whether the statement has been persisted to the file layer .
Open a new connection client2
You can find that just xa Transaction statements executed in are not persisted .
The third step : To verify client2 Hold client1 The business of id Can I submit successfully

You can find , Submission failed . Is it because of my client1 The connection was not closed ( sign out ), And lead to client2 Unable to submit successfully ? Based on this , I did another test , sign out client1 Of mysql Connect . Let... Again client2 Perform transactions 
It can be found from the figure that the submission was successful , We created client3 look down xa Whether the data submitted by the transaction is persisted to the file layer .
From this, we can see that it has been persisted to the file layer .
summary
Based on the above test , We know , When client1 Create good xa After the transaction, through the transaction id You can make client2 To commit a transaction .
Based on this principle , I designed a simple distributed transaction model diagram 
Business side through restful or rpc Get xa Business id, Judge these according to the execution results of other businesses xa Transaction execution rollback or commit .
xa Transaction rollback command
xa rollback "mysql_xa_1"
mysql_xa_1 For business id
边栏推荐
- 墨天轮“高可用架构”干货文档分享(含Oracle、MySQL、PG资料124篇)
- ImgUtil 图片处理工具类,文字提取,图片水印
- postgresql源码学习(23)—— 事务日志④-日志组装
- 雷达天线简介
- File常用工具類, 流相關運用 (記錄)
- Cmake learning-2
- 明德扬XILINX-K7-325T/410T核心板数据手册
- 中序和后序遍历构建二叉树[递归划分区间与回溯拼接子树+中后序和中前序的相似与不同]
- 11. application layer data transmission format / port number -bite
- Informatics Olympiad all in one 1002: output the second integer
猜你喜欢

Building SQL statements in Excel

Detailed explanation of list set

Middle order and post order traversal to construct binary tree [recursive partition interval and backtracking splicing subtree + similarity and difference between middle post order and middle pre orde

数据挖掘复习

File common tool class, stream related application (record)

14.ip protocol -bite

ImgUtil 图片处理工具类,文字提取,图片水印

Mingdeyang xilinx-k7-325t/410t core board data manual

12.UDP协议-bite

File常用工具类, 流相关运用 (记录)
随机推荐
CKS CKA ckad change terminal to remote desktop
14.IP协议-bite
智能聊天机器人的优势在哪里?资深独立站卖家告诉你!
14.ip protocol -bite
MySQL JSON array operation JSON_ array_ append、json_ array_ insert
Google software version experience cycle
服务器的数据库连不上了【服务已起、防火墙已关、端口已开、netlent 端口不通】
C语言大作业——匹配系统
postgresql源码学习(24)—— 事务日志⑤-日志写入WAL Buffer
TDesign, which gave us benefits last time, will tell us its open source story today
阿里云体验有奖:使用PolarDB-X与Flink搭建实时数据大屏
I am 35 years old. Can I change my career to be a programmer?
swift JSONSerialization
LeetCode笔记:Weekly Contest 299
Flink SQL任务TaskManager内存设置
MySQL scheduled full database backup & rolling deletion of backup data before the specified date
Summary of recent work
Classe d'outils commune de fichier, application liée au flux (enregistrement)
MySQL开发规范.pdf
Informatics Olympiad all in one 2061: trapezoidal area