首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >[MYSQL案例][001] MYSQL_BIN_LOG::open_purge_index_file failed to open register file

[MYSQL案例][001] MYSQL_BIN_LOG::open_purge_index_file failed to open register file

原创
作者头像
大大刺猬
发布2023-05-10 23:34:38
发布2023-05-10 23:34:38
2.5K00
代码可运行
举报
文章被收录于专栏:大大刺猬大大刺猬
运行总次数:0
代码可运行

环境/读前须知

MYSQL版本

报错

难易程度(共5级)

是否含模拟脚本

5.7/8.0

[ERROR] [MY-010846] [Server] MYSQL_BIN_LOG::open_purge_index_file failed to open register file.

2

难易度是根据第一次遇到时, 处理时间来判断的, 不一定准确, 请读者自行斟酌.

所给的案例都尽量给出能复现的脚本, 通常是python写的, 偶尔也会有shell写的.

本系列出现的截图均为模拟环境.

报错

mysql启动报错如下

5.7

代码语言:javascript
代码运行次数:0
运行
复制
2023-05-10T14:55:56.958837Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2023-05-10T14:55:56.960049Z 0 [Warning] Insecure configuration for --secure-file-priv: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path.
2023-05-10T14:55:56.960152Z 0 [Note] /soft/mysql_3308/mysqlbase/mysql/bin/mysqld (mysqld 5.7.38-log) starting as process 38376 ...
2023-05-10T14:55:56.969241Z 0 [Warning] Can't create test file /data/mysql_3308/mysqldata/ddcw21.lower-test
2023-05-10T14:55:56.969526Z 0 [Warning] Can't create test file /data/mysql_3308/mysqldata/ddcw21.lower-test
mysqld: File '/data/mysql_3308/mysqllog/binlog/m3308.~rec~' not found (Errcode: 28 - No space left on device)
2023-05-10T14:55:56.972077Z 0 [ERROR] MYSQL_BIN_LOG::open_purge_index_file failed to open register  file.
2023-05-10T14:55:56.972116Z 0 [ERROR] MYSQL_BIN_LOG::open_index_file failed to sync the index file.
2023-05-10T14:55:56.972176Z 0 [ERROR] Aborting

2023-05-10T14:55:56.972246Z 0 [Note] Binlog end
2023-05-10T14:55:56.972810Z 0 [Note] /soft/mysql_3308/mysqlbase/mysql/bin/mysqld: Shutdown complete

8.0

代码语言:javascript
代码运行次数:0
运行
复制
mysqld: File '/data/mysql_3314/mysqllog/binlog/m3314.~rec~' not found (OS errno 28 - No space left on device)
2023-05-10T14:54:25.876802Z 0 [Warning] [MY-011068] [Server] The syntax 'expire-logs-days' is deprecated and will be removed in a future release. Please use binlog_expire_logs_seconds instead.
2023-05-10T14:54:25.876849Z 0 [Warning] [MY-011069] [Server] The syntax '--relay-log-info-file' is deprecated and will be removed in a future release.
2023-05-10T14:54:25.876870Z 0 [Warning] [MY-011069] [Server] The syntax '--relay-log-info-repository' is deprecated and will be removed in a future release.
2023-05-10T14:54:25.876889Z 0 [Warning] [MY-011069] [Server] The syntax '--master-info-repository' is deprecated and will be removed in a future release.
2023-05-10T14:54:25.876954Z 0 [Warning] [MY-010097] [Server] Insecure configuration for --secure-file-priv: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path.
2023-05-10T14:54:25.877032Z 0 [System] [MY-010116] [Server] /soft/mysql_3314/mysqlbase/mysql/bin/mysqld (mysqld 8.0.28) starting as process 37123
2023-05-10T14:54:25.881545Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2023-05-10T14:54:25.881563Z 0 [Warning] [MY-013244] [Server] --collation-server: 'utf8_general_ci' is a collation of the deprecated character set UTF8MB3. Please consider using UTF8MB4 with an appropriate collation instead.
2023-05-10T14:54:25.882567Z 0 [Warning] [MY-010091] [Server] Can't create test file /data/mysql_3314/mysqldata/mysqld_tmp_file_case_insensitive_test.lower-test
2023-05-10T14:54:25.882603Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /data/mysql_3314/mysqldata/ is case insensitive
2023-05-10T14:54:25.887814Z 0 [ERROR] [MY-010846] [Server] MYSQL_BIN_LOG::open_purge_index_file failed to open register file.
2023-05-10T14:54:25.887985Z 0 [ERROR] [MY-010817] [Server] MYSQL_BIN_LOG::open_index_file failed to sync the index file.
2023-05-10T14:54:25.888076Z 0 [ERROR] [MY-010119] [Server] Aborting
2023-05-10T14:54:25.888448Z 0 [System] [MY-010910] [Server] /soft/mysql_3314/mysqlbase/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.28)  MySQL Community Server - GPL

