测试MySQL单机时,无意发现,MySQL 8.0的 ib_logfilesN的显示如下:
ll ib_logfile* -rw-r----- 1 greatsql greatsql 134217728 8月 4 18:36 ib_logfile0 -rw-r----- 1 greatsql greatsql 134217728 7月 27 17:31 ib_logfile1 -rw-r----- 1 greatsql greatsql 134217728 8月 4 18:03 ib_logfile2 -rw-r----- 1 greatsql greatsql 134217728 8月 4 18:36 ib_logfile3
其中ib_logfile0、iblogfile3的 最近改动时间为:2022-08-04 18:36
印象中,MySQL 8.0对 redo 做了大量优化,难道刷盘也做了改变?
赶紧登录到MySQL 重新执行一条insert,再观察一下。
1 ib_logfile* 2 -rw-r----- 1 greatsql greatsql 134217728 8月 9 22:55 ib_logfile0 3 -rw-r----- 1 greatsql greatsql 134217728 7月 27 17:31 ib_logfile1 4 -rw-r----- 1 greatsql greatsql 134217728 8月 4 18:03 ib_logfile2 5 -rw-r----- 1 greatsql greatsql 134217728 8月 9 22:55 ib_logfile3 6 [#3#root@greatsql82 /data/mysql8023/data 22:55:45]3 stat ib_logfile0 7 文件:"ib_logfile0"` 8 大小:134217728 块:262144 IO 块:4096 普通文件 9 设备:fd00h/64768d Inode:75740704 硬链接:1 10 权限:(0640/-rw-r-----) Uid:( 1000/ greatsql) Gid:( 1000/ greatsql) 11 最近访问:2022-08-04 19:22:32.746184752 +0800 12 最近更改:2022-08-09 22:55:40.166964294 +0800 13 最近改动:2022-08-09 22:55:40.166964294 +0800 14 创建时间:-` 15 [#4#root@greatsql82 /data/mysql8023/data 22:56:13]4 stat ib_logfile3 16 文件:"ib_logfile3" 17 大小:134217728 块:262144 IO 块:4096 普通文件 18 设备:******* Inode:75740707 硬链接:1 19 权限:(0640/-rw-r-----) Uid:( 1000/ greatsql) Gid:( 1000/ greatsql) 20 最近访问:2022-08-04 19:22:48.510210526 +0800 21 最近更改:2022-08-09 22:55:39.741963331 +0800 22 最近改动:2022-08-09 22:55:39.741963331 +0800 23 创建时间:-
在MySQL端执行一个事务后,可以看到ib_logfile0、iblogfile3都发生了改变,iblogfile3先改变,iblogfile0后改变,且改动时间相差不到0.42s
赶紧翻一下官网手册
By default, the redo log is physically represented on disk by two files named ib_logfile0 and ib_logfile1. MySQL writes to the redo log files in a circular fashion.
没有新变化,依旧是循环写 (那为啥写了iblogfile3后,还会写iblogfile0呢?)
最直接的当然是去看源码,一切尽在源码中。不过看代码实在太麻烦,不太适合大多数的人,gdb debug 过程,技术要求门槛较高。
有没有一个工具,能让运维人员直观地观测一下呢?
当然有!
sysdig这是笔者在GreatSQL社区了解到的一款观测性神器。
在MySQL执行
insert into test.t values(1,'aa');
追踪如下:
1 sysdig proc.pid=2617 and fd.type=file
2 273983 01:02:18.534336211 1 mysqld (2617.3021) < open fd=39(<f>/data/mysql8023/data/test/t.ibd) name=./test/t.ibd(/data/mysql8023/data/test/t.ibd) flags=1(O_RDONLY) mode=0 dev=FD00
3 `273988 01:02:18.534381910 1 mysqld (2617.3021) > lseek fd=39(<f>/data/mysql8023/data/test/t.ibd) offset=0 whence=1(SEEK_CUR)
4 `273989 01:02:18.534384266 1 mysqld (2617.3021) < lseek res=0
5 `273990 01:02:18.534385778 1 mysqld (2617.3021) > lseek fd=39(<f>/data/mysql8023/data/test/t.ibd) offset=0 whence=2(SEEK_END)
6 `273991 01:02:18.534386657 1 mysqld (2617.3021) < lseek res=114688
7 `273992 01:02:18.534387686 1 mysqld (2617.3021) > lseek fd=39(<f>/data/mysql8023/data/test/t.ibd) offset=0 whence=0(SEEK_SET)
8 `273993 01:02:18.534388675 1 mysqld (2617.3021) < lseek res=0
9 273996 01:02:18.534428831 1 mysqld (2617.3021) > pread fd=39( 来源:https://www.51cto.com/article/717962.html