pt-table-checksum-PXC-inconsistent-results-upon-resume-1311654

This commit is contained in:
Frank Cizmich
2014-08-05 16:51:34 -03:00
3 changed files with 58 additions and 28 deletions

View File

@@ -5977,19 +5977,28 @@ sub find_replication_differences {
} }
my ($dbh, $repl_table) = @args{@required_args}; my ($dbh, $repl_table) = @args{@required_args};
my $sql
= "SELECT CONCAT(db, '.', tbl) AS `table`, " my $tries = $self->{'OptionParser'}->get('replicate-check-retries') || 1;
. "chunk, chunk_index, lower_boundary, upper_boundary, " my $diffs;
. "COALESCE(this_cnt-master_cnt, 0) AS cnt_diff, " while ($tries--) {
. "COALESCE(" my $sql
. "this_crc <> master_crc OR ISNULL(master_crc) <> ISNULL(this_crc), 0" = "SELECT CONCAT(db, '.', tbl) AS `table`, "
. ") AS crc_diff, this_cnt, master_cnt, this_crc, master_crc " . "chunk, chunk_index, lower_boundary, upper_boundary, "
. "FROM $repl_table " . "COALESCE(this_cnt-master_cnt, 0) AS cnt_diff, "
. "WHERE (master_cnt <> this_cnt OR master_crc <> this_crc " . "COALESCE("
. "OR ISNULL(master_crc) <> ISNULL(this_crc))" . "this_crc <> master_crc OR ISNULL(master_crc) <> ISNULL(this_crc), 0"
. ($args{where} ? " AND ($args{where})" : ""); . ") AS crc_diff, this_cnt, master_cnt, this_crc, master_crc "
PTDEBUG && _d($sql); . "FROM $repl_table "
my $diffs = $dbh->selectall_arrayref($sql, { Slice => {} }); . "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);
$diffs = $dbh->selectall_arrayref($sql, { Slice => {} });
if (!@$diffs || !$tries) { # if no differences are found OR we are out of tries left...
last; # get out now
}
sleep 1;
}
return $diffs; return $diffs;
} }
@@ -8965,6 +8974,7 @@ sub main {
$print_header = 1; $print_header = 1;
$exit_status = 0; $exit_status = 0;
# ######################################################################## # ########################################################################
# Get configuration information. # Get configuration information.
# ######################################################################## # ########################################################################
@@ -10073,6 +10083,7 @@ sub main {
# Should be done automatically, but I like to be explicit. # Should be done automatically, but I like to be explicit.
$fetch_sth->finish(); $fetch_sth->finish();
$update_sth->finish(); $update_sth->finish();
$delete_sth->finish();
# Update rate, chunk size, and progress if the nibble actually # Update rate, chunk size, and progress if the nibble actually
# selected some rows. # selected some rows.
@@ -10383,6 +10394,7 @@ sub ts {
return $msg ? "$ts $msg" : $ts; return $msg ? "$ts $msg" : $ts;
} }
sub nibble_is_safe { sub nibble_is_safe {
my (%args) = @_; my (%args) = @_;
my @required_args = qw(Cxn tbl NibbleIterator OptionParser); my @required_args = qw(Cxn tbl NibbleIterator OptionParser);
@@ -12290,6 +12302,15 @@ differences found by previous checksumming, and then exits. It might be useful
if you run pt-table-checksum quietly in a cron job, for example, and later want if you run pt-table-checksum quietly in a cron job, for example, and later want
a report on the results of the cron job, perhaps to implement a Nagios check. a report on the results of the cron job, perhaps to implement a Nagios check.
=item --replicate-check-retries
type: int; default: 1
Retry checksum comparison this many times when a difference is encountered.
Only when a difference persists after this number of checks is it considered valid.
Using this option with a value of 2 or more alleviates spurious differences that
arise when using the --resume option.
=item --replicate-database =item --replicate-database
type: string type: string

View File

@@ -459,19 +459,28 @@ sub find_replication_differences {
} }
my ($dbh, $repl_table) = @args{@required_args}; my ($dbh, $repl_table) = @args{@required_args};
my $sql
= "SELECT CONCAT(db, '.', tbl) AS `table`, " my $tries = $self->{'OptionParser'}->get('replicate-check-retries') || 1;
. "chunk, chunk_index, lower_boundary, upper_boundary, " my $diffs;
. "COALESCE(this_cnt-master_cnt, 0) AS cnt_diff, " while ($tries--) {
. "COALESCE(" my $sql
. "this_crc <> master_crc OR ISNULL(master_crc) <> ISNULL(this_crc), 0" = "SELECT CONCAT(db, '.', tbl) AS `table`, "
. ") AS crc_diff, this_cnt, master_cnt, this_crc, master_crc " . "chunk, chunk_index, lower_boundary, upper_boundary, "
. "FROM $repl_table " . "COALESCE(this_cnt-master_cnt, 0) AS cnt_diff, "
. "WHERE (master_cnt <> this_cnt OR master_crc <> this_crc " . "COALESCE("
. "OR ISNULL(master_crc) <> ISNULL(this_crc))" . "this_crc <> master_crc OR ISNULL(master_crc) <> ISNULL(this_crc), 0"
. ($args{where} ? " AND ($args{where})" : ""); . ") AS crc_diff, this_cnt, master_cnt, this_crc, master_crc "
PTDEBUG && _d($sql); . "FROM $repl_table "
my $diffs = $dbh->selectall_arrayref($sql, { Slice => {} }); . "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);
$diffs = $dbh->selectall_arrayref($sql, { Slice => {} });
if (!@$diffs || !$tries) { # if no differences are found OR we are out of tries left...
last; # get out now
}
sleep 1;
}
return $diffs; return $diffs;
} }

View File

@@ -80,8 +80,8 @@ ok(
# other than to ensure that there's at least one for each table. # other than to ensure that there's at least one for each table.
$row = $master_dbh->selectrow_arrayref("select count(*) from percona.checksums"); $row = $master_dbh->selectrow_arrayref("select count(*) from percona.checksums");
ok( ok(
$row->[0] > 30 && $row->[0] < 50, $row->[0] > 30 && $row->[0] < 60,
'Between 30 and 50 chunks' 'Between 30 and 60 chunks'
) or diag($row->[0]); ) or diag($row->[0]);
# ############################################################################ # ############################################################################