zoukankan      html  css  js  c++  java
  • MySQL主从检验一致性工具pt-table-checksum报错的案例分析

    【问题】

    有同事反馈我们改造过的MySQL5.7.23版本,使用pt-table-checksum工具比较主从数据库的一致性时报错

    Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. REPLACE... SELECT is unsafe because the order in which rows are retrieved by the SELECT determines which (if any) rows are replaced. This order cannot be predicted and may differ on master and the slave.

    这个问题隐藏的比较深,经过反复测试,终于定位到原因了。

    【pt-table-checksum工具的关键处理流程】

    1、 pt-table-checksum工具有一部分处理逻辑,对于binlog_format为ROW模式的复制,会在master和slave上设置binlog_format=STATEMENT,确保从库也会执行 checksum SQL

    2、接下来执行REPLACE INTO的语句

    3、前面同事反馈的报错就发生在运行REPLACE INTO语句时

    对于Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. REPLACE... SELECT is unsafe because the order in which rows are retrieved by the SELECT determines which (if any) rows are replaced. This order cannot be predicted and may differ on master and the slave.的报错,其实是warning信息

    当执行set session binlog_format='statement'后运行REPLACE INTO,在MySQL5.6,5.7的版本中都会报warning

    关键的差异在于warning的code编号发生了变化,在MySQL5.6及原生MySQL5.7下是1592,在我们改造过的MySQL5.7.23下是1593

    4、从源码中看到pt-table-checksum对1592的code做了忽略,当出现1592的warnings时会继续下面的处理,而当编号变为1593时,pt-table-checksum工具在这里就直接报Error了

    将pt-table-checksum代码中的1592修改为1593,再次运行,恢复正常

    【为什么MySQL5.7.23下的code会发生变化】

     应该与我们MySQL源码改造时,新增提示信息有关,对应的code值是在编译时动态生成,由于中间新定义了报错信息,后面的error code值都增加1

    本身error code的值并不影响功能使用,但正好遇到第三方的pt-table-checksum工具这里代码写死了code值,所以导致了上面的问题。

    【改进方案】

    1、 为了更好的兼容性,建议大家在自定义提示信息时放在代码最下面,这样不影响其他code值的生成,

    2、 当前版本中如果有checksum的需求,可以临时修改vim /usr/bin/pt-table-checksum,增加1593的warning信息过滤

  • 相关阅读:
    C++文件读写详解(ofstream,ifstream,fstream)
    C++ char*,const char*,string,int 的相互转换
    Properties --- C++读配置信息的类
    值得推荐的C/C++框架和库
    leetcode 264: Ugly Number II
    几种Tab的实现方法
    HBase数据存储格式
    粗略。。Java项目设计模式之笔记----studying
    开放的平台、向上的文化——揭秘万达电商(4)
    RecyclerView
  • 原文地址:https://www.cnblogs.com/wangdong/p/9895126.html
Copyright © 2011-2022 走看看