MySQL案例-半同步引起Master实例Crash

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: -------------------------------------------------------------------------------------------------正文-----------------------------------...
-------------------------------------------------------------------------------------------------正文---------------------------------------------------------------------------------------------------------------

场景 : 
Crash发生时的数据库版本: MySQL-5.7.12, 官方标注在5.7.17进行了fix;
开启半同步的主从架构中, 从库开启半同步, 启动/重启slave线程导致Master实例Crash;

结论 :
mysql bug, 附上bug单链接: https://bugs.mysql.com/bug.php?id=79865

问题描述(摘抄):
Description: From 5.7,semi-sync add Ack_receiver thread for listening slave ack,which use select(). But select() can only listen socket fd between 1 and __FD_SET_SIZE(my os is 1024),  when socket fd is bigger than __FD_SET_SIZE, select() has no effect, and can never get  ack from slave,then semi-sync can't run normally.even more,select() use array store fds, when use FD_SET store fd which is bigger than __FD_SET_SIZE, array will overflow,so mysqld may crash。

主要问题就出在tcp连接的select方法, 通常, 操作系统通过宏FD_SET_SIZE来声明一个进程中select能操作的文件描述符的最大数据, 然而通常情况下, 这个FD_SET_SIZE的值仅为1024;

实际上, 用epoll或者poll会比较少, select貌似是用的很少的;


问题复现 :

准备一套MySQL-5.7.12的主从架构, 开启半同步:


为了能尽量简单的启用大量的文件描述符, 这里利用MyISAM分区表的"特性";


这时候在主库上连续执行select语句多次(>5);


这时候看一下主库的文件描述符数量;


那么现在在开启半同步的从库上重启一下slave, 同时tail一下主库的日志;


在重启线程几秒钟之后, 主库就发生了Crash;

PS: 在测试的过程中, 多次执行了select语句, 然后确认主库的半同步状态也是ON的情况下迅速在从库上重启slave, 基本是必现的;
PPS: MyISAM表在open的时候会同时打开所有的分区文件, 所以能比较方便的模拟占用大量文件描述符的情景;
(MyISAM分区表: http://blog.itpub.net/29510932/viewspace-2134679/)
PPPPPPPS:  _(:з」∠)_


附上测试用的脚本与Crash的信息

点击(此处)折叠或打开

  1. CREATE TABLE `myisam_t` (
  2.   `id` int(11) DEFAULT NULL
  3. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
  4. /*!50100 PARTITION BY HASH (id)
  5. PARTITIONS 2000 */


点击(此处)折叠或打开

  1. 2017-04-28T22:10:00.731611+08:00 5092 [Note] Start binlog_dump to master_thread_id(5092) slave_server(13043), pos(, 4)
  2. 2017-04-28T22:10:01.648365+08:00 5092 [Note] Start semi-sync binlog_dump to slave (server_id: 13043), pos(, 4)
  3. *** buffer overflow detected ***: /usr/sbin/mysqld terminated
  4. ======= Backtrace: =========
  5. /lib/x86_64-linux-gnu/libc.so.6(+0x731af)[0x7fcdfc7981af]
  6. /lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x37)[0x7fcdfc81dcf7]
  7. /lib/x86_64-linux-gnu/libc.so.6(+0xf6f10)[0x7fcdfc81bf10]
  8. /lib/x86_64-linux-gnu/libc.so.6(+0xf8c67)[0x7fcdfc81dc67]
  9. /usr/lib/mysql/plugin/semisync_master.so(_ZN12Ack_receiver17get_slave_socketsEP6fd_set+0x83)[0x7fcc73d4a493]
  10. /usr/lib/mysql/plugin/semisync_master.so(_ZN12Ack_receiver3runEv+0x603)[0x7fcc73d4aaf3]
  11. /usr/lib/mysql/plugin/semisync_master.so(ack_receive_handler+0x19)[0x7fcc73d4aba9]
  12. /usr/sbin/mysqld(pfs_spawn_thread+0x1b4)[0xe90784]
  13. /lib/x86_64-linux-gnu/libpthread.so.0(+0x80a4)[0x7fcdfdf650a4]
  14. /lib/x86_64-linux-gnu/libc.so.6(clone+0x6d)[0x7fcdfc80d87d]



点击(此处)折叠或打开

  1. 14:10:01 UTC - mysqld got signal 6 ;
  2. This could be because you hit a bug. It is also possible that this binary
  3. or one of the libraries it was linked against is corrupt, improperly built,
  4. or misconfigured. This error can also be caused by malfunctioning hardware.
  5. Attempting to collect some information that could help diagnose the problem.
  6. As this is a crash and something is definitely wrong, the information
  7. collection process might fail.

  8. key_buffer_size=8388608
  9. read_buffer_size=131072
  10. max_used_connections=5
  11. max_threads=9999
  12. thread_count=8
  13. connection_count=2
  14. It is possible that mysqld could use up to
  15. key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 21899362 K bytes of memory
  16. Hope that's ok; if not, decrease some variables in the equation.

  17. Thread pointer: 0x0
  18. Attempting backtrace. You can use the following information to find out
  19. where mysqld died. If you see no messages after this, something went
  20. terribly wrong...
  21. stack_bottom = 0 thread_stack 0x40000
  22. /usr/sbin/mysqld(my_print_stacktrace+0x2c)[0xe77fec]
  23. /usr/sbin/mysqld(handle_fatal_signal+0x459)[0x7a7019]
  24. /lib/x86_64-linux-gnu/libpthread.so.0(+0xf8d0)[0x7fcdfdf6c8d0]
  25. /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x37)[0x7fcdfc75a067]
  26. /lib/x86_64-linux-gnu/libc.so.6(abort+0x148)[0x7fcdfc75b448]
  27. /lib/x86_64-linux-gnu/libc.so.6(+0x731b4)[0x7fcdfc7981b4]
  28. /lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x37)[0x7fcdfc81dcf7]
  29. /lib/x86_64-linux-gnu/libc.so.6(+0xf6f10)[0x7fcdfc81bf10]
  30. /lib/x86_64-linux-gnu/libc.so.6(+0xf8c67)[0x7fcdfc81dc67]
  31. /usr/lib/mysql/plugin/semisync_master.so(_ZN12Ack_receiver17get_slave_socketsEP6fd_set+0x83)[0x7fcc73d4a493]
  32. /usr/lib/mysql/plugin/semisync_master.so(_ZN12Ack_receiver3runEv+0x603)[0x7fcc73d4aaf3]
  33. /usr/lib/mysql/plugin/semisync_master.so(ack_receive_handler+0x19)[0x7fcc73d4aba9]
  34. /usr/sbin/mysqld(pfs_spawn_thread+0x1b4)[0xe90784]
  35. /lib/x86_64-linux-gnu/libpthread.so.0(+0x80a4)[0x7fcdfdf650a4]
  36. /lib/x86_64-linux-gnu/libc.so.6(clone+0x6d)[0x7fcdfc80d87d]
  37. The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
  38. information that should help you find out what is causing the crash.


