mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-12 22:19:44 +00:00
Validate --max|critical-load (work in progress).
This commit is contained in:
@@ -4979,6 +4979,16 @@ sub main {
|
|||||||
# Explicit --chunk-size disable auto chunk sizing.
|
# Explicit --chunk-size disable auto chunk sizing.
|
||||||
$o->set('chunk-time', 0) if $o->got('chunk-size');
|
$o->set('chunk-time', 0) if $o->got('chunk-size');
|
||||||
|
|
||||||
|
foreach my $opt ( qw(max-load critical-load) ) {
|
||||||
|
my $spec = $o->get($opt);
|
||||||
|
eval {
|
||||||
|
MySQLStatusWaiter::_parse_spec($o->get($spec));
|
||||||
|
};
|
||||||
|
if ( $EVAL_ERROR ) {
|
||||||
|
$o->save_error("Invalid --$opt: $spec");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( !$o->get('help') ) {
|
if ( !$o->get('help') ) {
|
||||||
if ( @ARGV ) {
|
if ( @ARGV ) {
|
||||||
$o->save_error('Specify only one DSN on the command line');
|
$o->save_error('Specify only one DSN on the command line');
|
||||||
|
@@ -45,15 +45,17 @@ sub new {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PTDEBUG && _d('Parsing spec for max thresholds');
|
PTDEBUG && _d('Parsing spec for max thresholds');
|
||||||
my $max_val_for = _parse_spec(
|
my $max_val_for = _parse_spec($args{max_spec});
|
||||||
spec => $args{max_spec},
|
_set_initial_vals(
|
||||||
|
vars => $max_val_for,
|
||||||
get_status => $args{get_status},
|
get_status => $args{get_status},
|
||||||
threshold_factor => 0.2, # +20%
|
threshold_factor => 0.2, # +20%
|
||||||
);
|
);
|
||||||
|
|
||||||
PTDEBUG && _d('Parsing spec for critical thresholds');
|
PTDEBUG && _d('Parsing spec for critical thresholds');
|
||||||
my $critical_val_for = _parse_spec(
|
my $critical_val_for = _parse_spec($args{critical_spec} || []);
|
||||||
spec => $args{critical_spec} || [],
|
_set_initial_vals(
|
||||||
|
vars => $critical_val_for,
|
||||||
get_status => $args{get_status},
|
get_status => $args{get_status},
|
||||||
threshold_factor => 1.0, # double (x2; +100%)
|
threshold_factor => 1.0, # double (x2; +100%)
|
||||||
);
|
);
|
||||||
@@ -79,28 +81,24 @@ sub new {
|
|||||||
# Returns:
|
# Returns:
|
||||||
# Hashref with each variable's maximum permitted value.
|
# Hashref with each variable's maximum permitted value.
|
||||||
sub _parse_spec {
|
sub _parse_spec {
|
||||||
my ( %args ) = @_;
|
my ($spec) = @_;
|
||||||
my @required_args = qw(spec get_status);
|
|
||||||
foreach my $arg ( @required_args ) {
|
|
||||||
die "I need a $arg argument" unless defined $args{$arg};
|
|
||||||
}
|
|
||||||
my ($spec, $get_status) = @args{@required_args};
|
|
||||||
|
|
||||||
return unless $spec && scalar @$spec;
|
return unless $spec && scalar @$spec;
|
||||||
my $threshold_factor = $args{threshold_factor} || 0.20;
|
|
||||||
|
|
||||||
my %max_val_for;
|
my %max_val_for;
|
||||||
foreach my $var_val ( @$spec ) {
|
foreach my $var_val ( @$spec ) {
|
||||||
my ($var, $val) = split /[:=]/, $var_val;
|
my ($var, $val) = split /[:=]/, $var_val;
|
||||||
die "Invalid spec: $var_val" unless $var;
|
die "Invalid spec: $var_val" unless $var;
|
||||||
|
|
||||||
if ( !$val ) {
|
if ( !$val ) {
|
||||||
my $init_val = $get_status->($var);
|
PTDEBUG && _d('Will get intial value for', $var, 'later');
|
||||||
PTDEBUG && _d('Initial', $var, 'value:', $init_val);
|
$max_val_for{$var} = undef;
|
||||||
$val = int(($init_val * $threshold_factor) + $init_val);
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
PTDEBUG && _d('Wait if', $var, '>=', $val);
|
PTDEBUG && _d('Wait if', $var, '>=', $val);
|
||||||
$max_val_for{$var} = $val;
|
$max_val_for{$var} = $val;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return \%max_val_for;
|
return \%max_val_for;
|
||||||
}
|
}
|
||||||
@@ -192,6 +190,31 @@ sub wait {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub _set_initial_vals {
|
||||||
|
my (%args) = @_;
|
||||||
|
my @required_args = qw(vars get_status threshold_factor);
|
||||||
|
foreach my $arg ( @required_args ) {
|
||||||
|
die "I need a $arg argument" unless defined $args{$arg};
|
||||||
|
}
|
||||||
|
my ($vars, $get_status, $threshold_factor) = @args{@required_args};
|
||||||
|
|
||||||
|
PTDEBUG && _d('Setting initial values');
|
||||||
|
return unless $vars && scalar %$vars;
|
||||||
|
|
||||||
|
foreach my $var ( keys %$vars ) {
|
||||||
|
next if defined $vars->{$var};
|
||||||
|
|
||||||
|
my $init_val = $get_status->($var);
|
||||||
|
PTDEBUG && _d('Initial', $var, 'value:', $init_val);
|
||||||
|
die "Variable does not exist or has undefined value: $var"
|
||||||
|
unless defined $init_val;
|
||||||
|
|
||||||
|
my $val = int(($init_val * $threshold_factor) + $init_val);
|
||||||
|
$vars->{$var} = $val;
|
||||||
|
PTDEBUG && _d('Wait if', $var, '>=', $val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub _d {
|
sub _d {
|
||||||
my ($package, undef, $line) = caller 0;
|
my ($package, undef, $line) = caller 0;
|
||||||
@_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
|
@_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
|
||||||
|
@@ -39,6 +39,21 @@ sub sleep {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# #############################################################################
|
||||||
|
# _parse_spec()
|
||||||
|
# #############################################################################
|
||||||
|
|
||||||
|
throws_ok(
|
||||||
|
sub { new MySQLStatusWaiter(
|
||||||
|
max_spec => '100',
|
||||||
|
get_status => \&get_status,
|
||||||
|
sleep => \&sleep,
|
||||||
|
oktorun => \&oktorun,
|
||||||
|
) },
|
||||||
|
qr/Invalid spec/,
|
||||||
|
"Validate max_spec"
|
||||||
|
);
|
||||||
|
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
# Use initial vals + 20%.
|
# Use initial vals + 20%.
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
|
@@ -9,7 +9,7 @@ BEGIN {
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings FATAL => 'all';
|
use warnings FATAL => 'all';
|
||||||
use English qw(-no_match_vars);
|
use English qw(-no_match_vars);
|
||||||
use Test::More tests => 6;
|
use Test::More tests => 8;
|
||||||
|
|
||||||
use PerconaTest;
|
use PerconaTest;
|
||||||
|
|
||||||
@@ -58,6 +58,20 @@ like(
|
|||||||
"Cannot --alter-foreign-keys-method=drop_swap with --no-drop-new-table"
|
"Cannot --alter-foreign-keys-method=drop_swap with --no-drop-new-table"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$output = `$cmd h=127.1,P=12345,u=msandbox,p=msandbox,D=mysql,t=user --max-load 100 --alter "ENGINE=MyISAM" --dry-run`;
|
||||||
|
like(
|
||||||
|
$output,
|
||||||
|
qr/Invalid --max-load/,
|
||||||
|
"Validates --max-load"
|
||||||
|
);
|
||||||
|
|
||||||
|
$output = `$cmd h=127.1,P=12345,u=msandbox,p=msandbox,D=mysql,t=user --critical-load 100 --alter "ENGINE=MyISAM" --dry-run`;
|
||||||
|
like(
|
||||||
|
$output,
|
||||||
|
qr/Invalid --critical-load/,
|
||||||
|
"Validates --critical-load"
|
||||||
|
);
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Done.
|
# Done.
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
|
Reference in New Issue
Block a user