From fa8254712bf77d24ae8f91faf67de17363f06ffe Mon Sep 17 00:00:00 2001 From: Frank Cizmich Date: Thu, 17 Jul 2014 17:50:37 -0300 Subject: [PATCH] fixes pt-table-checksum-PXC-inconsistent-results-upon-resume-1311654 --- bin/pt-table-checksum | 52 ++++++++++++++----- t/pt-table-checksum/basics.t | 4 +- .../samples/default-results-5.5.txt | 2 +- .../samples/default-results-5.6.txt | 2 +- .../samples/static-chunk-size-results-5.5.txt | 2 +- .../samples/static-chunk-size-results-5.6.txt | 2 +- 6 files changed, 45 insertions(+), 19 deletions(-) diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index f34ab4be..31143ee1 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -5977,19 +5977,32 @@ sub find_replication_differences { } my ($dbh, $repl_table) = @args{@required_args}; - my $sql - = "SELECT 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 $repl_table " - . "WHERE (master_cnt <> this_cnt OR master_crc <> this_crc " - . "OR ISNULL(master_crc) <> ISNULL(this_crc))" - . ($args{where} ? " AND ($args{where})" : ""); - PTDEBUG && _d($sql); - my $diffs = $dbh->selectall_arrayref($sql, { Slice => {} }); + my $ts_clause = $self->{start_ts} ? " AND ts >= '$self->{start_ts}' " : ''; # issue 1311654 + my $ok_to_leave = 0; + my $tries = 5; # number of times to try again if replication checksum don't agree. + my $diffs; + do { + my $sql + = "SELECT 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 $repl_table " + . "WHERE (master_cnt <> this_cnt OR master_crc <> this_crc " + . "OR ISNULL(master_crc) <> ISNULL(this_crc)) $ts_clause" + . ($args{where} ? " AND ($args{where})" : ""); + PTDEBUG && _d($sql); + $diffs = $dbh->selectall_arrayref($sql, { Slice => {} }); + $tries--; + if (@$diffs) { + sleep 1; + } else { + $ok_to_leave = 1; + } + + } until ($ok_to_leave || !$tries); return $diffs; } @@ -8917,6 +8930,7 @@ use sigtrap 'handler', \&sig_int, 'normal-signals'; my $oktorun = 1; my $print_header = 1; my $exit_status = 0; +my $start_ts = 0; # issue 1311654 # "exit codes 1 - 2, 126 - 165, and 255 [1] have special meanings, # and should therefore be avoided for user-specified exit parameters" @@ -8964,6 +8978,9 @@ sub main { $print_header = 1; $exit_status = 0; + $start_ts = full_ts(); # issue 1311654 + PTDEBUG && _d("initial start_ts: [$start_ts]"); + # ######################################################################## # Get configuration information. # ######################################################################## @@ -10072,6 +10089,7 @@ sub main { # Should be done automatically, but I like to be explicit. $fetch_sth->finish(); $update_sth->finish(); + $delete_sth->finish(); # Update rate, chunk size, and progress if the nibble actually # selected some rows. @@ -10382,6 +10400,14 @@ sub ts { return $msg ? "$ts $msg" : $ts; } +sub full_ts { + my ($msg) = @_; + my ($s, $m, $h, $d, $M, $Y) = localtime; + $Y += 1900; + my $ts = sprintf('%04d-%02d-%02dT%02d:%02d:%02d', $Y, $M+1, $d, $h, $m, $s); + return $msg ? "$ts $msg" : $ts; +} + sub nibble_is_safe { my (%args) = @_; my @required_args = qw(Cxn tbl NibbleIterator OptionParser); diff --git a/t/pt-table-checksum/basics.t b/t/pt-table-checksum/basics.t index 1f4c43ff..e9c4b6ef 100644 --- a/t/pt-table-checksum/basics.t +++ b/t/pt-table-checksum/basics.t @@ -80,8 +80,8 @@ ok( # other than to ensure that there's at least one for each table. $row = $master_dbh->selectrow_arrayref("select count(*) from percona.checksums"); ok( - $row->[0] > 30 && $row->[0] < 50, - 'Between 30 and 50 chunks' + $row->[0] > 30 && $row->[0] < 60, + 'Between 30 and 60 chunks' ) or diag($row->[0]); # ############################################################################ diff --git a/t/pt-table-checksum/samples/default-results-5.5.txt b/t/pt-table-checksum/samples/default-results-5.5.txt index 7776a032..35b2b3ed 100644 --- a/t/pt-table-checksum/samples/default-results-5.5.txt +++ b/t/pt-table-checksum/samples/default-results-5.5.txt @@ -21,7 +21,7 @@ ERRORS DIFFS ROWS SKIPPED TABLE 0 0 0 0 mysql.time_zone_transition 0 0 0 0 mysql.time_zone_transition_type 0 0 2 0 mysql.user -0 0 38 0 percona_test.checksums +0 0 22 0 percona_test.checksums 0 0 1 0 percona_test.load_data 0 0 1 0 percona_test.sentinel 0 0 200 0 sakila.actor diff --git a/t/pt-table-checksum/samples/default-results-5.6.txt b/t/pt-table-checksum/samples/default-results-5.6.txt index 27a5a4ce..ed53ddf6 100644 --- a/t/pt-table-checksum/samples/default-results-5.6.txt +++ b/t/pt-table-checksum/samples/default-results-5.6.txt @@ -20,7 +20,7 @@ ERRORS DIFFS ROWS SKIPPED TABLE 0 0 0 0 mysql.time_zone_transition 0 0 0 0 mysql.time_zone_transition_type 0 0 2 0 mysql.user -0 0 37 0 percona_test.checksums +0 0 22 0 percona_test.checksums 0 0 1 0 percona_test.load_data 0 0 1 0 percona_test.sentinel 0 0 200 0 sakila.actor diff --git a/t/pt-table-checksum/samples/static-chunk-size-results-5.5.txt b/t/pt-table-checksum/samples/static-chunk-size-results-5.5.txt index 676ce574..e9ae9590 100644 --- a/t/pt-table-checksum/samples/static-chunk-size-results-5.5.txt +++ b/t/pt-table-checksum/samples/static-chunk-size-results-5.5.txt @@ -21,7 +21,7 @@ ERRORS DIFFS ROWS CHUNKS SKIPPED TABLE 0 0 0 1 0 mysql.time_zone_transition 0 0 0 1 0 mysql.time_zone_transition_type 0 0 2 1 0 mysql.user -0 0 38 1 0 percona_test.checksums +0 0 22 1 0 percona_test.checksums 0 0 1 1 0 percona_test.load_data 0 0 1 1 0 percona_test.sentinel 0 0 200 1 0 sakila.actor diff --git a/t/pt-table-checksum/samples/static-chunk-size-results-5.6.txt b/t/pt-table-checksum/samples/static-chunk-size-results-5.6.txt index 55b6e2fe..288000c1 100644 --- a/t/pt-table-checksum/samples/static-chunk-size-results-5.6.txt +++ b/t/pt-table-checksum/samples/static-chunk-size-results-5.6.txt @@ -20,7 +20,7 @@ ERRORS DIFFS ROWS CHUNKS SKIPPED TABLE 0 0 0 1 0 mysql.time_zone_transition 0 0 0 1 0 mysql.time_zone_transition_type 0 0 2 1 0 mysql.user -0 0 37 1 0 percona_test.checksums +0 0 22 1 0 percona_test.checksums 0 0 1 1 0 percona_test.load_data 0 0 1 1 0 percona_test.sentinel 0 0 200 1 0 sakila.actor