几个月前写过pt-table-checksum 3.0.4检测不出主从差异数据,当时的解决方案是使用旧版本,另一个挫方法是自行设置binlog_format='STATEMENT'。现在已经发布到3.0.9版本,结果又遇到相同的坑~
最近几版pt-table-checksum(已核实3.0.4和3.0.9有问题)在binlog_format='row',且主从存在差异数据时,却检测不出主从差异。原因就是处理过程中主上没有SET @@binlog_format := 'STATEMENT',导致下面两个核心语句不是以statement格式记录,从库不会进行CRC32相关运算,主从永远一致~

# pt-table-checksum 3.0.4检测不出差异数据
[root@ZST2 ~]# /usr/local/bin/pt-table-checksum --nocheck-binlog-format --nocheck-replication-filters --recursion-method=hosts --replicate=replcrash.checksums --databases=replcrash --tables=py_user,py_user_innodb --host=192.168.85.132 --port= --user=mydba --password=mysql5721
TS ERRORS DIFFS ROWS CHUNKS SKIPPED TIME TABLE
-08T09:: 0.257 replcrash.py_user
-08T09:: 1.056 replcrash.py_user_innodb # 两个核心语句
REPLACE INTO `replcrash`.`checksums` (db, tbl, chunk, chunk_index, lower_boundary, upper_boundary, this_cnt, this_crc) SELECT 'replcrash', 'py_user', '', NULL, NULL, NULL, COUNT(*) AS cnt, COALESCE(LOWER(CONV(BIT_XOR(CAST(CRC32(CONCAT_WS('#', `uid`, convert(`name` using utf8mb4), `add_time`, convert(`server_id` using utf8mb4), CONCAT(ISNULL(`name`), ISNULL(`add_time`), ISNULL(`server_id`)))) AS UNSIGNED)), , )), ) AS crc FROM `replcrash`.`py_user` /*checksum table*/
UPDATE `replcrash`.`checksums` SET chunk_time = '0.004092', master_crc = '5abbd632', master_cnt = '' WHERE db = 'replcrash' AND tbl = 'py_user' AND chunk = ''

通过对比旧版本(2.2.3)的/usr/local/bin/pt-table-checksum代码,发现只需稍微调整代码即可正常使用

