Merge lp:~percona-toolkit-dev/percona-toolkit/enhanced-set-vars-for-bug-1113301 into lp:~percona-toolkit-dev/percona-toolkit/pt-osc-metadata-lock-bug-1113301

Proposed by Daniel Nichter
Status: Merged
Merged at revision: 542
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/enhanced-set-vars-for-bug-1113301
Merge into: lp:~percona-toolkit-dev/percona-toolkit/pt-osc-metadata-lock-bug-1113301
Diff against target: 4956 lines (+2519/-490)
67 files modified
bin/pt-archiver (+109/-15)
bin/pt-config-diff (+108/-13)
bin/pt-deadlock-logger (+108/-13)
bin/pt-duplicate-key-checker (+108/-13)
bin/pt-find (+108/-13)
bin/pt-fk-error-logger (+108/-13)
bin/pt-heartbeat (+108/-13)
bin/pt-index-usage (+108/-13)
bin/pt-kill (+108/-13)
bin/pt-query-advisor (+108/-13)
bin/pt-query-digest (+108/-13)
bin/pt-show-grants (+108/-13)
bin/pt-slave-delay (+108/-13)
bin/pt-slave-find (+108/-13)
bin/pt-slave-restart (+108/-13)
bin/pt-table-checksum (+110/-62)
bin/pt-table-sync (+108/-13)
bin/pt-table-usage (+114/-22)
bin/pt-upgrade (+108/-13)
bin/pt-variable-advisor (+108/-13)
bin/pt-visual-explain (+114/-22)
lib/DSNParser.pm (+2/-0)
t/lib/Cxn.t (+14/-2)
t/lib/DSNParser.t (+11/-5)
t/lib/KeySize.t (+4/-4)
t/lib/Percona/XtraDB/Cluster-no-PXC.t (+14/-2)
t/lib/Percona/XtraDB/Cluster.t (+14/-2)
t/lib/ReplicaLagWaiter.t (+14/-2)
t/pt-archiver/check_slave_lag.t (+10/-18)
t/pt-fifo-split/pt-fifo-split.t (+73/-36)
t/pt-online-schema-change/ansi_quotes.t (+2/-1)
t/pt-online-schema-change/bugs.t (+2/-1)
t/pt-online-schema-change/check_alter.t (+2/-1)
t/pt-online-schema-change/privs.t (+2/-1)
t/pt-online-schema-change/pxc.t (+0/-2)
t/pt-online-schema-change/rename_columns.t (+2/-1)
t/pt-table-checksum/basics.t (+3/-3)
t/pt-table-checksum/bugs.t (+2/-2)
t/pt-table-checksum/char_chunking.t (+2/-2)
t/pt-table-checksum/chunk_index.t (+7/-7)
t/pt-table-checksum/chunk_size.t (+2/-2)
t/pt-table-checksum/create_replicate_table.t (+2/-2)
t/pt-table-checksum/error_handling.t (+3/-3)
t/pt-table-checksum/filters.t (+2/-2)
t/pt-table-checksum/float_precision.t (+2/-2)
t/pt-table-checksum/fnv_64.t (+2/-2)
t/pt-table-checksum/ignore_columns.t (+2/-2)
t/pt-table-checksum/issue_388.t (+2/-2)
t/pt-table-checksum/issue_47.t (+2/-2)
t/pt-table-checksum/issue_602.t (+2/-2)
t/pt-table-checksum/option_sanity.t (+5/-5)
t/pt-table-checksum/privs.t (+2/-2)
t/pt-table-checksum/progress.t (+2/-2)
t/pt-table-checksum/pxc.t (+2/-2)
t/pt-table-checksum/replication_filters.t (+2/-2)
t/pt-table-checksum/resume.t (+2/-2)
t/pt-table-checksum/run_time.t (+2/-2)
t/pt-table-checksum/skip_innodb.t (+2/-2)
t/pt-table-checksum/standard_options.t (+2/-2)
t/pt-table-checksum/throttle.t (+2/-2)
t/pt-table-sync/basics.t (+3/-3)
t/pt-table-sync/bugs.t (+2/-2)
t/pt-table-sync/filters.t (+2/-2)
t/pt-table-sync/issue_560.t (+1/-1)
t/pt-table-sync/issue_627.t (+1/-1)
t/pt-table-sync/issue_996.t (+1/-1)
t/pt-table-sync/triggers.t (+2/-2)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/enhanced-set-vars-for-bug-1113301
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+151339@code.launchpad.net

Description of the change

This branch was branched from lp:~percona-toolkit-dev/percona-toolkit/pt-osc-metadata-lock-bug-1113301 to update all the other tools' --set-vars and remove --lock-wait-timeout from pt-table-checksum.

To post a comment you must log in.
545. By Daniel Nichter

Fix tests to work with new --set-vars, and change --lock-wait-timeout to --set-vars innodb_lock_wait_timeout in tests.

546. By Daniel Nichter

Fix more tests for set-vars.

547. By Daniel Nichter

Don't set innodb_lock_wait_timeout in tests because it generates a warning on 5.0 and 5.1 that the tests don't suppress.

548. By Daniel Nichter

Pass file to OptionParser->new() in tests so OptionParser::get_vars() works.

549. By Daniel Nichter

Fix t/lib/Percona/XtraDB/Cluster-no-PXC.t.

550. By Daniel Nichter

