一、问题表现
半同步复制的Mysql集群,从库设置了super_read_only,但突然莫名其妙多出一个事务,如下图;
从库突然出现了自己的事务、或者比主库多出事务。
导致的问题:
1、这个事务不能闪回,这个从库无法作为容灾备用节点,需要人工介入处理;
2、由于主从表数据不一致,会复制异常,如1062、1032的报错;
二、问题原因
实例启动后第一次使用Memory引擎表,Server层会清空该表并写入binlog。
like this:
官网解释如下:
When a replication source server shuts down and restarts, its MEMORY tables become empty. To replicate this effect to replicas, the first time that the source uses a given MEMORY table after startup, it logs an event that notifies replicas that the table must be emptied by writing a DELETE or (from MySQL 8.0.22) TRUNCATE TABLE statement for that table to the binary log. This generated event is identifiable by a comment in the binary log, and if GTIDs are in use on the server, it has a GTID assigned. The statement is always logged in statement format, even if the binary logging format is set to ROW, and it is written even if read_only or super_read_only mode is set on the server.
三、可行的解决办法
对于半同步复制、异步复制的Mysql高可用集群,业务上应当禁用memory引擎表,或通过参数disabled_storage_engines进行限制。