运行环境

linuxCentOS release 6.8 (Final)

kernel:2.6.32-642.6.2.el6.x86_64

mysql Server version: 5.7.21-20-log Percona Server (GPL),MGR单主模式

1.故障现象

解析binlog

mysqlbinlog -v --base64-output=DECODE-ROWS mysql-bin.000042 --include-gtids='1bb1b861-f776-11e6-3319-010204058070:113111655'

1bb1b861-f776-11e6-3319-010204058070:113111655 该GTID的binlog内容 ycc01 与ycc03服务器内容一致

  

  1. ycc01.prod.bj2 mysql_3319
  2.  
  3. SET @@SESSION.GTID_NEXT= '1bb1b861-f776-11e6-3319-010204058070:113111655'/*!*/;
  4. # at
  5. # :: server id end_log_pos Query thread_id= exec_time= error_code=
  6. SET TIMESTAMP=/*!*/;
  7. BEGIN
  8. /*!*/;
  9. # at
  10. # :: server id end_log_pos Table_map: `ycc_cfcenter`.`config_center_client_list` mapped to number
  11. # at
  12. # :: server id end_log_pos Delete_rows: table id flags: STMT_END_F
  13. ### DELETE FROM `ycc_cfcenter`.`config_center_client_list`
  14. ### WHERE
  15. ### @=
  16. ### @=
  17. ### @='10.1.97.131'
  18. ### @=''
  19. ### @=
  20. # at
  21. # :: server id end_log_pos Xid =
  22. COMMIT/*!*/;
  23.  
  24. ycc03.prod.bj2 mysql_3319
  25.  
  26. SET @@SESSION.GTID_NEXT= '1bb1b861-f776-11e6-3319-010204058070:113111655'/*!*/;
  27. # at
  28. # :: server id end_log_pos Query thread_id= exec_time= error_code=
  29. SET TIMESTAMP=/*!*/;
  30. BEGIN
  31. /*!*/;
  32. # at
  33. # :: server id end_log_pos Table_map: `ycc_cfcenter`.`config_center_client_list` mapped to number
  34. # at
  35. # :: server id end_log_pos Delete_rows: table id flags: STMT_END_F
  36. ### DELETE FROM `ycc_cfcenter`.`config_center_client_list`
  37. ### WHERE
  38. ### @=
  39. ### @=
  40. ### @='10.1.97.131'
  41. ### @=''
  42. ### @=
  43. # at
  44. # :: server id end_log_pos Xid =
  45. COMMIT/*!*/;
 

mysqlbinlog -v --base64-output=DECODE-ROWS mysql-bin.000042 --include-gtids='1bb1b861-f776-11e6-3319-010204058070:113111656'

1bb1b861-f776-11e6-3319-010204058070:113111656 该GTID的binlog内容 ycc01 与ycc03服务器内容不一致

  1. ycc01.db.prod.bj2 mysql_3319
  2.  
  3. SET @@SESSION.GTID_NEXT= '1bb1b861-f776-11e6-3319-010204058070:113111656'/*!*/;
  4. # at
  5. # :: server id end_log_pos Query thread_id= exec_time= error_code=
  6. SET TIMESTAMP=/*!*/;
  7. BEGIN
  8. /*!*/;
  9. # at
  10. # :: server id end_log_pos Table_map: `ycc_cfcenter`.`config_center_client_list` mapped to number
  11. # at
  12. # :: server id end_log_pos Delete_rows: table id flags: STMT_END_F
  13. ### DELETE FROM `ycc_cfcenter`.`config_center_client_list`
  14. ### WHERE
  15. ### @=
  16. ### @=
  17. ### @='10.1.94.137'
  18. ### @=''
  19. ### @=
  20. # at
  21. # :: server id end_log_pos Xid =
  22. COMMIT/*!*/;
  23.  
  24. ycc03.db.prod.bj2 mysql_3319
  25. SET @@SESSION.GTID_NEXT= '1bb1b861-f776-11e6-3319-010204058070:113111656'/*!*/;
  26. # at
  27. # :: server id end_log_pos Query thread_id= exec_time= error_code=
  28. SET TIMESTAMP=/*!*/;
  29. BEGIN
  30. /*!*/;
  31. # at
  32. # :: server id end_log_pos Table_map: `ycc_cfcenter`.`config_center_client_list` mapped to number
  33. # at
  34. # :: server id end_log_pos Write_rows: table id flags: STMT_END_F
  35. ### INSERT INTO `ycc_cfcenter`.`config_center_client_list`
  36. ### SET
  37. ### @=
  38. ### @=
  39. ### @='10.1.97.131'
  40. ### @=''
  41. ### @=
  42. # at
  43. # :: server id end_log_pos Xid =
  44. COMMIT/*!*/;

