http://blog.chinaunix.net/uid-28212952-id-3494560.html

今天同事遇到一个故障,xtrabackup备份中flush tables with read lock进程状态是flushing table,持续了大约60000s,首先分析是被长事务堵住了,show processlists,未看到长事务,因为slave上不提供应用服务,所以只有xtrabackup备份一个进程,show slave status\G发现Seconds_Behind_Master=0,但slave io thread执行的master binlog 要比 slave sql thread执行的master binlog多几十个,显然Seconds_Behind_Master不该为0(暂时未找到原因),抽样观察 slave sql thread执行的pos不变,怀疑是sql thread卡住引起flush tables with read lock 处于flushing table,mysqlbinlog 解析relaylog 发现当前slave正在执行delete操作,后检查binlog_format=row且对应表无主键,master上一条无主键表的delete执行记录在binlog中每row对应一个event,当master binlog传到slave上执行时,每个event对要在slave进行一次全表扫描,至此原因找到了,解决方案:

第一种

1.stop slave; #会hang 几个或十几个小时进行delete操作的回滚

2.对未主键表创建主键

第二种

1.master  binlog_format=statment

2.master 备份

3.重做slave

Seconds_Behind_Master问题

show slave status\G 显示slave在复制中的信息,其中Seconds_Behind_Master常被用作衡量slave延迟秒数,虽然Seconds_Behind_Master值被许多认为不能够准确反映slave延迟情况,但由于show slave status\G简单易用,对于无须精确的场景足够了(精确方式如在master上表中定期插入timestamp,在slave上通过系统时间和timestamp进行对比得到精确slave延迟),简单看了下代码time_diff(Seconds_Behind_Master值)

sql/slave.cc
bool show_master_info(THD* thd, Master_info* mi)
long time_diff= ((long)(time(0) - mi->rli.last_master_timestamp)
                       - mi->clock_diff_with_master);

static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi)
clock_diff_with_master= 0; /* The "most sensible" value */

 

sql/rpl_rli.cc
void Relay_log_info::stmt_done(my_off_t event_master_log_pos,time_t event_creation_time)
last_master_timestamp= event_creation_time;

 

event_creation_time(代码中暂时未找到定义),从字面感觉在slave上对应的是Exec_Master_Log_Pos字段值,因此Seconds_Behind_Master值就是master当前系统时间戳(slave当前系统时间戳 - slave与master间的时间戳差) - slave sql thread当前已经执行完的master binlog pos.

manual中对Seconds_Behind_Master的解释如下,但与代码的计算公式不一致,Seconds_Behind_Master值是slave io thread当前已经获取的master binlog pos - slave sql thread当前已经执行完的master binlog pos

In essence, this field measures the time difference in seconds between the slave SQL thread and the slave I/O thread.

If the network connection between master and slave is fast, the slave I/O thread is very close to the master, so this field is a good approximation of how late the slave SQL thread is compared to the master. If the network is slow, this is not a good approximation; the slave SQL thread may quite often be caught up with the slow-reading slave I/O thread, soSeconds_Behind_Master often shows a value of 0, even if the I/O thread is late compared to the master. In other words, this column is useful only for fast networks.

个人倾向于代码中的解释,设计实验来验证,用取一天前的备份集新做了一个slave,change master且start slave后,Seconds_Behind_Master显示为60000多秒(20小时左右),显然是master当前系统时间戳 - slave sql thread当前已经执行完的master binlog pos的结果

