From f517675eb49c5f45b5115ebc2352e5a2bd720e32 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Fri, 3 Feb 2012 11:38:20 -0700 Subject: [PATCH] Compare lc(index) everywhere. --- bin/pt-table-checksum | 23 +++++++----- lib/NibbleIterator.pm | 2 +- t/pt-table-checksum/chunk_index.t | 39 +++++++++++++++++++- t/pt-table-checksum/samples/all-uc-table.sql | 22 +++++++++++ t/pt-table-checksum/samples/no-recheck.txt | 8 ++-- 5 files changed, 79 insertions(+), 15 deletions(-) create mode 100644 t/pt-table-checksum/samples/all-uc-table.sql diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index cdc2b1aa..3e11b20b 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -3778,7 +3778,7 @@ sub set_nibble_number { sub nibble_index { my ($self) = @_; - return $self->{index}; + return lc($self->{index}); } sub statements { @@ -6399,12 +6399,19 @@ sub main { sth => $sth->{explain_upper_boundary}, vals => [ @{$boundary->{lower}}, $nibble_iter->chunk_size() ], ); - if ( ($expl->{key} || '') ne $nibble_iter->nibble_index() ) { + if ( lc($expl->{key} || '') ne $nibble_iter->nibble_index() ) { PTDEBUG && _d('Cannot nibble next chunk, aborting table'); if ( $o->get('quiet') < 2 ) { - warn ts("Aborting $tbl->{db}.$tbl->{tbl} because " + my $msg + = "Aborting table $tbl->{db}.$tbl->{tbl} at chunk " . ($nibble_iter->nibble_number() + 1) - . " cannot be nibbled safely.\n"); + . " because it is not safe to chunk. Chunking should " + . "use the " + . ($nibble_iter->nibble_index() || '?') + . " index, but MySQL EXPLAIN reports that " + . ($expl->{key} ? "the $expl->{key}" : "no") + . " index will be used.\n"; + warn ts($msg); } $tbl->{checksum_results}->{errors}++; return 0; # stop nibbling table @@ -6460,7 +6467,7 @@ sub main { : 0; # Ensure that MySQL is using the chunk index. - if ( ($expl->{key} || '') ne $nibble_iter->nibble_index() ) { + if ( lc($expl->{key} || '') ne $nibble_iter->nibble_index() ) { PTDEBUG && _d('Chunk', $args{nibbleno}, 'of table', "$tbl->{db}.$tbl->{tbl} not using chunk index, skipping"); return 0; # next boundary @@ -7260,15 +7267,13 @@ sub have_more_chunks { # The previous chunk index must match the current chunk index, # else we don't know what to do. my $chunk_index = $nibble_iter->nibble_index() || ''; - if ( ($last_chunk->{chunk_index} || '') - ne ($nibble_iter->nibble_index() || '') ) { + if (lc($last_chunk->{chunk_index} || '') ne $chunk_index) { warn ts("Cannot resume from table $tbl->{db}.$tbl->{tbl} chunk " . "$last_chunk->{chunk} because the chunk indexes are different: " . ($last_chunk->{chunk_index} ? $last_chunk->{chunk_index} : "no index") . " was used originally but " - . ($nibble_iter->nibble_index() ? $nibble_iter->nibble_index() - : "no index") + . ($chunk_index ? $chunk_index : "no index") . " is used now. If the table has not changed significantly, " . "this may be caused by running the tool with different command " . "line options. This table will be skipped and checksumming " diff --git a/lib/NibbleIterator.pm b/lib/NibbleIterator.pm index 93f9a28c..fd8a9ad4 100644 --- a/lib/NibbleIterator.pm +++ b/lib/NibbleIterator.pm @@ -347,7 +347,7 @@ sub set_nibble_number { sub nibble_index { my ($self) = @_; - return $self->{index}; + return lc($self->{index}); } sub statements { diff --git a/t/pt-table-checksum/chunk_index.t b/t/pt-table-checksum/chunk_index.t index 34ff46f4..3aae20f7 100644 --- a/t/pt-table-checksum/chunk_index.t +++ b/t/pt-table-checksum/chunk_index.t @@ -25,7 +25,7 @@ if ( !$dbh ) { plan skip_all => 'Cannot connect to sandbox master'; } else { - plan tests => 6; + plan tests => 10; } # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic @@ -104,6 +104,43 @@ ok( "Explicit --chunk-index overrides MySQL's index for --where" ); +# ############################################################################# +# Bug 925855: pt-table-checksum index check is case-sensitive +# ############################################################################# +$sb->load_file('master', "t/pt-table-checksum/samples/all-uc-table.sql"); +my $exit_status = 0; +$output = output(sub { + $exit_status = pt_table_checksum::main( + $master_dsn, '--max-load', '', + qw(--lock-wait-timeout 3 --chunk-size 5 -t ALL_UC.T) + ) }, + stderr => 1, +); + +is( + $exit_status, + 0, + "Zero exit status (bug 925855)" +); + +is( + PerconaTest::count_checksum_results($output, 'skipped'), + 0, + "0 skipped (bug 925855)" +); + +is( + PerconaTest::count_checksum_results($output, 'errors'), + 0, + "0 errors (bug 925855)" +); + +is( + PerconaTest::count_checksum_results($output, 'rows'), + 13, + "14 rows checksummed (bug 925855)" +); + # ############################################################################# # Done. # ############################################################################# diff --git a/t/pt-table-checksum/samples/all-uc-table.sql b/t/pt-table-checksum/samples/all-uc-table.sql new file mode 100644 index 00000000..c07dff03 --- /dev/null +++ b/t/pt-table-checksum/samples/all-uc-table.sql @@ -0,0 +1,22 @@ +DROP DATABASE IF EXISTS ALL_UC; +CREATE DATABASE ALL_UC; +USE ALL_UC; +CREATE TABLE T ( + ID INT NOT NULL, + C VARCHAR(8) NOT NULL, + UNIQUE INDEX (ID) +) ENGINE=INNODB; +INSERT INTO T VALUES + (1, 'AAA'), + (2, 'BBB'), + (3, 'CCC'), + (4, 'DDD'), + (5, 'EEE'), + (6, 'FFF'), + (7, 'GGG'), + (8, 'HHH'), + (9, 'III'), + (10,'JJJ'), + (11,'KKK'), + (12,'LLL'), + (13,'MMM'); diff --git a/t/pt-table-checksum/samples/no-recheck.txt b/t/pt-table-checksum/samples/no-recheck.txt index e03c1a8c..bc1eae68 100644 --- a/t/pt-table-checksum/samples/no-recheck.txt +++ b/t/pt-table-checksum/samples/no-recheck.txt @@ -1,10 +1,10 @@ Differences on h=127.0.0.1,P=12346 TABLE CHUNK CNT_DIFF CRC_DIFF CHUNK_INDEX LOWER_BOUNDARY UPPER_BOUNDARY -sakila.city 1 0 1 PRIMARY 1 100 -sakila.city 6 0 1 PRIMARY 501 600 +sakila.city 1 0 1 primary 1 100 +sakila.city 6 0 1 primary 501 600 Differences on h=127.0.0.1,P=12347 TABLE CHUNK CNT_DIFF CRC_DIFF CHUNK_INDEX LOWER_BOUNDARY UPPER_BOUNDARY -sakila.city 1 0 1 PRIMARY 1 100 -sakila.city 6 0 1 PRIMARY 501 600 +sakila.city 1 0 1 primary 1 100 +sakila.city 6 0 1 primary 501 600