2.原因排查

官方已经反馈社区版MySQL 5.7.26和MySQL 8.0.16 中会修复,如果是企业版客户可以申请最新的hotfix版本。

在未升级 MySQL 版本前,若再发生此类故障,在修复时需要人工检查,检查切换时binlog中 GTID 信息与新主节点对应 GTID 的信息是否一致

如果不一致需要人工修复至一致状态,一致才可以将被踢出的原主节点加回集群。

参考文档

https://mp.weixin.qq.com/s/WuYRp2DU2uRq0vN-b29PPA?client=tim&ADUIN=190100183&ADSESSION=1555029984&ADTAG=CLIENT.QQ.5603_.0&ADPUBNO=26882

3.修复过程

3.1 确定故障点

查看故障节点error.log

error.log
2019-04-12T12:41:45.834694+08:00 3561943 [ERROR] Slave SQL for channel 'group_replication_applier': Could not execute Write_rows event on table ycc_cfcenter.config_center_client_list; Duplicate entry '1
36-10.1.94.137-5566' for key 'uniq_idx_project_id', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log FIRST, end_log_pos 327, Error_code: 1062
2019-04-12T12:41:45.834713+08:00 3561943 [Warning] Slave: Duplicate entry '136-10.1.94.137-5566' for key 'uniq_idx_project_id' Error_code: 1062

查看故障节点当前GTID

故障节点当前GTID
SHOW MASTER STATUS
FILE               POSITION  Binlog_Do_DB  Binlog_Ignore_DB  Executed_Gtid_Set                                
----------------  ---------  ------------  ----------------  --------------------------------------------------
mysql-bin.000042  747898223                                  1bb1b861-f776-11e6-3319-010204058070:1-113111661

解析故障节点包含【1bb1b861-f776-11e6-3319-010204058070:1-113111661】 GTID 的binlog 
##mysqlbinlog -vvv relay-bin-group_replication_applier.000053 --include-gtids="1bb1b861-f776-11e6-3319-010204058070:113111661"

故障节点binlog解析
SET @@SESSION.GTID_NEXT= '1bb1b861-f776-11e6-3319-010204058070:113111661'/*!*/;
# at 703004277
#190412 12:41:45 server id 58070  end_log_pos 81        Query   thread_id=4163376       exec_time=0     error_code=0
SET TIMESTAMP=1555044105/*!*/;
BEGIN
/*!*/;
# at 703004358
#190412 12:41:45 server id 58070  end_log_pos 161       Table_map: `ycc_cfcenter`.`config_center_client_list` mapped to number 108
# at 703004438
#190412 12:41:45 server id 58070  end_log_pos 327       Write_rows: table id 108 flags: STMT_END_F
 
BINLOG '
'/*!*/;
### INSERT INTO `ycc_cfcenter`.`config_center_client_list`
### SET
###   @1=380183781 /* LONGINT meta=0 nullable=0 is_null=0 */
###   @2=206 /* LONGINT meta=0 nullable=1 is_null=0 */
###   @3='10.1.97.133' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
###   @4='5566' /* VARSTRING(90) meta=90 nullable=1 is_null=0 */
###   @5=1555044105821 /* LONGINT meta=0 nullable=1 is_null=0 */
### INSERT INTO `ycc_cfcenter`.`config_center_client_list`
### SET
###   @1=380183788 /* LONGINT meta=0 nullable=0 is_null=0 */
###   @2=136 /* LONGINT meta=0 nullable=1 is_null=0 */
###   @3='10.1.94.137' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
###   @4='5566' /* VARSTRING(90) meta=90 nullable=1 is_null=0 */
###   @5=1555044105821 /* LONGINT meta=0 nullable=1 is_null=0 */
### INSERT INTO `ycc_cfcenter`.`config_center_client_list`
### SET
###   @1=380183795 /* LONGINT meta=0 nullable=0 is_null=0 */
###   @2=206 /* LONGINT meta=0 nullable=1 is_null=0 */
###   @3='10.1.97.131' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
###   @4='5566' /* VARSTRING(90) meta=90 nullable=1 is_null=0 */
###   @5=1555044105821 /* LONGINT meta=0 nullable=1 is_null=0 */
# at 703004604
#190412 12:41:45 server id 58070  end_log_pos 354       Xid = 604665142
COMMIT/*!*/;

解析主节点binlog 确定相同内容binlog event 对应的GTID值 
##mysqlbinlog -vvv mysql-bin.000042 --include-gtids="1bb1b861-f776-11e6-3319-010204058070:113111660-113111665'