故障分析

从mysql5.7的环境很容易判断出来是空间不足 No space left on device 所以我们使用df查看空间, 发现还比较充足

感兴趣的可以使用gdb断点MYSQL_BIN_LOG::open_purge_index_file去分析(gdb的使用可以看我之前的文章), 但是本系列文章尽量不讲源码.

我们知道文件系统还有个inode的东西用来记录文件信息, 我们查看inode信息如下

inode已经使用完了, 就无法创建文件, 所以我们需要释放inode出来. 可以删除不需要空文件或者小文件.

查找空文件参考命令

代码语言:javascript
代码运行次数:0
运行
复制
find /tmp -size 0 #文件多的话, 会刷屏,使用的时候要注意下

这里就不演示删除空文件了, 因为本来就是我模拟的空文件...

注: binlog.~rec~ 名字是binlog恢复的时候的'临时文件'

解决

删除不需要的空/小文件,释放inode即可.

模拟报错(复现)

python写的.

第一个参数: 路径, 空文件放哪, 放当前目录的话,太多了, 使用ls会卡死....

第二个参数: 多少个空文件, 默认10M

第三个参数: 多少个并发(进程)来创建空文件, 默认8个

代码语言:javascript
代码运行次数:0
运行
复制
python null_file.py /tmp/t20230510dir66 40000000 32
#在/tmp/t20230510dir66目录下面创建40M个空文件, 使用32个进程来创建(单个进程太慢了,就使用多进程)

脚本见文末

总结

日常使用mysql的时候总是会遇到奇奇怪怪的问题, 有的报错并不会直接告诉你原因, 但其实也就常见的那么几个....

我们不但要关系可用空间, 还得关心inode数量(虽然根目录有30M, 几乎不会被使用完, 但还是有使用完的情况).

附脚本

代码语言:javascript
代码运行次数:0
运行
复制
#在 param[0] 目录下面 生成 param[1] 个空文件, 并发为 param[2]

import sys,os
from multiprocessing import Process

dirname = sys.argv[1] if len(sys.argv) > 1 else 'dont_list_by_ddcw'
files = int(sys.argv[2]) if len(sys.argv) > 2 else 10*1000*1000 #默认10MB
parallel = int(sys.argv[3]) if len(sys.argv) > 3 else 8 #默认8个线程


#创建目录
os.makedirs(dirname,exist_ok=True)


#创建文件
def create_empty_file(n,p):#n:文件个数
	for x in range(n):
		try:
			filename = os.path.join(dirname,f'.{p}_{x}')
			os.mknod(filename)
		except:
			break

pl = {}
for x in range(parallel):
	pl[x] = Process(target=create_empty_file,args=(int(files/parallel),x))
for x in range(parallel):
	pl[x].start()
for x in range(parallel):
	pl[x].join()

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 环境/读前须知
  • 报错
    • 5.7
    • 8.0
    • 故障分析
  • 解决
  • 模拟报错(复现)
  • 总结
  • 附脚本
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档