mysql flush logs 1105_mysql flush logs

最近遇到一台mysql机器,空间不足,查看后发现是slow log文件占了大量空间(ext4),果断rm掉,然后再flush logs。flush logs的时候发现mysql会hang住。翻了一下flush logs的逻辑,执行flush logs的时候,mysql会执行reopen_file操作,reopen_file()先closeslow log file,再open,而这个过程是持有LOCK_log锁。目前mysql server层日志(slow/general/binary log)的写操作是都需要持有这个锁的。

这样,问题就来了。前面执行rm操作的时候,mysqld还在写对应的slow log,因此系统不会真正的删除这个文件,而执行flush logs操作的时候,mysql会去调用close()操作。close的manual是这么写的:

NAME

close - close a file descriptor

DESCRIPTION

close() closes a file descriptor, so that it no longer refers to any file and

may be reused. Any record locks (see fcntl(2)) held on the file it was associ-

ated with, and owned by the process, are removed (regardless of the file

descriptor that was used to obtain the lock).

If fd is the last copy of a particular file descriptor the resources associated

with it are freed; if the descriptor was the last reference to a file which has

been removed using unlink(2) the file is deleted.

linux删除文件的机制再加上mysql的LOCK_log这把大锁就会引起mysql hang住。类似的general log也会有这个问题。正确的做法是,将slow/general log mv成另外一个名字,再执行flush log操作,然后再去rm对应的文件。

链接:

http://www.mysqlperformanceblog.com/2007/12/09/be-careful-rotating-mysql-logs/

http://digital-forensics.sans.org/blog/2010/12/20/digital-forensics-understanding-ext4-part-1-extents

http://digital-forensics.sans.org/blog/2011/03/28/digital-forensics-understanding-ext4-part-3-extent-trees

http://digital-forensics.sans.org/blog/2011/04/08/understanding-ext4-part-4-demolition-derby

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值