当前位置:网站首页>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 statusOutput in progress ,Retrieved_Gtid_SetAndExecuted_Gtid_Setequal ( 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.
边栏推荐
- 基于IMDB评论数据集的情感分析
- 2022/6/29学习总结
- Exposure: a white box photo post processing framework reading notes
- Istio、eBPF 和 RSocket Broker:深入研究服务网格
- Personnaliser le plug - in GRPC
- C#依赖注入(直白明了)讲解 一看就会系列
- 241. Design priority for operational expressions: DFS application questions
- Learning summary on June 30, 2022
- Activity workflow engine
- Value/set in redis
猜你喜欢

About keil compiler, "file has been changed outside the editor, reload?" Solutions for

Learning summary on June 30, 2022

Le semester manquant

On recursion and Fibonacci sequence

博途V15添加GSD文件

Redis configuration environment variables

【单片机】【数码管】数码管显示

Software project management 9.2 Software project configuration management process

Rural guys earn from more than 2000 a month to hundreds of thousands a year. Most brick movers can walk my way ǃ

Exploration and practice of inress in kubernetes
随机推荐
2022/6/28学习总结
我在中山,到哪里开户比较好?实际上网上开户安全么?
Uniapp uses uni upgrade Center
Question: what professional qualities should test engineers have?
Golang根据参数引入相应配置文件的实现方式
Learning summary on June 29, 2022
Kernel synchronization mechanism
Are the consequences of securities account cancellation safe
redis中value/String
Computer graduation project asp Net attendance management system vs developing SQLSERVER database web structure c programming computer web page source code project
redis中value/hush
自组织是管理者和成员的双向奔赴
Value/hush in redis
VScode快捷键(最全)[通俗易懂]
The specified service is marked for deletion
The Missing Semester
Rural guys earn from more than 2000 a month to hundreds of thousands a year. Most brick movers can walk my way ǃ
Can I open an account today and buy stocks today? Is it safe to open an account online?
MQ-防止消息丢失及重复消费
CAD如何设置标注小数位