Merge lp:~percona-toolkit-dev/percona-toolkit/OptionParser-remove-optional_value into lp:percona-toolkit/2.1

Proposed by Brian Fraser
Status: Merged
Approved by: Daniel Nichter
Approved revision: 439
Merged at revision: 454
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/OptionParser-remove-optional_value
Merge into: lp:percona-toolkit/2.1
Diff against target: 4383 lines (+1264/-677)
31 files modified
bin/pt-archiver (+62/-29)
bin/pt-config-diff (+58/-28)
bin/pt-deadlock-logger (+62/-29)
bin/pt-diskstats (+57/-27)
bin/pt-duplicate-key-checker (+59/-29)
bin/pt-fifo-split (+5/-8)
bin/pt-find (+59/-28)
bin/pt-fingerprint (+5/-8)
bin/pt-fk-error-logger (+62/-29)
bin/pt-heartbeat (+61/-27)
bin/pt-index-usage (+62/-29)
bin/pt-kill (+59/-28)
bin/pt-log-player (+5/-8)
bin/pt-online-schema-change (+60/-29)
bin/pt-query-advisor (+62/-29)
bin/pt-query-digest (+63/-30)
bin/pt-show-grants (+5/-8)
bin/pt-slave-delay (+62/-29)
bin/pt-slave-find (+5/-8)
bin/pt-slave-restart (+59/-28)
bin/pt-table-checksum (+62/-29)
bin/pt-table-sync (+61/-27)
bin/pt-tcp-model (+5/-8)
bin/pt-trend (+5/-8)
bin/pt-upgrade (+59/-28)
bin/pt-variable-advisor (+59/-28)
lib/OptionParser.pm (+5/-8)
lib/Pingback.pm (+42/-11)
t/lib/OptionParser.t (+3/-62)
t/lib/Pingback.t (+18/-0)
t/pt-query-digest/version_check.t (+13/-0)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/OptionParser-remove-optional_value
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+132222@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

In Pingback.pm:

sub version_check {
   my $args = pop @_;
   my (@instances) = @_;

That should be our standard %args.

      print STDERR '--version-check is disabled by the PERCONA_VERSION_CHECK ',
                   "environment variable.\n\n";

I think those should just be warn "..." (we tend not to use print STDERR for whatever reason).

      $args->{protocol} ||= 'https';
      my @protocols = $args->{protocol} ne 'https' && $args->{protocol} ne 'http'
                    ? qw(https http)
                    : $args->{protocol};

Let's do this earlier, before the eval, and check for 'off'. If 'off', then return. This will need to happen in the future when we switch the default to 'auto'.

Also, make the ?: more clear because right now it reads like "if not https and not http, then use https and http"--huh? (because 'auto', but that's not clear).

Also, --version-check '' on the cmd line isn't handled, so we need to check the --version-check value before $o->usage_or_errors(). To do this, make a MAGIC_version_check_protocols lists and use that so the docs become the actual values we check for (see MAGIC_history_cols in pqd for an example).

While v-c is a manual thing, let's increase,

   $ua ||= HTTPMicro->new( timeout => 2 );

to 5 since the user, knowing what v-c does, should be a little more lenient (and eventually they'll get either "No advice" or a warning or something, so they'll know the delay was due to v-c working).

review: Needs Fixing
437. By Brian Fraser

Updates per Daniel's review

438. By Brian Fraser

Fixed a typo and added some regression tests

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

516for my $exec ( grep { slurp_file($_) =~ /package Pingback;/ }
 517 grep { !/~/ }
 518 glob("$trunk/bin/*")
 519 )

That's good, but let's do it a little more light-weight. Remember, our poor test boxes are already strained. Why not just:

my @vc_tools = map { /(\S+)/ } `grep --files-with-matches Pingback $trunk/bin/*`;
foreach my $tool ( @vc_tools ) {
...

In this error: "--version-check invalud value $value. Accepted values are", double space between the sentence, i.e. \s\s instead of just \s before "Accepted" (blame Baron for encouraging my grammatical zealousness).

Typo in --version-check docs: ""auto" first tries using "https", and resolts to"

review: Needs Fixing
439. By Brian Fraser

Fixes per Daniel's review

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/pt-archiver'
--- bin/pt-archiver 2012-11-05 17:57:11 +0000
+++ bin/pt-archiver 2012-11-06 15:04:24 +0000
@@ -86,7 +86,6 @@
86 'default' => 1,86 'default' => 1,
87 'cumulative' => 1,87 'cumulative' => 1,
88 'negatable' => 1,88 'negatable' => 1,
89 'value_is_optional' => 1,
90 );89 );
9190
92 my $self = {91 my $self = {
@@ -328,10 +327,9 @@
328 $opt->{short} = undef;327 $opt->{short} = undef;
329 }328 }
330329
331 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;330 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
332 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;331 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
333 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;332 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
334 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
335333
336 $opt->{group} ||= 'default';334 $opt->{group} ||= 'default';
337 $self->{groups}->{ $opt->{group} }->{$long} = 1;335 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -467,7 +465,7 @@
467 if ( $opt->{is_cumulative} ) {465 if ( $opt->{is_cumulative} ) {
468 $opt->{value}++;466 $opt->{value}++;
469 }467 }
470 elsif ( !($opt->{optional_value} && !$val) ) {468 else {
471 $opt->{value} = $val;469 $opt->{value} = $val;
472 }470 }
473 $opt->{got} = 1;471 $opt->{got} = 1;
@@ -1008,12 +1006,11 @@
1008sub _parse_attribs {1006sub _parse_attribs {
1009 my ( $self, $option, $attribs ) = @_;1007 my ( $self, $option, $attribs ) = @_;
1010 my $types = $self->{types};1008 my $types = $self->{types};
1011 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
1012 return $option1009 return $option
1013 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )1010 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
1014 . ($attribs->{'negatable'} ? '!' : '' )1011 . ($attribs->{'negatable'} ? '!' : '' )
1015 . ($attribs->{'cumulative'} ? '+' : '' )1012 . ($attribs->{'cumulative'} ? '+' : '' )
1016 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );1013 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
1017}1014}
10181015
1019sub _parse_synopsis {1016sub _parse_synopsis {
@@ -4810,14 +4807,19 @@
4810};4807};
48114808
4812sub version_check {4809sub version_check {
4813 my $args = pop @_;4810 my %args = @_;
4814 my (@instances) = @_;4811 my @instances = $args{instances} ? @{ $args{instances} } : ();
48154812
4816 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {4813 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
4817 print STDERR '--version-check is disabled by the PERCONA_VERSION_CHECK ',4814 warn '--version-check is disabled by the PERCONA_VERSION_CHECK ',
4818 "environment variable.\n\n";4815 "environment variable.\n\n";
4819 return;4816 return;
4820 }4817 }
4818
4819 $args{protocol} ||= 'https';
4820 my @protocols = $args{protocol} eq 'auto'
4821 ? qw(https http)
4822 : $args{protocol};
4821 4823
4822 my $instances_to_check = [];4824 my $instances_to_check = [];
4823 my $time = int(time());4825 my $time = int(time());
@@ -4832,22 +4834,28 @@
4832 ($time_to_check, $instances_to_check)4834 ($time_to_check, $instances_to_check)
4833 = time_to_check($check_time_file, \@instances, $time);4835 = time_to_check($check_time_file, \@instances, $time);
4834 if ( !$time_to_check ) {4836 if ( !$time_to_check ) {
4835 print STDERR 'It is not time to --version-check again; ',4837 warn 'It is not time to --version-check again; ',
4836 "only 1 check per day.\n\n";4838 "only 1 check per day.\n\n";
4837 return;4839 return;
4838 }4840 }
48394841
4840 my $protocol = $args->{protocol} || 'https';4842 my $advice;
4841 my $advice = pingback(4843 my $e;
4842 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",4844 for my $protocol ( @protocols ) {
4843 instances => $instances_to_check,4845 $advice = eval { pingback(
4844 protocol => $args->{protocol},4846 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
4845 );4847 instances => $instances_to_check,
4848 protocol => $protocol,
4849 ) };
4850 last if !$advice && !$EVAL_ERROR;
4851 $e ||= $EVAL_ERROR;
4852 }
4846 if ( $advice ) {4853 if ( $advice ) {
4847 print "# Percona suggests these upgrades:\n";4854 print "# Percona suggests these upgrades:\n";
4848 print join("\n", map { "# * $_" } @$advice), "\n\n";4855 print join("\n", map { "# * $_" } @$advice), "\n\n";
4849 }4856 }
4850 else {4857 else {
4858 die $e if $e;
4851 print "# No suggestions at this time.\n\n";4859 print "# No suggestions at this time.\n\n";
4852 ($ENV{PTVCDEBUG} || PTDEBUG )4860 ($ENV{PTVCDEBUG} || PTDEBUG )
4853 && _d('--version-check worked, but there were no suggestions');4861 && _d('--version-check worked, but there were no suggestions');
@@ -4873,7 +4881,7 @@
48734881
4874 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};4882 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};
48754883
4876 $ua ||= HTTPMicro->new( timeout => 2 );4884 $ua ||= HTTPMicro->new( timeout => 5 );
4877 $vc ||= VersionCheck->new();4885 $vc ||= VersionCheck->new();
48784886
4879 my $response = $ua->request('GET', $url);4887 my $response = $ua->request('GET', $url);
@@ -5089,6 +5097,21 @@
5089 return $client_response;5097 return $client_response;
5090}5098}
50915099
5100sub validate_options {
5101 my ($o) = @_;
5102
5103 return if !$o->got('version-check');
5104
5105 my $value = $o->get('version-check');
5106 my @values = split /, /,
5107 $o->read_para_after(__FILE__, qr/MAGIC_version_check/);
5108 chomp(@values);
5109
5110 return if grep { $value eq $_ } @values;
5111 $o->save_error("--version-check invalid value $value. Accepted values are "
5112 . join(", ", @values[0..$#values-1]) . " and $values[-1]" );
5113}
5114
5092sub _d {5115sub _d {
5093 my ($package, undef, $line) = caller 0;5116 my ($package, undef, $line) = caller 0;
5094 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }5117 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
@@ -5233,6 +5256,8 @@
5233 $o->save_error("--bulk-delete is meaningless with --limit 1");5256 $o->save_error("--bulk-delete is meaningless with --limit 1");
5234 }5257 }
52355258
5259 Pingback::validate_options($o);
5260
5236 }5261 }
52375262
5238 if ( $bulk_del || $o->get('bulk-insert') ) {5263 if ( $bulk_del || $o->get('bulk-insert') ) {
@@ -5630,11 +5655,13 @@
5630 # ########################################################################5655 # ########################################################################
5631 # Do the version-check5656 # Do the version-check
5632 # ########################################################################5657 # ########################################################################
5633 if ( $o->got('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) {5658 if ( $o->get('version-check') ne 'off' && (!$o->has('quiet') || !$o->get('quiet')) ) {
5634 Pingback::version_check(5659 Pingback::version_check(
5635 { dbh => $src->{dbh}, dsn => $src->{dsn} },5660 instances => [
5636 ( $dst ? { dbh => $dst->{dbh}, dsn => $dst->{dsn} } : () ),5661 { dbh => $src->{dbh}, dsn => $src->{dsn} },
5637 { protocol => $o->get('version-check') },5662 ( $dst ? { dbh => $dst->{dbh}, dsn => $dst->{dsn} } : () ),
5663 ],
5664 protocol => $o->get('version-check'),
5638 );5665 );
5639 }5666 }
56405667
@@ -7071,14 +7098,20 @@
70717098
7072=item --version-check7099=item --version-check
70737100
7074type: string; value_is_optional: yes; default: https7101type: string; default: off
70757102
7076Send program versions to Percona and print suggested upgrades and problems.7103Send program versions to Percona and print suggested upgrades and problems.
70777104Possible values for --version-check:
7078If specified without a value, it will use https by default; However, this7105
7079might fail if C<IO::Socket::SSL> is not installed on your system; for the7106=for comment ignore-pt-internal-value
7080latter case, you may choose to use C<--version-check http>, which will forgo7107MAGIC_version_check
7081encryption but should work out of the box.7108
7109https, http, auto, off
7110
7111C<auto> first tries using C<https>, and resorts to C<http> if that fails.
7112Keep in mind that C<https> might not be available if
7113C<IO::Socket::SSL> is not installed on your system, although
7114C<--version-check http> should work everywhere.
70827115
7083The version check feature causes the tool to send and receive data from7116The version check feature causes the tool to send and receive data from
7084Percona over the web. The data contains program versions from the local7117Percona over the web. The data contains program versions from the local
70857118
=== modified file 'bin/pt-config-diff'
--- bin/pt-config-diff 2012-10-31 09:18:34 +0000
+++ bin/pt-config-diff 2012-11-06 15:04:24 +0000
@@ -85,7 +85,6 @@
85 'default' => 1,85 'default' => 1,
86 'cumulative' => 1,86 'cumulative' => 1,
87 'negatable' => 1,87 'negatable' => 1,
88 'value_is_optional' => 1,
89 );88 );
9089
91 my $self = {90 my $self = {
@@ -327,10 +326,9 @@
327 $opt->{short} = undef;326 $opt->{short} = undef;
328 }327 }
329328
330 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;329 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
331 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;330 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
332 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;331 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
333 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
334332
335 $opt->{group} ||= 'default';333 $opt->{group} ||= 'default';
336 $self->{groups}->{ $opt->{group} }->{$long} = 1;334 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -466,7 +464,7 @@
466 if ( $opt->{is_cumulative} ) {464 if ( $opt->{is_cumulative} ) {
467 $opt->{value}++;465 $opt->{value}++;
468 }466 }
469 elsif ( !($opt->{optional_value} && !$val) ) {467 else {
470 $opt->{value} = $val;468 $opt->{value} = $val;
471 }469 }
472 $opt->{got} = 1;470 $opt->{got} = 1;
@@ -1007,12 +1005,11 @@
1007sub _parse_attribs {1005sub _parse_attribs {
1008 my ( $self, $option, $attribs ) = @_;1006 my ( $self, $option, $attribs ) = @_;
1009 my $types = $self->{types};1007 my $types = $self->{types};
1010 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
1011 return $option1008 return $option
1012 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )1009 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
1013 . ($attribs->{'negatable'} ? '!' : '' )1010 . ($attribs->{'negatable'} ? '!' : '' )
1014 . ($attribs->{'cumulative'} ? '+' : '' )1011 . ($attribs->{'cumulative'} ? '+' : '' )
1015 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );1012 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
1016}1013}
10171014
1018sub _parse_synopsis {1015sub _parse_synopsis {
@@ -3959,14 +3956,19 @@
3959};3956};
39603957
3961sub version_check {3958sub version_check {
3962 my $args = pop @_;3959 my %args = @_;
3963 my (@instances) = @_;3960 my @instances = $args{instances} ? @{ $args{instances} } : ();
39643961
3965 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {3962 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
3966 print STDERR '--version-check is disabled by the PERCONA_VERSION_CHECK ',3963 warn '--version-check is disabled by the PERCONA_VERSION_CHECK ',
3967 "environment variable.\n\n";3964 "environment variable.\n\n";
3968 return;3965 return;
3969 }3966 }
3967
3968 $args{protocol} ||= 'https';
3969 my @protocols = $args{protocol} eq 'auto'
3970 ? qw(https http)
3971 : $args{protocol};
3970 3972
3971 my $instances_to_check = [];3973 my $instances_to_check = [];
3972 my $time = int(time());3974 my $time = int(time());
@@ -3981,22 +3983,28 @@
3981 ($time_to_check, $instances_to_check)3983 ($time_to_check, $instances_to_check)
3982 = time_to_check($check_time_file, \@instances, $time);3984 = time_to_check($check_time_file, \@instances, $time);
3983 if ( !$time_to_check ) {3985 if ( !$time_to_check ) {
3984 print STDERR 'It is not time to --version-check again; ',3986 warn 'It is not time to --version-check again; ',
3985 "only 1 check per day.\n\n";3987 "only 1 check per day.\n\n";
3986 return;3988 return;
3987 }3989 }
39883990
3989 my $protocol = $args->{protocol} || 'https';3991 my $advice;
3990 my $advice = pingback(3992 my $e;
3991 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",3993 for my $protocol ( @protocols ) {
3992 instances => $instances_to_check,3994 $advice = eval { pingback(
3993 protocol => $args->{protocol},3995 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
3994 );3996 instances => $instances_to_check,
3997 protocol => $protocol,
3998 ) };
3999 last if !$advice && !$EVAL_ERROR;
4000 $e ||= $EVAL_ERROR;
4001 }
3995 if ( $advice ) {4002 if ( $advice ) {
3996 print "# Percona suggests these upgrades:\n";4003 print "# Percona suggests these upgrades:\n";
3997 print join("\n", map { "# * $_" } @$advice), "\n\n";4004 print join("\n", map { "# * $_" } @$advice), "\n\n";
3998 }4005 }
3999 else {4006 else {
4007 die $e if $e;
4000 print "# No suggestions at this time.\n\n";4008 print "# No suggestions at this time.\n\n";
4001 ($ENV{PTVCDEBUG} || PTDEBUG )4009 ($ENV{PTVCDEBUG} || PTDEBUG )
4002 && _d('--version-check worked, but there were no suggestions');4010 && _d('--version-check worked, but there were no suggestions');
@@ -4022,7 +4030,7 @@
40224030
4023 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};4031 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};
40244032
4025 $ua ||= HTTPMicro->new( timeout => 2 );4033 $ua ||= HTTPMicro->new( timeout => 5 );
4026 $vc ||= VersionCheck->new();4034 $vc ||= VersionCheck->new();
40274035
4028 my $response = $ua->request('GET', $url);4036 my $response = $ua->request('GET', $url);
@@ -4238,6 +4246,21 @@
4238 return $client_response;4246 return $client_response;
4239}4247}
42404248
4249sub validate_options {
4250 my ($o) = @_;
4251
4252 return if !$o->got('version-check');
4253
4254 my $value = $o->get('version-check');
4255 my @values = split /, /,
4256 $o->read_para_after(__FILE__, qr/MAGIC_version_check/);
4257 chomp(@values);
4258
4259 return if grep { $value eq $_ } @values;
4260 $o->save_error("--version-check invalid value $value. Accepted values are "
4261 . join(", ", @values[0..$#values-1]) . " and $values[-1]" );
4262}
4263
4241sub _d {4264sub _d {
4242 my ($package, undef, $line) = caller 0;4265 my ($package, undef, $line) = caller 0;
4243 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }4266 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
@@ -4290,6 +4313,7 @@
4290 if ( @ARGV < 1 ) {4313 if ( @ARGV < 1 ) {
4291 $o->save_error("Specify at least one file or DSN on the command line");4314 $o->save_error("Specify at least one file or DSN on the command line");
4292 }4315 }
4316 Pingback::validate_options($o);
4293 }4317 }
42944318
4295 $o->usage_or_errors();4319 $o->usage_or_errors();
@@ -4364,10 +4388,10 @@
4364 # ########################################################################4388 # ########################################################################
4365 # Do the version-check4389 # Do the version-check
4366 # ########################################################################4390 # ########################################################################
4367 if ( $o->got('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) {4391 if ( $o->get('version-check') ne 'off' && (!$o->has('quiet') || !$o->get('quiet')) ) {
4368 Pingback::version_check(4392 Pingback::version_check(
4369 map({ +{ dbh => $_->dbh, dsn => $_->dsn } } @cxn),4393 instances => [ map({ +{ dbh => $_->dbh, dsn => $_->dsn } } @cxn) ],
4370 { protocol => $o->get('version-check') },4394 protocol => $o->get('version-check'),
4371 );4395 );
4372 }4396 }
43734397
@@ -4651,14 +4675,20 @@
46514675
4652=item --version-check4676=item --version-check
46534677
4654type: string; value_is_optional: yes; default: https4678type: string; default: off
46554679
4656Send program versions to Percona and print suggested upgrades and problems.4680Send program versions to Percona and print suggested upgrades and problems.
46574681Possible values for --version-check:
4658If specified without a value, it will use https by default; However, this4682
4659might fail if C<IO::Socket::SSL> is not installed on your system, in which4683=for comment ignore-pt-internal-value
4660case you may choose to use C<--version-check http>, which will forgo4684MAGIC_version_check
4661encryption but should work out of the box.4685
4686https, http, auto, off
4687
4688C<auto> first tries using C<https>, and resorts to C<http> if that fails.
4689Keep in mind that C<https> might not be available if
4690C<IO::Socket::SSL> is not installed on your system, although
4691C<--version-check http> should work everywhere.
46624692
4663The version check feature causes the tool to send and receive data from4693The version check feature causes the tool to send and receive data from
4664Percona over the web. The data contains program versions from the local4694Percona over the web. The data contains program versions from the local
46654695
=== modified file 'bin/pt-deadlock-logger'
--- bin/pt-deadlock-logger 2012-10-31 09:18:34 +0000
+++ bin/pt-deadlock-logger 2012-11-06 15:04:24 +0000
@@ -83,7 +83,6 @@
83 'default' => 1,83 'default' => 1,
84 'cumulative' => 1,84 'cumulative' => 1,
85 'negatable' => 1,85 'negatable' => 1,
86 'value_is_optional' => 1,
87 );86 );
8887
89 my $self = {88 my $self = {
@@ -325,10 +324,9 @@
325 $opt->{short} = undef;324 $opt->{short} = undef;
326 }325 }
327326
328 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;327 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
329 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;328 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
330 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;329 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
331 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
332330
333 $opt->{group} ||= 'default';331 $opt->{group} ||= 'default';
334 $self->{groups}->{ $opt->{group} }->{$long} = 1;332 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -464,7 +462,7 @@
464 if ( $opt->{is_cumulative} ) {462 if ( $opt->{is_cumulative} ) {
465 $opt->{value}++;463 $opt->{value}++;
466 }464 }
467 elsif ( !($opt->{optional_value} && !$val) ) {465 else {
468 $opt->{value} = $val;466 $opt->{value} = $val;
469 }467 }
470 $opt->{got} = 1;468 $opt->{got} = 1;
@@ -1005,12 +1003,11 @@
1005sub _parse_attribs {1003sub _parse_attribs {
1006 my ( $self, $option, $attribs ) = @_;1004 my ( $self, $option, $attribs ) = @_;
1007 my $types = $self->{types};1005 my $types = $self->{types};
1008 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
1009 return $option1006 return $option
1010 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )1007 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
1011 . ($attribs->{'negatable'} ? '!' : '' )1008 . ($attribs->{'negatable'} ? '!' : '' )
1012 . ($attribs->{'cumulative'} ? '+' : '' )1009 . ($attribs->{'cumulative'} ? '+' : '' )
1013 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );1010 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
1014}1011}
10151012
1016sub _parse_synopsis {1013sub _parse_synopsis {
@@ -3401,14 +3398,19 @@
3401};3398};
34023399
3403sub version_check {3400sub version_check {
3404 my $args = pop @_;3401 my %args = @_;
3405 my (@instances) = @_;3402 my @instances = $args{instances} ? @{ $args{instances} } : ();
34063403
3407 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {3404 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
3408 print STDERR '--version-check is disabled by the PERCONA_VERSION_CHECK ',3405 warn '--version-check is disabled by the PERCONA_VERSION_CHECK ',
3409 "environment variable.\n\n";3406 "environment variable.\n\n";
3410 return;3407 return;
3411 }3408 }
3409
3410 $args{protocol} ||= 'https';
3411 my @protocols = $args{protocol} eq 'auto'
3412 ? qw(https http)
3413 : $args{protocol};
3412 3414
3413 my $instances_to_check = [];3415 my $instances_to_check = [];
3414 my $time = int(time());3416 my $time = int(time());
@@ -3423,22 +3425,28 @@
3423 ($time_to_check, $instances_to_check)3425 ($time_to_check, $instances_to_check)
3424 = time_to_check($check_time_file, \@instances, $time);3426 = time_to_check($check_time_file, \@instances, $time);
3425 if ( !$time_to_check ) {3427 if ( !$time_to_check ) {
3426 print STDERR 'It is not time to --version-check again; ',3428 warn 'It is not time to --version-check again; ',
3427 "only 1 check per day.\n\n";3429 "only 1 check per day.\n\n";
3428 return;3430 return;
3429 }3431 }
34303432
3431 my $protocol = $args->{protocol} || 'https';3433 my $advice;
3432 my $advice = pingback(3434 my $e;
3433 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",3435 for my $protocol ( @protocols ) {
3434 instances => $instances_to_check,3436 $advice = eval { pingback(
3435 protocol => $args->{protocol},3437 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
3436 );3438 instances => $instances_to_check,
3439 protocol => $protocol,
3440 ) };
3441 last if !$advice && !$EVAL_ERROR;
3442 $e ||= $EVAL_ERROR;
3443 }
3437 if ( $advice ) {3444 if ( $advice ) {
3438 print "# Percona suggests these upgrades:\n";3445 print "# Percona suggests these upgrades:\n";
3439 print join("\n", map { "# * $_" } @$advice), "\n\n";3446 print join("\n", map { "# * $_" } @$advice), "\n\n";
3440 }3447 }
3441 else {3448 else {
3449 die $e if $e;
3442 print "# No suggestions at this time.\n\n";3450 print "# No suggestions at this time.\n\n";
3443 ($ENV{PTVCDEBUG} || PTDEBUG )3451 ($ENV{PTVCDEBUG} || PTDEBUG )
3444 && _d('--version-check worked, but there were no suggestions');3452 && _d('--version-check worked, but there were no suggestions');
@@ -3464,7 +3472,7 @@
34643472
3465 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};3473 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};
34663474
3467 $ua ||= HTTPMicro->new( timeout => 2 );3475 $ua ||= HTTPMicro->new( timeout => 5 );
3468 $vc ||= VersionCheck->new();3476 $vc ||= VersionCheck->new();
34693477
3470 my $response = $ua->request('GET', $url);3478 my $response = $ua->request('GET', $url);
@@ -3680,6 +3688,21 @@
3680 return $client_response;3688 return $client_response;
3681}3689}
36823690
3691sub validate_options {
3692 my ($o) = @_;
3693
3694 return if !$o->got('version-check');
3695
3696 my $value = $o->get('version-check');
3697 my @values = split /, /,
3698 $o->read_para_after(__FILE__, qr/MAGIC_version_check/);
3699 chomp(@values);
3700
3701 return if grep { $value eq $_ } @values;
3702 $o->save_error("--version-check invalid value $value. Accepted values are "
3703 . join(", ", @values[0..$#values-1]) . " and $values[-1]" );
3704}
3705
3683sub _d {3706sub _d {
3684 my ($package, undef, $line) = caller 0;3707 my ($package, undef, $line) = caller 0;
3685 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }3708 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
@@ -3802,6 +3825,8 @@
3802 $o->save_error("--dest requires a 't' (table) part");3825 $o->save_error("--dest requires a 't' (table) part");
3803 }3826 }
38043827
3828 Pingback::validate_options($o);
3829
3805 # Avoid running forever with zero second interval.3830 # Avoid running forever with zero second interval.
3806 if ( $o->get('run-time') && !$o->get('interval') ) {3831 if ( $o->get('run-time') && !$o->get('interval') ) {
3807 $o->set('interval', 1);3832 $o->set('interval', 1);
@@ -3871,11 +3896,13 @@
3871 # ########################################################################3896 # ########################################################################
3872 # Do the version-check3897 # Do the version-check
3873 # ########################################################################3898 # ########################################################################
3874 if ( $o->got('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) {3899 if ( $o->get('version-check') ne 'off' && (!$o->has('quiet') || !$o->get('quiet')) ) {
3875 Pingback::version_check(3900 Pingback::version_check(
3876 { dbh => $dbh, dsn => $source_dsn },3901 instances => [
3877 ($dest_dsn ? { dbh => $dest_dsn, dsn => $dest_dsn } : ()),3902 { dbh => $dbh, dsn => $source_dsn },
3878 { protocol => $o->get('version-check') },3903 ($dest_dsn ? { dbh => $dest_dsn, dsn => $dest_dsn } : ()),
3904 ],
3905 protocol => $o->get('version-check'),
3879 );3906 );
3880 }3907 }
38813908
@@ -4563,14 +4590,20 @@
45634590
4564=item --version-check4591=item --version-check
45654592
4566type: string; value_is_optional: yes; default: https4593type: string; default: off
45674594
4568Send program versions to Percona and print suggested upgrades and problems.4595Send program versions to Percona and print suggested upgrades and problems.
45694596Possible values for --version-check:
4570If specified without a value, it will use https by default; However, this4597
4571might fail if C<IO::Socket::SSL> is not installed on your system, in which4598=for comment ignore-pt-internal-value
4572case you may choose to use C<--version-check http>, which will forgo4599MAGIC_version_check
4573encryption but should work out of the box.4600
4601https, http, auto, off
4602
4603C<auto> first tries using C<https>, and resorts to C<http> if that fails.
4604Keep in mind that C<https> might not be available if
4605C<IO::Socket::SSL> is not installed on your system, although
4606C<--version-check http> should work everywhere.
45744607
4575The version check feature causes the tool to send and receive data from4608The version check feature causes the tool to send and receive data from
4576Percona over the web. The data contains program versions from the local4609Percona over the web. The data contains program versions from the local
45774610
=== modified file 'bin/pt-diskstats'
--- bin/pt-diskstats 2012-10-22 18:17:08 +0000
+++ bin/pt-diskstats 2012-11-06 15:04:24 +0000
@@ -85,7 +85,6 @@
85 'default' => 1,85 'default' => 1,
86 'cumulative' => 1,86 'cumulative' => 1,
87 'negatable' => 1,87 'negatable' => 1,
88 'value_is_optional' => 1,
89 );88 );
9089
91 my $self = {90 my $self = {
@@ -327,10 +326,9 @@
327 $opt->{short} = undef;326 $opt->{short} = undef;
328 }327 }
329328
330 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;329 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
331 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;330 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
332 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;331 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
333 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
334332
335 $opt->{group} ||= 'default';333 $opt->{group} ||= 'default';
336 $self->{groups}->{ $opt->{group} }->{$long} = 1;334 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -466,7 +464,7 @@
466 if ( $opt->{is_cumulative} ) {464 if ( $opt->{is_cumulative} ) {
467 $opt->{value}++;465 $opt->{value}++;
468 }466 }
469 elsif ( !($opt->{optional_value} && !$val) ) {467 else {
470 $opt->{value} = $val;468 $opt->{value} = $val;
471 }469 }
472 $opt->{got} = 1;470 $opt->{got} = 1;
@@ -1007,12 +1005,11 @@
1007sub _parse_attribs {1005sub _parse_attribs {
1008 my ( $self, $option, $attribs ) = @_;1006 my ( $self, $option, $attribs ) = @_;
1009 my $types = $self->{types};1007 my $types = $self->{types};
1010 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
1011 return $option1008 return $option
1012 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )1009 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
1013 . ($attribs->{'negatable'} ? '!' : '' )1010 . ($attribs->{'negatable'} ? '!' : '' )
1014 . ($attribs->{'cumulative'} ? '+' : '' )1011 . ($attribs->{'cumulative'} ? '+' : '' )
1015 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );1012 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
1016}1013}
10171014
1018sub _parse_synopsis {1015sub _parse_synopsis {
@@ -4496,14 +4493,19 @@
4496};4493};
44974494
4498sub version_check {4495sub version_check {
4499 my $args = pop @_;4496 my %args = @_;
4500 my (@instances) = @_;4497 my @instances = $args{instances} ? @{ $args{instances} } : ();
45014498
4502 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {4499 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
4503 print STDERR '--version-check is disabled by the PERCONA_VERSION_CHECK ',4500 warn '--version-check is disabled by the PERCONA_VERSION_CHECK ',
4504 "environment variable.\n\n";4501 "environment variable.\n\n";
4505 return;4502 return;
4506 }4503 }
4504
4505 $args{protocol} ||= 'https';
4506 my @protocols = $args{protocol} eq 'auto'
4507 ? qw(https http)
4508 : $args{protocol};
4507 4509
4508 my $instances_to_check = [];4510 my $instances_to_check = [];
4509 my $time = int(time());4511 my $time = int(time());
@@ -4518,22 +4520,28 @@
4518 ($time_to_check, $instances_to_check)4520 ($time_to_check, $instances_to_check)
4519 = time_to_check($check_time_file, \@instances, $time);4521 = time_to_check($check_time_file, \@instances, $time);
4520 if ( !$time_to_check ) {4522 if ( !$time_to_check ) {
4521 print STDERR 'It is not time to --version-check again; ',4523 warn 'It is not time to --version-check again; ',
4522 "only 1 check per day.\n\n";4524 "only 1 check per day.\n\n";
4523 return;4525 return;
4524 }4526 }
45254527
4526 my $protocol = $args->{protocol} || 'https';4528 my $advice;
4527 my $advice = pingback(4529 my $e;
4528 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",4530 for my $protocol ( @protocols ) {
4529 instances => $instances_to_check,4531 $advice = eval { pingback(
4530 protocol => $args->{protocol},4532 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
4531 );4533 instances => $instances_to_check,
4534 protocol => $protocol,
4535 ) };
4536 last if !$advice && !$EVAL_ERROR;
4537 $e ||= $EVAL_ERROR;
4538 }
4532 if ( $advice ) {4539 if ( $advice ) {
4533 print "# Percona suggests these upgrades:\n";4540 print "# Percona suggests these upgrades:\n";
4534 print join("\n", map { "# * $_" } @$advice), "\n\n";4541 print join("\n", map { "# * $_" } @$advice), "\n\n";
4535 }4542 }
4536 else {4543 else {
4544 die $e if $e;
4537 print "# No suggestions at this time.\n\n";4545 print "# No suggestions at this time.\n\n";
4538 ($ENV{PTVCDEBUG} || PTDEBUG )4546 ($ENV{PTVCDEBUG} || PTDEBUG )
4539 && _d('--version-check worked, but there were no suggestions');4547 && _d('--version-check worked, but there were no suggestions');
@@ -4559,7 +4567,7 @@
45594567
4560 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};4568 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};
45614569
4562 $ua ||= HTTPMicro->new( timeout => 2 );4570 $ua ||= HTTPMicro->new( timeout => 5 );
4563 $vc ||= VersionCheck->new();4571 $vc ||= VersionCheck->new();
45644572
4565 my $response = $ua->request('GET', $url);4573 my $response = $ua->request('GET', $url);
@@ -4775,6 +4783,21 @@
4775 return $client_response;4783 return $client_response;
4776}4784}
47774785
4786sub validate_options {
4787 my ($o) = @_;
4788
4789 return if !$o->got('version-check');
4790
4791 my $value = $o->get('version-check');
4792 my @values = split /, /,
4793 $o->read_para_after(__FILE__, qr/MAGIC_version_check/);
4794 chomp(@values);
4795
4796 return if grep { $value eq $_ } @values;
4797 $o->save_error("--version-check invalid value $value. Accepted values are "
4798 . join(", ", @values[0..$#values-1]) . " and $values[-1]" );
4799}
4800
4778sub _d {4801sub _d {
4779 my ($package, undef, $line) = caller 0;4802 my ($package, undef, $line) = caller 0;
4780 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }4803 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
@@ -4828,6 +4851,7 @@
4828 if ( !$o->get('columns-regex') ) {4851 if ( !$o->get('columns-regex') ) {
4829 $o->save_error("A regex pattern for --column-regex must be specified");4852 $o->save_error("A regex pattern for --column-regex must be specified");
4830 }4853 }
4854 Pingback::validate_options($o);
4831 }4855 }
48324856
4833 $o->usage_or_errors();4857 $o->usage_or_errors();
@@ -4835,8 +4859,8 @@
4835 # ########################################################################4859 # ########################################################################
4836 # Do the version-check4860 # Do the version-check
4837 # ########################################################################4861 # ########################################################################
4838 if ( $o->got('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) {4862 if ( $o->get('version-check') ne 'off' && (!$o->has('quiet') || !$o->get('quiet')) ) {
4839 Pingback::version_check({ protocol => $o->get('version-check') });4863 Pingback::version_check(protocol => $o->get('version-check'));
4840 }4864 }
48414865
4842 # ########################################################################4866 # ########################################################################
@@ -5427,14 +5451,20 @@
54275451
5428=item --version-check5452=item --version-check
54295453
5430type: string; value_is_optional: yes; default: https5454type: string; default: off
54315455
5432Send program versions to Percona and print suggested upgrades and problems.5456Send program versions to Percona and print suggested upgrades and problems.
54335457Possible values for --version-check:
5434If specified without a value, it will use https by default; However, this5458
5435might fail if C<IO::Socket::SSL> is not installed on your system, in which5459=for comment ignore-pt-internal-value
5436case you may choose to use C<--version-check http>, which will forgo5460MAGIC_version_check
5437encryption but should work out of the box.5461
5462https, http, auto, off
5463
5464C<auto> first tries using C<https>, and resorts to C<http> if that fails.
5465Keep in mind that C<https> might not be available if
5466C<IO::Socket::SSL> is not installed on your system, although
5467C<--version-check http> should work everywhere.
54385468
5439The version check feature causes the tool to send and receive data from5469The version check feature causes the tool to send and receive data from
5440Percona over the web. The data contains program versions from the local5470Percona over the web. The data contains program versions from the local
54415471
=== modified file 'bin/pt-duplicate-key-checker'
--- bin/pt-duplicate-key-checker 2012-11-05 17:57:11 +0000
+++ bin/pt-duplicate-key-checker 2012-11-06 15:04:24 +0000
@@ -992,7 +992,6 @@
992 'default' => 1,992 'default' => 1,
993 'cumulative' => 1,993 'cumulative' => 1,
994 'negatable' => 1,994 'negatable' => 1,
995 'value_is_optional' => 1,
996 );995 );
997996
998 my $self = {997 my $self = {
@@ -1234,10 +1233,9 @@
1234 $opt->{short} = undef;1233 $opt->{short} = undef;
1235 }1234 }
12361235
1237 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;1236 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
1238 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;1237 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
1239 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;1238 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
1240 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
12411239
1242 $opt->{group} ||= 'default';1240 $opt->{group} ||= 'default';
1243 $self->{groups}->{ $opt->{group} }->{$long} = 1;1241 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -1373,7 +1371,7 @@
1373 if ( $opt->{is_cumulative} ) {1371 if ( $opt->{is_cumulative} ) {
1374 $opt->{value}++;1372 $opt->{value}++;
1375 }1373 }
1376 elsif ( !($opt->{optional_value} && !$val) ) {1374 else {
1377 $opt->{value} = $val;1375 $opt->{value} = $val;
1378 }1376 }
1379 $opt->{got} = 1;1377 $opt->{got} = 1;
@@ -1914,12 +1912,11 @@
1914sub _parse_attribs {1912sub _parse_attribs {
1915 my ( $self, $option, $attribs ) = @_;1913 my ( $self, $option, $attribs ) = @_;
1916 my $types = $self->{types};1914 my $types = $self->{types};
1917 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
1918 return $option1915 return $option
1919 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )1916 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
1920 . ($attribs->{'negatable'} ? '!' : '' )1917 . ($attribs->{'negatable'} ? '!' : '' )
1921 . ($attribs->{'cumulative'} ? '+' : '' )1918 . ($attribs->{'cumulative'} ? '+' : '' )
1922 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );1919 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
1923}1920}
19241921
1925sub _parse_synopsis {1922sub _parse_synopsis {
@@ -4326,14 +4323,19 @@
4326};4323};
43274324
4328sub version_check {4325sub version_check {
4329 my $args = pop @_;4326 my %args = @_;
4330 my (@instances) = @_;4327 my @instances = $args{instances} ? @{ $args{instances} } : ();
43314328
4332 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {4329 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
4333 print STDERR '--version-check is disabled by the PERCONA_VERSION_CHECK ',4330 warn '--version-check is disabled by the PERCONA_VERSION_CHECK ',
4334 "environment variable.\n\n";4331 "environment variable.\n\n";
4335 return;4332 return;
4336 }4333 }
4334
4335 $args{protocol} ||= 'https';
4336 my @protocols = $args{protocol} eq 'auto'
4337 ? qw(https http)
4338 : $args{protocol};
4337 4339
4338 my $instances_to_check = [];4340 my $instances_to_check = [];
4339 my $time = int(time());4341 my $time = int(time());
@@ -4348,22 +4350,28 @@
4348 ($time_to_check, $instances_to_check)4350 ($time_to_check, $instances_to_check)
4349 = time_to_check($check_time_file, \@instances, $time);4351 = time_to_check($check_time_file, \@instances, $time);
4350 if ( !$time_to_check ) {4352 if ( !$time_to_check ) {
4351 print STDERR 'It is not time to --version-check again; ',4353 warn 'It is not time to --version-check again; ',
4352 "only 1 check per day.\n\n";4354 "only 1 check per day.\n\n";
4353 return;4355 return;
4354 }4356 }
43554357
4356 my $protocol = $args->{protocol} || 'https';4358 my $advice;
4357 my $advice = pingback(4359 my $e;
4358 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",4360 for my $protocol ( @protocols ) {
4359 instances => $instances_to_check,4361 $advice = eval { pingback(
4360 protocol => $args->{protocol},4362 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
4361 );4363 instances => $instances_to_check,
4364 protocol => $protocol,
4365 ) };
4366 last if !$advice && !$EVAL_ERROR;
4367 $e ||= $EVAL_ERROR;
4368 }
4362 if ( $advice ) {4369 if ( $advice ) {
4363 print "# Percona suggests these upgrades:\n";4370 print "# Percona suggests these upgrades:\n";
4364 print join("\n", map { "# * $_" } @$advice), "\n\n";4371 print join("\n", map { "# * $_" } @$advice), "\n\n";
4365 }4372 }
4366 else {4373 else {
4374 die $e if $e;
4367 print "# No suggestions at this time.\n\n";4375 print "# No suggestions at this time.\n\n";
4368 ($ENV{PTVCDEBUG} || PTDEBUG )4376 ($ENV{PTVCDEBUG} || PTDEBUG )
4369 && _d('--version-check worked, but there were no suggestions');4377 && _d('--version-check worked, but there were no suggestions');
@@ -4389,7 +4397,7 @@
43894397
4390 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};4398 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};
43914399
4392 $ua ||= HTTPMicro->new( timeout => 2 );4400 $ua ||= HTTPMicro->new( timeout => 5 );
4393 $vc ||= VersionCheck->new();4401 $vc ||= VersionCheck->new();
43944402
4395 my $response = $ua->request('GET', $url);4403 my $response = $ua->request('GET', $url);
@@ -4605,6 +4613,21 @@
4605 return $client_response;4613 return $client_response;
4606}4614}
46074615
4616sub validate_options {
4617 my ($o) = @_;
4618
4619 return if !$o->got('version-check');
4620
4621 my $value = $o->get('version-check');
4622 my @values = split /, /,
4623 $o->read_para_after(__FILE__, qr/MAGIC_version_check/);
4624 chomp(@values);
4625
4626 return if grep { $value eq $_ } @values;
4627 $o->save_error("--version-check invalid value $value. Accepted values are "
4628 . join(", ", @values[0..$#values-1]) . " and $values[-1]" );
4629}
4630
4608sub _d {4631sub _d {
4609 my ($package, undef, $line) = caller 0;4632 my ($package, undef, $line) = caller 0;
4610 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }4633 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
@@ -4662,7 +4685,8 @@
46624685
4663 my $dp = $o->DSNParser();4686 my $dp = $o->DSNParser();
4664 $dp->prop('set-vars', $o->get('set-vars'));4687 $dp->prop('set-vars', $o->get('set-vars'));
46654688 Pingback::validate_options($o);
4689
4666 $o->usage_or_errors();4690 $o->usage_or_errors();
46674691
4668 # ########################################################################4692 # ########################################################################
@@ -4692,10 +4716,10 @@
4692 # ########################################################################4716 # ########################################################################
4693 # Do the version-check4717 # Do the version-check
4694 # ########################################################################4718 # ########################################################################
4695 if ( $o->got('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) {4719 if ( $o->get('version-check') ne 'off' && (!$o->has('quiet') || !$o->get('quiet')) ) {
4696 Pingback::version_check(4720 Pingback::version_check(
4697 {dbh => $dbh, dsn => $dsn},4721 instances => [ {dbh => $dbh, dsn => $dsn} ],
4698 { protocol => $o->get('version-check') },4722 protocol => $o->get('version-check'),
4699 );4723 );
4700 }4724 }
47014725
@@ -5199,14 +5223,20 @@
51995223
5200=item --version-check5224=item --version-check
52015225
5202type: string; value_is_optional: yes; default: https5226type: string; default: off
52035227
5204Send program versions to Percona and print suggested upgrades and problems.5228Send program versions to Percona and print suggested upgrades and problems.
52055229Possible values for --version-check:
5206If specified without a value, it will use https by default; However, this5230
5207might fail if C<IO::Socket::SSL> is not installed on your system, in which5231=for comment ignore-pt-internal-value
5208case you may choose to use C<--version-check http>, which will forgo5232MAGIC_version_check
5209encryption but should work out of the box.5233
5234https, http, auto, off
5235
5236C<auto> first tries using C<https>, and resorts to C<http> if that fails.
5237Keep in mind that C<https> might not be available if
5238C<IO::Socket::SSL> is not installed on your system, although
5239C<--version-check http> should work everywhere.
52105240
5211The version check feature causes the tool to send and receive data from5241The version check feature causes the tool to send and receive data from
5212Percona over the web. The data contains program versions from the local5242Percona over the web. The data contains program versions from the local
52135243
=== modified file 'bin/pt-fifo-split'
--- bin/pt-fifo-split 2012-10-31 01:14:11 +0000
+++ bin/pt-fifo-split 2012-11-06 15:04:24 +0000
@@ -57,7 +57,6 @@
57 'default' => 1,57 'default' => 1,
58 'cumulative' => 1,58 'cumulative' => 1,
59 'negatable' => 1,59 'negatable' => 1,
60 'value_is_optional' => 1,
61 );60 );
6261
63 my $self = {62 my $self = {
@@ -299,10 +298,9 @@
299 $opt->{short} = undef;298 $opt->{short} = undef;
300 }299 }
301300
302 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;301 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
303 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;302 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
304 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;303 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
305 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
306304
307 $opt->{group} ||= 'default';305 $opt->{group} ||= 'default';
308 $self->{groups}->{ $opt->{group} }->{$long} = 1;306 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -438,7 +436,7 @@
438 if ( $opt->{is_cumulative} ) {436 if ( $opt->{is_cumulative} ) {
439 $opt->{value}++;437 $opt->{value}++;
440 }438 }
441 elsif ( !($opt->{optional_value} && !$val) ) {439 else {
442 $opt->{value} = $val;440 $opt->{value} = $val;
443 }441 }
444 $opt->{got} = 1;442 $opt->{got} = 1;
@@ -979,12 +977,11 @@
979sub _parse_attribs {977sub _parse_attribs {
980 my ( $self, $option, $attribs ) = @_;978 my ( $self, $option, $attribs ) = @_;
981 my $types = $self->{types};979 my $types = $self->{types};
982 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
983 return $option980 return $option
984 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )981 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
985 . ($attribs->{'negatable'} ? '!' : '' )982 . ($attribs->{'negatable'} ? '!' : '' )
986 . ($attribs->{'cumulative'} ? '+' : '' )983 . ($attribs->{'cumulative'} ? '+' : '' )
987 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );984 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
988}985}
989986
990sub _parse_synopsis {987sub _parse_synopsis {
991988
=== modified file 'bin/pt-find'
--- bin/pt-find 2012-11-05 17:57:11 +0000
+++ bin/pt-find 2012-11-06 15:04:24 +0000
@@ -459,7 +459,6 @@
459 'default' => 1,459 'default' => 1,
460 'cumulative' => 1,460 'cumulative' => 1,
461 'negatable' => 1,461 'negatable' => 1,
462 'value_is_optional' => 1,
463 );462 );
464463
465 my $self = {464 my $self = {
@@ -701,10 +700,9 @@
701 $opt->{short} = undef;700 $opt->{short} = undef;
702 }701 }
703702
704 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;703 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
705 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;704 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
706 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;705 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
707 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
708706
709 $opt->{group} ||= 'default';707 $opt->{group} ||= 'default';
710 $self->{groups}->{ $opt->{group} }->{$long} = 1;708 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -840,7 +838,7 @@
840 if ( $opt->{is_cumulative} ) {838 if ( $opt->{is_cumulative} ) {
841 $opt->{value}++;839 $opt->{value}++;
842 }840 }
843 elsif ( !($opt->{optional_value} && !$val) ) {841 else {
844 $opt->{value} = $val;842 $opt->{value} = $val;
845 }843 }
846 $opt->{got} = 1;844 $opt->{got} = 1;
@@ -1381,12 +1379,11 @@
1381sub _parse_attribs {1379sub _parse_attribs {
1382 my ( $self, $option, $attribs ) = @_;1380 my ( $self, $option, $attribs ) = @_;
1383 my $types = $self->{types};1381 my $types = $self->{types};
1384 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
1385 return $option1382 return $option
1386 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )1383 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
1387 . ($attribs->{'negatable'} ? '!' : '' )1384 . ($attribs->{'negatable'} ? '!' : '' )
1388 . ($attribs->{'cumulative'} ? '+' : '' )1385 . ($attribs->{'cumulative'} ? '+' : '' )
1389 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );1386 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
1390}1387}
13911388
1392sub _parse_synopsis {1389sub _parse_synopsis {
@@ -3166,14 +3163,19 @@
3166};3163};
31673164
3168sub version_check {3165sub version_check {
3169 my $args = pop @_;3166 my %args = @_;
3170 my (@instances) = @_;3167 my @instances = $args{instances} ? @{ $args{instances} } : ();
31713168
3172 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {3169 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
3173 print STDERR '--version-check is disabled by the PERCONA_VERSION_CHECK ',3170 warn '--version-check is disabled by the PERCONA_VERSION_CHECK ',
3174 "environment variable.\n\n";3171 "environment variable.\n\n";
3175 return;3172 return;
3176 }3173 }
3174
3175 $args{protocol} ||= 'https';
3176 my @protocols = $args{protocol} eq 'auto'
3177 ? qw(https http)
3178 : $args{protocol};
3177 3179
3178 my $instances_to_check = [];3180 my $instances_to_check = [];
3179 my $time = int(time());3181 my $time = int(time());
@@ -3188,22 +3190,28 @@
3188 ($time_to_check, $instances_to_check)3190 ($time_to_check, $instances_to_check)
3189 = time_to_check($check_time_file, \@instances, $time);3191 = time_to_check($check_time_file, \@instances, $time);
3190 if ( !$time_to_check ) {3192 if ( !$time_to_check ) {
3191 print STDERR 'It is not time to --version-check again; ',3193 warn 'It is not time to --version-check again; ',
3192 "only 1 check per day.\n\n";3194 "only 1 check per day.\n\n";
3193 return;3195 return;
3194 }3196 }
31953197
3196 my $protocol = $args->{protocol} || 'https';3198 my $advice;
3197 my $advice = pingback(3199 my $e;
3198 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",3200 for my $protocol ( @protocols ) {
3199 instances => $instances_to_check,3201 $advice = eval { pingback(
3200 protocol => $args->{protocol},3202 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
3201 );3203 instances => $instances_to_check,
3204 protocol => $protocol,
3205 ) };
3206 last if !$advice && !$EVAL_ERROR;
3207 $e ||= $EVAL_ERROR;
3208 }
3202 if ( $advice ) {3209 if ( $advice ) {
3203 print "# Percona suggests these upgrades:\n";3210 print "# Percona suggests these upgrades:\n";
3204 print join("\n", map { "# * $_" } @$advice), "\n\n";3211 print join("\n", map { "# * $_" } @$advice), "\n\n";
3205 }3212 }
3206 else {3213 else {
3214 die $e if $e;
3207 print "# No suggestions at this time.\n\n";3215 print "# No suggestions at this time.\n\n";
3208 ($ENV{PTVCDEBUG} || PTDEBUG )3216 ($ENV{PTVCDEBUG} || PTDEBUG )
3209 && _d('--version-check worked, but there were no suggestions');3217 && _d('--version-check worked, but there were no suggestions');
@@ -3229,7 +3237,7 @@
32293237
3230 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};3238 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};
32313239
3232 $ua ||= HTTPMicro->new( timeout => 2 );3240 $ua ||= HTTPMicro->new( timeout => 5 );
3233 $vc ||= VersionCheck->new();3241 $vc ||= VersionCheck->new();
32343242
3235 my $response = $ua->request('GET', $url);3243 my $response = $ua->request('GET', $url);
@@ -3445,6 +3453,21 @@
3445 return $client_response;3453 return $client_response;
3446}3454}
34473455
3456sub validate_options {
3457 my ($o) = @_;
3458
3459 return if !$o->got('version-check');
3460
3461 my $value = $o->get('version-check');
3462 my @values = split /, /,
3463 $o->read_para_after(__FILE__, qr/MAGIC_version_check/);
3464 chomp(@values);
3465
3466 return if grep { $value eq $_ } @values;
3467 $o->save_error("--version-check invalid value $value. Accepted values are "
3468 . join(", ", @values[0..$#values-1]) . " and $values[-1]" );
3469}
3470
3448sub _d {3471sub _d {
3449 my ($package, undef, $line) = caller 0;3472 my ($package, undef, $line) = caller 0;
3450 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }3473 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
@@ -3761,6 +3784,8 @@
3761 $o->save_error("--server-id regex doesn't capture digits with (\\d+)");3784 $o->save_error("--server-id regex doesn't capture digits with (\\d+)");
3762 }3785 }
37633786
3787 Pingback::validate_options($o);
3788
3764 $o->usage_or_errors();3789 $o->usage_or_errors();
37653790
3766 # Interpolate strings for printf and exec. At the same time discover whether3791 # Interpolate strings for printf and exec. At the same time discover whether
@@ -3860,10 +3885,10 @@
3860 # ########################################################################3885 # ########################################################################
3861 # Do the version-check3886 # Do the version-check
3862 # ########################################################################3887 # ########################################################################
3863 if ( $o->got('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) {3888 if ( $o->get('version-check') ne 'off' && (!$o->has('quiet') || !$o->get('quiet')) ) {
3864 Pingback::version_check(3889 Pingback::version_check(
3865 {dbh => $dbh, dsn => $dsn},3890 instances => [{dbh => $dbh, dsn => $dsn}],
3866 {protocol => $o->get('version-check')},3891 protocol => $o->get('version-check'),
3867 );3892 );
3868 }3893 }
38693894
@@ -4316,14 +4341,20 @@
43164341
4317=item --version-check4342=item --version-check
43184343
4319type: string; value_is_optional: yes; default: https4344type: string; default: off
43204345
4321Send program versions to Percona and print suggested upgrades and problems.4346Send program versions to Percona and print suggested upgrades and problems.
43224347Possible values for --version-check:
4323If specified without a value, it will use https by default; However, this4348
4324might fail if C<IO::Socket::SSL> is not installed on your system, in which4349=for comment ignore-pt-internal-value
4325case you may choose to use C<--version-check http>, which will forgo4350MAGIC_version_check
4326encryption but should work out of the box.4351
4352https, http, auto, off
4353
4354C<auto> first tries using C<https>, and resorts to C<http> if that fails.
4355Keep in mind that C<https> might not be available if
4356C<IO::Socket::SSL> is not installed on your system, although
4357C<--version-check http> should work everywhere.
43274358
4328The version check feature causes the tool to send and receive data from4359The version check feature causes the tool to send and receive data from
4329Percona over the web. The data contains program versions from the local4360Percona over the web. The data contains program versions from the local
43304361
=== modified file 'bin/pt-fingerprint'
--- bin/pt-fingerprint 2012-10-22 18:17:08 +0000
+++ bin/pt-fingerprint 2012-11-06 15:04:24 +0000
@@ -58,7 +58,6 @@
58 'default' => 1,58 'default' => 1,
59 'cumulative' => 1,59 'cumulative' => 1,
60 'negatable' => 1,60 'negatable' => 1,
61 'value_is_optional' => 1,
62 );61 );
6362
64 my $self = {63 my $self = {
@@ -300,10 +299,9 @@
300 $opt->{short} = undef;299 $opt->{short} = undef;
301 }300 }
302301
303 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;302 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
304 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;303 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
305 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;304 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
306 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
307305
308 $opt->{group} ||= 'default';306 $opt->{group} ||= 'default';
309 $self->{groups}->{ $opt->{group} }->{$long} = 1;307 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -439,7 +437,7 @@
439 if ( $opt->{is_cumulative} ) {437 if ( $opt->{is_cumulative} ) {
440 $opt->{value}++;438 $opt->{value}++;
441 }439 }
442 elsif ( !($opt->{optional_value} && !$val) ) {440 else {
443 $opt->{value} = $val;441 $opt->{value} = $val;
444 }442 }
445 $opt->{got} = 1;443 $opt->{got} = 1;
@@ -980,12 +978,11 @@
980sub _parse_attribs {978sub _parse_attribs {
981 my ( $self, $option, $attribs ) = @_;979 my ( $self, $option, $attribs ) = @_;
982 my $types = $self->{types};980 my $types = $self->{types};
983 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
984 return $option981 return $option
985 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )982 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
986 . ($attribs->{'negatable'} ? '!' : '' )983 . ($attribs->{'negatable'} ? '!' : '' )
987 . ($attribs->{'cumulative'} ? '+' : '' )984 . ($attribs->{'cumulative'} ? '+' : '' )
988 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );985 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
989}986}
990987
991sub _parse_synopsis {988sub _parse_synopsis {
992989
=== modified file 'bin/pt-fk-error-logger'
--- bin/pt-fk-error-logger 2012-10-31 09:18:34 +0000
+++ bin/pt-fk-error-logger 2012-11-06 15:04:24 +0000
@@ -82,7 +82,6 @@
82 'default' => 1,82 'default' => 1,
83 'cumulative' => 1,83 'cumulative' => 1,
84 'negatable' => 1,84 'negatable' => 1,
85 'value_is_optional' => 1,
86 );85 );
8786
88 my $self = {87 my $self = {
@@ -324,10 +323,9 @@
324 $opt->{short} = undef;323 $opt->{short} = undef;
325 }324 }
326325
327 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;326 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
328 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;327 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
329 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;328 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
330 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
331329
332 $opt->{group} ||= 'default';330 $opt->{group} ||= 'default';
333 $self->{groups}->{ $opt->{group} }->{$long} = 1;331 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -463,7 +461,7 @@
463 if ( $opt->{is_cumulative} ) {461 if ( $opt->{is_cumulative} ) {
464 $opt->{value}++;462 $opt->{value}++;
465 }463 }
466 elsif ( !($opt->{optional_value} && !$val) ) {464 else {
467 $opt->{value} = $val;465 $opt->{value} = $val;
468 }466 }
469 $opt->{got} = 1;467 $opt->{got} = 1;
@@ -1004,12 +1002,11 @@
1004sub _parse_attribs {1002sub _parse_attribs {
1005 my ( $self, $option, $attribs ) = @_;1003 my ( $self, $option, $attribs ) = @_;
1006 my $types = $self->{types};1004 my $types = $self->{types};
1007 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
1008 return $option1005 return $option
1009 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )1006 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
1010 . ($attribs->{'negatable'} ? '!' : '' )1007 . ($attribs->{'negatable'} ? '!' : '' )
1011 . ($attribs->{'cumulative'} ? '+' : '' )1008 . ($attribs->{'cumulative'} ? '+' : '' )
1012 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );1009 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
1013}1010}
10141011
1015sub _parse_synopsis {1012sub _parse_synopsis {
@@ -3105,14 +3102,19 @@
3105};3102};
31063103
3107sub version_check {3104sub version_check {
3108 my $args = pop @_;3105 my %args = @_;
3109 my (@instances) = @_;3106 my @instances = $args{instances} ? @{ $args{instances} } : ();
31103107
3111 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {3108 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
3112 print STDERR '--version-check is disabled by the PERCONA_VERSION_CHECK ',3109 warn '--version-check is disabled by the PERCONA_VERSION_CHECK ',
3113 "environment variable.\n\n";3110 "environment variable.\n\n";
3114 return;3111 return;
3115 }3112 }
3113
3114 $args{protocol} ||= 'https';
3115 my @protocols = $args{protocol} eq 'auto'
3116 ? qw(https http)
3117 : $args{protocol};
3116 3118
3117 my $instances_to_check = [];3119 my $instances_to_check = [];
3118 my $time = int(time());3120 my $time = int(time());
@@ -3127,22 +3129,28 @@
3127 ($time_to_check, $instances_to_check)3129 ($time_to_check, $instances_to_check)
3128 = time_to_check($check_time_file, \@instances, $time);3130 = time_to_check($check_time_file, \@instances, $time);
3129 if ( !$time_to_check ) {3131 if ( !$time_to_check ) {
3130 print STDERR 'It is not time to --version-check again; ',3132 warn 'It is not time to --version-check again; ',
3131 "only 1 check per day.\n\n";3133 "only 1 check per day.\n\n";
3132 return;3134 return;
3133 }3135 }
31343136
3135 my $protocol = $args->{protocol} || 'https';3137 my $advice;
3136 my $advice = pingback(3138 my $e;
3137 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",3139 for my $protocol ( @protocols ) {
3138 instances => $instances_to_check,3140 $advice = eval { pingback(
3139 protocol => $args->{protocol},3141 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
3140 );3142 instances => $instances_to_check,
3143 protocol => $protocol,
3144 ) };
3145 last if !$advice && !$EVAL_ERROR;
3146 $e ||= $EVAL_ERROR;
3147 }
3141 if ( $advice ) {3148 if ( $advice ) {
3142 print "# Percona suggests these upgrades:\n";3149 print "# Percona suggests these upgrades:\n";
3143 print join("\n", map { "# * $_" } @$advice), "\n\n";3150 print join("\n", map { "# * $_" } @$advice), "\n\n";
3144 }3151 }
3145 else {3152 else {
3153 die $e if $e;
3146 print "# No suggestions at this time.\n\n";3154 print "# No suggestions at this time.\n\n";
3147 ($ENV{PTVCDEBUG} || PTDEBUG )3155 ($ENV{PTVCDEBUG} || PTDEBUG )
3148 && _d('--version-check worked, but there were no suggestions');3156 && _d('--version-check worked, but there were no suggestions');
@@ -3168,7 +3176,7 @@
31683176
3169 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};3177 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};
31703178
3171 $ua ||= HTTPMicro->new( timeout => 2 );3179 $ua ||= HTTPMicro->new( timeout => 5 );
3172 $vc ||= VersionCheck->new();3180 $vc ||= VersionCheck->new();
31733181
3174 my $response = $ua->request('GET', $url);3182 my $response = $ua->request('GET', $url);
@@ -3384,6 +3392,21 @@
3384 return $client_response;3392 return $client_response;
3385}3393}
33863394
3395sub validate_options {
3396 my ($o) = @_;
3397
3398 return if !$o->got('version-check');
3399
3400 my $value = $o->get('version-check');
3401 my @values = split /, /,
3402 $o->read_para_after(__FILE__, qr/MAGIC_version_check/);
3403 chomp(@values);
3404
3405 return if grep { $value eq $_ } @values;
3406 $o->save_error("--version-check invalid value $value. Accepted values are "
3407 . join(", ", @values[0..$#values-1]) . " and $values[-1]" );
3408}
3409
3387sub _d {3410sub _d {
3388 my ($package, undef, $line) = caller 0;3411 my ($package, undef, $line) = caller 0;
3389 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }3412 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
@@ -3456,6 +3479,8 @@
3456 if ( $dst_dsn && !$dst_dsn->{t} ) {3479 if ( $dst_dsn && !$dst_dsn->{t} ) {
3457 $o->save_error("--dest requires a 't' (table) part");3480 $o->save_error("--dest requires a 't' (table) part");
3458 }3481 }
3482
3483 Pingback::validate_options($o);
3459 }3484 }
34603485
3461 $o->usage_or_errors();3486 $o->usage_or_errors();
@@ -3516,11 +3541,13 @@
3516 # ########################################################################3541 # ########################################################################
3517 # Do the version-check3542 # Do the version-check
3518 # ########################################################################3543 # ########################################################################
3519 if ( $o->got('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) {3544 if ( $o->get('version-check') ne 'off' && (!$o->has('quiet') || !$o->get('quiet')) ) {
3520 Pingback::version_check(3545 Pingback::version_check(
3521 { dbh => $dbh, dsn => $src_dsn },3546 instances => [
3522 ($dst_dbh ? { dbh => $dst_dbh, dsn => $dst_dsn } : ()),3547 { dbh => $dbh, dsn => $src_dsn },
3523 { protocol => $o->get('version-check') },3548 ($dst_dbh ? { dbh => $dst_dbh, dsn => $dst_dsn } : ())
3549 ],
3550 protocol => $o->get('version-check'),
3524 );3551 );
3525 }3552 }
35263553
@@ -3810,14 +3837,20 @@
38103837
3811=item --version-check3838=item --version-check
38123839
3813type: string; value_is_optional: yes; default: https3840type: string; default: off
38143841
3815Send program versions to Percona and print suggested upgrades and problems.3842Send program versions to Percona and print suggested upgrades and problems.
38163843Possible values for --version-check:
3817If specified without a value, it will use https by default; However, this3844
3818might fail if C<IO::Socket::SSL> is not installed on your system, in which3845=for comment ignore-pt-internal-value
3819case you may choose to use C<--version-check http>, which will forgo3846MAGIC_version_check
3820encryption but should work out of the box.3847
3848https, http, auto, off
3849
3850C<auto> first tries using C<https>, and resorts to C<http> if that fails.
3851Keep in mind that C<https> might not be available if
3852C<IO::Socket::SSL> is not installed on your system, although
3853C<--version-check http> should work everywhere.
38213854
3822The version check feature causes the tool to send and receive data from3855The version check feature causes the tool to send and receive data from
3823Percona over the web. The data contains program versions from the local3856Percona over the web. The data contains program versions from the local
38243857
=== modified file 'bin/pt-heartbeat'
--- bin/pt-heartbeat 2012-11-05 17:57:11 +0000
+++ bin/pt-heartbeat 2012-11-06 15:04:24 +0000
@@ -818,7 +818,6 @@
818 'default' => 1,818 'default' => 1,
819 'cumulative' => 1,819 'cumulative' => 1,
820 'negatable' => 1,820 'negatable' => 1,
821 'value_is_optional' => 1,
822 );821 );
823822
824 my $self = {823 my $self = {
@@ -1060,10 +1059,9 @@
1060 $opt->{short} = undef;1059 $opt->{short} = undef;
1061 }1060 }
10621061
1063 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;1062 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
1064 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;1063 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
1065 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;1064 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
1066 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
10671065
1068 $opt->{group} ||= 'default';1066 $opt->{group} ||= 'default';
1069 $self->{groups}->{ $opt->{group} }->{$long} = 1;1067 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -1199,7 +1197,7 @@
1199 if ( $opt->{is_cumulative} ) {1197 if ( $opt->{is_cumulative} ) {
1200 $opt->{value}++;1198 $opt->{value}++;
1201 }1199 }
1202 elsif ( !($opt->{optional_value} && !$val) ) {1200 else {
1203 $opt->{value} = $val;1201 $opt->{value} = $val;
1204 }1202 }
1205 $opt->{got} = 1;1203 $opt->{got} = 1;
@@ -1740,12 +1738,11 @@
1740sub _parse_attribs {1738sub _parse_attribs {
1741 my ( $self, $option, $attribs ) = @_;1739 my ( $self, $option, $attribs ) = @_;
1742 my $types = $self->{types};1740 my $types = $self->{types};
1743 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
1744 return $option1741 return $option
1745 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )1742 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
1746 . ($attribs->{'negatable'} ? '!' : '' )1743 . ($attribs->{'negatable'} ? '!' : '' )
1747 . ($attribs->{'cumulative'} ? '+' : '' )1744 . ($attribs->{'cumulative'} ? '+' : '' )
1748 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );1745 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
1749}1746}
17501747
1751sub _parse_synopsis {1748sub _parse_synopsis {
@@ -4250,14 +4247,19 @@
4250};4247};
42514248
4252sub version_check {4249sub version_check {
4253 my $args = pop @_;4250 my %args = @_;
4254 my (@instances) = @_;4251 my @instances = $args{instances} ? @{ $args{instances} } : ();
42554252
4256 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {4253 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
4257 print STDERR '--version-check is disabled by the PERCONA_VERSION_CHECK ',4254 warn '--version-check is disabled by the PERCONA_VERSION_CHECK ',
4258 "environment variable.\n\n";4255 "environment variable.\n\n";
4259 return;4256 return;
4260 }4257 }
4258
4259 $args{protocol} ||= 'https';
4260 my @protocols = $args{protocol} eq 'auto'
4261 ? qw(https http)
4262 : $args{protocol};
4261 4263
4262 my $instances_to_check = [];4264 my $instances_to_check = [];
4263 my $time = int(time());4265 my $time = int(time());
@@ -4272,22 +4274,28 @@
4272 ($time_to_check, $instances_to_check)4274 ($time_to_check, $instances_to_check)
4273 = time_to_check($check_time_file, \@instances, $time);4275 = time_to_check($check_time_file, \@instances, $time);
4274 if ( !$time_to_check ) {4276 if ( !$time_to_check ) {
4275 print STDERR 'It is not time to --version-check again; ',4277 warn 'It is not time to --version-check again; ',
4276 "only 1 check per day.\n\n";4278 "only 1 check per day.\n\n";
4277 return;4279 return;
4278 }4280 }
42794281
4280 my $protocol = $args->{protocol} || 'https';4282 my $advice;
4281 my $advice = pingback(4283 my $e;
4282 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",4284 for my $protocol ( @protocols ) {
4283 instances => $instances_to_check,4285 $advice = eval { pingback(
4284 protocol => $args->{protocol},4286 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
4285 );4287 instances => $instances_to_check,
4288 protocol => $protocol,
4289 ) };
4290 last if !$advice && !$EVAL_ERROR;
4291 $e ||= $EVAL_ERROR;
4292 }
4286 if ( $advice ) {4293 if ( $advice ) {
4287 print "# Percona suggests these upgrades:\n";4294 print "# Percona suggests these upgrades:\n";
4288 print join("\n", map { "# * $_" } @$advice), "\n\n";4295 print join("\n", map { "# * $_" } @$advice), "\n\n";
4289 }4296 }
4290 else {4297 else {
4298 die $e if $e;
4291 print "# No suggestions at this time.\n\n";4299 print "# No suggestions at this time.\n\n";
4292 ($ENV{PTVCDEBUG} || PTDEBUG )4300 ($ENV{PTVCDEBUG} || PTDEBUG )
4293 && _d('--version-check worked, but there were no suggestions');4301 && _d('--version-check worked, but there were no suggestions');
@@ -4313,7 +4321,7 @@
43134321
4314 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};4322 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};
43154323
4316 $ua ||= HTTPMicro->new( timeout => 2 );4324 $ua ||= HTTPMicro->new( timeout => 5 );
4317 $vc ||= VersionCheck->new();4325 $vc ||= VersionCheck->new();
43184326
4319 my $response = $ua->request('GET', $url);4327 my $response = $ua->request('GET', $url);
@@ -4529,6 +4537,21 @@
4529 return $client_response;4537 return $client_response;
4530}4538}
45314539
4540sub validate_options {
4541 my ($o) = @_;
4542
4543 return if !$o->got('version-check');
4544
4545 my $value = $o->get('version-check');
4546 my @values = split /, /,
4547 $o->read_para_after(__FILE__, qr/MAGIC_version_check/);
4548 chomp(@values);
4549
4550 return if grep { $value eq $_ } @values;
4551 $o->save_error("--version-check invalid value $value. Accepted values are "
4552 . join(", ", @values[0..$#values-1]) . " and $values[-1]" );
4553}
4554
4532sub _d {4555sub _d {
4533 my ($package, undef, $line) = caller 0;4556 my ($package, undef, $line) = caller 0;
4534 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }4557 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
@@ -4630,6 +4653,8 @@
4630 $o->save_error("Invalid --recursion-method: $EVAL_ERROR")4653 $o->save_error("Invalid --recursion-method: $EVAL_ERROR")
4631 }4654 }
46324655
4656 Pingback::validate_options($o);
4657
4633 $o->usage_or_errors();4658 $o->usage_or_errors();
46344659
4635 # ########################################################################4660 # ########################################################################
@@ -4980,8 +5005,11 @@
4980 # ########################################################################5005 # ########################################################################
4981 # Do the version-check5006 # Do the version-check
4982 # ########################################################################5007 # ########################################################################
4983 if ( $o->got('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) {5008 if ( $o->get('version-check') ne 'off' && (!$o->has('quiet') || !$o->get('quiet')) ) {
4984 Pingback::version_check({dbh => $dbh, dsn => $dsn}, { protocol => $o->get('version-check') });5009 Pingback::version_check(
5010 instances => [ {dbh => $dbh, dsn => $dsn} ],
5011 protocol => $o->get('version-check'),
5012 );
4985 }5013 }
49865014
4987 # ########################################################################5015 # ########################################################################
@@ -5713,14 +5741,20 @@
57135741
5714=item --version-check5742=item --version-check
57155743
5716type: string; value_is_optional: yes; default: https5744type: string; default: off
57175745
5718Send program versions to Percona and print suggested upgrades and problems.5746Send program versions to Percona and print suggested upgrades and problems.
57195747Possible values for --version-check:
5720If specified without a value, it will use https by default; However, this5748
5721might fail if C<IO::Socket::SSL> is not installed on your system, in which5749=for comment ignore-pt-internal-value
5722case you may choose to use C<--version-check http>, which will forgo5750MAGIC_version_check
5723encryption but should work out of the box.5751
5752https, http, auto, off
5753
5754C<auto> first tries using C<https>, and resorts to C<http> if that fails.
5755Keep in mind that C<https> might not be available if
5756C<IO::Socket::SSL> is not installed on your system, although
5757C<--version-check http> should work everywhere.
57245758
5725The version check feature causes the tool to send and receive data from5759The version check feature causes the tool to send and receive data from
5726Percona over the web. The data contains program versions from the local5760Percona over the web. The data contains program versions from the local
57275761
=== modified file 'bin/pt-index-usage'
--- bin/pt-index-usage 2012-11-05 17:57:11 +0000
+++ bin/pt-index-usage 2012-11-06 15:04:24 +0000
@@ -589,7 +589,6 @@
589 'default' => 1,589 'default' => 1,
590 'cumulative' => 1,590 'cumulative' => 1,
591 'negatable' => 1,591 'negatable' => 1,
592 'value_is_optional' => 1,
593 );592 );
594593
595 my $self = {594 my $self = {
@@ -831,10 +830,9 @@
831 $opt->{short} = undef;830 $opt->{short} = undef;
832 }831 }
833832
834 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;833 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
835 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;834 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
836 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;835 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
837 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
838836
839 $opt->{group} ||= 'default';837 $opt->{group} ||= 'default';
840 $self->{groups}->{ $opt->{group} }->{$long} = 1;838 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -970,7 +968,7 @@
970 if ( $opt->{is_cumulative} ) {968 if ( $opt->{is_cumulative} ) {
971 $opt->{value}++;969 $opt->{value}++;
972 }970 }
973 elsif ( !($opt->{optional_value} && !$val) ) {971 else {
974 $opt->{value} = $val;972 $opt->{value} = $val;
975 }973 }
976 $opt->{got} = 1;974 $opt->{got} = 1;
@@ -1511,12 +1509,11 @@
1511sub _parse_attribs {1509sub _parse_attribs {
1512 my ( $self, $option, $attribs ) = @_;1510 my ( $self, $option, $attribs ) = @_;
1513 my $types = $self->{types};1511 my $types = $self->{types};
1514 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
1515 return $option1512 return $option
1516 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )1513 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
1517 . ($attribs->{'negatable'} ? '!' : '' )1514 . ($attribs->{'negatable'} ? '!' : '' )
1518 . ($attribs->{'cumulative'} ? '+' : '' )1515 . ($attribs->{'cumulative'} ? '+' : '' )
1519 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );1516 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
1520}1517}
15211518
1522sub _parse_synopsis {1519sub _parse_synopsis {
@@ -5820,14 +5817,19 @@
5820};5817};
58215818
5822sub version_check {5819sub version_check {
5823 my $args = pop @_;5820 my %args = @_;
5824 my (@instances) = @_;5821 my @instances = $args{instances} ? @{ $args{instances} } : ();
58255822
5826 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {5823 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
5827 print STDERR '--version-check is disabled by the PERCONA_VERSION_CHECK ',5824 warn '--version-check is disabled by the PERCONA_VERSION_CHECK ',
5828 "environment variable.\n\n";5825 "environment variable.\n\n";
5829 return;5826 return;
5830 }5827 }
5828
5829 $args{protocol} ||= 'https';
5830 my @protocols = $args{protocol} eq 'auto'
5831 ? qw(https http)
5832 : $args{protocol};
5831 5833
5832 my $instances_to_check = [];5834 my $instances_to_check = [];
5833 my $time = int(time());5835 my $time = int(time());
@@ -5842,22 +5844,28 @@
5842 ($time_to_check, $instances_to_check)5844 ($time_to_check, $instances_to_check)
5843 = time_to_check($check_time_file, \@instances, $time);5845 = time_to_check($check_time_file, \@instances, $time);
5844 if ( !$time_to_check ) {5846 if ( !$time_to_check ) {
5845 print STDERR 'It is not time to --version-check again; ',5847 warn 'It is not time to --version-check again; ',
5846 "only 1 check per day.\n\n";5848 "only 1 check per day.\n\n";
5847 return;5849 return;
5848 }5850 }
58495851
5850 my $protocol = $args->{protocol} || 'https';5852 my $advice;
5851 my $advice = pingback(5853 my $e;
5852 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",5854 for my $protocol ( @protocols ) {
5853 instances => $instances_to_check,5855 $advice = eval { pingback(
5854 protocol => $args->{protocol},5856 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
5855 );5857 instances => $instances_to_check,
5858 protocol => $protocol,
5859 ) };
5860 last if !$advice && !$EVAL_ERROR;
5861 $e ||= $EVAL_ERROR;
5862 }
5856 if ( $advice ) {5863 if ( $advice ) {
5857 print "# Percona suggests these upgrades:\n";5864 print "# Percona suggests these upgrades:\n";
5858 print join("\n", map { "# * $_" } @$advice), "\n\n";5865 print join("\n", map { "# * $_" } @$advice), "\n\n";
5859 }5866 }
5860 else {5867 else {
5868 die $e if $e;
5861 print "# No suggestions at this time.\n\n";5869 print "# No suggestions at this time.\n\n";
5862 ($ENV{PTVCDEBUG} || PTDEBUG )5870 ($ENV{PTVCDEBUG} || PTDEBUG )
5863 && _d('--version-check worked, but there were no suggestions');5871 && _d('--version-check worked, but there were no suggestions');
@@ -5883,7 +5891,7 @@
58835891
5884 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};5892 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};
58855893
5886 $ua ||= HTTPMicro->new( timeout => 2 );5894 $ua ||= HTTPMicro->new( timeout => 5 );
5887 $vc ||= VersionCheck->new();5895 $vc ||= VersionCheck->new();
58885896
5889 my $response = $ua->request('GET', $url);5897 my $response = $ua->request('GET', $url);
@@ -6099,6 +6107,21 @@
6099 return $client_response;6107 return $client_response;
6100}6108}
61016109
6110sub validate_options {
6111 my ($o) = @_;
6112
6113 return if !$o->got('version-check');
6114
6115 my $value = $o->get('version-check');
6116 my @values = split /, /,
6117 $o->read_para_after(__FILE__, qr/MAGIC_version_check/);
6118 chomp(@values);
6119
6120 return if grep { $value eq $_ } @values;
6121 $o->save_error("--version-check invalid value $value. Accepted values are "
6122 . join(", ", @values[0..$#values-1]) . " and $values[-1]" );
6123}
6124
6102sub _d {6125sub _d {
6103 my ($package, undef, $line) = caller 0;6126 my ($package, undef, $line) = caller 0;
6104 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }6127 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
@@ -6168,6 +6191,8 @@
6168 . "--save-results-database DSN");6191 . "--save-results-database DSN");
6169 }6192 }
6170 }6193 }
6194
6195 Pingback::validate_options($o);
6171 }6196 }
61726197
6173 $o->usage_or_errors();6198 $o->usage_or_errors();
@@ -6311,11 +6336,13 @@
6311 # ########################################################################6336 # ########################################################################
6312 # Do the version-check6337 # Do the version-check
6313 # ########################################################################6338 # ########################################################################
6314 if ( $o->got('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) {6339 if ( $o->get('version-check') ne 'off' && (!$o->has('quiet') || !$o->get('quiet')) ) {
6315 Pingback::version_check(6340 Pingback::version_check(
6316 { dbh => $dbh, dsn => $dsn },6341 instances => [
6317 ($res_dbh ? { dbh => $res_dbh, dsn => $res_dsn } : ()),6342 { dbh => $dbh, dsn => $dsn },
6318 { protocol => $o->get('version-check') },6343 ($res_dbh ? { dbh => $res_dbh, dsn => $res_dsn } : ())
6344 ],
6345 protocol => $o->get('version-check'),
6319 );6346 );
6320 }6347 }
63216348
@@ -7230,14 +7257,20 @@
72307257
7231=item --version-check7258=item --version-check
72327259
7233type: string; value_is_optional: yes; default: https7260type: string; default: off
72347261
7235Send program versions to Percona and print suggested upgrades and problems.7262Send program versions to Percona and print suggested upgrades and problems.
72367263Possible values for --version-check:
7237If specified without a value, it will use https by default; However, this7264
7238might fail if C<IO::Socket::SSL> is not installed on your system, in which7265=for comment ignore-pt-internal-value
7239case you may choose to use C<--version-check http>, which will forgo7266MAGIC_version_check
7240encryption but should work out of the box.7267
7268https, http, auto, off
7269
7270C<auto> first tries using C<https>, and resorts to C<http> if that fails.
7271Keep in mind that C<https> might not be available if
7272C<IO::Socket::SSL> is not installed on your system, although
7273C<--version-check http> should work everywhere.
72417274
7242The version check feature causes the tool to send and receive data from7275The version check feature causes the tool to send and receive data from
7243Percona over the web. The data contains program versions from the local7276Percona over the web. The data contains program versions from the local
72447277
=== modified file 'bin/pt-kill'
--- bin/pt-kill 2012-11-05 17:57:11 +0000
+++ bin/pt-kill 2012-11-06 15:04:24 +0000
@@ -90,7 +90,6 @@
90 'default' => 1,90 'default' => 1,
91 'cumulative' => 1,91 'cumulative' => 1,
92 'negatable' => 1,92 'negatable' => 1,
93 'value_is_optional' => 1,
94 );93 );
9594
96 my $self = {95 my $self = {
@@ -332,10 +331,9 @@
332 $opt->{short} = undef;331 $opt->{short} = undef;
333 }332 }
334333
335 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;334 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
336 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;335 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
337 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;336 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
338 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
339337
340 $opt->{group} ||= 'default';338 $opt->{group} ||= 'default';
341 $self->{groups}->{ $opt->{group} }->{$long} = 1;339 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -471,7 +469,7 @@
471 if ( $opt->{is_cumulative} ) {469 if ( $opt->{is_cumulative} ) {
472 $opt->{value}++;470 $opt->{value}++;
473 }471 }
474 elsif ( !($opt->{optional_value} && !$val) ) {472 else {
475 $opt->{value} = $val;473 $opt->{value} = $val;
476 }474 }
477 $opt->{got} = 1;475 $opt->{got} = 1;
@@ -1012,12 +1010,11 @@
1012sub _parse_attribs {1010sub _parse_attribs {
1013 my ( $self, $option, $attribs ) = @_;1011 my ( $self, $option, $attribs ) = @_;
1014 my $types = $self->{types};1012 my $types = $self->{types};
1015 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
1016 return $option1013 return $option
1017 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )1014 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
1018 . ($attribs->{'negatable'} ? '!' : '' )1015 . ($attribs->{'negatable'} ? '!' : '' )
1019 . ($attribs->{'cumulative'} ? '+' : '' )1016 . ($attribs->{'cumulative'} ? '+' : '' )
1020 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );1017 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
1021}1018}
10221019
1023sub _parse_synopsis {1020sub _parse_synopsis {
@@ -5843,14 +5840,19 @@
5843};5840};
58445841
5845sub version_check {5842sub version_check {
5846 my $args = pop @_;5843 my %args = @_;
5847 my (@instances) = @_;5844 my @instances = $args{instances} ? @{ $args{instances} } : ();
58485845
5849 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {5846 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
5850 print STDERR '--version-check is disabled by the PERCONA_VERSION_CHECK ',5847 warn '--version-check is disabled by the PERCONA_VERSION_CHECK ',
5851 "environment variable.\n\n";5848 "environment variable.\n\n";
5852 return;5849 return;
5853 }5850 }
5851
5852 $args{protocol} ||= 'https';
5853 my @protocols = $args{protocol} eq 'auto'
5854 ? qw(https http)
5855 : $args{protocol};
5854 5856
5855 my $instances_to_check = [];5857 my $instances_to_check = [];
5856 my $time = int(time());5858 my $time = int(time());
@@ -5865,22 +5867,28 @@
5865 ($time_to_check, $instances_to_check)5867 ($time_to_check, $instances_to_check)
5866 = time_to_check($check_time_file, \@instances, $time);5868 = time_to_check($check_time_file, \@instances, $time);
5867 if ( !$time_to_check ) {5869 if ( !$time_to_check ) {
5868 print STDERR 'It is not time to --version-check again; ',5870 warn 'It is not time to --version-check again; ',
5869 "only 1 check per day.\n\n";5871 "only 1 check per day.\n\n";
5870 return;5872 return;
5871 }5873 }
58725874
5873 my $protocol = $args->{protocol} || 'https';5875 my $advice;
5874 my $advice = pingback(5876 my $e;
5875 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",5877 for my $protocol ( @protocols ) {
5876 instances => $instances_to_check,5878 $advice = eval { pingback(
5877 protocol => $args->{protocol},5879 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
5878 );5880 instances => $instances_to_check,
5881 protocol => $protocol,
5882 ) };
5883 last if !$advice && !$EVAL_ERROR;
5884 $e ||= $EVAL_ERROR;
5885 }
5879 if ( $advice ) {5886 if ( $advice ) {
5880 print "# Percona suggests these upgrades:\n";5887 print "# Percona suggests these upgrades:\n";
5881 print join("\n", map { "# * $_" } @$advice), "\n\n";5888 print join("\n", map { "# * $_" } @$advice), "\n\n";
5882 }5889 }
5883 else {5890 else {
5891 die $e if $e;
5884 print "# No suggestions at this time.\n\n";5892 print "# No suggestions at this time.\n\n";
5885 ($ENV{PTVCDEBUG} || PTDEBUG )5893 ($ENV{PTVCDEBUG} || PTDEBUG )
5886 && _d('--version-check worked, but there were no suggestions');5894 && _d('--version-check worked, but there were no suggestions');
@@ -5906,7 +5914,7 @@
59065914
5907 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};5915 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};
59085916
5909 $ua ||= HTTPMicro->new( timeout => 2 );5917 $ua ||= HTTPMicro->new( timeout => 5 );
5910 $vc ||= VersionCheck->new();5918 $vc ||= VersionCheck->new();
59115919
5912 my $response = $ua->request('GET', $url);5920 my $response = $ua->request('GET', $url);
@@ -6122,6 +6130,21 @@
6122 return $client_response;6130 return $client_response;
6123}6131}
61246132
6133sub validate_options {
6134 my ($o) = @_;
6135
6136 return if !$o->got('version-check');
6137
6138 my $value = $o->get('version-check');
6139 my @values = split /, /,
6140 $o->read_para_after(__FILE__, qr/MAGIC_version_check/);
6141 chomp(@values);
6142
6143 return if grep { $value eq $_ } @values;
6144 $o->save_error("--version-check invalid value $value. Accepted values are "
6145 . join(", ", @values[0..$#values-1]) . " and $values[-1]" );
6146}
6147
6125sub _d {6148sub _d {
6126 my ($package, undef, $line) = caller 0;6149 my ($package, undef, $line) = caller 0;
6127 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }6150 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
@@ -6205,6 +6228,8 @@
6205 $o->save_error("Invalid value for --victims: $victims");6228 $o->save_error("Invalid value for --victims: $victims");
6206 }6229 }
62076230
6231 Pingback::validate_options($o);
6232
6208 $o->usage_or_errors();6233 $o->usage_or_errors();
62096234
6210 # ########################################################################6235 # ########################################################################
@@ -6485,10 +6510,10 @@
6485 # ########################################################################6510 # ########################################################################
6486 # Do the version-check6511 # Do the version-check
6487 # ########################################################################6512 # ########################################################################
6488 if ( $o->got('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) {6513 if ( $o->get('version-check') ne 'off' && (!$o->has('quiet') || !$o->get('quiet')) ) {
6489 Pingback::version_check(6514 Pingback::version_check(
6490 ($dbh ? { dbh => $dbh, dsn => $cxn->dsn() } : ()),6515 instances => [ ($dbh ? { dbh => $dbh, dsn => $cxn->dsn() } : ()) ],
6491 { protocol => $o->get('version-check') },6516 protocol => $o->get('version-check'),
6492 );6517 );
6493 }6518 }
64946519
@@ -7219,14 +7244,20 @@
72197244
7220=item --version-check7245=item --version-check
72217246
7222type: string; value_is_optional: yes; default: https7247type: string; default: off
72237248
7224Send program versions to Percona and print suggested upgrades and problems.7249Send program versions to Percona and print suggested upgrades and problems.
72257250Possible values for --version-check:
7226If specified without a value, it will use https by default; However, this7251
7227might fail if C<IO::Socket::SSL> is not installed on your system, in which7252=for comment ignore-pt-internal-value
7228case you may choose to use C<--version-check http>, which will forgo7253MAGIC_version_check
7229encryption but should work out of the box.7254
7255https, http, auto, off
7256
7257C<auto> first tries using C<https>, and resorts to C<http> if that fails.
7258Keep in mind that C<https> might not be available if
7259C<IO::Socket::SSL> is not installed on your system, although
7260C<--version-check http> should work everywhere.
72307261
7231The version check feature causes the tool to send and receive data from7262The version check feature causes the tool to send and receive data from
7232Percona over the web. The data contains program versions from the local7263Percona over the web. The data contains program versions from the local
72337264
=== modified file 'bin/pt-log-player'
--- bin/pt-log-player 2012-10-31 09:18:34 +0000
+++ bin/pt-log-player 2012-11-06 15:04:24 +0000
@@ -62,7 +62,6 @@
62 'default' => 1,62 'default' => 1,
63 'cumulative' => 1,63 'cumulative' => 1,
64 'negatable' => 1,64 'negatable' => 1,
65 'value_is_optional' => 1,
66 );65 );
6766
68 my $self = {67 my $self = {
@@ -304,10 +303,9 @@
304 $opt->{short} = undef;303 $opt->{short} = undef;
305 }304 }
306305
307 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;306 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
308 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;307 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
309 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;308 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
310 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
311309
312 $opt->{group} ||= 'default';310 $opt->{group} ||= 'default';
313 $self->{groups}->{ $opt->{group} }->{$long} = 1;311 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -443,7 +441,7 @@
443 if ( $opt->{is_cumulative} ) {441 if ( $opt->{is_cumulative} ) {
444 $opt->{value}++;442 $opt->{value}++;
445 }443 }
446 elsif ( !($opt->{optional_value} && !$val) ) {444 else {
447 $opt->{value} = $val;445 $opt->{value} = $val;
448 }446 }
449 $opt->{got} = 1;447 $opt->{got} = 1;
@@ -984,12 +982,11 @@
984sub _parse_attribs {982sub _parse_attribs {
985 my ( $self, $option, $attribs ) = @_;983 my ( $self, $option, $attribs ) = @_;
986 my $types = $self->{types};984 my $types = $self->{types};
987 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
988 return $option985 return $option
989 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )986 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
990 . ($attribs->{'negatable'} ? '!' : '' )987 . ($attribs->{'negatable'} ? '!' : '' )
991 . ($attribs->{'cumulative'} ? '+' : '' )988 . ($attribs->{'cumulative'} ? '+' : '' )
992 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );989 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
993}990}
994991
995sub _parse_synopsis {992sub _parse_synopsis {
996993
=== modified file 'bin/pt-online-schema-change'
--- bin/pt-online-schema-change 2012-11-05 17:57:11 +0000
+++ bin/pt-online-schema-change 2012-11-06 15:04:24 +0000
@@ -96,7 +96,6 @@
96 'default' => 1,96 'default' => 1,
97 'cumulative' => 1,97 'cumulative' => 1,
98 'negatable' => 1,98 'negatable' => 1,
99 'value_is_optional' => 1,
100 );99 );
101100
102 my $self = {101 my $self = {
@@ -338,10 +337,9 @@
338 $opt->{short} = undef;337 $opt->{short} = undef;
339 }338 }
340339
341 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;340 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
342 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;341 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
343 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;342 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
344 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
345343
346 $opt->{group} ||= 'default';344 $opt->{group} ||= 'default';
347 $self->{groups}->{ $opt->{group} }->{$long} = 1;345 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -477,7 +475,7 @@
477 if ( $opt->{is_cumulative} ) {475 if ( $opt->{is_cumulative} ) {
478 $opt->{value}++;476 $opt->{value}++;
479 }477 }
480 elsif ( !($opt->{optional_value} && !$val) ) {478 else {
481 $opt->{value} = $val;479 $opt->{value} = $val;
482 }480 }
483 $opt->{got} = 1;481 $opt->{got} = 1;
@@ -1018,12 +1016,11 @@
1018sub _parse_attribs {1016sub _parse_attribs {
1019 my ( $self, $option, $attribs ) = @_;1017 my ( $self, $option, $attribs ) = @_;
1020 my $types = $self->{types};1018 my $types = $self->{types};
1021 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
1022 return $option1019 return $option
1023 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )1020 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
1024 . ($attribs->{'negatable'} ? '!' : '' )1021 . ($attribs->{'negatable'} ? '!' : '' )
1025 . ($attribs->{'cumulative'} ? '+' : '' )1022 . ($attribs->{'cumulative'} ? '+' : '' )
1026 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );1023 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
1027}1024}
10281025
1029sub _parse_synopsis {1026sub _parse_synopsis {
@@ -6865,14 +6862,19 @@
6865};6862};
68666863
6867sub version_check {6864sub version_check {
6868 my $args = pop @_;6865 my %args = @_;
6869 my (@instances) = @_;6866 my @instances = $args{instances} ? @{ $args{instances} } : ();
68706867
6871 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {6868 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
6872 print STDERR '--version-check is disabled by the PERCONA_VERSION_CHECK ',6869 warn '--version-check is disabled by the PERCONA_VERSION_CHECK ',
6873 "environment variable.\n\n";6870 "environment variable.\n\n";
6874 return;6871 return;
6875 }6872 }
6873
6874 $args{protocol} ||= 'https';
6875 my @protocols = $args{protocol} eq 'auto'
6876 ? qw(https http)
6877 : $args{protocol};
6876 6878
6877 my $instances_to_check = [];6879 my $instances_to_check = [];
6878 my $time = int(time());6880 my $time = int(time());
@@ -6887,22 +6889,28 @@
6887 ($time_to_check, $instances_to_check)6889 ($time_to_check, $instances_to_check)
6888 = time_to_check($check_time_file, \@instances, $time);6890 = time_to_check($check_time_file, \@instances, $time);
6889 if ( !$time_to_check ) {6891 if ( !$time_to_check ) {
6890 print STDERR 'It is not time to --version-check again; ',6892 warn 'It is not time to --version-check again; ',
6891 "only 1 check per day.\n\n";6893 "only 1 check per day.\n\n";
6892 return;6894 return;
6893 }6895 }
68946896
6895 my $protocol = $args->{protocol} || 'https';6897 my $advice;
6896 my $advice = pingback(6898 my $e;
6897 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",6899 for my $protocol ( @protocols ) {
6898 instances => $instances_to_check,6900 $advice = eval { pingback(
6899 protocol => $args->{protocol},6901 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
6900 );6902 instances => $instances_to_check,
6903 protocol => $protocol,
6904 ) };
6905 last if !$advice && !$EVAL_ERROR;
6906 $e ||= $EVAL_ERROR;
6907 }
6901 if ( $advice ) {6908 if ( $advice ) {
6902 print "# Percona suggests these upgrades:\n";6909 print "# Percona suggests these upgrades:\n";
6903 print join("\n", map { "# * $_" } @$advice), "\n\n";6910 print join("\n", map { "# * $_" } @$advice), "\n\n";
6904 }6911 }
6905 else {6912 else {
6913 die $e if $e;
6906 print "# No suggestions at this time.\n\n";6914 print "# No suggestions at this time.\n\n";
6907 ($ENV{PTVCDEBUG} || PTDEBUG )6915 ($ENV{PTVCDEBUG} || PTDEBUG )
6908 && _d('--version-check worked, but there were no suggestions');6916 && _d('--version-check worked, but there were no suggestions');
@@ -6928,7 +6936,7 @@
69286936
6929 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};6937 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};
69306938
6931 $ua ||= HTTPMicro->new( timeout => 2 );6939 $ua ||= HTTPMicro->new( timeout => 5 );
6932 $vc ||= VersionCheck->new();6940 $vc ||= VersionCheck->new();
69336941
6934 my $response = $ua->request('GET', $url);6942 my $response = $ua->request('GET', $url);
@@ -7144,6 +7152,21 @@
7144 return $client_response;7152 return $client_response;
7145}7153}
71467154
7155sub validate_options {
7156 my ($o) = @_;
7157
7158 return if !$o->got('version-check');
7159
7160 my $value = $o->get('version-check');
7161 my @values = split /, /,
7162 $o->read_para_after(__FILE__, qr/MAGIC_version_check/);
7163 chomp(@values);
7164
7165 return if grep { $value eq $_ } @values;
7166 $o->save_error("--version-check invalid value $value. Accepted values are "
7167 . join(", ", @values[0..$#values-1]) . " and $values[-1]" );
7168}
7169
7147sub _d {7170sub _d {
7148 my ($package, undef, $line) = caller 0;7171 my ($package, undef, $line) = caller 0;
7149 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }7172 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
@@ -7293,6 +7316,8 @@
7293 $o->save_error("Invalid --recursion-method: $EVAL_ERROR")7316 $o->save_error("Invalid --recursion-method: $EVAL_ERROR")
7294 }7317 }
72957318
7319 Pingback::validate_options($o);
7320
7296 $o->usage_or_errors(); 7321 $o->usage_or_errors();
72977322
7298 if ( $o->get('quiet') ) {7323 if ( $o->get('quiet') ) {
@@ -7546,11 +7571,11 @@
7546 # ########################################################################7571 # ########################################################################
7547 # Do the version-check7572 # Do the version-check
7548 # ########################################################################7573 # ########################################################################
7549 if ( $o->got('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) {7574 if ( $o->get('version-check') ne 'off' && (!$o->has('quiet') || !$o->get('quiet')) ) {
7550 Pingback::version_check(7575 Pingback::version_check(
7551 map({ +{ dbh => $_->dbh(), dsn => $_->dsn() } }7576 instances => [ map({ +{ dbh => $_->dbh(), dsn => $_->dsn() } }
7552 $cxn, ($slaves ? @$slaves : ())),7577 $cxn, ($slaves ? @$slaves : ())) ],
7553 { protocol => $o->get('version-check') },7578 protocol => $o->get('version-check'),
7554 );7579 );
7555 }7580 }
7556 7581
@@ -9881,14 +9906,20 @@
98819906
9882=item --version-check9907=item --version-check
98839908
9884type: string; value_is_optional: yes; default: https9909type: string; default: off
98859910
9886Send program versions to Percona and print suggested upgrades and problems.9911Send program versions to Percona and print suggested upgrades and problems.
98879912Possible values for --version-check:
9888If specified without a value, it will use https by default; However, this9913
9889might fail if C<IO::Socket::SSL> is not installed on your system, in which9914=for comment ignore-pt-internal-value
9890case you may choose to use C<--version-check http>, which will forgo9915MAGIC_version_check
9891encryption but should work out of the box.9916
9917https, http, auto, off
9918
9919C<auto> first tries using C<https>, and resorts to C<http> if that fails.
9920Keep in mind that C<https> might not be available if
9921C<IO::Socket::SSL> is not installed on your system, although
9922C<--version-check http> should work everywhere.
98929923
9893The version check feature causes the tool to send and receive data from9924The version check feature causes the tool to send and receive data from
9894Percona over the web. The data contains program versions from the local9925Percona over the web. The data contains program versions from the local
98959926
=== modified file 'bin/pt-query-advisor'
--- bin/pt-query-advisor 2012-11-05 17:57:11 +0000
+++ bin/pt-query-advisor 2012-11-06 15:04:24 +0000
@@ -470,7 +470,6 @@
470 'default' => 1,470 'default' => 1,
471 'cumulative' => 1,471 'cumulative' => 1,
472 'negatable' => 1,472 'negatable' => 1,
473 'value_is_optional' => 1,
474 );473 );
475474
476 my $self = {475 my $self = {
@@ -712,10 +711,9 @@
712 $opt->{short} = undef;711 $opt->{short} = undef;
713 }712 }
714713
715 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;714 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
716 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;715 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
717 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;716 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
718 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
719717
720 $opt->{group} ||= 'default';718 $opt->{group} ||= 'default';
721 $self->{groups}->{ $opt->{group} }->{$long} = 1;719 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -851,7 +849,7 @@
851 if ( $opt->{is_cumulative} ) {849 if ( $opt->{is_cumulative} ) {
852 $opt->{value}++;850 $opt->{value}++;
853 }851 }
854 elsif ( !($opt->{optional_value} && !$val) ) {852 else {
855 $opt->{value} = $val;853 $opt->{value} = $val;
856 }854 }
857 $opt->{got} = 1;855 $opt->{got} = 1;
@@ -1392,12 +1390,11 @@
1392sub _parse_attribs {1390sub _parse_attribs {
1393 my ( $self, $option, $attribs ) = @_;1391 my ( $self, $option, $attribs ) = @_;
1394 my $types = $self->{types};1392 my $types = $self->{types};
1395 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
1396 return $option1393 return $option
1397 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )1394 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
1398 . ($attribs->{'negatable'} ? '!' : '' )1395 . ($attribs->{'negatable'} ? '!' : '' )
1399 . ($attribs->{'cumulative'} ? '+' : '' )1396 . ($attribs->{'cumulative'} ? '+' : '' )
1400 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );1397 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
1401}1398}
14021399
1403sub _parse_synopsis {1400sub _parse_synopsis {
@@ -7017,14 +7014,19 @@
7017};7014};
70187015
7019sub version_check {7016sub version_check {
7020 my $args = pop @_;7017 my %args = @_;
7021 my (@instances) = @_;7018 my @instances = $args{instances} ? @{ $args{instances} } : ();
70227019
7023 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {7020 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
7024 print STDERR '--version-check is disabled by the PERCONA_VERSION_CHECK ',7021 warn '--version-check is disabled by the PERCONA_VERSION_CHECK ',
7025 "environment variable.\n\n";7022 "environment variable.\n\n";
7026 return;7023 return;
7027 }7024 }
7025
7026 $args{protocol} ||= 'https';
7027 my @protocols = $args{protocol} eq 'auto'
7028 ? qw(https http)
7029 : $args{protocol};
7028 7030
7029 my $instances_to_check = [];7031 my $instances_to_check = [];
7030 my $time = int(time());7032 my $time = int(time());
@@ -7039,22 +7041,28 @@
7039 ($time_to_check, $instances_to_check)7041 ($time_to_check, $instances_to_check)
7040 = time_to_check($check_time_file, \@instances, $time);7042 = time_to_check($check_time_file, \@instances, $time);
7041 if ( !$time_to_check ) {7043 if ( !$time_to_check ) {
7042 print STDERR 'It is not time to --version-check again; ',7044 warn 'It is not time to --version-check again; ',
7043 "only 1 check per day.\n\n";7045 "only 1 check per day.\n\n";
7044 return;7046 return;
7045 }7047 }
70467048
7047 my $protocol = $args->{protocol} || 'https';7049 my $advice;
7048 my $advice = pingback(7050 my $e;
7049 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",7051 for my $protocol ( @protocols ) {
7050 instances => $instances_to_check,7052 $advice = eval { pingback(
7051 protocol => $args->{protocol},7053 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
7052 );7054 instances => $instances_to_check,
7055 protocol => $protocol,
7056 ) };
7057 last if !$advice && !$EVAL_ERROR;
7058 $e ||= $EVAL_ERROR;
7059 }
7053 if ( $advice ) {7060 if ( $advice ) {
7054 print "# Percona suggests these upgrades:\n";7061 print "# Percona suggests these upgrades:\n";
7055 print join("\n", map { "# * $_" } @$advice), "\n\n";7062 print join("\n", map { "# * $_" } @$advice), "\n\n";
7056 }7063 }
7057 else {7064 else {
7065 die $e if $e;
7058 print "# No suggestions at this time.\n\n";7066 print "# No suggestions at this time.\n\n";
7059 ($ENV{PTVCDEBUG} || PTDEBUG )7067 ($ENV{PTVCDEBUG} || PTDEBUG )
7060 && _d('--version-check worked, but there were no suggestions');7068 && _d('--version-check worked, but there were no suggestions');
@@ -7080,7 +7088,7 @@
70807088
7081 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};7089 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};
70827090
7083 $ua ||= HTTPMicro->new( timeout => 2 );7091 $ua ||= HTTPMicro->new( timeout => 5 );
7084 $vc ||= VersionCheck->new();7092 $vc ||= VersionCheck->new();
70857093
7086 my $response = $ua->request('GET', $url);7094 my $response = $ua->request('GET', $url);
@@ -7296,6 +7304,21 @@
7296 return $client_response;7304 return $client_response;
7297}7305}
72987306
7307sub validate_options {
7308 my ($o) = @_;
7309
7310 return if !$o->got('version-check');
7311
7312 my $value = $o->get('version-check');
7313 my @values = split /, /,
7314 $o->read_para_after(__FILE__, qr/MAGIC_version_check/);
7315 chomp(@values);
7316
7317 return if grep { $value eq $_ } @values;
7318 $o->save_error("--version-check invalid value $value. Accepted values are "
7319 . join(", ", @values[0..$#values-1]) . " and $values[-1]" );
7320}
7321
7299sub _d {7322sub _d {
7300 my ($package, undef, $line) = caller 0;7323 my ($package, undef, $line) = caller 0;
7301 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }7324 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
@@ -7373,6 +7396,8 @@
7373 $o->save_error("Invalid --group-by value. Valid values are: "7396 $o->save_error("Invalid --group-by value. Valid values are: "
7374 . "rule_id, query_id, none");7397 . "rule_id, query_id, none");
7375 }7398 }
7399
7400 Pingback::validate_options($o);
7376 }7401 }
73777402
7378 $o->usage_or_errors();7403 $o->usage_or_errors();
@@ -7702,11 +7727,13 @@
7702 # ########################################################################7727 # ########################################################################
7703 # Do the version-check7728 # Do the version-check
7704 # ########################################################################7729 # ########################################################################
7705 if ( $o->got('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) {7730 if ( $o->get('version-check') ne 'off' && (!$o->has('quiet') || !$o->get('quiet')) ) {
7706 Pingback::version_check(7731 Pingback::version_check(
7707 ($review_dbh ? { dbh => $review_dbh, dsn => $review_dsn } : ()),7732 instances => [
7708 ($dbh ? { dbh => $dbh, dsn => $dsn } : ()),7733 ($review_dbh ? { dbh => $review_dbh, dsn => $review_dsn } : ()),
7709 { protocol => $o->get('version-check') },7734 ($dbh ? { dbh => $dbh, dsn => $dsn } : ()),
7735 ],
7736 protocol => $o->get('version-check'),
7710 );7737 );
7711 }7738 }
77127739
@@ -8479,14 +8506,20 @@
84798506
8480=item --version-check8507=item --version-check
84818508
8482type: string; value_is_optional: yes; default: https8509type: string; default: off
84838510
8484Send program versions to Percona and print suggested upgrades and problems.8511Send program versions to Percona and print suggested upgrades and problems.
84858512Possible values for --version-check:
8486If specified without a value, it will use https by default; However, this8513
8487might fail if C<IO::Socket::SSL> is not installed on your system, in which8514=for comment ignore-pt-internal-value
8488case you may choose to use C<--version-check http>, which will forgo8515MAGIC_version_check
8489encryption but should work out of the box.8516
8517https, http, auto, off
8518
8519C<auto> first tries using C<https>, and resorts to C<http> if that fails.
8520Keep in mind that C<https> might not be available if
8521C<IO::Socket::SSL> is not installed on your system, although
8522C<--version-check http> should work everywhere.
84908523
8491The version check feature causes the tool to send and receive data from8524The version check feature causes the tool to send and receive data from
8492Percona over the web. The data contains program versions from the local8525Percona over the web. The data contains program versions from the local
84938526
=== modified file 'bin/pt-query-digest'
--- bin/pt-query-digest 2012-11-05 17:57:11 +0000
+++ bin/pt-query-digest 2012-11-06 15:04:24 +0000
@@ -608,7 +608,6 @@
608 'default' => 1,608 'default' => 1,
609 'cumulative' => 1,609 'cumulative' => 1,
610 'negatable' => 1,610 'negatable' => 1,
611 'value_is_optional' => 1,
612 );611 );
613612
614 my $self = {613 my $self = {
@@ -850,10 +849,9 @@
850 $opt->{short} = undef;849 $opt->{short} = undef;
851 }850 }
852851
853 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;852 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
854 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;853 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
855 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;854 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
856 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
857855
858 $opt->{group} ||= 'default';856 $opt->{group} ||= 'default';
859 $self->{groups}->{ $opt->{group} }->{$long} = 1;857 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -989,7 +987,7 @@
989 if ( $opt->{is_cumulative} ) {987 if ( $opt->{is_cumulative} ) {
990 $opt->{value}++;988 $opt->{value}++;
991 }989 }
992 elsif ( !($opt->{optional_value} && !$val) ) {990 else {
993 $opt->{value} = $val;991 $opt->{value} = $val;
994 }992 }
995 $opt->{got} = 1;993 $opt->{got} = 1;
@@ -1530,12 +1528,11 @@
1530sub _parse_attribs {1528sub _parse_attribs {
1531 my ( $self, $option, $attribs ) = @_;1529 my ( $self, $option, $attribs ) = @_;
1532 my $types = $self->{types};1530 my $types = $self->{types};
1533 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
1534 return $option1531 return $option
1535 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )1532 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
1536 . ($attribs->{'negatable'} ? '!' : '' )1533 . ($attribs->{'negatable'} ? '!' : '' )
1537 . ($attribs->{'cumulative'} ? '+' : '' )1534 . ($attribs->{'cumulative'} ? '+' : '' )
1538 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );1535 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
1539}1536}
15401537
1541sub _parse_synopsis {1538sub _parse_synopsis {
@@ -12947,14 +12944,19 @@
12947};12944};
1294812945
12949sub version_check {12946sub version_check {
12950 my $args = pop @_;12947 my %args = @_;
12951 my (@instances) = @_;12948 my @instances = $args{instances} ? @{ $args{instances} } : ();
1295212949
12953 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {12950 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
12954 print STDERR '--version-check is disabled by the PERCONA_VERSION_CHECK ',12951 warn '--version-check is disabled by the PERCONA_VERSION_CHECK ',
12955 "environment variable.\n\n";12952 "environment variable.\n\n";
12956 return;12953 return;
12957 }12954 }
12955
12956 $args{protocol} ||= 'https';
12957 my @protocols = $args{protocol} eq 'auto'
12958 ? qw(https http)
12959 : $args{protocol};
12958 12960
12959 my $instances_to_check = [];12961 my $instances_to_check = [];
12960 my $time = int(time());12962 my $time = int(time());
@@ -12969,22 +12971,28 @@
12969 ($time_to_check, $instances_to_check)12971 ($time_to_check, $instances_to_check)
12970 = time_to_check($check_time_file, \@instances, $time);12972 = time_to_check($check_time_file, \@instances, $time);
12971 if ( !$time_to_check ) {12973 if ( !$time_to_check ) {
12972 print STDERR 'It is not time to --version-check again; ',12974 warn 'It is not time to --version-check again; ',
12973 "only 1 check per day.\n\n";12975 "only 1 check per day.\n\n";
12974 return;12976 return;
12975 }12977 }
1297612978
12977 my $protocol = $args->{protocol} || 'https';12979 my $advice;
12978 my $advice = pingback(12980 my $e;
12979 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",12981 for my $protocol ( @protocols ) {
12980 instances => $instances_to_check,12982 $advice = eval { pingback(
12981 protocol => $args->{protocol},12983 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
12982 );12984 instances => $instances_to_check,
12985 protocol => $protocol,
12986 ) };
12987 last if !$advice && !$EVAL_ERROR;
12988 $e ||= $EVAL_ERROR;
12989 }
12983 if ( $advice ) {12990 if ( $advice ) {
12984 print "# Percona suggests these upgrades:\n";12991 print "# Percona suggests these upgrades:\n";
12985 print join("\n", map { "# * $_" } @$advice), "\n\n";12992 print join("\n", map { "# * $_" } @$advice), "\n\n";
12986 }12993 }
12987 else {12994 else {
12995 die $e if $e;
12988 print "# No suggestions at this time.\n\n";12996 print "# No suggestions at this time.\n\n";
12989 ($ENV{PTVCDEBUG} || PTDEBUG )12997 ($ENV{PTVCDEBUG} || PTDEBUG )
12990 && _d('--version-check worked, but there were no suggestions');12998 && _d('--version-check worked, but there were no suggestions');
@@ -13010,7 +13018,7 @@
1301013018
13011 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};13019 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};
1301213020
13013 $ua ||= HTTPMicro->new( timeout => 2 );13021 $ua ||= HTTPMicro->new( timeout => 5 );
13014 $vc ||= VersionCheck->new();13022 $vc ||= VersionCheck->new();
1301513023
13016 my $response = $ua->request('GET', $url);13024 my $response = $ua->request('GET', $url);
@@ -13226,6 +13234,21 @@
13226 return $client_response;13234 return $client_response;
13227}13235}
1322813236
13237sub validate_options {
13238 my ($o) = @_;
13239
13240 return if !$o->got('version-check');
13241
13242 my $value = $o->get('version-check');
13243 my @values = split /, /,
13244 $o->read_para_after(__FILE__, qr/MAGIC_version_check/);
13245 chomp(@values);
13246
13247 return if grep { $value eq $_ } @values;
13248 $o->save_error("--version-check invalid value $value. Accepted values are "
13249 . join(", ", @values[0..$#values-1]) . " and $values[-1]" );
13250}
13251
13229sub _d {13252sub _d {
13230 my ($package, undef, $line) = caller 0;13253 my ($package, undef, $line) = caller 0;
13231 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }13254 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
@@ -13373,6 +13396,8 @@
13373 $o->save_error($EVAL_ERROR);13396 $o->save_error($EVAL_ERROR);
13374 }13397 }
1337513398
13399 Pingback::validate_options($o);
13400
13376 $o->usage_or_errors();13401 $o->usage_or_errors();
1337713402
13378 # ########################################################################13403 # ########################################################################
@@ -14583,12 +14608,14 @@
14583 # ########################################################################14608 # ########################################################################
14584 # Do the version-check14609 # Do the version-check
14585 # ########################################################################14610 # ########################################################################
14586 if ( $o->got('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) {14611 if ( $o->get('version-check') ne 'off' && (!$o->has('quiet') || !$o->get('quiet')) ) {
14587 Pingback::version_check(14612 Pingback::version_check(
14588 ($qv_dbh ? { dbh => $qv_dbh, dsn => $review_dsn } : ()),14613 instances => [
14589 ($ps_dbh ? { dbh => $ps_dbh, dsn => $ps_dsn } : ()),14614 ($qv_dbh ? { dbh => $qv_dbh, dsn => $review_dsn } : ()),
14590 ($ex_dbh ? { dbh => $ex_dbh, dsn => $ex_dsn } : ()),14615 ($ps_dbh ? { dbh => $ps_dbh, dsn => $ps_dsn } : ()),
14591 { protocol => $o->get('version-check') },14616 ($ex_dbh ? { dbh => $ex_dbh, dsn => $ex_dsn } : ())
14617 ],
14618 protocol => $o->get('version-check'),
14592 );14619 );
14593 }14620 }
1459414621
@@ -16974,14 +17001,20 @@
1697417001
16975=item --version-check17002=item --version-check
1697617003
16977type: string; value_is_optional: yes; default: https17004type: string; default: off
1697817005
16979Send program versions to Percona and print suggested upgrades and problems.17006Send program versions to Percona and print suggested upgrades and problems.
1698017007Possible values for --version-check:
16981If specified without a value, it will use https by default; However, this17008
16982might fail if C<IO::Socket::SSL> is not installed on your system, in which17009=for comment ignore-pt-internal-value
16983case you may choose to use C<--version-check http>, which will forgo17010MAGIC_version_check
16984encryption but should work out of the box.17011
17012https, http, auto, off
17013
17014C<auto> first tries using C<https>, and resorts to C<http> if that fails.
17015Keep in mind that C<https> might not be available if
17016C<IO::Socket::SSL> is not installed on your system, although
17017C<--version-check http> should work everywhere.
1698517018
16986The version check feature causes the tool to send and receive data from17019The version check feature causes the tool to send and receive data from
16987Percona over the web. The data contains program versions from the local17020Percona over the web. The data contains program versions from the local
1698817021
=== modified file 'bin/pt-show-grants'
--- bin/pt-show-grants 2012-11-01 09:15:54 +0000
+++ bin/pt-show-grants 2012-11-06 15:04:24 +0000
@@ -58,7 +58,6 @@
58 'default' => 1,58 'default' => 1,
59 'cumulative' => 1,59 'cumulative' => 1,
60 'negatable' => 1,60 'negatable' => 1,
61 'value_is_optional' => 1,
62 );61 );
6362
64 my $self = {63 my $self = {
@@ -300,10 +299,9 @@
300 $opt->{short} = undef;299 $opt->{short} = undef;
301 }300 }
302301
303 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;302 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
304 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;303 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
305 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;304 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
306 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
307305
308 $opt->{group} ||= 'default';306 $opt->{group} ||= 'default';
309 $self->{groups}->{ $opt->{group} }->{$long} = 1;307 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -439,7 +437,7 @@
439 if ( $opt->{is_cumulative} ) {437 if ( $opt->{is_cumulative} ) {
440 $opt->{value}++;438 $opt->{value}++;
441 }439 }
442 elsif ( !($opt->{optional_value} && !$val) ) {440 else {
443 $opt->{value} = $val;441 $opt->{value} = $val;
444 }442 }
445 $opt->{got} = 1;443 $opt->{got} = 1;
@@ -980,12 +978,11 @@
980sub _parse_attribs {978sub _parse_attribs {
981 my ( $self, $option, $attribs ) = @_;979 my ( $self, $option, $attribs ) = @_;
982 my $types = $self->{types};980 my $types = $self->{types};
983 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
984 return $option981 return $option
985 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )982 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
986 . ($attribs->{'negatable'} ? '!' : '' )983 . ($attribs->{'negatable'} ? '!' : '' )
987 . ($attribs->{'cumulative'} ? '+' : '' )984 . ($attribs->{'cumulative'} ? '+' : '' )
988 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );985 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
989}986}
990987
991sub _parse_synopsis {988sub _parse_synopsis {
992989
=== modified file 'bin/pt-slave-delay'
--- bin/pt-slave-delay 2012-10-31 09:18:34 +0000
+++ bin/pt-slave-delay 2012-11-06 15:04:24 +0000
@@ -83,7 +83,6 @@
83 'default' => 1,83 'default' => 1,
84 'cumulative' => 1,84 'cumulative' => 1,
85 'negatable' => 1,85 'negatable' => 1,
86 'value_is_optional' => 1,
87 );86 );
8887
89 my $self = {88 my $self = {
@@ -325,10 +324,9 @@
325 $opt->{short} = undef;324 $opt->{short} = undef;
326 }325 }
327326
328 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;327 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
329 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;328 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
330 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;329 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
331 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
332330
333 $opt->{group} ||= 'default';331 $opt->{group} ||= 'default';
334 $self->{groups}->{ $opt->{group} }->{$long} = 1;332 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -464,7 +462,7 @@
464 if ( $opt->{is_cumulative} ) {462 if ( $opt->{is_cumulative} ) {
465 $opt->{value}++;463 $opt->{value}++;
466 }464 }
467 elsif ( !($opt->{optional_value} && !$val) ) {465 else {
468 $opt->{value} = $val;466 $opt->{value} = $val;
469 }467 }
470 $opt->{got} = 1;468 $opt->{got} = 1;
@@ -1005,12 +1003,11 @@
1005sub _parse_attribs {1003sub _parse_attribs {
1006 my ( $self, $option, $attribs ) = @_;1004 my ( $self, $option, $attribs ) = @_;
1007 my $types = $self->{types};1005 my $types = $self->{types};
1008 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
1009 return $option1006 return $option
1010 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )1007 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
1011 . ($attribs->{'negatable'} ? '!' : '' )1008 . ($attribs->{'negatable'} ? '!' : '' )
1012 . ($attribs->{'cumulative'} ? '+' : '' )1009 . ($attribs->{'cumulative'} ? '+' : '' )
1013 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );1010 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
1014}1011}
10151012
1016sub _parse_synopsis {1013sub _parse_synopsis {
@@ -3514,14 +3511,19 @@
3514};3511};
35153512
3516sub version_check {3513sub version_check {
3517 my $args = pop @_;3514 my %args = @_;
3518 my (@instances) = @_;3515 my @instances = $args{instances} ? @{ $args{instances} } : ();
35193516
3520 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {3517 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
3521 print STDERR '--version-check is disabled by the PERCONA_VERSION_CHECK ',3518 warn '--version-check is disabled by the PERCONA_VERSION_CHECK ',
3522 "environment variable.\n\n";3519 "environment variable.\n\n";
3523 return;3520 return;
3524 }3521 }
3522
3523 $args{protocol} ||= 'https';
3524 my @protocols = $args{protocol} eq 'auto'
3525 ? qw(https http)
3526 : $args{protocol};
3525 3527
3526 my $instances_to_check = [];3528 my $instances_to_check = [];
3527 my $time = int(time());3529 my $time = int(time());
@@ -3536,22 +3538,28 @@
3536 ($time_to_check, $instances_to_check)3538 ($time_to_check, $instances_to_check)
3537 = time_to_check($check_time_file, \@instances, $time);3539 = time_to_check($check_time_file, \@instances, $time);
3538 if ( !$time_to_check ) {3540 if ( !$time_to_check ) {
3539 print STDERR 'It is not time to --version-check again; ',3541 warn 'It is not time to --version-check again; ',
3540 "only 1 check per day.\n\n";3542 "only 1 check per day.\n\n";
3541 return;3543 return;
3542 }3544 }
35433545
3544 my $protocol = $args->{protocol} || 'https';3546 my $advice;
3545 my $advice = pingback(3547 my $e;
3546 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",3548 for my $protocol ( @protocols ) {
3547 instances => $instances_to_check,3549 $advice = eval { pingback(
3548 protocol => $args->{protocol},3550 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
3549 );3551 instances => $instances_to_check,
3552 protocol => $protocol,
3553 ) };
3554 last if !$advice && !$EVAL_ERROR;
3555 $e ||= $EVAL_ERROR;
3556 }
3550 if ( $advice ) {3557 if ( $advice ) {
3551 print "# Percona suggests these upgrades:\n";3558 print "# Percona suggests these upgrades:\n";
3552 print join("\n", map { "# * $_" } @$advice), "\n\n";3559 print join("\n", map { "# * $_" } @$advice), "\n\n";
3553 }3560 }
3554 else {3561 else {
3562 die $e if $e;
3555 print "# No suggestions at this time.\n\n";3563 print "# No suggestions at this time.\n\n";
3556 ($ENV{PTVCDEBUG} || PTDEBUG )3564 ($ENV{PTVCDEBUG} || PTDEBUG )
3557 && _d('--version-check worked, but there were no suggestions');3565 && _d('--version-check worked, but there were no suggestions');
@@ -3577,7 +3585,7 @@
35773585
3578 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};3586 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};
35793587
3580 $ua ||= HTTPMicro->new( timeout => 2 );3588 $ua ||= HTTPMicro->new( timeout => 5 );
3581 $vc ||= VersionCheck->new();3589 $vc ||= VersionCheck->new();
35823590
3583 my $response = $ua->request('GET', $url);3591 my $response = $ua->request('GET', $url);
@@ -3793,6 +3801,21 @@
3793 return $client_response;3801 return $client_response;
3794}3802}
37953803
3804sub validate_options {
3805 my ($o) = @_;
3806
3807 return if !$o->got('version-check');
3808
3809 my $value = $o->get('version-check');
3810 my @values = split /, /,
3811 $o->read_para_after(__FILE__, qr/MAGIC_version_check/);
3812 chomp(@values);
3813
3814 return if grep { $value eq $_ } @values;
3815 $o->save_error("--version-check invalid value $value. Accepted values are "
3816 . join(", ", @values[0..$#values-1]) . " and $values[-1]" );
3817}
3818
3796sub _d {3819sub _d {
3797 my ($package, undef, $line) = caller 0;3820 my ($package, undef, $line) = caller 0;
3798 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }3821 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
@@ -3856,6 +3879,8 @@
3856 $o->set('run-time', max($o->get('run-time'), 1));3879 $o->set('run-time', max($o->get('run-time'), 1));
3857 }3880 }
38583881
3882 Pingback::validate_options($o);
3883
3859 $o->usage_or_errors();3884 $o->usage_or_errors();
38603885
3861 # #######################################################################3886 # #######################################################################
@@ -3909,14 +3934,16 @@
3909 # ########################################################################3934 # ########################################################################
3910 # Do the version-check3935 # Do the version-check
3911 # ########################################################################3936 # ########################################################################
3912 if ( $o->got('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) {3937 if ( $o->get('version-check') ne 'off' && (!$o->has('quiet') || !$o->get('quiet')) ) {
3913 my $tmp_master_dsn = $master_dsn3938 my $tmp_master_dsn = $master_dsn
3914 ? $master_dsn3939 ? $master_dsn
3915 : { h => $status->{master_host}, P => $status->{master_port} };3940 : { h => $status->{master_host}, P => $status->{master_port} };
3916 Pingback::version_check(3941 Pingback::version_check(
3917 { dbh => $slave_dbh, dsn => $slave_dsn },3942 instances => [
3918 { dbh => $master_dbh, dsn => $tmp_master_dsn },3943 { dbh => $slave_dbh, dsn => $slave_dsn },
3919 { protocol => $o->get('version-check') },3944 { dbh => $master_dbh, dsn => $tmp_master_dsn }
3945 ],
3946 protocol => $o->get('version-check'),
3920 );3947 );
3921 }3948 }
39223949
@@ -4393,14 +4420,20 @@
43934420
4394=item --version-check4421=item --version-check
43954422
4396type: string; value_is_optional: yes; default: https4423type: string; default: off
43974424
4398Send program versions to Percona and print suggested upgrades and problems.4425Send program versions to Percona and print suggested upgrades and problems.
43994426Possible values for --version-check:
4400If specified without a value, it will use https by default; However, this4427
4401might fail if C<IO::Socket::SSL> is not installed on your system, in which4428=for comment ignore-pt-internal-value
4402case you may choose to use C<--version-check http>, which will forgo4429MAGIC_version_check
4403encryption but should work out of the box.4430
4431https, http, auto, off
4432
4433C<auto> first tries using C<https>, and resorts to C<http> if that fails.
4434Keep in mind that C<https> might not be available if
4435C<IO::Socket::SSL> is not installed on your system, although
4436C<--version-check http> should work everywhere.
44044437
4405The version check feature causes the tool to send and receive data from4438The version check feature causes the tool to send and receive data from
4406Percona over the web. The data contains program versions from the local4439Percona over the web. The data contains program versions from the local
44074440
=== modified file 'bin/pt-slave-find'
--- bin/pt-slave-find 2012-10-31 09:18:34 +0000
+++ bin/pt-slave-find 2012-11-06 15:04:24 +0000
@@ -62,7 +62,6 @@
62 'default' => 1,62 'default' => 1,
63 'cumulative' => 1,63 'cumulative' => 1,
64 'negatable' => 1,64 'negatable' => 1,
65 'value_is_optional' => 1,
66 );65 );
6766
68 my $self = {67 my $self = {
@@ -304,10 +303,9 @@
304 $opt->{short} = undef;303 $opt->{short} = undef;
305 }304 }
306305
307 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;306 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
308 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;307 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
309 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;308 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
310 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
311309
312 $opt->{group} ||= 'default';310 $opt->{group} ||= 'default';
313 $self->{groups}->{ $opt->{group} }->{$long} = 1;311 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -443,7 +441,7 @@
443 if ( $opt->{is_cumulative} ) {441 if ( $opt->{is_cumulative} ) {
444 $opt->{value}++;442 $opt->{value}++;
445 }443 }
446 elsif ( !($opt->{optional_value} && !$val) ) {444 else {
447 $opt->{value} = $val;445 $opt->{value} = $val;
448 }446 }
449 $opt->{got} = 1;447 $opt->{got} = 1;
@@ -984,12 +982,11 @@
984sub _parse_attribs {982sub _parse_attribs {
985 my ( $self, $option, $attribs ) = @_;983 my ( $self, $option, $attribs ) = @_;
986 my $types = $self->{types};984 my $types = $self->{types};
987 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
988 return $option985 return $option
989 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )986 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
990 . ($attribs->{'negatable'} ? '!' : '' )987 . ($attribs->{'negatable'} ? '!' : '' )
991 . ($attribs->{'cumulative'} ? '+' : '' )988 . ($attribs->{'cumulative'} ? '+' : '' )
992 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );989 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
993}990}
994991
995sub _parse_synopsis {992sub _parse_synopsis {
996993
=== modified file 'bin/pt-slave-restart'
--- bin/pt-slave-restart 2012-10-31 09:18:34 +0000
+++ bin/pt-slave-restart 2012-11-06 15:04:24 +0000
@@ -204,7 +204,6 @@
204 'default' => 1,204 'default' => 1,
205 'cumulative' => 1,205 'cumulative' => 1,
206 'negatable' => 1,206 'negatable' => 1,
207 'value_is_optional' => 1,
208 );207 );
209208
210 my $self = {209 my $self = {
@@ -446,10 +445,9 @@
446 $opt->{short} = undef;445 $opt->{short} = undef;
447 }446 }
448447
449 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;448 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
450 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;449 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
451 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;450 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
452 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
453451
454 $opt->{group} ||= 'default';452 $opt->{group} ||= 'default';
455 $self->{groups}->{ $opt->{group} }->{$long} = 1;453 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -585,7 +583,7 @@
585 if ( $opt->{is_cumulative} ) {583 if ( $opt->{is_cumulative} ) {
586 $opt->{value}++;584 $opt->{value}++;
587 }585 }
588 elsif ( !($opt->{optional_value} && !$val) ) {586 else {
589 $opt->{value} = $val;587 $opt->{value} = $val;
590 }588 }
591 $opt->{got} = 1;589 $opt->{got} = 1;
@@ -1126,12 +1124,11 @@
1126sub _parse_attribs {1124sub _parse_attribs {
1127 my ( $self, $option, $attribs ) = @_;1125 my ( $self, $option, $attribs ) = @_;
1128 my $types = $self->{types};1126 my $types = $self->{types};
1129 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
1130 return $option1127 return $option
1131 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )1128 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
1132 . ($attribs->{'negatable'} ? '!' : '' )1129 . ($attribs->{'negatable'} ? '!' : '' )
1133 . ($attribs->{'cumulative'} ? '+' : '' )1130 . ($attribs->{'cumulative'} ? '+' : '' )
1134 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );1131 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
1135}1132}
11361133
1137sub _parse_synopsis {1134sub _parse_synopsis {
@@ -4137,14 +4134,19 @@
4137};4134};
41384135
4139sub version_check {4136sub version_check {
4140 my $args = pop @_;4137 my %args = @_;
4141 my (@instances) = @_;4138 my @instances = $args{instances} ? @{ $args{instances} } : ();
41424139
4143 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {4140 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
4144 print STDERR '--version-check is disabled by the PERCONA_VERSION_CHECK ',4141 warn '--version-check is disabled by the PERCONA_VERSION_CHECK ',
4145 "environment variable.\n\n";4142 "environment variable.\n\n";
4146 return;4143 return;
4147 }4144 }
4145
4146 $args{protocol} ||= 'https';
4147 my @protocols = $args{protocol} eq 'auto'
4148 ? qw(https http)
4149 : $args{protocol};
4148 4150
4149 my $instances_to_check = [];4151 my $instances_to_check = [];
4150 my $time = int(time());4152 my $time = int(time());
@@ -4159,22 +4161,28 @@
4159 ($time_to_check, $instances_to_check)4161 ($time_to_check, $instances_to_check)
4160 = time_to_check($check_time_file, \@instances, $time);4162 = time_to_check($check_time_file, \@instances, $time);
4161 if ( !$time_to_check ) {4163 if ( !$time_to_check ) {
4162 print STDERR 'It is not time to --version-check again; ',4164 warn 'It is not time to --version-check again; ',
4163 "only 1 check per day.\n\n";4165 "only 1 check per day.\n\n";
4164 return;4166 return;
4165 }4167 }
41664168
4167 my $protocol = $args->{protocol} || 'https';4169 my $advice;
4168 my $advice = pingback(4170 my $e;
4169 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",4171 for my $protocol ( @protocols ) {
4170 instances => $instances_to_check,4172 $advice = eval { pingback(
4171 protocol => $args->{protocol},4173 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
4172 );4174 instances => $instances_to_check,
4175 protocol => $protocol,
4176 ) };
4177 last if !$advice && !$EVAL_ERROR;
4178 $e ||= $EVAL_ERROR;
4179 }
4173 if ( $advice ) {4180 if ( $advice ) {
4174 print "# Percona suggests these upgrades:\n";4181 print "# Percona suggests these upgrades:\n";
4175 print join("\n", map { "# * $_" } @$advice), "\n\n";4182 print join("\n", map { "# * $_" } @$advice), "\n\n";
4176 }4183 }
4177 else {4184 else {
4185 die $e if $e;
4178 print "# No suggestions at this time.\n\n";4186 print "# No suggestions at this time.\n\n";
4179 ($ENV{PTVCDEBUG} || PTDEBUG )4187 ($ENV{PTVCDEBUG} || PTDEBUG )
4180 && _d('--version-check worked, but there were no suggestions');4188 && _d('--version-check worked, but there were no suggestions');
@@ -4200,7 +4208,7 @@
42004208
4201 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};4209 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};
42024210
4203 $ua ||= HTTPMicro->new( timeout => 2 );4211 $ua ||= HTTPMicro->new( timeout => 5 );
4204 $vc ||= VersionCheck->new();4212 $vc ||= VersionCheck->new();
42054213
4206 my $response = $ua->request('GET', $url);4214 my $response = $ua->request('GET', $url);
@@ -4416,6 +4424,21 @@
4416 return $client_response;4424 return $client_response;
4417}4425}
44184426
4427sub validate_options {
4428 my ($o) = @_;
4429
4430 return if !$o->got('version-check');
4431
4432 my $value = $o->get('version-check');
4433 my @values = split /, /,
4434 $o->read_para_after(__FILE__, qr/MAGIC_version_check/);
4435 chomp(@values);
4436
4437 return if grep { $value eq $_ } @values;
4438 $o->save_error("--version-check invalid value $value. Accepted values are "
4439 . join(", ", @values[0..$#values-1]) . " and $values[-1]" );
4440}
4441
4419sub _d {4442sub _d {
4420 my ($package, undef, $line) = caller 0;4443 my ($package, undef, $line) = caller 0;
4421 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }4444 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
@@ -4491,6 +4514,8 @@
4491 $o->save_error("Invalid --recursion-method: $EVAL_ERROR")4514 $o->save_error("Invalid --recursion-method: $EVAL_ERROR")
4492 }4515 }
44934516
4517 Pingback::validate_options($o);
4518
4494 $o->usage_or_errors();4519 $o->usage_or_errors();
44954520
4496 # ########################################################################4521 # ########################################################################
@@ -4595,10 +4620,10 @@
4595 # ########################################################################4620 # ########################################################################
4596 # Do the version-check4621 # Do the version-check
4597 # ########################################################################4622 # ########################################################################
4598 if ( $o->got('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) {4623 if ( $o->get('version-check') ne 'off' && (!$o->has('quiet') || !$o->get('quiet')) ) {
4599 Pingback::version_check(4624 Pingback::version_check(
4600 { dbh => $dbh, dsn => $dsn }, @servers_to_watch,4625 instances => [ { dbh => $dbh, dsn => $dsn }, @servers_to_watch ],
4601 { protocol => $o->get('version-check') },4626 protocol => $o->get('version-check'),
4602 );4627 );
4603 }4628 }
4604 4629
@@ -5312,14 +5337,20 @@
53125337
5313=item --version-check5338=item --version-check
53145339
5315type: string; value_is_optional: yes; default: https5340type: string; default: off
53165341
5317Send program versions to Percona and print suggested upgrades and problems.5342Send program versions to Percona and print suggested upgrades and problems.
53185343Possible values for --version-check:
5319If specified without a value, it will use https by default; However, this5344
5320might fail if C<IO::Socket::SSL> is not installed on your system, in which5345=for comment ignore-pt-internal-value
5321case you may choose to use C<--version-check http>, which will forgo5346MAGIC_version_check
5322encryption but should work out of the box.5347
5348https, http, auto, off
5349
5350C<auto> first tries using C<https>, and resorts to C<http> if that fails.
5351Keep in mind that C<https> might not be available if
5352C<IO::Socket::SSL> is not installed on your system, although
5353C<--version-check http> should work everywhere.
53235354
5324The version check feature causes the tool to send and receive data from5355The version check feature causes the tool to send and receive data from
5325Percona over the web. The data contains program versions from the local5356Percona over the web. The data contains program versions from the local
53265357
=== modified file 'bin/pt-table-checksum'
--- bin/pt-table-checksum 2012-11-05 17:57:11 +0000
+++ bin/pt-table-checksum 2012-11-06 15:04:24 +0000
@@ -1047,14 +1047,19 @@
1047};1047};
10481048
1049sub version_check {1049sub version_check {
1050 my $args = pop @_;1050 my %args = @_;
1051 my (@instances) = @_;1051 my @instances = $args{instances} ? @{ $args{instances} } : ();
10521052
1053 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {1053 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
1054 print STDERR '--version-check is disabled by the PERCONA_VERSION_CHECK ',1054 warn '--version-check is disabled by the PERCONA_VERSION_CHECK ',
1055 "environment variable.\n\n";1055 "environment variable.\n\n";
1056 return;1056 return;
1057 }1057 }
1058
1059 $args{protocol} ||= 'https';
1060 my @protocols = $args{protocol} eq 'auto'
1061 ? qw(https http)
1062 : $args{protocol};
1058 1063
1059 my $instances_to_check = [];1064 my $instances_to_check = [];
1060 my $time = int(time());1065 my $time = int(time());
@@ -1069,22 +1074,28 @@
1069 ($time_to_check, $instances_to_check)1074 ($time_to_check, $instances_to_check)
1070 = time_to_check($check_time_file, \@instances, $time);1075 = time_to_check($check_time_file, \@instances, $time);
1071 if ( !$time_to_check ) {1076 if ( !$time_to_check ) {
1072 print STDERR 'It is not time to --version-check again; ',1077 warn 'It is not time to --version-check again; ',
1073 "only 1 check per day.\n\n";1078 "only 1 check per day.\n\n";
1074 return;1079 return;
1075 }1080 }
10761081
1077 my $protocol = $args->{protocol} || 'https';1082 my $advice;
1078 my $advice = pingback(1083 my $e;
1079 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",1084 for my $protocol ( @protocols ) {
1080 instances => $instances_to_check,1085 $advice = eval { pingback(
1081 protocol => $args->{protocol},1086 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
1082 );1087 instances => $instances_to_check,
1088 protocol => $protocol,
1089 ) };
1090 last if !$advice && !$EVAL_ERROR;
1091 $e ||= $EVAL_ERROR;
1092 }
1083 if ( $advice ) {1093 if ( $advice ) {
1084 print "# Percona suggests these upgrades:\n";1094 print "# Percona suggests these upgrades:\n";
1085 print join("\n", map { "# * $_" } @$advice), "\n\n";1095 print join("\n", map { "# * $_" } @$advice), "\n\n";
1086 }1096 }
1087 else {1097 else {
1098 die $e if $e;
1088 print "# No suggestions at this time.\n\n";1099 print "# No suggestions at this time.\n\n";
1089 ($ENV{PTVCDEBUG} || PTDEBUG )1100 ($ENV{PTVCDEBUG} || PTDEBUG )
1090 && _d('--version-check worked, but there were no suggestions');1101 && _d('--version-check worked, but there were no suggestions');
@@ -1110,7 +1121,7 @@
11101121
1111 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};1122 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};
11121123
1113 $ua ||= HTTPMicro->new( timeout => 2 );1124 $ua ||= HTTPMicro->new( timeout => 5 );
1114 $vc ||= VersionCheck->new();1125 $vc ||= VersionCheck->new();
11151126
1116 my $response = $ua->request('GET', $url);1127 my $response = $ua->request('GET', $url);
@@ -1326,6 +1337,21 @@
1326 return $client_response;1337 return $client_response;
1327}1338}
13281339
1340sub validate_options {
1341 my ($o) = @_;
1342
1343 return if !$o->got('version-check');
1344
1345 my $value = $o->get('version-check');
1346 my @values = split /, /,
1347 $o->read_para_after(__FILE__, qr/MAGIC_version_check/);
1348 chomp(@values);
1349
1350 return if grep { $value eq $_ } @values;
1351 $o->save_error("--version-check invalid value $value. Accepted values are "
1352 . join(", ", @values[0..$#values-1]) . " and $values[-1]" );
1353}
1354
1329sub _d {1355sub _d {
1330 my ($package, undef, $line) = caller 0;1356 my ($package, undef, $line) = caller 0;
1331 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }1357 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
@@ -1756,7 +1782,6 @@
1756 'default' => 1,1782 'default' => 1,
1757 'cumulative' => 1,1783 'cumulative' => 1,
1758 'negatable' => 1,1784 'negatable' => 1,
1759 'value_is_optional' => 1,
1760 );1785 );
17611786
1762 my $self = {1787 my $self = {
@@ -1998,10 +2023,9 @@
1998 $opt->{short} = undef;2023 $opt->{short} = undef;
1999 }2024 }
20002025
2001 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;2026 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
2002 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;2027 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
2003 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;2028 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
2004 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
20052029
2006 $opt->{group} ||= 'default';2030 $opt->{group} ||= 'default';
2007 $self->{groups}->{ $opt->{group} }->{$long} = 1;2031 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -2137,7 +2161,7 @@
2137 if ( $opt->{is_cumulative} ) {2161 if ( $opt->{is_cumulative} ) {
2138 $opt->{value}++;2162 $opt->{value}++;
2139 }2163 }
2140 elsif ( !($opt->{optional_value} && !$val) ) {2164 else {
2141 $opt->{value} = $val;2165 $opt->{value} = $val;
2142 }2166 }
2143 $opt->{got} = 1;2167 $opt->{got} = 1;
@@ -2678,12 +2702,11 @@
2678sub _parse_attribs {2702sub _parse_attribs {
2679 my ( $self, $option, $attribs ) = @_;2703 my ( $self, $option, $attribs ) = @_;
2680 my $types = $self->{types};2704 my $types = $self->{types};
2681 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
2682 return $option2705 return $option
2683 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )2706 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
2684 . ($attribs->{'negatable'} ? '!' : '' )2707 . ($attribs->{'negatable'} ? '!' : '' )
2685 . ($attribs->{'cumulative'} ? '+' : '' )2708 . ($attribs->{'cumulative'} ? '+' : '' )
2686 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );2709 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
2687}2710}
26882711
2689sub _parse_synopsis {2712sub _parse_synopsis {
@@ -8376,6 +8399,8 @@
8376 $o->save_error("Invalid --recursion-method: $EVAL_ERROR")8399 $o->save_error("Invalid --recursion-method: $EVAL_ERROR")
8377 }8400 }
83788401
8402 Pingback::validate_options($o);
8403
8379 $o->usage_or_errors();8404 $o->usage_or_errors();
8380 8405
8381 # ########################################################################8406 # ########################################################################
@@ -8827,11 +8852,13 @@
8827 # ########################################################################8852 # ########################################################################
8828 # Do the version-check8853 # Do the version-check
8829 # ########################################################################8854 # ########################################################################
8830 if ( $o->got('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) {8855 if ( $o->get('version-check') ne 'off' && (!$o->has('quiet') || !$o->get('quiet')) ) {
8831 Pingback::version_check(8856 Pingback::version_check(
8832 { dbh => $master_dbh, dsn => $master_dsn },8857 instances => [
8833 map({ +{ dbh => $_->dbh(), dsn => $_->dsn() } } @$slaves),8858 { dbh => $master_dbh, dsn => $master_dsn },
8834 { protocol => $o->get('version-check') },8859 map({ +{ dbh => $_->dbh(), dsn => $_->dsn() } } @$slaves)
8860 ],
8861 protocol => $o->get('version-check'),
8835 );8862 );
8836 }8863 }
88378864
@@ -11321,14 +11348,20 @@
1132111348
11322=item --version-check11349=item --version-check
1132311350
11324type: string; value_is_optional: yes; default: https11351type: string; default: off
1132511352
11326Send program versions to Percona and print suggested upgrades and problems.11353Send program versions to Percona and print suggested upgrades and problems.
1132711354Possible values for --version-check:
11328If specified without a value, it will use https by default; However, this11355
11329might fail if C<IO::Socket::SSL> is not installed on your system, in which11356=for comment ignore-pt-internal-value
11330case you may choose to use C<--version-check http>, which will forgo11357MAGIC_version_check
11331encryption but should work out of the box.11358
11359https, http, auto, off
11360
11361C<auto> first tries using C<https>, and resorts to C<http> if that fails.
11362Keep in mind that C<https> might not be available if
11363C<IO::Socket::SSL> is not installed on your system, although
11364C<--version-check http> should work everywhere.
1133211365
11333The version check feature causes the tool to send and receive data from11366The version check feature causes the tool to send and receive data from
11334Percona over the web. The data contains program versions from the local11367Percona over the web. The data contains program versions from the local
1133511368
=== modified file 'bin/pt-table-sync'
--- bin/pt-table-sync 2012-11-05 17:57:11 +0000
+++ bin/pt-table-sync 2012-11-06 15:04:24 +0000
@@ -99,7 +99,6 @@
99 'default' => 1,99 'default' => 1,
100 'cumulative' => 1,100 'cumulative' => 1,
101 'negatable' => 1,101 'negatable' => 1,
102 'value_is_optional' => 1,
103 );102 );
104103
105 my $self = {104 my $self = {
@@ -341,10 +340,9 @@
341 $opt->{short} = undef;340 $opt->{short} = undef;
342 }341 }
343342
344 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;343 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
345 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;344 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
346 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;345 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
347 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
348346
349 $opt->{group} ||= 'default';347 $opt->{group} ||= 'default';
350 $self->{groups}->{ $opt->{group} }->{$long} = 1;348 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -480,7 +478,7 @@
480 if ( $opt->{is_cumulative} ) {478 if ( $opt->{is_cumulative} ) {
481 $opt->{value}++;479 $opt->{value}++;
482 }480 }
483 elsif ( !($opt->{optional_value} && !$val) ) {481 else {
484 $opt->{value} = $val;482 $opt->{value} = $val;
485 }483 }
486 $opt->{got} = 1;484 $opt->{got} = 1;
@@ -1021,12 +1019,11 @@
1021sub _parse_attribs {1019sub _parse_attribs {
1022 my ( $self, $option, $attribs ) = @_;1020 my ( $self, $option, $attribs ) = @_;
1023 my $types = $self->{types};1021 my $types = $self->{types};
1024 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
1025 return $option1022 return $option
1026 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )1023 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
1027 . ($attribs->{'negatable'} ? '!' : '' )1024 . ($attribs->{'negatable'} ? '!' : '' )
1028 . ($attribs->{'cumulative'} ? '+' : '' )1025 . ($attribs->{'cumulative'} ? '+' : '' )
1029 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );1026 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
1030}1027}
10311028
1032sub _parse_synopsis {1029sub _parse_synopsis {
@@ -9242,14 +9239,19 @@
9242};9239};
92439240
9244sub version_check {9241sub version_check {
9245 my $args = pop @_;9242 my %args = @_;
9246 my (@instances) = @_;9243 my @instances = $args{instances} ? @{ $args{instances} } : ();
92479244
9248 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {9245 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
9249 print STDERR '--version-check is disabled by the PERCONA_VERSION_CHECK ',9246 warn '--version-check is disabled by the PERCONA_VERSION_CHECK ',
9250 "environment variable.\n\n";9247 "environment variable.\n\n";
9251 return;9248 return;
9252 }9249 }
9250
9251 $args{protocol} ||= 'https';
9252 my @protocols = $args{protocol} eq 'auto'
9253 ? qw(https http)
9254 : $args{protocol};
9253 9255
9254 my $instances_to_check = [];9256 my $instances_to_check = [];
9255 my $time = int(time());9257 my $time = int(time());
@@ -9264,22 +9266,28 @@
9264 ($time_to_check, $instances_to_check)9266 ($time_to_check, $instances_to_check)
9265 = time_to_check($check_time_file, \@instances, $time);9267 = time_to_check($check_time_file, \@instances, $time);
9266 if ( !$time_to_check ) {9268 if ( !$time_to_check ) {
9267 print STDERR 'It is not time to --version-check again; ',9269 warn 'It is not time to --version-check again; ',
9268 "only 1 check per day.\n\n";9270 "only 1 check per day.\n\n";
9269 return;9271 return;
9270 }9272 }
92719273
9272 my $protocol = $args->{protocol} || 'https';9274 my $advice;
9273 my $advice = pingback(9275 my $e;
9274 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",9276 for my $protocol ( @protocols ) {
9275 instances => $instances_to_check,9277 $advice = eval { pingback(
9276 protocol => $args->{protocol},9278 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
9277 );9279 instances => $instances_to_check,
9280 protocol => $protocol,
9281 ) };
9282 last if !$advice && !$EVAL_ERROR;
9283 $e ||= $EVAL_ERROR;
9284 }
9278 if ( $advice ) {9285 if ( $advice ) {
9279 print "# Percona suggests these upgrades:\n";9286 print "# Percona suggests these upgrades:\n";
9280 print join("\n", map { "# * $_" } @$advice), "\n\n";9287 print join("\n", map { "# * $_" } @$advice), "\n\n";
9281 }9288 }
9282 else {9289 else {
9290 die $e if $e;
9283 print "# No suggestions at this time.\n\n";9291 print "# No suggestions at this time.\n\n";
9284 ($ENV{PTVCDEBUG} || PTDEBUG )9292 ($ENV{PTVCDEBUG} || PTDEBUG )
9285 && _d('--version-check worked, but there were no suggestions');9293 && _d('--version-check worked, but there were no suggestions');
@@ -9305,7 +9313,7 @@
93059313
9306 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};9314 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};
93079315
9308 $ua ||= HTTPMicro->new( timeout => 2 );9316 $ua ||= HTTPMicro->new( timeout => 5 );
9309 $vc ||= VersionCheck->new();9317 $vc ||= VersionCheck->new();
93109318
9311 my $response = $ua->request('GET', $url);9319 my $response = $ua->request('GET', $url);
@@ -9521,6 +9529,21 @@
9521 return $client_response;9529 return $client_response;
9522}9530}
95239531
9532sub validate_options {
9533 my ($o) = @_;
9534
9535 return if !$o->got('version-check');
9536
9537 my $value = $o->get('version-check');
9538 my @values = split /, /,
9539 $o->read_para_after(__FILE__, qr/MAGIC_version_check/);
9540 chomp(@values);
9541
9542 return if grep { $value eq $_ } @values;
9543 $o->save_error("--version-check invalid value $value. Accepted values are "
9544 . join(", ", @values[0..$#values-1]) . " and $values[-1]" );
9545}
9546
9524sub _d {9547sub _d {
9525 my ($package, undef, $line) = caller 0;9548 my ($package, undef, $line) = caller 0;
9526 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }9549 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
@@ -9668,6 +9691,8 @@
9668 $o->save_error("Invalid --recursion-method: $EVAL_ERROR")9691 $o->save_error("Invalid --recursion-method: $EVAL_ERROR")
9669 }9692 }
96709693
9694 Pingback::validate_options($o);
9695
9671 $o->usage_or_errors();9696 $o->usage_or_errors();
96729697
9673 # ########################################################################9698 # ########################################################################
@@ -9778,8 +9803,11 @@
9778 +{ dbh => $dbh, dsn => $dsn }9803 +{ dbh => $dbh, dsn => $dsn }
9779 } @dsns;9804 } @dsns;
97809805
9781 if ( $o->got('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) {9806 if ( $o->get('version-check') ne 'off' && (!$o->has('quiet') || !$o->get('quiet')) ) {
9782 Pingback::version_check(@instances, { protocol => $o->get('version-check') });9807 Pingback::version_check(
9808 instances => [@instances],
9809 protocol => $o->get('version-check'),
9810 );
9783 }9811 }
97849812
9785 map { $_->disconnect } @vc_dbhs; # disconnect dbh created for version check9813 map { $_->disconnect } @vc_dbhs; # disconnect dbh created for version check
@@ -12291,14 +12319,20 @@
1229112319
12292=item --version-check12320=item --version-check
1229312321
12294type: string; value_is_optional: yes; default: https12322type: string; default: off
1229512323
12296Send program versions to Percona and print suggested upgrades and problems.12324Send program versions to Percona and print suggested upgrades and problems.
1229712325Possible values for --version-check:
12298If specified without a value, it will use https by default; However, this12326
12299might fail if C<IO::Socket::SSL> is not installed on your system, in which12327=for comment ignore-pt-internal-value
12300case you may choose to use C<--version-check http>, which will forgo12328MAGIC_version_check
12301encryption but should work out of the box.12329
12330https, http, auto, off
12331
12332C<auto> first tries using C<https>, and resorts to C<http> if that fails.
12333Keep in mind that C<https> might not be available if
12334C<IO::Socket::SSL> is not installed on your system, although
12335C<--version-check http> should work everywhere.
1230212336
12303The version check feature causes the tool to send and receive data from12337The version check feature causes the tool to send and receive data from
12304Percona over the web. The data contains program versions from the local12338Percona over the web. The data contains program versions from the local
1230512339
=== modified file 'bin/pt-tcp-model'
--- bin/pt-tcp-model 2012-10-22 18:17:08 +0000
+++ bin/pt-tcp-model 2012-11-06 15:04:24 +0000
@@ -61,7 +61,6 @@
61 'default' => 1,61 'default' => 1,
62 'cumulative' => 1,62 'cumulative' => 1,
63 'negatable' => 1,63 'negatable' => 1,
64 'value_is_optional' => 1,
65 );64 );
6665
67 my $self = {66 my $self = {
@@ -303,10 +302,9 @@
303 $opt->{short} = undef;302 $opt->{short} = undef;
304 }303 }
305304
306 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;305 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
307 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;306 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
308 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;307 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
309 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
310308
311 $opt->{group} ||= 'default';309 $opt->{group} ||= 'default';
312 $self->{groups}->{ $opt->{group} }->{$long} = 1;310 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -442,7 +440,7 @@
442 if ( $opt->{is_cumulative} ) {440 if ( $opt->{is_cumulative} ) {
443 $opt->{value}++;441 $opt->{value}++;
444 }442 }
445 elsif ( !($opt->{optional_value} && !$val) ) {443 else {
446 $opt->{value} = $val;444 $opt->{value} = $val;
447 }445 }
448 $opt->{got} = 1;446 $opt->{got} = 1;
@@ -983,12 +981,11 @@
983sub _parse_attribs {981sub _parse_attribs {
984 my ( $self, $option, $attribs ) = @_;982 my ( $self, $option, $attribs ) = @_;
985 my $types = $self->{types};983 my $types = $self->{types};
986 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
987 return $option984 return $option
988 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )985 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
989 . ($attribs->{'negatable'} ? '!' : '' )986 . ($attribs->{'negatable'} ? '!' : '' )
990 . ($attribs->{'cumulative'} ? '+' : '' )987 . ($attribs->{'cumulative'} ? '+' : '' )
991 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );988 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
992}989}
993990
994sub _parse_synopsis {991sub _parse_synopsis {
995992
=== modified file 'bin/pt-trend'
--- bin/pt-trend 2012-10-30 23:04:22 +0000
+++ bin/pt-trend 2012-11-06 15:04:24 +0000
@@ -61,7 +61,6 @@
61 'default' => 1,61 'default' => 1,
62 'cumulative' => 1,62 'cumulative' => 1,
63 'negatable' => 1,63 'negatable' => 1,
64 'value_is_optional' => 1,
65 );64 );
6665
67 my $self = {66 my $self = {
@@ -303,10 +302,9 @@
303 $opt->{short} = undef;302 $opt->{short} = undef;
304 }303 }
305304
306 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;305 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
307 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;306 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
308 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;307 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
309 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
310308
311 $opt->{group} ||= 'default';309 $opt->{group} ||= 'default';
312 $self->{groups}->{ $opt->{group} }->{$long} = 1;310 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -442,7 +440,7 @@
442 if ( $opt->{is_cumulative} ) {440 if ( $opt->{is_cumulative} ) {
443 $opt->{value}++;441 $opt->{value}++;
444 }442 }
445 elsif ( !($opt->{optional_value} && !$val) ) {443 else {
446 $opt->{value} = $val;444 $opt->{value} = $val;
447 }445 }
448 $opt->{got} = 1;446 $opt->{got} = 1;
@@ -983,12 +981,11 @@
983sub _parse_attribs {981sub _parse_attribs {
984 my ( $self, $option, $attribs ) = @_;982 my ( $self, $option, $attribs ) = @_;
985 my $types = $self->{types};983 my $types = $self->{types};
986 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
987 return $option984 return $option
988 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )985 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
989 . ($attribs->{'negatable'} ? '!' : '' )986 . ($attribs->{'negatable'} ? '!' : '' )
990 . ($attribs->{'cumulative'} ? '+' : '' )987 . ($attribs->{'cumulative'} ? '+' : '' )
991 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );988 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
992}989}
993990
994sub _parse_synopsis {991sub _parse_synopsis {
995992
=== modified file 'bin/pt-upgrade'
--- bin/pt-upgrade 2012-11-05 17:57:11 +0000
+++ bin/pt-upgrade 2012-11-06 15:04:24 +0000
@@ -1011,7 +1011,6 @@
1011 'default' => 1,1011 'default' => 1,
1012 'cumulative' => 1,1012 'cumulative' => 1,
1013 'negatable' => 1,1013 'negatable' => 1,
1014 'value_is_optional' => 1,
1015 );1014 );
10161015
1017 my $self = {1016 my $self = {
@@ -1253,10 +1252,9 @@
1253 $opt->{short} = undef;1252 $opt->{short} = undef;
1254 }1253 }
12551254
1256 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;1255 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
1257 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;1256 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
1258 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;1257 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
1259 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
12601258
1261 $opt->{group} ||= 'default';1259 $opt->{group} ||= 'default';
1262 $self->{groups}->{ $opt->{group} }->{$long} = 1;1260 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -1392,7 +1390,7 @@
1392 if ( $opt->{is_cumulative} ) {1390 if ( $opt->{is_cumulative} ) {
1393 $opt->{value}++;1391 $opt->{value}++;
1394 }1392 }
1395 elsif ( !($opt->{optional_value} && !$val) ) {1393 else {
1396 $opt->{value} = $val;1394 $opt->{value} = $val;
1397 }1395 }
1398 $opt->{got} = 1;1396 $opt->{got} = 1;
@@ -1933,12 +1931,11 @@
1933sub _parse_attribs {1931sub _parse_attribs {
1934 my ( $self, $option, $attribs ) = @_;1932 my ( $self, $option, $attribs ) = @_;
1935 my $types = $self->{types};1933 my $types = $self->{types};
1936 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
1937 return $option1934 return $option
1938 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )1935 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
1939 . ($attribs->{'negatable'} ? '!' : '' )1936 . ($attribs->{'negatable'} ? '!' : '' )
1940 . ($attribs->{'cumulative'} ? '+' : '' )1937 . ($attribs->{'cumulative'} ? '+' : '' )
1941 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );1938 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
1942}1939}
19431940
1944sub _parse_synopsis {1941sub _parse_synopsis {
@@ -11314,14 +11311,19 @@
11314};11311};
1131511312
11316sub version_check {11313sub version_check {
11317 my $args = pop @_;11314 my %args = @_;
11318 my (@instances) = @_;11315 my @instances = $args{instances} ? @{ $args{instances} } : ();
1131911316
11320 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {11317 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
11321 print STDERR '--version-check is disabled by the PERCONA_VERSION_CHECK ',11318 warn '--version-check is disabled by the PERCONA_VERSION_CHECK ',
11322 "environment variable.\n\n";11319 "environment variable.\n\n";
11323 return;11320 return;
11324 }11321 }
11322
11323 $args{protocol} ||= 'https';
11324 my @protocols = $args{protocol} eq 'auto'
11325 ? qw(https http)
11326 : $args{protocol};
11325 11327
11326 my $instances_to_check = [];11328 my $instances_to_check = [];
11327 my $time = int(time());11329 my $time = int(time());
@@ -11336,22 +11338,28 @@
11336 ($time_to_check, $instances_to_check)11338 ($time_to_check, $instances_to_check)
11337 = time_to_check($check_time_file, \@instances, $time);11339 = time_to_check($check_time_file, \@instances, $time);
11338 if ( !$time_to_check ) {11340 if ( !$time_to_check ) {
11339 print STDERR 'It is not time to --version-check again; ',11341 warn 'It is not time to --version-check again; ',
11340 "only 1 check per day.\n\n";11342 "only 1 check per day.\n\n";
11341 return;11343 return;
11342 }11344 }
1134311345
11344 my $protocol = $args->{protocol} || 'https';11346 my $advice;
11345 my $advice = pingback(11347 my $e;
11346 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",11348 for my $protocol ( @protocols ) {
11347 instances => $instances_to_check,11349 $advice = eval { pingback(
11348 protocol => $args->{protocol},11350 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
11349 );11351 instances => $instances_to_check,
11352 protocol => $protocol,
11353 ) };
11354 last if !$advice && !$EVAL_ERROR;
11355 $e ||= $EVAL_ERROR;
11356 }
11350 if ( $advice ) {11357 if ( $advice ) {
11351 print "# Percona suggests these upgrades:\n";11358 print "# Percona suggests these upgrades:\n";
11352 print join("\n", map { "# * $_" } @$advice), "\n\n";11359 print join("\n", map { "# * $_" } @$advice), "\n\n";
11353 }11360 }
11354 else {11361 else {
11362 die $e if $e;
11355 print "# No suggestions at this time.\n\n";11363 print "# No suggestions at this time.\n\n";
11356 ($ENV{PTVCDEBUG} || PTDEBUG )11364 ($ENV{PTVCDEBUG} || PTDEBUG )
11357 && _d('--version-check worked, but there were no suggestions');11365 && _d('--version-check worked, but there were no suggestions');
@@ -11377,7 +11385,7 @@
1137711385
11378 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};11386 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};
1137911387
11380 $ua ||= HTTPMicro->new( timeout => 2 );11388 $ua ||= HTTPMicro->new( timeout => 5 );
11381 $vc ||= VersionCheck->new();11389 $vc ||= VersionCheck->new();
1138211390
11383 my $response = $ua->request('GET', $url);11391 my $response = $ua->request('GET', $url);
@@ -11593,6 +11601,21 @@
11593 return $client_response;11601 return $client_response;
11594}11602}
1159511603
11604sub validate_options {
11605 my ($o) = @_;
11606
11607 return if !$o->got('version-check');
11608
11609 my $value = $o->get('version-check');
11610 my @values = split /, /,
11611 $o->read_para_after(__FILE__, qr/MAGIC_version_check/);
11612 chomp(@values);
11613
11614 return if grep { $value eq $_ } @values;
11615 $o->save_error("--version-check invalid value $value. Accepted values are "
11616 . join(", ", @values[0..$#values-1]) . " and $values[-1]" );
11617}
11618
11596sub _d {11619sub _d {
11597 my ($package, undef, $line) = caller 0;11620 my ($package, undef, $line) = caller 0;
11598 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }11621 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
@@ -11686,6 +11709,8 @@
11686 $o->save_error('Specify at least one host DSN');11709 $o->save_error('Specify at least one host DSN');
11687 }11710 }
1168811711
11712 Pingback::validate_options($o);
11713
11689 $o->usage_or_errors();11714 $o->usage_or_errors();
1169011715
11691 if ( $o->get('explain-hosts') ) {11716 if ( $o->get('explain-hosts') ) {
@@ -11947,10 +11972,10 @@
11947 # ########################################################################11972 # ########################################################################
11948 # Do the version-check11973 # Do the version-check
11949 # ########################################################################11974 # ########################################################################
11950 if ( $o->got('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) {11975 if ( $o->get('version-check') ne 'off' && (!$o->has('quiet') || !$o->get('quiet')) ) {
11951 Pingback::version_check(11976 Pingback::version_check(
11952 map({ +{ dbh => $_->{dbh}, dsn => $_->{dsn} } } @$hosts),11977 instances => [ map({ +{ dbh => $_->{dbh}, dsn => $_->{dsn} } } @$hosts) ],
11953 { protocol => $o->get('version-check') },11978 protocol => $o->get('version-check'),
11954 );11979 );
11955 }11980 }
1195611981
@@ -12884,14 +12909,20 @@
1288412909
12885=item --version-check12910=item --version-check
1288612911
12887type: string; value_is_optional: yes; default: https12912type: string; default: off
1288812913
12889Send program versions to Percona and print suggested upgrades and problems.12914Send program versions to Percona and print suggested upgrades and problems.
1289012915Possible values for --version-check:
12891If specified without a value, it will use https by default; However, this12916
12892might fail if C<IO::Socket::SSL> is not installed on your system, in which12917=for comment ignore-pt-internal-value
12893case you may choose to use C<--version-check http>, which will forgo12918MAGIC_version_check
12894encryption but should work out of the box.12919
12920https, http, auto, off
12921
12922C<auto> first tries using C<https>, and resorts to C<http> if that fails.
12923Keep in mind that C<https> might not be available if
12924C<IO::Socket::SSL> is not installed on your system, although
12925C<--version-check http> should work everywhere.
1289512926
12896The version check feature causes the tool to send and receive data from12927The version check feature causes the tool to send and receive data from
12897Percona over the web. The data contains program versions from the local12928Percona over the web. The data contains program versions from the local
1289812929
=== modified file 'bin/pt-variable-advisor'
--- bin/pt-variable-advisor 2012-10-31 09:18:34 +0000
+++ bin/pt-variable-advisor 2012-11-06 15:04:24 +0000
@@ -87,7 +87,6 @@
87 'default' => 1,87 'default' => 1,
88 'cumulative' => 1,88 'cumulative' => 1,
89 'negatable' => 1,89 'negatable' => 1,
90 'value_is_optional' => 1,
91 );90 );
9291
93 my $self = {92 my $self = {
@@ -329,10 +328,9 @@
329 $opt->{short} = undef;328 $opt->{short} = undef;
330 }329 }
331330
332 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;331 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
333 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;332 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
334 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;333 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
335 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
336334
337 $opt->{group} ||= 'default';335 $opt->{group} ||= 'default';
338 $self->{groups}->{ $opt->{group} }->{$long} = 1;336 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -468,7 +466,7 @@
468 if ( $opt->{is_cumulative} ) {466 if ( $opt->{is_cumulative} ) {
469 $opt->{value}++;467 $opt->{value}++;
470 }468 }
471 elsif ( !($opt->{optional_value} && !$val) ) {469 else {
472 $opt->{value} = $val;470 $opt->{value} = $val;
473 }471 }
474 $opt->{got} = 1;472 $opt->{got} = 1;
@@ -1009,12 +1007,11 @@
1009sub _parse_attribs {1007sub _parse_attribs {
1010 my ( $self, $option, $attribs ) = @_;1008 my ( $self, $option, $attribs ) = @_;
1011 my $types = $self->{types};1009 my $types = $self->{types};
1012 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
1013 return $option1010 return $option
1014 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )1011 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
1015 . ($attribs->{'negatable'} ? '!' : '' )1012 . ($attribs->{'negatable'} ? '!' : '' )
1016 . ($attribs->{'cumulative'} ? '+' : '' )1013 . ($attribs->{'cumulative'} ? '+' : '' )
1017 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );1014 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
1018}1015}
10191016
1020sub _parse_synopsis {1017sub _parse_synopsis {
@@ -4426,14 +4423,19 @@
4426};4423};
44274424
4428sub version_check {4425sub version_check {
4429 my $args = pop @_;4426 my %args = @_;
4430 my (@instances) = @_;4427 my @instances = $args{instances} ? @{ $args{instances} } : ();
44314428
4432 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {4429 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
4433 print STDERR '--version-check is disabled by the PERCONA_VERSION_CHECK ',4430 warn '--version-check is disabled by the PERCONA_VERSION_CHECK ',
4434 "environment variable.\n\n";4431 "environment variable.\n\n";
4435 return;4432 return;
4436 }4433 }
4434
4435 $args{protocol} ||= 'https';
4436 my @protocols = $args{protocol} eq 'auto'
4437 ? qw(https http)
4438 : $args{protocol};
4437 4439
4438 my $instances_to_check = [];4440 my $instances_to_check = [];
4439 my $time = int(time());4441 my $time = int(time());
@@ -4448,22 +4450,28 @@
4448 ($time_to_check, $instances_to_check)4450 ($time_to_check, $instances_to_check)
4449 = time_to_check($check_time_file, \@instances, $time);4451 = time_to_check($check_time_file, \@instances, $time);
4450 if ( !$time_to_check ) {4452 if ( !$time_to_check ) {
4451 print STDERR 'It is not time to --version-check again; ',4453 warn 'It is not time to --version-check again; ',
4452 "only 1 check per day.\n\n";4454 "only 1 check per day.\n\n";
4453 return;4455 return;
4454 }4456 }
44554457
4456 my $protocol = $args->{protocol} || 'https';4458 my $advice;
4457 my $advice = pingback(4459 my $e;
4458 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",4460 for my $protocol ( @protocols ) {
4459 instances => $instances_to_check,4461 $advice = eval { pingback(
4460 protocol => $args->{protocol},4462 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
4461 );4463 instances => $instances_to_check,
4464 protocol => $protocol,
4465 ) };
4466 last if !$advice && !$EVAL_ERROR;
4467 $e ||= $EVAL_ERROR;
4468 }
4462 if ( $advice ) {4469 if ( $advice ) {
4463 print "# Percona suggests these upgrades:\n";4470 print "# Percona suggests these upgrades:\n";
4464 print join("\n", map { "# * $_" } @$advice), "\n\n";4471 print join("\n", map { "# * $_" } @$advice), "\n\n";
4465 }4472 }
4466 else {4473 else {
4474 die $e if $e;
4467 print "# No suggestions at this time.\n\n";4475 print "# No suggestions at this time.\n\n";
4468 ($ENV{PTVCDEBUG} || PTDEBUG )4476 ($ENV{PTVCDEBUG} || PTDEBUG )
4469 && _d('--version-check worked, but there were no suggestions');4477 && _d('--version-check worked, but there were no suggestions');
@@ -4489,7 +4497,7 @@
44894497
4490 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};4498 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};
44914499
4492 $ua ||= HTTPMicro->new( timeout => 2 );4500 $ua ||= HTTPMicro->new( timeout => 5 );
4493 $vc ||= VersionCheck->new();4501 $vc ||= VersionCheck->new();
44944502
4495 my $response = $ua->request('GET', $url);4503 my $response = $ua->request('GET', $url);
@@ -4705,6 +4713,21 @@
4705 return $client_response;4713 return $client_response;
4706}4714}
47074715
4716sub validate_options {
4717 my ($o) = @_;
4718
4719 return if !$o->got('version-check');
4720
4721 my $value = $o->get('version-check');
4722 my @values = split /, /,
4723 $o->read_para_after(__FILE__, qr/MAGIC_version_check/);
4724 chomp(@values);
4725
4726 return if grep { $value eq $_ } @values;
4727 $o->save_error("--version-check invalid value $value. Accepted values are "
4728 . join(", ", @values[0..$#values-1]) . " and $values[-1]" );
4729}
4730
4708sub _d {4731sub _d {
4709 my ($package, undef, $line) = caller 0;4732 my ($package, undef, $line) = caller 0;
4710 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }4733 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
@@ -4761,6 +4784,8 @@
4761 }4784 }
4762 }4785 }
47634786
4787 Pingback::validate_options($o);
4788
4764 $o->usage_or_errors();4789 $o->usage_or_errors();
47654790
4766 # #########################################################################4791 # #########################################################################
@@ -4835,10 +4860,10 @@
4835 # ########################################################################4860 # ########################################################################
4836 # Do the version-check4861 # Do the version-check
4837 # ########################################################################4862 # ########################################################################
4838 if ( $o->got('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) {4863 if ( $o->get('version-check') ne 'off' && (!$o->has('quiet') || !$o->get('quiet')) ) {
4839 Pingback::version_check(4864 Pingback::version_check(
4840 ($dbh ? { dbh => $dbh, dsn => $dsn } : ()),4865 instances => [ ($dbh ? { dbh => $dbh, dsn => $dsn } : ()) ],
4841 { protocol => $o->get('version-check') },4866 protocol => $o->get('version-check'),
4842 );4867 );
4843 }4868 }
48444869
@@ -5667,14 +5692,20 @@
56675692
5668=item --version-check5693=item --version-check
56695694
5670type: string; value_is_optional: yes; default: https5695type: string; default: off
56715696
5672Send program versions to Percona and print suggested upgrades and problems.5697Send program versions to Percona and print suggested upgrades and problems.
56735698Possible values for --version-check:
5674If specified without a value, it will use https by default; However, this5699
5675might fail if C<IO::Socket::SSL> is not installed on your system, in which5700=for comment ignore-pt-internal-value
5676case you may choose to use C<--version-check http>, which will forgo5701MAGIC_version_check
5677encryption but should work out of the box.5702
5703https, http, auto, off
5704
5705C<auto> first tries using C<https>, and resorts to C<http> if that fails.
5706Keep in mind that C<https> might not be available if
5707C<IO::Socket::SSL> is not installed on your system, although
5708C<--version-check http> should work everywhere.
56785709
5679The version check feature causes the tool to send and receive data from5710The version check feature causes the tool to send and receive data from
5680Percona over the web. The data contains program versions from the local5711Percona over the web. The data contains program versions from the local
56815712
=== modified file 'lib/OptionParser.pm'
--- lib/OptionParser.pm 2012-10-22 17:43:33 +0000
+++ lib/OptionParser.pm 2012-11-06 15:04:24 +0000
@@ -107,7 +107,6 @@
107 'default' => 1,107 'default' => 1,
108 'cumulative' => 1,108 'cumulative' => 1,
109 'negatable' => 1,109 'negatable' => 1,
110 'value_is_optional' => 1,
111 );110 );
112111
113 my $self = {112 my $self = {
@@ -414,10 +413,9 @@
414 $opt->{short} = undef;413 $opt->{short} = undef;
415 }414 }
416415
417 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;416 $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0;
418 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;417 $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0;
419 $opt->{optional_value} = $opt->{spec} =~ m/:/ ? 1 : 0;418 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
420 $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0;
421419
422 $opt->{group} ||= 'default';420 $opt->{group} ||= 'default';
423 $self->{groups}->{ $opt->{group} }->{$long} = 1;421 $self->{groups}->{ $opt->{group} }->{$long} = 1;
@@ -600,7 +598,7 @@
600 if ( $opt->{is_cumulative} ) {598 if ( $opt->{is_cumulative} ) {
601 $opt->{value}++;599 $opt->{value}++;
602 }600 }
603 elsif ( !($opt->{optional_value} && !$val) ) {601 else {
604 $opt->{value} = $val;602 $opt->{value} = $val;
605 }603 }
606 $opt->{got} = 1;604 $opt->{got} = 1;
@@ -1275,12 +1273,11 @@
1275sub _parse_attribs {1273sub _parse_attribs {
1276 my ( $self, $option, $attribs ) = @_;1274 my ( $self, $option, $attribs ) = @_;
1277 my $types = $self->{types};1275 my $types = $self->{types};
1278 my $eq = $attribs->{'value_is_optional'} ? ':' : '=';
1279 return $option1276 return $option
1280 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )1277 . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' )
1281 . ($attribs->{'negatable'} ? '!' : '' )1278 . ($attribs->{'negatable'} ? '!' : '' )
1282 . ($attribs->{'cumulative'} ? '+' : '' )1279 . ($attribs->{'cumulative'} ? '+' : '' )
1283 . ($attribs->{'type'} ? $eq . $types->{$attribs->{type}} : '' );1280 . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' );
1284}1281}
12851282
1286sub _parse_synopsis {1283sub _parse_synopsis {
12871284
=== modified file 'lib/Pingback.pm'
--- lib/Pingback.pm 2012-09-24 19:24:11 +0000
+++ lib/Pingback.pm 2012-11-06 15:04:24 +0000
@@ -55,17 +55,25 @@
55};55};
5656
57sub version_check {57sub version_check {
58 my $args = pop @_;58 my %args = @_;
59 my (@instances) = @_;59 my @instances = $args{instances} ? @{ $args{instances} } : ();
60 # If this blows up, oh well, don't bother the user about it.60 # If this blows up, oh well, don't bother the user about it.
61 # This feature is a "best effort" only; we don't want it to61 # This feature is a "best effort" only; we don't want it to
62 # get in the way of the tool's real work.62 # get in the way of the tool's real work.
6363
64 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {64 if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
65 print STDERR '--version-check is disabled by the PERCONA_VERSION_CHECK ',65 warn '--version-check is disabled by the PERCONA_VERSION_CHECK ',
66 "environment variable.\n\n";66 "environment variable.\n\n";
67 return;67 return;
68 }68 }
69
70 # we got here if the protocol wasn't "off", and the values
71 # were validated earlier, so just handle auto
72 # This line is mostly here for the test suite:
73 $args{protocol} ||= 'https';
74 my @protocols = $args{protocol} eq 'auto'
75 ? qw(https http)
76 : $args{protocol};
69 77
70 my $instances_to_check = [];78 my $instances_to_check = [];
71 my $time = int(time());79 my $time = int(time());
@@ -82,22 +90,29 @@
82 ($time_to_check, $instances_to_check)90 ($time_to_check, $instances_to_check)
83 = time_to_check($check_time_file, \@instances, $time);91 = time_to_check($check_time_file, \@instances, $time);
84 if ( !$time_to_check ) {92 if ( !$time_to_check ) {
85 print STDERR 'It is not time to --version-check again; ',93 warn 'It is not time to --version-check again; ',
86 "only 1 check per day.\n\n";94 "only 1 check per day.\n\n";
87 return;95 return;
88 }96 }
8997
90 my $protocol = $args->{protocol} || 'https';98 my $advice;
91 my $advice = pingback(99 my $e;
92 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",100 for my $protocol ( @protocols ) {
93 instances => $instances_to_check,101 $advice = eval { pingback(
94 protocol => $args->{protocol},102 url => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
95 );103 instances => $instances_to_check,
104 protocol => $protocol,
105 ) };
106 # No advice, and no error, so no reason to keep trying.
107 last if !$advice && !$EVAL_ERROR;
108 $e ||= $EVAL_ERROR;
109 }
96 if ( $advice ) {110 if ( $advice ) {
97 print "# Percona suggests these upgrades:\n";111 print "# Percona suggests these upgrades:\n";
98 print join("\n", map { "# * $_" } @$advice), "\n\n";112 print join("\n", map { "# * $_" } @$advice), "\n\n";
99 }113 }
100 else {114 else {
115 die $e if $e;
101 print "# No suggestions at this time.\n\n";116 print "# No suggestions at this time.\n\n";
102 ($ENV{PTVCDEBUG} || PTDEBUG )117 ($ENV{PTVCDEBUG} || PTDEBUG )
103 && _d('--version-check worked, but there were no suggestions');118 && _d('--version-check worked, but there were no suggestions');
@@ -124,7 +139,7 @@
124 # Optional args139 # Optional args
125 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};140 my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};
126141
127 $ua ||= HTTPMicro->new( timeout => 2 );142 $ua ||= HTTPMicro->new( timeout => 5 );
128 $vc ||= VersionCheck->new();143 $vc ||= VersionCheck->new();
129144
130 # GET https://upgrade.percona.com, the server will return145 # GET https://upgrade.percona.com, the server will return
@@ -393,6 +408,22 @@
393 return $client_response;408 return $client_response;
394}409}
395410
411sub validate_options {
412 my ($o) = @_;
413
414 # No need to validate anything if we didn't get an explicit v-c
415 return if !$o->got('version-check');
416
417 my $value = $o->get('version-check');
418 my @values = split /, /,
419 $o->read_para_after(__FILE__, qr/MAGIC_version_check/);
420 chomp(@values);
421
422 return if grep { $value eq $_ } @values;
423 $o->save_error("--version-check invalid value $value. Accepted values are "
424 . join(", ", @values[0..$#values-1]) . " and $values[-1]" );
425}
426
396sub _d {427sub _d {
397 my ($package, undef, $line) = caller 0;428 my ($package, undef, $line) = caller 0;
398 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }429 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
399430
=== modified file 't/lib/OptionParser.t'
--- t/lib/OptionParser.t 2012-10-22 18:16:42 +0000
+++ t/lib/OptionParser.t 2012-11-06 15:04:24 +0000
@@ -145,7 +145,6 @@
145 type => 's',145 type => 's',
146 got => 0,146 got => 0,
147 value => undef,147 value => undef,
148 optional_value => 0,
149 },148 },
150 'port' => {149 'port' => {
151 spec => 'port|p=i',150 spec => 'port|p=i',
@@ -159,7 +158,6 @@
159 type => 'i',158 type => 'i',
160 got => 0,159 got => 0,
161 value => undef,160 value => undef,
162 optional_value => 0,
163 },161 },
164 'price' => {162 'price' => {
165 spec => 'price=f',163 spec => 'price=f',
@@ -173,7 +171,6 @@
173 type => 'f',171 type => 'f',
174 got => 0,172 got => 0,
175 value => undef,173 value => undef,
176 optional_value => 0,
177 },174 },
178 'hash-req' => {175 'hash-req' => {
179 spec => 'hash-req=s',176 spec => 'hash-req=s',
@@ -187,7 +184,6 @@
187 type => 'H',184 type => 'H',
188 got => 0,185 got => 0,
189 value => undef,186 value => undef,
190 optional_value => 0,
191 },187 },
192 'hash-opt' => {188 'hash-opt' => {
193 spec => 'hash-opt=s',189 spec => 'hash-opt=s',
@@ -201,7 +197,6 @@
201 type => 'h',197 type => 'h',
202 got => 0,198 got => 0,
203 value => undef,199 value => undef,
204 optional_value => 0,
205 },200 },
206 'array-req' => {201 'array-req' => {
207 spec => 'array-req=s',202 spec => 'array-req=s',
@@ -215,7 +210,6 @@
215 type => 'A',210 type => 'A',
216 got => 0,211 got => 0,
217 value => undef,212 value => undef,
218 optional_value => 0,
219 },213 },
220 'array-opt' => {214 'array-opt' => {
221 spec => 'array-opt=s',215 spec => 'array-opt=s',
@@ -229,7 +223,6 @@
229 type => 'a',223 type => 'a',
230 got => 0,224 got => 0,
231 value => undef,225 value => undef,
232 optional_value => 0,
233 },226 },
234 'host' => {227 'host' => {
235 spec => 'host=s',228 spec => 'host=s',
@@ -243,7 +236,6 @@
243 type => 'd',236 type => 'd',
244 got => 0,237 got => 0,
245 value => undef,238 value => undef,
246 optional_value => 0,
247 },239 },
248 'chunk-size' => {240 'chunk-size' => {
249 spec => 'chunk-size=s',241 spec => 'chunk-size=s',
@@ -257,7 +249,6 @@
257 type => 'z',249 type => 'z',
258 got => 0,250 got => 0,
259 value => undef,251 value => undef,
260 optional_value => 0,
261 },252 },
262 'time' => {253 'time' => {
263 spec => 'time=s',254 spec => 'time=s',
@@ -271,7 +262,6 @@
271 type => 'm',262 type => 'm',
272 got => 0,263 got => 0,
273 value => undef,264 value => undef,
274 optional_value => 0,
275 },265 },
276 'help' => {266 'help' => {
277 spec => 'help+',267 spec => 'help+',
@@ -285,7 +275,6 @@
285 type => undef,275 type => undef,
286 got => 0,276 got => 0,
287 value => undef,277 value => undef,
288 optional_value => 0,
289 },278 },
290 'other' => {279 'other' => {
291 spec => 'other!',280 spec => 'other!',
@@ -299,7 +288,6 @@
299 type => undef,288 type => undef,
300 got => 0,289 got => 0,
301 value => undef,290 value => undef,
302 optional_value => 0,
303 }291 }
304 },292 },
305 'Parse opt specs'293 'Parse opt specs'
@@ -520,7 +508,6 @@
520 type => undef,508 type => undef,
521 got => 0,509 got => 0,
522 value => undef,510 value => undef,
523 optional_value => 0,
524 },511 },
525 'defaultset' => {512 'defaultset' => {
526 spec => 'defaultset!',513 spec => 'defaultset!',
@@ -536,7 +523,6 @@
536 type => undef,523 type => undef,
537 got => 0,524 got => 0,
538 value => undef,525 value => undef,
539 optional_value => 0,
540 },526 },
541 'defaults-file' => {527 'defaults-file' => {
542 spec => 'defaults-file|F=s',528 spec => 'defaults-file|F=s',
@@ -550,7 +536,6 @@
550 type => 's',536 type => 's',
551 got => 0,537 got => 0,
552 value => undef,538 value => undef,
553 optional_value => 0,
554 },539 },
555 'dog' => {540 'dog' => {
556 spec => 'dog|D=s',541 spec => 'dog|D=s',
@@ -564,7 +549,6 @@
564 type => 's',549 type => 's',
565 got => 0,550 got => 0,
566 value => undef,551 value => undef,
567 optional_value => 0,
568 },552 },
569 'love' => {553 'love' => {
570 spec => 'love|l+',554 spec => 'love|l+',
@@ -578,7 +562,6 @@
578 type => undef,562 type => undef,
579 got => 0,563 got => 0,
580 value => undef,564 value => undef,
581 optional_value => 0,
582 },565 },
583 },566 },
584 'Parse dog specs'567 'Parse dog specs'
@@ -978,7 +961,6 @@
978 long => 'bar',961 long => 'bar',
979 type => undef,962 type => undef,
980 parsed => 1,963 parsed => 1,
981 optional_value=> 0,
982 },964 },
983 'Disabled opt is not destroyed'965 'Disabled opt is not destroyed'
984);966);
@@ -2008,55 +1990,13 @@
2008$output = output(1990$output = output(
2009 sub { $o->usage_or_errors(undef, 1); },1991 sub { $o->usage_or_errors(undef, 1); },
2010);1992);
1993$synop{usage} =~ s/([\[\]])/\\$1/g;
2011like(1994like(
2012 $output,1995 $output,
2013 qr/^$synop{description} For more details.+\nUsage: \Q$synop{usage}\E\n?$/m,1996 qr/^$synop{description} For more details.+\nUsage: $synop{usage}$/m,
2014 "Uses desc and usage from SYNOPSIS for help"1997 "Uses desc and usage from SYNOPSIS for help"
2015);1998);
20161999
2017# Add a value_is_optional option
2018@ARGV = qw();
2019$o->get_opts();
2020
2021ok(
2022 !$o->got('version-check'),
2023 "version-check is not true by default"
2024);
2025
2026is(
2027 $o->get('version-check'),
2028 "https",
2029 "..but it still has a value",
2030);
2031
2032@ARGV = qw(--version-check);
2033$o->get_opts();
2034
2035ok(
2036 $o->got('version-check'),
2037 "version-check is true if specified without arguments"
2038);
2039
2040is(
2041 $o->get('version-check'),
2042 "https",
2043 "..and has the default value",
2044);
2045
2046@ARGV = qw(--version-check http);
2047$o->get_opts();
2048
2049ok(
2050 $o->got('version-check'),
2051 "version-check is true if specified with arguments"
2052);
2053
2054is(
2055 $o->get('version-check'),
2056 "http",
2057 "..and has the specified value",
2058);
2059
2060# #############################################################################2000# #############################################################################
2061# Bug 1039074: Tools exit 0 on error parsing options, should exit non-zero2001# Bug 1039074: Tools exit 0 on error parsing options, should exit non-zero
2062# #############################################################################2002# #############################################################################
@@ -2094,3 +2034,4 @@
2094);2034);
20952035
2096done_testing;2036done_testing;
2037exit;
20972038
=== modified file 't/lib/Pingback.t'
--- t/lib/Pingback.t 2012-10-06 17:39:02 +0000
+++ t/lib/Pingback.t 2012-11-06 15:04:24 +0000
@@ -510,6 +510,24 @@
510}510}
511511
512# #############################################################################512# #############################################################################
513# Check that the --v-c OPT validation works everywhere
514# #############################################################################
515
516use File::Basename qw(basename);
517
518my @vc_tools = grep { chomp; basename($_) =~ /\A[a-z-]+\z/ }
519 `grep --files-with-matches Pingback $trunk/bin/*`;
520
521foreach my $tool ( @vc_tools ) {
522 my $output = `$tool --version-check ftp`;
523 like(
524 $output,
525 qr/\Q* --version-check invalid value ftp. Accepted values are https, http, auto and off/,
526 "Valid values for v-c are checked in $tool"
527 );
528}
529
530# #############################################################################
513# Done.531# Done.
514# #############################################################################532# #############################################################################
515$sb->wipe_clean($master_dbh) if $master_dbh;533$sb->wipe_clean($master_dbh) if $master_dbh;
516534
=== modified file 't/pt-query-digest/version_check.t'
--- t/pt-query-digest/version_check.t 2012-09-24 20:12:53 +0000
+++ t/pt-query-digest/version_check.t 2012-11-06 15:04:24 +0000
@@ -109,6 +109,19 @@
109 "percona-toolkit-version-check file not created with --no-version-check"109 "percona-toolkit-version-check file not created with --no-version-check"
110);110);
111111
112$output = `PTVCDEBUG=1 $cmd --version-check off @args 2>&1`;
113
114unlike(
115 $output,
116 qr/(?:VersionCheck|Pingback|Percona suggests)/,
117 "Looks like --version-check off disabled the version-check"
118) or diag($output);
119
120ok(
121 !-f $check_time_file,
122 "percona-toolkit-version-check file not created with --version-check off"
123);
124
112# PERCONA_VERSION_CHECK=0 is handled in Pingback, so it will print a line125# PERCONA_VERSION_CHECK=0 is handled in Pingback, so it will print a line
113# for PTVCDEBUG saying why it didn't run. So we just check that it doesn't126# for PTVCDEBUG saying why it didn't run. So we just check that it doesn't
114# create the file which also signifies that it didn't run.127# create the file which also signifies that it didn't run.

Subscribers

People subscribed via source and target branches