~percona-toolkit-dev/percona-toolkit/fix-887638-ptqa-negative-at-byte

« back to all changes in this revision

Viewing changes to bin/pt-table-checksum

Merged OptionParser-remove-optional_value & updated modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
1047
1047
};
1048
1048
 
1049
1049
sub version_check {
1050
 
   my $args        = pop @_;
1051
 
   my (@instances) = @_;
 
1050
   my %args      = @_;
 
1051
   my @instances = $args{instances} ? @{ $args{instances} } : ();
1052
1052
 
1053
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
1055
                   "environment variable.\n\n";
1056
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
1064
   my $instances_to_check = [];
1060
1065
   my $time               = int(time());
1069
1074
      ($time_to_check, $instances_to_check)
1070
1075
         = time_to_check($check_time_file, \@instances, $time);
1071
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
1078
                      "only 1 check per day.\n\n";
1074
1079
         return;
1075
1080
      }
1076
1081
 
1077
 
      my $protocol = $args->{protocol} || 'https';
1078
 
      my $advice = pingback(
1079
 
         url       => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
1080
 
         instances => $instances_to_check,
1081
 
         protocol  => $args->{protocol},
1082
 
      );
 
1082
      my $advice;
 
1083
      my $e;
 
1084
      for my $protocol ( @protocols ) {
 
1085
         $advice = eval { pingback(
 
1086
            url       => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
 
1087
            instances => $instances_to_check,
 
1088
            protocol  => $protocol,
 
1089
         ) };
 
1090
         last if !$advice && !$EVAL_ERROR;
 
1091
         $e ||= $EVAL_ERROR;
 
1092
      }
1083
1093
      if ( $advice ) {
1084
1094
         print "# Percona suggests these upgrades:\n";
1085
1095
         print join("\n", map { "#   * $_" } @$advice), "\n\n";
1086
1096
      }
1087
1097
      else {
 
1098
         die $e if $e;
1088
1099
         print "# No suggestions at this time.\n\n";
1089
1100
         ($ENV{PTVCDEBUG} || PTDEBUG )
1090
1101
            && _d('--version-check worked, but there were no suggestions');
1110
1121
 
1111
1122
   my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};
1112
1123
 
1113
 
   $ua ||= HTTPMicro->new( timeout => 2 );
 
1124
   $ua ||= HTTPMicro->new( timeout => 5 );
1114
1125
   $vc ||= VersionCheck->new();
1115
1126
 
1116
1127
   my $response = $ua->request('GET', $url);
1326
1337
   return $client_response;
1327
1338
}
1328
1339
 
 
1340
sub 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
 
1329
1355
sub _d {
1330
1356
   my ($package, undef, $line) = caller 0;
1331
1357
   @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
1756
1782
      'default'    => 1,
1757
1783
      'cumulative' => 1,
1758
1784
      'negatable'  => 1,
1759
 
      'value_is_optional' => 1,
1760
1785
   );
1761
1786
 
1762
1787
   my $self = {
1998
2023
            $opt->{short} = undef;
1999
2024
         }
2000
2025
 
2001
 
         $opt->{is_negatable}   = $opt->{spec} =~ m/!/        ? 1 : 0;
2002
 
         $opt->{is_cumulative}  = $opt->{spec} =~ m/\+/       ? 1 : 0;
2003
 
         $opt->{optional_value} = $opt->{spec} =~ m/:/        ? 1 : 0;
2004
 
         $opt->{is_required}    = $opt->{desc} =~ m/required/ ? 1 : 0;
 
2026
         $opt->{is_negatable}  = $opt->{spec} =~ m/!/        ? 1 : 0;
 
2027
         $opt->{is_cumulative} = $opt->{spec} =~ m/\+/       ? 1 : 0;
 
2028
         $opt->{is_required}   = $opt->{desc} =~ m/required/ ? 1 : 0;
2005
2029
 
2006
2030
         $opt->{group} ||= 'default';
2007
2031
         $self->{groups}->{ $opt->{group} }->{$long} = 1;
2137
2161
   if ( $opt->{is_cumulative} ) {
2138
2162
      $opt->{value}++;
2139
2163
   }
2140
 
   elsif ( !($opt->{optional_value} && !$val) ) {
 
2164
   else {
2141
2165
      $opt->{value} = $val;
2142
2166
   }
2143
2167
   $opt->{got} = 1;
2678
2702
sub _parse_attribs {
2679
2703
   my ( $self, $option, $attribs ) = @_;
2680
2704
   my $types = $self->{types};
2681
 
   my $eq    = $attribs->{'value_is_optional'} ? ':' : '=';
2682
2705
   return $option
2683
2706
      . ($attribs->{'short form'} ? '|' . $attribs->{'short form'}   : '' )
2684
2707
      . ($attribs->{'negatable'}  ? '!'                              : '' )
2685
2708
      . ($attribs->{'cumulative'} ? '+'                              : '' )
2686
 
      . ($attribs->{'type'}       ? $eq . $types->{$attribs->{type}} : '' );
 
2709
      . ($attribs->{'type'}       ? '=' . $types->{$attribs->{type}} : '' );
2687
2710
}
2688
2711
 
2689
2712
sub _parse_synopsis {
8377
8400
      $o->save_error("Invalid --recursion-method: $EVAL_ERROR")
8378
8401
   }
8379
8402
 
 
8403
   Pingback::validate_options($o);
 
8404
   
8380
8405
   $o->usage_or_errors();
8381
8406
 
8382
8407
   # ########################################################################
8828
8853
   # ########################################################################
8829
8854
   # Do the version-check
8830
8855
   # ########################################################################
8831
 
   if ( $o->got('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) {
 
8856
   if ( $o->get('version-check') ne 'off' && (!$o->has('quiet') || !$o->get('quiet')) ) {
8832
8857
      Pingback::version_check(
8833
 
         { dbh => $master_dbh, dsn => $master_dsn },
8834
 
         map({ +{ dbh => $_->dbh(), dsn => $_->dsn() } } @$slaves),
8835
 
         { protocol => $o->get('version-check') },
 
8858
         instances => [
 
8859
            { dbh => $master_dbh, dsn => $master_dsn },
 
8860
            map({ +{ dbh => $_->dbh(), dsn => $_->dsn() } } @$slaves)
 
8861
         ],
 
8862
         protocol => $o->get('version-check'),
8836
8863
      );
8837
8864
   }
8838
8865
 
11322
11349
 
11323
11350
=item --version-check
11324
11351
 
11325
 
type: string; value_is_optional: yes; default: https
 
11352
type: string; default: off
11326
11353
 
11327
11354
Send program versions to Percona and print suggested upgrades and problems.
11328
 
 
11329
 
If specified without a value, it will use https by default; However, this
11330
 
might fail if C<IO::Socket::SSL> is not installed on your system, in which
11331
 
case you may choose to use C<--version-check http>, which will forgo
11332
 
encryption but should work out of the box.
 
11355
Possible values for --version-check:
 
11356
 
 
11357
=for comment ignore-pt-internal-value
 
11358
MAGIC_version_check
 
11359
 
 
11360
https, http, auto, off
 
11361
 
 
11362
C<auto> first tries using C<https>, and resorts to C<http> if that fails.
 
11363
Keep in mind that C<https> might not be available if
 
11364
C<IO::Socket::SSL> is not installed on your system, although
 
11365
C<--version-check http> should work everywhere.
11333
11366
 
11334
11367
The version check feature causes the tool to send and receive data from
11335
11368
Percona over the web.  The data contains program versions from the local