一、问题来源
类似如下:
show master status
file : mysql-bin.000001
pos : 102400
ll 拿到的:
102100 Jul 20 18:17 mysql-bin.000001
如果有压力的情况下可能看到这样的现象,也就是物理文件比show master status的要小
二、原因
原因在于flush阶段分为2步:
- 写入binlog的io cache,可以当成一个缓存
process_flush_stage_queue - 然后flush io cache到物理文件
flush_cache_to_file
而对于show master status来讲获取的位置为binlog的io cache的位置,show_master_status函数为其入口函数,获取的方式如下:
static inline my_off_t my_b_tell(const IO_CACHE *info)
{
return info->pos_in_file + (*info->current_pos - info->request_pos);
}
通过在process_flush_stage_queue后进行debug如下:
image.png
image.png
三、问题
5.6、5.7 show_master_status会获取LOCK_log锁,flush阶段整个也会处于LOCK_log下,按理说不会出现这种问题。锁会互斥。
从IO cache的地址来看也是同一个
-
show master status
my_b_tell (info=0x2dc0d28 <mysql_bin_log+840>) -
写入IO CACHE
(gdb) p &(this->log_file)
$34 = (IO_CACHE *) 0x2dc0d28 <mysql_bin_log+840>
询问后发现这是5.5,不做研究了
备用栈:
(gdb) bt
#0 setup_io_cache (info=0x42ccf50) at /opt/percona-server-locks-detail-5.7.22/mysys/mf_iocache.c:102
#1 0x000000000188a425 in init_functions (info=0x42ccf50) at /opt/percona-server-locks-detail-5.7.22/mysys/mf_iocache.c:164
#2 0x000000000188af8b in reinit_io_cache (info=0x42ccf50, type=READ_CACHE, seek_offset=0, use_async_io=0 '\000', clear_cache=0 '\000')
at /opt/percona-server-locks-detail-5.7.22/mysys/mf_iocache.c:489
#3 0x0000000001813b0a in MYSQL_BIN_LOG::do_write_cache (this=0x2dc09e0 <mysql_bin_log>, cache=0x42ccf50, writer=0x7fffec109eb0)
at /opt/percona-server-locks-detail-5.7.22/sql/binlog.cc:7953
#4 0x00000000018144f0 in MYSQL_BIN_LOG::write_cache (this=0x2dc09e0 <mysql_bin_log>, thd=0x4172090, cache_data=0x42ccf48, writer=0x7fffec109eb0)
at /opt/percona-server-locks-detail-5.7.22/sql/binlog.cc:8262
#5 0x00000000018053d4 in binlog_cache_data::flush (this=0x42ccf48, thd=0x4172090, bytes_written=0x7fffec109f48, wrote_xid=0x7fffec109f87)
at /opt/percona-server-locks-detail-5.7.22/sql/binlog.cc:1718
#6 0x0000000001820f40 in binlog_cache_mngr::flush (this=0x42ccd90, thd=0x4172090, bytes_written=0x7fffec109f88, wrote_xid=0x7fffec109f87)
at /opt/percona-server-locks-detail-5.7.22/sql/binlog.cc:945
#7 0x00000000018168e1 in MYSQL_BIN_LOG::flush_thread_caches (this=0x2dc09e0 <mysql_bin_log>, thd=0x4172090) at /opt/percona-server-locks-detail-5.7.22/sql/binlog.cc:9084
#8 0x0000000001816ae2 in MYSQL_BIN_LOG::process_flush_stage_queue (this=0x2dc09e0 <mysql_bin_log>, total_bytes_var=0x7fffec10a0c8, rotate_var=0x7fffec10a0c7, out_queue_var=0x7fffec10a0b8)
at /opt/percona-server-locks-detail-5.7.22/sql/binlog.cc:9147
#9 0x0000000001817ff8 in MYSQL_BIN_LOG::ordered_commit (this=0x2dc09e0 <mysql_bin_log>, thd=0x4172090, all=false, skip_commit=false)
at /opt/percona-server-locks-detail-5.7.22/sql/binlog.cc:9782
#10 0x00000000018166f1 in MYSQL_BIN_LOG::commit (this=0x2dc09e0 <mysql_bin_log>, thd=0x4172090, all=false) at /opt/percona-server-locks-detail-5.7.22/sql/binlog.cc:9033
#11 0x0000000000f54824 in ha_commit_trans (thd=0x4172090, all=false, ignore_global_read_lock=false) at /opt/percona-server-locks-detail-5.7.22/sql/handler.cc:1830
#12 0x0000000001676337 in trans_commit_stmt (thd=0x4172090) at /opt/percona-server-locks-detail-5.7.22/sql/transaction.cc:458
#13 0x0000000001570408 in mysql_execute_command (thd=0x4172090, first_level=true) at /opt/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:5293
#14 0x0000000001571bed in mysql_parse (thd=0x4172090, parser_state=0x7fffec10c5b0) at /opt/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:5901
#15 0x000000000156673d in dispatch_command (thd=0x4172090, com_data=0x7fffec10cd90, command=COM_QUERY) at /opt/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:1490
#16 0x00000000015655c5 in do_command (thd=0x4172090) at /opt/percona-server-locks-detail-5.7.22/sql/sql_parse.cc:1021
#17 0x00000000016a635c in handle_connection (arg=0x3c2b360) at /opt/percona-server-locks-detail-5.7.22/sql/conn_handler/connection_handler_per_thread.cc:312
#18 0x00000000018ce0b2 in pfs_spawn_thread (arg=0x2fa9160) at /opt/percona-server-locks-detail-5.7.22/storage/perfschema/pfs.cc:2190
#19 0x00007ffff7bc6ea5 in start_thread () from /lib64/libpthread.so.0
#20 0x00007ffff66748dd in clone () from /lib64/libc.so.6
网友评论