diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index a7095af5..b1a3bbce 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -4802,7 +4802,6 @@ sub new { _check_and_set_vals( vars => $max_val_for, get_status => $args{get_status}, - ceiling => $args{ceiling}, threshold_factor => 0.2, # +20% ); } @@ -4953,7 +4952,7 @@ sub _check_and_set_vals { else { PTDEBUG && _d('Initial', $var, 'value:', $init_val); $val = ($init_val * $threshold_factor) + $init_val; - $vars->{$var} = $args{ceiling} ? int(ceil($val)) : int($val); + $vars->{$var} = int(ceil($val)); } PTDEBUG && _d('Wait if', $var, '>=', $val); } diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index aa34e6d0..dc8b8a60 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -8347,6 +8347,7 @@ package MySQLStatusWaiter; use strict; use warnings FATAL => 'all'; +use POSIX qw( ceil ); use English qw(-no_match_vars); use constant PTDEBUG => $ENV{PTDEBUG} || 0; @@ -8512,8 +8513,8 @@ sub _check_and_set_vals { } else { PTDEBUG && _d('Initial', $var, 'value:', $init_val); - $val = int(($init_val * $threshold_factor) + $init_val); - $vars->{$var} = $args{'ceiling'} ? ceil($val) : $val; + $val = ($init_val * $threshold_factor) + $init_val; + $vars->{$var} = int(ceil($val)); } PTDEBUG && _d('Wait if', $var, '>=', $val); } diff --git a/lib/MySQLStatusWaiter.pm b/lib/MySQLStatusWaiter.pm index 8ecbe7cb..99177be6 100644 --- a/lib/MySQLStatusWaiter.pm +++ b/lib/MySQLStatusWaiter.pm @@ -51,7 +51,6 @@ sub new { _check_and_set_vals( vars => $max_val_for, get_status => $args{get_status}, - ceiling => $args{ceiling}, threshold_factor => 0.2, # +20% ); } @@ -224,7 +223,7 @@ sub _check_and_set_vals { else { PTDEBUG && _d('Initial', $var, 'value:', $init_val); $val = ($init_val * $threshold_factor) + $init_val; - $vars->{$var} = $args{ceiling} ? int(ceil($val)) : int($val); + $vars->{$var} = int(ceil($val)); } PTDEBUG && _d('Wait if', $var, '>=', $val); } diff --git a/t/lib/MySQLStatusWaiter.t b/t/lib/MySQLStatusWaiter.t index b46b20d6..1dadfccd 100644 --- a/t/lib/MySQLStatusWaiter.t +++ b/t/lib/MySQLStatusWaiter.t @@ -10,7 +10,7 @@ use strict; use warnings FATAL => 'all'; use POSIX qw( ceil floor ); use English qw(-no_match_vars); -use Test::More tests => 22; +use Test::More tests => 17; use MySQLStatusWaiter; use PerconaTest; @@ -78,33 +78,35 @@ throws_ok( "Catch non-existent variable" ); + # ############################################################################ -# Use initial vals + 20%. +# Initial vals + 20% # ############################################################################ + @vals = ( # initial check for existence - { Threads_connected => 10, }, - { Threads_running => 5, }, + { Threads_connected => 9, }, + { Threads_running => 4, }, # first check, no wait { Threads_connected => 1, }, { Threads_running => 1, }, # second check, wait - { Threads_connected => 12, }, # too high - { Threads_running => 6, }, # too high + { Threads_connected => 11, }, # too high + { Threads_running => 5, }, # too high # third check, wait - { Threads_connected => 12, }, # too high - { Threads_running => 5, }, + { Threads_connected => 11, }, # too high + { Threads_running => 4, }, # fourth check, wait { Threads_connected => 10, }, - { Threads_running => 6, }, # too high + { Threads_running => 5, }, # too high # fifth check, no wait { Threads_connected => 10, }, - { Threads_running => 5, }, + { Threads_running => 4, }, ); $oktorun = 1; @@ -119,10 +121,10 @@ my $sw = new MySQLStatusWaiter( is_deeply( $sw->max_values(), { - Threads_connected => int(10 + (10 * 0.20)), - Threads_running => int(5 + (5 * 0.20)), + Threads_connected => ceil(9 + (9 * 0.20)), + Threads_running => ceil(4 + (4 * 0.20)), }, - "Initial values +20%" + "Threshold = ceil(InitialValue * 1.2)" ); # first check @@ -164,94 +166,6 @@ is( "Slept until values low enough" ); -# ############################################################################ -# Initial vals + 20% plus ceiling option -# ############################################################################ - -@vals = ( - # initial check for existence - { Threads_connected => 9, }, - { Threads_running => 4, }, - - # first check, no wait - { Threads_connected => 1, }, - { Threads_running => 1, }, - - # second check, wait - { Threads_connected => 11, }, # too high - { Threads_running => 5, }, # too high - - # third check, wait - { Threads_connected => 11, }, # too high - { Threads_running => 4, }, - - # fourth check, wait - { Threads_connected => 10, }, - { Threads_running => 5, }, # too high - - # fifth check, no wait - { Threads_connected => 10, }, - { Threads_running => 4, }, -); - -$oktorun = 1; - -$sw = new MySQLStatusWaiter( - oktorun => \&oktorun, - get_status => \&get_status, - sleep => \&sleep, - ceiling => 'true', - max_spec => [qw(Threads_connected Threads_running)], -); - -is_deeply( - $sw->max_values(), - { - Threads_connected => ceil(9 + (9 * 0.20)), - Threads_running => ceil(4 + (4 * 0.20)), - }, - "Using Ceiling: Initial values = ceil(val+20%)" -); - -# first check -@checked = (); -$slept = 0; -$sw->wait(); - -is_deeply( - \@checked, - [qw(Threads_connected Threads_running)], - "Using Ceiling: Checked both vars" -); - -is( - $slept, - 0, - "Using Ceiling: Vals not too high, did not sleep" -); - -# second through fifth checks -@checked = (); -$slept = 0; -$sw->wait(); - -is_deeply( - \@checked, - [qw( - Threads_connected Threads_running - Threads_connected Threads_running - Threads_connected Threads_running - Threads_connected Threads_running - )], - "Using Ceiling: Rechecked all variables" -); - -is( - $slept, - 3, - "Using Ceiling: Slept until values low enough" -); - # ############################################################################ # Use static vals. # ############################################################################