主库binlog解析
SET @@SESSION.GTID_NEXT= '1bb1b861-f776-11e6-3319-010204058070:113111662'/*!*/;
# at 418536376
#190412 12:41:45 server id 58070  end_log_pos 418536457         Query   thread_id=4163376       exec_time=0     error_code=0
SET TIMESTAMP=1555044105/*!*/;
BEGIN
/*!*/;
# at 418536457
#190412 12:41:45 server id 58070  end_log_pos 418536537         Table_map: `ycc_cfcenter`.`config_center_client_list` mapped to number 108
# at 418536537
#190412 12:41:45 server id 58070  end_log_pos 418536703         Write_rows: table id 108 flags: STMT_END_F
 
BINLOG '
'/*!*/;
### INSERT INTO `ycc_cfcenter`.`config_center_client_list`
### SET
###   @1=380183781 /* LONGINT meta=0 nullable=0 is_null=0 */
###   @2=206 /* LONGINT meta=0 nullable=1 is_null=0 */
###   @3='10.1.97.133' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
###   @4='5566' /* VARSTRING(90) meta=90 nullable=1 is_null=0 */
###   @5=1555044105821 /* LONGINT meta=0 nullable=1 is_null=0 */
### INSERT INTO `ycc_cfcenter`.`config_center_client_list`
### SET
###   @1=380183788 /* LONGINT meta=0 nullable=0 is_null=0 */
###   @2=136 /* LONGINT meta=0 nullable=1 is_null=0 */
###   @3='10.1.94.137' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
###   @4='5566' /* VARSTRING(90) meta=90 nullable=1 is_null=0 */
###   @5=1555044105821 /* LONGINT meta=0 nullable=1 is_null=0 */
### INSERT INTO `ycc_cfcenter`.`config_center_client_list`
### SET
###   @1=380183795 /* LONGINT meta=0 nullable=0 is_null=0 */
###   @2=206 /* LONGINT meta=0 nullable=1 is_null=0 */
###   @3='10.1.97.131' /* VARSTRING(300) meta=300 nullable=1 is_null=0 */
###   @4='5566' /* VARSTRING(90) meta=90 nullable=1 is_null=0 */
###   @5=1555044105821 /* LONGINT meta=0 nullable=1 is_null=0 */
# at 418536703
#190412 12:41:45 server id 58070  end_log_pos 418536730         Xid = 604665142
COMMIT/*!*/;

3.2 确定故障点结果汇总

1.故障节点提示 Duplicate entry '136-10.1.94.137-5566' for key 'uniq_idx_project_id'  有唯一约束冲突

2.故障节点当前GTID  【1bb1b861-f776-11e6-3319-010204058070:1-113111660】

3.故障节点与主节点GTID相差一个值,相同binlog event 主节点GTID【1bb1b861-f776-11e6-3319-010204058070:113111662】  故障节点【1bb1b861-f776-11e6-3319-010204058070:113111661】

3.3 故障节点修复过程

3.3.1 停止故障节点MGR服务
    STOP group_replication;
    SET GLOBAL super_read_only=0
3.3.2 删除冲突键数据
    DELETE FROM config_center_client_list WHERE project_id=136 AND client_ip='10.1.94.137' AND PORT=5566
3.3.3 清除故障节点GTID信息
    RESET MASTER 
3.3.4 重置故障节点GTID信息,故障节点因唯一约束冲突未重做的binlog event,在主节点对应的GTID为【1bb1b861-f776-11e6-3319-010204058070:113111662】。
    SET @@GLOBAL.GTID_PURGED='1bb1b861-f776-11e6-3319-010204058070:1-113111661';
    START group_replication;
    SHOW MASTER STATUS

3.3.5 在故障节点执行, 需要跳过的GTID只有一个,也可以用以下方法,这样就不需要reset masert。

STOP group_replication;
SET GLOBAL super_read_only=0
set sql_log_bin=0
DELETE FROM config_center_client_list WHERE project_id=136 AND client_ip='10.1.94.137' AND PORT=5566
set sql_log_bin=1
set session gtid_next="1bb1b861-f776-11e6-3319-010204058070:113111661"; 
begin;commit; 
set session gtid_next="AUTOMATIC"; 
START group_replication;