Seconds_Behind_Master的更多相关文章

  1. 备库Seconds_Behind_Master的计算

    背景 在mysql主备环境下,主备同步过程如下,主库更新产生binlog, 备库io线程拉取主库binlog生成relay log.备库sql线程执行relay log从而保持和主库同步. 理论上主库 ...

  2. 请不要用SECONDS_BEHIND_MASTER来衡量MYSQL主备的延迟时间【转】

    本文来自:http://www.woqutech.com/?p=1116 MySQL 本身通过 show slave status 提供了 Seconds_Behind_Master ,用于衡量主备之 ...

  3. 请不要用SECONDS_BEHIND_MASTER来衡量MYSQL主备的延迟时间

    链接:http://www.woqutech.com/?p=1116 MySQL 本身通过 show slave status 提供了 Seconds_Behind_Master ,用于衡量主备之间的 ...

  4. Mysql slave 状态之Seconds_Behind_Master

    在MySQL的主从环境中,我们可以通过在slave上执行show slave status来查看slave的一些状态信息,其中有一个比较重要的参数Seconds_Behind_Master.那么你是否 ...

  5. MySQL slave状态之Seconds_Behind_Master

    在MySQL的主从环境中,我们能够通过在slave上运行show slave status来查看slave的一些状态信息,当中有一个比較重要的參数Seconds_Behind_Master.那么你是否 ...

  6. 获取从库Seconds_Behind_Master监控主从同步

    #!/bin/bash now_date=`date "+%Y-%m-%d,%H:%M:%S"` flag_old=`cat /home/oracle/scripts/flag.t ...

  7. mysql主从同步(5)-同步延迟状态考量(seconds_behind_master和pt-heartbea)

    一般情况下,我们是通过"show slave status \G;"提供的Seconds_Behind_Master值来衡量mysql主从同步的延迟情况.具体说明见:mysql主从 ...

  8. mysql之 误用SECONDS_BEHIND_MASTER衡量MYSQL主备的延迟时间

    链接:http://www.woqutech.com/?p=1116 MySQL 本身通过 show slave status 提供了 Seconds_Behind_Master ,用于衡量主备之间的 ...

  9. MySQL slave状态之Seconds_Behind_Master【转】

    在MySQL的主从环境中,我们可以通过在slave上执行show slave status来查看slave的一些状态信息,其中有一个比较重要的参数Seconds_Behind_Master.那么你是否 ...

随机推荐

  1. IOS init initWith 等相关集中

    1.initWithCoder    当一个view从nib初始化的时候,会调用这个函数.  用keyedArchiver序列化一个类的实力,后面用keyedUnArchiver拿回来的时候会调用到 ...

  2. 第2课 讲解主流三大web服务器之Apache服务器(httpd服务器) - 大型网站高并发架构与自动化运维实战(六)

    基本配置 配置固定IP地址 打开默认的网卡配置文件 cd /etc/sysconfig/network-script/ cp ifcfg-eth0 ifcfg-eth1 vim ifcfg-eth0 ...

  3. 一起刷LeetCode4-Median of Two Sorted Arrays

    实验室太吵了...怎么办啊... ----------------------------------------------------------------------------------- ...

  4. 《Genesis-3D开源游戏引擎完整实例教程-跑酷游戏篇:简介及目录》(附上完整工程文件)

    跑酷游戏制作 游戏类型: 此游戏Demo,为跑酷类游戏. 框架简介: 游戏通常由程序代码和资源组成.如果说模型.贴图.声音之类的可以给游戏环境提供一个物理描述和设置,那么脚本和代码块会给游戏赋予生命, ...

  5. Unity3d自定义脚本模板

    这是一个小技巧,打开Unity安装目录,如: C:\Program Files (x86)\Unity\Editor\Data\Resources\ScriptTemplates /* * * Tit ...

  6. Java并发控制机制详解

    在一般性开发中,笔者经常看到很多同学在对待java并发开发模型中只会使用一些基础的方法.比如Volatile,synchronized.像Lock和atomic这类高级并发包很多人并不经常使用.我想大 ...

  7. sass学习(1)——了解sass

    为什么要选择sass 我们在手写css中,会遇到很多很麻烦的问题.倒不是一些技术的问题,而是工程量的问题.例如,如何可以代替难记的16进制颜色,如何可以让层次更清晰,还有重复的代码该如何偷懒.其实这一 ...

  8. 注意 sizeof 中不要有复杂运算操作

    http://github.tiankonguse.com/blog/2014/12/05/c-base/ 一个比较有意思的问题 #include<stdio.h> ; int f() { ...

  9. DelphiXE7操作sqlite数据库

    准备工作: 1.用SQLiteExpertPers建立一个sqlite数据库. 2.打开delphi xe7. 一.FireDAC法 设置库联接 1.放入FDConnection1控件 2.放入FDC ...

  10. codeforces Ebony and Ivory(水题)

    A. Ebony and Ivory time limit per test 2 seconds memory limit per test 256 megabytes input standard ...