Merge lp:~percona-toolkit-dev/percona-toolkit/fix-1050737-1075638-ptc-division-by-zero-nibble_time into lp:percona-toolkit/2.1

Proposed by Brian Fraser on 2012-11-16
Status: Merged
Approved by: Daniel Nichter on 2012-12-05
Approved revision: 451
Merged at revision: 482
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/fix-1050737-1075638-ptc-division-by-zero-nibble_time
Merge into: lp:percona-toolkit/2.1
Diff against target: 77 lines (+40/-5)
2 files modified
bin/pt-table-checksum (+6/-5)
t/pt-table-checksum/bugs.t (+34/-0)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/fix-1050737-1075638-ptc-division-by-zero-nibble_time
Reviewer Review Type Date Requested Status
Daniel Nichter 2012-11-16 Approve on 2012-12-05
Review via email: mp+134589@code.launchpad.net
To post a comment you must log in.
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/pt-table-checksum'
2--- bin/pt-table-checksum 2012-11-13 15:22:01 +0000
3+++ bin/pt-table-checksum 2012-11-16 01:11:24 +0000
4@@ -9391,14 +9391,15 @@
5 # Update the rate of rows per second for the entire server.
6 # This is used for the initial chunk size of the next table.
7 $total_rows += $cnt;
8- $total_time += $tbl->{nibble_time};
9- $total_rate = int($total_rows / $total_time);
10+ $total_time += ($tbl->{nibble_time} || 0);
11+ $total_rate = $total_time ? int($total_rows / $total_time) : 0;
12 PTDEBUG && _d('Total avg rate:', $total_rate);
13
14 # Adjust chunk size. This affects the next chunk.
15 if ( $o->get('chunk-time') ) {
16- $tbl->{chunk_size}
17- = $tbl->{rate}->update($cnt, $tbl->{nibble_time});
18+ $tbl->{chunk_size} = $tbl->{nibble_time}
19+ ? $tbl->{rate}->update($cnt, $tbl->{nibble_time})
20+ : $o->get('chunk-time');
21
22 if ( $tbl->{chunk_size} < 1 ) {
23 # This shouldn't happen. WeightedAvgRate::update() may return
24@@ -9414,7 +9415,7 @@
25 . "or increase --chunk-time. The last chunk, number "
26 . "$chunk of table $tbl->{db}.$tbl->{tbl}, "
27 . "selected $cnt rows and took "
28- . sprintf('%.3f', $tbl->{nibble_time})
29+ . sprintf('%.3f', $tbl->{nibble_time} || 0)
30 . " seconds to execute.\n");
31 }
32 }
33
34=== modified file 't/pt-table-checksum/bugs.t'
35--- t/pt-table-checksum/bugs.t 2012-11-08 20:38:04 +0000
36+++ t/pt-table-checksum/bugs.t 2012-11-16 01:11:24 +0000
37@@ -193,6 +193,40 @@
38 );
39
40 # #############################################################################
41+# Illegal division by zero at pt-table-checksum line 7950
42+# https://bugs.launchpad.net/percona-toolkit/+bug/1075638
43+# and the ptc part of
44+# divison by zero errors on default Gentoo mysql
45+# https://bugs.launchpad.net/percona-toolkit/+bug/1050737
46+# #############################################################################
47+
48+{
49+ no warnings qw(redefine once);
50+ my $orig = \&Time::HiRes::time;
51+ my $time = Time::HiRes::time();
52+ local *pt_table_checksum::time = local *Time::HiRes::time = sub { $time };
53+
54+ ($output) = output(
55+ sub { pt_table_checksum::main(@args,
56+ qw(--replicate=pt.checksums -t test.t --chunk-size 10))
57+ },
58+ stderr => 1
59+ );
60+
61+ unlike(
62+ $output,
63+ qr/Illegal division by zero/,
64+ "Bugs 1075638 and 1050737: No division by zero error when nibble_time is zero"
65+ );
66+
67+ is(
68+ PerconaTest::count_checksum_results($output, 'diffs'),
69+ 3,
70+ "Bug 1075638 and 1050737: ...And we get the correct number of diffs"
71+ );
72+}
73+
74+# #############################################################################
75 # pt-table-checksum doesn't warn if binlog_format=row or mixed on slaves
76 # https://bugs.launchpad.net/percona-toolkit/+bug/938068
77 # #############################################################################

Subscribers

People subscribed via source and target branches