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. POJ2987 Firing 最大权闭合图

    详情请参考http://www.cnblogs.com/kane0526/archive/2013/04/05/3001557.html 值得注意的地方,割边会把图分成两部分,一部分和起点相连,另一部 ...

  2. 为Fitnesse-20140630定制RestFixture代码

    摘要:Fitnesse插件RestFixture在最新版Fitnesse输出测试结果为html文本,而非html.本博文记录RestFixture定制代码的过程. 准备开发环境 假定你已经正确安装JD ...

  3. Oracle中错误代码ORA-02292 违反了完整性约束条件解决

    百度处理: A表被B表引用,删除A表的时候提示ORA-02292,A表的主键被引用了,虽然已经把B表的数据全部删除掉,但仍然删除不了A表的数据.解决办法: 用禁用约束语句把A表的主键约束给禁用掉.1. ...

  4. 【ActiveX】实现安全接口

    转自:http://www.cnblogs.com/carekee/articles/1772201.html 感谢原作者! ActiveX控件打包成cab后,在脚本中调用中时,要保证控件的安全性才能 ...

  5. 在这个年纪,打DOTA冲分有那么可笑么?

    大学四年,毕业两年,6年dota,总是在最无助的时候让心灵得到一丝安宁的东西,烟和dota. 我不知道dota对别人的意义是什么,一盘dota,在最多不超过1个半小时的时间里,仿佛经历了一个小人生,每 ...

  6. The Services(服务)

    datastore和运行时环境的关系就是和一个服务的关系:应用使用API访问一个独立的系统(separate system),这个系统管理应用的所有的独立于应用实例的扩展需求(scaling need ...

  7. javascript !!作用

    javaScript中使用!!表示取得boolean值,具体作用如下 var value= !!test[1]; 取变量的Boolean值, 相当于 var value = test[1]?true: ...

  8. [转载] I wish you enough

    几天前,我在机场无意中听到一对父女告别时最后一刻的对白.广播员已经通知大家准备登机了.他们站在安检口旁边紧紧拥抱,父亲对女儿说:“我爱你,希望你一切都充足!” 女儿回答:“爸爸,我是那么满足我们在一起 ...

  9. 大道至简—SQLite3 使用教学

    OS X自从10.4后把SQLite这套相当出名的数据库软件,放进了作业系统工具集里.OS X包装的是第三版的SQLite,又称SQLite3.这套软件有几个特色:        软件属于公共财(pu ...

  10. hdu 2063 过山车(匈牙利算法模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=2063 过山车 Time Limit: 1000/1000 MS (Java/Others)    Memory ...