Merge lp:~percona-toolkit-dev/percona-toolkit/fix-1022622-ptcd-case-sensitivity into lp:percona-toolkit/2.1

Proposed by Brian Fraser
Status: Merged
Approved by: Daniel Nichter
Approved revision: 332
Merged at revision: 497
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/fix-1022622-ptcd-case-sensitivity
Merge into: lp:percona-toolkit/2.1
Diff against target: 275 lines (+110/-17)
4 files modified
bin/pt-config-diff (+29/-10)
lib/MySQLConfigComparer.pm (+7/-1)
t/lib/MySQLConfigComparer.t (+36/-2)
t/pt-config-diff/basics.t (+38/-4)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/fix-1022622-ptcd-case-sensitivity
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+117471@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

23 - if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) {
24 - $sql = "/*!40101 SET NAMES $charset*/";
25 + if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
26 + $sql = qq{/*!40101 SET NAMES "$charset"*/};

Is that part of the bug fix? Or what's it related to?

Revision history for this message
Brian Fraser (fraserbn) wrote :

Looks like that's from running update-modules on ptcd.

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-config-diff'
2--- bin/pt-config-diff 2012-07-13 01:42:54 +0000
3+++ bin/pt-config-diff 2012-07-31 16:04:38 +0000
4@@ -1291,7 +1291,7 @@
5 PTDEBUG && _d($dbh, $sql);
6 my ($sql_mode) = eval { $dbh->selectrow_array($sql) };
7 if ( $EVAL_ERROR ) {
8- die $EVAL_ERROR;
9+ die "Error getting the current SQL_MODE: $EVAL_ERROR";
10 }
11
12 $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
13@@ -1301,15 +1301,17 @@
14 PTDEBUG && _d($dbh, $sql);
15 eval { $dbh->do($sql) };
16 if ( $EVAL_ERROR ) {
17- die $EVAL_ERROR;
18+ die "Error setting SQL_QUOTE_SHOW_CREATE, SQL_MODE"
19+ . ($sql_mode ? " and $sql_mode" : '')
20+ . ": $EVAL_ERROR";
21 }
22
23- if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) {
24- $sql = "/*!40101 SET NAMES $charset*/";
25+ if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
26+ $sql = qq{/*!40101 SET NAMES "$charset"*/};
27 PTDEBUG && _d($dbh, ':', $sql);
28 eval { $dbh->do($sql) };
29 if ( $EVAL_ERROR ) {
30- die $EVAL_ERROR;
31+ die "Error setting NAMES to $charset: $EVAL_ERROR";
32 }
33 PTDEBUG && _d('Enabling charset for STDOUT');
34 if ( $charset eq 'utf8' ) {
35@@ -1321,12 +1323,12 @@
36 }
37 }
38
39- if ( $self->prop('set-vars') ) {
40- $sql = "SET " . $self->prop('set-vars');
41+ if ( my $var = $self->prop('set-vars') ) {
42+ $sql = "SET $var";
43 PTDEBUG && _d($dbh, ':', $sql);
44 eval { $dbh->do($sql) };
45 if ( $EVAL_ERROR ) {
46- die $EVAL_ERROR;
47+ die "Error setting $var: $EVAL_ERROR";
48 }
49 }
50 }
51@@ -1451,6 +1453,7 @@
52 dsn_name => $dp->as_string($dsn, [qw(h P S)]),
53 hostname => '',
54 set => $args{set},
55+ NAME_lc => defined($args{NAME_lc}) ? $args{NAME_lc} : 1,
56 dbh_set => 0,
57 OptionParser => $o,
58 DSNParser => $dp,
59@@ -1488,7 +1491,10 @@
60
61 PTDEBUG && _d($dbh, 'Setting dbh');
62
63- $dbh->{FetchHashKeyName} = 'NAME_lc';
64+ if ( !exists $self->{NAME_lc}
65+ || (defined $self->{NAME_lc} && $self->{NAME_lc}) ) {
66+ $dbh->{FetchHashKeyName} = 'NAME_lc';
67+ }
68
69 my $sql = 'SELECT @@hostname, @@server_id';
70 PTDEBUG && _d($dbh, $sql);
71@@ -2382,6 +2388,9 @@
72 value_is_optional => \%value_is_optional,
73 any_value_is_true => \%any_value_is_true,
74 base_path => \%base_path,
75+ ignore_case => exists $args{ignore_case}
76+ ? $args{ignore_case}
77+ : 1,
78 };
79
80 return bless $self, $class;
81@@ -2408,6 +2417,7 @@
82 my $config0 = $configs->[0];
83 my $last_config = @$configs - 1;
84 my $vars = $self->_get_shared_vars(%args);
85+ my $ignore_case = $self->{ignore_case};
86
87 my $diffs;
88 VARIABLE:
89@@ -2432,7 +2442,9 @@
90 next CONFIG if $val0 == $valN;
91 }
92 else {
93- next CONFIG if $val0 eq $valN;
94+ next CONFIG if $ignore_case
95+ ? lc($val0) eq lc($valN)
96+ : $val0 eq $valN;
97
98 if ( $config0->format() ne $configN->format() ) {
99 if ( $any_value_is_true->{$var} ) {
100@@ -2933,6 +2945,7 @@
101 my $trp = new TextResultSetParser();
102 my $config_cmp = new MySQLConfigComparer(
103 ignore_variables => $o->get('ignore-variables'),
104+ ignore_case => $o->get('ignore-case'),
105 );
106 my %common_modules = (
107 DSNParser => $dp,
108@@ -3162,6 +3175,12 @@
109
110 Prompt for a password when connecting to MySQL.
111
112+=item --[no]ignore-case
113+
114+default: yes
115+
116+Compare the variables case-insensitively.
117+
118 =item --charset
119
120 short form: -A; type: string
121
122=== modified file 'lib/MySQLConfigComparer.pm'
123--- lib/MySQLConfigComparer.pm 2012-01-19 19:46:56 +0000
124+++ lib/MySQLConfigComparer.pm 2012-07-31 16:04:38 +0000
125@@ -126,6 +126,9 @@
126 value_is_optional => \%value_is_optional,
127 any_value_is_true => \%any_value_is_true,
128 base_path => \%base_path,
129+ ignore_case => exists $args{ignore_case}
130+ ? $args{ignore_case}
131+ : 1,
132 };
133
134 return bless $self, $class;
135@@ -172,6 +175,7 @@
136 my $config0 = $configs->[0];
137 my $last_config = @$configs - 1;
138 my $vars = $self->_get_shared_vars(%args);
139+ my $ignore_case = $self->{ignore_case};
140
141 # Compare variables from first config (config0) to other configs (configN).
142 my $diffs;
143@@ -197,7 +201,9 @@
144 next CONFIG if $val0 == $valN;
145 }
146 else {
147- next CONFIG if $val0 eq $valN;
148+ next CONFIG if $ignore_case
149+ ? lc($val0) eq lc($valN)
150+ : $val0 eq $valN;
151
152 # Special rules apply when comparing different inputs/formats,
153 # e.g. when comparing an option file to SHOW VARIABLES. This
154
155=== modified file 't/lib/MySQLConfigComparer.t'
156--- t/lib/MySQLConfigComparer.t 2012-03-06 13:56:08 +0000
157+++ t/lib/MySQLConfigComparer.t 2012-07-31 16:04:38 +0000
158@@ -9,7 +9,7 @@
159 use strict;
160 use warnings FATAL => 'all';
161 use English qw(-no_match_vars);
162-use Test::More tests => 16;
163+use Test::More;
164
165 use TextResultSetParser();
166 use MySQLConfigComparer;
167@@ -370,6 +370,39 @@
168 }
169
170 # #############################################################################
171+# Case insensitivity
172+# #############################################################################
173+
174+$c1 = new MySQLConfig(
175+ result_set => [['binlog_format', 'MIXED']],
176+ format => 'option_file',
177+);
178+
179+$c2 = new MySQLConfig(
180+ result_set => [['binlog_format', 'mixed']],
181+ format => 'option_file',
182+);
183+
184+is_deeply(
185+ diff($c1, $c2),
186+ undef,
187+ "Case insensitivity is on by default"
188+);
189+
190+my $case_cc = MySQLConfigComparer->new( ignore_case => undef, );
191+
192+is_deeply(
193+ $case_cc->diff(configs => [$c1, $c2]),
194+ {
195+ binlog_format => [
196+ 'MIXED',
197+ 'mixed'
198+ ]
199+ },
200+ "..but can be turned off"
201+);
202+
203+# #############################################################################
204 # Done.
205 # #############################################################################
206 {
207@@ -382,4 +415,5 @@
208 qr/Complete test coverage/,
209 '_d() works'
210 );
211-exit;
212+
213+done_testing;
214
215=== modified file 't/pt-config-diff/basics.t'
216--- t/pt-config-diff/basics.t 2012-06-03 19:14:30 +0000
217+++ t/pt-config-diff/basics.t 2012-07-31 16:04:38 +0000
218@@ -26,11 +26,9 @@
219 elsif ( !$slave_dbh ) {
220 plan skip_all => 'Cannot connect to sandbox slave';
221 }
222-else {
223- plan tests => 13;
224-}
225
226 my $cnf = '/tmp/12345/my.sandbox.cnf';
227+my $samples = "$trunk/t/pt-config-diff/samples/";
228 my $output;
229 my $retval;
230
231@@ -163,7 +161,43 @@
232 );
233
234 # #############################################################################
235+# Case insensitivity
236+# #############################################################################
237+
238+use File::Spec;
239+
240+$output = output(
241+ sub { $retval = pt_config_diff::main(
242+ File::Spec->catfile($samples, "case1.cnf"),
243+ File::Spec->catfile($samples, "case2.cnf"),
244+ ) },
245+ stderr => 1,
246+);
247+
248+is(
249+ $output,
250+ "",
251+ "Case-insensitive by default, finds no diffs"
252+);
253+
254+$output = output(
255+ sub { $retval = pt_config_diff::main(
256+ File::Spec->catfile($samples, "case1.cnf"),
257+ File::Spec->catfile($samples, "case2.cnf"),
258+ '--no-ignore-case',
259+ ) },
260+ stderr => 1,
261+);
262+
263+like(
264+ $output,
265+ qr/binlog_format\s+genlog\s+GENLOG/,
266+ "With case-insensitivity turned off, finds one diff"
267+);
268+
269+# #############################################################################
270 # Done.
271 # #############################################################################
272 ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
273-exit;
274+
275+done_testing;

Subscribers

People subscribed via source and target branches