相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
29天前
|
关系型数据库 MySQL
elasticsearch对比mysql以及使用工具同步mysql数据全量增量
elasticsearch对比mysql以及使用工具同步mysql数据全量增量
21 0
|
1月前
Mybatis+mysql动态分页查询数据案例——测试类HouseDaoMybatisImplTest)
Mybatis+mysql动态分页查询数据案例——测试类HouseDaoMybatisImplTest)
21 1
|
1月前
|
Java 关系型数据库 数据库连接
Mybatis+MySQL动态分页查询数据经典案例(含代码以及测试)
Mybatis+MySQL动态分页查询数据经典案例(含代码以及测试)
26 1
|
1月前
|
存储 SQL 关系型数据库
创建并配置RDS实例
在阿里云上创建RDS实例涉及登录控制台、进入RDS管理页面、创建实例、选择数据库引擎和版本、配置实例规格与存储、设定网络与安全组、设置实例信息、确认订单并支付,最后初始化数据库。操作步骤可能因界面更新或数据库引擎不同略有差异。
19 1
|
1月前
Mybatis+mysql动态分页查询数据案例——条件类(HouseCondition)
Mybatis+mysql动态分页查询数据案例——条件类(HouseCondition)
15 1
|
1月前
Mybatis+mysql动态分页查询数据案例——分页工具类(Page.java)
Mybatis+mysql动态分页查询数据案例——分页工具类(Page.java)
22 1
|
1月前
Mybatis+mysql动态分页查询数据案例——房屋信息的实现类(HouseDaoMybatisImpl)
Mybatis+mysql动态分页查询数据案例——房屋信息的实现类(HouseDaoMybatisImpl)
22 2
|
1月前
Mybatis+mysql动态分页查询数据案例——工具类(MybatisUtil.java)
Mybatis+mysql动态分页查询数据案例——工具类(MybatisUtil.java)
15 1
|
2天前
|
关系型数据库 MySQL 数据库
一台MySQL数据库启动多个实例
一台MySQL数据库启动多个实例
|
8天前
|
Java 关系型数据库 MySQL
一套java+ spring boot与vue+ mysql技术开发的UWB高精度工厂人员定位全套系统源码有应用案例
UWB (ULTRA WIDE BAND, UWB) 技术是一种无线载波通讯技术,它不采用正弦载波,而是利用纳秒级的非正弦波窄脉冲传输数据,因此其所占的频谱范围很宽。一套UWB精确定位系统,最高定位精度可达10cm,具有高精度,高动态,高容量,低功耗的应用。
一套java+ spring boot与vue+ mysql技术开发的UWB高精度工厂人员定位全套系统源码有应用案例