当前位置:网站首页>Technology sharing | big transaction blocking show master status
Technology sharing | big transaction blocking show master status
2022-07-23 10:00:00 【java_ beautiful】
Preface
MySQL The master-slave copy function can build a slave library for MySQL Create an online backup system , But it cannot switch independently ; Third party high availability tools are needed . However, when there are large transactions running, it will block some show sentence ; for example “show master status”, Cause miscarriage of justice .
Scene simulation
1、 Construct 20 million rows of data , Delete as a transaction

2、 New session execution show master status , stay sql The execution of the statement was successful . stay commit Blocked during .

3、show master status be in starting state , That is, the first stage of statement execution , Start-up phase , Prepare resources .

4、 see stack Information ,show master status It's about getting lock_log Blocked when locking
#6 0x0000000000ee8278 in MYSQL_BIN_LOG::get_currrent_log (this=0x1e839c0 <mysql_bin_log>, linfo=0x7f3ea82e62d0, need_lock_log=<optimized out>) at /export/home/pb2/build/sb_0-32013917-1545390211.74/mysql-5.7.25/sql/binlog.cc:5514
......
#6 0x0000000000eef824 in MYSQL_BIN_LOG::change_stage (this=<optimized out>, thd=<optimized out>, stage=<optimized out>, queue=<optimized out>, leave_mutex=<optimized out>, enter_metux=0x1e839c8 <mysql_bin_log+8>) at /export/home/pb2/build/sb_0-32013917-1545390211.74/mysql-5.7.25/sql/binlog.cc:91705、 Finally, because the transaction is too big , Final show master status Overtime , Cause failover .
The reason is commit And show master status Blocking and waiting between , Next, analyze the reasons .
Cause analysis :commit
commit The process is divided into the following stages ( With 5.7.25 For example ), For atomic operations , Write once .
1、prepare The main function of this stage is to brush redo 、undo ; here binlog It only involves some preparatory actions . reference binlog_prepare function .
static int binlog_prepare(handlerton *hton, THD *thd, bool all)
{
DBUG_ENTER("binlog_prepare");
if (!all)
{
thd->get_transaction()->store_commit_parent(mysql_bin_log.
m_dependency_tracker.get_max_committed_timestamp());
}2、flush The main function of the stage is persistence redo ; obtain lock_log Locks block other group transactions from writing , And generate flush queue ( The first transaction is leader , This was followed by follower ) And write binlog , At this time, the memory writes but does not brush the disk , reference process_flush_stage_queue function
int
MYSQL_BIN_LOG::process_flush_stage_queue(my_off_t *total_bytes_var,
bool *rotate_var,
THD **out_queue_var)
{
DBUG_ENTER("MYSQL_BIN_LOG::process_flush_stage_queue");
#ifndef DBUG_OFF
// number of flushes per group.
int no_flushes= 0;
#endif
DBUG_ASSERT(total_bytes_var && rotate_var && out_queue_var);
my_off_t total_bytes= 0;
int flush_error= 1;
mysql_mutex_assert_owner(&LOCK_log);3、sync The stage function is to release lock_log lock , obtain lock_sync Lock blocks other transaction groups from scrubbing , And according to sync_binlog Decide the disk brushing strategy .
if (change_stage(thd, Stage_manager::SYNC_STAGE, wait_queue, &LOCK_log, &LOCK_sync))
{
DBUG_PRINT("return", ("Thread ID: %u, commit_error: %d",
thd->thread_id(), thd->commit_error));
DBUG_RETURN(finish_commit(thd));
}4、commit Stage release lock_sync lock , obtain lock_commit Lock and wait follower Transaction submission , Release the lock and empty after submitting binlog Cache and judge whether to refresh and archive binlog
Cause analysis :show master status
show master status Its function is from the last binlog Get in file Executed_Gtid Information and the binlog Executed gtid Information . Its function entry is : https://github.com/mysql/mysq... 624 Line and get lock_log lock :
int MYSQL_BIN_LOG::get_current_log(LOG_INFO* linfo, bool need_lock_log/*true*/)
{
if (need_lock_log)
mysql_mutex_lock(&LOCK_log);
int ret = raw_get_current_log(linfo);
if (need_lock_log)
mysql_mutex_unlock(&LOCK_log);
return ret;
}Conclusion
The example in the case is a single big transaction , Therefore, the group submitted sync Stage , from commit(flush Stage ) as well as show master status You can see in the steps of , The blocking between two operations is caused by lock_log Caused by lock contention , The nature of the lock is lock_log Log lock , Rather than MDL And engine layer lock , If the transaction is larger ,flush Phase write binlog The longer the period and the longer the lock will be held ; Thus blocking other transaction submissions and binlog Of show operation , Therefore, the corresponding solution is :
1、 Big things can cause io Skyrocketing 、 Problems such as master-slave delay and transaction blocking , stay MGR The environment may even cause replication disruption ,mysql Big things need to be avoided .
2、binlog Is a constantly changing document ,show master status The statement can be changed to select @@global.gtid_executed ; To get GTID Information .
边栏推荐
- RESTful是什么
- 【无标题】
- Qt::WA_TransparentForMouseEvents 了解一下
- PNA peptide nucleic acid modified peptide suc ala PNA | 2-ala ala leupna | AC Phe Gly PNA
- Distributed lock optimization scheme under 100 million traffic! It works so well~
- 2022-07-22:以下go语言代码输出什么?A:1;B:1.5;C:编译错误;D:1.49。 package main import “fmt“ func main() { var i
- 本地提权的学习
- The method of page Jump in PHP
- 面试官:解释一下ThreadLocal 核心原理
- 系统安全测试要怎么做,详细来说说
猜你喜欢

分库分表真的适合你的系统吗?聊聊分库分表和NewSQL如何选择

【C语言对链表的操作(链表的初始化,建立,求长,增加,删除,以及输出)】

Use recursive string inversion and Full Permutation

可视化全链路日志追踪

幻核即将关闭?数字藏品还有未来吗?

Tsinghua, air, Tencent | 3D isovariant molecular map pre training

亿级融资事件占比超30%,超自动化的下一站是何处?丨曼孚科技

Ardunio——ULN2003驱动板和直流电机风扇——控制风扇转速

在Unity中使用Tessellation

How can a platform enterprise solve the business of ledger accounting?
随机推荐
第三方依赖库 AG Grid调研分析
系统安全测试要怎么做,详细来说说
Want to give up software testing, 4 years of experience to interview 10 minutes, the test is now so difficult?
技术分享 | 大事务阻塞 show master status
DigiCert代码签名证书
零基础怎么学习单片机?
PHP script paging TXT content case
抖音白天与晚上触发不同特效的Graph节点编写
C——位运算
How to learn SCM based on zero?
本地提权的学习
d类型不同的模板错误
华泰证券开户安全吗是真的吗,是正规的吧
大专学历想0基础学编程以后找工作可行吗 ?
MySQL数据库UDF提权学习
[learning notes] node -- from 0 foundation to actual enterprise official website
【学习笔记】Node--从0基础到实战企业官网
php 将图片转换 base64 格式与还原生成图片
可视化全链路日志追踪
nchar字符引起的ora-12899错误