From b2bf471e7d79534a6b0f0df09525f9d494420cb8 Mon Sep 17 00:00:00 2001 From: Frank Cizmich Date: Thu, 31 Jul 2014 18:26:45 -0300 Subject: [PATCH] modified RowChecksum module and updated it in pt-table-checksum (only tool that uses it) --- bin/pt-table-checksum | 29 +++++++++++++++-------------- lib/RowChecksum.pm | 39 ++++++++++++++++++++++++++------------- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index 31143ee1..940c2cfe 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -5977,9 +5977,10 @@ sub find_replication_differences { } my ($dbh, $repl_table) = @args{@required_args}; - my $ts_clause = $self->{start_ts} ? " AND ts >= '$self->{start_ts}' " : ''; # issue 1311654 + + my $ts_clause = $self->{start_ts} ? " AND ts >= '$self->{start_ts}' " : ''; # only check rows created in this run + my $tries = 5; # try again up to five times if replication checksum don't agree. 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 @@ -5993,16 +5994,15 @@ sub find_replication_differences { . "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); + 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; } @@ -8978,8 +8978,9 @@ sub main { $print_header = 1; $exit_status = 0; - $start_ts = full_ts(); # issue 1311654 - PTDEBUG && _d("initial start_ts: [$start_ts]"); + # get start time + $start_ts = full_ts(); + PTDEBUG && _d("initial start_ts: $start_ts"); # ######################################################################## # Get configuration information. diff --git a/lib/RowChecksum.pm b/lib/RowChecksum.pm index c567c19b..ff3d9e83 100644 --- a/lib/RowChecksum.pm +++ b/lib/RowChecksum.pm @@ -459,19 +459,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}' " : ''; # only check rows created in this run + my $tries = 5; # try again up to five times if replication checksum don't agree. + my $ok_to_leave = 0; + 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; }