# pt-table-checksum 3.0. 只需注释掉第9335行和9364行,这层逻辑应该应用于任何情况下,因此不需要使用if判断
[root@ZST2 ~]# vim /usr/local/bin/pt-table-checksum
...
#if ( $o->get('check-binlog-format') ) {
# https://bugs.launchpad.net/percona-toolkit/+bug/919352
# The tool shouldn't blindly attempt to change binlog_format;
# instead, it should check if it's already set to STATEMENT.
# This is becase starting with MySQL 5.1., changing the format
# requires a SUPER user.
if ( VersionParser->new($dbh) >= '5.1.5' ) {
$sql = 'SELECT @@binlog_format';
PTDEBUG && _d($dbh, $sql);
my ($original_binlog_format) = $dbh->selectrow_array($sql);
PTDEBUG && _d('Original binlog_format:', $original_binlog_format);
if ( $original_binlog_format !~ /STATEMENT/i ) {
$sql = q{/*!50108 SET @@binlog_format := 'STATEMENT'*/};
eval {
PTDEBUG && _d($dbh, $sql);
$dbh->do($sql);
};
if ( $EVAL_ERROR ) {
die "Failed to $sql: $EVAL_ERROR\n"
. "This tool requires binlog_format=STATEMENT, "
. "but the current binlog_format is set to "
."$original_binlog_format and an error occurred while "
. "attempting to change it. If running MySQL 5.1.29 or newer, "
. "setting binlog_format requires the SUPER privilege. "
. "You will need to manually set binlog_format to 'STATEMENT' "
. "before running this tool.\n";
}
}
}
#}
... # 查看pt版本
[root@ZST2 ~]# /usr/local/bin/pt-table-checksum --version
pt-table-checksum 3.0.
[root@ZST2 ~]#
# 修改后检测出主从不一致
[root@ZST2 ~]# /usr/local/bin/pt-table-checksum --nocheck-binlog-format --nocheck-replication-filters --recursion-method=hosts --replicate=replcrash.checksums --databases=replcrash --tables=py_user,py_user_innodb --host=192.168.85.132 --port= --user=mydba --password=mysql5721
TS ERRORS DIFFS ROWS CHUNKS SKIPPED TIME TABLE
-08T09:: 0.030 replcrash.py_user
-08T09:: 0.561 replcrash.py_user_innodb
[root@ZST2 ~]# # general-log信息
[root@ZST1 ~]# cat /data/mysql/mysql3306/data/ZST1.log |more
...
--08T01::.315064Z Query SHOW VARIABLES LIKE 'version%'
--08T01::.318337Z Query SHOW ENGINES
--08T01::.319229Z Query SHOW VARIABLES LIKE 'innodb_version'
--08T01::.322518Z Query SELECT @@binlog_format
--08T01::.323019Z Query /*!50108 SET @@binlog_format := 'STATEMENT'*/
--08T01::.323453Z Query SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ
--08T01::.324012Z Query SHOW VARIABLES LIKE 'wsrep_on'
--08T01::.327830Z Query SELECT @@SERVER_ID
--08T01::.328416Z Query SHOW SLAVE HOSTS
--08T01::.344178Z Query SHOW VARIABLES LIKE 'wsrep_on'
--08T01::.347571Z Query SELECT @@SERVER_ID
--08T01::.351692Z Query SHOW VARIABLES LIKE 'wsrep_on'
--08T01::.355034Z Query SELECT @@SERVER_ID
--08T01::.359543Z Query SHOW DATABASES LIKE 'replcrash'
--08T01::.360406Z Query CREATE DATABASE IF NOT EXISTS `replcrash` /* pt-table-checksum */
--08T01::.361538Z Query USE `replcrash`
--08T01::.362069Z Query SHOW TABLES FROM `replcrash` LIKE 'checksums'
--08T01::.364738Z Query CREATE TABLE IF NOT EXISTS `replcrash`.`checksums` (
db CHAR() NOT NULL,
tbl CHAR() NOT NULL,
chunk INT NOT NULL,
chunk_time FLOAT NULL,
chunk_index VARCHAR() NULL,
lower_boundary TEXT NULL,
upper_boundary TEXT NULL,
this_crc CHAR() NOT NULL,
this_cnt INT NOT NULL,
master_crc CHAR() NULL,
master_cnt INT NULL,
ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (db, tbl, chunk),
INDEX ts_db_tbl (ts, db, tbl)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
--08T01::.920625Z Query SHOW GLOBAL STATUS LIKE 'Threads_running'
--08T01::.924636Z Query SELECT CONCAT(@@hostname, @@port)
...



如果遇到类似问题,建议开启general_log,查看处理过程,再核验到底什么原因导致检测不出主从差异数据(・ω・)


09:21 2018/5/10 补充,其实可以在命令行带上--set-vars binlog_format='statement'
详细说明参考:pt-table-checksum not detecting diffs

[root@ZST2 ~]# /usr/local/bin/pt-table-checksum --nocheck-binlog-format --nocheck-replication-filters --recursion-method=hosts --replicate=replcrash.checksums --databases=replcrash --tables=py_user,py_user_innodb --host=192.168.85.132 --port= --user=mydba --password=mysql5721 --set-vars binlog_format='statement'
TS ERRORS DIFFS ROWS CHUNKS SKIPPED TIME TABLE
-10T09:: 0.024 replcrash.py_user
-10T09:: 0.695 replcrash.py_user_innodb
[root@ZST2 ~]#

善于思考,善于搜索,不要期盼别人把结果原封不动地送到嘴里~.~

pt-table-checksum检测不出主从差异处理的更多相关文章

  1. pt-table-checksum 3.0.4检测不出主从差异数据

    群里好几位同学问 pt-table-checksum 3.0.4, 主从两个表数据是不一致,为啥检测不出来?前段时间自己也测试过,只是没整理成随笔^_- 一.基本环境 VMware10.0+CentO ...

  2. NXP ARM Vector Table CheckSum

    Signature Creator for NXP Cortex-M Devices Algorithm for creating the checksum The reserved Cortex-M ...

  3. 一种table超出高度自动出滚动条的解决方案

    在日常的开发过程中,我们可能会遇到这样一种需求,在指定高度内显示table,超过高度时表格出滚动条. 让我们带着这个问题,一起来探讨吧! <!DOCTYPE html> <html ...

  4. table 锁定表头,出滚动对齐

    前一段时间来了一个汇总的需求,想锁定表头,这个问题在网上找了老半天,实现起来都比较麻烦,经过这几天的摸索终于找到一个简洁的处理方法 下面介绍一下如何处理的: 1.thead 和tbody 放两个tab ...

  5. OpenCV—Python 轮廓检测 绘出矩形框(findContours\ boundingRect\rectangle

    千万注意opencv的轮廓检测和边缘检测是两码事 本文链接:https://blog.csdn.net/wsp_1138886114/article/details/82945328 1 获取轮廓 O ...

  6. Lua Table pairs输出顺序问题 (版本差异 解决数字索引间断并兼容字符串索引)

    问题标签: Lua Table 迭代器;Lua Table 输出顺序; Lua Table 顺序输出;Lua Table 数字索引 字符串索引;Lua Table pairs; 问题背景: 使用pai ...

  7. 鼠标右键Table的td弹出多级菜单,双击td编辑

    <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="C ...

  8. XCode4.5.6,iOS6.1下测试 判断当前设备,及其联网状态等; 关于设备插上后XCode检测不出的情况的说明

    目录[-] 一.判断设备 二.判断网络连接状态 三.设备不显示的解决办法 一.判断设备 01 //设备名称 02 return [UIDevice currentDevice].name; 03   ...

  9. elementUI vue table 操作选项中弹出框确定dialog

    1.html <el-table-column label="操作" width="150" fixed="right" align= ...

随机推荐

  1. Async和Await 异步方法

    Async和Await关键字是C#异步编程的核心.通过使用这两个关键字,你可以使用.NET Framework或Windows Runtime的资源创建一个异步方法如同你创建一个同步的方法一样容易.通 ...

  2. face detection,landmark, recognition with deeplearning

    人脸特征点定位 Joint Face Detection and Alignment using Multi-task Cascaded Convolutional Neural Networks c ...

  3. Java新AIO/NIO2:AsynchronousServerSocketChannel和AsynchronousSocketChannel简单服务器-客户端

    Java新AIO/NIO2:AsynchronousServerSocketChannel和AsynchronousSocketChannel简单服务器-客户端用AsynchronousServerS ...

  4. 09 Zabbix Item类型之Zabbix SNMP类型

    点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 Zabbix Item类型之Zabbix SNMP类型 SNMP是监控服务器以外设备的非常好的方式 ...

  5. 自学Python2.1-基本数据类型-字符串方法 下

    自学Python之路 自学Python2.1-基本数据类型-字符串方法 下 class str(object): """ str(object='') -> str ...

  6. How to Add Trust Sites into IE before IE10 through Group Policy

    Due to IE10 published, I'll conclude the methods that how to add trust sites in to IE of the version ...

  7. 用DBContext (EF) 实现通用增删改查的REST方法

    我们用ADO.NET Entity Data Model来生成实体类后,一般都会对这些类进行基本的增删改查操作,如果每个类都要写这些基本的方法,实在太乏味了.下面就是通过step by step的方式 ...

  8. 学习2__STM32--汉字显示

    汉字显示操作流程 第一,进入主函数 int main(void) { u32 fontcnt; u8 i,j; u8 fontx[];//gbk码 u8 key,t; delay_init(); // ...

  9. POJ P3352 Road Construction 解题报告

    P3352 Road Construction 描述 这几乎是夏季,这意味着它几乎是夏季施工时间!今年,负责岛屿热带岛屿天堂道路的优秀人士,希望修复和升级岛上各个旅游景点之间的各种道路. 道路本身也很 ...

  10. yml实例

    producer.yml apiVersion: v1kind: Podmetadata:name: producer-consumerspec:containers:- image: busybox ...