修改FEDERATED引擎表数据引起的从库宕机,改表需谨慎

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介:
FEDERATED表不仅可以读,而且可以被修改。主从复制中如果用到了FEDERATED表,当在主库修改此表时,会引起从库宕机。宕机原因不太清楚。

测试mysql版本:percona server 5.6.29
主库:192.168.1.25:3306
从库:192.168.1.25:3307
单机:192.168.1.26:33060

在192.168.1.26:33060上建表
CREATE TABLE tt (
id int(11) NOT NULL AUTO_INCREMENT,
d date DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
插入两条数据:
insert into tt (d) select '2017-10-23';
insert into tt (d) select '2017-10-23';

在192.168.1.25:3306上建FEDERATED表
CREATE TABLE tt (
id int(11) NOT NULL AUTO_INCREMENT,
d date DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=FEDERATED DEFAULT CHARSET=latin1 CONNECTION='mysql://dba:XXXXXXX@192.168.1.26:33060/ssq/tt'

在192.168.1.25:3306上执行update操作:

mysql> select * from tt;
id d
1 2017-10-23
2 2017-10-23

2 rows in set (0.00 sec)

mysql> update tt set d='2017-10-24';
Query OK, 2 rows affected (0.01 sec)
Rows matched: 2 Changed: 2 Warnings: 0

此时,192.168.1.25:3307实例直接挂掉,日志如下:
03:14:23 UTC - mysqld got signal 11 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help
diagnose the problem, but since we have already crashed,
something is definitely wrong and this may fail.
Please help us make Percona Server better by reporting any
bugs at http://bugs.percona.com/

key_buffer_size=67108864
read_buffer_size=2097152
max_used_connections=1
max_threads=1502
thread_count=3
connection_count=1
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 15466807 K bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

Thread pointer: 0x7fa927c13000
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 7fa928b61820 thread_stack 0x30000
/opt/mysql/bin/mysqld(my_print_stacktrace+0x2c)[0x8f8bbc]
/opt/mysql/bin/mysqld(handle_fatal_signal+0x461)[0x67de61]
/lib64/libpthread.so.0(+0xf7e0)[0x7faa0e19f7e0]
/opt/mysql/bin/mysqld(_ZN12ha_federated7rnd_posEPhS0_+0x2f)[0x95167f]
/opt/mysql/bin/mysqld(_ZN7handler10ha_rnd_posEPhS0_+0x65)[0x5c1f95]
/opt/mysql/bin/mysqld(_ZN14Rows_log_event24do_index_scan_and_updateEPK14Relay_log_info+0x1fb)[0x88f58b]
/opt/mysql/bin/mysqld(_ZN14Rows_log_event14do_apply_eventEPK14Relay_log_info+0x526)[0x88e906]
/opt/mysql/bin/mysqld(_ZN9Log_event11apply_eventEP14Relay_log_info+0x6a)[0x887eba]
/opt/mysql/bin/mysqld(_Z26apply_event_and_update_posPP9Log_eventP3THDP14Relay_log_info+0x25e)[0x8bf82e]
/opt/mysql/bin/mysqld(handle_slave_sql+0x11cb)[0x8c342b]
/opt/mysql/bin/mysqld(pfs_spawn_thread+0x143)[0x930853]
/lib64/libpthread.so.0(+0x7aa1)[0x7faa0e197aa1]
/lib64/libc.so.6(clone+0x6d)[0x7faa0c6a4bcd]

Trying to get some variables.
Some pointers may be invalid and cause the dump to abort.
Query (0): is an invalid pointer
Connection ID (thread ID): 3
Status: NOT_KILLED

You may download the Percona Server operations manual by visiting
http://www.percona.com/software/percona-server/. You may find information
in the manual which will help you identify the cause of the crash.

192.168.1.25:3306的binlog:
BINLOG '
j3XlWRPR/wEALQAAAIYJAAAAAJwAAAAAAAEAA3NzcQACdHQAAgMKAAK8YmJy
j3XlWR/R/wEARAAAAMoJAAAAAJwAAAAAAAEAAgAC///8AQAAAFfDD/wBAAAAWMMP/AIAAABXww/8
AgAAAFjDD0wm4Ys=
'/!/;

UPDATE ssq.tt

WHERE

@1=1 / INT meta=0 nullable=0 is_null=0 /

@2='2017:10:23' / DATE meta=0 nullable=1 is_null=0 /

SET

@1=1 / INT meta=0 nullable=0 is_null=0 /

@2='2017:10:24' / DATE meta=0 nullable=1 is_null=0 /

UPDATE ssq.tt

WHERE

@1=2 / INT meta=0 nullable=0 is_null=0 /

@2='2017:10:23' / DATE meta=0 nullable=1 is_null=0 /

SET

@1=2 / INT meta=0 nullable=0 is_null=0 /

@2='2017:10:24' / DATE meta=0 nullable=1 is_null=0 /

at 2506

171017 11:14:23 server id 1025 end_log_pos 2578 CRC32 0x42bf2f4a Query thread_id=61141 exec_time=0 error_code=0

SET TIMESTAMP=1508210063/!/;
COMMIT

192.168.1.25:3307的relay log,从show slave status可以看出,就是从库执行到下面这个事务时宕机了。
BINLOG '
j3XlWRPR/wEALQAAAIYJAAAAAJwAAAAAAAEAA3NzcQACdHQAAgMKAAK8YmJy
j3XlWR/R/wEARAAAAMoJAAAAAJwAAAAAAAEAAgAC///8AQAAAFfDD/wBAAAAWMMP/AIAAABXww/8
AgAAAFjDD0wm4Ys=
'/!/;

UPDATE ssq.tt

WHERE

@1=1 / INT meta=0 nullable=0 is_null=0 /

@2='2017:10:23' / DATE meta=0 nullable=1 is_null=0 /

SET

@1=1 / INT meta=0 nullable=0 is_null=0 /

@2='2017:10:24' / DATE meta=0 nullable=1 is_null=0 /

UPDATE ssq.tt

WHERE

@1=2 / INT meta=0 nullable=0 is_null=0 /

@2='2017:10:23' / DATE meta=0 nullable=1 is_null=0 /

SET

@1=2 / INT meta=0 nullable=0 is_null=0 /

@2='2017:10:24' / DATE meta=0 nullable=1 is_null=0 /

at 2068

171017 11:14:23 server id 1025 end_log_pos 2578 CRC32 0x42bf2f4a Query thread_id=61141 exec_time=0 error_code=0

SET TIMESTAMP=1508210063/!/;
COMMIT

总结:
主库192.168.1.25:3306执行 update tt set d='2017-10-24';
会修改192.168.1.26:33060原表数据
主库产生的binlog传到从库,当从库执行update时会导致从库宕机,
理论上来讲,从库执行update时候数据已经被主库修改,这会导致从库更新不到数据,服务挂掉原因尚不清楚。欢迎大家讨论。

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
存储 运维 安全
数据库运维之InnoDB存储引擎表损坏修复方法
InnoDB存储引擎表的损坏可能是多种因素导致的,比如服务器断电、系统崩溃、硬盘损坏、写数据过程中mysqld进程被kill掉。
1029 0
|
关系型数据库 MySQL 数据库
数据库同步功能要慎用
数据库同步功能要慎用
81 0
|
关系型数据库 数据库
批量修改数据库的引擎由MyISAM 修改为 InnoDB
批量修改数据库的引擎由MyISAM 修改为 InnoDB
69 0
|
SQL 前端开发 关系型数据库
MySQL主从复制--单库复制搭建
MySQL主从复制的基本步骤大致一致,这里通过一次业务操作的库级别复制,大致梳理下主从复制搭建的核心过程
375 0
|
关系型数据库 MySQL SQL
mysql主从复制、半同步复制配置记录
mysql主从复制、半同步复制配置记录
1599 0
|
SQL 关系型数据库 MySQL
undrop-for-innodb实测(一)-- 表结构恢复
undrop是一款针对mysql innodb的数据恢复工具,通过扫描文件或磁盘设备,然后解析innodb数据页进而恢复丢失的数据,对于drop、truncate以及文件损坏都很有帮助。本文介绍drop操作后表结构的恢复过程。
4131 0
|
存储 监控 关系型数据库
MySQL探秘(四):InnoDB的磁盘文件及落盘机制
任何一个技术都有其底层的关键基础技术,这些关键技术很有可能也是其他技术的关键技术,学习这些底层技术,就可以一通百通,让你很快的掌握其他技术。如何在磁盘上存储数据,如何使用日志文件保证数据不丢失以及如何落盘,不仅是MySQL等数据库的关键技术,也是MQ消息队列或者其他中间件的关键技术之一
下一篇
无影云桌面