• 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++11新特性之七——final/override控制
    __declspec的用法
    zedboard学习(1)OLED驱动显示图像
    python+NLTK 自然语言学习处理三:如何在nltk/matplotlib中的图片中显示中文
    流畅python学习笔记第十八章:使用asyncio编写服务器
    流畅python学习笔记第十八章:使用asyncio包处理并发(二)
    Django之博客系统:自定义认证
    Django之博客系统:用户注册和Profile
  • 原文地址:https://www.cnblogs.com/wangdong/p/9895126.html
Copyright © 2020-2023  润新知