pt-table-sync does not work with special characters (like '-') in database name

Bug #1460644 reported by Yevgen Yaremenko
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Percona Toolkit moved to https://jira.percona.com/projects/PT
New
Undecided
Unassigned

Bug Description

> pt-table-sync --version
pt-table-sync 2.2.6

Mysql version:
Server version: 5.6.20-68.0 Percona Server (GPL), Release 68.0, Revision 656

STR:

1) Configure replication between db-master and db-slave (db-master -> db-slave);

2) Create database with '-' in name:

create database `test-01`;
use `test-01`;
CREATE TABLE test_table (id INT) ENGINE = InnoDB;
insert into test_table values (1);
insert into test_table values (2);

3) calculate checksum (should be executed from db-slave server):

/usr/bin/pt-table-checksum --user "pb_user" --password "qwerty" --databases test-01 --replicate=test-01.pt_table_checksum --nocheck-replication-filters --recursion-method=hosts --function MURMUR_HASH "h=db-master,P=3306" --tables test_table

4) try to sync tables (if there are any diffs):

> /usr/bin/pt-table-sync --execute --user "user" --password "password" --databases test-01 --replicate=test-01.pt_table_checksum --recursion-method=hosts "h=db-master,P=3306" --verbose
DBD::mysql::db selectall_arrayref failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-01.pt_table_checksum WHERE master_cnt <> this_cnt OR master_crc <> this_cr' at line 1 [for Statement "SELECT db, tbl, CONCAT(db, '.', tbl) AS `table`, chunk, chunk_index, lower_boundary, upper_boundary, COALESCE(this_cnt-master_cnt, 0) AS cnt_diff, COALESCE(this_crc <> master_crc OR ISNULL(master_crc) <> ISNULL(this_crc), 0) AS crc_diff, this_cnt, master_cnt, this_crc, master_crc FROM test-01.pt_table_checksum WHERE master_cnt <> this_cnt OR master_crc <> this_crc OR ISNULL(master_crc) <> ISNULL(this_crc)"] at /usr/bin/pt-table-sync line 4957.
Issuing rollback() due to DESTROY without explicit disconnect() of DBD::mysql::db handle ;host=db-master;port=3306;mysql_read_default_group=client at /usr/bin/pt-table-sync line 4957.
Issuing rollback() due to DESTROY without explicit disconnect() of DBD::mysql::db handle ;host=db-master;port=3306;mysql_read_default_group=client at /usr/bin/pt-table-sync line 4957.

We can't rename our production databases (to exclude '-'). Also we need to have pt_table_checksum per each database and to keep this table in the corresponding database.

I have fixed the issue in the following way:

> diff -u /usr/bin/pt-table-sync ./pt-table-sync
--- /usr/bin/pt-table-sync 2015-04-15 09:22:48.000000000 +0000
+++ ./pt-table-sync 2015-06-01 07:46:55.823409148 +0000
@@ -4943,6 +4943,8 @@
 sub find_replication_differences {
    my ( $self, $dbh, $table ) = @_;

+ $table =~ s/(.*)\.(.*)/\`$1\`\.$2/;
+
    my $sql
       = "SELECT db, tbl, CONCAT(db, '.', tbl) AS `table`, "
       . "chunk, chunk_index, lower_boundary, upper_boundary, "

Revision history for this message
Yevgen Yaremenko (yevgenyaremenko) wrote :
tags: added: pt-table-sync
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.