故障分析 | Binlog 太大导致无法解析怎么办?


外向笑小鸭子
外向笑小鸭子 2024-01-02 10:45:05 51991
分类专栏: 资讯

1故障现象

由于业务写入了一条大事务,导致 MySQL 的 binlog 膨胀。在解析大的 binlog 时,经常会遇到这个问题,导致无法解析,没有其他工具的情况下,很难分析问题。

2故障复现

oot@xuzong mysql]# ls -lh mysql-bin.003300
-rw-r----- 1 my3696 mysql 6.7G Oct 30 16:24 mysql-bin.003300
[root@xuzong mysql]# /usr/local/mysql-5.7.35/bin/mysqlbinlog -vv mysql-bin.003300 > 1.sql
mysqlbinlog: Error writing file '/tmp/tmp.0Uirch' (Errcode: 28 - No space left on device)
mysqlbinlog: Error writing file '/tmp/tmp.0Uirch' (Errcode: 28 - No space left on device)
mysqlbinlog: Error writing file '/tmp/tmp.0Uirch' (Errcode: 28 - No space left on device)
mysqlbinlog: Error writing file '/tmp/tmp.0Uirch' (Errcode: 28 - No space left on device)
mysqlbinlog: Error writing file '/tmp/tmp.334z3P' (Errcode: 28 - No space left on device)
mysqlbinlog: Error writing file '/tmp/tmp.0Uirch' (Errcode: 28 - No space left on device)
mysqlbinlog: Error writing file '/tmp/tmp.0Uirch' (Errcode: 28 - No space left on device)
mysqlbinlog: Error writing file '/tmp/tmp.0Uirch' (Errcode: 28 - No space left on device)
mysqlbinlog: Error writing file '/tmp/tmp.0Uirch' (Errcode: 28 - No space left on device)
mysqlbinlog: Error writing file '/tmp/tmp.0Uirch' (Errcode: 28 - No space left on device)

3猜测

  1. 可能是配置文件中 tmpdir 的问题,但是修改这个得重启 MySQL。
  2. 能不能在不重启 MySQL 的情况下,修改这个临时空间。

4验证猜测

猜测一

看一下 my.cnf 设置的 tmpdir,发现并不是使用的这个参数,看来猜测一不对。

[root@mysql mysql]# cat my.cnf | grep tmpdir
tmpdir                          = /data1/dbatemp

猜测二

网上搜了一下,大部分是讲临时表满怎么解决的,也就是猜测一的方案,并没有很明确的方法来修改 mybinlog 解析时,所使用的的临时句柄占用空间。

5问题分析

只能看看源码,看一下 mysqlbinlog 到底是怎么获取 tmpdir 的。

mysqbinlog.cc

int main(int argc, char** argv)
{
........
  MY_TMPDIR tmpdir;
  tmpdir.list= 0;
  if (!dirname_for_local_load)
  {
    if (init_tmpdir(&tmpdir, 0))
      exit(1);
    dirname_for_local_load= my_strdup(PSI_NOT_INSTRUMENTED,
                                      my_tmpdir(&tmpdir), MY_WME);
  }
........
}

mf_tempdir.cc

my_bool init_tmpdir(MY_TMPDIR *tmpdir, const char *pathlist)
{
  char *end, *copy;
  char buff[FN_REFLEN];
  DBUG_ENTER("init_tmpdir");
  DBUG_PRINT("enter", ("pathlist: %s", pathlist ? pathlist : "NULL"));

  Prealloced_array<char*, 10, true> full_list(key_memory_MY_TMPDIR_full_list);

  memset(tmpdir, 0, sizeof(*tmpdir));
  if (!pathlist || !pathlist[0])
  {
    /* Get default temporary directory */
    pathlist=getenv("TMPDIR"); /* Use this if possible */ //这里能看到是获取的机器环境变量
#if defined(_WIN32)
    if (!pathlist)
      pathlist=getenv("TEMP"); //windows是temp
    if (!pathlist)
      pathlist=getenv("TMP");  //linux是tmp
#endif
    if (!pathlist || !pathlist[0])
      pathlist= DEFAULT_TMPDIR;
  }
........
}

好家伙,竟然是获取的机器环境变量,那么这个问题就解决了。

6问题处理

临时修改一下机器的 tmpdir 变量即可。

[root@mysql mysql]# export TMPDIR="/data1"
[root@mysql mysql]# echo ${TMPDIR:-/tmp}
[root@xuzong mysql]# /usr/local/mysql-5.7.35/bin/mysqlbinlog -vv mysql-bin.003300 > 1.sql

7总结

  1. 有问题先翻翻手册,不行再看看源码。
  2. 可以考虑使用 binlog 解析工具,比如 bin2sql 解决问题。
  3. 可以看看慢日志里是否有记录。

8补充

原来这个问题在 MySQL 官方手册[1] 中有所描述,在此做一个补充。

图片

When running mysqlbinlog against a large binary log, be careful that the filesystem has enough space for the resulting files. To configure the directory that mysqlbinlog uses for temporary files, use the TMPDIR environment variable.

参考资料

[1]

mysqlbinlog: https://dev.mysql.com/doc/refman/8.0/en/mysqlbinlog.html

 

本文关键字:#MySQL# #日志# #源码#

网站声明:如果转载,请联系本站管理员。否则一切后果自行承担。

本文链接:https://www.xckfsq.com/news/show.html?id=34101
赞同 0
评论 0 条
外向笑小鸭子L0
粉丝 0 发表 622 + 关注 私信
上周热门
如何使用 StarRocks 管理和优化数据湖中的数据?  2951
【软件正版化】软件正版化工作要点  2872
统信UOS试玩黑神话:悟空  2833
信刻光盘安全隔离与信息交换系统  2728
镜舟科技与中启乘数科技达成战略合作,共筑数据服务新生态  1261
grub引导程序无法找到指定设备和分区  1226
华为全联接大会2024丨软通动力分论坛精彩议程抢先看!  165
2024海洋能源产业融合发展论坛暨博览会同期活动-海洋能源与数字化智能化论坛成功举办  163
点击报名 | 京东2025校招进校行程预告  163
华为纯血鸿蒙正式版9月底见!但Mate 70的内情还得接着挖...  159
本周热议
我的信创开放社区兼职赚钱历程 40
今天你签到了吗? 27
如何玩转信创开放社区—从小白进阶到专家 15
信创开放社区邀请他人注册的具体步骤如下 15
方德桌面操作系统 14
用抖音玩法闯信创开放社区——用平台宣传企业产品服务 13
我有15积分有什么用? 13
如何让你先人一步获得悬赏问题信息?(创作者必看) 12
2024中国信创产业发展大会暨中国信息科技创新与应用博览会 9
中央国家机关政府采购中心:应当将CPU、操作系统符合安全可靠测评要求纳入采购需求 8

加入交流群

请使用微信扫一扫!