master硬盘空间不足可能引起的问题

MySQL master硬盘满用引起更新语句阻塞, 表现为select正常, insert, update不能执行却占用线程资源,log出现Too many connections提示, 同时提示Error信息:

mysqld: Disk is full writing './mysql-bin.000295' (Errcode: 28). Waiting for someone to free space... (Expect up to 60 secs delay for server to continue after freeing disk space)

too many connections 引起不能登录, 可临时使用 gdb -p $(cat path/mysql.pid) -ex “set max_connections=5000” -batch增加max_connections的变量值,不过在并发特别大的时候可能会引起Server崩溃。 线程连接超过指定值 ERROR: Can’t create a new thread,可通过临时增加进程limit缓解:echo -n “Max processes=SOFT_LIMIT:HARD_LIMIT” > /proc/pidof mysqld/limits

登录进去后的操作需要考虑以下几点:

1. 不要做flush log相关操作

硬盘已经满了, 一些事件可能在binlog中只记录了一部分, flush 操作需要对描述符进行更新, 可能会引起数据的不完整; 同样的因为flush操作也需要空间来创建新binlog文件, 硬盘没有空间也可能是flush线程和insert, update语句一样处于堵塞状态, 在有空间后才会提交;

2.用purge来清理一些早期的binlog文件

这种方式不需要额外的空间, 只清理已有的数据;

3. 不要kill线程

如第1点说的, 一些事件可能在binlog中只记录了一部分,这个时候kill相关的线程既不能使它提交,也不能使它回退, 可能会引起事件中断, 比如下面slave连接master时提示的错误:

Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'binlog truncated in the middle of event; consider out of disk space on master; the first event 'mysql-bin.000291' at 881945637, the last event read from './mysql-bin.000295' at 579006435, the last byte read from './mysql-bin.000295' at 579006464.'