【问题标题】:pt-table-checksum not detecting diffspt-table-checksum 未检测到差异
【发布时间】:2017-09-07 15:03:01
【问题描述】:

我有一个使用 MariaDB 的简单主->从设置:

大师:Ubuntu 16.04 LTS 和 MariaDB 10.2.8 和 percona-toolkit 3.0.4

从站:Ubuntu 16.04 LTS 和 MariaDB 10.2.7

复制运行良好,现在我想检查主从之间的数据是否相同。

我在master上安装了percona-toolkit并创建了一个校验和用户:

MariaDB> GRANT REPLICATION SLAVE,PROCESS,SUPER, SELECT ON *.* TO `pt_checksum`@'%' IDENTIFIED BY 'password';
MariaDB> GRANT ALL PRIVILEGES ON percona.* TO `pt_checksum`@'%';
MariaDB> FLUSH PRIVILEGES;

我还在 slave conf 中添加了 report_host,以便它向 master 展示自己:

MariaDB [(none)]> show slave hosts;
+-----------+-----------+------+-----------+
| Server_id | Host      | Port | Master_id |
+-----------+-----------+------+-----------+
|         2 | 10.0.0.49 | 3306 |         1 |
+-----------+-----------+------+-----------+
1 row in set (0.00 sec)

为了测试 pt-table-checksum,我从从属服务器上的测试数据库中的 Tickets 表中删除了一行。我已经验证了这一行确实丢失了,但仍然存在于 master 上。

但是 pt-table-checksum 没有报告这个差异:

# pt-table-checksum --databases=shop_test --tables=Tickets --host=localhost --user=pt_checksum --password=... --no-check-binlog-format --no-check-replication-filters
        TS ERRORS  DIFFS     ROWS  CHUNKS SKIPPED    TIME TABLE
09-07T16:15:02      0      0       14       1       0   0.013 shop_test.Tickets

所以我在我的环境中设置了 PTDEBUG=1,但似乎主服务器与从服务器连接良好。我试图从输出中挑选出相关位:

# MasterSlave:5175 9725 Connected to h=localhost,p=...,u=pt_checksum
# MasterSlave:5184 9725 SELECT @@SERVER_ID
# MasterSlave:5186 9725 Working on server ID 1
# MasterSlave:5219 9725 Looking for slaves on h=localhost,p=...,u=pt_checksum using methods processlist hosts
# MasterSlave:5226 9725 Finding slaves with _find_slaves_by_processlist
# MasterSlave:5288 9725 DBI::db=HASH(0x31c5190) SHOW GRANTS FOR CURRENT_USER()
# MasterSlave:5318 9725 DBI::db=HASH(0x31c5190) SHOW FULL PROCESSLIST
# DSNParser:1417 9725 Parsing h=10.0.0.49
[...]
# MasterSlave:5231 9725 Found 1 slaves
# MasterSlave:5208 9725 Recursing from h=localhost,p=...,u=pt_checksum to h=10.0.0.49,p=...,u=pt_checksum
# MasterSlave:5155 9725 Recursion methods: processlist hosts
[...]
# MasterSlave:5175 9725 Connected to h=10.0.0.49,p=...,u=pt_checksum
# MasterSlave:5184 9725 SELECT @@SERVER_ID
# MasterSlave:5186 9725 Working on server ID 2
# MasterSlave:5097 9725 Found slave: h=10.0.0.49,p=...,u=pt_checksum
[...]
# pt_table_checksum:9793 9725 Exit status 0 oktorun 1
# Cxn:3764 9725 Destroying cxn
# Cxn:3774 9725 DBI::db=HASH(0x31cd218) Disconnecting dbh on slaveserver h=10.0.0.49
# Cxn:3764 9725 Destroying cxn
# Cxn:3774 9725 DBI::db=HASH(0x31c5190) Disconnecting dbh on masterserver h=localhost

我没有想法,为什么没有检测到丢失的行?

【问题讨论】:

    标签: checksum database-replication percona


    【解决方案1】:

    我在周末注意到一个新的错误报告,今天我确认这确实是我遇到的问题。

    解决方法是添加--set-vars binlog_format=statement

    当我设置此选项时,差异会在第二次运行后显现出来。

    在第一次运行期间,slave 上的校验和表更改为:

    MariaDB [percona]> select tbl, this_crc, this_cnt, master_crc,master_cnt from checksums where tbl = 'Tickets' and db = 'shop_test';
    +---------+----------+----------+------------+------------+
    | tbl     | this_crc | this_cnt | master_crc | master_cnt |
    +---------+----------+----------+------------+------------+
    | Tickets | f30abebe |       14 | f30abebe   |         14 |
    +---------+----------+----------+------------+------------+
    

    ...到...

    MariaDB [percona]> select tbl, this_crc, this_cnt, master_crc,master_cnt from checksums where tbl = 'Tickets' and db = 'shop_test';
    +---------+----------+----------+------------+------------+
    | tbl     | this_crc | this_cnt | master_crc | master_cnt |
    +---------+----------+----------+------------+------------+
    | Tickets | 284ec207 |       13 | f30abebe   |         14 |
    +---------+----------+----------+------------+------------+
    

    第二次运行后,差异也出现在 pt-checksum-table 输出中:

    # pt-table-checksum --tables=shop_test.Tickets --host=localhost --user=pt_checksum --password=... --no-check-binlog-format --no-check-replication-filters --set-vars binlog_format=statement
                TS ERRORS  DIFFS     ROWS  CHUNKS SKIPPED    TIME TABLE
    09-11T11:17:37      0      1       14       1       0   0.022 shop_test.Tickets
    

    我检查了SHOW VARIABLES LIKE 'binlog_format',binlog_format 仍然是“混合”,所以显然它只会在会话期间发生变化。根据文档,据我了解,这应该自动发生:

    这仅适用于基于语句的复制(pt-table-checksum 将在持续时间内将 binlog 格式切换为 STATEMENT 如果您的服务器使用基于行的复制,则会话)。

    错误报告: https://jira.percona.com/browse/PT-1443

    [更新] 2020 年 9 月问题仍未解决

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-24
      • 2020-03-12
      • 2015-11-20
      • 2011-09-19
      • 1970-01-01
      相关资源
      最近更新 更多