Merge lp:~percona-toolkit-dev/percona-toolkit/fix-ptc-bug-1210537 into lp:~percona-toolkit-dev/percona-toolkit/release-2.2.5

Proposed by Daniel Nichter
Status: Merged
Approved by: Daniel Nichter
Approved revision: 626
Merged at revision: 622
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/fix-ptc-bug-1210537
Merge into: lp:~percona-toolkit-dev/percona-toolkit/release-2.2.5
Diff against target: 176 lines (+77/-20)
4 files modified
bin/pt-table-checksum (+13/-4)
lib/MasterSlave.pm (+14/-7)
t/lib/MasterSlave.t (+28/-9)
t/pt-table-checksum/bugs.t (+22/-0)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/fix-ptc-bug-1210537
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+188894@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) :
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 2013-08-08 19:28:36 +0000
3+++ bin/pt-table-checksum 2013-10-02 18:43:27 +0000
4@@ -9208,15 +9208,24 @@
5 }
6
7 my $trimmed_nodes = Cxn->remove_duplicate_cxns(
8- cxns => [ $master_cxn, @$slaves ],
9- );
10+ cxns => [ $master_cxn, @$slaves ],
11+ );
12 ($master_cxn, @$slaves) = @$trimmed_nodes;
13
14+ # If no slaves or nodes were found, and a recursion method was given
15+ # (implicitly or explicitly), and that method is not none, then warn
16+ # and continue but exit non-zero because there won't be any diffs but
17+ # this could be a false-positive from having no slaves/nodes to check.
18+ # https://bugs.launchpad.net/percona-toolkit/+bug/1210537
19 PTDEBUG && _d(scalar @$slaves, 'slaves found');
20- if ( !@$slaves && $o->get('recursion-method')->[0] ne 'none' ) {
21+ if ( !@$slaves
22+ && (($o->get('recursion-method')->[0] || '') ne 'none'
23+ || $autodiscover_cluster))
24+ {
25 $exit_status |= 1;
26 if ( $o->get('quiet') < 2 ) {
27- warn "Diffs cannot be detected because no slaves were found. "
28+ my $type = $autodiscover_cluster ? 'cluster nodes' : 'slaves';
29+ warn "Diffs cannot be detected because no $type were found. "
30 . "Please read the --recursion-method documentation for "
31 . "information.\n";
32 }
33
34=== modified file 'lib/MasterSlave.pm'
35--- lib/MasterSlave.pm 2013-04-12 15:58:10 +0000
36+++ lib/MasterSlave.pm 2013-10-02 18:43:27 +0000
37@@ -32,8 +32,18 @@
38 sub check_recursion_method {
39 my ($methods) = @_;
40
41- if ( @$methods != 1 ) {
42- if ( grep({ !m/processlist|hosts/i } @$methods)
43+ # Check that each method is valid.
44+ foreach my $method ( @$methods ) {
45+ die "Invalid recursion method: " . ($method || 'undef') . "\n"
46+ unless $method && $method =~ m/^(?:processlist$|hosts$|none$|cluster|dsn=)/i;
47+ }
48+
49+ # Check for invalid combination of methods.
50+ if ( @$methods > 1 ) {
51+ if ( grep( { m/none/ } @$methods) && grep( {! m/none/ } @$methods) ) {
52+ die "--recursion-method=none cannot be combined with other methods\n";
53+ }
54+ elsif ( grep({ !m/processlist|hosts/i } @$methods)
55 && $methods->[0] !~ /^dsn=/i )
56 {
57 die "Invalid combination of recursion methods: "
58@@ -41,11 +51,8 @@
59 . "Only hosts and processlist may be combined.\n"
60 }
61 }
62- else {
63- my ($method) = @$methods;
64- die "Invalid recursion method: " . ( $method || 'undef' )
65- unless $method && $method =~ m/^(?:processlist$|hosts$|none$|dsn=)/i;
66- }
67+
68+ return;
69 }
70
71 sub new {
72
73=== modified file 't/lib/MasterSlave.t'
74--- t/lib/MasterSlave.t 2012-08-14 23:08:06 +0000
75+++ t/lib/MasterSlave.t 2013-10-02 18:43:27 +0000
76@@ -11,10 +11,6 @@
77 use English qw(-no_match_vars);
78 use Test::More;
79
80-if ( !$ENV{SLOW_TESTS} ) {
81- plan skip_all => "lib/MasterSlave.t is a top 5 slowest file; set SLOW_TESTS=1 to enable it.";
82-}
83-
84 use MasterSlave;
85 use DSNParser;
86 use VersionParser;
87@@ -709,28 +705,51 @@
88 # ############################################################################
89 # Invalid recursion methods are caught
90 # ############################################################################
91-local $EVAL_ERROR;
92 eval {
93 MasterSlave::check_recursion_method([qw(stuff)])
94 };
95-
96 like(
97 $EVAL_ERROR,
98 qr/Invalid recursion method: stuff/,
99 "--recursion-method stuff causes error"
100 );
101
102-local $EVAL_ERROR;
103 eval {
104 MasterSlave::check_recursion_method([qw(processlist stuff)])
105 };
106-
107 like(
108 $EVAL_ERROR,
109- qr/Invalid combination of recursion methods: processlist, stuff/,
110+ qr/Invalid recursion method: stuff/,
111 "--recursion-method processlist,stuff causes error",
112 );
113
114+eval {
115+ MasterSlave::check_recursion_method([qw(none hosts)])
116+};
117+like(
118+ $EVAL_ERROR,
119+ qr/none cannot be combined with other methods/,
120+ "--recursion-method none,hosts"
121+);
122+
123+eval {
124+ MasterSlave::check_recursion_method([qw(cluster none)])
125+};
126+like(
127+ $EVAL_ERROR,
128+ qr/none cannot be combined with other methods/,
129+ "--recursion-method cluster,none"
130+);
131+
132+eval {
133+ MasterSlave::check_recursion_method([qw(none none)])
134+};
135+like(
136+ $EVAL_ERROR,
137+ qr/Invalid combination of recursion methods: none, none/,
138+ "--recursion-method none,none"
139+);
140+
141 # #############################################################################
142 # Done.
143 # #############################################################################
144
145=== modified file 't/pt-table-checksum/bugs.t'
146--- t/pt-table-checksum/bugs.t 2013-03-02 02:02:13 +0000
147+++ t/pt-table-checksum/bugs.t 2013-10-02 18:43:27 +0000
148@@ -273,6 +273,28 @@
149 }
150
151 # #############################################################################
152+# pt-table-checksum --recursion-method cluster crashes
153+# https://bugs.launchpad.net/percona-toolkit/+bug/1210537
154+# #############################################################################
155+
156+$output = output(sub {
157+ pt_table_checksum::main($master_dsn,
158+ qw(--recursion-method cluster -t mysql.user)
159+ )},
160+ stderr => 1,
161+);
162+unlike(
163+ $output,
164+ qr/uninitialized value/,
165+ "Bug 1210537: no crash with --recursion-method cluster"
166+);
167+like(
168+ $output,
169+ qr/mysql.user/,
170+ "Bug 1210537: tool ran"
171+);
172+
173+# #############################################################################
174 # Done.
175 # #############################################################################
176 $sb->wipe_clean($master_dbh);

Subscribers

People subscribed via source and target branches

to all changes: