From f4362cb2e7d5f5fae5fa9c9bc5c490f2448a6a9b Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Thu, 5 Jan 2012 11:46:38 -0700 Subject: [PATCH] Test and fix bug 911996. --- Changelog | 2 ++ bin/pt-table-sync | 4 ++-- t/pt-table-sync/basics.t | 31 ++++++++++++++++++++++++++++++- t/pt-table-sync/diff_where.t | 2 +- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/Changelog b/Changelog index 043810b4..16f8035e 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,7 @@ Changelog for Percona Toolkit + * Fixed bug 911996: pt-table-sync --replicate causes "Unknown column" error + v2.0.1 released 2011-12-30 * Completely redesigned pt-table-checksum diff --git a/bin/pt-table-sync b/bin/pt-table-sync index 93db4eb2..f5c3f733 100755 --- a/bin/pt-table-sync +++ b/bin/pt-table-sync @@ -8892,13 +8892,13 @@ sub diff_where { my $lb_sql = $asc->{boundaries}->{'>='}; foreach my $val ( $q->deserialize_list($diff->{lower_boundary}) ) { my $quoted_val = $q->quote_val($val); - $lb_sql =~ s/\?/$val/; + $lb_sql =~ s/\?/$quoted_val/; } my $ub_sql = $asc->{boundaries}->{'<='}; foreach my $val ( $q->deserialize_list($diff->{upper_boundary}) ) { my $quoted_val = $q->quote_val($val); - $ub_sql =~ s/\?/$val/; + $ub_sql =~ s/\?/$quoted_val/; } return "$lb_sql AND $ub_sql"; diff --git a/t/pt-table-sync/basics.t b/t/pt-table-sync/basics.t index bbbe512b..09020277 100644 --- a/t/pt-table-sync/basics.t +++ b/t/pt-table-sync/basics.t @@ -28,7 +28,7 @@ elsif ( !$slave_dbh ) { plan skip_all => 'Cannot connect to sandbox slave'; } else { - plan tests => 17; + plan tests => 19; } $sb->wipe_clean($master_dbh); @@ -168,6 +168,35 @@ ok($output, 'Synced with Nibble and data-size chunksize'); # Restore PTDEBUG env. $ENV{PTDEBUG} = $dbg || 0; +# ########################################################################### +# Fix bug 911996. +# ########################################################################### +`$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox --max-load '' --lock-wait 3 --chunk-size 50 --chunk-index idx_actor_last_name -t sakila.actor --quiet`; + +PerconaTest::wait_for_table($slave_dbh, "percona.checksums", "db='sakila' and tbl='actor' and chunk=7"); +$slave_dbh->do("update percona.checksums set this_crc='' where db='sakila' and tbl='actor' and chunk=3"); +$slave_dbh->do("update sakila.actor set last_name='' where actor_id=30"); + +$output = output( + sub { + pt_table_sync::main('h=127.1,P=12345,u=msandbox,p=msandbox', + qw(--print --execute --replicate percona.checksums), + qw(--no-foreign-key-checks)) + } +); + +like( + $output, + qr/^REPLACE INTO `sakila`.`actor`\(`actor_id`, `first_name`, `last_name`, `last_update`\) VALUES \('30', 'SANDRA', 'PECK', '2006-02-15 04:34:33'\)/, + "--replicate with char index col (bug 911996)" +); + +$output = `$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox --max-load '' --lock-wait 3 --chunk-size 50 --chunk-index idx_actor_last_name -t sakila.actor`; +is( + PerconaTest::count_checksum_results($output, 'diffs'), + 0, + "Synced diff (bug 911996)" +); # ############################################################################# # Done. diff --git a/t/pt-table-sync/diff_where.t b/t/pt-table-sync/diff_where.t index bcf86f1d..dce9c625 100644 --- a/t/pt-table-sync/diff_where.t +++ b/t/pt-table-sync/diff_where.t @@ -54,7 +54,7 @@ test_diff_where( this_crc => '4a57d814', upper_boundary => '9' }, - where => "((`id` >= 7)) AND ((`id` <= 9))", + where => "((`id` >= '7')) AND ((`id` <= '9'))", ); # #############################################################################