Truly fix t[/pt-fifo-split/pt-fifo-split.t.

551. By Daniel Nichter

Fix error in t/lib/DSNParser.t.

552. By Daniel Nichter

Make t/lib/KeySize.t flexible because EXPLAIN plans differ slightly.

553. By Daniel Nichter

Skip t/pt-archiver/check_slave_lag.t on MySQL 5.6 because the trick doesn't work.

Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

Tests are passing again.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/pt-archiver'
2--- bin/pt-archiver 2013-02-27 00:01:17 +0000
3+++ bin/pt-archiver 2013-03-03 15:43:19 +0000
4@@ -712,6 +712,7 @@
5
6 use List::Util qw(max);
7 use Getopt::Long;
8+use Data::Dumper;
9
10 my $POD_link_re = '[LC]<"?([^">]+)"?>';
11
12@@ -1695,6 +1696,45 @@
13 );
14 };
15
16+sub set_vars {
17+ my ($self, $file) = @_;
18+ $file ||= $self->{file} || __FILE__;
19+
20+ my %user_vars;
21+ my $user_vars = $self->has('set-vars') ? $self->get('set-vars') : undef;
22+ if ( $user_vars ) {
23+ foreach my $var_val ( @$user_vars ) {
24+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
25+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
26+ $user_vars{$var} = {
27+ val => $val,
28+ default => 0,
29+ };
30+ }
31+ }
32+
33+ my %default_vars;
34+ my $default_vars = $self->read_para_after($file, qr/MAGIC_set_vars/);
35+ if ( $default_vars ) {
36+ %default_vars = map {
37+ my $var_val = $_;
38+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
39+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
40+ $var => {
41+ val => $val,
42+ default => 1,
43+ };
44+ } split("\n", $default_vars);
45+ }
46+
47+ my %vars = (
48+ %default_vars, # first the tool's defaults
49+ %user_vars, # then the user's which overwrite the defaults
50+ );
51+ PTDEBUG && _d('--set-vars:', Dumper(\%vars));
52+ return \%vars;
53+}
54+
55 sub _d {
56 my ($package, undef, $line) = caller 0;
57 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
58@@ -2397,7 +2437,7 @@
59
60 if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
61 $sql = qq{/*!40101 SET NAMES "$charset"*/};
62- PTDEBUG && _d($dbh, ':', $sql);
63+ PTDEBUG && _d($dbh, $sql);
64 eval { $dbh->do($sql) };
65 if ( $EVAL_ERROR ) {
66 die "Error setting NAMES to $charset: $EVAL_ERROR";
67@@ -2412,13 +2452,8 @@
68 }
69 }
70
71- if ( my $var = $self->prop('set-vars') ) {
72- $sql = "SET $var";
73- PTDEBUG && _d($dbh, ':', $sql);
74- eval { $dbh->do($sql) };
75- if ( $EVAL_ERROR ) {
76- die "Error setting $var: $EVAL_ERROR";
77- }
78+ if ( my $vars = $self->prop('set-vars') ) {
79+ $self->set_vars($dbh, $vars);
80 }
81
82 $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
83@@ -2493,6 +2528,55 @@
84 return \%new_dsn;
85 }
86
87+sub set_vars {
88+ my ($self, $dbh, $vars) = @_;
89+
90+ foreach my $var ( sort keys %$vars ) {
91+ my $val = $vars->{$var}->{val};
92+
93+ (my $quoted_var = $var) =~ s/_/\\_/;
94+ my ($var_exists, $current_val);
95+ eval {
96+ ($var_exists, $current_val) = $dbh->selectrow_array(
97+ "SHOW VARIABLES LIKE '$quoted_var'");
98+ };
99+ my $e = $EVAL_ERROR;
100+ if ( $e ) {
101+ PTDEBUG && _d($e);
102+ }
103+
104+ if ( $vars->{$var}->{default} && !$var_exists ) {
105+ PTDEBUG && _d('Not setting default var', $var,
106+ 'because it does not exist');
107+ next;
108+ }
109+
110+ if ( $current_val && $current_val eq $val ) {
111+ PTDEBUG && _d('Not setting var', $var, 'because its value',
112+ 'is already', $val);
113+ next;
114+ }
115+
116+ my $sql = "SET SESSION $var=$val";
117+ PTDEBUG && _d($dbh, $sql);
118+ eval { $dbh->do($sql) };
119+ if ( my $set_error = $EVAL_ERROR ) {
120+ chomp($set_error);
121+ $set_error =~ s/ at \S+ line \d+//;
122+ my $msg = "Error setting $var: $set_error";
123+ if ( $current_val ) {
124+ $msg .= " The current value for $var is $current_val. "
125+ . "If the variable is read only (not dynamic), specify "
126+ . "--set-vars $var=$current_val to avoid this warning, "
127+ . "else manually set the variable and restart MySQL.";
128+ }
129+ warn $msg . "\n\n";
130+ }
131+ }
132+
133+ return;
134+}
135+
136 sub _d {
137 my ($package, undef, $line) = caller 0;
138 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
139@@ -5335,7 +5419,7 @@
140 $o->get_opts();
141
142 my $dp = $o->DSNParser();
143- $dp->prop('set-vars', $o->get('set-vars'));
144+ $dp->prop('set-vars', $o->set_vars());
145
146 # Frequently used options.
147 $src = $o->get('source');
148@@ -7094,12 +7178,22 @@
149
150 =item --set-vars
151
152-type: string; default: wait_timeout=10000
153-
154-Set these MySQL variables.
155-
156-Specify any variables you want to be set immediately after connecting to MySQL.
157-These will be included in a C<SET> command.
158+type: Array
159+
160+Set the MySQL variables in this comma-separated list of C<variable=value> pairs.
161+
162+By default, the tool sets:
163+
164+=for comment ignore-pt-internal-value
165+MAGIC_set_vars
166+
167+ wait_timeout=10000
168+
169+Variables specified on the command line override these defaults. For
170+example, specifying C<--set-vars wait_timeout=500> overrides the default
171+value of C<10000>.
172+
173+The tool prints a warning and continues if a variable cannot be set.
174
175 =item --share-lock
176
177
178=== modified file 'bin/pt-config-diff'
179--- bin/pt-config-diff 2013-02-26 23:57:02 +0000
180+++ bin/pt-config-diff 2013-03-03 15:43:19 +0000
181@@ -712,6 +712,7 @@
182
183 use List::Util qw(max);
184 use Getopt::Long;
185+use Data::Dumper;
186
187 my $POD_link_re = '[LC]<"?([^">]+)"?>';
188
189@@ -1695,6 +1696,45 @@
190 );
191 };
192
193+sub set_vars {
194+ my ($self, $file) = @_;
195+ $file ||= $self->{file} || __FILE__;
196+
197+ my %user_vars;
198+ my $user_vars = $self->has('set-vars') ? $self->get('set-vars') : undef;
199+ if ( $user_vars ) {
200+ foreach my $var_val ( @$user_vars ) {
201+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
202+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
203+ $user_vars{$var} = {
204+ val => $val,
205+ default => 0,
206+ };
207+ }
208+ }
209+
210+ my %default_vars;
211+ my $default_vars = $self->read_para_after($file, qr/MAGIC_set_vars/);
212+ if ( $default_vars ) {
213+ %default_vars = map {
214+ my $var_val = $_;
215+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
216+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
217+ $var => {
218+ val => $val,
219+ default => 1,
220+ };
221+ } split("\n", $default_vars);
222+ }
223+
224+ my %vars = (
225+ %default_vars, # first the tool's defaults
226+ %user_vars, # then the user's which overwrite the defaults
227+ );
228+ PTDEBUG && _d('--set-vars:', Dumper(\%vars));
229+ return \%vars;
230+}
231+
232 sub _d {
233 my ($package, undef, $line) = caller 0;
234 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
235@@ -1986,7 +2026,7 @@
236
237 if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
238 $sql = qq{/*!40101 SET NAMES "$charset"*/};
239- PTDEBUG && _d($dbh, ':', $sql);
240+ PTDEBUG && _d($dbh, $sql);
241 eval { $dbh->do($sql) };
242 if ( $EVAL_ERROR ) {
243 die "Error setting NAMES to $charset: $EVAL_ERROR";
244@@ -2001,13 +2041,8 @@
245 }
246 }
247
248- if ( my $var = $self->prop('set-vars') ) {
249- $sql = "SET $var";
250- PTDEBUG && _d($dbh, ':', $sql);
251- eval { $dbh->do($sql) };
252- if ( $EVAL_ERROR ) {
253- die "Error setting $var: $EVAL_ERROR";
254- }
255+ if ( my $vars = $self->prop('set-vars') ) {
256+ $self->set_vars($dbh, $vars);
257 }
258
259 $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
260@@ -2082,6 +2117,55 @@
261 return \%new_dsn;
262 }
263
264+sub set_vars {
265+ my ($self, $dbh, $vars) = @_;
266+
267+ foreach my $var ( sort keys %$vars ) {
268+ my $val = $vars->{$var}->{val};
269+
270+ (my $quoted_var = $var) =~ s/_/\\_/;
271+ my ($var_exists, $current_val);
272+ eval {
273+ ($var_exists, $current_val) = $dbh->selectrow_array(
274+ "SHOW VARIABLES LIKE '$quoted_var'");
275+ };
276+ my $e = $EVAL_ERROR;
277+ if ( $e ) {
278+ PTDEBUG && _d($e);
279+ }
280+
281+ if ( $vars->{$var}->{default} && !$var_exists ) {
282+ PTDEBUG && _d('Not setting default var', $var,
283+ 'because it does not exist');
284+ next;
285+ }
286+
287+ if ( $current_val && $current_val eq $val ) {
288+ PTDEBUG && _d('Not setting var', $var, 'because its value',
289+ 'is already', $val);
290+ next;
291+ }
292+
293+ my $sql = "SET SESSION $var=$val";
294+ PTDEBUG && _d($dbh, $sql);
295+ eval { $dbh->do($sql) };
296+ if ( my $set_error = $EVAL_ERROR ) {
297+ chomp($set_error);
298+ $set_error =~ s/ at \S+ line \d+//;
299+ my $msg = "Error setting $var: $set_error";
300+ if ( $current_val ) {
301+ $msg .= " The current value for $var is $current_val. "
302+ . "If the variable is read only (not dynamic), specify "
303+ . "--set-vars $var=$current_val to avoid this warning, "
304+ . "else manually set the variable and restart MySQL.";
305+ }
306+ warn $msg . "\n\n";
307+ }
308+ }
309+
310+ return;
311+}
312+
313 sub _d {
314 my ($package, undef, $line) = caller 0;
315 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
316@@ -4984,7 +5068,7 @@
317 $o->get_opts();
318
319 my $dp = $o->DSNParser();
320- $dp->prop('set-vars', $o->get('set-vars'));
321+ $dp->prop('set-vars', $o->set_vars());
322
323 if ( !$o->get('help') ) {
324 if ( @ARGV < 1 ) {
325@@ -5325,10 +5409,21 @@
326
327 =item --set-vars
328
329-type: string; default: wait_timeout=10000
330-
331-Set these MySQL variables. Immediately after connecting to MySQL, this string
332-will be appended to SET and executed.
333+type: Array
334+
335+Set the MySQL variables in this comma-separated list of C<variable=value> pairs.
336+
337+By default, the tool sets:
338+
339+=for comment ignore-pt-internal-value
340+MAGIC_set_vars
341+
342+ wait_timeout=10000
343+
344+Variables specified on the command line override these defaults. For
345+example, specifying C<--set-vars wait_timeout=500> overrides the defaultvalue of C<10000>.
346+
347+The tool prints a warning and continues if a variable cannot be set.
348
349 =item --socket
350
351
352=== modified file 'bin/pt-deadlock-logger'
353--- bin/pt-deadlock-logger 2013-02-28 02:23:08 +0000
354+++ bin/pt-deadlock-logger 2013-03-03 15:43:19 +0000
355@@ -67,6 +67,7 @@
356
357 use List::Util qw(max);
358 use Getopt::Long;
359+use Data::Dumper;
360
361 my $POD_link_re = '[LC]<"?([^">]+)"?>';
362
363@@ -1050,6 +1051,45 @@
364 );
365 };
366
367+sub set_vars {
368+ my ($self, $file) = @_;
369+ $file ||= $self->{file} || __FILE__;
370+
371+ my %user_vars;
372+ my $user_vars = $self->has('set-vars') ? $self->get('set-vars') : undef;
373+ if ( $user_vars ) {
374+ foreach my $var_val ( @$user_vars ) {
375+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
376+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
377+ $user_vars{$var} = {
378+ val => $val,
379+ default => 0,
380+ };
381+ }
382+ }
383+
384+ my %default_vars;
385+ my $default_vars = $self->read_para_after($file, qr/MAGIC_set_vars/);
386+ if ( $default_vars ) {
387+ %default_vars = map {
388+ my $var_val = $_;
389+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
390+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
391+ $var => {
392+ val => $val,
393+ default => 1,
394+ };
395+ } split("\n", $default_vars);
396+ }
397+
398+ my %vars = (
399+ %default_vars, # first the tool's defaults
400+ %user_vars, # then the user's which overwrite the defaults
401+ );
402+ PTDEBUG && _d('--set-vars:', Dumper(\%vars));
403+ return \%vars;
404+}
405+
406 sub _d {
407 my ($package, undef, $line) = caller 0;
408 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
409@@ -2330,7 +2370,7 @@
410
411 if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
412 $sql = qq{/*!40101 SET NAMES "$charset"*/};
413- PTDEBUG && _d($dbh, ':', $sql);
414+ PTDEBUG && _d($dbh, $sql);
415 eval { $dbh->do($sql) };
416 if ( $EVAL_ERROR ) {
417 die "Error setting NAMES to $charset: $EVAL_ERROR";
418@@ -2345,13 +2385,8 @@
419 }
420 }
421
422- if ( my $var = $self->prop('set-vars') ) {
423- $sql = "SET $var";
424- PTDEBUG && _d($dbh, ':', $sql);
425- eval { $dbh->do($sql) };
426- if ( $EVAL_ERROR ) {
427- die "Error setting $var: $EVAL_ERROR";
428- }
429+ if ( my $vars = $self->prop('set-vars') ) {
430+ $self->set_vars($dbh, $vars);
431 }
432
433 $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
434@@ -2426,6 +2461,55 @@
435 return \%new_dsn;
436 }
437
438+sub set_vars {
439+ my ($self, $dbh, $vars) = @_;
440+
441+ foreach my $var ( sort keys %$vars ) {
442+ my $val = $vars->{$var}->{val};
443+
444+ (my $quoted_var = $var) =~ s/_/\\_/;
445+ my ($var_exists, $current_val);
446+ eval {
447+ ($var_exists, $current_val) = $dbh->selectrow_array(
448+ "SHOW VARIABLES LIKE '$quoted_var'");
449+ };
450+ my $e = $EVAL_ERROR;
451+ if ( $e ) {
452+ PTDEBUG && _d($e);
453+ }
454+
455+ if ( $vars->{$var}->{default} && !$var_exists ) {
456+ PTDEBUG && _d('Not setting default var', $var,
457+ 'because it does not exist');
458+ next;
459+ }
460+
461+ if ( $current_val && $current_val eq $val ) {
462+ PTDEBUG && _d('Not setting var', $var, 'because its value',
463+ 'is already', $val);
464+ next;
465+ }
466+
467+ my $sql = "SET SESSION $var=$val";
468+ PTDEBUG && _d($dbh, $sql);
469+ eval { $dbh->do($sql) };
470+ if ( my $set_error = $EVAL_ERROR ) {
471+ chomp($set_error);
472+ $set_error =~ s/ at \S+ line \d+//;
473+ my $msg = "Error setting $var: $set_error";
474+ if ( $current_val ) {
475+ $msg .= " The current value for $var is $current_val. "
476+ . "If the variable is read only (not dynamic), specify "
477+ . "--set-vars $var=$current_val to avoid this warning, "
478+ . "else manually set the variable and restart MySQL.";
479+ }
480+ warn $msg . "\n\n";
481+ }
482+ }
483+
484+ return;
485+}
486+
487 sub _d {
488 my ($package, undef, $line) = caller 0;
489 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
490@@ -4254,7 +4338,7 @@
491 $o->get_opts();
492
493 my $dp = $o->DSNParser();
494- $dp->prop('set-vars', $o->get('set-vars'));
495+ $dp->prop('set-vars', $o->set_vars());
496
497 my $src;
498 if ( my $src_dsn_string = shift @ARGV ) {
499@@ -5116,10 +5200,21 @@
500
501 =item --set-vars
502
503-type: string; default: wait_timeout=10000
504-
505-Set these MySQL variables. Immediately after connecting to MySQL, this string
506-will be appended to SET and executed.
507+type: Array
508+
509+Set the MySQL variables in this comma-separated list of C<variable=value> pairs.
510+
511+By default, the tool sets:
512+
513+=for comment ignore-pt-internal-value
514+MAGIC_set_vars
515+
516+ wait_timeout=10000
517+
518+Variables specified on the command line override these defaults. For
519+example, specifying C<--set-vars wait_timeout=500> overrides the defaultvalue of C<10000>.
520+
521+The tool prints a warning and continues if a variable cannot be set.
522
523 =item --socket
524
525
526=== modified file 'bin/pt-duplicate-key-checker'
527--- bin/pt-duplicate-key-checker 2013-02-27 00:01:17 +0000
528+++ bin/pt-duplicate-key-checker 2013-03-03 15:43:19 +0000
529@@ -875,7 +875,7 @@
530
531 if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
532 $sql = qq{/*!40101 SET NAMES "$charset"*/};
533- PTDEBUG && _d($dbh, ':', $sql);
534+ PTDEBUG && _d($dbh, $sql);
535 eval { $dbh->do($sql) };
536 if ( $EVAL_ERROR ) {
537 die "Error setting NAMES to $charset: $EVAL_ERROR";
538@@ -890,13 +890,8 @@
539 }
540 }
541
542- if ( my $var = $self->prop('set-vars') ) {
543- $sql = "SET $var";
544- PTDEBUG && _d($dbh, ':', $sql);
545- eval { $dbh->do($sql) };
546- if ( $EVAL_ERROR ) {
547- die "Error setting $var: $EVAL_ERROR";
548- }
549+ if ( my $vars = $self->prop('set-vars') ) {
550+ $self->set_vars($dbh, $vars);
551 }
552
553 $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
554@@ -971,6 +966,55 @@
555 return \%new_dsn;
556 }
557
558+sub set_vars {
559+ my ($self, $dbh, $vars) = @_;
560+
561+ foreach my $var ( sort keys %$vars ) {
562+ my $val = $vars->{$var}->{val};
563+
564+ (my $quoted_var = $var) =~ s/_/\\_/;
565+ my ($var_exists, $current_val);
566+ eval {
567+ ($var_exists, $current_val) = $dbh->selectrow_array(
568+ "SHOW VARIABLES LIKE '$quoted_var'");
569+ };
570+ my $e = $EVAL_ERROR;
571+ if ( $e ) {
572+ PTDEBUG && _d($e);
573+ }
574+
575+ if ( $vars->{$var}->{default} && !$var_exists ) {
576+ PTDEBUG && _d('Not setting default var', $var,
577+ 'because it does not exist');
578+ next;
579+ }
580+
581+ if ( $current_val && $current_val eq $val ) {
582+ PTDEBUG && _d('Not setting var', $var, 'because its value',
583+ 'is already', $val);
584+ next;
585+ }
586+
587+ my $sql = "SET SESSION $var=$val";
588+ PTDEBUG && _d($dbh, $sql);
589+ eval { $dbh->do($sql) };
590+ if ( my $set_error = $EVAL_ERROR ) {
591+ chomp($set_error);
592+ $set_error =~ s/ at \S+ line \d+//;
593+ my $msg = "Error setting $var: $set_error";
594+ if ( $current_val ) {
595+ $msg .= " The current value for $var is $current_val. "
596+ . "If the variable is read only (not dynamic), specify "
597+ . "--set-vars $var=$current_val to avoid this warning, "
598+ . "else manually set the variable and restart MySQL.";
599+ }
600+ warn $msg . "\n\n";
601+ }
602+ }
603+
604+ return;
605+}
606+
607 sub _d {
608 my ($package, undef, $line) = caller 0;
609 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
610@@ -1003,6 +1047,7 @@
611
612 use List::Util qw(max);
613 use Getopt::Long;
614+use Data::Dumper;
615
616 my $POD_link_re = '[LC]<"?([^">]+)"?>';
617
618@@ -1986,6 +2031,45 @@
619 );
620 };
621
622+sub set_vars {
623+ my ($self, $file) = @_;
624+ $file ||= $self->{file} || __FILE__;
625+
626+ my %user_vars;
627+ my $user_vars = $self->has('set-vars') ? $self->get('set-vars') : undef;
628+ if ( $user_vars ) {
629+ foreach my $var_val ( @$user_vars ) {
630+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
631+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
632+ $user_vars{$var} = {
633+ val => $val,
634+ default => 0,
635+ };
636+ }
637+ }
638+
639+ my %default_vars;
640+ my $default_vars = $self->read_para_after($file, qr/MAGIC_set_vars/);
641+ if ( $default_vars ) {
642+ %default_vars = map {
643+ my $var_val = $_;
644+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
645+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
646+ $var => {
647+ val => $val,
648+ default => 1,
649+ };
650+ } split("\n", $default_vars);
651+ }
652+
653+ my %vars = (
654+ %default_vars, # first the tool's defaults
655+ %user_vars, # then the user's which overwrite the defaults
656+ );
657+ PTDEBUG && _d('--set-vars:', Dumper(\%vars));
658+ return \%vars;
659+}
660+
661 sub _d {
662 my ($package, undef, $line) = caller 0;
663 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
664@@ -4662,7 +4746,7 @@
665 $o->get_opts();
666
667 my $dp = $o->DSNParser();
668- $dp->prop('set-vars', $o->get('set-vars'));
669+ $dp->prop('set-vars', $o->set_vars());
670
671 $o->usage_or_errors();
672
673@@ -5144,10 +5228,21 @@
674
675 =item --set-vars
676
677-type: string; default: wait_timeout=10000
678-
679-Set these MySQL variables. Immediately after connecting to MySQL, this string
680-will be appended to SET and executed.
681+type: Array
682+
683+Set the MySQL variables in this comma-separated list of C<variable=value> pairs.
684+
685+By default, the tool sets:
686+
687+=for comment ignore-pt-internal-value
688+MAGIC_set_vars
689+
690+ wait_timeout=10000
691+
692+Variables specified on the command line override these defaults. For
693+example, specifying C<--set-vars wait_timeout=500> overrides the defaultvalue of C<10000>.
694+
695+The tool prints a warning and continues if a variable cannot be set.
696
697 =item --socket
698
699
700=== modified file 'bin/pt-find'
701--- bin/pt-find 2013-02-27 00:01:17 +0000
702+++ bin/pt-find 2013-03-03 15:43:19 +0000
703@@ -309,7 +309,7 @@
704
705 if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
706 $sql = qq{/*!40101 SET NAMES "$charset"*/};
707- PTDEBUG && _d($dbh, ':', $sql);
708+ PTDEBUG && _d($dbh, $sql);
709 eval { $dbh->do($sql) };
710 if ( $EVAL_ERROR ) {
711 die "Error setting NAMES to $charset: $EVAL_ERROR";
712@@ -324,13 +324,8 @@
713 }
714 }
715
716- if ( my $var = $self->prop('set-vars') ) {
717- $sql = "SET $var";
718- PTDEBUG && _d($dbh, ':', $sql);
719- eval { $dbh->do($sql) };
720- if ( $EVAL_ERROR ) {
721- die "Error setting $var: $EVAL_ERROR";
722- }
723+ if ( my $vars = $self->prop('set-vars') ) {
724+ $self->set_vars($dbh, $vars);
725 }
726
727 $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
728@@ -405,6 +400,55 @@
729 return \%new_dsn;
730 }
731
732+sub set_vars {
733+ my ($self, $dbh, $vars) = @_;
734+
735+ foreach my $var ( sort keys %$vars ) {
736+ my $val = $vars->{$var}->{val};
737+
738+ (my $quoted_var = $var) =~ s/_/\\_/;
739+ my ($var_exists, $current_val);
740+ eval {
741+ ($var_exists, $current_val) = $dbh->selectrow_array(
742+ "SHOW VARIABLES LIKE '$quoted_var'");
743+ };
744+ my $e = $EVAL_ERROR;
745+ if ( $e ) {
746+ PTDEBUG && _d($e);
747+ }
748+
749+ if ( $vars->{$var}->{default} && !$var_exists ) {
750+ PTDEBUG && _d('Not setting default var', $var,
751+ 'because it does not exist');
752+ next;
753+ }
754+
755+ if ( $current_val && $current_val eq $val ) {
756+ PTDEBUG && _d('Not setting var', $var, 'because its value',
757+ 'is already', $val);
758+ next;
759+ }
760+
761+ my $sql = "SET SESSION $var=$val";
762+ PTDEBUG && _d($dbh, $sql);
763+ eval { $dbh->do($sql) };
764+ if ( my $set_error = $EVAL_ERROR ) {
765+ chomp($set_error);
766+ $set_error =~ s/ at \S+ line \d+//;
767+ my $msg = "Error setting $var: $set_error";
768+ if ( $current_val ) {
769+ $msg .= " The current value for $var is $current_val. "
770+ . "If the variable is read only (not dynamic), specify "
771+ . "--set-vars $var=$current_val to avoid this warning, "
772+ . "else manually set the variable and restart MySQL.";
773+ }
774+ warn $msg . "\n\n";
775+ }
776+ }
777+
778+ return;
779+}
780+
781 sub _d {
782 my ($package, undef, $line) = caller 0;
783 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
784@@ -437,6 +481,7 @@
785
786 use List::Util qw(max);
787 use Getopt::Long;
788+use Data::Dumper;
789
790 my $POD_link_re = '[LC]<"?([^">]+)"?>';
791
792@@ -1420,6 +1465,45 @@
793 );
794 };
795
796+sub set_vars {
797+ my ($self, $file) = @_;
798+ $file ||= $self->{file} || __FILE__;
799+
800+ my %user_vars;
801+ my $user_vars = $self->has('set-vars') ? $self->get('set-vars') : undef;
802+ if ( $user_vars ) {
803+ foreach my $var_val ( @$user_vars ) {
804+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
805+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
806+ $user_vars{$var} = {
807+ val => $val,
808+ default => 0,
809+ };
810+ }
811+ }
812+
813+ my %default_vars;
814+ my $default_vars = $self->read_para_after($file, qr/MAGIC_set_vars/);
815+ if ( $default_vars ) {
816+ %default_vars = map {
817+ my $var_val = $_;
818+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
819+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
820+ $var => {
821+ val => $val,
822+ default => 1,
823+ };
824+ } split("\n", $default_vars);
825+ }
826+
827+ my %vars = (
828+ %default_vars, # first the tool's defaults
829+ %user_vars, # then the user's which overwrite the defaults
830+ );
831+ PTDEBUG && _d('--set-vars:', Dumper(\%vars));
832+ return \%vars;
833+}
834+
835 sub _d {
836 my ($package, undef, $line) = caller 0;
837 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
838@@ -3719,7 +3803,7 @@
839 $o->get_opts();
840
841 my $dp = $o->DSNParser();
842- $dp->prop('set-vars', $o->get('set-vars'));
843+ $dp->prop('set-vars', $o->set_vars());
844
845 # Make sure OptionParser understands that these options are used.
846 # cmin ctime empty kmin ktime mmin mtime exec printf
847@@ -4263,10 +4347,21 @@
848
849 =item --set-vars
850
851-type: string; default: wait_timeout=10000
852-
853-Set these MySQL variables. Immediately after connecting to MySQL, this string
854-will be appended to SET and executed.
855+type: Array
856+
857+Set the MySQL variables in this comma-separated list of C<variable=value> pairs.
858+
859+By default, the tool sets:
860+
861+=for comment ignore-pt-internal-value
862+MAGIC_set_vars
863+
864+ wait_timeout=10000
865+
866+Variables specified on the command line override these defaults. For
867+example, specifying C<--set-vars wait_timeout=500> overrides the defaultvalue of C<10000>.
868+
869+The tool prints a warning and continues if a variable cannot be set.
870
871 =item --socket
872
873
874=== modified file 'bin/pt-fk-error-logger'
875--- bin/pt-fk-error-logger 2013-02-28 02:23:08 +0000
876+++ bin/pt-fk-error-logger 2013-03-03 15:43:19 +0000
877@@ -62,6 +62,7 @@
878
879 use List::Util qw(max);
880 use Getopt::Long;
881+use Data::Dumper;
882
883 my $POD_link_re = '[LC]<"?([^">]+)"?>';
884
885@@ -1045,6 +1046,45 @@
886 );
887 };
888
889+sub set_vars {
890+ my ($self, $file) = @_;
891+ $file ||= $self->{file} || __FILE__;
892+
893+ my %user_vars;
894+ my $user_vars = $self->has('set-vars') ? $self->get('set-vars') : undef;
895+ if ( $user_vars ) {
896+ foreach my $var_val ( @$user_vars ) {
897+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
898+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
899+ $user_vars{$var} = {
900+ val => $val,
901+ default => 0,
902+ };
903+ }
904+ }
905+
906+ my %default_vars;
907+ my $default_vars = $self->read_para_after($file, qr/MAGIC_set_vars/);
908+ if ( $default_vars ) {
909+ %default_vars = map {
910+ my $var_val = $_;
911+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
912+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
913+ $var => {
914+ val => $val,
915+ default => 1,
916+ };
917+ } split("\n", $default_vars);
918+ }
919+
920+ my %vars = (
921+ %default_vars, # first the tool's defaults
922+ %user_vars, # then the user's which overwrite the defaults
923+ );
924+ PTDEBUG && _d('--set-vars:', Dumper(\%vars));
925+ return \%vars;
926+}
927+
928 sub _d {
929 my ($package, undef, $line) = caller 0;
930 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
931@@ -1487,7 +1527,7 @@
932
933 if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
934 $sql = qq{/*!40101 SET NAMES "$charset"*/};
935- PTDEBUG && _d($dbh, ':', $sql);
936+ PTDEBUG && _d($dbh, $sql);
937 eval { $dbh->do($sql) };
938 if ( $EVAL_ERROR ) {
939 die "Error setting NAMES to $charset: $EVAL_ERROR";
940@@ -1502,13 +1542,8 @@
941 }
942 }
943
944- if ( my $var = $self->prop('set-vars') ) {
945- $sql = "SET $var";
946- PTDEBUG && _d($dbh, ':', $sql);
947- eval { $dbh->do($sql) };
948- if ( $EVAL_ERROR ) {
949- die "Error setting $var: $EVAL_ERROR";
950- }
951+ if ( my $vars = $self->prop('set-vars') ) {
952+ $self->set_vars($dbh, $vars);
953 }
954
955 $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
956@@ -1583,6 +1618,55 @@
957 return \%new_dsn;
958 }
959
960+sub set_vars {
961+ my ($self, $dbh, $vars) = @_;
962+
963+ foreach my $var ( sort keys %$vars ) {
964+ my $val = $vars->{$var}->{val};
965+
966+ (my $quoted_var = $var) =~ s/_/\\_/;
967+ my ($var_exists, $current_val);
968+ eval {
969+ ($var_exists, $current_val) = $dbh->selectrow_array(
970+ "SHOW VARIABLES LIKE '$quoted_var'");
971+ };
972+ my $e = $EVAL_ERROR;
973+ if ( $e ) {
974+ PTDEBUG && _d($e);
975+ }
976+
977+ if ( $vars->{$var}->{default} && !$var_exists ) {
978+ PTDEBUG && _d('Not setting default var', $var,
979+ 'because it does not exist');
980+ next;
981+ }
982+
983+ if ( $current_val && $current_val eq $val ) {
984+ PTDEBUG && _d('Not setting var', $var, 'because its value',
985+ 'is already', $val);
986+ next;
987+ }
988+
989+ my $sql = "SET SESSION $var=$val";
990+ PTDEBUG && _d($dbh, $sql);
991+ eval { $dbh->do($sql) };
992+ if ( my $set_error = $EVAL_ERROR ) {
993+ chomp($set_error);
994+ $set_error =~ s/ at \S+ line \d+//;
995+ my $msg = "Error setting $var: $set_error";
996+ if ( $current_val ) {
997+ $msg .= " The current value for $var is $current_val. "
998+ . "If the variable is read only (not dynamic), specify "
999+ . "--set-vars $var=$current_val to avoid this warning, "
1000+ . "else manually set the variable and restart MySQL.";
1001+ }
1002+ warn $msg . "\n\n";
1003+ }
1004+ }
1005+
1006+ return;
1007+}
1008+
1009 sub _d {
1010 my ($package, undef, $line) = caller 0;
1011 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
1012@@ -3721,7 +3805,7 @@
1013 $o->get_opts();
1014
1015 my $dp = $o->DSNParser();
1016- $dp->prop('set-vars', $o->get('set-vars'));
1017+ $dp->prop('set-vars', $o->set_vars());
1018
1019 my $src;
1020 if ( my $src_dsn_string = shift @ARGV ) {
1021@@ -4127,10 +4211,21 @@
1022
1023 =item --set-vars
1024
1025-type: string; default: wait_timeout=10000
1026-
1027-Set these MySQL variables. Immediately after connecting to MySQL, this string
1028-will be appended to SET and executed.
1029+type: Array
1030+
1031+Set the MySQL variables in this comma-separated list of C<variable=value> pairs.
1032+
1033+By default, the tool sets:
1034+
1035+=for comment ignore-pt-internal-value
1036+MAGIC_set_vars
1037+
1038+ wait_timeout=10000
1039+
1040+Variables specified on the command line override these defaults. For
1041+example, specifying C<--set-vars wait_timeout=500> overrides the defaultvalue of C<10000>.
1042+
1043+The tool prints a warning and continues if a variable cannot be set.
1044
1045 =item --socket
1046
1047
1048=== modified file 'bin/pt-heartbeat'
1049--- bin/pt-heartbeat 2013-02-27 00:01:17 +0000
1050+++ bin/pt-heartbeat 2013-03-03 15:43:19 +0000
1051@@ -797,6 +797,7 @@
1052
1053 use List::Util qw(max);
1054 use Getopt::Long;
1055+use Data::Dumper;
1056
1057 my $POD_link_re = '[LC]<"?([^">]+)"?>';
1058
1059@@ -1780,6 +1781,45 @@
1060 );
1061 };
1062
1063+sub set_vars {
1064+ my ($self, $file) = @_;
1065+ $file ||= $self->{file} || __FILE__;
1066+
1067+ my %user_vars;
1068+ my $user_vars = $self->has('set-vars') ? $self->get('set-vars') : undef;
1069+ if ( $user_vars ) {
1070+ foreach my $var_val ( @$user_vars ) {
1071+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
1072+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
1073+ $user_vars{$var} = {
1074+ val => $val,
1075+ default => 0,
1076+ };
1077+ }
1078+ }
1079+
1080+ my %default_vars;
1081+ my $default_vars = $self->read_para_after($file, qr/MAGIC_set_vars/);
1082+ if ( $default_vars ) {
1083+ %default_vars = map {
1084+ my $var_val = $_;
1085+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
1086+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
1087+ $var => {
1088+ val => $val,
1089+ default => 1,
1090+ };
1091+ } split("\n", $default_vars);
1092+ }
1093+
1094+ my %vars = (
1095+ %default_vars, # first the tool's defaults
1096+ %user_vars, # then the user's which overwrite the defaults
1097+ );
1098+ PTDEBUG && _d('--set-vars:', Dumper(\%vars));
1099+ return \%vars;
1100+}
1101+
1102 sub _d {
1103 my ($package, undef, $line) = caller 0;
1104 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
1105@@ -2071,7 +2111,7 @@
1106
1107 if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
1108 $sql = qq{/*!40101 SET NAMES "$charset"*/};
1109- PTDEBUG && _d($dbh, ':', $sql);
1110+ PTDEBUG && _d($dbh, $sql);
1111 eval { $dbh->do($sql) };
1112 if ( $EVAL_ERROR ) {
1113 die "Error setting NAMES to $charset: $EVAL_ERROR";
1114@@ -2086,13 +2126,8 @@
1115 }
1116 }
1117
1118- if ( my $var = $self->prop('set-vars') ) {
1119- $sql = "SET $var";
1120- PTDEBUG && _d($dbh, ':', $sql);
1121- eval { $dbh->do($sql) };
1122- if ( $EVAL_ERROR ) {
1123- die "Error setting $var: $EVAL_ERROR";
1124- }
1125+ if ( my $vars = $self->prop('set-vars') ) {
1126+ $self->set_vars($dbh, $vars);
1127 }
1128
1129 $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
1130@@ -2167,6 +2202,55 @@
1131 return \%new_dsn;
1132 }
1133
1134+sub set_vars {
1135+ my ($self, $dbh, $vars) = @_;
1136+
1137+ foreach my $var ( sort keys %$vars ) {
1138+ my $val = $vars->{$var}->{val};
1139+
1140+ (my $quoted_var = $var) =~ s/_/\\_/;
1141+ my ($var_exists, $current_val);
1142+ eval {
1143+ ($var_exists, $current_val) = $dbh->selectrow_array(
1144+ "SHOW VARIABLES LIKE '$quoted_var'");
1145+ };
1146+ my $e = $EVAL_ERROR;
1147+ if ( $e ) {
1148+ PTDEBUG && _d($e);
1149+ }
1150+
1151+ if ( $vars->{$var}->{default} && !$var_exists ) {
1152+ PTDEBUG && _d('Not setting default var', $var,
1153+ 'because it does not exist');
1154+ next;
1155+ }
1156+
1157+ if ( $current_val && $current_val eq $val ) {
1158+ PTDEBUG && _d('Not setting var', $var, 'because its value',
1159+ 'is already', $val);
1160+ next;
1161+ }
1162+
1163+ my $sql = "SET SESSION $var=$val";
1164+ PTDEBUG && _d($dbh, $sql);
1165+ eval { $dbh->do($sql) };
1166+ if ( my $set_error = $EVAL_ERROR ) {
1167+ chomp($set_error);
1168+ $set_error =~ s/ at \S+ line \d+//;
1169+ my $msg = "Error setting $var: $set_error";
1170+ if ( $current_val ) {
1171+ $msg .= " The current value for $var is $current_val. "
1172+ . "If the variable is read only (not dynamic), specify "
1173+ . "--set-vars $var=$current_val to avoid this warning, "
1174+ . "else manually set the variable and restart MySQL.";
1175+ }
1176+ warn $msg . "\n\n";
1177+ }
1178+ }
1179+
1180+ return;
1181+}
1182+
1183 sub _d {
1184 my ($package, undef, $line) = caller 0;
1185 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
1186@@ -4641,7 +4725,7 @@
1187
1188 my $dp = $o->DSNParser;
1189 $dp->prop('dbidriver', $o->get('dbi-driver'));
1190- $dp->prop('set-vars', $o->get('set-vars'));
1191+ $dp->prop('set-vars', $o->set_vars());
1192
1193 if ( !$o->get('help') ) {
1194 my @frames = $o->get('frames') =~ m/(\d+[smhd])/g;
1195@@ -5737,10 +5821,21 @@
1196
1197 =item --set-vars
1198
1199-type: string; default: wait_timeout=10000
1200-
1201-Set these MySQL variables. Immediately after connecting to MySQL, this string
1202-will be appended to SET and executed.
1203+type: Array
1204+
1205+Set the MySQL variables in this comma-separated list of C<variable=value> pairs.
1206+
1207+By default, the tool sets:
1208+
1209+=for comment ignore-pt-internal-value
1210+MAGIC_set_vars
1211+
1212+ wait_timeout=10000
1213+
1214+Variables specified on the command line override these defaults. For
1215+example, specifying C<--set-vars wait_timeout=500> overrides the defaultvalue of C<10000>.
1216+
1217+The tool prints a warning and continues if a variable cannot be set.
1218
1219 =item --skew
1220
1221
1222=== modified file 'bin/pt-index-usage'
1223--- bin/pt-index-usage 2013-02-22 17:47:57 +0000
1224+++ bin/pt-index-usage 2013-03-03 15:43:19 +0000
1225@@ -319,7 +319,7 @@
1226
1227 if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
1228 $sql = qq{/*!40101 SET NAMES "$charset"*/};
1229- PTDEBUG && _d($dbh, ':', $sql);
1230+ PTDEBUG && _d($dbh, $sql);
1231 eval { $dbh->do($sql) };
1232 if ( $EVAL_ERROR ) {
1233 die "Error setting NAMES to $charset: $EVAL_ERROR";
1234@@ -334,13 +334,8 @@
1235 }
1236 }
1237
1238- if ( my $var = $self->prop('set-vars') ) {
1239- $sql = "SET $var";
1240- PTDEBUG && _d($dbh, ':', $sql);
1241- eval { $dbh->do($sql) };
1242- if ( $EVAL_ERROR ) {
1243- die "Error setting $var: $EVAL_ERROR";
1244- }
1245+ if ( my $vars = $self->prop('set-vars') ) {
1246+ $self->set_vars($dbh, $vars);
1247 }
1248
1249 $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
1250@@ -415,6 +410,55 @@
1251 return \%new_dsn;
1252 }
1253
1254+sub set_vars {
1255+ my ($self, $dbh, $vars) = @_;
1256+
1257+ foreach my $var ( sort keys %$vars ) {
1258+ my $val = $vars->{$var}->{val};
1259+
1260+ (my $quoted_var = $var) =~ s/_/\\_/;
1261+ my ($var_exists, $current_val);
1262+ eval {
1263+ ($var_exists, $current_val) = $dbh->selectrow_array(
1264+ "SHOW VARIABLES LIKE '$quoted_var'");
1265+ };
1266+ my $e = $EVAL_ERROR;
1267+ if ( $e ) {
1268+ PTDEBUG && _d($e);
1269+ }
1270+
1271+ if ( $vars->{$var}->{default} && !$var_exists ) {
1272+ PTDEBUG && _d('Not setting default var', $var,
1273+ 'because it does not exist');
1274+ next;
1275+ }
1276+
1277+ if ( $current_val && $current_val eq $val ) {
1278+ PTDEBUG && _d('Not setting var', $var, 'because its value',
1279+ 'is already', $val);
1280+ next;
1281+ }
1282+
1283+ my $sql = "SET SESSION $var=$val";
1284+ PTDEBUG && _d($dbh, $sql);
1285+ eval { $dbh->do($sql) };
1286+ if ( my $set_error = $EVAL_ERROR ) {
1287+ chomp($set_error);
1288+ $set_error =~ s/ at \S+ line \d+//;
1289+ my $msg = "Error setting $var: $set_error";
1290+ if ( $current_val ) {
1291+ $msg .= " The current value for $var is $current_val. "
1292+ . "If the variable is read only (not dynamic), specify "
1293+ . "--set-vars $var=$current_val to avoid this warning, "
1294+ . "else manually set the variable and restart MySQL.";
1295+ }
1296+ warn $msg . "\n\n";
1297+ }
1298+ }
1299+
1300+ return;
1301+}
1302+
1303 sub _d {
1304 my ($package, undef, $line) = caller 0;
1305 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
1306@@ -598,6 +642,7 @@
1307
1308 use List::Util qw(max);
1309 use Getopt::Long;
1310+use Data::Dumper;
1311
1312 my $POD_link_re = '[LC]<"?([^">]+)"?>';
1313
1314@@ -1581,6 +1626,45 @@
1315 );
1316 };
1317
1318+sub set_vars {
1319+ my ($self, $file) = @_;
1320+ $file ||= $self->{file} || __FILE__;
1321+
1322+ my %user_vars;
1323+ my $user_vars = $self->has('set-vars') ? $self->get('set-vars') : undef;
1324+ if ( $user_vars ) {
1325+ foreach my $var_val ( @$user_vars ) {
1326+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
1327+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
1328+ $user_vars{$var} = {
1329+ val => $val,
1330+ default => 0,
1331+ };
1332+ }
1333+ }
1334+
1335+ my %default_vars;
1336+ my $default_vars = $self->read_para_after($file, qr/MAGIC_set_vars/);
1337+ if ( $default_vars ) {
1338+ %default_vars = map {
1339+ my $var_val = $_;
1340+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
1341+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
1342+ $var => {
1343+ val => $val,
1344+ default => 1,
1345+ };
1346+ } split("\n", $default_vars);
1347+ }
1348+
1349+ my %vars = (
1350+ %default_vars, # first the tool's defaults
1351+ %user_vars, # then the user's which overwrite the defaults
1352+ );
1353+ PTDEBUG && _d('--set-vars:', Dumper(\%vars));
1354+ return \%vars;
1355+}
1356+
1357 sub _d {
1358 my ($package, undef, $line) = caller 0;
1359 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
1360@@ -6112,7 +6196,7 @@
1361 $o->get_specs();
1362 $o->get_opts();
1363 my $dp = $o->DSNParser();
1364- $dp->prop('set-vars', $o->get('set-vars'));
1365+ $dp->prop('set-vars', $o->set_vars());
1366 $o->set('progress', undef) if $o->get('q');
1367
1368 if ( !$o->got('help') ) {
1369@@ -7159,10 +7243,21 @@
1370
1371 =item --set-vars
1372
1373-type: string; default: wait_timeout=10000
1374-
1375-Set these MySQL variables. Immediately after connecting to MySQL, this
1376-string will be appended to SET and executed.
1377+type: Array
1378+
1379+Set the MySQL variables in this comma-separated list of C<variable=value> pairs.
1380+
1381+By default, the tool sets:
1382+
1383+=for comment ignore-pt-internal-value
1384+MAGIC_set_vars
1385+
1386+ wait_timeout=10000
1387+
1388+Variables specified on the command line override these defaults. For
1389+example, specifying C<--set-vars wait_timeout=500> overrides the defaultvalue of C<10000>.
1390+
1391+The tool prints a warning and continues if a variable cannot be set.
1392
1393 =item --socket
1394
1395
1396=== modified file 'bin/pt-kill'
1397--- bin/pt-kill 2013-02-27 00:01:17 +0000
1398+++ bin/pt-kill 2013-03-03 15:43:19 +0000
1399@@ -72,6 +72,7 @@
1400
1401 use List::Util qw(max);
1402 use Getopt::Long;
1403+use Data::Dumper;
1404
1405 my $POD_link_re = '[LC]<"?([^">]+)"?>';
1406
1407@@ -1055,6 +1056,45 @@
1408 );
1409 };
1410
1411+sub set_vars {
1412+ my ($self, $file) = @_;
1413+ $file ||= $self->{file} || __FILE__;
1414+
1415+ my %user_vars;
1416+ my $user_vars = $self->has('set-vars') ? $self->get('set-vars') : undef;
1417+ if ( $user_vars ) {
1418+ foreach my $var_val ( @$user_vars ) {
1419+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
1420+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
1421+ $user_vars{$var} = {
1422+ val => $val,
1423+ default => 0,
1424+ };
1425+ }
1426+ }
1427+
1428+ my %default_vars;
1429+ my $default_vars = $self->read_para_after($file, qr/MAGIC_set_vars/);
1430+ if ( $default_vars ) {
1431+ %default_vars = map {
1432+ my $var_val = $_;
1433+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
1434+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
1435+ $var => {
1436+ val => $val,
1437+ default => 1,
1438+ };
1439+ } split("\n", $default_vars);
1440+ }
1441+
1442+ my %vars = (
1443+ %default_vars, # first the tool's defaults
1444+ %user_vars, # then the user's which overwrite the defaults
1445+ );
1446+ PTDEBUG && _d('--set-vars:', Dumper(\%vars));
1447+ return \%vars;
1448+}
1449+
1450 sub _d {
1451 my ($package, undef, $line) = caller 0;
1452 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
1453@@ -1990,7 +2030,7 @@
1454
1455 if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
1456 $sql = qq{/*!40101 SET NAMES "$charset"*/};
1457- PTDEBUG && _d($dbh, ':', $sql);
1458+ PTDEBUG && _d($dbh, $sql);
1459 eval { $dbh->do($sql) };
1460 if ( $EVAL_ERROR ) {
1461 die "Error setting NAMES to $charset: $EVAL_ERROR";
1462@@ -2005,13 +2045,8 @@
1463 }
1464 }
1465
1466- if ( my $var = $self->prop('set-vars') ) {
1467- $sql = "SET $var";
1468- PTDEBUG && _d($dbh, ':', $sql);
1469- eval { $dbh->do($sql) };
1470- if ( $EVAL_ERROR ) {
1471- die "Error setting $var: $EVAL_ERROR";
1472- }
1473+ if ( my $vars = $self->prop('set-vars') ) {
1474+ $self->set_vars($dbh, $vars);
1475 }
1476
1477 $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
1478@@ -2086,6 +2121,55 @@
1479 return \%new_dsn;
1480 }
1481
1482+sub set_vars {
1483+ my ($self, $dbh, $vars) = @_;
1484+
1485+ foreach my $var ( sort keys %$vars ) {
1486+ my $val = $vars->{$var}->{val};
1487+
1488+ (my $quoted_var = $var) =~ s/_/\\_/;
1489+ my ($var_exists, $current_val);
1490+ eval {
1491+ ($var_exists, $current_val) = $dbh->selectrow_array(
1492+ "SHOW VARIABLES LIKE '$quoted_var'");
1493+ };
1494+ my $e = $EVAL_ERROR;
1495+ if ( $e ) {
1496+ PTDEBUG && _d($e);
1497+ }
1498+
1499+ if ( $vars->{$var}->{default} && !$var_exists ) {
1500+ PTDEBUG && _d('Not setting default var', $var,
1501+ 'because it does not exist');
1502+ next;
1503+ }
1504+
1505+ if ( $current_val && $current_val eq $val ) {
1506+ PTDEBUG && _d('Not setting var', $var, 'because its value',
1507+ 'is already', $val);
1508+ next;
1509+ }
1510+
1511+ my $sql = "SET SESSION $var=$val";
1512+ PTDEBUG && _d($dbh, $sql);
1513+ eval { $dbh->do($sql) };
1514+ if ( my $set_error = $EVAL_ERROR ) {
1515+ chomp($set_error);
1516+ $set_error =~ s/ at \S+ line \d+//;
1517+ my $msg = "Error setting $var: $set_error";
1518+ if ( $current_val ) {
1519+ $msg .= " The current value for $var is $current_val. "
1520+ . "If the variable is read only (not dynamic), specify "
1521+ . "--set-vars $var=$current_val to avoid this warning, "
1522+ . "else manually set the variable and restart MySQL.";
1523+ }
1524+ warn $msg . "\n\n";
1525+ }
1526+ }
1527+
1528+ return;
1529+}
1530+
1531 sub _d {
1532 my ($package, undef, $line) = caller 0;
1533 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
1534@@ -6371,7 +6455,7 @@
1535 $o->get_opts();
1536
1537 my $dp = $o->DSNParser();
1538- $dp->prop('set-vars', $o->get('set-vars'));
1539+ $dp->prop('set-vars', $o->set_vars());
1540
1541 if ( !$o->got('busy-time') ) {
1542 $o->set('interval', 30) unless $o->got('interval');
1543@@ -7383,10 +7467,21 @@
1544
1545 =item --set-vars
1546
1547-type: string; default: wait_timeout=10000
1548-
1549-Set these MySQL variables. Immediately after connecting to MySQL, this string
1550-will be appended to SET and executed.
1551+type: Array
1552+
1553+Set the MySQL variables in this comma-separated list of C<variable=value> pairs.
1554+
1555+By default, the tool sets:
1556+
1557+=for comment ignore-pt-internal-value
1558+MAGIC_set_vars
1559+
1560+ wait_timeout=10000
1561+
1562+Variables specified on the command line override these defaults. For
1563+example, specifying C<--set-vars wait_timeout=500> overrides the defaultvalue of C<10000>.
1564+
1565+The tool prints a warning and continues if a variable cannot be set.
1566
1567 =item --socket
1568
1569
1570=== modified file 'bin/pt-query-advisor'
1571--- bin/pt-query-advisor 2013-02-27 00:01:17 +0000
1572+++ bin/pt-query-advisor 2013-03-03 15:43:19 +0000
1573@@ -969,7 +969,7 @@
1574
1575 if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
1576 $sql = qq{/*!40101 SET NAMES "$charset"*/};
1577- PTDEBUG && _d($dbh, ':', $sql);
1578+ PTDEBUG && _d($dbh, $sql);
1579 eval { $dbh->do($sql) };
1580 if ( $EVAL_ERROR ) {
1581 die "Error setting NAMES to $charset: $EVAL_ERROR";
1582@@ -984,13 +984,8 @@
1583 }
1584 }
1585
1586- if ( my $var = $self->prop('set-vars') ) {
1587- $sql = "SET $var";
1588- PTDEBUG && _d($dbh, ':', $sql);
1589- eval { $dbh->do($sql) };
1590- if ( $EVAL_ERROR ) {
1591- die "Error setting $var: $EVAL_ERROR";
1592- }
1593+ if ( my $vars = $self->prop('set-vars') ) {
1594+ $self->set_vars($dbh, $vars);
1595 }
1596
1597 $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
1598@@ -1065,6 +1060,55 @@
1599 return \%new_dsn;
1600 }
1601
1602+sub set_vars {
1603+ my ($self, $dbh, $vars) = @_;
1604+
1605+ foreach my $var ( sort keys %$vars ) {
1606+ my $val = $vars->{$var}->{val};
1607+
1608+ (my $quoted_var = $var) =~ s/_/\\_/;
1609+ my ($var_exists, $current_val);
1610+ eval {
1611+ ($var_exists, $current_val) = $dbh->selectrow_array(
1612+ "SHOW VARIABLES LIKE '$quoted_var'");
1613+ };
1614+ my $e = $EVAL_ERROR;
1615+ if ( $e ) {
1616+ PTDEBUG && _d($e);
1617+ }
1618+
1619+ if ( $vars->{$var}->{default} && !$var_exists ) {
1620+ PTDEBUG && _d('Not setting default var', $var,
1621+ 'because it does not exist');
1622+ next;
1623+ }
1624+
1625+ if ( $current_val && $current_val eq $val ) {
1626+ PTDEBUG && _d('Not setting var', $var, 'because its value',
1627+ 'is already', $val);
1628+ next;
1629+ }
1630+
1631+ my $sql = "SET SESSION $var=$val";
1632+ PTDEBUG && _d($dbh, $sql);
1633+ eval { $dbh->do($sql) };
1634+ if ( my $set_error = $EVAL_ERROR ) {
1635+ chomp($set_error);
1636+ $set_error =~ s/ at \S+ line \d+//;
1637+ my $msg = "Error setting $var: $set_error";
1638+ if ( $current_val ) {
1639+ $msg .= " The current value for $var is $current_val. "
1640+ . "If the variable is read only (not dynamic), specify "
1641+ . "--set-vars $var=$current_val to avoid this warning, "
1642+ . "else manually set the variable and restart MySQL.";
1643+ }
1644+ warn $msg . "\n\n";
1645+ }
1646+ }
1647+
1648+ return;
1649+}
1650+
1651 sub _d {
1652 my ($package, undef, $line) = caller 0;
1653 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
1654@@ -1097,6 +1141,7 @@
1655
1656 use List::Util qw(max);
1657 use Getopt::Long;
1658+use Data::Dumper;
1659
1660 my $POD_link_re = '[LC]<"?([^">]+)"?>';
1661
1662@@ -2080,6 +2125,45 @@
1663 );
1664 };
1665
1666+sub set_vars {
1667+ my ($self, $file) = @_;
1668+ $file ||= $self->{file} || __FILE__;
1669+
1670+ my %user_vars;
1671+ my $user_vars = $self->has('set-vars') ? $self->get('set-vars') : undef;
1672+ if ( $user_vars ) {
1673+ foreach my $var_val ( @$user_vars ) {
1674+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
1675+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
1676+ $user_vars{$var} = {
1677+ val => $val,
1678+ default => 0,
1679+ };
1680+ }
1681+ }
1682+
1683+ my %default_vars;
1684+ my $default_vars = $self->read_para_after($file, qr/MAGIC_set_vars/);
1685+ if ( $default_vars ) {
1686+ %default_vars = map {
1687+ my $var_val = $_;
1688+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
1689+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
1690+ $var => {
1691+ val => $val,
1692+ default => 1,
1693+ };
1694+ } split("\n", $default_vars);
1695+ }
1696+
1697+ my %vars = (
1698+ %default_vars, # first the tool's defaults
1699+ %user_vars, # then the user's which overwrite the defaults
1700+ );
1701+ PTDEBUG && _d('--set-vars:', Dumper(\%vars));
1702+ return \%vars;
1703+}
1704+
1705 sub _d {
1706 my ($package, undef, $line) = caller 0;
1707 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
1708@@ -8078,7 +8162,7 @@
1709 $o->get_opts();
1710
1711 my $dp = $o->DSNParser();
1712- $dp->prop('set-vars', $o->get('set-vars'));
1713+ $dp->prop('set-vars', $o->set_vars());
1714
1715 my $review_dsn = $o->get('review');
1716 my $groupby = lc $o->get('group-by');
1717@@ -9150,10 +9234,21 @@
1718
1719 =item --set-vars
1720
1721-type: string; default: wait_timeout=10000
1722-
1723-Set these MySQL variables. Immediately after connecting to MySQL, this string
1724-will be appended to SET and executed.
1725+type: Array
1726+
1727+Set the MySQL variables in this comma-separated list of C<variable=value> pairs.
1728+
1729+By default, the tool sets:
1730+
1731+=for comment ignore-pt-internal-value
1732+MAGIC_set_vars
1733+
1734+ wait_timeout=10000
1735+
1736+Variables specified on the command line override these defaults. For
1737+example, specifying C<--set-vars wait_timeout=500> overrides the defaultvalue of C<10000>.
1738+
1739+The tool prints a warning and continues if a variable cannot be set.
1740
1741 =item --[no]show-create-table
1742
1743
1744=== modified file 'bin/pt-query-digest'
1745--- bin/pt-query-digest 2013-02-28 02:23:08 +0000
1746+++ bin/pt-query-digest 2013-03-03 15:43:19 +0000
1747@@ -981,7 +981,7 @@
1748
1749 if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
1750 $sql = qq{/*!40101 SET NAMES "$charset"*/};
1751- PTDEBUG && _d($dbh, ':', $sql);
1752+ PTDEBUG && _d($dbh, $sql);
1753 eval { $dbh->do($sql) };
1754 if ( $EVAL_ERROR ) {
1755 die "Error setting NAMES to $charset: $EVAL_ERROR";
1756@@ -996,13 +996,8 @@
1757 }
1758 }
1759
1760- if ( my $var = $self->prop('set-vars') ) {
1761- $sql = "SET $var";
1762- PTDEBUG && _d($dbh, ':', $sql);
1763- eval { $dbh->do($sql) };
1764- if ( $EVAL_ERROR ) {
1765- die "Error setting $var: $EVAL_ERROR";
1766- }
1767+ if ( my $vars = $self->prop('set-vars') ) {
1768+ $self->set_vars($dbh, $vars);
1769 }
1770
1771 $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
1772@@ -1077,6 +1072,55 @@
1773 return \%new_dsn;
1774 }
1775
1776+sub set_vars {
1777+ my ($self, $dbh, $vars) = @_;
1778+
1779+ foreach my $var ( sort keys %$vars ) {
1780+ my $val = $vars->{$var}->{val};
1781+
1782+ (my $quoted_var = $var) =~ s/_/\\_/;
1783+ my ($var_exists, $current_val);
1784+ eval {
1785+ ($var_exists, $current_val) = $dbh->selectrow_array(
1786+ "SHOW VARIABLES LIKE '$quoted_var'");
1787+ };
1788+ my $e = $EVAL_ERROR;
1789+ if ( $e ) {
1790+ PTDEBUG && _d($e);
1791+ }
1792+
1793+ if ( $vars->{$var}->{default} && !$var_exists ) {
1794+ PTDEBUG && _d('Not setting default var', $var,
1795+ 'because it does not exist');
1796+ next;
1797+ }
1798+
1799+ if ( $current_val && $current_val eq $val ) {
1800+ PTDEBUG && _d('Not setting var', $var, 'because its value',
1801+ 'is already', $val);
1802+ next;
1803+ }
1804+
1805+ my $sql = "SET SESSION $var=$val";
1806+ PTDEBUG && _d($dbh, $sql);
1807+ eval { $dbh->do($sql) };
1808+ if ( my $set_error = $EVAL_ERROR ) {
1809+ chomp($set_error);
1810+ $set_error =~ s/ at \S+ line \d+//;
1811+ my $msg = "Error setting $var: $set_error";
1812+ if ( $current_val ) {
1813+ $msg .= " The current value for $var is $current_val. "
1814+ . "If the variable is read only (not dynamic), specify "
1815+ . "--set-vars $var=$current_val to avoid this warning, "
1816+ . "else manually set the variable and restart MySQL.";
1817+ }
1818+ warn $msg . "\n\n";
1819+ }
1820+ }
1821+
1822+ return;
1823+}
1824+
1825 sub _d {
1826 my ($package, undef, $line) = caller 0;
1827 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
1828@@ -1260,6 +1304,7 @@
1829
1830 use List::Util qw(max);
1831 use Getopt::Long;
1832+use Data::Dumper;
1833
1834 my $POD_link_re = '[LC]<"?([^">]+)"?>';
1835
1836@@ -2243,6 +2288,45 @@
1837 );
1838 };
1839
1840+sub set_vars {
1841+ my ($self, $file) = @_;
1842+ $file ||= $self->{file} || __FILE__;
1843+
1844+ my %user_vars;
1845+ my $user_vars = $self->has('set-vars') ? $self->get('set-vars') : undef;
1846+ if ( $user_vars ) {
1847+ foreach my $var_val ( @$user_vars ) {
1848+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
1849+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
1850+ $user_vars{$var} = {
1851+ val => $val,
1852+ default => 0,
1853+ };
1854+ }
1855+ }
1856+
1857+ my %default_vars;
1858+ my $default_vars = $self->read_para_after($file, qr/MAGIC_set_vars/);
1859+ if ( $default_vars ) {
1860+ %default_vars = map {
1861+ my $var_val = $_;
1862+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
1863+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
1864+ $var => {
1865+ val => $val,
1866+ default => 1,
1867+ };
1868+ } split("\n", $default_vars);
1869+ }
1870+
1871+ my %vars = (
1872+ %default_vars, # first the tool's defaults
1873+ %user_vars, # then the user's which overwrite the defaults
1874+ );
1875+ PTDEBUG && _d('--set-vars:', Dumper(\%vars));
1876+ return \%vars;
1877+}
1878+
1879 sub _d {
1880 my ($package, undef, $line) = caller 0;
1881 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
1882@@ -12394,7 +12478,7 @@
1883 $o->get_opts();
1884
1885 my $dp = $o->DSNParser();
1886- $dp->prop('set-vars', $o->get('set-vars'));
1887+ $dp->prop('set-vars', $o->set_vars());
1888
1889 # Frequently used options.
1890 my $review_dsn = $o->get('review');
1891@@ -15408,10 +15492,21 @@
1892
1893 =item --set-vars
1894
1895-type: string; default: wait_timeout=10000
1896-
1897-Set these MySQL variables. Immediately after connecting to MySQL, this
1898-string will be appended to SET and executed.
1899+type: Array
1900+
1901+Set the MySQL variables in this comma-separated list of C<variable=value> pairs.
1902+
1903+By default, the tool sets:
1904+
1905+=for comment ignore-pt-internal-value
1906+MAGIC_set_vars
1907+
1908+ wait_timeout=10000
1909+
1910+Variables specified on the command line override these defaults. For
1911+example, specifying C<--set-vars wait_timeout=500> overrides the defaultvalue of C<10000>.
1912+
1913+The tool prints a warning and continues if a variable cannot be set.
1914
1915 =item --shorten
1916
1917
1918=== modified file 'bin/pt-show-grants'
1919--- bin/pt-show-grants 2013-02-27 00:01:17 +0000
1920+++ bin/pt-show-grants 2013-03-03 15:43:19 +0000
1921@@ -37,6 +37,7 @@
1922
1923 use List::Util qw(max);
1924 use Getopt::Long;
1925+use Data::Dumper;
1926
1927 my $POD_link_re = '[LC]<"?([^">]+)"?>';
1928
1929@@ -1020,6 +1021,45 @@
1930 );
1931 };
1932
1933+sub set_vars {
1934+ my ($self, $file) = @_;
1935+ $file ||= $self->{file} || __FILE__;
1936+
1937+ my %user_vars;
1938+ my $user_vars = $self->has('set-vars') ? $self->get('set-vars') : undef;
1939+ if ( $user_vars ) {
1940+ foreach my $var_val ( @$user_vars ) {
1941+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
1942+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
1943+ $user_vars{$var} = {
1944+ val => $val,
1945+ default => 0,
1946+ };
1947+ }
1948+ }
1949+
1950+ my %default_vars;
1951+ my $default_vars = $self->read_para_after($file, qr/MAGIC_set_vars/);
1952+ if ( $default_vars ) {
1953+ %default_vars = map {
1954+ my $var_val = $_;
1955+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
1956+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
1957+ $var => {
1958+ val => $val,
1959+ default => 1,
1960+ };
1961+ } split("\n", $default_vars);
1962+ }
1963+
1964+ my %vars = (
1965+ %default_vars, # first the tool's defaults
1966+ %user_vars, # then the user's which overwrite the defaults
1967+ );
1968+ PTDEBUG && _d('--set-vars:', Dumper(\%vars));
1969+ return \%vars;
1970+}
1971+
1972 sub _d {
1973 my ($package, undef, $line) = caller 0;
1974 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
1975@@ -1311,7 +1351,7 @@
1976
1977 if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
1978 $sql = qq{/*!40101 SET NAMES "$charset"*/};
1979- PTDEBUG && _d($dbh, ':', $sql);
1980+ PTDEBUG && _d($dbh, $sql);
1981 eval { $dbh->do($sql) };
1982 if ( $EVAL_ERROR ) {
1983 die "Error setting NAMES to $charset: $EVAL_ERROR";
1984@@ -1326,13 +1366,8 @@
1985 }
1986 }
1987
1988- if ( my $var = $self->prop('set-vars') ) {
1989- $sql = "SET $var";
1990- PTDEBUG && _d($dbh, ':', $sql);
1991- eval { $dbh->do($sql) };
1992- if ( $EVAL_ERROR ) {
1993- die "Error setting $var: $EVAL_ERROR";
1994- }
1995+ if ( my $vars = $self->prop('set-vars') ) {
1996+ $self->set_vars($dbh, $vars);
1997 }
1998
1999 $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
2000@@ -1407,6 +1442,55 @@
2001 return \%new_dsn;
2002 }
2003
2004+sub set_vars {
2005+ my ($self, $dbh, $vars) = @_;
2006+
2007+ foreach my $var ( sort keys %$vars ) {
2008+ my $val = $vars->{$var}->{val};
2009+
2010+ (my $quoted_var = $var) =~ s/_/\\_/;
2011+ my ($var_exists, $current_val);
2012+ eval {
2013+ ($var_exists, $current_val) = $dbh->selectrow_array(
2014+ "SHOW VARIABLES LIKE '$quoted_var'");
2015+ };
2016+ my $e = $EVAL_ERROR;
2017+ if ( $e ) {
2018+ PTDEBUG && _d($e);
2019+ }
2020+
2021+ if ( $vars->{$var}->{default} && !$var_exists ) {
2022+ PTDEBUG && _d('Not setting default var', $var,
2023+ 'because it does not exist');
2024+ next;
2025+ }
2026+
2027+ if ( $current_val && $current_val eq $val ) {
2028+ PTDEBUG && _d('Not setting var', $var, 'because its value',
2029+ 'is already', $val);
2030+ next;
2031+ }
2032+
2033+ my $sql = "SET SESSION $var=$val";
2034+ PTDEBUG && _d($dbh, $sql);
2035+ eval { $dbh->do($sql) };
2036+ if ( my $set_error = $EVAL_ERROR ) {
2037+ chomp($set_error);
2038+ $set_error =~ s/ at \S+ line \d+//;
2039+ my $msg = "Error setting $var: $set_error";
2040+ if ( $current_val ) {
2041+ $msg .= " The current value for $var is $current_val. "
2042+ . "If the variable is read only (not dynamic), specify "
2043+ . "--set-vars $var=$current_val to avoid this warning, "
2044+ . "else manually set the variable and restart MySQL.";
2045+ }
2046+ warn $msg . "\n\n";
2047+ }
2048+ }
2049+
2050+ return;
2051+}
2052+
2053 sub _d {
2054 my ($package, undef, $line) = caller 0;
2055 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
2056@@ -1654,7 +1738,7 @@
2057 $o->get_opts();
2058
2059 my $dp = $o->DSNParser();
2060- $dp->prop('set-vars', $o->get('set-vars'));
2061+ $dp->prop('set-vars', $o->set_vars());
2062
2063 $o->usage_or_errors();
2064
2065@@ -2119,10 +2203,21 @@
2066
2067 =item --set-vars
2068
2069-type: string; default: wait_timeout=10000
2070-
2071-Set these MySQL variables. Immediately after connecting to MySQL, this
2072-string will be appended to SET and executed.
2073+type: Array
2074+
2075+Set the MySQL variables in this comma-separated list of C<variable=value> pairs.
2076+
2077+By default, the tool sets:
2078+
2079+=for comment ignore-pt-internal-value
2080+MAGIC_set_vars
2081+
2082+ wait_timeout=10000
2083+
2084+Variables specified on the command line override these defaults. For
2085+example, specifying C<--set-vars wait_timeout=500> overrides the defaultvalue of C<10000>.
2086+
2087+The tool prints a warning and continues if a variable cannot be set.
2088
2089 =item --socket
2090
2091
2092=== modified file 'bin/pt-slave-delay'
2093--- bin/pt-slave-delay 2013-02-27 00:01:17 +0000
2094+++ bin/pt-slave-delay 2013-03-03 15:43:19 +0000
2095@@ -65,6 +65,7 @@
2096
2097 use List::Util qw(max);
2098 use Getopt::Long;
2099+use Data::Dumper;
2100
2101 my $POD_link_re = '[LC]<"?([^">]+)"?>';
2102
2103@@ -1048,6 +1049,45 @@
2104 );
2105 };
2106
2107+sub set_vars {
2108+ my ($self, $file) = @_;
2109+ $file ||= $self->{file} || __FILE__;
2110+
2111+ my %user_vars;
2112+ my $user_vars = $self->has('set-vars') ? $self->get('set-vars') : undef;
2113+ if ( $user_vars ) {
2114+ foreach my $var_val ( @$user_vars ) {
2115+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
2116+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
2117+ $user_vars{$var} = {
2118+ val => $val,
2119+ default => 0,
2120+ };
2121+ }
2122+ }
2123+
2124+ my %default_vars;
2125+ my $default_vars = $self->read_para_after($file, qr/MAGIC_set_vars/);
2126+ if ( $default_vars ) {
2127+ %default_vars = map {
2128+ my $var_val = $_;
2129+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
2130+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
2131+ $var => {
2132+ val => $val,
2133+ default => 1,
2134+ };
2135+ } split("\n", $default_vars);
2136+ }
2137+
2138+ my %vars = (
2139+ %default_vars, # first the tool's defaults
2140+ %user_vars, # then the user's which overwrite the defaults
2141+ );
2142+ PTDEBUG && _d('--set-vars:', Dumper(\%vars));
2143+ return \%vars;
2144+}
2145+
2146 sub _d {
2147 my ($package, undef, $line) = caller 0;
2148 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
2149@@ -1983,7 +2023,7 @@
2150
2151 if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
2152 $sql = qq{/*!40101 SET NAMES "$charset"*/};
2153- PTDEBUG && _d($dbh, ':', $sql);
2154+ PTDEBUG && _d($dbh, $sql);
2155 eval { $dbh->do($sql) };
2156 if ( $EVAL_ERROR ) {
2157 die "Error setting NAMES to $charset: $EVAL_ERROR";
2158@@ -1998,13 +2038,8 @@
2159 }
2160 }
2161
2162- if ( my $var = $self->prop('set-vars') ) {
2163- $sql = "SET $var";
2164- PTDEBUG && _d($dbh, ':', $sql);
2165- eval { $dbh->do($sql) };
2166- if ( $EVAL_ERROR ) {
2167- die "Error setting $var: $EVAL_ERROR";
2168- }
2169+ if ( my $vars = $self->prop('set-vars') ) {
2170+ $self->set_vars($dbh, $vars);
2171 }
2172
2173 $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
2174@@ -2079,6 +2114,55 @@
2175 return \%new_dsn;
2176 }
2177
2178+sub set_vars {
2179+ my ($self, $dbh, $vars) = @_;
2180+
2181+ foreach my $var ( sort keys %$vars ) {
2182+ my $val = $vars->{$var}->{val};
2183+
2184+ (my $quoted_var = $var) =~ s/_/\\_/;
2185+ my ($var_exists, $current_val);
2186+ eval {
2187+ ($var_exists, $current_val) = $dbh->selectrow_array(
2188+ "SHOW VARIABLES LIKE '$quoted_var'");
2189+ };
2190+ my $e = $EVAL_ERROR;
2191+ if ( $e ) {
2192+ PTDEBUG && _d($e);
2193+ }
2194+
2195+ if ( $vars->{$var}->{default} && !$var_exists ) {
2196+ PTDEBUG && _d('Not setting default var', $var,
2197+ 'because it does not exist');
2198+ next;
2199+ }
2200+
2201+ if ( $current_val && $current_val eq $val ) {
2202+ PTDEBUG && _d('Not setting var', $var, 'because its value',
2203+ 'is already', $val);
2204+ next;
2205+ }
2206+
2207+ my $sql = "SET SESSION $var=$val";
2208+ PTDEBUG && _d($dbh, $sql);
2209+ eval { $dbh->do($sql) };
2210+ if ( my $set_error = $EVAL_ERROR ) {
2211+ chomp($set_error);
2212+ $set_error =~ s/ at \S+ line \d+//;
2213+ my $msg = "Error setting $var: $set_error";
2214+ if ( $current_val ) {
2215+ $msg .= " The current value for $var is $current_val. "
2216+ . "If the variable is read only (not dynamic), specify "
2217+ . "--set-vars $var=$current_val to avoid this warning, "
2218+ . "else manually set the variable and restart MySQL.";
2219+ }
2220+ warn $msg . "\n\n";
2221+ }
2222+ }
2223+
2224+ return;
2225+}
2226+
2227 sub _d {
2228 my ($package, undef, $line) = caller 0;
2229 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
2230@@ -3981,7 +4065,7 @@
2231 $o->get_opts();
2232
2233 my $dp = $o->DSNParser();
2234- $dp->prop('set-vars', $o->get('set-vars'));
2235+ $dp->prop('set-vars', $o->set_vars());
2236
2237 my $dsn_defaults = $dp->parse_options($o);
2238 my $slave_dsn = @ARGV ? $dp->parse(shift @ARGV, $dsn_defaults)
2239@@ -4505,10 +4589,21 @@
2240
2241 =item --set-vars
2242
2243-type: string; default: wait_timeout=10000
2244-
2245-Set these MySQL variables. Immediately after connecting to MySQL, this string
2246-will be appended to SET and executed.
2247+type: Array
2248+
2249+Set the MySQL variables in this comma-separated list of C<variable=value> pairs.
2250+
2251+By default, the tool sets:
2252+
2253+=for comment ignore-pt-internal-value
2254+MAGIC_set_vars
2255+
2256+ wait_timeout=10000
2257+
2258+Variables specified on the command line override these defaults. For
2259+example, specifying C<--set-vars wait_timeout=500> overrides the defaultvalue of C<10000>.
2260+
2261+The tool prints a warning and continues if a variable cannot be set.
2262
2263 =item --socket
2264
2265
2266=== modified file 'bin/pt-slave-find'
2267--- bin/pt-slave-find 2013-02-27 00:01:17 +0000
2268+++ bin/pt-slave-find 2013-03-03 15:43:19 +0000
2269@@ -45,6 +45,7 @@
2270
2271 use List::Util qw(max);
2272 use Getopt::Long;
2273+use Data::Dumper;
2274
2275 my $POD_link_re = '[LC]<"?([^">]+)"?>';
2276
2277@@ -1028,6 +1029,45 @@
2278 );
2279 };
2280
2281+sub set_vars {
2282+ my ($self, $file) = @_;
2283+ $file ||= $self->{file} || __FILE__;
2284+
2285+ my %user_vars;
2286+ my $user_vars = $self->has('set-vars') ? $self->get('set-vars') : undef;
2287+ if ( $user_vars ) {
2288+ foreach my $var_val ( @$user_vars ) {
2289+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
2290+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
2291+ $user_vars{$var} = {
2292+ val => $val,
2293+ default => 0,
2294+ };
2295+ }
2296+ }
2297+
2298+ my %default_vars;
2299+ my $default_vars = $self->read_para_after($file, qr/MAGIC_set_vars/);
2300+ if ( $default_vars ) {
2301+ %default_vars = map {
2302+ my $var_val = $_;
2303+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
2304+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
2305+ $var => {
2306+ val => $val,
2307+ default => 1,
2308+ };
2309+ } split("\n", $default_vars);
2310+ }
2311+
2312+ my %vars = (
2313+ %default_vars, # first the tool's defaults
2314+ %user_vars, # then the user's which overwrite the defaults
2315+ );
2316+ PTDEBUG && _d('--set-vars:', Dumper(\%vars));
2317+ return \%vars;
2318+}
2319+
2320 sub _d {
2321 my ($package, undef, $line) = caller 0;
2322 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
2323@@ -1963,7 +2003,7 @@
2324
2325 if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
2326 $sql = qq{/*!40101 SET NAMES "$charset"*/};
2327- PTDEBUG && _d($dbh, ':', $sql);
2328+ PTDEBUG && _d($dbh, $sql);
2329 eval { $dbh->do($sql) };
2330 if ( $EVAL_ERROR ) {
2331 die "Error setting NAMES to $charset: $EVAL_ERROR";
2332@@ -1978,13 +2018,8 @@
2333 }
2334 }
2335
2336- if ( my $var = $self->prop('set-vars') ) {
2337- $sql = "SET $var";
2338- PTDEBUG && _d($dbh, ':', $sql);
2339- eval { $dbh->do($sql) };
2340- if ( $EVAL_ERROR ) {
2341- die "Error setting $var: $EVAL_ERROR";
2342- }
2343+ if ( my $vars = $self->prop('set-vars') ) {
2344+ $self->set_vars($dbh, $vars);
2345 }
2346
2347 $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
2348@@ -2059,6 +2094,55 @@
2349 return \%new_dsn;
2350 }
2351
2352+sub set_vars {
2353+ my ($self, $dbh, $vars) = @_;
2354+
2355+ foreach my $var ( sort keys %$vars ) {
2356+ my $val = $vars->{$var}->{val};
2357+
2358+ (my $quoted_var = $var) =~ s/_/\\_/;
2359+ my ($var_exists, $current_val);
2360+ eval {
2361+ ($var_exists, $current_val) = $dbh->selectrow_array(
2362+ "SHOW VARIABLES LIKE '$quoted_var'");
2363+ };
2364+ my $e = $EVAL_ERROR;
2365+ if ( $e ) {
2366+ PTDEBUG && _d($e);
2367+ }
2368+
2369+ if ( $vars->{$var}->{default} && !$var_exists ) {
2370+ PTDEBUG && _d('Not setting default var', $var,
2371+ 'because it does not exist');
2372+ next;
2373+ }
2374+
2375+ if ( $current_val && $current_val eq $val ) {
2376+ PTDEBUG && _d('Not setting var', $var, 'because its value',
2377+ 'is already', $val);
2378+ next;
2379+ }
2380+
2381+ my $sql = "SET SESSION $var=$val";
2382+ PTDEBUG && _d($dbh, $sql);
2383+ eval { $dbh->do($sql) };
2384+ if ( my $set_error = $EVAL_ERROR ) {
2385+ chomp($set_error);
2386+ $set_error =~ s/ at \S+ line \d+//;
2387+ my $msg = "Error setting $var: $set_error";
2388+ if ( $current_val ) {
2389+ $msg .= " The current value for $var is $current_val. "
2390+ . "If the variable is read only (not dynamic), specify "
2391+ . "--set-vars $var=$current_val to avoid this warning, "
2392+ . "else manually set the variable and restart MySQL.";
2393+ }
2394+ warn $msg . "\n\n";
2395+ }
2396+ }
2397+
2398+ return;
2399+}
2400+
2401 sub _d {
2402 my ($package, undef, $line) = caller 0;
2403 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
2404@@ -3584,7 +3668,7 @@
2405 $o->get_opts();
2406
2407 my $dp = $o->DSNParser();
2408- $dp->prop('set-vars', $o->get('set-vars'));
2409+ $dp->prop('set-vars', $o->set_vars());
2410
2411 if ( $o->get('ask-pass') ) {
2412 $o->set('password', OptionParser::prompt_noecho("Enter password: "));
2413@@ -4047,10 +4131,21 @@
2414
2415 =item --set-vars
2416
2417-type: string; default: wait_timeout=10000
2418-
2419-Set these MySQL variables. Immediately after connecting to MySQL, this
2420-string will be appended to SET and executed.
2421+type: Array
2422+
2423+Set the MySQL variables in this comma-separated list of C<variable=value> pairs.
2424+
2425+By default, the tool sets:
2426+
2427+=for comment ignore-pt-internal-value
2428+MAGIC_set_vars
2429+
2430+ wait_timeout=10000
2431+
2432+Variables specified on the command line override these defaults. For
2433+example, specifying C<--set-vars wait_timeout=500> overrides the defaultvalue of C<10000>.
2434+
2435+The tool prints a warning and continues if a variable cannot be set.
2436
2437 =item --socket
2438
2439
2440=== modified file 'bin/pt-slave-restart'
2441--- bin/pt-slave-restart 2013-02-27 00:01:17 +0000
2442+++ bin/pt-slave-restart 2013-03-03 15:43:19 +0000
2443@@ -217,6 +217,7 @@
2444
2445 use List::Util qw(max);
2446 use Getopt::Long;
2447+use Data::Dumper;
2448
2449 my $POD_link_re = '[LC]<"?([^">]+)"?>';
2450
2451@@ -1200,6 +1201,45 @@
2452 );
2453 };
2454
2455+sub set_vars {
2456+ my ($self, $file) = @_;
2457+ $file ||= $self->{file} || __FILE__;
2458+
2459+ my %user_vars;
2460+ my $user_vars = $self->has('set-vars') ? $self->get('set-vars') : undef;
2461+ if ( $user_vars ) {
2462+ foreach my $var_val ( @$user_vars ) {
2463+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
2464+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
2465+ $user_vars{$var} = {
2466+ val => $val,
2467+ default => 0,
2468+ };
2469+ }
2470+ }
2471+
2472+ my %default_vars;
2473+ my $default_vars = $self->read_para_after($file, qr/MAGIC_set_vars/);
2474+ if ( $default_vars ) {
2475+ %default_vars = map {
2476+ my $var_val = $_;
2477+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
2478+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
2479+ $var => {
2480+ val => $val,
2481+ default => 1,
2482+ };
2483+ } split("\n", $default_vars);
2484+ }
2485+
2486+ my %vars = (
2487+ %default_vars, # first the tool's defaults
2488+ %user_vars, # then the user's which overwrite the defaults
2489+ );
2490+ PTDEBUG && _d('--set-vars:', Dumper(\%vars));
2491+ return \%vars;
2492+}
2493+
2494 sub _d {
2495 my ($package, undef, $line) = caller 0;
2496 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
2497@@ -2329,7 +2369,7 @@
2498
2499 if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
2500 $sql = qq{/*!40101 SET NAMES "$charset"*/};
2501- PTDEBUG && _d($dbh, ':', $sql);
2502+ PTDEBUG && _d($dbh, $sql);
2503 eval { $dbh->do($sql) };
2504 if ( $EVAL_ERROR ) {
2505 die "Error setting NAMES to $charset: $EVAL_ERROR";
2506@@ -2344,13 +2384,8 @@
2507 }
2508 }
2509
2510- if ( my $var = $self->prop('set-vars') ) {
2511- $sql = "SET $var";
2512- PTDEBUG && _d($dbh, ':', $sql);
2513- eval { $dbh->do($sql) };
2514- if ( $EVAL_ERROR ) {
2515- die "Error setting $var: $EVAL_ERROR";
2516- }
2517+ if ( my $vars = $self->prop('set-vars') ) {
2518+ $self->set_vars($dbh, $vars);
2519 }
2520
2521 $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
2522@@ -2425,6 +2460,55 @@
2523 return \%new_dsn;
2524 }
2525
2526+sub set_vars {
2527+ my ($self, $dbh, $vars) = @_;
2528+
2529+ foreach my $var ( sort keys %$vars ) {
2530+ my $val = $vars->{$var}->{val};
2531+
2532+ (my $quoted_var = $var) =~ s/_/\\_/;
2533+ my ($var_exists, $current_val);
2534+ eval {
2535+ ($var_exists, $current_val) = $dbh->selectrow_array(
2536+ "SHOW VARIABLES LIKE '$quoted_var'");
2537+ };
2538+ my $e = $EVAL_ERROR;
2539+ if ( $e ) {
2540+ PTDEBUG && _d($e);
2541+ }
2542+
2543+ if ( $vars->{$var}->{default} && !$var_exists ) {
2544+ PTDEBUG && _d('Not setting default var', $var,
2545+ 'because it does not exist');
2546+ next;
2547+ }
2548+
2549+ if ( $current_val && $current_val eq $val ) {
2550+ PTDEBUG && _d('Not setting var', $var, 'because its value',
2551+ 'is already', $val);
2552+ next;
2553+ }
2554+
2555+ my $sql = "SET SESSION $var=$val";
2556+ PTDEBUG && _d($dbh, $sql);
2557+ eval { $dbh->do($sql) };
2558+ if ( my $set_error = $EVAL_ERROR ) {
2559+ chomp($set_error);
2560+ $set_error =~ s/ at \S+ line \d+//;
2561+ my $msg = "Error setting $var: $set_error";
2562+ if ( $current_val ) {
2563+ $msg .= " The current value for $var is $current_val. "
2564+ . "If the variable is read only (not dynamic), specify "
2565+ . "--set-vars $var=$current_val to avoid this warning, "
2566+ . "else manually set the variable and restart MySQL.";
2567+ }
2568+ warn $msg . "\n\n";
2569+ }
2570+ }
2571+
2572+ return;
2573+}
2574+
2575 sub _d {
2576 my ($package, undef, $line) = caller 0;
2577 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
2578@@ -4636,7 +4720,7 @@
2579 $o->get_opts();
2580
2581 $dp = $o->DSNParser();
2582- $dp->prop('set-vars', $o->get('set-vars'));
2583+ $dp->prop('set-vars', $o->set_vars());
2584
2585 $o->set('verbose', 0) if $o->get('quiet');
2586
2587@@ -5386,10 +5470,21 @@
2588
2589 =item --set-vars
2590
2591-type: string; default: wait_timeout=10000
2592-
2593-Set these MySQL variables. Immediately after connecting to MySQL, this string
2594-will be appended to SET and executed.
2595+type: Array
2596+
2597+Set the MySQL variables in this comma-separated list of C<variable=value> pairs.
2598+
2599+By default, the tool sets:
2600+
2601+=for comment ignore-pt-internal-value
2602+MAGIC_set_vars
2603+
2604+ wait_timeout=10000
2605+
2606+Variables specified on the command line override these defaults. For
2607+example, specifying C<--set-vars wait_timeout=500> overrides the defaultvalue of C<10000>.
2608+
2609+The tool prints a warning and continues if a variable cannot be set.
2610
2611 =item --skip-count
2612
2613
2614=== modified file 'bin/pt-table-checksum'
2615--- bin/pt-table-checksum 2013-03-01 02:26:04 +0000
2616+++ bin/pt-table-checksum 2013-03-03 15:43:19 +0000
2617@@ -1555,7 +1555,7 @@
2618
2619 if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
2620 $sql = qq{/*!40101 SET NAMES "$charset"*/};
2621- PTDEBUG && _d($dbh, ':', $sql);
2622+ PTDEBUG && _d($dbh, $sql);
2623 eval { $dbh->do($sql) };
2624 if ( $EVAL_ERROR ) {
2625 die "Error setting NAMES to $charset: $EVAL_ERROR";
2626@@ -1570,13 +1570,8 @@
2627 }
2628 }
2629
2630- if ( my $var = $self->prop('set-vars') ) {
2631- $sql = "SET $var";
2632- PTDEBUG && _d($dbh, ':', $sql);
2633- eval { $dbh->do($sql) };
2634- if ( $EVAL_ERROR ) {
2635- die "Error setting $var: $EVAL_ERROR";
2636- }
2637+ if ( my $vars = $self->prop('set-vars') ) {
2638+ $self->set_vars($dbh, $vars);
2639 }
2640
2641 $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
2642@@ -1651,6 +1646,55 @@
2643 return \%new_dsn;
2644 }
2645
2646+sub set_vars {
2647+ my ($self, $dbh, $vars) = @_;
2648+
2649+ foreach my $var ( sort keys %$vars ) {
2650+ my $val = $vars->{$var}->{val};
2651+
2652+ (my $quoted_var = $var) =~ s/_/\\_/;
2653+ my ($var_exists, $current_val);
2654+ eval {
2655+ ($var_exists, $current_val) = $dbh->selectrow_array(
2656+ "SHOW VARIABLES LIKE '$quoted_var'");
2657+ };
2658+ my $e = $EVAL_ERROR;
2659+ if ( $e ) {
2660+ PTDEBUG && _d($e);
2661+ }
2662+
2663+ if ( $vars->{$var}->{default} && !$var_exists ) {
2664+ PTDEBUG && _d('Not setting default var', $var,
2665+ 'because it does not exist');
2666+ next;
2667+ }
2668+
2669+ if ( $current_val && $current_val eq $val ) {
2670+ PTDEBUG && _d('Not setting var', $var, 'because its value',
2671+ 'is already', $val);
2672+ next;
2673+ }
2674+
2675+ my $sql = "SET SESSION $var=$val";
2676+ PTDEBUG && _d($dbh, $sql);
2677+ eval { $dbh->do($sql) };
2678+ if ( my $set_error = $EVAL_ERROR ) {
2679+ chomp($set_error);
2680+ $set_error =~ s/ at \S+ line \d+//;
2681+ my $msg = "Error setting $var: $set_error";
2682+ if ( $current_val ) {
2683+ $msg .= " The current value for $var is $current_val. "
2684+ . "If the variable is read only (not dynamic), specify "
2685+ . "--set-vars $var=$current_val to avoid this warning, "
2686+ . "else manually set the variable and restart MySQL.";
2687+ }
2688+ warn $msg . "\n\n";
2689+ }
2690+ }
2691+
2692+ return;
2693+}
2694+
2695 sub _d {
2696 my ($package, undef, $line) = caller 0;
2697 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
2698@@ -1683,6 +1727,7 @@
2699
2700 use List::Util qw(max);
2701 use Getopt::Long;
2702+use Data::Dumper;
2703
2704 my $POD_link_re = '[LC]<"?([^">]+)"?>';
2705
2706@@ -2666,6 +2711,45 @@
2707 );
2708 };
2709
2710+sub set_vars {
2711+ my ($self, $file) = @_;
2712+ $file ||= $self->{file} || __FILE__;
2713+
2714+ my %user_vars;
2715+ my $user_vars = $self->has('set-vars') ? $self->get('set-vars') : undef;
2716+ if ( $user_vars ) {
2717+ foreach my $var_val ( @$user_vars ) {
2718+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
2719+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
2720+ $user_vars{$var} = {
2721+ val => $val,
2722+ default => 0,
2723+ };
2724+ }
2725+ }
2726+
2727+ my %default_vars;
2728+ my $default_vars = $self->read_para_after($file, qr/MAGIC_set_vars/);
2729+ if ( $default_vars ) {
2730+ %default_vars = map {
2731+ my $var_val = $_;
2732+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
2733+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
2734+ $var => {
2735+ val => $val,
2736+ default => 1,
2737+ };
2738+ } split("\n", $default_vars);
2739+ }
2740+
2741+ my %vars = (
2742+ %default_vars, # first the tool's defaults
2743+ %user_vars, # then the user's which overwrite the defaults
2744+ );
2745+ PTDEBUG && _d('--set-vars:', Dumper(\%vars));
2746+ return \%vars;
2747+}
2748+
2749 sub _d {
2750 my ($package, undef, $line) = caller 0;
2751 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
2752@@ -8613,7 +8697,7 @@
2753 $o->get_opts();
2754
2755 my $dp = $o->DSNParser();
2756- $dp->prop('set-vars', $o->get('set-vars'));
2757+ $dp->prop('set-vars', $o->set_vars());
2758
2759 # Add the --replicate table to --ignore-tables.
2760 my %ignore_tables = (
2761@@ -8754,43 +8838,7 @@
2762 . "level to REPEATABLE-READ.\n";
2763 }
2764
2765- # We set innodb_lock_wait_timeout=1 (the option's default value)
2766- # so that if this tool happens to cause some locking, it will more
2767- # likely be the victim than other connections and thus avoid disrupting
2768- # the server. The var is only dynamic with the InnoDB plugin, so
2769- # if setting it fails we only warn if the server's value is greater
2770- # than the desired value. E.g. if user does --lock-wait-timeout 5
2771- # and the set fails but the server's value is 1, then that's ok, but
2772- # if the server's value is 10, then that's not ok.
2773- my $lock_wait_timeout = $o->get('lock-wait-timeout');
2774- my $set_lwt = "SET SESSION innodb_lock_wait_timeout=$lock_wait_timeout";
2775- PTDEBUG && _d($dbh, $set_lwt);
2776- eval {
2777- $dbh->do($set_lwt);
2778- };
2779- if ( $EVAL_ERROR ) {
2780- PTDEBUG && _d($EVAL_ERROR);
2781- # Get the server's current value.
2782- $sql = "SHOW SESSION VARIABLES LIKE 'innodb_lock_wait_timeout'";
2783- PTDEBUG && _d($dbh, $sql);
2784- my (undef, $curr_lwt) = $dbh->selectrow_array($sql);
2785- PTDEBUG && _d('innodb_lock_wait_timeout on server:', $curr_lwt);
2786- if ( !defined $curr_lwt ) {
2787- PTDEBUG && _d('innodb_lock_wait_timeout does not exist;',
2788- 'InnoDB is probably disabled');
2789- }
2790- elsif ( $curr_lwt > $lock_wait_timeout ) {
2791- warn "Failed to $set_lwt: $EVAL_ERROR\n"
2792- . "The current innodb_lock_wait_timeout value "
2793- . "$curr_lwt is greater than the --lock-wait-timeout "
2794- . "value $lock_wait_timeout and the variable cannot be "
2795- . "changed. innodb_lock_wait_timeout is only dynamic when "
2796- . "using the InnoDB plugin. To prevent this warning, either "
2797- . "specify --lock-wait-time=$curr_lwt, or manually set "
2798- . "innodb_lock_wait_timeout to a value less than or equal "
2799- . "to $lock_wait_timeout and restart MySQL.\n";
2800- }
2801- }
2802+ return;
2803 };
2804
2805 # Do not call "new Cxn(" directly; use this sub so that set_on_connect
2806@@ -11553,18 +11601,6 @@
2807
2808 Ignore tables whose names match the Perl regex.
2809
2810-=item --lock-wait-timeout
2811-
2812-type: int; default: 1
2813-
2814-Set the session value of C<innodb_lock_wait_timeout> on the master host.
2815-This option helps guard against long lock waits if the checksum queries
2816-become slow for some reason. Setting this option dynamically requires the
2817-InnoDB plugin, so this works only on newer InnoDB and MySQL versions. If
2818-setting the value fails and the current server value is greater than the
2819-specified value, then a warning is printed; else, if the current server
2820-value is less than or equal to the specified value, no warning is printed.
2821-
2822 =item --max-lag
2823
2824 type: time; default: 1s; group: Throttle
2825@@ -11824,10 +11860,22 @@
2826
2827 =item --set-vars
2828
2829-type: string; default: wait_timeout=10000; group: Connection
2830-
2831-Set these MySQL variables. Immediately after connecting to MySQL, this
2832-string will be appended to SET and executed.
2833+type: Array; group: Connection
2834+
2835+Set the MySQL variables in this comma-separated list of C<variable=value> pairs.
2836+
2837+By default, the tool sets:
2838+
2839+=for comment ignore-pt-internal-value
2840+MAGIC_set_vars
2841+
2842+ wait_timeout=10000
2843+ innodb_lock_wait_timeout=1
2844+
2845+Variables specified on the command line override these defaults. For
2846+example, specifying C<--set-vars wait_timeout=500> overrides the defaultvalue of C<10000>.
2847+
2848+The tool prints a warning and continues if a variable cannot be set.
2849
2850 =item --socket
2851
2852
2853=== modified file 'bin/pt-table-sync'
2854--- bin/pt-table-sync 2013-02-27 00:01:17 +0000
2855+++ bin/pt-table-sync 2013-03-03 15:43:19 +0000
2856@@ -80,6 +80,7 @@
2857
2858 use List::Util qw(max);
2859 use Getopt::Long;
2860+use Data::Dumper;
2861
2862 my $POD_link_re = '[LC]<"?([^">]+)"?>';
2863
2864@@ -1063,6 +1064,45 @@
2865 );
2866 };
2867
2868+sub set_vars {
2869+ my ($self, $file) = @_;
2870+ $file ||= $self->{file} || __FILE__;
2871+
2872+ my %user_vars;
2873+ my $user_vars = $self->has('set-vars') ? $self->get('set-vars') : undef;
2874+ if ( $user_vars ) {
2875+ foreach my $var_val ( @$user_vars ) {
2876+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
2877+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
2878+ $user_vars{$var} = {
2879+ val => $val,
2880+ default => 0,
2881+ };
2882+ }
2883+ }
2884+
2885+ my %default_vars;
2886+ my $default_vars = $self->read_para_after($file, qr/MAGIC_set_vars/);
2887+ if ( $default_vars ) {
2888+ %default_vars = map {
2889+ my $var_val = $_;
2890+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
2891+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
2892+ $var => {
2893+ val => $val,
2894+ default => 1,
2895+ };
2896+ } split("\n", $default_vars);
2897+ }
2898+
2899+ my %vars = (
2900+ %default_vars, # first the tool's defaults
2901+ %user_vars, # then the user's which overwrite the defaults
2902+ );
2903+ PTDEBUG && _d('--set-vars:', Dumper(\%vars));
2904+ return \%vars;
2905+}
2906+
2907 sub _d {
2908 my ($package, undef, $line) = caller 0;
2909 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
2910@@ -2149,7 +2189,7 @@
2911
2912 if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
2913 $sql = qq{/*!40101 SET NAMES "$charset"*/};
2914- PTDEBUG && _d($dbh, ':', $sql);
2915+ PTDEBUG && _d($dbh, $sql);
2916 eval { $dbh->do($sql) };
2917 if ( $EVAL_ERROR ) {
2918 die "Error setting NAMES to $charset: $EVAL_ERROR";
2919@@ -2164,13 +2204,8 @@
2920 }
2921 }
2922
2923- if ( my $var = $self->prop('set-vars') ) {
2924- $sql = "SET $var";
2925- PTDEBUG && _d($dbh, ':', $sql);
2926- eval { $dbh->do($sql) };
2927- if ( $EVAL_ERROR ) {
2928- die "Error setting $var: $EVAL_ERROR";
2929- }
2930+ if ( my $vars = $self->prop('set-vars') ) {
2931+ $self->set_vars($dbh, $vars);
2932 }
2933
2934 $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
2935@@ -2245,6 +2280,55 @@
2936 return \%new_dsn;
2937 }
2938
2939+sub set_vars {
2940+ my ($self, $dbh, $vars) = @_;
2941+
2942+ foreach my $var ( sort keys %$vars ) {
2943+ my $val = $vars->{$var}->{val};
2944+
2945+ (my $quoted_var = $var) =~ s/_/\\_/;
2946+ my ($var_exists, $current_val);
2947+ eval {
2948+ ($var_exists, $current_val) = $dbh->selectrow_array(
2949+ "SHOW VARIABLES LIKE '$quoted_var'");
2950+ };
2951+ my $e = $EVAL_ERROR;
2952+ if ( $e ) {
2953+ PTDEBUG && _d($e);
2954+ }
2955+
2956+ if ( $vars->{$var}->{default} && !$var_exists ) {
2957+ PTDEBUG && _d('Not setting default var', $var,
2958+ 'because it does not exist');
2959+ next;
2960+ }
2961+
2962+ if ( $current_val && $current_val eq $val ) {
2963+ PTDEBUG && _d('Not setting var', $var, 'because its value',
2964+ 'is already', $val);
2965+ next;
2966+ }
2967+
2968+ my $sql = "SET SESSION $var=$val";
2969+ PTDEBUG && _d($dbh, $sql);
2970+ eval { $dbh->do($sql) };
2971+ if ( my $set_error = $EVAL_ERROR ) {
2972+ chomp($set_error);
2973+ $set_error =~ s/ at \S+ line \d+//;
2974+ my $msg = "Error setting $var: $set_error";
2975+ if ( $current_val ) {
2976+ $msg .= " The current value for $var is $current_val. "
2977+ . "If the variable is read only (not dynamic), specify "
2978+ . "--set-vars $var=$current_val to avoid this warning, "
2979+ . "else manually set the variable and restart MySQL.";
2980+ }
2981+ warn $msg . "\n\n";
2982+ }
2983+ }
2984+
2985+ return;
2986+}
2987+
2988 sub _d {
2989 my ($package, undef, $line) = caller 0;
2990 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
2991@@ -9476,7 +9560,7 @@
2992 $o->get_opts();
2993
2994 my $dp = $o->DSNParser();
2995- $dp->prop('set-vars', $o->get('set-vars'));
2996+ $dp->prop('set-vars', $o->set_vars());
2997
2998 if ( $o->get('replicate') || $o->get('sync-to-master') ) {
2999 $o->set('wait', 60) unless $o->got('wait');
3000@@ -12137,10 +12221,21 @@
3001
3002 =item --set-vars
3003
3004-type: string; default: wait_timeout=10000
3005-
3006-Set these MySQL variables. Immediately after connecting to MySQL, this
3007-string will be appended to SET and executed.
3008+type: Array
3009+
3010+Set the MySQL variables in this comma-separated list of C<variable=value> pairs.
3011+
3012+By default, the tool sets:
3013+
3014+=for comment ignore-pt-internal-value
3015+MAGIC_set_vars
3016+
3017+ wait_timeout=10000
3018+
3019+Variables specified on the command line override these defaults. For
3020+example, specifying C<--set-vars wait_timeout=500> overrides the defaultvalue of C<10000>.
3021+
3022+The tool prints a warning and continues if a variable cannot be set.
3023
3024 =item --socket
3025
3026
3027=== modified file 'bin/pt-table-usage'
3028--- bin/pt-table-usage 2013-02-28 02:23:08 +0000
3029+++ bin/pt-table-usage 2013-03-03 15:43:19 +0000
3030@@ -300,7 +300,7 @@
3031
3032 if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
3033 $sql = qq{/*!40101 SET NAMES "$charset"*/};
3034- PTDEBUG && _d($dbh, ':', $sql);
3035+ PTDEBUG && _d($dbh, $sql);
3036 eval { $dbh->do($sql) };
3037 if ( $EVAL_ERROR ) {
3038 die "Error setting NAMES to $charset: $EVAL_ERROR";
3039@@ -315,13 +315,8 @@
3040 }
3041 }
3042
3043- if ( my $var = $self->prop('set-vars') ) {
3044- $sql = "SET $var";
3045- PTDEBUG && _d($dbh, ':', $sql);
3046- eval { $dbh->do($sql) };
3047- if ( $EVAL_ERROR ) {
3048- die "Error setting $var: $EVAL_ERROR";
3049- }
3050+ if ( my $vars = $self->prop('set-vars') ) {
3051+ $self->set_vars($dbh, $vars);
3052 }
3053
3054 $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
3055@@ -396,6 +391,55 @@
3056 return \%new_dsn;
3057 }
3058
3059+sub set_vars {
3060+ my ($self, $dbh, $vars) = @_;
3061+
3062+ foreach my $var ( sort keys %$vars ) {
3063+ my $val = $vars->{$var}->{val};
3064+
3065+ (my $quoted_var = $var) =~ s/_/\\_/;
3066+ my ($var_exists, $current_val);
3067+ eval {
3068+ ($var_exists, $current_val) = $dbh->selectrow_array(
3069+ "SHOW VARIABLES LIKE '$quoted_var'");
3070+ };
3071+ my $e = $EVAL_ERROR;
3072+ if ( $e ) {
3073+ PTDEBUG && _d($e);
3074+ }
3075+
3076+ if ( $vars->{$var}->{default} && !$var_exists ) {
3077+ PTDEBUG && _d('Not setting default var', $var,
3078+ 'because it does not exist');
3079+ next;
3080+ }
3081+
3082+ if ( $current_val && $current_val eq $val ) {
3083+ PTDEBUG && _d('Not setting var', $var, 'because its value',
3084+ 'is already', $val);
3085+ next;
3086+ }
3087+
3088+ my $sql = "SET SESSION $var=$val";
3089+ PTDEBUG && _d($dbh, $sql);
3090+ eval { $dbh->do($sql) };
3091+ if ( my $set_error = $EVAL_ERROR ) {
3092+ chomp($set_error);
3093+ $set_error =~ s/ at \S+ line \d+//;
3094+ my $msg = "Error setting $var: $set_error";
3095+ if ( $current_val ) {
3096+ $msg .= " The current value for $var is $current_val. "
3097+ . "If the variable is read only (not dynamic), specify "
3098+ . "--set-vars $var=$current_val to avoid this warning, "
3099+ . "else manually set the variable and restart MySQL.";
3100+ }
3101+ warn $msg . "\n\n";
3102+ }
3103+ }
3104+
3105+ return;
3106+}
3107+
3108 sub _d {
3109 my ($package, undef, $line) = caller 0;
3110 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
3111@@ -428,6 +472,7 @@
3112
3113 use List::Util qw(max);
3114 use Getopt::Long;
3115+use Data::Dumper;
3116
3117 my $POD_link_re = '[LC]<"?([^">]+)"?>';
3118
3119@@ -449,7 +494,6 @@
3120 'default' => 1,
3121 'cumulative' => 1,
3122 'negatable' => 1,
3123- 'value_is_optional' => 1,
3124 );
3125
3126 my $self = {
3127@@ -691,10 +735,9 @@
3128 $opt->{short} = undef;
3129 }
3130
3131- $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
3132- $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
3133- $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;
3134- $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
3135+ $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
3136+ $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
3137+ $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
3138
3139 $opt->{group} ||= 'default';
3140 $self->{groups}->{ $opt->{group} }->{$long} = 1;
3141@@ -830,7 +873,7 @@
3142 if ( $opt->{is_cumulative} ) {
3143 $opt->{value}++;
3144 }
3145- elsif ( !($opt->{optional_value} && !$val) ) {
3146+ else {
3147 $opt->{value} = $val;
3148 }
3149 $opt->{got} = 1;
3150@@ -1210,7 +1253,7 @@
3151 $desc .= ". Optional suffix s=seconds, m=minutes, h=hours, "
3152 . "d=days; if no suffix, $s is used.";
3153 }
3154- $desc = join("\n$rpad", grep { $_ } $desc =~ m/(.{0,$rcol})(?:\s+|$)/g);
3155+ $desc = join("\n$rpad", grep { $_ } $desc =~ m/(.{0,$rcol}(?!\W))(?:\s+|(?<=\W)|$)/g);
3156 $desc =~ s/ +$//mg;
3157 if ( $short ) {
3158 $usage .= sprintf(" --%-${maxs}s -%s %s\n", $long, $short, $desc);
3159@@ -1371,12 +1414,11 @@
3160 sub _parse_attribs {
3161 my ( $self, $option, $attribs ) = @_;
3162 my $types = $self->{types};
3163- my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
3164 return $option
3165 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
3166 . ($attribs->{'negatable'} ? '!' : '' )
3167 . ($attribs->{'cumulative'} ? '+' : '' )
3168- . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );
3169+ . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
3170 }
3171
3172 sub _parse_synopsis {
3173@@ -1414,6 +1456,45 @@
3174 );
3175 };
3176
3177+sub set_vars {
3178+ my ($self, $file) = @_;
3179+ $file ||= $self->{file} || __FILE__;
3180+
3181+ my %user_vars;
3182+ my $user_vars = $self->has('set-vars') ? $self->get('set-vars') : undef;
3183+ if ( $user_vars ) {
3184+ foreach my $var_val ( @$user_vars ) {
3185+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
3186+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
3187+ $user_vars{$var} = {
3188+ val => $val,
3189+ default => 0,
3190+ };
3191+ }
3192+ }
3193+
3194+ my %default_vars;
3195+ my $default_vars = $self->read_para_after($file, qr/MAGIC_set_vars/);
3196+ if ( $default_vars ) {
3197+ %default_vars = map {
3198+ my $var_val = $_;
3199+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
3200+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
3201+ $var => {
3202+ val => $val,
3203+ default => 1,
3204+ };
3205+ } split("\n", $default_vars);
3206+ }
3207+
3208+ my %vars = (
3209+ %default_vars, # first the tool's defaults
3210+ %user_vars, # then the user's which overwrite the defaults
3211+ );
3212+ PTDEBUG && _d('--set-vars:', Dumper(\%vars));
3213+ return \%vars;
3214+}
3215+
3216 sub _d {
3217 my ($package, undef, $line) = caller 0;
3218 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
3219@@ -6398,7 +6479,7 @@
3220 $o->get_opts();
3221
3222 my $dp = $o->DSNParser();
3223- $dp->prop('set-vars', $o->get('set-vars'));
3224+ $dp->prop('set-vars', $o->set_vars());
3225
3226 $o->usage_or_errors();
3227
3228@@ -7245,10 +7326,21 @@
3229
3230 =item --set-vars
3231
3232-type: string; default: wait_timeout=10000
3233-
3234-Set these MySQL variables. Immediately after connecting to MySQL, this
3235-string will be appended to SET and executed.
3236+type: Array
3237+
3238+Set the MySQL variables in this comma-separated list of C<variable=value> pairs.
3239+
3240+By default, the tool sets:
3241+
3242+=for comment ignore-pt-internal-value
3243+MAGIC_set_vars
3244+
3245+ wait_timeout=10000
3246+
3247+Variables specified on the command line override these defaults. For
3248+example, specifying C<--set-vars wait_timeout=500> overrides the defaultvalue of C<10000>.
3249+
3250+The tool prints a warning and continues if a variable cannot be set.
3251
3252 =item --socket
3253
3254
3255=== modified file 'bin/pt-upgrade'
3256--- bin/pt-upgrade 2013-02-27 00:01:17 +0000
3257+++ bin/pt-upgrade 2013-03-03 15:43:19 +0000
3258@@ -981,7 +981,7 @@
3259
3260 if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
3261 $sql = qq{/*!40101 SET NAMES "$charset"*/};
3262- PTDEBUG && _d($dbh, ':', $sql);
3263+ PTDEBUG && _d($dbh, $sql);
3264 eval { $dbh->do($sql) };
3265 if ( $EVAL_ERROR ) {
3266 die "Error setting NAMES to $charset: $EVAL_ERROR";
3267@@ -996,13 +996,8 @@
3268 }
3269 }
3270
3271- if ( my $var = $self->prop('set-vars') ) {
3272- $sql = "SET $var";
3273- PTDEBUG && _d($dbh, ':', $sql);
3274- eval { $dbh->do($sql) };
3275- if ( $EVAL_ERROR ) {
3276- die "Error setting $var: $EVAL_ERROR";
3277- }
3278+ if ( my $vars = $self->prop('set-vars') ) {
3279+ $self->set_vars($dbh, $vars);
3280 }
3281
3282 $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
3283@@ -1077,6 +1072,55 @@
3284 return \%new_dsn;
3285 }
3286
3287+sub set_vars {
3288+ my ($self, $dbh, $vars) = @_;
3289+
3290+ foreach my $var ( sort keys %$vars ) {
3291+ my $val = $vars->{$var}->{val};
3292+
3293+ (my $quoted_var = $var) =~ s/_/\\_/;
3294+ my ($var_exists, $current_val);
3295+ eval {
3296+ ($var_exists, $current_val) = $dbh->selectrow_array(
3297+ "SHOW VARIABLES LIKE '$quoted_var'");
3298+ };
3299+ my $e = $EVAL_ERROR;
3300+ if ( $e ) {
3301+ PTDEBUG && _d($e);
3302+ }
3303+
3304+ if ( $vars->{$var}->{default} && !$var_exists ) {
3305+ PTDEBUG && _d('Not setting default var', $var,
3306+ 'because it does not exist');
3307+ next;
3308+ }
3309+
3310+ if ( $current_val && $current_val eq $val ) {
3311+ PTDEBUG && _d('Not setting var', $var, 'because its value',
3312+ 'is already', $val);
3313+ next;
3314+ }
3315+
3316+ my $sql = "SET SESSION $var=$val";
3317+ PTDEBUG && _d($dbh, $sql);
3318+ eval { $dbh->do($sql) };
3319+ if ( my $set_error = $EVAL_ERROR ) {
3320+ chomp($set_error);
3321+ $set_error =~ s/ at \S+ line \d+//;
3322+ my $msg = "Error setting $var: $set_error";
3323+ if ( $current_val ) {
3324+ $msg .= " The current value for $var is $current_val. "
3325+ . "If the variable is read only (not dynamic), specify "
3326+ . "--set-vars $var=$current_val to avoid this warning, "
3327+ . "else manually set the variable and restart MySQL.";
3328+ }
3329+ warn $msg . "\n\n";
3330+ }
3331+ }
3332+
3333+ return;
3334+}
3335+
3336 sub _d {
3337 my ($package, undef, $line) = caller 0;
3338 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
3339@@ -1671,6 +1715,7 @@
3340
3341 use List::Util qw(max);
3342 use Getopt::Long;
3343+use Data::Dumper;
3344
3345 my $POD_link_re = '[LC]<"?([^">]+)"?>';
3346
3347@@ -2654,6 +2699,45 @@
3348 );
3349 };
3350
3351+sub set_vars {
3352+ my ($self, $file) = @_;
3353+ $file ||= $self->{file} || __FILE__;
3354+
3355+ my %user_vars;
3356+ my $user_vars = $self->has('set-vars') ? $self->get('set-vars') : undef;
3357+ if ( $user_vars ) {
3358+ foreach my $var_val ( @$user_vars ) {
3359+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
3360+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
3361+ $user_vars{$var} = {
3362+ val => $val,
3363+ default => 0,
3364+ };
3365+ }
3366+ }
3367+
3368+ my %default_vars;
3369+ my $default_vars = $self->read_para_after($file, qr/MAGIC_set_vars/);
3370+ if ( $default_vars ) {
3371+ %default_vars = map {
3372+ my $var_val = $_;
3373+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
3374+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
3375+ $var => {
3376+ val => $val,
3377+ default => 1,
3378+ };
3379+ } split("\n", $default_vars);
3380+ }
3381+
3382+ my %vars = (
3383+ %default_vars, # first the tool's defaults
3384+ %user_vars, # then the user's which overwrite the defaults
3385+ );
3386+ PTDEBUG && _d('--set-vars:', Dumper(\%vars));
3387+ return \%vars;
3388+}
3389+
3390 sub _d {
3391 my ($package, undef, $line) = caller 0;
3392 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
3393@@ -12296,7 +12380,7 @@
3394 $o->get_opts();
3395
3396 my $dp = $o->DSNParser();
3397- $dp->prop('set-vars', $o->get('set-vars'));
3398+ $dp->prop('set-vars', $o->set_vars());
3399
3400 if ( !$o->get('help') ) {
3401 if ( @ARGV < 1 ) {
3402@@ -13522,10 +13606,21 @@
3403
3404 =item --set-vars
3405
3406-type: string; default: wait_timeout=10000
3407-
3408-Set these MySQL variables. Immediately after connecting to MySQL, this
3409-string will be appended to SET and executed.
3410+type: Array
3411+
3412+Set the MySQL variables in this comma-separated list of C<variable=value> pairs.
3413+
3414+By default, the tool sets:
3415+
3416+=for comment ignore-pt-internal-value
3417+MAGIC_set_vars
3418+
3419+ wait_timeout=10000
3420+
3421+Variables specified on the command line override these defaults. For
3422+example, specifying C<--set-vars wait_timeout=500> overrides the defaultvalue of C<10000>.
3423+
3424+The tool prints a warning and continues if a variable cannot be set.
3425
3426 =item --shorten
3427
3428
3429=== modified file 'bin/pt-variable-advisor'
3430--- bin/pt-variable-advisor 2013-02-27 00:01:17 +0000
3431+++ bin/pt-variable-advisor 2013-03-03 15:43:19 +0000
3432@@ -69,6 +69,7 @@
3433
3434 use List::Util qw(max);
3435 use Getopt::Long;
3436+use Data::Dumper;
3437
3438 my $POD_link_re = '[LC]<"?([^">]+)"?>';
3439
3440@@ -1052,6 +1053,45 @@
3441 );
3442 };
3443
3444+sub set_vars {
3445+ my ($self, $file) = @_;
3446+ $file ||= $self->{file} || __FILE__;
3447+
3448+ my %user_vars;
3449+ my $user_vars = $self->has('set-vars') ? $self->get('set-vars') : undef;
3450+ if ( $user_vars ) {
3451+ foreach my $var_val ( @$user_vars ) {
3452+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
3453+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
3454+ $user_vars{$var} = {
3455+ val => $val,
3456+ default => 0,
3457+ };
3458+ }
3459+ }
3460+
3461+ my %default_vars;
3462+ my $default_vars = $self->read_para_after($file, qr/MAGIC_set_vars/);
3463+ if ( $default_vars ) {
3464+ %default_vars = map {
3465+ my $var_val = $_;
3466+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
3467+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
3468+ $var => {
3469+ val => $val,
3470+ default => 1,
3471+ };
3472+ } split("\n", $default_vars);
3473+ }
3474+
3475+ my %vars = (
3476+ %default_vars, # first the tool's defaults
3477+ %user_vars, # then the user's which overwrite the defaults
3478+ );
3479+ PTDEBUG && _d('--set-vars:', Dumper(\%vars));
3480+ return \%vars;
3481+}
3482+
3483 sub _d {
3484 my ($package, undef, $line) = caller 0;
3485 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
3486@@ -1987,7 +2027,7 @@
3487
3488 if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
3489 $sql = qq{/*!40101 SET NAMES "$charset"*/};
3490- PTDEBUG && _d($dbh, ':', $sql);
3491+ PTDEBUG && _d($dbh, $sql);
3492 eval { $dbh->do($sql) };
3493 if ( $EVAL_ERROR ) {
3494 die "Error setting NAMES to $charset: $EVAL_ERROR";
3495@@ -2002,13 +2042,8 @@
3496 }
3497 }
3498
3499- if ( my $var = $self->prop('set-vars') ) {
3500- $sql = "SET $var";
3501- PTDEBUG && _d($dbh, ':', $sql);
3502- eval { $dbh->do($sql) };
3503- if ( $EVAL_ERROR ) {
3504- die "Error setting $var: $EVAL_ERROR";
3505- }
3506+ if ( my $vars = $self->prop('set-vars') ) {
3507+ $self->set_vars($dbh, $vars);
3508 }
3509
3510 $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
3511@@ -2083,6 +2118,55 @@
3512 return \%new_dsn;
3513 }
3514
3515+sub set_vars {
3516+ my ($self, $dbh, $vars) = @_;
3517+
3518+ foreach my $var ( sort keys %$vars ) {
3519+ my $val = $vars->{$var}->{val};
3520+
3521+ (my $quoted_var = $var) =~ s/_/\\_/;
3522+ my ($var_exists, $current_val);
3523+ eval {
3524+ ($var_exists, $current_val) = $dbh->selectrow_array(
3525+ "SHOW VARIABLES LIKE '$quoted_var'");
3526+ };
3527+ my $e = $EVAL_ERROR;
3528+ if ( $e ) {
3529+ PTDEBUG && _d($e);
3530+ }
3531+
3532+ if ( $vars->{$var}->{default} && !$var_exists ) {
3533+ PTDEBUG && _d('Not setting default var', $var,
3534+ 'because it does not exist');
3535+ next;
3536+ }
3537+
3538+ if ( $current_val && $current_val eq $val ) {
3539+ PTDEBUG && _d('Not setting var', $var, 'because its value',
3540+ 'is already', $val);
3541+ next;
3542+ }
3543+
3544+ my $sql = "SET SESSION $var=$val";
3545+ PTDEBUG && _d($dbh, $sql);
3546+ eval { $dbh->do($sql) };
3547+ if ( my $set_error = $EVAL_ERROR ) {
3548+ chomp($set_error);
3549+ $set_error =~ s/ at \S+ line \d+//;
3550+ my $msg = "Error setting $var: $set_error";
3551+ if ( $current_val ) {
3552+ $msg .= " The current value for $var is $current_val. "
3553+ . "If the variable is read only (not dynamic), specify "
3554+ . "--set-vars $var=$current_val to avoid this warning, "
3555+ . "else manually set the variable and restart MySQL.";
3556+ }
3557+ warn $msg . "\n\n";
3558+ }
3559+ }
3560+
3561+ return;
3562+}
3563+
3564 sub _d {
3565 my ($package, undef, $line) = caller 0;
3566 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
3567@@ -4885,7 +4969,7 @@
3568 $o->get_opts();
3569
3570 my $dp = $o->DSNParser();
3571- $dp->prop('set-vars', $o->get('set-vars'));
3572+ $dp->prop('set-vars', $o->set_vars());
3573
3574 my $vars_from = $o->get('source-of-variables');
3575 # my $status_from = lc $o->get('source-of-status');
3576@@ -5766,10 +5850,21 @@
3577
3578 =item --set-vars
3579
3580-type: string; default: wait_timeout=10000
3581-
3582-Set these MySQL variables. Immediately after connecting to MySQL, this string
3583-will be appended to SET and executed.
3584+type: Array
3585+
3586+Set the MySQL variables in this comma-separated list of C<variable=value> pairs.
3587+
3588+By default, the tool sets:
3589+
3590+=for comment ignore-pt-internal-value
3591+MAGIC_set_vars
3592+
3593+ wait_timeout=10000
3594+
3595+Variables specified on the command line override these defaults. For
3596+example, specifying C<--set-vars wait_timeout=500> overrides the defaultvalue of C<10000>.
3597+
3598+The tool prints a warning and continues if a variable cannot be set.
3599
3600 =item --socket
3601
3602
3603=== modified file 'bin/pt-visual-explain'
3604--- bin/pt-visual-explain 2013-02-27 00:01:17 +0000
3605+++ bin/pt-visual-explain 2013-03-03 15:43:19 +0000
3606@@ -711,6 +711,7 @@
3607
3608 use List::Util qw(max);
3609 use Getopt::Long;
3610+use Data::Dumper;
3611
3612 my $POD_link_re = '[LC]<"?([^">]+)"?>';
3613
3614@@ -732,7 +733,6 @@
3615 'default' => 1,
3616 'cumulative' => 1,
3617 'negatable' => 1,
3618- 'value_is_optional' => 1,
3619 );
3620
3621 my $self = {
3622@@ -974,10 +974,9 @@
3623 $opt->{short} = undef;
3624 }
3625
3626- $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
3627- $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
3628- $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;
3629- $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
3630+ $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
3631+ $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
3632+ $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
3633
3634 $opt->{group} ||= 'default';
3635 $self->{groups}->{ $opt->{group} }->{$long} = 1;
3636@@ -1113,7 +1112,7 @@
3637 if ( $opt->{is_cumulative} ) {
3638 $opt->{value}++;
3639 }
3640- elsif ( !($opt->{optional_value} && !$val) ) {
3641+ else {
3642 $opt->{value} = $val;
3643 }
3644 $opt->{got} = 1;
3645@@ -1493,7 +1492,7 @@
3646 $desc .= ". Optional suffix s=seconds, m=minutes, h=hours, "
3647 . "d=days; if no suffix, $s is used.";
3648 }
3649- $desc = join("\n$rpad", grep { $_ } $desc =~ m/(.{0,$rcol})(?:\s+|$)/g);
3650+ $desc = join("\n$rpad", grep { $_ } $desc =~ m/(.{0,$rcol}(?!\W))(?:\s+|(?<=\W)|$)/g);
3651 $desc =~ s/ +$//mg;
3652 if ( $short ) {
3653 $usage .= sprintf(" --%-${maxs}s -%s %s\n", $long, $short, $desc);
3654@@ -1654,12 +1653,11 @@
3655 sub _parse_attribs {
3656 my ( $self, $option, $attribs ) = @_;
3657 my $types = $self->{types};
3658- my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
3659 return $option
3660 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
3661 . ($attribs->{'negatable'} ? '!' : '' )
3662 . ($attribs->{'cumulative'} ? '+' : '' )
3663- . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );
3664+ . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
3665 }
3666
3667 sub _parse_synopsis {
3668@@ -1697,6 +1695,45 @@
3669 );
3670 };
3671
3672+sub set_vars {
3673+ my ($self, $file) = @_;
3674+ $file ||= $self->{file} || __FILE__;
3675+
3676+ my %user_vars;
3677+ my $user_vars = $self->has('set-vars') ? $self->get('set-vars') : undef;
3678+ if ( $user_vars ) {
3679+ foreach my $var_val ( @$user_vars ) {
3680+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
3681+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
3682+ $user_vars{$var} = {
3683+ val => $val,
3684+ default => 0,
3685+ };
3686+ }
3687+ }
3688+
3689+ my %default_vars;
3690+ my $default_vars = $self->read_para_after($file, qr/MAGIC_set_vars/);
3691+ if ( $default_vars ) {
3692+ %default_vars = map {
3693+ my $var_val = $_;
3694+ my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/;
3695+ die "Invalid --set-vars value: $var_val\n" unless $var && $val;
3696+ $var => {
3697+ val => $val,
3698+ default => 1,
3699+ };
3700+ } split("\n", $default_vars);
3701+ }
3702+
3703+ my %vars = (
3704+ %default_vars, # first the tool's defaults
3705+ %user_vars, # then the user's which overwrite the defaults
3706+ );
3707+ PTDEBUG && _d('--set-vars:', Dumper(\%vars));
3708+ return \%vars;
3709+}
3710+
3711 sub _d {
3712 my ($package, undef, $line) = caller 0;
3713 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
3714@@ -1988,7 +2025,7 @@
3715
3716 if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) {
3717 $sql = qq{/*!40101 SET NAMES "$charset"*/};
3718- PTDEBUG && _d($dbh, ':', $sql);
3719+ PTDEBUG && _d($dbh, $sql);
3720 eval { $dbh->do($sql) };
3721 if ( $EVAL_ERROR ) {
3722 die "Error setting NAMES to $charset: $EVAL_ERROR";
3723@@ -2003,13 +2040,8 @@
3724 }
3725 }
3726
3727- if ( my $var = $self->prop('set-vars') ) {
3728- $sql = "SET $var";
3729- PTDEBUG && _d($dbh, ':', $sql);
3730- eval { $dbh->do($sql) };
3731- if ( $EVAL_ERROR ) {
3732- die "Error setting $var: $EVAL_ERROR";
3733- }
3734+ if ( my $vars = $self->prop('set-vars') ) {
3735+ $self->set_vars($dbh, $vars);
3736 }
3737
3738 $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1'
3739@@ -2084,6 +2116,55 @@
3740 return \%new_dsn;
3741 }
3742
3743+sub set_vars {
3744+ my ($self, $dbh, $vars) = @_;
3745+
3746+ foreach my $var ( sort keys %$vars ) {
3747+ my $val = $vars->{$var}->{val};
3748+
3749+ (my $quoted_var = $var) =~ s/_/\\_/;
3750+ my ($var_exists, $current_val);
3751+ eval {
3752+ ($var_exists, $current_val) = $dbh->selectrow_array(
3753+ "SHOW VARIABLES LIKE '$quoted_var'");
3754+ };
3755+ my $e = $EVAL_ERROR;
3756+ if ( $e ) {
3757+ PTDEBUG && _d($e);
3758+ }
3759+
3760+ if ( $vars->{$var}->{default} && !$var_exists ) {
3761+ PTDEBUG && _d('Not setting default var', $var,
3762+ 'because it does not exist');
3763+ next;
3764+ }
3765+
3766+ if ( $current_val && $current_val eq $val ) {
3767+ PTDEBUG && _d('Not setting var', $var, 'because its value',
3768+ 'is already', $val);
3769+ next;
3770+ }
3771+
3772+ my $sql = "SET SESSION $var=$val";
3773+ PTDEBUG && _d($dbh, $sql);
3774+ eval { $dbh->do($sql) };
3775+ if ( my $set_error = $EVAL_ERROR ) {
3776+ chomp($set_error);
3777+ $set_error =~ s/ at \S+ line \d+//;
3778+ my $msg = "Error setting $var: $set_error";
3779+ if ( $current_val ) {
3780+ $msg .= " The current value for $var is $current_val. "
3781+ . "If the variable is read only (not dynamic), specify "
3782+ . "--set-vars $var=$current_val to avoid this warning, "
3783+ . "else manually set the variable and restart MySQL.";
3784+ }
3785+ warn $msg . "\n\n";
3786+ }
3787+ }
3788+
3789+ return;
3790+}
3791+
3792 sub _d {
3793 my ($package, undef, $line) = caller 0;
3794 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
3795@@ -2329,7 +2410,7 @@
3796 $o->get_opts();
3797
3798 my $dp = $o->DSNParser();
3799- $dp->prop('set-vars', $o->get('set-vars'));
3800+ $dp->prop('set-vars', $o->set_vars());
3801
3802 $o->usage_or_errors();
3803
3804@@ -2966,10 +3047,21 @@
3805
3806 =item --set-vars
3807
3808-type: string; default: wait_timeout=10000
3809-
3810-Set these MySQL variables. Immediately after connecting to MySQL, this
3811-string will be appended to SET and executed.
3812+type: Array
3813+
3814+Set the MySQL variables in this comma-separated list of C<variable=value> pairs.
3815+
3816+By default, the tool sets:
3817+
3818+=for comment ignore-pt-internal-value
3819+MAGIC_set_vars
3820+
3821+ wait_timeout=10000
3822+
3823+Variables specified on the command line override these defaults. For
3824+example, specifying C<--set-vars wait_timeout=500> overrides the defaultvalue of C<10000>.
3825+
3826+The tool prints a warning and continues if a variable cannot be set.
3827
3828 =item --socket
3829
3830
3831=== modified file 'lib/DSNParser.pm'
3832--- lib/DSNParser.pm 2013-02-28 01:47:00 +0000
3833+++ lib/DSNParser.pm 2013-03-03 15:43:19 +0000
3834@@ -448,6 +448,8 @@
3835 sub set_vars {
3836 my ($self, $dbh, $vars) = @_;
3837
3838+ return unless $vars;
3839+
3840 foreach my $var ( sort keys %$vars ) {
3841 my $val = $vars->{$var}->{val};
3842
3843
3844=== modified file 't/lib/Cxn.t'
3845--- t/lib/Cxn.t 2013-02-26 23:34:48 +0000
3846+++ t/lib/Cxn.t 2013-03-03 15:43:19 +0000
3847@@ -29,10 +29,22 @@
3848 plan skip_all => 'Cannot connect to sandbox master';
3849 }
3850
3851-my $o = new OptionParser(description => 'Cxn');
3852+my $o = new OptionParser(
3853+ description => 'Cxn',
3854+ file => "$trunk/bin/pt-table-checksum",
3855+);
3856 $o->get_specs("$trunk/bin/pt-table-checksum");
3857 $o->get_opts();
3858-$dp->prop('set-vars', $o->get('set-vars'));
3859+
3860+# In 2.1, these tests did not set innodb_lock_wait_timeout because
3861+# it was not a --set-vars default but rather its own option handled
3862+# by/in the tool. In 2.2, the var is a --set-vars default, which
3863+# means it will cause a warning on 5.0 and 5.1, so we remoe the var
3864+# to remove the warning.
3865+my $set_vars = $o->set_vars();
3866+delete $set_vars->{innodb_lock_wait_timeout};
3867+delete $set_vars->{lock_wait_timeout};
3868+$dp->prop('set-vars', $set_vars);
3869
3870 sub make_cxn {
3871 my (%args) = @_;
3872
3873=== modified file 't/lib/DSNParser.t'
3874--- t/lib/DSNParser.t 2012-12-03 03:43:10 +0000
3875+++ t/lib/DSNParser.t 2013-03-03 15:43:19 +0000
3876@@ -439,7 +439,7 @@
3877 $dbh->disconnect();
3878
3879 $dp = new DSNParser(opts => $opts);
3880- $dp->prop('set-vars', 'wait_timeout=1000');
3881+ $dp->prop('set-vars', { wait_timeout => { val => 1000, default => 1}});
3882 $d = $dp->parse('h=127.0.0.1,P=12345,A=utf8,u=msandbox,p=msandbox');
3883 my $dbh2 = $dp->get_dbh($dp->get_cxn_params($d), {mysql_use_result=>1});
3884 sleep 2;
3885@@ -560,8 +560,14 @@
3886 "get_dbh dies with an unknown charset"
3887 );
3888
3889-$dp->prop('set-vars', "time_zoen='UTC'");
3890-($out, undef) = full_output(sub { $dp->get_dbh($dp->get_cxn_params($dsn), {}) });
3891+$dp->prop('set-vars', { time_zoen => { val => 'UTC' }});
3892+$out = output(
3893+ sub {
3894+ my $dbh = $dp->get_dbh($dp->get_cxn_params($dsn), {});
3895+ $dbh->disconnect();
3896+ },
3897+ stderr => 1,
3898+);
3899
3900 like(
3901 $out,
3902@@ -575,7 +581,7 @@
3903 # https://bugs.launchpad.net/percona-toolkit/+bug/1078887
3904 # #############################################################################
3905
3906-$dp->prop('set-vars', "sql_mode=ANSI_QUOTES");
3907+$dp->prop('set-vars', { sql_mode => { val=>'ANSI_QUOTES' }});
3908 my $sql_mode_dbh = $dp->get_dbh($dp->get_cxn_params($dsn), {});
3909
3910 my (undef, $sql_mode) = $sql_mode_dbh->selectrow_array(q{SHOW VARIABLES LIKE 'sql\_mode'});
3911@@ -628,4 +634,4 @@
3912 # Done.
3913 # #############################################################################
3914 done_testing;
3915-
3916\ No newline at end of file
3917+
3918
3919=== modified file 't/lib/KeySize.t'
3920--- t/lib/KeySize.t 2012-06-03 17:54:32 +0000
3921+++ t/lib/KeySize.t 2013-03-03 15:43:19 +0000
3922@@ -144,18 +144,18 @@
3923 '',
3924 'No error (issue 364)'
3925 );
3926-is(
3927+like(
3928 $ks->explain(),
3929- "extra: Using where; Using index
3930+ qr/^extra: Using where; Using index
3931 id: 1
3932 key: BASE_KID_ID
3933 key_len: 17
3934 possible_keys: BASE_KID_ID
3935 ref: NULL
3936-rows: 176
3937+rows: 17[1-9]
3938 select_type: SIMPLE
3939 table: issue_364
3940-type: index",
3941+type: index\Z/,
3942 'EXPLAIN plan (issue 364)'
3943 );
3944 is(
3945
3946=== modified file 't/lib/Percona/XtraDB/Cluster-no-PXC.t'
3947--- t/lib/Percona/XtraDB/Cluster-no-PXC.t 2012-11-21 20:04:42 +0000
3948+++ t/lib/Percona/XtraDB/Cluster-no-PXC.t 2013-03-03 15:43:19 +0000
3949@@ -43,10 +43,22 @@
3950 plan skip_all => 'Cannot connect to sandbox master';
3951 }
3952
3953-my $o = new OptionParser(description => 'Cxn');
3954+my $o = new OptionParser(
3955+ description => 'Cxn',
3956+ file => "$trunk/bin/pt-table-checksum",
3957+);
3958 $o->get_specs("$trunk/bin/pt-table-checksum");
3959 $o->get_opts();
3960-$dp->prop('set-vars', $o->get('set-vars'));
3961+
3962+# In 2.1, these tests did not set innodb_lock_wait_timeout because
3963+# it was not a --set-vars default but rather its own option handled
3964+# by/in the tool. In 2.2, the var is a --set-vars default, which
3965+# means it will cause a warning on 5.0 and 5.1, so we remoe the var
3966+# to remove the warning.
3967+my $set_vars = $o->set_vars();
3968+delete $set_vars->{innodb_lock_wait_timeout};
3969+delete $set_vars->{lock_wait_timeout};
3970+$dp->prop('set-vars', $set_vars);
3971
3972 sub make_cxn {
3973 my (%args) = @_;
3974
3975=== modified file 't/lib/Percona/XtraDB/Cluster.t'
3976--- t/lib/Percona/XtraDB/Cluster.t 2012-11-21 20:04:42 +0000
3977+++ t/lib/Percona/XtraDB/Cluster.t 2013-03-03 15:43:19 +0000
3978@@ -44,10 +44,22 @@
3979 plan skip_all => "PXC-only test";
3980 }
3981
3982-my $o = new OptionParser(description => 'Cxn');
3983+my $o = new OptionParser(
3984+ description => 'Cxn',
3985+ file => "$trunk/bin/pt-table-checksum",
3986+);
3987 $o->get_specs("$trunk/bin/pt-table-checksum");
3988 $o->get_opts();
3989-$dp->prop('set-vars', $o->get('set-vars'));
3990+
3991+# In 2.1, these tests did not set innodb_lock_wait_timeout because
3992+# it was not a --set-vars default but rather its own option handled
3993+# by/in the tool. In 2.2, the var is a --set-vars default, which
3994+# means it will cause a warning on 5.0 and 5.1, so we remoe the var
3995+# to remove the warning.
3996+my $set_vars = $o->set_vars();
3997+delete $set_vars->{innodb_lock_wait_timeout};
3998+delete $set_vars->{lock_wait_timeout};
3999+$dp->prop('set-vars', $set_vars);
4000
4001 sub make_cxn {
4002 my (%args) = @_;
4003
4004=== modified file 't/lib/ReplicaLagWaiter.t'
4005--- t/lib/ReplicaLagWaiter.t 2011-10-19 17:27:19 +0000
4006+++ t/lib/ReplicaLagWaiter.t 2013-03-03 15:43:19 +0000
4007@@ -41,10 +41,22 @@
4008 }
4009
4010 my $dp = new DSNParser(opts=>$dsn_opts);
4011-my $o = new OptionParser(description => 'Cxn');
4012+my $o = new OptionParser(
4013+ description => 'Cxn',
4014+ file => "$trunk/bin/pt-table-checksum",
4015+);
4016 $o->get_specs("$trunk/bin/pt-table-checksum");
4017 $o->get_opts();
4018-$dp->prop('set-vars', $o->get('set-vars'));
4019+
4020+# In 2.1, these tests did not set innodb_lock_wait_timeout because
4021+# it was not a --set-vars default but rather its own option handled
4022+# by/in the tool. In 2.2, the var is a --set-vars default, which
4023+# means it will cause a warning on 5.0 and 5.1, so we remoe the var
4024+# to remove the warning.
4025+my $set_vars = $o->set_vars();
4026+delete $set_vars->{innodb_lock_wait_timeout};
4027+delete $set_vars->{lock_wait_timeout};
4028+$dp->prop('set-vars', $set_vars);
4029
4030 my $r1 = new Cxn(dsn=>{n=>'slave1'}, dbh=>1, DSNParser=>$dp, OptionParser=>$o);
4031 my $r2 = new Cxn(dsn=>{n=>'slave2'}, dbh=>2, DSNParser=>$dp, OptionParser=>$o);
4032
4033=== modified file 't/pt-archiver/check_slave_lag.t'
4034--- t/pt-archiver/check_slave_lag.t 2013-02-12 16:23:45 +0000
4035+++ t/pt-archiver/check_slave_lag.t 2013-03-03 15:43:19 +0000
4036@@ -29,13 +29,10 @@
4037 elsif ( $sb->is_cluster_mode ) {
4038 plan skip_all => 'Not for PXC',
4039 }
4040-else {
4041- plan tests => 7;
4042+elsif ( $sandbox_version ge '5.6' ) {
4043+ plan skip_all => 'Slave trick does not work on MySQL 5.6+';
4044 }
4045
4046-$sb->wipe_clean($dbh);
4047-$sb->wipe_clean($dbh2);
4048-
4049 my $output;
4050 my $sql;
4051 my $cnf = "/tmp/12345/my.sandbox.cnf";
4052@@ -44,6 +41,7 @@
4053 # #############################################################################
4054 # Issue 758: Make mk-archiver wait for a slave
4055 # #############################################################################
4056+
4057 $sb->load_file('master', 't/pt-archiver/samples/issue_758.sql');
4058
4059 is_deeply(
4060@@ -52,11 +50,9 @@
4061 'Table not purged yet (issue 758)'
4062 );
4063
4064-# TODO: MySQL 5.6 is no longer tricked by this method.
4065-
4066 # Once this goes through repl, the slave will sleep causing
4067 # seconds behind master to increase > 0.
4068-system('/tmp/12345/use -e "insert into issue_758.t select sleep(2)"');
4069+system('/tmp/12345/use -e "insert into issue_758.t select sleep(3)"');
4070
4071 # Slave seems to be lagging now so the first row should get purged
4072 # immediately, then the script should wait about 2 seconds until
4073@@ -70,14 +66,11 @@
4074 'No changes on slave yet (issue 758)'
4075 );
4076
4077-TODO: {
4078- local $::TODO = "Timing-related test, may fail";
4079- is_deeply(
4080- $dbh->selectall_arrayref('select * from issue_758.t'),
4081- [[0],[2]],
4082- 'First row purged (issue 758)'
4083- );
4084-}
4085+is_deeply(
4086+ $dbh->selectall_arrayref('select * from issue_758.t'),
4087+ [[0],[2]],
4088+ 'First row purged (issue 758)'
4089+);
4090
4091 # The script it waiting for slave lag so no more rows should be purged yet.
4092 sleep 1;
4093@@ -106,6 +99,5 @@
4094 # Done.
4095 # #############################################################################
4096 $sb->wipe_clean($dbh);
4097-$sb->wipe_clean($dbh2);
4098 ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
4099-exit;
4100+done_testing;
4101
4102=== modified file 't/pt-fifo-split/pt-fifo-split.t'
4103--- t/pt-fifo-split/pt-fifo-split.t 2013-02-28 05:24:57 +0000
4104+++ t/pt-fifo-split/pt-fifo-split.t 2013-03-03 15:43:19 +0000
4105@@ -11,7 +11,8 @@
4106 use English qw(-no_match_vars);
4107 use Test::More;
4108 use File::Temp qw(tempfile);
4109-use IO::File;
4110+use Data::Dumper;
4111+use Time::HiRes qw(sleep);
4112
4113 use PerconaTest;
4114 require "$trunk/bin/pt-fifo-split";
4115@@ -27,24 +28,60 @@
4116 my ($fh, $filename) = tempfile("pt-fifo-split-data.XXXXXXXXX", OPEN => 1, TMPDIR => 1, UNLINK => 1);
4117 $fh->autoflush(1);
4118 print { $fh } "$_\n" for 1..9;
4119+close $fh;
4120+
4121+# WARNING: This can "deadlock" if not done correctly. First, for Perl open():
4122+# "When you open a fifo, the program will block until there's something on
4123+# the other end." So pt-fifo-split needs to mkfifo and open() it first,
4124+# then we open it. That's ok, but the problem is: after we read everything,
4125+# pt-fifo-split will close, rm, mkfifo, and open() it again. That can take
4126+# a few microseconds longer than the test closing and trying to read the
4127+# fifo again. In fact, the test can close, -p $fifo, and open() before
4128+# pt-fifo-split has done rm (unlink). When this happens, the test holds
4129+# open the fifo it just read, then pt-fifo-split creates a new fifo and
4130+# open()s it and blocks because there's no program on the other end--
4131+# because the test is reading a phantom fifo. Rather make the tool sleep
4132+# some arbitrary time before re-open()ing the fifo, we check for a new
4133+# file inode which ensures the fifo is new.
4134+sub read_fifo {
4135+ my ($n_reads) = @_;
4136+ my $last_inode = 0;
4137+ my @data;
4138+ for (1..$n_reads) {
4139+ PerconaTest::wait_until(sub {
4140+ my $inode;
4141+ (undef, $inode) = stat($fifo) if -p $fifo;
4142+ if ( $inode && $inode != $last_inode ) {
4143+ $last_inode = $inode;
4144+ return 1;
4145+ }
4146+ return;
4147+ });
4148+ open my $read_fifo_fh, '<', $fifo
4149+ or die "Cannot open $fifo: $OS_ERROR";
4150+ my $data = '';
4151+ while ( <$read_fifo_fh> ) {
4152+ $data .= $_;
4153+ }
4154+ close $read_fifo_fh;
4155+ push @data, $data;
4156+ }
4157+ return \@data;
4158+}
4159
4160 local $SIG{CHLD} = 'IGNORE';
4161 my $pid = fork();
4162 die "Cannot fork: $OS_ERROR" unless defined $pid;
4163 if ( !$pid ) {
4164 exec { $cmd } $cmd, qw(--lines 2), $filename;
4165- exit 1;
4166-}
4167-
4168-PerconaTest::wait_until(sub { -p $fifo });
4169-my @fifo;
4170-while (kill 0, $pid) {
4171- push @fifo, slurp_file($fifo) if -e $fifo;
4172-}
4173+}
4174+
4175+my $data = read_fifo(5);
4176+
4177 waitpid($pid, 0);
4178
4179 is_deeply(
4180- \@fifo,
4181+ $data,
4182 [
4183 "1\n2\n",
4184 "3\n4\n",
4185@@ -53,53 +90,53 @@
4186 "9\n",
4187 ],
4188 "--lines=2 with 9 lines works as expected"
4189-);
4190+) or diag(Dumper($data));
4191
4192 $pid = fork();
4193 die "Cannot fork: $OS_ERROR" unless defined $pid;
4194 if ( !$pid ) {
4195 exec { $cmd } $cmd, qw(--lines 15), $filename;
4196- exit 1;
4197-}
4198-PerconaTest::wait_until(sub { -p $fifo });
4199-
4200-@fifo = ();
4201-while (kill 0, $pid) {
4202- push @fifo, slurp_file($fifo) if -e $fifo;
4203-}
4204+}
4205+
4206+$data = read_fifo(1);
4207+
4208 waitpid($pid, 0);
4209
4210 is_deeply(
4211- \@fifo,
4212- [
4213- "1\n2\n3\n4\n5\n6\n7\n8\n9\n",
4214- ],
4215+ $data,
4216+ [ "1\n2\n3\n4\n5\n6\n7\n8\n9\n" ],
4217 "--lines=15 with 9 lines works as expected"
4218-);
4219-
4220-close $fh or die "Cannot close $filename: $OS_ERROR";
4221+) or diag(Dumper($data));
4222
4223 system("($cmd --lines 10000 $trunk/bin/pt-fifo-split > /dev/null 2>&1 < /dev/null)&");
4224-PerconaTest::wait_until(sub { -p $fifo });
4225-
4226-my $contents = slurp_file($fifo);
4227+
4228+$data = read_fifo(1);
4229+
4230 my $contents2 = load_file('bin/pt-fifo-split');
4231
4232-is($contents, $contents2, 'I read the file');
4233+is_deeply(
4234+ $data,
4235+ [ $contents2 ],
4236+ 'I read the file'
4237+);
4238
4239 system("($cmd $trunk/t/pt-fifo-split/samples/file_with_lines --offset 2 > /dev/null 2>&1 < /dev/null)&");
4240-PerconaTest::wait_until(sub { -p $fifo });
4241-
4242-$contents = slurp_file($fifo);
4243-
4244-is($contents, <<EOF
4245+
4246+$data = read_fifo(1);
4247+
4248+is_deeply(
4249+ $data,
4250+ [
4251+<<EOF
4252 2 hi
4253 3 there
4254 4 b
4255 5 c
4256 6 d
4257 EOF
4258-, 'Offset works');
4259+ ],
4260+ 'Offset works'
4261+);
4262
4263 # #########################################################################
4264 # Issue 391: Add --pid option to all scripts
4265
4266=== modified file 't/pt-online-schema-change/ansi_quotes.t'
4267--- t/pt-online-schema-change/ansi_quotes.t 2013-02-28 01:47:00 +0000
4268+++ t/pt-online-schema-change/ansi_quotes.t 2013-03-03 15:43:19 +0000
4269@@ -29,7 +29,8 @@
4270 }
4271
4272 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4273-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4274+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the
4275+# tool will die.
4276 my $master_dsn = 'h=127.1,P=12348,u=msandbox,p=msandbox';
4277 my @args = (qw(--set-vars innodb_lock_wait_timeout=3));
4278 my $output;
4279
4280=== modified file 't/pt-online-schema-change/bugs.t'
4281--- t/pt-online-schema-change/bugs.t 2013-02-28 01:47:00 +0000
4282+++ t/pt-online-schema-change/bugs.t 2013-03-03 15:43:19 +0000
4283@@ -30,7 +30,8 @@
4284 }
4285
4286 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4287-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4288+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the
4289+# tool will die.
4290 my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
4291 my @args = (qw(--set-vars innodb_lock_wait_timeout=3));
4292 my $output;
4293
4294=== modified file 't/pt-online-schema-change/check_alter.t'
4295--- t/pt-online-schema-change/check_alter.t 2013-02-28 01:47:00 +0000
4296+++ t/pt-online-schema-change/check_alter.t 2013-03-03 15:43:19 +0000
4297@@ -30,7 +30,8 @@
4298 }
4299
4300 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4301-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4302+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the
4303+# tool will die.
4304 my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
4305 my @args = (qw(--set-vars innodb_lock_wait_timeout=3));
4306 my $output;
4307
4308=== modified file 't/pt-online-schema-change/privs.t'
4309--- t/pt-online-schema-change/privs.t 2013-02-28 01:47:00 +0000
4310+++ t/pt-online-schema-change/privs.t 2013-03-03 15:43:19 +0000
4311@@ -40,7 +40,8 @@
4312 }
4313
4314 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4315-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4316+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the
4317+# tool will die.
4318 my $master_dsn = 'h=127.1,P=12345,p=msandbox';
4319 my @args = (qw(--set-vars innodb_lock_wait_timeout=3));
4320 my $row;
4321
4322=== modified file 't/pt-online-schema-change/pxc.t'
4323--- t/pt-online-schema-change/pxc.t 2013-02-28 01:47:00 +0000
4324+++ t/pt-online-schema-change/pxc.t 2013-03-03 15:43:19 +0000
4325@@ -46,8 +46,6 @@
4326 plan skip_all => "PXC tests";
4327 }
4328
4329-# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4330-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4331 my $node1_dsn = $sb->dsn_for('node1');
4332 my $output;
4333 my $exit;
4334
4335=== modified file 't/pt-online-schema-change/rename_columns.t'
4336--- t/pt-online-schema-change/rename_columns.t 2013-02-28 01:47:00 +0000
4337+++ t/pt-online-schema-change/rename_columns.t 2013-03-03 15:43:19 +0000
4338@@ -30,7 +30,8 @@
4339 }
4340
4341 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4342-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4343+# so we need to specify --set-vars innodb_lock_wait_timeout-3 else the
4344+# tool will die.
4345 my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
4346 my @args = (qw(--set-vars innodb_lock_wait_timeout=3));
4347 my $output;
4348
4349=== modified file 't/pt-table-checksum/basics.t'
4350--- t/pt-table-checksum/basics.t 2013-02-28 02:44:37 +0000
4351+++ t/pt-table-checksum/basics.t 2013-03-03 15:43:19 +0000
4352@@ -40,9 +40,9 @@
4353 }
4354
4355 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4356-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4357+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the tool will die.
4358 my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
4359-my @args = ($master_dsn, qw(--lock-wait-timeout 3));
4360+my @args = ($master_dsn, qw(--set-vars innodb_lock_wait_timeout=3));
4361 my $row;
4362 my $output;
4363 my $exit_status;
4364@@ -351,7 +351,7 @@
4365 $output = output(
4366 sub { $exit_status = pt_table_checksum::main(
4367 qw(--user msandbox --pass msandbox),
4368- qw(-S /tmp/12345/mysql_sandbox12345.sock --lock-wait-timeout 3)) },
4369+ qw(-S /tmp/12345/mysql_sandbox12345.sock --set-vars innodb_lock_wait_timeout=3)) },
4370 stderr => 1,
4371 );
4372
4373
4374=== modified file 't/pt-table-checksum/bugs.t'
4375--- t/pt-table-checksum/bugs.t 2013-02-19 20:01:58 +0000
4376+++ t/pt-table-checksum/bugs.t 2013-03-03 15:43:19 +0000
4377@@ -40,9 +40,9 @@
4378 }
4379
4380 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4381-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4382+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the tool will die.
4383 my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
4384-my @args = ($master_dsn, qw(--lock-wait-timeout 3));
4385+my @args = ($master_dsn, qw(--set-vars innodb_lock_wait_timeout=3));
4386 my $output;
4387 my $exit_status;
4388 my $sample = "t/pt-table-checksum/samples/";
4389
4390=== modified file 't/pt-table-checksum/char_chunking.t'
4391--- t/pt-table-checksum/char_chunking.t 2013-02-18 20:54:25 +0000
4392+++ t/pt-table-checksum/char_chunking.t 2013-03-03 15:43:19 +0000
4393@@ -27,10 +27,10 @@
4394 }
4395
4396 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4397-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4398+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the tool will die.
4399 # And --max-load "" prevents waiting for status variables.
4400 my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
4401-my @args = ($master_dsn, qw(--lock-wait-timeout 3), '--max-load', '');
4402+my @args = ($master_dsn, qw(--set-vars innodb_lock_wait_timeout=3), '--max-load', '');
4403
4404 $sb->create_dbs($master_dbh, ['test']);
4405 $sb->load_file('master', "t/lib/samples/char-chunking/ascii.sql", 'test');
4406
4407=== modified file 't/pt-table-checksum/chunk_index.t'
4408--- t/pt-table-checksum/chunk_index.t 2012-11-21 16:58:40 +0000
4409+++ t/pt-table-checksum/chunk_index.t 2013-03-03 15:43:19 +0000
4410@@ -27,10 +27,10 @@
4411 }
4412
4413 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4414-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4415+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the tool will die.
4416 # And --max-load "" prevents waiting for status variables.
4417 my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
4418-my @args = ($master_dsn, qw(--lock-wait-timeout 3 --explain --chunk-size 3), '--max-load', '');
4419+my @args = ($master_dsn, qw(--set-vars innodb_lock_wait_timeout=3 --explain --chunk-size 3), '--max-load', '');
4420 my $output;
4421 my $out = "t/pt-table-checksum/samples/";
4422
4423@@ -110,7 +110,7 @@
4424 $output = output(sub {
4425 $exit_status = pt_table_checksum::main(
4426 $master_dsn, '--max-load', '',
4427- qw(--lock-wait-timeout 3 --chunk-size 5 -t ALL_UC.T)
4428+ qw(--set-vars innodb_lock_wait_timeout=3 --chunk-size 5 -t ALL_UC.T)
4429 ) },
4430 stderr => 1,
4431 );
4432@@ -164,7 +164,7 @@
4433 $output = output(sub {
4434 $exit_status = pt_table_checksum::main(
4435 $master_dsn, '--max-load', '',
4436- qw(--lock-wait-timeout 3 --chunk-size 10 -t bad_plan.t)
4437+ qw(--set-vars innodb_lock_wait_timeout=3 --chunk-size 10 -t bad_plan.t)
4438 ) },
4439 stderr => 1,
4440 );
4441@@ -190,7 +190,7 @@
4442 sub {
4443 pt_table_checksum::main(
4444 $master_dsn, '--max-load', '',
4445- qw(--lock-wait-timeout 3 --chunk-size 5000 -t sakila.rental),
4446+ qw(--set-vars innodb_lock_wait_timeout=3 --chunk-size 5000 -t sakila.rental),
4447 qw(--chunk-index rental_date --chunk-index-columns 2),
4448 qw(--explain --explain));
4449 },
4450@@ -203,7 +203,7 @@
4451 sub {
4452 $exit_status = pt_table_checksum::main(
4453 $master_dsn, '--max-load', '',
4454- qw(--lock-wait-timeout 3 --chunk-size 1000 -t sakila.film_actor),
4455+ qw(--set-vars innodb_lock_wait_timeout=3 --chunk-size 1000 -t sakila.film_actor),
4456 qw(--chunk-index PRIMARY --chunk-index-columns 9),
4457 );
4458 },
4459@@ -220,7 +220,7 @@
4460 sub {
4461 $exit_status = pt_table_checksum::main(
4462 $master_dsn, '--max-load', '',
4463- qw(--lock-wait-timeout 3 --chunk-size 1000 -t sakila.film_actor),
4464+ qw(--set-vars innodb_lock_wait_timeout=3 --chunk-size 1000 -t sakila.film_actor),
4465 qw(--chunk-index-columns 1 --chunk-size-limit 3),
4466 );
4467 },
4468
4469=== modified file 't/pt-table-checksum/chunk_size.t'
4470--- t/pt-table-checksum/chunk_size.t 2012-11-21 16:58:40 +0000
4471+++ t/pt-table-checksum/chunk_size.t 2013-03-03 15:43:19 +0000
4472@@ -28,10 +28,10 @@
4473 }
4474
4475 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4476-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4477+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the tool will die.
4478 # And --max-load "" prevents waiting for status variables.
4479 my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
4480-my @args = ($master_dsn, qw(--lock-wait-timeout 3), '--max-load', '');
4481+my @args = ($master_dsn, qw(--set-vars innodb_lock_wait_timeout=3), '--max-load', '');
4482
4483 my $row;
4484 my $output;
4485
4486=== modified file 't/pt-table-checksum/create_replicate_table.t'
4487--- t/pt-table-checksum/create_replicate_table.t 2012-11-21 16:58:40 +0000
4488+++ t/pt-table-checksum/create_replicate_table.t 2013-03-03 15:43:19 +0000
4489@@ -31,10 +31,10 @@
4490 }
4491
4492 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4493-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4494+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the tool will die.
4495 # And --max-load "" prevents waiting for status variables.
4496 my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
4497-my @args = ($master_dsn, qw(--lock-wait-timeout 3), '--max-load', '');
4498+my @args = ($master_dsn, qw(--set-vars innodb_lock_wait_timeout=3), '--max-load', '');
4499
4500 my $output;
4501 my $row;
4502
4503=== modified file 't/pt-table-checksum/error_handling.t'
4504--- t/pt-table-checksum/error_handling.t 2013-02-19 20:01:58 +0000
4505+++ t/pt-table-checksum/error_handling.t 2013-03-03 15:43:19 +0000
4506@@ -30,10 +30,10 @@
4507 }
4508
4509 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4510-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4511+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the tool will die.
4512 # And --max-load "" prevents waiting for status variables.
4513 my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
4514-my @args = ($master_dsn, qw(--lock-wait-timeout 3), '--max-load', '');
4515+my @args = ($master_dsn, qw(--set-vars innodb_lock_wait_timeout=3), '--max-load', '');
4516 my $output;
4517 my $exit_status;
4518
4519@@ -189,7 +189,7 @@
4520 $output = output(
4521 sub { $exit_status = pt_table_checksum::main(
4522 "h=127.1,u=ro_checksum_user,p=msandbox,P=12345",
4523- qw(--lock-wait-timeout 3 -t mysql.user)) },
4524+ qw(--set-vars innodb_lock_wait_timeout=3 -t mysql.user)) },
4525 stderr => 1,
4526 );
4527
4528
4529=== modified file 't/pt-table-checksum/filters.t'
4530--- t/pt-table-checksum/filters.t 2012-11-21 16:58:40 +0000
4531+++ t/pt-table-checksum/filters.t 2013-03-03 15:43:19 +0000
4532@@ -28,10 +28,10 @@
4533 }
4534
4535 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4536-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4537+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the tool will die.
4538 # And --max-load "" prevents waiting for status variables.
4539 my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
4540-my @args = ($master_dsn, qw(--lock-wait-timeout 3), '--max-load', '');
4541+my @args = ($master_dsn, qw(--set-vars innodb_lock_wait_timeout=3), '--max-load', '');
4542
4543
4544 # ############################################################################
4545
4546=== modified file 't/pt-table-checksum/float_precision.t'
4547--- t/pt-table-checksum/float_precision.t 2012-11-21 16:58:40 +0000
4548+++ t/pt-table-checksum/float_precision.t 2013-03-03 15:43:19 +0000
4549@@ -27,10 +27,10 @@
4550 }
4551
4552 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4553-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4554+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the tool will die.
4555 # And --max-load "" prevents waiting for status variables.
4556 my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
4557-my @args = ($master_dsn, qw(--lock-wait-timeout 3), '--max-load', '');
4558+my @args = ($master_dsn, qw(--set-vars innodb_lock_wait_timeout=3), '--max-load', '');
4559 my $output;
4560
4561 $sb->load_file('master', "t/pt-table-checksum/samples/float_precision.sql");
4562
4563=== modified file 't/pt-table-checksum/fnv_64.t'
4564--- t/pt-table-checksum/fnv_64.t 2012-11-21 16:58:40 +0000
4565+++ t/pt-table-checksum/fnv_64.t 2013-03-03 15:43:19 +0000
4566@@ -24,10 +24,10 @@
4567 }
4568
4569 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4570-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4571+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the tool will die.
4572 # And --max-load "" prevents waiting for status variables.
4573 my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
4574-my @args = ($master_dsn, qw(--lock-wait-timeout 3), '--max-load', '');
4575+my @args = ($master_dsn, qw(--set-vars innodb_lock_wait_timeout=3), '--max-load', '');
4576 my $sample = "t/pt-table-checksum/samples/";
4577 my $row;
4578 my $output;
4579
4580=== modified file 't/pt-table-checksum/ignore_columns.t'
4581--- t/pt-table-checksum/ignore_columns.t 2012-11-21 16:58:40 +0000
4582+++ t/pt-table-checksum/ignore_columns.t 2013-03-03 15:43:19 +0000
4583@@ -31,10 +31,10 @@
4584 }
4585
4586 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4587-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4588+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the tool will die.
4589 # And --max-load "" prevents waiting for status variables.
4590 my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
4591-my @args = ($master_dsn, qw(--lock-wait-timeout 3), '--max-load', '');
4592+my @args = ($master_dsn, qw(--set-vars innodb_lock_wait_timeout=3), '--max-load', '');
4593 my $output;
4594
4595 $sb->create_dbs($master_dbh, [qw(test)]);
4596
4597=== modified file 't/pt-table-checksum/issue_388.t'
4598--- t/pt-table-checksum/issue_388.t 2012-12-14 19:14:12 +0000
4599+++ t/pt-table-checksum/issue_388.t 2013-03-03 15:43:19 +0000
4600@@ -27,10 +27,10 @@
4601 }
4602
4603 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4604-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4605+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the tool will die.
4606 # And --max-load "" prevents waiting for status variables.
4607 my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
4608-my @args = ($master_dsn, qw(--lock-wait-timeout 3), '--max-load', '');
4609+my @args = ($master_dsn, qw(--set-vars innodb_lock_wait_timeout=3), '--max-load', '');
4610 my $output;
4611
4612 # #############################################################################
4613
4614=== modified file 't/pt-table-checksum/issue_47.t'
4615--- t/pt-table-checksum/issue_47.t 2012-11-21 16:58:40 +0000
4616+++ t/pt-table-checksum/issue_47.t 2013-03-03 15:43:19 +0000
4617@@ -27,10 +27,10 @@
4618 }
4619
4620 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4621-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4622+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the tool will die.
4623 # And --max-load "" prevents waiting for status variables.
4624 my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
4625-my @args = ($master_dsn, qw(--lock-wait-timeout 3), '--max-load', '');
4626+my @args = ($master_dsn, qw(--set-vars innodb_lock_wait_timeout=3), '--max-load', '');
4627 my $output;
4628 my $row;
4629
4630
4631=== modified file 't/pt-table-checksum/issue_602.t'
4632--- t/pt-table-checksum/issue_602.t 2012-11-21 16:58:40 +0000
4633+++ t/pt-table-checksum/issue_602.t 2013-03-03 15:43:19 +0000
4634@@ -27,10 +27,10 @@
4635 }
4636
4637 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4638-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4639+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the tool will die.
4640 # And --max-load "" prevents waiting for status variables.
4641 my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
4642-my @args = ($master_dsn, qw(--lock-wait-timeout 3), '--max-load', '');
4643+my @args = ($master_dsn, qw(--set-vars innodb_lock_wait_timeout=3), '--max-load', '');
4644 my $output;
4645
4646 $sb->load_file('master', 't/pt-table-checksum/samples/issue_602.sql');
4647
4648=== modified file 't/pt-table-checksum/option_sanity.t'
4649--- t/pt-table-checksum/option_sanity.t 2012-11-21 16:58:40 +0000
4650+++ t/pt-table-checksum/option_sanity.t 2013-03-03 15:43:19 +0000
4651@@ -57,11 +57,11 @@
4652 "Default --host=localhost"
4653 );
4654
4655-like(
4656- $output,
4657- qr/^ --lock-wait-timeout\s+1$/m,
4658- "Default --lock-wait-timeout=1"
4659-);
4660+#like(
4661+# $output,
4662+# qr/^ --lock-wait-timeout\s+1$/m,
4663+# "Default --lock-wait-timeout=1"
4664+#);
4665
4666 like(
4667 $output,
4668
4669=== modified file 't/pt-table-checksum/privs.t'
4670--- t/pt-table-checksum/privs.t 2012-11-21 16:58:40 +0000
4671+++ t/pt-table-checksum/privs.t 2013-03-03 15:43:19 +0000
4672@@ -41,9 +41,9 @@
4673 }
4674
4675 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4676-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4677+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the tool will die.
4678 my $master_dsn = 'h=127.1,P=12345';
4679-my @args = (qw(--lock-wait-timeout 3));
4680+my @args = (qw(--set-vars innodb_lock_wait_timeout=3));
4681 my $row;
4682 my $output;
4683 my $exit_status;
4684
4685=== modified file 't/pt-table-checksum/progress.t'
4686--- t/pt-table-checksum/progress.t 2012-11-21 16:58:40 +0000
4687+++ t/pt-table-checksum/progress.t 2013-03-03 15:43:19 +0000
4688@@ -41,13 +41,13 @@
4689 }
4690
4691 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4692-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4693+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the tool will die.
4694 # And --max-load "" prevents waiting for status variables. Setting
4695 # --chunk-size may help prevent the tool from running too fast and finishing
4696 # before the TEST_WISHLIST job below finishes. (Or, it might just make things
4697 # worse. This is a random stab in the dark. There is a problem either way.)
4698 my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
4699-my @args = ($master_dsn, qw(--lock-wait-timeout 3),
4700+my @args = ($master_dsn, qw(--set-vars innodb_lock_wait_timeout=3),
4701 '--progress', 'time,1', '--max-load', '', '--chunk-size', '500');
4702 my $output;
4703 my $row;
4704
4705=== modified file 't/pt-table-checksum/pxc.t'
4706--- t/pt-table-checksum/pxc.t 2012-11-30 18:14:06 +0000
4707+++ t/pt-table-checksum/pxc.t 2013-03-03 15:43:19 +0000
4708@@ -42,9 +42,9 @@
4709 }
4710
4711 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4712-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4713+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the tool will die.
4714 my $node1_dsn = $sb->dsn_for('node1');
4715-my @args = ($node1_dsn, qw(--lock-wait-timeout 3));
4716+my @args = ($node1_dsn, qw(--set-vars innodb_lock_wait_timeout=3));
4717 my $output;
4718 my $exit_status;
4719 my $sample = "t/pt-table-checksum/samples/";
4720
4721=== modified file 't/pt-table-checksum/replication_filters.t'
4722--- t/pt-table-checksum/replication_filters.t 2013-03-02 01:31:31 +0000
4723+++ t/pt-table-checksum/replication_filters.t 2013-03-03 15:43:19 +0000
4724@@ -48,10 +48,10 @@
4725 }
4726
4727 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4728-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4729+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the tool will die.
4730 # And --max-load "" prevents waiting for status variables.
4731 my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
4732-my @args = ($master_dsn, qw(--lock-wait-timeout 3), '--max-load', '');
4733+my @args = ($master_dsn, qw(--set-vars innodb_lock_wait_timeout=3), '--max-load', '');
4734 my $output;
4735 my $row;
4736
4737
4738=== modified file 't/pt-table-checksum/resume.t'
4739--- t/pt-table-checksum/resume.t 2012-11-21 16:58:40 +0000
4740+++ t/pt-table-checksum/resume.t 2013-03-03 15:43:19 +0000
4741@@ -31,10 +31,10 @@
4742 }
4743
4744 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4745-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4746+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the tool will die.
4747 # And --max-load "" prevents waiting for status variables.
4748 my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
4749-my @args = ($master_dsn, qw(--lock-wait-timeout 3), '--max-load', '');
4750+my @args = ($master_dsn, qw(--set-vars innodb_lock_wait_timeout=3), '--max-load', '');
4751 my $row;
4752 my $output;
4753
4754
4755=== modified file 't/pt-table-checksum/run_time.t'
4756--- t/pt-table-checksum/run_time.t 2012-12-20 23:18:15 +0000
4757+++ t/pt-table-checksum/run_time.t 2013-03-03 15:43:19 +0000
4758@@ -29,10 +29,10 @@
4759 }
4760
4761 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4762-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4763+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the tool will die.
4764 # And --max-load "" prevents waiting for status variables.
4765 my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
4766-my @args = ($master_dsn, qw(--lock-wait-timeout 3), '--max-load', '');
4767+my @args = ($master_dsn, qw(--set-vars innodb_lock_wait_timeout=3), '--max-load', '');
4768 my $output;
4769 my $exit_status;
4770
4771
4772=== modified file 't/pt-table-checksum/skip_innodb.t'
4773--- t/pt-table-checksum/skip_innodb.t 2013-02-19 20:01:58 +0000
4774+++ t/pt-table-checksum/skip_innodb.t 2013-03-03 15:43:19 +0000
4775@@ -39,10 +39,10 @@
4776 }
4777
4778 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4779-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4780+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the tool will die.
4781 # And --max-load "" prevents waiting for status variables.
4782 my $master_dsn = 'h=127.1,P=12348,u=msandbox,p=msandbox';
4783-my @args = ($master_dsn, qw(--lock-wait-timeout 3), '--max-load', '');
4784+my @args = ($master_dsn, qw(--set-vars innodb_lock_wait_timeout=3), '--max-load', '');
4785 my $output;
4786 my $retval;
4787
4788
4789=== modified file 't/pt-table-checksum/standard_options.t'
4790--- t/pt-table-checksum/standard_options.t 2012-11-21 16:58:40 +0000
4791+++ t/pt-table-checksum/standard_options.t 2013-03-03 15:43:19 +0000
4792@@ -31,9 +31,9 @@
4793 }
4794
4795 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4796-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4797+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the tool will die.
4798 # And --max-load "" prevents waiting for status variables.
4799-my @args = (qw(--lock-wait-timeout 3 --explain --tables sakila.country),
4800+my @args = (qw(--set-vars innodb_lock_wait_timeout=3 --explain --tables sakila.country),
4801 '--max-load', '');
4802 my $cnf = "/tmp/12345/my.sandbox.cnf";
4803 my $pid_file = "/tmp/mk-table-checksum-test.pid";
4804
4805=== modified file 't/pt-table-checksum/throttle.t'
4806--- t/pt-table-checksum/throttle.t 2012-11-21 16:58:40 +0000
4807+++ t/pt-table-checksum/throttle.t 2013-03-03 15:43:19 +0000
4808@@ -41,10 +41,10 @@
4809 }
4810
4811 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
4812-# so we need to specify --lock-wait-timeout=3 else the tool will die.
4813+# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the tool will die.
4814 # And --max-load "" prevents waiting for status variables.
4815 my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
4816-my @args = ($master_dsn, qw(--lock-wait-timeout 3), '--max-load', '',
4817+my @args = ($master_dsn, qw(--set-vars innodb_lock_wait_timeout=3), '--max-load', '',
4818 '--progress', 'time,1');
4819 my $output;
4820 my $row;
4821
4822=== modified file 't/pt-table-sync/basics.t'
4823--- t/pt-table-sync/basics.t 2013-02-19 20:01:58 +0000
4824+++ t/pt-table-sync/basics.t 2013-03-03 15:43:19 +0000
4825@@ -172,7 +172,7 @@
4826
4827 # pt-table-checksum waits for all checksums to replicate to all slaves,
4828 # so no need to call $sb->wait_for_slaves() after this.
4829-`$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox --max-load '' --lock-wait 3 --chunk-size 50 --chunk-index idx_actor_last_name -t sakila.actor --quiet`;
4830+`$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox --max-load '' --set-vars innodb_lock_wait_timeout=3 --chunk-size 50 --chunk-index idx_actor_last_name -t sakila.actor --quiet`;
4831
4832 $slave_dbh->do("update percona.checksums set this_crc='' where db='sakila' and tbl='actor' and chunk=3");
4833 $slave_dbh->do("update sakila.actor set last_name='' where actor_id=30");
4834@@ -192,7 +192,7 @@
4835 "--replicate with char index col (bug 911996)"
4836 );
4837
4838-$output = `$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox --max-load '' --lock-wait 3 --chunk-size 50 --chunk-index idx_actor_last_name -t sakila.actor`;
4839+$output = `$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox --max-load '' --set-vars innodb_lock_wait_timeout=3 --chunk-size 50 --chunk-index idx_actor_last_name -t sakila.actor`;
4840 is(
4841 PerconaTest::count_checksum_results($output, 'diffs'),
4842 0,
4843@@ -205,7 +205,7 @@
4844
4845 # pt-table-checksum waits for all checksums to replicate to all slaves,
4846 # so no need to call $sb->wait_for_slaves() after this.
4847-`$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox --max-load '' --lock-wait 3 --chunk-size 2 -t test.t --quiet`;
4848+`$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox --max-load '' --set-vars innodb_lock_wait_timeout=3 --chunk-size 2 -t test.t --quiet`;
4849
4850 $output = output(
4851 sub {
4852
4853=== modified file 't/pt-table-sync/bugs.t'
4854--- t/pt-table-sync/bugs.t 2012-06-07 16:43:18 +0000
4855+++ t/pt-table-sync/bugs.t 2013-03-03 15:43:19 +0000
4856@@ -46,7 +46,7 @@
4857 $slave_dbh->do("DELETE FROM test.aaa WHERE STOP_ARCHIVE IN (5,6,7)");
4858 $slave_dbh->do("UPDATE test.zzz SET c='x' WHERE id IN (44,45,46)");
4859
4860-$output = `$trunk/bin/pt-table-checksum $master_dsn --lock-wait-timeout 3 --max-load '' -d test --chunk-size 10 2>&1`;
4861+$output = `$trunk/bin/pt-table-checksum $master_dsn --set-vars innodb_lock_wait_timeout=3 --max-load '' -d test --chunk-size 10 2>&1`;
4862
4863 is(
4864 PerconaTest::count_checksum_results($output, 'diffs'),
4865@@ -112,7 +112,7 @@
4866 $slave_dbh->do("DELETE FROM test.aaa WHERE STOP_ARCHIVE IN (5,6,7)");
4867 $slave_dbh->do("UPDATE test.zzz SET c='x' WHERE id IN (44,45,46)");
4868
4869-$output = `$trunk/bin/pt-table-checksum $master_dsn --lock-wait-timeout 3 --max-load '' -d test --chunk-size 10 2>&1`;
4870+$output = `$trunk/bin/pt-table-checksum $master_dsn --set-vars innodb_lock_wait_timeout=3 --max-load '' -d test --chunk-size 10 2>&1`;
4871
4872 is(
4873 PerconaTest::count_checksum_results($output, 'diffs'),
4874
4875=== modified file 't/pt-table-sync/filters.t'
4876--- t/pt-table-sync/filters.t 2012-07-11 18:21:47 +0000
4877+++ t/pt-table-sync/filters.t 2013-03-03 15:43:19 +0000
4878@@ -110,7 +110,7 @@
4879 # Checksum the filter tables.
4880 $master_dbh->do("DROP DATABASE IF EXISTS percona");
4881 $sb->wait_for_slaves();
4882-diag(`$trunk/bin/pt-table-checksum $master_dsn -d d1,d2,d3 --chunk-size 100 --quiet --lock-wait-timeout 3 --max-load ''`);
4883+diag(`$trunk/bin/pt-table-checksum $master_dsn -d d1,d2,d3 --chunk-size 100 --quiet --set-vars innodb_lock_wait_timeout=3 --max-load ''`);
4884
4885 my $rows = $master_dbh->selectall_arrayref("SELECT CONCAT(db, '.', tbl) FROM percona.checksums ORDER BY db, tbl");
4886 is_deeply(
4887@@ -180,7 +180,7 @@
4888 $slave_dbh->do("INSERT INTO test.empty_it VALUES (null,11,11,'eleven')");
4889
4890 # Create the checksums.
4891-diag(`$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox -d test --quiet --quiet --lock-wait-timeout 3 --max-load ''`);
4892+diag(`$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox -d test --quiet --quiet --set-vars innodb_lock_wait_timeout=3 --max-load ''`);
4893
4894 # Make sure all the tables were checksummed.
4895 $rows = $master_dbh->selectall_arrayref("SELECT DISTINCT db, tbl FROM percona.checksums ORDER BY db, tbl");
4896
4897=== modified file 't/pt-table-sync/issue_560.t'
4898--- t/pt-table-sync/issue_560.t 2012-06-07 14:25:44 +0000
4899+++ t/pt-table-sync/issue_560.t 2013-03-03 15:43:19 +0000
4900@@ -40,7 +40,7 @@
4901 $slave_dbh->do('UPDATE issue_560.buddy_list SET buddy_id=0 WHERE player_id IN (333,334)');
4902 $slave_dbh->do('UPDATE issue_560.buddy_list SET buddy_id=0 WHERE player_id=486');
4903
4904-$output = `$trunk/bin/pt-table-checksum --replicate issue_560.checksum h=127.1,P=12345,u=msandbox,p=msandbox -d issue_560 --chunk-size 50 --lock-wait-time 3`;
4905+$output = `$trunk/bin/pt-table-checksum --replicate issue_560.checksum h=127.1,P=12345,u=msandbox,p=msandbox -d issue_560 --chunk-size 50 --set-vars innodb_lock_wait_timeout=3`;
4906
4907 is(
4908 PerconaTest::count_checksum_results($output, 'diffs'),
4909
4910=== modified file 't/pt-table-sync/issue_627.t'
4911--- t/pt-table-sync/issue_627.t 2012-06-03 17:54:32 +0000
4912+++ t/pt-table-sync/issue_627.t 2013-03-03 15:43:19 +0000
4913@@ -48,7 +48,7 @@
4914 $slave_dbh->do('UPDATE issue_375.t SET foo="zz" WHERE id=100');
4915
4916 # Checksum and replicate.
4917-diag(`$trunk/bin/pt-table-checksum --create-replicate-table --replicate issue_375.checksum h=127.1,P=12345,u=msandbox,p=msandbox -d issue_375 -t t --lock-wait-time 3 > /dev/null`);
4918+diag(`$trunk/bin/pt-table-checksum --create-replicate-table --replicate issue_375.checksum h=127.1,P=12345,u=msandbox,p=msandbox -d issue_375 -t t --set-vars innodb_lock_wait_timeout=3 > /dev/null`);
4919
4920 # And now sync using the replicated checksum results/differences.
4921 $output = output(
4922
4923=== modified file 't/pt-table-sync/issue_996.t'
4924--- t/pt-table-sync/issue_996.t 2012-06-03 17:54:32 +0000
4925+++ t/pt-table-sync/issue_996.t 2013-03-03 15:43:19 +0000
4926@@ -33,7 +33,7 @@
4927 my $output;
4928 my @args = ('--sync-to-master', 'h=127.1,P=12346,u=msandbox,p=msandbox',
4929 qw(-d issue_375 --replicate issue_375.checksums --print));
4930-my $pt_table_checksum = "$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox -d issue_375 --chunk-size 20 --chunk-size-limit 0 --lock-wait-time 3";
4931+my $pt_table_checksum = "$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox -d issue_375 --chunk-size 20 --chunk-size-limit 0 --set-vars innodb_lock_wait_timeout=3";
4932
4933 # #############################################################################
4934 # Issue 996: might not chunk inside of mk-table-checksum's boundaries
4935
4936=== modified file 't/pt-table-sync/triggers.t'
4937--- t/pt-table-sync/triggers.t 2012-07-11 19:46:54 +0000
4938+++ t/pt-table-sync/triggers.t 2013-03-03 15:43:19 +0000
4939@@ -44,7 +44,7 @@
4940 $sb->load_file('master', 't/pt-table-sync/samples/issue_37.sql');
4941 $sb->use('master', '-e "SET SQL_LOG_BIN=0; INSERT INTO test.issue_37 VALUES (1), (2);"');
4942
4943-`$trunk/bin/pt-table-checksum h=127.0.0.1,P=12345,u=msandbox,p=msandbox --replicate test.checksum -d test --lock-wait-time 3 2>&1 > /dev/null`;
4944+`$trunk/bin/pt-table-checksum h=127.0.0.1,P=12345,u=msandbox,p=msandbox --replicate test.checksum -d test --set-vars innodb_lock_wait_timeout=3 2>&1 > /dev/null`;
4945
4946 $output = `$trunk/bin/pt-table-sync --no-check-slave --execute u=msandbox,p=msandbox,h=127.0.0.1,P=12345,D=test,t=issue_37 h=127.1,P=12346 2>&1`;
4947 like($output,
4948@@ -103,7 +103,7 @@
4949 $slave_dbh->do('DELETE FROM db2.t1 WHERE i > 4');
4950
4951 # Replicate checksum of db2.t1.
4952-$output = `$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox --replicate db1.checksum --create-replicate-table --databases db1,db2 --lock-wait-time 3 2>&1`;
4953+$output = `$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox --replicate db1.checksum --create-replicate-table --databases db1,db2 --set-vars innodb_lock_wait_timeout=3 2>&1`;
4954 like(
4955 $output,
4956 qr/db2.t1/,

Subscribers

People subscribed via source and target branches

to all changes: