MySQL alter table时执行innobackupex全备再看Seconds_Behind_Master
1.场景描述
早上7:25 接到Report中心同学告警,昨天业务报表数据没有完整跑出来,缺少500位业务员的数据,并且很快定位到,缺少的是huabei_order库上的数据。Report中心的数据是BI每天5:15从huabei_order库的从库上抽取。查看监控告警,从库实例确实在4:50 --6:00 有延迟,但已恢复。数据不完整,直接原因就是主从延迟。
7:55 请求BI重新抽取数据,重新生成报表。
8:20 报表数据验证无误。
问题还没结束:
忽略监控告警的不及时、不完整。
还需要回答的问题是为什么在业务低峰期会出现延迟?是什么操作造成的?【问题1】
监控界面主从延迟指标
看到这样的走势图,又一个需要思考的问题:为什么延迟会瞬间飙升到24440s以上(实际可能已达25K以上),延迟不应该是逐渐累积的吗?【问题2】
确实是业务低峰期,和研发、产品、业务确认,23:30 之后没有大的操作、大的流量,也没有特别的活动、促销。从数据库Server业务压力上考虑,确实没有特殊的操作。
忽然想到,备份,完整备份。我们的灾备,数据库的完整备份实在从库上做的,cron 设置在每天的00:05 , 一般执行2个小时, 并且是周二、周五执行,当天正好是周二。
虽然自己也不太相信这个就是真正的原因,但毕竟是一个可考虑的因素。查看完整备份的log。
2.全量备份
失败
报错信息如下:
210831 04:49:46 >> log scanned up to (1168680308582)
210831 04:49:47 >> log scanned up to (1168680308668)
210831 04:49:48 >> log scanned up to (1168680308770)
210831 04:49:49 >> log scanned up to (1168680308856)
210831 04:49:50 >> log scanned up to (1168680308942)
210831 04:49:51 >> log scanned up to (1168680309028)
210831 04:49:52 >> log scanned up to (1168680309114)
InnoDB: Last flushed lsn: 1168515708469 load_index lsn 1168680309114
InnoDB: An optimized (without redo logging) DDLoperation has been performed. All modified pages may not have been flushed to the disk yet.
PXB will not be able take a consistent backup. Retry the backup operation
mysql: [Warning] Using a password on the command line interface can be insecure.
失败了,并且时间都很吻合,04:49 完整备份失败,04:49 主从延迟瞬间飙升。
查看完整备份历史,过去备份耗时在2个小时左右,而本次备份执行了4个小时50分钟,还失败了。
(说明:从完整备份打印的log来看,打印FLUSH TABLES WITH READ LOCK时,完整备份就快结束了,所以,在此图上,通过FLUSH TABLES WITH READ LOCK的时间代表完整备份结束的时间)
到此时,相信很多同学,已经准备把锅甩给完整备份了。
需要思考的问题 :DDL操作和xtrabackup是怎么相互影响的?为什么全量备份失败后,延迟问题才会马上被监控到(Seconds_Behind_Master才显示异常)?【问题3】
3.继续分析原因,寻找DDL
每个问题都不简单。
我们先看问题3.DDL操作和xtrabackup是怎么相互影响的?为什么全量备份失败后,延迟问题才会马上被监控到(Seconds_Behind_Master才显示异常)?【问题3】
回答这个问题,需要先找到具体的DDL操作。
但是备份期间没有执行过DDL操作。上次一DDL操作 要追溯到前一天19:50。迷雾重重、元凶隐隐。
想到MySQL DDL操作,一般执行时间相对较长,slow log 中或许有蛛丝马迹。
ELK--MySQL日志系统走起。
还是找到了一条大鱼,alter table ,添加字段。时间点吻合(04:49),执行时间超长25438秒(并且和Seconds_Behind_Master飙升后的值很接近 )。
从库DDL执行log
25438秒 ≈ 7 小时
从库所有的操作都来自主库,接下来,我们看下主库啥时候执行DDL的。
主库DDL执行情况
主库执行了 5089 秒,结束于 前一天的21:18。向前推 5089 秒,也就是 19:50前后。
为什么执行时间会这么长呢?这张表确实是大表、宽表--1.6 亿 数据量、130G大小,其信息如下:
所以,到现在,才算把主从延迟的问题定位到-----DDL 和 innobackupex。两者相互影响、相互拖累,才导致这个时间段内的延迟产生。这也算问题1的答案吧。
4.Seconds_Behind_Master 问题解答
此处我们尝试问答第二个问题:为什么延迟,会瞬间飙升到24440S以上,延迟不应该是逐渐累积的吗?【问题2】
我么先看下主从复制指标:Seconds_Behind_Master 的官方描述
Seconds_Behind_Master: The number of seconds that the replication SQL thread is behind processing the source's binary log. A high number (or an increasing one) can indicate that the replica is unable to handle events from the source in a timely fashion.
A value of 0 for Seconds_Behind_Master can usually be interpreted as meaning that the replica has caught up with the source, but there are some cases where this is not strictly true. For example, this can occur if the network connection between source and replica is broken but the replication I/O thread has not yet noticed this—that is, slave_net_timeout has not yet elapsed.
It is also possible that transient values for Seconds_Behind_Master may not reflect the situation accurately. When the replication SQL thread has caught up on I/O, Seconds_Behind_Master displays 0; but when the replication I/O thread is still queuing up a new event, Seconds_Behind_Master may show a large value until the SQL thread finishes executing the new event. This is especially likely when the events have old timestamps; in such cases, if you execute SHOW SLAVE STATUS several times in a relatively short period, you may see this value change back and forth repeatedly between 0 and a relatively large value.
Check the Seconds_Behind_Master
column in the output from SHOW REPLICA | SLAVE STATUS
.
When the replication SQL thread executes an event read from the source, it modifies its own time to the event timestamp. (This is why TIMESTAMP
is well replicated.) In the Time
column in the output of SHOW PROCESSLIST
, the number of seconds displayed for the replication SQL thread is the number of seconds between the timestamp of the last replicated event and the real time of the replica machine. You can use this to determine the date of the last replicated event. Note that if your replica has been disconnected from the source for one hour, and then reconnects, you may immediately see large Time
values such as 3600 for the replication SQL thread in SHOW PROCESSLIST
. This is because the replica is executing statements that are one hour old.
通过以上的描述 和 本 Case 中 Seconds_Behind_Master 的数字变化:
Seconds_Behind_Master 似乎应该为:SQL thread 重做主节点同步过来的binlog even, 执行提交后,比较从节点执行even的时间和主节点binlog event 中的时间所得到时间差。
再回答这个问题, Seconds_Behind_Master瞬间飙升到24440S 以上【因为我们的telegraf 抓取是20S一次,并且从监控库图上可看到,有一个快速下降趋势,所以,真正的最大值应该为25K以上,很可能会比慢查询的25438 还稍微大些】,这个值是怎么来的?应该就是从库DDL提交的时刻【04:49】减去主库DDL提交的时刻【前一天的21:18】的差值。 --这也算问题2的答案吧。
所以,Seconds_Behind_Master = 0 时,主从延迟可能已经很厉害了,除了官网提到的网络问题,还有就是从库正则执行同步过来的大DDL(尚未提交)。例如在本例的00:00---04:00 其实已经存在延迟了。
5.innobackupex知识补充
关于问题 3中 为什么全量备份失败后,延迟问题才会马上被监控到(Seconds_Behind_Master才显示异常)? 目前来看,尚未分析到直接因果关系,应该是概率事件。
innobackupex备份流程图如下:
经过验证测试,innobackupex备份开始时,并不是先看当前数据库是否有DDL操作,而是其中的某个线程在备份这张表时(或 scan lsn)才判断是否有DDL,有则推出报错。验证方法,在一张大表上执行DDL(保证DDL时间足够长),在DDL运行期间,开始备份,我们我看到这个很多表在执行copy备份,是运行了一段时间后,才报错的。
此外, innobackupex备份过程中,执行DDL,都会导致备份失败,与表大小无关,即使这张表只有一笔数据。
补充说明:
MySQL版本为5.7.22
innobackupex的版本为 innobackupex version 2.4.9 Linux (x86_64) (revision id: a467167cdd4)
6.参考文献
1.mysqldump与innobackupex备份过程知多少(完结篇)
https://blog.csdn.net/joy0921/article/details/80130860
2.MySQL中的seconds_behind_master的理解
https://www.cnblogs.com/drizzle-xu/p/9713350.html?ivk_sa=1024320u
3.How do I know how late a replica is compared to the source?
https://dev.mysql.com/doc/refman/8.0/en/faqs-replication.html
MySQL alter table时执行innobackupex全备再看Seconds_Behind_Master的更多相关文章
- MySQL ALTER TABLE: ALTER vs CHANGE vs MODIFY COLUMN
ALTER COLUMN 语法: ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT} 作用: 设置或删除列的默认值.该操作会直接修 ...
- mysql ALTER TABLE语句 语法
mysql ALTER TABLE语句 语法 作用:用于在已有的表中添加.修改或删除列.无铁芯直线电机 语法:添加列:ALTER TABLE table_name ADD column_name da ...
- mysql Alter table设置default的问题,是bug么?
不用不知道,用了没用? 昨天在线上创建了一个表,其中有两个列是timestamp类型的,创建语句假设是这样的: create table timetest(id int, createtime tim ...
- 【待整理】MySQL alter table modify vs alter table add产生state不一样
MySQL:5.6.35 OS:redhat5.8 今天更新数据库某些表字段,有如下两SQL: ①alter table xx modify xxxx;(表大概是77w) ②alter table s ...
- MySQL ALTER TABLE语法
先看一下定义(密密麻麻) ALTER TABLE tbl_name [alter_specification [, alter_specification] ...] [partition_optio ...
- mysql alter table
准备: create table t(x int,y int); 用法 1: 修改列的数据类 alter table t modify column y nvarchar(32); 用法2: 给表加一 ...
- mysql 添加索引,ALTER TABLE和CREATE INDEX的区别
nvicat-->mysql表设计-->创建索引. (1)使用ALTER TABLE语句创建索引,其中包括普通索引.UNIQUE索引和PRIMARY KEY索引3种创建索引的格式: PRI ...
- MySQL 索引管理与执行计划
1.1 索引的介绍 索引是对数据库表中一列或多列的值进行排序的一种结构,使用索引可快速访问数据库表中的特定信息.如果想按特定职员的姓来查找他或她,则与在表中搜索所有的行相比,索引有助于更快地获取信息. ...
- MySQL ALTER命令
当我们需要修改数据表名或者修改数据表字段时,就需要使用到MySQL ALTER命令. 开始本文教程前让我们先创建一张表,表名为:testalter_tbl. root@host# mysql -u r ...
随机推荐
- ifix 自动化(Automation)错误弹窗的解决方案
在先前ifix项目中添加了语音模块,然后概率性跳出自动化(Automation)错误弹窗,先前分析了很多种原因,从代码的冗余,编码等角度进行了优化,效果不是很理想,仍然会概率性出现.经过反反复复大约3 ...
- HTML5 socket
client: <!DOCTYPE html> <html> <head> <title></title> <meta http-eq ...
- Liferay Portal CE 反序列化命令执行漏洞(CVE-2020-7961)
影响范围 Liferay Portal 6.1.X Liferay Portal 6.2.X Liferay Portal 7.0.X Liferay Portal 7.1.X Liferay Por ...
- Apereo CAS 4.1 反序列化命令执行漏洞
命令执行 java -jar apereo-cas-attack-1.0-SNAPSHOT-all.jar CommonsCollections4 "touch /tmp/success&q ...
- 【Azure 应用服务】App Service 运行状况健康检查功能简介 (Health check)
通过Azure App Service门户,启用Health Check来监视应用服务的实例,当发现其中一个实例处于不健康(unhealthy)状态时,通过重新路由(即把有问题的实例从负载均衡器中移除 ...
- UNIX环境高级编程APUE练习4.6-实现类似cp(1)的程序,保留文件中的空洞
1 题面 编写类似cp(1)的程序,它复制包含空洞的文件,但是不将字节0写到输出文件中去. 2 基本思路 首先要搞清楚空洞的性质以判断一个文件是否有空洞,以及空洞的位置 知道了空洞的位置之后,读到源文 ...
- Linux远程访问控制
目录 一.SSH远程管理 1.1.定义 1.2.配置OpenSSH服务端 二.sshd服务支持两种验证方式 2.1.密码验证 2.2.使用SSH客户端程序 ssh远程登录 scp远程复制 sftp安全 ...
- Golang语言系列-13-常用内置包
常用内置包 net/http包 http请求和响应 http服务端 main.go文件 package main import ( "fmt" "io/ioutil&qu ...
- 【笔记】使用PCA对数据进行降噪(理解)
使用PCA对数据进行降噪(使用手写数字实例) (在notebook中) 加载库并制作虚拟的数据并进行绘制 import numpy as np import matplotlib.pyplot as ...
- Pytest+Allure 示例
0. 前言 简介 Allure 框架是一个灵活的.轻量级的.支持多语言的测试报告工具,它不仅以 Web 的方式展示了简介的测试结果,而且允许参与开发过程的每个人可以从日常执行的测试中,最大限度地提取有 ...