当前位置:网站首页>Technology sharing | MySQL: how about copying half a transaction from the database?
Technology sharing | MySQL: how about copying half a transaction from the database?
2022-07-01 12:00:00 【ActionTech】
author : Hu Chengqing
Love can be born DBA Team members , Good at fault analysis 、 performance optimization , Personal blog :https://www.jianshu.com/u/a95ec11f67a8, Welcome to discuss .
In this paper, the source : Original contribution
* Produced by aikesheng open source community , Original content is not allowed to be used without authorization , For reprint, please contact the editor and indicate the source .
Copy exception
In the process of copying , The main database fails or the network is interrupted , Will cause slave io thread interrupt , It is possible that only half a transaction is copied from the Library . For example, the transactions executed by the main database are as follows :
begin;
insert 1;
insert 2;
commit;
Received from library binlog It may only contain part of the transaction , such as :
- situation 1: Contains only begin;
- situation 2: Contains only begin;insert 1;
- situation 3: Contains only begin;insert 1;insert 2;
From library slave sql thread Play back this part binlog after , Will wait for slave io thread Read the remaining... From the main library binlog, And before that sql The thread plays back the half transaction , It's the same as we manually perform half a transaction , Neither commit nor rollback .
How should we deal with this anomaly ?
- When slave io thread recovery , What to do ?
- When slave io thread Can't recover , What to do ?
Experimental process
The test method :
##1. Used in slave Library tc Simulate network latency , Intended to make reading binlog It's slowing down
tc qdisc add dev eth0 root netem delay 3000ms 3000ms 100%
##2. Execute a multi statement transaction in the main database
begin;
update t2 set pad='4' where id < 40;
update t2 set pad='5' where id < 50;
update t2 set pad='6' where id < 60;
commit;
##3. Execute... In the main library commit After success , Use immediately iptables Cut off the network between master and slave
iptables -A OUTPUT -d 172.16.21.4 -j DROP
iptables -A INPUT -s 172.16.21.4 -j DROP
In this way, the phenomenon we can observe from the library is :
- One of them worker The thread state is
Waiting for an event from Coordinator
, This status indicates work The thread has finished its work and is waiting Coordinator ( Coordination thread ) Assign a new relay log event , But it also shows that it is executingupdate t2 set pad='5' where id < 50
, This is a contradiction 1:
show slave status
Output in progress ,Retrieved_Gtid_Set
AndExecuted_Gtid_Set
equal ( signify sql The thread has played back all relay log), But above worker The thread is playing back again SQL , This is a contradiction 2:
Finally, we passed relay log Compaction hammer , You can see this transaction relay log Incomplete , To update t2 set pad='5' where id < 50
; This Rows_query event
It's over :
When slave io thread Can't recover
If slave io thread Can't recover for a long time , that sql Threads can't wait for the rest binlog, Never commit or rollback , Will always hold the lock of this transaction :
If it is caused by the failure of the main library slave io thread abnormal , It is likely to switch between master and slave , After upgrading from the library to the main ,SQL Transaction locks held by threads may block business requests .
It should be at this time stop slave stop it sql Threads , Let the transaction rollback release the lock . It should be noted that : In this case stop slave Will wait for 60 second ( etc. slave io thread Receive the remaining binlog),60 Seconds before it stops sql Threads :
When slave io thread recovery
slave io thread After an abnormal interrupt ,sql Threads work normally ,sql The thread executes some transactions , And will wait io Thread sends new binlog.slave io thread After thread recovery , If it is based on GTID Copy , From the present GTID The transaction begins to retrieve the complete binlog, The current transaction will be rolled back first from the Library , Then replay the newly received binlog.
边栏推荐
- Kafuka learning path (I) Kafuka installation and simple use
- 耐克如何常年霸榜第一名?最新財報答案來了
- 2022/6/29学习总结
- Matrix of numpy
- Summary of JFrame knowledge points 1
- C # dependency injection (straight to the point) will be explained as soon as you see the series
- 巩固-C#运算符
- Openinstall: wechat applet jump to H5 configuration service domain name tutorial
- About keil compiler, "file has been changed outside the editor, reload?" Solutions for
- Redis configuration environment variables
猜你喜欢
LeetCode力扣(剑指offer 31-35)31. 栈的压入弹出序列32I.II.III.从上到下打印二叉树33. 二叉搜索树的后序遍历序列34. 二叉树中和为某一值的路径35. 复杂链表的复制
Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS
华为HMS Core携手超图为三维GIS注入新动能
C summary of knowledge points 1
Abbirb120 industrial robot mechanical zero position
深入理解 grpc part1
Talk about biological live broadcast - genovis Zhang Hongyan antibody specific enzyme digestion technology helps to characterize the structure of antibody drugs
GID:旷视提出全方位的检测模型知识蒸馏 | CVPR 2021
[Maui] add click events for label, image and other controls
Y48. Chapter III kubernetes from introduction to mastery -- pod status and probe (21)
随机推荐
The Missing Semester
Explore the contour detection function findcontours() of OpenCV in detail with practical examples, and thoroughly understand the real role and meaning of each parameter and mode
对于mvvm和mvc的理解
邻接矩阵无向图(一) - 基本概念与C语言
LeetCode力扣(剑指offer 31-35)31. 栈的压入弹出序列32I.II.III.从上到下打印二叉树33. 二叉搜索树的后序遍历序列34. 二叉树中和为某一值的路径35. 复杂链表的复制
The specified service is marked for deletion
Kernel synchronization mechanism
Impressive bug summary (continuously updated)
JS date format conversion method
redis中value/hush
The Missing Semester
Use set_ Handler filters out specific SystemC wrapping & error messages
Extended tree (I) - concept and C implementation
Can solo be accessed through IPv6?
Unity xlua co process packaging
Prepare for the Blue Bridge Cup Day10__ PWM control light brightness
迅为i.MX8Mmini开发板离线构建Yocto系统
Why does the JVM heap memory exceed 32g and pointer compression fail?
Openinstall: wechat applet jump to H5 configuration service domain name tutorial
今天开户今天能买股票吗?在线开户是很安全么?