MGR主从不一致问题排查与修复的更多相关文章

  1. pt-table-sync修复mysql主从不一致的数据

    pt-table-sync简介 顾名思义,它用来修复多个实例之间数据的不一致.它可以让主从的数据修复到最终一致,也可以使通过应用双写或多写的多个不相关的数据库实例修复到一致.同时它还内部集成了pt-t ...

  2. pt-table-sync 配合pt-table-checksum 修复主从不一致

    pt-table-sync 配合pt-table-checksum 修复主从不一致. 先执行下面这条语句,打印出要执行的命令,确认无误后再将  --print  改为  --execute 执行.注意 ...

  3. MySQL主从不一致修复

    场景: 线上正在服务的库由于紧急主从切换导致主从不一致,报错信息如下: Last_Error: Coordinator stopped because there were error(s) in t ...

  4. Linux 系统故障排查和修复技巧

    Linux 系统故障排查和修复技巧 我发现Linux系统在启动过程中会出现一些故障,导致系统无法正常启动,我在这里写了几个应用单用户模式.GRUB命令操作.Linux救援模式的故障修复案例帮助大家了解 ...

  5. MySQL主从不一致的几种故障总结分析、解决和预防

    (1).主从不一致故障,从库宕机,从库启动后重复写入数据报错解决与预防:relay_log_info_repository=TABLE(InnoDB)参数解释说明:若relay_log_info_re ...

  6. redis 数据库主从不一致问题解决方案

     在聊数据库与缓存一致性问题之前,先聊聊数据库主库与从库的一致性问题. 问:常见的数据库集群架构如何? 答:一主多从,主从同步,读写分离. 如上图: (1)一个主库提供写服务 (2)多个从库提供读服务 ...

  7. Linux启动故障排查和修复技巧

    一个执着于技术的公众号 我发现Linux系统在启动过程中会出现一些故障,导致系统无法正常启动,我在这里写了几个应对单用户模式.GRUB命令操作.Linux救援模式的故障修复案例帮助大家了解此类问题的解 ...

  8. mysql主从不一致解决方法

    方法一:忽略错误后,继续同步 该方法适用于主从库数据相差不大,或者要求数据可以不完全统一的情况,数据要求不严格的情况 stop slave; #表示跳过一步错误,后面的数字可变 set global ...

  9. Linux系统故障排查和修复技巧

    本文转自:http://os.51cto.com/art/201304/388384.htm 我发现Linux系统在启动过程中会出现一些故障,导致系统无法正常启动,我在这里写了几个应用单用户模式.GR ...

随机推荐

  1. Handle的原理(Looper、Handler、Message三者关系)

    转载请注明出处:http://blog.csdn.net/lowprofile_coding/article/details/72580044 介绍 前面的内容对Handler做了介绍,也讲解了如何使 ...

  2. [Hadoop] Windows 下的 Hadoop 2.7.5 环境搭建

    原文地址:https://www.cnblogs.com/memento/p/9148721.html 准备说明: jdk:jdk-8u161-windows-x64.exe hadoop:hadoo ...

  3. Java学习笔记:输入、输出数据

    相关内容: 输出数据: print println printf 输入数据: Scanner 首发时间:2018-03-16 16:30 输出数据: JAVA中在屏幕中打印数据可以使用: System ...

  4. c#事务处理(sqlTransaction)

    事务: /// <summary> /// 删除考勤 /// </summary> /// <param name="dto">Id</p ...

  5. owncloud 实现私有云进行多端文件同步

    研究生生涯开始了,事情逐渐多了起来.都没时间写博客了... 开学实验室配了台电脑,我把主机装上了Fedora 作为我的服务器.平时有些实验室的材料,经常几个电脑一起看,使用U盘拷来拷去很是麻烦.今天重 ...

  6. [HDFS_4] HDFS 的 Java 应用开发

    0. 说明 在 IDEA下 进行 HDFS 的 Java 应用开发 通过编写代码实现对 HDFS 的增删改查操作 1. 流程 1.1 在项目下新建 Moudle 略 1.2 为 Moudle 添加 M ...

  7. 自定义mysql类用于快速执行数据库查询以及将查询结果转为json文件

    由于每次连接数据库进行查询比较麻烦,偶尔还需要将查询结果转为json格式的文件, 因此暂时定义一个mysql的类,将这些常用的方法进行封装,便于直接调用(代码如下,个人用,没写什么注释). 注:导入了 ...

  8. web页面中快速找到html对应元素两种方法

    一.第一种方法(通过先进入开发模式然后再去选择网页元素) 1.打开IE.Chrome.FireFox等,按 F12 键进入开发模式 2.在打开的控制窗口左上角有个  箭头 按钮,点击它之后,此时将鼠标 ...

  9. Android中消息系统模型和Handler Looper

    http://www.cnblogs.com/bastard/archive/2012/06/08/2541944.html Android中消息系统模型和Handler Looper 作为Andro ...

  10. Linux系统学习之网络管理

    网络接口配置 使用ifconfig检查和配置网卡 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ...