Merge lp:~percona-toolkit-dev/percona-toolkit/validate-load-options-bug-996915 into lp:percona-toolkit/2.1
- validate-load-options-bug-996915
- Merge into 2.1
Proposed by
Daniel Nichter
Status: | Merged |
---|---|
Merged at revision: | 268 |
Proposed branch: | lp:~percona-toolkit-dev/percona-toolkit/validate-load-options-bug-996915 |
Merge into: | lp:percona-toolkit/2.1 |
Diff against target: |
612 lines (+315/-89) 6 files modified
bin/pt-online-schema-change (+91/-31) bin/pt-table-checksum (+88/-30) lib/MySQLStatusWaiter.pm (+60/-24) t/lib/MySQLStatusWaiter.t (+49/-2) t/pt-online-schema-change/option_sanity.t (+15/-1) t/pt-table-checksum/option_sanity.t (+12/-1) |
To merge this branch: | bzr merge lp:~percona-toolkit-dev/percona-toolkit/validate-load-options-bug-996915 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Daniel Nichter | Approve | ||
Review via email: mp+107480@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
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
1 | === modified file 'bin/pt-online-schema-change' | |||
2 | --- bin/pt-online-schema-change 2012-05-25 16:24:32 +0000 | |||
3 | +++ bin/pt-online-schema-change 2012-05-25 21:39:18 +0000 | |||
4 | @@ -3701,18 +3701,24 @@ | |||
5 | 3701 | } | 3701 | } |
6 | 3702 | 3702 | ||
7 | 3703 | PTDEBUG && _d('Parsing spec for max thresholds'); | 3703 | PTDEBUG && _d('Parsing spec for max thresholds'); |
13 | 3704 | my $max_val_for = _parse_spec( | 3704 | my $max_val_for = _parse_spec($args{max_spec}); |
14 | 3705 | spec => $args{max_spec}, | 3705 | if ( $max_val_for ) { |
15 | 3706 | get_status => $args{get_status}, | 3706 | _check_and_set_vals( |
16 | 3707 | threshold_factor => 0.2, # +20% | 3707 | vars => $max_val_for, |
17 | 3708 | ); | 3708 | get_status => $args{get_status}, |
18 | 3709 | threshold_factor => 0.2, # +20% | ||
19 | 3710 | ); | ||
20 | 3711 | } | ||
21 | 3709 | 3712 | ||
22 | 3710 | PTDEBUG && _d('Parsing spec for critical thresholds'); | 3713 | PTDEBUG && _d('Parsing spec for critical thresholds'); |
28 | 3711 | my $critical_val_for = _parse_spec( | 3714 | my $critical_val_for = _parse_spec($args{critical_spec} || []); |
29 | 3712 | spec => $args{critical_spec} || [], | 3715 | if ( $critical_val_for ) { |
30 | 3713 | get_status => $args{get_status}, | 3716 | _check_and_set_vals( |
31 | 3714 | threshold_factor => 1.0, # double (x2; +100%) | 3717 | vars => $critical_val_for, |
32 | 3715 | ); | 3718 | get_status => $args{get_status}, |
33 | 3719 | threshold_factor => 1.0, # double (x2; +100%) | ||
34 | 3720 | ); | ||
35 | 3721 | } | ||
36 | 3716 | 3722 | ||
37 | 3717 | my $self = { | 3723 | my $self = { |
38 | 3718 | get_status => $args{get_status}, | 3724 | get_status => $args{get_status}, |
39 | @@ -3726,27 +3732,29 @@ | |||
40 | 3726 | } | 3732 | } |
41 | 3727 | 3733 | ||
42 | 3728 | sub _parse_spec { | 3734 | sub _parse_spec { |
49 | 3729 | my ( %args ) = @_; | 3735 | my ($spec) = @_; |
44 | 3730 | my @required_args = qw(spec get_status); | ||
45 | 3731 | foreach my $arg ( @required_args ) { | ||
46 | 3732 | die "I need a $arg argument" unless defined $args{$arg}; | ||
47 | 3733 | } | ||
48 | 3734 | my ($spec, $get_status) = @args{@required_args}; | ||
50 | 3735 | 3736 | ||
51 | 3736 | return unless $spec && scalar @$spec; | 3737 | return unless $spec && scalar @$spec; |
52 | 3737 | my $threshold_factor = $args{threshold_factor} || 0.20; | ||
53 | 3738 | 3738 | ||
54 | 3739 | my %max_val_for; | 3739 | my %max_val_for; |
55 | 3740 | foreach my $var_val ( @$spec ) { | 3740 | foreach my $var_val ( @$spec ) { |
56 | 3741 | die "Empty or undefined spec\n" unless $var_val; | ||
57 | 3742 | $var_val =~ s/^\s+//; | ||
58 | 3743 | $var_val =~ s/\s+$//g; | ||
59 | 3744 | |||
60 | 3741 | my ($var, $val) = split /[:=]/, $var_val; | 3745 | my ($var, $val) = split /[:=]/, $var_val; |
62 | 3742 | die "Invalid spec: $var_val" unless $var; | 3746 | die "$var_val does not contain a variable\n" unless $var; |
63 | 3747 | die "$var is not a variable name\n" unless $var =~ m/^[a-zA-Z_]+$/; | ||
64 | 3748 | |||
65 | 3743 | if ( !$val ) { | 3749 | if ( !$val ) { |
72 | 3744 | my $init_val = $get_status->($var); | 3750 | PTDEBUG && _d('Will get intial value for', $var, 'later'); |
73 | 3745 | PTDEBUG && _d('Initial', $var, 'value:', $init_val); | 3751 | $max_val_for{$var} = undef; |
74 | 3746 | $val = int(($init_val * $threshold_factor) + $init_val); | 3752 | } |
75 | 3747 | } | 3753 | else { |
76 | 3748 | PTDEBUG && _d('Wait if', $var, '>=', $val); | 3754 | die "The value for $var must be a number\n" |
77 | 3749 | $max_val_for{$var} = $val; | 3755 | unless $val =~ m/^[\d\.]+$/; |
78 | 3756 | $max_val_for{$var} = $val; | ||
79 | 3757 | } | ||
80 | 3750 | } | 3758 | } |
81 | 3751 | 3759 | ||
82 | 3752 | return \%max_val_for; | 3760 | return \%max_val_for; |
83 | @@ -3826,6 +3834,34 @@ | |||
84 | 3826 | return; | 3834 | return; |
85 | 3827 | } | 3835 | } |
86 | 3828 | 3836 | ||
87 | 3837 | sub _check_and_set_vals { | ||
88 | 3838 | my (%args) = @_; | ||
89 | 3839 | my @required_args = qw(vars get_status threshold_factor); | ||
90 | 3840 | foreach my $arg ( @required_args ) { | ||
91 | 3841 | die "I need a $arg argument" unless defined $args{$arg}; | ||
92 | 3842 | } | ||
93 | 3843 | my ($vars, $get_status, $threshold_factor) = @args{@required_args}; | ||
94 | 3844 | |||
95 | 3845 | PTDEBUG && _d('Checking and setting values'); | ||
96 | 3846 | return unless $vars && scalar %$vars; | ||
97 | 3847 | |||
98 | 3848 | foreach my $var ( keys %$vars ) { | ||
99 | 3849 | my $init_val = $get_status->($var); | ||
100 | 3850 | die "Variable $var does not exist or its value is undefined\n" | ||
101 | 3851 | unless defined $init_val; | ||
102 | 3852 | my $val; | ||
103 | 3853 | if ( defined $vars->{$var} ) { | ||
104 | 3854 | $val = $vars->{$var}; | ||
105 | 3855 | } | ||
106 | 3856 | else { | ||
107 | 3857 | PTDEBUG && _d('Initial', $var, 'value:', $init_val); | ||
108 | 3858 | $val = int(($init_val * $threshold_factor) + $init_val); | ||
109 | 3859 | $vars->{$var} = $val; | ||
110 | 3860 | } | ||
111 | 3861 | PTDEBUG && _d('Wait if', $var, '>=', $val); | ||
112 | 3862 | } | ||
113 | 3863 | } | ||
114 | 3864 | |||
115 | 3829 | sub _d { | 3865 | sub _d { |
116 | 3830 | my ($package, undef, $line) = caller 0; | 3866 | my ($package, undef, $line) = caller 0; |
117 | 3831 | @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; } | 3867 | @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; } |
118 | @@ -4979,6 +5015,18 @@ | |||
119 | 4979 | # Explicit --chunk-size disable auto chunk sizing. | 5015 | # Explicit --chunk-size disable auto chunk sizing. |
120 | 4980 | $o->set('chunk-time', 0) if $o->got('chunk-size'); | 5016 | $o->set('chunk-time', 0) if $o->got('chunk-size'); |
121 | 4981 | 5017 | ||
122 | 5018 | foreach my $opt ( qw(max-load critical-load) ) { | ||
123 | 5019 | next unless $o->has($opt); | ||
124 | 5020 | my $spec = $o->get($opt); | ||
125 | 5021 | eval { | ||
126 | 5022 | MySQLStatusWaiter::_parse_spec($o->get($opt)); | ||
127 | 5023 | }; | ||
128 | 5024 | if ( $EVAL_ERROR ) { | ||
129 | 5025 | chomp $EVAL_ERROR; | ||
130 | 5026 | $o->save_error("Invalid --$opt: $EVAL_ERROR"); | ||
131 | 5027 | } | ||
132 | 5028 | } | ||
133 | 5029 | |||
134 | 4982 | if ( !$o->get('help') ) { | 5030 | if ( !$o->get('help') ) { |
135 | 4983 | if ( @ARGV ) { | 5031 | if ( @ARGV ) { |
136 | 4984 | $o->save_error('Specify only one DSN on the command line'); | 5032 | $o->save_error('Specify only one DSN on the command line'); |
137 | @@ -5226,13 +5274,25 @@ | |||
138 | 5226 | }; | 5274 | }; |
139 | 5227 | } | 5275 | } |
140 | 5228 | 5276 | ||
148 | 5229 | $sys_load = new MySQLStatusWaiter( | 5277 | eval { |
149 | 5230 | max_spec => $o->get('max-load'), | 5278 | $sys_load = new MySQLStatusWaiter( |
150 | 5231 | critical_spec => $o->get('critical-load'), | 5279 | max_spec => $o->get('max-load'), |
151 | 5232 | get_status => $get_status, | 5280 | critical_spec => $o->get('critical-load'), |
152 | 5233 | oktorun => sub { return $oktorun }, | 5281 | get_status => $get_status, |
153 | 5234 | sleep => $sleep, | 5282 | oktorun => sub { return $oktorun }, |
154 | 5235 | ); | 5283 | sleep => $sleep, |
155 | 5284 | ); | ||
156 | 5285 | }; | ||
157 | 5286 | if ( $EVAL_ERROR ) { | ||
158 | 5287 | chomp $EVAL_ERROR; | ||
159 | 5288 | die "Error checking --max-load or --critial-load: $EVAL_ERROR. " | ||
160 | 5289 | . "Check that the variables specified for --max-load and " | ||
161 | 5290 | . "--critical-load are spelled correctly and exist in " | ||
162 | 5291 | . "SHOW GLOBAL STATUS. Current values for these options are:\n" | ||
163 | 5292 | . " --max-load " . (join(',', @{$o->get('max-load')})) . "\n" | ||
164 | 5293 | . " --critial-load " . (join(',', @{$o->get('critical-load')})) | ||
165 | 5294 | . "\n"; | ||
166 | 5295 | } | ||
167 | 5236 | 5296 | ||
168 | 5237 | if ( $o->get('progress') ) { | 5297 | if ( $o->get('progress') ) { |
169 | 5238 | $replica_lag_pr = new Progress( | 5298 | $replica_lag_pr = new Progress( |
170 | 5239 | 5299 | ||
171 | === modified file 'bin/pt-table-checksum' | |||
172 | --- bin/pt-table-checksum 2012-05-24 17:25:20 +0000 | |||
173 | +++ bin/pt-table-checksum 2012-05-25 21:39:18 +0000 | |||
174 | @@ -5653,18 +5653,24 @@ | |||
175 | 5653 | } | 5653 | } |
176 | 5654 | 5654 | ||
177 | 5655 | PTDEBUG && _d('Parsing spec for max thresholds'); | 5655 | PTDEBUG && _d('Parsing spec for max thresholds'); |
183 | 5656 | my $max_val_for = _parse_spec( | 5656 | my $max_val_for = _parse_spec($args{max_spec}); |
184 | 5657 | spec => $args{max_spec}, | 5657 | if ( $max_val_for ) { |
185 | 5658 | get_status => $args{get_status}, | 5658 | _check_and_set_vals( |
186 | 5659 | threshold_factor => 0.2, # +20% | 5659 | vars => $max_val_for, |
187 | 5660 | ); | 5660 | get_status => $args{get_status}, |
188 | 5661 | threshold_factor => 0.2, # +20% | ||
189 | 5662 | ); | ||
190 | 5663 | } | ||
191 | 5661 | 5664 | ||
192 | 5662 | PTDEBUG && _d('Parsing spec for critical thresholds'); | 5665 | PTDEBUG && _d('Parsing spec for critical thresholds'); |
198 | 5663 | my $critical_val_for = _parse_spec( | 5666 | my $critical_val_for = _parse_spec($args{critical_spec} || []); |
199 | 5664 | spec => $args{critical_spec} || [], | 5667 | if ( $critical_val_for ) { |
200 | 5665 | get_status => $args{get_status}, | 5668 | _check_and_set_vals( |
201 | 5666 | threshold_factor => 1.0, # double (x2; +100%) | 5669 | vars => $critical_val_for, |
202 | 5667 | ); | 5670 | get_status => $args{get_status}, |
203 | 5671 | threshold_factor => 1.0, # double (x2; +100%) | ||
204 | 5672 | ); | ||
205 | 5673 | } | ||
206 | 5668 | 5674 | ||
207 | 5669 | my $self = { | 5675 | my $self = { |
208 | 5670 | get_status => $args{get_status}, | 5676 | get_status => $args{get_status}, |
209 | @@ -5678,27 +5684,29 @@ | |||
210 | 5678 | } | 5684 | } |
211 | 5679 | 5685 | ||
212 | 5680 | sub _parse_spec { | 5686 | sub _parse_spec { |
219 | 5681 | my ( %args ) = @_; | 5687 | my ($spec) = @_; |
214 | 5682 | my @required_args = qw(spec get_status); | ||
215 | 5683 | foreach my $arg ( @required_args ) { | ||
216 | 5684 | die "I need a $arg argument" unless defined $args{$arg}; | ||
217 | 5685 | } | ||
218 | 5686 | my ($spec, $get_status) = @args{@required_args}; | ||
220 | 5687 | 5688 | ||
221 | 5688 | return unless $spec && scalar @$spec; | 5689 | return unless $spec && scalar @$spec; |
222 | 5689 | my $threshold_factor = $args{threshold_factor} || 0.20; | ||
223 | 5690 | 5690 | ||
224 | 5691 | my %max_val_for; | 5691 | my %max_val_for; |
225 | 5692 | foreach my $var_val ( @$spec ) { | 5692 | foreach my $var_val ( @$spec ) { |
226 | 5693 | die "Empty or undefined spec\n" unless $var_val; | ||
227 | 5694 | $var_val =~ s/^\s+//; | ||
228 | 5695 | $var_val =~ s/\s+$//g; | ||
229 | 5696 | |||
230 | 5693 | my ($var, $val) = split /[:=]/, $var_val; | 5697 | my ($var, $val) = split /[:=]/, $var_val; |
232 | 5694 | die "Invalid spec: $var_val" unless $var; | 5698 | die "$var_val does not contain a variable\n" unless $var; |
233 | 5699 | die "$var is not a variable name\n" unless $var =~ m/^[a-zA-Z_]+$/; | ||
234 | 5700 | |||
235 | 5695 | if ( !$val ) { | 5701 | if ( !$val ) { |
242 | 5696 | my $init_val = $get_status->($var); | 5702 | PTDEBUG && _d('Will get intial value for', $var, 'later'); |
243 | 5697 | PTDEBUG && _d('Initial', $var, 'value:', $init_val); | 5703 | $max_val_for{$var} = undef; |
244 | 5698 | $val = int(($init_val * $threshold_factor) + $init_val); | 5704 | } |
245 | 5699 | } | 5705 | else { |
246 | 5700 | PTDEBUG && _d('Wait if', $var, '>=', $val); | 5706 | die "The value for $var must be a number\n" |
247 | 5701 | $max_val_for{$var} = $val; | 5707 | unless $val =~ m/^[\d\.]+$/; |
248 | 5708 | $max_val_for{$var} = $val; | ||
249 | 5709 | } | ||
250 | 5702 | } | 5710 | } |
251 | 5703 | 5711 | ||
252 | 5704 | return \%max_val_for; | 5712 | return \%max_val_for; |
253 | @@ -5778,6 +5786,34 @@ | |||
254 | 5778 | return; | 5786 | return; |
255 | 5779 | } | 5787 | } |
256 | 5780 | 5788 | ||
257 | 5789 | sub _check_and_set_vals { | ||
258 | 5790 | my (%args) = @_; | ||
259 | 5791 | my @required_args = qw(vars get_status threshold_factor); | ||
260 | 5792 | foreach my $arg ( @required_args ) { | ||
261 | 5793 | die "I need a $arg argument" unless defined $args{$arg}; | ||
262 | 5794 | } | ||
263 | 5795 | my ($vars, $get_status, $threshold_factor) = @args{@required_args}; | ||
264 | 5796 | |||
265 | 5797 | PTDEBUG && _d('Checking and setting values'); | ||
266 | 5798 | return unless $vars && scalar %$vars; | ||
267 | 5799 | |||
268 | 5800 | foreach my $var ( keys %$vars ) { | ||
269 | 5801 | my $init_val = $get_status->($var); | ||
270 | 5802 | die "Variable $var does not exist or its value is undefined\n" | ||
271 | 5803 | unless defined $init_val; | ||
272 | 5804 | my $val; | ||
273 | 5805 | if ( defined $vars->{$var} ) { | ||
274 | 5806 | $val = $vars->{$var}; | ||
275 | 5807 | } | ||
276 | 5808 | else { | ||
277 | 5809 | PTDEBUG && _d('Initial', $var, 'value:', $init_val); | ||
278 | 5810 | $val = int(($init_val * $threshold_factor) + $init_val); | ||
279 | 5811 | $vars->{$var} = $val; | ||
280 | 5812 | } | ||
281 | 5813 | PTDEBUG && _d('Wait if', $var, '>=', $val); | ||
282 | 5814 | } | ||
283 | 5815 | } | ||
284 | 5816 | |||
285 | 5781 | sub _d { | 5817 | sub _d { |
286 | 5782 | my ($package, undef, $line) = caller 0; | 5818 | my ($package, undef, $line) = caller 0; |
287 | 5783 | @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; } | 5819 | @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; } |
288 | @@ -5940,6 +5976,18 @@ | |||
289 | 5940 | 5976 | ||
290 | 5941 | $o->set('chunk-time', 0) if $o->got('chunk-size'); | 5977 | $o->set('chunk-time', 0) if $o->got('chunk-size'); |
291 | 5942 | 5978 | ||
292 | 5979 | foreach my $opt ( qw(max-load critical-load) ) { | ||
293 | 5980 | next unless $o->has($opt); | ||
294 | 5981 | my $spec = $o->get($opt); | ||
295 | 5982 | eval { | ||
296 | 5983 | MySQLStatusWaiter::_parse_spec($o->get($opt)); | ||
297 | 5984 | }; | ||
298 | 5985 | if ( $EVAL_ERROR ) { | ||
299 | 5986 | chomp $EVAL_ERROR; | ||
300 | 5987 | $o->save_error("Invalid --$opt: $EVAL_ERROR"); | ||
301 | 5988 | } | ||
302 | 5989 | } | ||
303 | 5990 | |||
304 | 5943 | if ( !$o->get('help') ) { | 5991 | if ( !$o->get('help') ) { |
305 | 5944 | if ( @ARGV > 1 ) { | 5992 | if ( @ARGV > 1 ) { |
306 | 5945 | $o->save_error("More than one host specified; only one allowed"); | 5993 | $o->save_error("More than one host specified; only one allowed"); |
307 | @@ -6299,12 +6347,22 @@ | |||
308 | 6299 | }; | 6347 | }; |
309 | 6300 | } | 6348 | } |
310 | 6301 | 6349 | ||
317 | 6302 | $sys_load = new MySQLStatusWaiter( | 6350 | eval { |
318 | 6303 | max_spec => $o->get('max-load'), | 6351 | $sys_load = new MySQLStatusWaiter( |
319 | 6304 | get_status => $get_status, | 6352 | max_spec => $o->get('max-load'), |
320 | 6305 | oktorun => sub { return $oktorun }, | 6353 | get_status => $get_status, |
321 | 6306 | sleep => $sleep, | 6354 | oktorun => sub { return $oktorun }, |
322 | 6307 | ); | 6355 | sleep => $sleep, |
323 | 6356 | ); | ||
324 | 6357 | }; | ||
325 | 6358 | if ( $EVAL_ERROR ) { | ||
326 | 6359 | chomp $EVAL_ERROR; | ||
327 | 6360 | die "Error checking --max-load: $EVAL_ERROR. " | ||
328 | 6361 | . "Check that the variables specified for --max-load " | ||
329 | 6362 | . "are spelled correctly and exist in " | ||
330 | 6363 | . "SHOW GLOBAL STATUS. Current value for this option is:\n" | ||
331 | 6364 | . " --max-load " . (join(',', @{$o->get('max-load')})) . "\n"; | ||
332 | 6365 | } | ||
333 | 6308 | 6366 | ||
334 | 6309 | if ( $o->get('progress') ) { | 6367 | if ( $o->get('progress') ) { |
335 | 6310 | $replica_lag_pr = new Progress( | 6368 | $replica_lag_pr = new Progress( |
336 | 6311 | 6369 | ||
337 | === modified file 'lib/MySQLStatusWaiter.pm' | |||
338 | --- lib/MySQLStatusWaiter.pm 2012-03-28 01:17:17 +0000 | |||
339 | +++ lib/MySQLStatusWaiter.pm 2012-05-25 21:39:18 +0000 | |||
340 | @@ -45,18 +45,24 @@ | |||
341 | 45 | } | 45 | } |
342 | 46 | 46 | ||
343 | 47 | PTDEBUG && _d('Parsing spec for max thresholds'); | 47 | PTDEBUG && _d('Parsing spec for max thresholds'); |
349 | 48 | my $max_val_for = _parse_spec( | 48 | my $max_val_for = _parse_spec($args{max_spec}); |
350 | 49 | spec => $args{max_spec}, | 49 | if ( $max_val_for ) { |
351 | 50 | get_status => $args{get_status}, | 50 | _check_and_set_vals( |
352 | 51 | threshold_factor => 0.2, # +20% | 51 | vars => $max_val_for, |
353 | 52 | ); | 52 | get_status => $args{get_status}, |
354 | 53 | threshold_factor => 0.2, # +20% | ||
355 | 54 | ); | ||
356 | 55 | } | ||
357 | 53 | 56 | ||
358 | 54 | PTDEBUG && _d('Parsing spec for critical thresholds'); | 57 | PTDEBUG && _d('Parsing spec for critical thresholds'); |
364 | 55 | my $critical_val_for = _parse_spec( | 58 | my $critical_val_for = _parse_spec($args{critical_spec} || []); |
365 | 56 | spec => $args{critical_spec} || [], | 59 | if ( $critical_val_for ) { |
366 | 57 | get_status => $args{get_status}, | 60 | _check_and_set_vals( |
367 | 58 | threshold_factor => 1.0, # double (x2; +100%) | 61 | vars => $critical_val_for, |
368 | 59 | ); | 62 | get_status => $args{get_status}, |
369 | 63 | threshold_factor => 1.0, # double (x2; +100%) | ||
370 | 64 | ); | ||
371 | 65 | } | ||
372 | 60 | 66 | ||
373 | 61 | my $self = { | 67 | my $self = { |
374 | 62 | get_status => $args{get_status}, | 68 | get_status => $args{get_status}, |
375 | @@ -79,27 +85,29 @@ | |||
376 | 79 | # Returns: | 85 | # Returns: |
377 | 80 | # Hashref with each variable's maximum permitted value. | 86 | # Hashref with each variable's maximum permitted value. |
378 | 81 | sub _parse_spec { | 87 | sub _parse_spec { |
385 | 82 | my ( %args ) = @_; | 88 | my ($spec) = @_; |
380 | 83 | my @required_args = qw(spec get_status); | ||
381 | 84 | foreach my $arg ( @required_args ) { | ||
382 | 85 | die "I need a $arg argument" unless defined $args{$arg}; | ||
383 | 86 | } | ||
384 | 87 | my ($spec, $get_status) = @args{@required_args}; | ||
386 | 88 | 89 | ||
387 | 89 | return unless $spec && scalar @$spec; | 90 | return unless $spec && scalar @$spec; |
388 | 90 | my $threshold_factor = $args{threshold_factor} || 0.20; | ||
389 | 91 | 91 | ||
390 | 92 | my %max_val_for; | 92 | my %max_val_for; |
391 | 93 | foreach my $var_val ( @$spec ) { | 93 | foreach my $var_val ( @$spec ) { |
392 | 94 | die "Empty or undefined spec\n" unless $var_val; | ||
393 | 95 | $var_val =~ s/^\s+//; | ||
394 | 96 | $var_val =~ s/\s+$//g; | ||
395 | 97 | |||
396 | 94 | my ($var, $val) = split /[:=]/, $var_val; | 98 | my ($var, $val) = split /[:=]/, $var_val; |
398 | 95 | die "Invalid spec: $var_val" unless $var; | 99 | die "$var_val does not contain a variable\n" unless $var; |
399 | 100 | die "$var is not a variable name\n" unless $var =~ m/^[a-zA-Z_]+$/; | ||
400 | 101 | |||
401 | 96 | if ( !$val ) { | 102 | if ( !$val ) { |
408 | 97 | my $init_val = $get_status->($var); | 103 | PTDEBUG && _d('Will get intial value for', $var, 'later'); |
409 | 98 | PTDEBUG && _d('Initial', $var, 'value:', $init_val); | 104 | $max_val_for{$var} = undef; |
410 | 99 | $val = int(($init_val * $threshold_factor) + $init_val); | 105 | } |
411 | 100 | } | 106 | else { |
412 | 101 | PTDEBUG && _d('Wait if', $var, '>=', $val); | 107 | die "The value for $var must be a number\n" |
413 | 102 | $max_val_for{$var} = $val; | 108 | unless $val =~ m/^[\d\.]+$/; |
414 | 109 | $max_val_for{$var} = $val; | ||
415 | 110 | } | ||
416 | 103 | } | 111 | } |
417 | 104 | 112 | ||
418 | 105 | return \%max_val_for; | 113 | return \%max_val_for; |
419 | @@ -192,6 +200,34 @@ | |||
420 | 192 | return; | 200 | return; |
421 | 193 | } | 201 | } |
422 | 194 | 202 | ||
423 | 203 | sub _check_and_set_vals { | ||
424 | 204 | my (%args) = @_; | ||
425 | 205 | my @required_args = qw(vars get_status threshold_factor); | ||
426 | 206 | foreach my $arg ( @required_args ) { | ||
427 | 207 | die "I need a $arg argument" unless defined $args{$arg}; | ||
428 | 208 | } | ||
429 | 209 | my ($vars, $get_status, $threshold_factor) = @args{@required_args}; | ||
430 | 210 | |||
431 | 211 | PTDEBUG && _d('Checking and setting values'); | ||
432 | 212 | return unless $vars && scalar %$vars; | ||
433 | 213 | |||
434 | 214 | foreach my $var ( keys %$vars ) { | ||
435 | 215 | my $init_val = $get_status->($var); | ||
436 | 216 | die "Variable $var does not exist or its value is undefined\n" | ||
437 | 217 | unless defined $init_val; | ||
438 | 218 | my $val; | ||
439 | 219 | if ( defined $vars->{$var} ) { | ||
440 | 220 | $val = $vars->{$var}; | ||
441 | 221 | } | ||
442 | 222 | else { | ||
443 | 223 | PTDEBUG && _d('Initial', $var, 'value:', $init_val); | ||
444 | 224 | $val = int(($init_val * $threshold_factor) + $init_val); | ||
445 | 225 | $vars->{$var} = $val; | ||
446 | 226 | } | ||
447 | 227 | PTDEBUG && _d('Wait if', $var, '>=', $val); | ||
448 | 228 | } | ||
449 | 229 | } | ||
450 | 230 | |||
451 | 195 | sub _d { | 231 | sub _d { |
452 | 196 | my ($package, undef, $line) = caller 0; | 232 | my ($package, undef, $line) = caller 0; |
453 | 197 | @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; } | 233 | @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; } |
454 | 198 | 234 | ||
455 | === modified file 't/lib/MySQLStatusWaiter.t' | |||
456 | --- t/lib/MySQLStatusWaiter.t 2012-03-28 01:17:17 +0000 | |||
457 | +++ t/lib/MySQLStatusWaiter.t 2012-05-25 21:39:18 +0000 | |||
458 | @@ -9,7 +9,7 @@ | |||
459 | 9 | use strict; | 9 | use strict; |
460 | 10 | use warnings FATAL => 'all'; | 10 | use warnings FATAL => 'all'; |
461 | 11 | use English qw(-no_match_vars); | 11 | use English qw(-no_match_vars); |
463 | 12 | use Test::More tests => 14; | 12 | use Test::More tests => 17; |
464 | 13 | 13 | ||
465 | 14 | use MySQLStatusWaiter; | 14 | use MySQLStatusWaiter; |
466 | 15 | use PerconaTest; | 15 | use PerconaTest; |
467 | @@ -39,11 +39,48 @@ | |||
468 | 39 | return; | 39 | return; |
469 | 40 | } | 40 | } |
470 | 41 | 41 | ||
471 | 42 | # ############################################################################# | ||
472 | 43 | # _parse_spec() | ||
473 | 44 | # ############################################################################# | ||
474 | 45 | |||
475 | 46 | throws_ok( | ||
476 | 47 | sub { new MySQLStatusWaiter( | ||
477 | 48 | max_spec => [qw(100)], | ||
478 | 49 | get_status => \&get_status, | ||
479 | 50 | sleep => \&sleep, | ||
480 | 51 | oktorun => \&oktorun, | ||
481 | 52 | ) }, | ||
482 | 53 | qr/100 is not a variable name/, | ||
483 | 54 | "Catch non-variable name" | ||
484 | 55 | ); | ||
485 | 56 | |||
486 | 57 | throws_ok( | ||
487 | 58 | sub { new MySQLStatusWaiter( | ||
488 | 59 | max_spec => [qw(foo=bar)], | ||
489 | 60 | get_status => \&get_status, | ||
490 | 61 | sleep => \&sleep, | ||
491 | 62 | oktorun => \&oktorun, | ||
492 | 63 | ) }, | ||
493 | 64 | qr/value for foo must be a number/, | ||
494 | 65 | "Catch non-number value" | ||
495 | 66 | ); | ||
496 | 67 | |||
497 | 68 | throws_ok( | ||
498 | 69 | sub { new MySQLStatusWaiter( | ||
499 | 70 | max_spec => [qw(foo)], | ||
500 | 71 | get_status => \&get_status, | ||
501 | 72 | sleep => \&sleep, | ||
502 | 73 | oktorun => \&oktorun, | ||
503 | 74 | ) }, | ||
504 | 75 | qr/foo does not exist/, | ||
505 | 76 | "Catch non-existent variable" | ||
506 | 77 | ); | ||
507 | 78 | |||
508 | 42 | # ############################################################################ | 79 | # ############################################################################ |
509 | 43 | # Use initial vals + 20%. | 80 | # Use initial vals + 20%. |
510 | 44 | # ############################################################################ | 81 | # ############################################################################ |
511 | 45 | @vals = ( | 82 | @vals = ( |
513 | 46 | # initial values | 83 | # initial check for existence |
514 | 47 | { Threads_connected => 10, }, | 84 | { Threads_connected => 10, }, |
515 | 48 | { Threads_running => 5, }, | 85 | { Threads_running => 5, }, |
516 | 49 | 86 | ||
517 | @@ -68,6 +105,8 @@ | |||
518 | 68 | { Threads_running => 5, }, | 105 | { Threads_running => 5, }, |
519 | 69 | ); | 106 | ); |
520 | 70 | 107 | ||
521 | 108 | $oktorun = 1; | ||
522 | 109 | |||
523 | 71 | my $sw = new MySQLStatusWaiter( | 110 | my $sw = new MySQLStatusWaiter( |
524 | 72 | oktorun => \&oktorun, | 111 | oktorun => \&oktorun, |
525 | 73 | get_status => \&get_status, | 112 | get_status => \&get_status, |
526 | @@ -127,6 +166,10 @@ | |||
527 | 127 | # Use static vals. | 166 | # Use static vals. |
528 | 128 | # ############################################################################ | 167 | # ############################################################################ |
529 | 129 | @vals = ( | 168 | @vals = ( |
530 | 169 | # initial check for existence | ||
531 | 170 | { Threads_connected => 1, }, | ||
532 | 171 | { Threads_running => 1, }, | ||
533 | 172 | |||
534 | 130 | # first check, no wait | 173 | # first check, no wait |
535 | 131 | { Threads_connected => 1, }, | 174 | { Threads_connected => 1, }, |
536 | 132 | { Threads_running => 1, }, | 175 | { Threads_running => 1, }, |
537 | @@ -208,6 +251,10 @@ | |||
538 | 208 | # Critical thresholds (with static vals). | 251 | # Critical thresholds (with static vals). |
539 | 209 | # ############################################################################ | 252 | # ############################################################################ |
540 | 210 | @vals = ( | 253 | @vals = ( |
541 | 254 | # initial check for existence | ||
542 | 255 | { Threads_running => 1, }, | ||
543 | 256 | { Threads_running => 9, }, | ||
544 | 257 | |||
545 | 211 | # first check, no wait | 258 | # first check, no wait |
546 | 212 | { Threads_running => 1, }, | 259 | { Threads_running => 1, }, |
547 | 213 | { Threads_running => 9, }, | 260 | { Threads_running => 9, }, |
548 | 214 | 261 | ||
549 | === modified file 't/pt-online-schema-change/option_sanity.t' | |||
550 | --- t/pt-online-schema-change/option_sanity.t 2012-05-25 16:24:32 +0000 | |||
551 | +++ t/pt-online-schema-change/option_sanity.t 2012-05-25 21:39:18 +0000 | |||
552 | @@ -9,7 +9,7 @@ | |||
553 | 9 | use strict; | 9 | use strict; |
554 | 10 | use warnings FATAL => 'all'; | 10 | use warnings FATAL => 'all'; |
555 | 11 | use English qw(-no_match_vars); | 11 | use English qw(-no_match_vars); |
557 | 12 | use Test::More tests => 6; | 12 | use Test::More tests => 8; |
558 | 13 | 13 | ||
559 | 14 | use PerconaTest; | 14 | use PerconaTest; |
560 | 15 | 15 | ||
561 | @@ -58,6 +58,20 @@ | |||
562 | 58 | "Cannot --alter-foreign-keys-method=drop_swap with --no-drop-new-table" | 58 | "Cannot --alter-foreign-keys-method=drop_swap with --no-drop-new-table" |
563 | 59 | ); | 59 | ); |
564 | 60 | 60 | ||
565 | 61 | $output = `$cmd h=127.1,P=12345,u=msandbox,p=msandbox,D=mysql,t=user --max-load 100 --alter "ENGINE=MyISAM" --dry-run`; | ||
566 | 62 | like( | ||
567 | 63 | $output, | ||
568 | 64 | qr/Invalid --max-load/, | ||
569 | 65 | "Validates --max-load" | ||
570 | 66 | ); | ||
571 | 67 | |||
572 | 68 | $output = `$cmd h=127.1,P=12345,u=msandbox,p=msandbox,D=mysql,t=user --critical-load 100 --alter "ENGINE=MyISAM" --dry-run`; | ||
573 | 69 | like( | ||
574 | 70 | $output, | ||
575 | 71 | qr/Invalid --critical-load/, | ||
576 | 72 | "Validates --critical-load" | ||
577 | 73 | ); | ||
578 | 74 | |||
579 | 61 | # ############################################################################# | 75 | # ############################################################################# |
580 | 62 | # Done. | 76 | # Done. |
581 | 63 | # ############################################################################# | 77 | # ############################################################################# |
582 | 64 | 78 | ||
583 | === modified file 't/pt-table-checksum/option_sanity.t' | |||
584 | --- t/pt-table-checksum/option_sanity.t 2011-12-27 17:24:35 +0000 | |||
585 | +++ t/pt-table-checksum/option_sanity.t 2012-05-25 21:39:18 +0000 | |||
586 | @@ -9,7 +9,7 @@ | |||
587 | 9 | use strict; | 9 | use strict; |
588 | 10 | use warnings FATAL => 'all'; | 10 | use warnings FATAL => 'all'; |
589 | 11 | use English qw(-no_match_vars); | 11 | use English qw(-no_match_vars); |
591 | 12 | use Test::More tests => 18; | 12 | use Test::More tests => 19; |
592 | 13 | 13 | ||
593 | 14 | use PerconaTest; | 14 | use PerconaTest; |
594 | 15 | shift @INC; # our unshift (above) | 15 | shift @INC; # our unshift (above) |
595 | @@ -157,6 +157,17 @@ | |||
596 | 157 | ); | 157 | ); |
597 | 158 | 158 | ||
598 | 159 | # ############################################################################# | 159 | # ############################################################################# |
599 | 160 | # --max-load | ||
600 | 161 | # ############################################################################# | ||
601 | 162 | |||
602 | 163 | $output = `$trunk/bin/pt-table-checksum h=127.1,P=12345 --max-load 100`; | ||
603 | 164 | like( | ||
604 | 165 | $output, | ||
605 | 166 | qr/Invalid --max-load/, | ||
606 | 167 | "Validates --max-load" | ||
607 | 168 | ); | ||
608 | 169 | |||
609 | 170 | # ############################################################################# | ||
610 | 160 | # Done. | 171 | # Done. |
611 | 161 | # ############################################################################# | 172 | # ############################################################################# |
612 | 162 | exit; | 173 | exit; |