如何得到Slave应用relay-log的时间
官方社区版MySQL 5.7.19 基于Row+Position搭建的一主一从异步复制结构:Master->{Slave}
| ROLE | HOSTNAME | BASEDIR | DATADIR | IP | PORT |
| Master | ZST1 | /usr/local/mysql | /data/mysql/mysql3307/data | 192.168.85.132 | 3307 |
| Slave | ZST2 | /usr/local/mysql | /data/mysql/mysql3307/data | 192.168.85.133 | 3307 |
最初是想核实延迟复制的master_delay=N以哪个时间作为基准计算,想到如果在Slave的表中添加一个以current_timestamp为默认值的时间列,从库在应用relay-log时将"当前"时间写入。将它和表中原来的时间字段作对比,就可以知道延迟时间。想法貌似不错,但...自以为是...很悲催~
# 测试表结构
mydba@192.168.85.133,3307 [replcrash]> show create table py_user;
+---------+----------------------------------------------+
| Table | Create Table |
+---------+----------------------------------------------+
| py_user | CREATE TABLE `py_user` (
`uid` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(32) DEFAULT NULL,
`add_time` datetime DEFAULT CURRENT_TIMESTAMP,
`server_id` varchar(10) DEFAULT NULL,
PRIMARY KEY (`uid`)
) ENGINE=InnoDB AUTO_INCREMENT=4105 DEFAULT CHARSET=utf8 |
+---------+----------------------------------------------+
1 row in set (0.00 sec) # Slave开启延迟复制
mydba@192.168.85.133,3307 [replcrash]> change master to master_delay = 30;
# 添加参考列
mydba@192.168.85.133,3307 [replcrash]> alter table py_user add ins_time datetime default current_timestamp;
然后往Master写入新数据,并到Slave查看数据
# Slave数据
mydba@192.168.85.133,3307 [replcrash]> select * from py_user;
+-----+--------------------------+---------------------+-----------+---------------------+
| uid | name | add_time | server_id | ins_time |
+-----+--------------------------+---------------------+-----------+---------------------+
| 1 | BD9U7I9W68BTDIXWEEUQNYRX | 2017-12-19 11:07:40 | 1323307 | 2017-12-19 11:07:40 |
| 2 | 9722XBCKISXDBSRDA5VA0A | 2017-12-19 11:07:42 | 1323307 | 2017-12-19 11:07:42 |
+-----+--------------------------+---------------------+-----------+---------------------+
2 rows in set (0.00 sec) # general-log
[root@ZST2 data]# cat mysql-general.log
/usr/local/mysql/bin/mysqld, Version: 5.7.19-log (MySQL Community Server (GPL)). started with:
Tcp port: 3307 Unix socket: /tmp/mysql3307.sock
Time Id Command Argument
...
2017-12-19T03:07:46.515218Z 17 Query truncate table py_user
2017-12-19T03:08:10.516900Z 17 Query BEGIN
2017-12-19T03:08:10.517318Z 17 Query COMMIT /* implicit, from Xid_log_event */
2017-12-19T03:08:12.517930Z 17 Query BEGIN
2017-12-19T03:08:12.518383Z 17 Query COMMIT /* implicit, from Xid_log_event */
2017-12-19T03:08:27.614844Z 3 Query select * from py_user
[root@ZST2 data]#
general-log可以看出Slave确实是晚于Master 30秒才应用,但新写入的记录对应的ins_time并没有滞后add_time 30秒
为什么会出现这种情况?解析relay-log查看日志中是如何记录的
# Slave上的relay-log信息
[root@ZST2 data]# mysqlbinlog -v -vv --base64-output=decode-rows relay-bin.
...
# at
# :: server id end_log_pos CRC32 0x6fdfa523 Query thread_id= exec_time= error_code=
SET TIMESTAMP=/*!*/;
BEGIN
/*!*/;
# at
# :: server id end_log_pos CRC32 0x9edb1d95 Table_map: `replcrash`.`py_user` mapped to number
# at
# :: server id end_log_pos CRC32 0x18252616 Write_rows: table id flags: STMT_END_F
### INSERT INTO `replcrash`.`py_user`
### SET
### @= /* INT meta=0 nullable=0 is_null=0 */
### @='9722XBCKISXDBSRDA5VA0A' /* VARSTRING(96) meta=96 nullable=1 is_null=0 */
### @='2017-12-19 11:07:42' /* DATETIME(0) meta=0 nullable=1 is_null=0 */
### @='' /* VARSTRING(30) meta=30 nullable=1 is_null=0 */
# at
# :: server id end_log_pos CRC32 0x5e49e8d9 Xid =
COMMIT/*!*/; # Slave上的binlog信息
[root@ZST2 logs]# mysqlbinlog -v -vv --base64-output=decode-rows mysql-bin.
...
# at
# :: server id end_log_pos CRC32 0x70e91679 Query thread_id= exec_time= error_code=
SET TIMESTAMP=/*!*/;
BEGIN
/*!*/;
# at
# :: server id end_log_pos CRC32 0x9fcf7ba6 Table_map: `replcrash`.`py_user` mapped to number
# at
# :: server id end_log_pos CRC32 0x17e542da Write_rows: table id flags: STMT_END_F
### INSERT INTO `replcrash`.`py_user`
### SET
### @= /* INT meta=0 nullable=0 is_null=0 */
### @='9722XBCKISXDBSRDA5VA0A' /* VARSTRING(96) meta=96 nullable=1 is_null=0 */
### @='2017-12-19 11:07:42' /* DATETIME(0) meta=0 nullable=1 is_null=0 */
### @='' /* VARSTRING(30) meta=30 nullable=1 is_null=0 */
### @='2017-12-19 11:07:42' /* DATETIME(0) meta=0 nullable=1 is_null=0 */
# at
# :: server id end_log_pos CRC32 0x8557b6ea Xid =
COMMIT/*!*/;
在relay-log/binlog中可以看到SET TIMESTAMP=1513652862/*!*/;
mydba@192.168.85.133,3307 [replcrash]> set timestamp=1513652862;select now();set timestamp=0;select now();
Query OK, 0 rows affected (0.00 sec) +---------------------+
| now() |
+---------------------+
| 2017-12-19 11:07:42 |
+---------------------+
1 row in set (0.00 sec) Query OK, 0 rows affected (0.00 sec) +---------------------+
| now() |
+---------------------+
| 2017-12-20 10:48:49 |
+---------------------+
1 row in set (0.00 sec) mydba@192.168.85.133,3307 [replcrash]>
正是由于设置了TIMESTAMP,从库ins_time列使用current_timestamp默认值时就得到当时的时间。SBR的环境中,时间相关的函数(now(),current_date(),current_time()等),都能安全的复制到Slave的原因也是因为binlog中记录有timestamp
因此上面添加列获取Slave应用relay-log的时间肯定行不通。如果只是偶尔查看的话,可以从general-log中提取~.~
master_delay = N
An event received from the master is not executed until at least N seconds later than its execution on the master. The exceptions are that there is no delay for format description events or log file rotation events, which affect only the internal state of the SQL thread.
如何得到Slave应用relay-log的时间的更多相关文章
- 【故障处理】ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository
今天在使用冷备份文件重做从库时遇到一个报错,值得研究一下. 版本:MySQL5.6.27 一.报错现象 dba:(none)> start slave; ERROR (HY000): Slave ...
- Slave SQL_THREAD如何重放Relay log
复制的介绍: 根据日志定义的模式不一样,可以分为:Statement(SBR)模式,Row(RBR)格式或者是MIXED格式,记录最小的单位是一个Event,binlog日志前4个字节是一个magic ...
- Relay log read failure
root@localhost > show slave status\G*************************** 1. row ************************** ...
- 【FAQ系列】Relay log 导致复制启动失败
今天在使用冷备份文件重做从库时遇到一个报错,值得研究一下. 版本:MySQL5.6.27 一.报错现象 dba:(none)> start slave; ERROR (HY000): Slave ...
- mysql主从同步失败 Relay log read failure: Could not parse relay log event entry
mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQ ...
- 【MySQL】Last_SQL_Errno: 1594Relay log read failure: Could not parse relay log event entry...问题总结处理
备库报错: Last_SQL_Errno: 1594 Last_SQL_Error: Relay log read failure: Could not parse relay log event e ...
- ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository
salve复制线程停止,尝试start slave 时报ERROR 1872错误mysql> system perror 1872 MySQL error code 1872 (ER_SLAVE ...
- Slave failed to initialize relay log info structure from the repository
现象 查看slave 服务状态 show slave status\G; 错误 Last_Errno: 1872 Last_Error: Slave failed to initialize rela ...
- 17.2.2.1 The Slave Relay Log Slave中继日志
17.2.2.1 The Slave Relay Log Slave中继日志 中继日志, 像binary log,有一组文件组成包含events 描述数据库的修改,和一个index文件包含所有使用过的 ...
- mysql5.7启动slave报错 ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository
原因:检查my.cnf,原来没指定relay_log,mysql默认产生的relay_log名被该server上的另一个mysql slave占用了. 解决方法:1.在my.cnf中添加 relay_ ...
随机推荐
- Linux内核分析第十八章读书笔记
第十八章 调试 调试工作艰难是内核级开发区别于用户级开发的一个显著特点. 18.1 准备开始 我们需要什么? 一个bug 一个藏匿bug的内核版本 思路:假定能够让bug重现 在用户级程序中,bug直 ...
- Serial,Parallel,CMS,G1四大GC收集器特点小结
1.Serial收集器一个单线程的收集器,在进行垃圾收集时候,必须暂停其他所有的工作线程直到它收集结束.特点:CPU利用率最高,停顿时间即用户等待时间比较长.适用场景:小型应用通过JVM参数-XX:+ ...
- 从0到1搭建基于Kafka、Flume和Hive的海量数据分析系统(一)数据收集应用
大数据时代,一大技术特征是对海量数据采集.存储和分析的多组件解决方案.而其中对来自于传感器.APP的SDK和各类互联网应用的原生日志数据的采集存储则是基本中的基本.本系列文章将从0到1,概述一下搭建基 ...
- 如何有效地让一个“ParentFont = False”子控件使用与父母相同的字体名称?
如何有效地让一个“ParentFont = False”子控件使用与父母相同的字体名称?(How to efficiently let a `ParentFont = False` child con ...
- 洛谷P4831 Scarlet loves WenHuaKe
这道题告诉我们推式子的时候头要够铁. 题意 问一个\(n\times m\)的棋盘,摆上\(n\times 2\)个中国象棋的炮使其两两不能攻击的方案数,对\(998244353\)取模. \((n\ ...
- 【大数据】Spark内核解析
1. Spark 内核概述 Spark内核泛指Spark的核心运行机制,包括Spark核心组件的运行机制.Spark任务调度机制.Spark内存管理机制.Spark核心功能的运行原理等,熟练掌握Spa ...
- 【大数据】SparkSql学习笔记
第1章 Spark SQL概述 1.1 什么是Spark SQL Spark SQL是Spark用来处理结构化数据的一个模块,它提供了2个编程抽象:DataFrame和 DataSet,并且作为分布式 ...
- tomcat 启用NIO
从Tomcat6.0以后, Java开发者很容易就可以是用NIO的技术来提升tomcat的并发处理能力. <Connector port="8080" protocol=&q ...
- Java 基本数据类型 sizeof 功能
Java 基本数据类型 sizeof 功能 来源 https://blog.csdn.net/ithomer/article/details/7310008 Java基本数据类型int 32b ...
- 在c语言中嵌入汇编语句,对于我来说相当难。
今天早上在csdn论坛上看到一个帖子http://topic.csdn.net/u/20120917/14/82f42e17-977a-4824-95bd-7b79db15d283.html:“C语言 ...