From 9b4c80fd0fd4d991f91544e075d32e72cb44fee3 Mon Sep 17 00:00:00 2001 From: Brian Fraser Date: Fri, 9 Nov 2012 10:32:22 -0300 Subject: [PATCH] Fixes for bugs 1074179 and the ptc part of 1050737: division by zero errors when nibble_time is zero --- bin/pt-table-checksum | 11 ++++++----- t/pt-table-checksum/bugs.t | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index 5f92d279..7d5047a7 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -9232,14 +9232,15 @@ sub main { # Update the rate of rows per second for the entire server. # This is used for the initial chunk size of the next table. $total_rows += $cnt; - $total_time += $tbl->{nibble_time}; - $total_rate = int($total_rows / $total_time); + $total_time += ($tbl->{nibble_time} || 0); + $total_rate = $total_time ? int($total_rows / $total_time) : 0; PTDEBUG && _d('Total avg rate:', $total_rate); # Adjust chunk size. This affects the next chunk. if ( $o->get('chunk-time') ) { - $tbl->{chunk_size} - = $tbl->{rate}->update($cnt, $tbl->{nibble_time}); + $tbl->{chunk_size} = $tbl->{nibble_time} + ? $tbl->{rate}->update($cnt, $tbl->{nibble_time}) + : $o->get('chunk-time'); if ( $tbl->{chunk_size} < 1 ) { # This shouldn't happen. WeightedAvgRate::update() may return @@ -9255,7 +9256,7 @@ sub main { . "or increase --chunk-time. The last chunk, number " . "$chunk of table $tbl->{db}.$tbl->{tbl}, " . "selected $cnt rows and took " - . sprintf('%.3f', $tbl->{nibble_time}) + . sprintf('%.3f', $tbl->{nibble_time} || 0) . " seconds to execute.\n"); } } diff --git a/t/pt-table-checksum/bugs.t b/t/pt-table-checksum/bugs.t index f31e6a86..5cb46a15 100644 --- a/t/pt-table-checksum/bugs.t +++ b/t/pt-table-checksum/bugs.t @@ -192,6 +192,40 @@ like( "Bug 1016131: ptc should skip tables where all columns are excluded" ); +# ############################################################################# +# Illegal division by zero at pt-table-checksum line 7950 +# https://bugs.launchpad.net/percona-toolkit/+bug/1075638 +# and the ptc part of +# divison by zero errors on default Gentoo mysql +# https://bugs.launchpad.net/percona-toolkit/+bug/1050737 +# ############################################################################# + +{ + no warnings qw(redefine once); + my $orig = \&Time::HiRes::time; + my $time = Time::HiRes::time(); + local *pt_table_checksum::time = local *Time::HiRes::time = sub { $time }; + + ($output) = output( + sub { pt_table_checksum::main(@args, + qw(--replicate=pt.checksums -t test.t --chunk-size 10)) + }, + stderr => 1 + ); + + unlike( + $output, + qr/Illegal division by zero/, + "Bugs 1075638 and 1050737: No division by zero error when nibble_time is zero" + ); + + is( + PerconaTest::count_checksum_results($output, 'diffs'), + 3, + "Bug 1075638 and 1050737: ...And we get the correct number of diffs" + ); +} + # ############################################################################# # pt-table-checksum doesn't warn if binlog_format=row or mixed on slaves # https://bugs.launchpad.net/percona-toolkit/+bug/938068