网络闪段致slave 出错分析

告警信息

    check_ins_slave_io_running (err_cnt:1)critical-  slaveio not run on ins:3014,3051,3060,3079,3097,3104,3106,3107,3108,3116,3119,3123,3170,3150,3151
         

复制错误

    错误1:

     Last_IO_Errno: 1159 (ER_NET_READ_INTERRUPTED)

     Last_IO_Error: The slave I/O thread stops because a fatal error is encountered when it try to get the value of SERVER_ID variable from master. Error: 

     错误2:     

    Last_IO_Errno: 1593 (ER_SLAVE_FATAL_ERROR)

    Last_IO_Error: The slave I/O thread stops because SET @master_heartbeat_period on master failed. Error: 

 

分析

 1 首先从告警信息,同一主机出现大量实例的复制错误。首先可以排出是mysql问题。应该是外部环境导致,例如网络,硬件故障等。

 2 错误1159即ER_NET_READ_INTERRUPTED网络中断,由此可以推断是网络问题导致

 3 从错误信息中,Last_IO_Error: The slave I/O thread stops because a fatal error is encountered when it try to get the value of SERVER_ID variable from master。定位源码可看到,IO thread每次启动io_thread从主库拉binlog是都有以下逻辑,(handle_slave_io-> get_master_version_and_clock)检查serverid是否重复,时间钟,时区,字符集,设置master heartbeat等. 此错误是在检查serverid时发生网路中断所致。

  类似的错误还有:

   Get master TIME_ZONE failed with error:xxx

 

处理方法

    stop slave;start slave; 即可恢复 

 

附:

http://dev.mysql.com/doc/refman/5.5/en/change-master-to.html change master 时可以指定MASTER_CONNECT_RETRY表示连接断开重试间隔时间,master-retry-count是mysqld启动命令行参数表示连接重试次数 。http://dev.mysql.com/doc/refman/5.5/en/replication-options-slave.html#option_mysqld_master-retry-count.

 

为什么这个错误没有重连呢,原因是这个错误出现后,用户退出了io_thread线程。重连是io_thread发出的,因此自然就不会重连了。看如下日志:

 

140814  8:40:05 [Note] Event Scheduler: scheduler thread started with id 93413

140814  8:40:49 [ERROR] Slave I/O: The slave I/O thread stops because SET @master_heartbeat_period on master failed. Error: , Error_code: 1593

140814  8:40:49 [Note] Slave I/O thread exiting, read up to log 'mysql-bin.000012', position 107

  

问题:

is_network_error函数判断没有把ER_NET_READ_INTERRUPTED加入到网络错误中。

bool is_network_error(uint errorno)

  if (errorno == CR_CONNECTION_ERROR || 

      errorno == CR_CONN_HOST_ERROR ||

      errorno == CR_SERVER_GONE_ERROR ||

      errorno == CR_SERVER_LOST ||

      errorno == ER_CON_COUNT_ERROR ||

      errorno == ER_SERVER_SHUTDOWN)

    return TRUE;

 

  return FALSE;   

}

这里如果修改认为ER_NET_READ_INTERRUPTED为网络错误,就不会退出io_thread线程,并且会重连。

不过如果这样重连会导致用会忽略get_master_version_and_clock里面的后续检查,这个应该选择退出io_thread线程,而不重连的原因吧。

 

原文地址:https://www.cnblogs.com/justfortaste/p/3915927.html