Merge lp:~percona-toolkit-dev/percona-toolkit/pt-osc-retry-timeouts into lp:percona-toolkit/2.2
- pt-osc-retry-timeouts
- Merge into 2.2
Proposed by
Daniel Nichter
Status: | Merged |
---|---|
Merged at revision: | 547 |
Proposed branch: | lp:~percona-toolkit-dev/percona-toolkit/pt-osc-retry-timeouts |
Merge into: | lp:percona-toolkit/2.2 |
Diff against target: |
560 lines (+190/-80) 6 files modified
bin/pt-online-schema-change (+166/-78) lib/Retry.pm (+2/-0) t/pt-online-schema-change/metadata_locks.t (+4/-2) t/pt-online-schema-change/samples/stats-dry-run.txt (+6/-0) t/pt-online-schema-change/samples/stats-execute-5.5.txt (+6/-0) t/pt-online-schema-change/samples/stats-execute.txt (+6/-0) |
To merge this branch: | bzr merge lp:~percona-toolkit-dev/percona-toolkit/pt-osc-retry-timeouts |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Daniel Nichter | Approve | ||
Review via email: mp+151854@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
- 550. By Daniel Nichter
-
Update sample file with --tries output.
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 2013-03-04 18:08:22 +0000 | |||
3 | +++ bin/pt-online-schema-change 2013-03-05 23:44:21 +0000 | |||
4 | @@ -3578,6 +3578,8 @@ | |||
5 | 3578 | use English qw(-no_match_vars); | 3578 | use English qw(-no_match_vars); |
6 | 3579 | use constant PTDEBUG => $ENV{PTDEBUG} || 0; | 3579 | use constant PTDEBUG => $ENV{PTDEBUG} || 0; |
7 | 3580 | 3580 | ||
8 | 3581 | use Time::HiRes qw(sleep); | ||
9 | 3582 | |||
10 | 3581 | sub new { | 3583 | sub new { |
11 | 3582 | my ( $class, %args ) = @_; | 3584 | my ( $class, %args ) = @_; |
12 | 3583 | my $self = { | 3585 | my $self = { |
13 | @@ -7617,6 +7619,13 @@ | |||
14 | 7617 | . $n_chunk_index_cols); | 7619 | . $n_chunk_index_cols); |
15 | 7618 | } | 7620 | } |
16 | 7619 | 7621 | ||
17 | 7622 | my $tries = eval { | ||
18 | 7623 | validate_tries($o); | ||
19 | 7624 | }; | ||
20 | 7625 | if ( $EVAL_ERROR ) { | ||
21 | 7626 | $o->save_error($EVAL_ERROR); | ||
22 | 7627 | } | ||
23 | 7628 | |||
24 | 7620 | if ( !$o->get('help') ) { | 7629 | if ( !$o->get('help') ) { |
25 | 7621 | if ( @ARGV ) { | 7630 | if ( @ARGV ) { |
26 | 7622 | $o->save_error('Specify only one DSN on the command line'); | 7631 | $o->save_error('Specify only one DSN on the command line'); |
27 | @@ -7974,6 +7983,17 @@ | |||
28 | 7974 | ); | 7983 | ); |
29 | 7975 | 7984 | ||
30 | 7976 | # ######################################################################## | 7985 | # ######################################################################## |
31 | 7986 | # Print --tries. | ||
32 | 7987 | # ######################################################################## | ||
33 | 7988 | print "Operation, tries, wait:\n"; | ||
34 | 7989 | { | ||
35 | 7990 | my $fmt = " %s, %s, %s\n"; | ||
36 | 7991 | foreach my $op ( sort keys %$tries ) { | ||
37 | 7992 | printf $fmt, $op, $tries->{$op}->{tries}, $tries->{$op}->{wait}; | ||
38 | 7993 | } | ||
39 | 7994 | } | ||
40 | 7995 | |||
41 | 7996 | # ######################################################################## | ||
42 | 7977 | # Get child tables of the original table, if necessary. | 7997 | # Get child tables of the original table, if necessary. |
43 | 7978 | # ######################################################################## | 7998 | # ######################################################################## |
44 | 7979 | my $child_tables; | 7999 | my $child_tables; |
45 | @@ -8427,7 +8447,7 @@ | |||
46 | 8427 | Quoter => $q, | 8447 | Quoter => $q, |
47 | 8428 | OptionParser => $o, | 8448 | OptionParser => $o, |
48 | 8429 | Retry => $retry, | 8449 | Retry => $retry, |
50 | 8430 | retries => $o->get('retries'), | 8450 | tries => $tries, |
51 | 8431 | stats => \%stats, | 8451 | stats => \%stats, |
52 | 8432 | ); | 8452 | ); |
53 | 8433 | } | 8453 | } |
54 | @@ -8453,7 +8473,7 @@ | |||
55 | 8453 | Quoter => $q, | 8473 | Quoter => $q, |
56 | 8454 | OptionParser => $o, | 8474 | OptionParser => $o, |
57 | 8455 | Retry => $retry, | 8475 | Retry => $retry, |
59 | 8456 | retries => $o->get('retries'), | 8476 | tries => $tries, |
60 | 8457 | stats => \%stats, | 8477 | stats => \%stats, |
61 | 8458 | ); | 8478 | ); |
62 | 8459 | }; | 8479 | }; |
63 | @@ -8642,7 +8662,7 @@ | |||
64 | 8642 | # Exec and time the chunk checksum query. | 8662 | # Exec and time the chunk checksum query. |
65 | 8643 | $tbl->{nibble_time} = exec_nibble( | 8663 | $tbl->{nibble_time} = exec_nibble( |
66 | 8644 | %args, | 8664 | %args, |
68 | 8645 | retries => $o->get('retries'), | 8665 | tries => $tries, |
69 | 8646 | Retry => $retry, | 8666 | Retry => $retry, |
70 | 8647 | Quoter => $q, | 8667 | Quoter => $q, |
71 | 8648 | stats => \%stats, | 8668 | stats => \%stats, |
72 | @@ -8852,7 +8872,7 @@ | |||
73 | 8852 | Quoter => $q, | 8872 | Quoter => $q, |
74 | 8853 | OptionParser => $o, | 8873 | OptionParser => $o, |
75 | 8854 | Retry => $retry, | 8874 | Retry => $retry, |
77 | 8855 | retries => $o->get('retries'), | 8875 | tries => $tries, |
78 | 8856 | stats => \%stats, | 8876 | stats => \%stats, |
79 | 8857 | ); | 8877 | ); |
80 | 8858 | }; | 8878 | }; |
81 | @@ -8900,7 +8920,7 @@ | |||
82 | 8900 | TableParser => $tp, | 8920 | TableParser => $tp, |
83 | 8901 | stats => \%stats, | 8921 | stats => \%stats, |
84 | 8902 | Retry => $retry, | 8922 | Retry => $retry, |
86 | 8903 | retries => $o->get('retries'), | 8923 | tries => $tries, |
87 | 8904 | ); | 8924 | ); |
88 | 8905 | } | 8925 | } |
89 | 8906 | elsif ( $alter_fk_method eq 'drop_swap' ) { | 8926 | elsif ( $alter_fk_method eq 'drop_swap' ) { |
90 | @@ -8911,7 +8931,7 @@ | |||
91 | 8911 | OptionParser => $o, | 8931 | OptionParser => $o, |
92 | 8912 | stats => \%stats, | 8932 | stats => \%stats, |
93 | 8913 | Retry => $retry, | 8933 | Retry => $retry, |
95 | 8914 | retries => $o->get('retries'), | 8934 | tries => $tries, |
96 | 8915 | ); | 8935 | ); |
97 | 8916 | } | 8936 | } |
98 | 8917 | elsif ( !$alter_fk_method | 8937 | elsif ( !$alter_fk_method |
99 | @@ -9003,6 +9023,56 @@ | |||
100 | 9003 | # Subroutines. | 9023 | # Subroutines. |
101 | 9004 | # ############################################################################ | 9024 | # ############################################################################ |
102 | 9005 | 9025 | ||
103 | 9026 | sub validate_tries { | ||
104 | 9027 | my ($o) = @_; | ||
105 | 9028 | my @ops = qw( | ||
106 | 9029 | create_triggers | ||
107 | 9030 | drop_triggers | ||
108 | 9031 | copy_rows | ||
109 | 9032 | swap_tables | ||
110 | 9033 | update_foreign_keys | ||
111 | 9034 | ); | ||
112 | 9035 | my %user_tries; | ||
113 | 9036 | my $user_tries = $o->get('tries'); | ||
114 | 9037 | if ( $user_tries ) { | ||
115 | 9038 | foreach my $var_val ( @$user_tries ) { | ||
116 | 9039 | my ($op, $tries, $wait) = split(':', $var_val); | ||
117 | 9040 | die "Invalid --tries value: $var_val\n" unless $op && $tries && $wait; | ||
118 | 9041 | die "Invalid --tries operation: $op\n" unless grep { $op eq $_ } @ops; | ||
119 | 9042 | die "Invalid --tries tries: $tries\n" unless $tries > 0; | ||
120 | 9043 | die "Invalid --tries wait: $wait\n" unless $wait > 0; | ||
121 | 9044 | $user_tries{$op} = { | ||
122 | 9045 | tries => $tries, | ||
123 | 9046 | wait => $wait, | ||
124 | 9047 | }; | ||
125 | 9048 | } | ||
126 | 9049 | } | ||
127 | 9050 | |||
128 | 9051 | my %default_tries; | ||
129 | 9052 | my $default_tries = $o->read_para_after(__FILE__, qr/MAGIC_tries/); | ||
130 | 9053 | if ( $default_tries ) { | ||
131 | 9054 | %default_tries = map { | ||
132 | 9055 | my $var_val = $_; | ||
133 | 9056 | my ($op, $tries, $wait) = $var_val =~ m/(\S+)/g; | ||
134 | 9057 | die "Invalid --tries value: $var_val\n" unless $op && $tries && $wait; | ||
135 | 9058 | die "Invalid --tries operation: $op\n" unless grep { $op eq $_ } @ops; | ||
136 | 9059 | die "Invalid --tries tries: $tries\n" unless $tries > 0; | ||
137 | 9060 | die "Invalid --tries wait: $wait\n" unless $wait > 0; | ||
138 | 9061 | $op => { | ||
139 | 9062 | tries => $tries, | ||
140 | 9063 | wait => $wait, | ||
141 | 9064 | }; | ||
142 | 9065 | } grep { m/^\s+\w+\s+\d+\s+[\d\.]+/ } split("\n", $default_tries); | ||
143 | 9066 | } | ||
144 | 9067 | |||
145 | 9068 | my %tries = ( | ||
146 | 9069 | %default_tries, # first the tool's defaults | ||
147 | 9070 | %user_tries, # then the user's which overwrite the defaults | ||
148 | 9071 | ); | ||
149 | 9072 | PTDEBUG && _d('--tries:', Dumper(\%tries)); | ||
150 | 9073 | return \%tries; | ||
151 | 9074 | } | ||
152 | 9075 | |||
153 | 9006 | sub check_alter { | 9076 | sub check_alter { |
154 | 9007 | my (%args) = @_; | 9077 | my (%args) = @_; |
155 | 9008 | my @required_args = qw(alter tbl dry_run Cxn TableParser); | 9078 | my @required_args = qw(alter tbl dry_run Cxn TableParser); |
156 | @@ -9300,15 +9370,15 @@ | |||
157 | 9300 | 9370 | ||
158 | 9301 | sub swap_tables { | 9371 | sub swap_tables { |
159 | 9302 | my (%args) = @_; | 9372 | my (%args) = @_; |
161 | 9303 | my @required_args = qw(orig_tbl new_tbl Cxn Quoter OptionParser Retry retries stats); | 9373 | my @required_args = qw(orig_tbl new_tbl Cxn Quoter OptionParser Retry tries stats); |
162 | 9304 | foreach my $arg ( @required_args ) { | 9374 | foreach my $arg ( @required_args ) { |
163 | 9305 | die "I need a $arg argument" unless $args{$arg}; | 9375 | die "I need a $arg argument" unless $args{$arg}; |
164 | 9306 | } | 9376 | } |
166 | 9307 | my ($orig_tbl, $new_tbl, $cxn, $q, $o, $retry, $retries, $stats) = @args{@required_args}; | 9377 | my ($orig_tbl, $new_tbl, $cxn, $q, $o, $retry, $tries, $stats) = @args{@required_args}; |
167 | 9308 | 9378 | ||
168 | 9309 | my $prefix = '_'; | 9379 | my $prefix = '_'; |
169 | 9310 | my $table_name = $orig_tbl->{tbl} . ($args{suffix} || ''); | 9380 | my $table_name = $orig_tbl->{tbl} . ($args{suffix} || ''); |
171 | 9311 | my $tries = 10; # don't try forever | 9381 | my $name_tries = 10; # don't try forever |
172 | 9312 | my $table_exists = qr/table.+?already exists/i; | 9382 | my $table_exists = qr/table.+?already exists/i; |
173 | 9313 | 9383 | ||
174 | 9314 | # This sub only works for --execute. Since the options are | 9384 | # This sub only works for --execute. Since the options are |
175 | @@ -9326,7 +9396,7 @@ | |||
176 | 9326 | elsif ( $o->get('execute') ) { | 9396 | elsif ( $o->get('execute') ) { |
177 | 9327 | print "Swapping tables...\n"; | 9397 | print "Swapping tables...\n"; |
178 | 9328 | 9398 | ||
180 | 9329 | while ( $tries-- ) { | 9399 | while ( $name_tries-- ) { |
181 | 9330 | $table_name = $prefix . $table_name; | 9400 | $table_name = $prefix . $table_name; |
182 | 9331 | 9401 | ||
183 | 9332 | if ( length($table_name) > 64 ) { | 9402 | if ( length($table_name) > 64 ) { |
184 | @@ -9344,7 +9414,7 @@ | |||
185 | 9344 | osc_retry( | 9414 | osc_retry( |
186 | 9345 | Cxn => $cxn, | 9415 | Cxn => $cxn, |
187 | 9346 | Retry => $retry, | 9416 | Retry => $retry, |
189 | 9347 | retries => $retries, | 9417 | tries => $tries->{swap_tables}, |
190 | 9348 | stats => $stats, | 9418 | stats => $stats, |
191 | 9349 | code => sub { | 9419 | code => sub { |
192 | 9350 | PTDEBUG && _d($sql); | 9420 | PTDEBUG && _d($sql); |
193 | @@ -9380,7 +9450,7 @@ | |||
194 | 9380 | 9450 | ||
195 | 9381 | # This shouldn't happen. | 9451 | # This shouldn't happen. |
196 | 9382 | # Here and in the attempt to find a new table name we probably ought to | 9452 | # Here and in the attempt to find a new table name we probably ought to |
198 | 9383 | # use --retries (and maybe a Retry object?) | 9453 | # use --tries (and maybe a Retry object?) |
199 | 9384 | die "Failed to find a unique old table name after serveral attempts.\n"; | 9454 | die "Failed to find a unique old table name after serveral attempts.\n"; |
200 | 9385 | } | 9455 | } |
201 | 9386 | } | 9456 | } |
202 | @@ -9530,11 +9600,11 @@ | |||
203 | 9530 | my ( %args ) = @_; | 9600 | my ( %args ) = @_; |
204 | 9531 | my @required_args = qw(orig_tbl old_tbl child_tables stats | 9601 | my @required_args = qw(orig_tbl old_tbl child_tables stats |
205 | 9532 | Cxn Quoter OptionParser TableParser | 9602 | Cxn Quoter OptionParser TableParser |
207 | 9533 | Retry retries); | 9603 | Retry tries); |
208 | 9534 | foreach my $arg ( @required_args ) { | 9604 | foreach my $arg ( @required_args ) { |
209 | 9535 | die "I need a $arg argument" unless $args{$arg}; | 9605 | die "I need a $arg argument" unless $args{$arg}; |
210 | 9536 | } | 9606 | } |
212 | 9537 | my ($orig_tbl, $old_tbl, $child_tables, $stats, $cxn, $q, $o, $tp, $retry, $retries) | 9607 | my ($orig_tbl, $old_tbl, $child_tables, $stats, $cxn, $q, $o, $tp, $retry, $tries) |
213 | 9538 | = @args{@required_args}; | 9608 | = @args{@required_args}; |
214 | 9539 | 9609 | ||
215 | 9540 | # MySQL has a "feature" where if the parent tbl is in the same db, | 9610 | # MySQL has a "feature" where if the parent tbl is in the same db, |
216 | @@ -9612,7 +9682,7 @@ | |||
217 | 9612 | osc_retry( | 9682 | osc_retry( |
218 | 9613 | Cxn => $cxn, | 9683 | Cxn => $cxn, |
219 | 9614 | Retry => $retry, | 9684 | Retry => $retry, |
221 | 9615 | retries => $retries, | 9685 | tries => $tries->{update_foreign_keys}, |
222 | 9616 | stats => $stats, | 9686 | stats => $stats, |
223 | 9617 | code => sub { | 9687 | code => sub { |
224 | 9618 | PTDEBUG && _d($sql); | 9688 | PTDEBUG && _d($sql); |
225 | @@ -9632,11 +9702,11 @@ | |||
226 | 9632 | 9702 | ||
227 | 9633 | sub drop_swap { | 9703 | sub drop_swap { |
228 | 9634 | my ( %args ) = @_; | 9704 | my ( %args ) = @_; |
230 | 9635 | my @required_args = qw(orig_tbl new_tbl Cxn OptionParser stats Retry retries); | 9705 | my @required_args = qw(orig_tbl new_tbl Cxn OptionParser stats Retry tries); |
231 | 9636 | foreach my $arg ( @required_args ) { | 9706 | foreach my $arg ( @required_args ) { |
232 | 9637 | die "I need a $arg argument" unless $args{$arg}; | 9707 | die "I need a $arg argument" unless $args{$arg}; |
233 | 9638 | } | 9708 | } |
235 | 9639 | my ($orig_tbl, $new_tbl, $cxn, $o, $stats, $retry, $retries) = @args{@required_args}; | 9709 | my ($orig_tbl, $new_tbl, $cxn, $o, $stats, $retry, $tries) = @args{@required_args}; |
236 | 9640 | 9710 | ||
237 | 9641 | if ( $o->get('dry-run') ) { | 9711 | if ( $o->get('dry-run') ) { |
238 | 9642 | print "Not drop-swapping tables because this is a dry run.\n"; | 9712 | print "Not drop-swapping tables because this is a dry run.\n"; |
239 | @@ -9658,7 +9728,7 @@ | |||
240 | 9658 | osc_retry( | 9728 | osc_retry( |
241 | 9659 | Cxn => $cxn, | 9729 | Cxn => $cxn, |
242 | 9660 | Retry => $retry, | 9730 | Retry => $retry, |
244 | 9661 | retries => $retries, | 9731 | tries => $tries->{update_foreign_keys}, |
245 | 9662 | stats => $stats, | 9732 | stats => $stats, |
246 | 9663 | code => sub { | 9733 | code => sub { |
247 | 9664 | PTDEBUG && _d($sql); | 9734 | PTDEBUG && _d($sql); |
248 | @@ -9677,11 +9747,11 @@ | |||
249 | 9677 | 9747 | ||
250 | 9678 | sub create_triggers { | 9748 | sub create_triggers { |
251 | 9679 | my ( %args ) = @_; | 9749 | my ( %args ) = @_; |
253 | 9680 | my @required_args = qw(orig_tbl new_tbl del_tbl columns Cxn Quoter OptionParser Retry retries stats); | 9750 | my @required_args = qw(orig_tbl new_tbl del_tbl columns Cxn Quoter OptionParser Retry tries stats); |
254 | 9681 | foreach my $arg ( @required_args ) { | 9751 | foreach my $arg ( @required_args ) { |
255 | 9682 | die "I need a $arg argument" unless $args{$arg}; | 9752 | die "I need a $arg argument" unless $args{$arg}; |
256 | 9683 | } | 9753 | } |
258 | 9684 | my ($orig_tbl, $new_tbl, $del_tbl, $cols, $cxn, $q, $o, $retry, $retries, $stats) = @args{@required_args}; | 9754 | my ($orig_tbl, $new_tbl, $del_tbl, $cols, $cxn, $q, $o, $retry, $tries, $stats) = @args{@required_args}; |
259 | 9685 | 9755 | ||
260 | 9686 | # This sub works for --dry-run and --execute. With --dry-run it's | 9756 | # This sub works for --dry-run and --execute. With --dry-run it's |
261 | 9687 | # only interesting if --print is specified, too; then the user can | 9757 | # only interesting if --print is specified, too; then the user can |
262 | @@ -9752,7 +9822,7 @@ | |||
263 | 9752 | osc_retry( | 9822 | osc_retry( |
264 | 9753 | Cxn => $cxn, | 9823 | Cxn => $cxn, |
265 | 9754 | Retry => $retry, | 9824 | Retry => $retry, |
267 | 9755 | retries => $retries, | 9825 | tries => $tries->{create_triggers}, |
268 | 9756 | stats => $stats, | 9826 | stats => $stats, |
269 | 9757 | code => sub { | 9827 | code => sub { |
270 | 9758 | PTDEBUG && _d($sql); | 9828 | PTDEBUG && _d($sql); |
271 | @@ -9778,11 +9848,11 @@ | |||
272 | 9778 | 9848 | ||
273 | 9779 | sub drop_triggers { | 9849 | sub drop_triggers { |
274 | 9780 | my ( %args ) = @_; | 9850 | my ( %args ) = @_; |
276 | 9781 | my @required_args = qw(tbl Cxn Quoter OptionParser Retry retries stats); | 9851 | my @required_args = qw(tbl Cxn Quoter OptionParser Retry tries stats); |
277 | 9782 | foreach my $arg ( @required_args ) { | 9852 | foreach my $arg ( @required_args ) { |
278 | 9783 | die "I need a $arg argument" unless $args{$arg}; | 9853 | die "I need a $arg argument" unless $args{$arg}; |
279 | 9784 | } | 9854 | } |
281 | 9785 | my ($tbl, $cxn, $q, $o, $retry, $retries, $stats) = @args{@required_args}; | 9855 | my ($tbl, $cxn, $q, $o, $retry, $tries, $stats) = @args{@required_args}; |
282 | 9786 | 9856 | ||
283 | 9787 | # This sub works for --dry-run and --execute, although --dry-run is | 9857 | # This sub works for --dry-run and --execute, although --dry-run is |
284 | 9788 | # only interesting with --print so the user can see the drop trigger | 9858 | # only interesting with --print so the user can see the drop trigger |
285 | @@ -9802,7 +9872,7 @@ | |||
286 | 9802 | osc_retry( | 9872 | osc_retry( |
287 | 9803 | Cxn => $cxn, | 9873 | Cxn => $cxn, |
288 | 9804 | Retry => $retry, | 9874 | Retry => $retry, |
290 | 9805 | retries => $retries, | 9875 | tries => $tries->{drop_triggers}, |
291 | 9806 | stats => $stats, | 9876 | stats => $stats, |
292 | 9807 | code => sub { | 9877 | code => sub { |
293 | 9808 | PTDEBUG && _d($sql); | 9878 | PTDEBUG && _d($sql); |
294 | @@ -9846,20 +9916,20 @@ | |||
295 | 9846 | 9916 | ||
296 | 9847 | sub osc_retry { | 9917 | sub osc_retry { |
297 | 9848 | my (%args) = @_; | 9918 | my (%args) = @_; |
299 | 9849 | my @required_args = qw(Cxn Retry retries code stats); | 9919 | my @required_args = qw(Cxn Retry tries code stats); |
300 | 9850 | foreach my $arg ( @required_args ) { | 9920 | foreach my $arg ( @required_args ) { |
301 | 9851 | die "I need a $arg argument" unless $args{$arg}; | 9921 | die "I need a $arg argument" unless $args{$arg}; |
302 | 9852 | } | 9922 | } |
303 | 9853 | my $cxn = $args{Cxn}; | 9923 | my $cxn = $args{Cxn}; |
304 | 9854 | my $retry = $args{Retry}; | 9924 | my $retry = $args{Retry}; |
306 | 9855 | my $retries = $args{retries}; | 9925 | my $tries = $args{tries}; |
307 | 9856 | my $code = $args{code}; | 9926 | my $code = $args{code}; |
308 | 9857 | my $stats = $args{stats}; | 9927 | my $stats = $args{stats}; |
309 | 9858 | my $ignore_errors = $args{ignore_errors}; | 9928 | my $ignore_errors = $args{ignore_errors}; |
310 | 9859 | 9929 | ||
311 | 9860 | return $retry->retry( | 9930 | return $retry->retry( |
314 | 9861 | tries => $retries, | 9931 | tries => $tries->{tries}, |
315 | 9862 | wait => sub { sleep 0.25; return; }, | 9932 | wait => sub { sleep ($tries->{wait} || 0.25) }, |
316 | 9863 | try => $code, | 9933 | try => $code, |
317 | 9864 | fail => sub { | 9934 | fail => sub { |
318 | 9865 | my (%args) = @_; | 9935 | my (%args) = @_; |
319 | @@ -9911,11 +9981,11 @@ | |||
320 | 9911 | 9981 | ||
321 | 9912 | sub exec_nibble { | 9982 | sub exec_nibble { |
322 | 9913 | my (%args) = @_; | 9983 | my (%args) = @_; |
324 | 9914 | my @required_args = qw(Cxn tbl stats retries Retry NibbleIterator Quoter); | 9984 | my @required_args = qw(Cxn tbl stats tries Retry NibbleIterator Quoter); |
325 | 9915 | foreach my $arg ( @required_args ) { | 9985 | foreach my $arg ( @required_args ) { |
326 | 9916 | die "I need a $arg argument" unless $args{$arg}; | 9986 | die "I need a $arg argument" unless $args{$arg}; |
327 | 9917 | } | 9987 | } |
329 | 9918 | my ($cxn, $tbl, $stats, $retries, $retry, $nibble_iter, $q) | 9988 | my ($cxn, $tbl, $stats, $tries, $retry, $nibble_iter, $q) |
330 | 9919 | = @args{@required_args}; | 9989 | = @args{@required_args}; |
331 | 9920 | 9990 | ||
332 | 9921 | my $sth = $nibble_iter->statements(); | 9991 | my $sth = $nibble_iter->statements(); |
333 | @@ -9952,7 +10022,7 @@ | |||
334 | 9952 | return osc_retry( | 10022 | return osc_retry( |
335 | 9953 | Cxn => $cxn, | 10023 | Cxn => $cxn, |
336 | 9954 | Retry => $retry, | 10024 | Retry => $retry, |
338 | 9955 | retries => $retries, | 10025 | tries => $tries->{copy_rows}, |
339 | 9956 | stats => $stats, | 10026 | stats => $stats, |
340 | 9957 | code => sub { | 10027 | code => sub { |
341 | 9958 | # ################################################################### | 10028 | # ################################################################### |
342 | @@ -10396,13 +10466,6 @@ | |||
343 | 10396 | NAMES UTF8 after connecting to MySQL. Any other value sets binmode on STDOUT | 10466 | NAMES UTF8 after connecting to MySQL. Any other value sets binmode on STDOUT |
344 | 10397 | without the utf8 layer, and runs SET NAMES after connecting to MySQL. | 10467 | without the utf8 layer, and runs SET NAMES after connecting to MySQL. |
345 | 10398 | 10468 | ||
346 | 10399 | =item --check-interval | ||
347 | 10400 | |||
348 | 10401 | type: time; default: 1 | ||
349 | 10402 | |||
350 | 10403 | Sleep time between checks for L<"--max-lag">. | ||
351 | 10404 | |||
352 | 10405 | |||
353 | 10406 | =item --[no]check-alter | 10469 | =item --[no]check-alter |
354 | 10407 | 10470 | ||
355 | 10408 | default: yes | 10471 | default: yes |
356 | @@ -10434,6 +10497,12 @@ | |||
357 | 10434 | 10497 | ||
358 | 10435 | =back | 10498 | =back |
359 | 10436 | 10499 | ||
360 | 10500 | =item --check-interval | ||
361 | 10501 | |||
362 | 10502 | type: time; default: 1 | ||
363 | 10503 | |||
364 | 10504 | Sleep time between checks for L<"--max-lag">. | ||
365 | 10505 | |||
366 | 10437 | =item --[no]check-plan | 10506 | =item --[no]check-plan |
367 | 10438 | 10507 | ||
368 | 10439 | default: yes | 10508 | default: yes |
369 | @@ -10814,46 +10883,6 @@ | |||
370 | 10814 | table. Currently, the DSNs are ordered by id, but id and parent_id are otherwise | 10883 | table. Currently, the DSNs are ordered by id, but id and parent_id are otherwise |
371 | 10815 | ignored. | 10884 | ignored. |
372 | 10816 | 10885 | ||
373 | 10817 | =item --retries | ||
374 | 10818 | |||
375 | 10819 | type: int; default: 10 | ||
376 | 10820 | |||
377 | 10821 | Retry critical operations and recover from non-fatal errors. The tool | ||
378 | 10822 | retries these operations: | ||
379 | 10823 | |||
380 | 10824 | Creating triggers | ||
381 | 10825 | Dropping triggers | ||
382 | 10826 | Copying chunks | ||
383 | 10827 | Swapping tables | ||
384 | 10828 | Rebuilding foreign key constraints | ||
385 | 10829 | |||
386 | 10830 | For creating and dropping triggers, the number of retries applies to each | ||
387 | 10831 | C<CREATE TRIGGER> and C<DROP TRIGGER> statement for each trigger. | ||
388 | 10832 | For copying chunks, the number of retries applies to each chunk, not the | ||
389 | 10833 | entire table. For swapping tables, the number of retries usually applies | ||
390 | 10834 | once because there is usually only one C<RENAME TABLE> statement. | ||
391 | 10835 | For rebuilding foreign key constraints, the number of retries applies to | ||
392 | 10836 | each statement (C<ALTER> statements for the C<rebuild_constraints> | ||
393 | 10837 | L<"--alter-foreign-keys-method">; other statements for the C<drop_swap> | ||
394 | 10838 | method). | ||
395 | 10839 | |||
396 | 10840 | The tool retries each operation if these errors occur: | ||
397 | 10841 | |||
398 | 10842 | Lock wait timeout (innodb_lock_wait_timeout and lock_wait_timeout) | ||
399 | 10843 | Deadlock found | ||
400 | 10844 | Query is killed (KILL QUERY <thread_id>) | ||
401 | 10845 | Connection is killed (KILL CONNECTION <thread_id>) | ||
402 | 10846 | Lost connection to MySQL | ||
403 | 10847 | |||
404 | 10848 | In the case of lost and killed connections, the tool will automatically | ||
405 | 10849 | reconnect. | ||
406 | 10850 | |||
407 | 10851 | To alter extremely busy tables, it may be necessary to increase L<"--retries">, | ||
408 | 10852 | and also C<innodb_lock_wait_timeout> and (for MySQL 5.5 and newer) | ||
409 | 10853 | C<lock_wait_timeout> by specifying higher values with L<"--set-vars">. | ||
410 | 10854 | |||
411 | 10855 | Failures and retries are recorded in the L<"--statistics">. | ||
412 | 10856 | |||
413 | 10857 | =item --set-vars | 10886 | =item --set-vars |
414 | 10858 | 10887 | ||
415 | 10859 | type: Array | 10888 | type: Array |
416 | @@ -10895,6 +10924,65 @@ | |||
417 | 10895 | place of the original table. The original table becomes the "old table," and | 10924 | place of the original table. The original table becomes the "old table," and |
418 | 10896 | the tool drops it unless you disable L<"--[no]drop-old-table">. | 10925 | the tool drops it unless you disable L<"--[no]drop-old-table">. |
419 | 10897 | 10926 | ||
420 | 10927 | =item --tries | ||
421 | 10928 | |||
422 | 10929 | type: array | ||
423 | 10930 | |||
424 | 10931 | How many times to try critical operations. If certain operations fail due | ||
425 | 10932 | to non-fatal, recoverable errors, the tool waits and tries the operation | ||
426 | 10933 | again. These are the operations that are retried, with their default number | ||
427 | 10934 | of tries and wait time between tries (in seconds): | ||
428 | 10935 | |||
429 | 10936 | =for comment ignore-pt-internal-value | ||
430 | 10937 | MAGIC_tries | ||
431 | 10938 | |||
432 | 10939 | OPERATION TRIES WAIT | ||
433 | 10940 | =================== ===== ==== | ||
434 | 10941 | create_triggers 10 1 | ||
435 | 10942 | drop_triggers 10 1 | ||
436 | 10943 | copy_rows 10 0.25 | ||
437 | 10944 | swap_tables 10 1 | ||
438 | 10945 | update_foreign_keys 10 1 | ||
439 | 10946 | |||
440 | 10947 | To change the defaults, specify the new values like: | ||
441 | 10948 | |||
442 | 10949 | --tries create_triggers:5:0.5,drop_triggers:5:0.5 | ||
443 | 10950 | |||
444 | 10951 | That makes the tool try C<create_triggers> and C<drop_triggers> 2 times | ||
445 | 10952 | with a 0.5 second wait between tries. So the format is: | ||
446 | 10953 | |||
447 | 10954 | operation:tries:wait[,operation:tries:wait] | ||
448 | 10955 | |||
449 | 10956 | All three values must be specified. | ||
450 | 10957 | |||
451 | 10958 | Note that most operations are affected only in MySQL 5.5 and newer by | ||
452 | 10959 | C<lock_wait_timeout> (see L<"--set-vars">) because of metadata locks. | ||
453 | 10960 | The C<copy_rows> operation is affected in any version of MySQL by | ||
454 | 10961 | C<innodb_lock_wait_timeout>. | ||
455 | 10962 | |||
456 | 10963 | For creating and dropping triggers, the number of tries applies to each | ||
457 | 10964 | C<CREATE TRIGGER> and C<DROP TRIGGER> statement for each trigger. | ||
458 | 10965 | For copying rows, the number of tries applies to each chunk, not the | ||
459 | 10966 | entire table. For swapping tables, the number of tries usually applies | ||
460 | 10967 | once because there is usually only one C<RENAME TABLE> statement. | ||
461 | 10968 | For rebuilding foreign key constraints, the number of tries applies to | ||
462 | 10969 | each statement (C<ALTER> statements for the C<rebuild_constraints> | ||
463 | 10970 | L<"--alter-foreign-keys-method">; other statements for the C<drop_swap> | ||
464 | 10971 | method). | ||
465 | 10972 | |||
466 | 10973 | The tool retries each operation if these errors occur: | ||
467 | 10974 | |||
468 | 10975 | Lock wait timeout (innodb_lock_wait_timeout and lock_wait_timeout) | ||
469 | 10976 | Deadlock found | ||
470 | 10977 | Query is killed (KILL QUERY <thread_id>) | ||
471 | 10978 | Connection is killed (KILL CONNECTION <thread_id>) | ||
472 | 10979 | Lost connection to MySQL | ||
473 | 10980 | |||
474 | 10981 | In the case of lost and killed connections, the tool will automatically | ||
475 | 10982 | reconnect. | ||
476 | 10983 | |||
477 | 10984 | Failures and retries are recorded in the L<"--statistics">. | ||
478 | 10985 | |||
479 | 10898 | =item --user | 10986 | =item --user |
480 | 10899 | 10987 | ||
481 | 10900 | short form: -u; type: string | 10988 | short form: -u; type: string |
482 | 10901 | 10989 | ||
483 | === modified file 'lib/Retry.pm' | |||
484 | --- lib/Retry.pm 2013-01-03 00:19:16 +0000 | |||
485 | +++ lib/Retry.pm 2013-03-05 23:44:21 +0000 | |||
486 | @@ -27,6 +27,8 @@ | |||
487 | 27 | use English qw(-no_match_vars); | 27 | use English qw(-no_match_vars); |
488 | 28 | use constant PTDEBUG => $ENV{PTDEBUG} || 0; | 28 | use constant PTDEBUG => $ENV{PTDEBUG} || 0; |
489 | 29 | 29 | ||
490 | 30 | use Time::HiRes qw(sleep); | ||
491 | 31 | |||
492 | 30 | sub new { | 32 | sub new { |
493 | 31 | my ( $class, %args ) = @_; | 33 | my ( $class, %args ) = @_; |
494 | 32 | my $self = { | 34 | my $self = { |
495 | 33 | 35 | ||
496 | === modified file 't/pt-online-schema-change/metadata_locks.t' | |||
497 | --- t/pt-online-schema-change/metadata_locks.t 2013-02-28 19:29:17 +0000 | |||
498 | +++ t/pt-online-schema-change/metadata_locks.t 2013-03-05 23:44:21 +0000 | |||
499 | @@ -51,7 +51,8 @@ | |||
500 | 51 | ($output) = full_output( | 51 | ($output) = full_output( |
501 | 52 | sub { pt_online_schema_change::main( | 52 | sub { pt_online_schema_change::main( |
502 | 53 | "$master_dsn,D=pt_osc,t=t", | 53 | "$master_dsn,D=pt_osc,t=t", |
504 | 54 | qw(--statistics --execute --retries 2 --set-vars lock_wait_timeout=1), | 54 | qw(--statistics --execute --tries create_triggers:2:0.1), |
505 | 55 | qw(--set-vars lock_wait_timeout=1), | ||
506 | 55 | '--plugin', "$plugin/block_create_triggers.pm", | 56 | '--plugin', "$plugin/block_create_triggers.pm", |
507 | 56 | )}, | 57 | )}, |
508 | 57 | stderr => 1, | 58 | stderr => 1, |
509 | @@ -76,7 +77,8 @@ | |||
510 | 76 | ($output) = full_output( | 77 | ($output) = full_output( |
511 | 77 | sub { pt_online_schema_change::main( | 78 | sub { pt_online_schema_change::main( |
512 | 78 | "$master_dsn,D=pt_osc,t=t", | 79 | "$master_dsn,D=pt_osc,t=t", |
514 | 79 | qw(--statistics --execute --retries 2 --set-vars lock_wait_timeout=1), | 80 | qw(--statistics --execute --tries swap_tables:2:0.1), |
515 | 81 | qw(--set-vars lock_wait_timeout=1), | ||
516 | 80 | '--plugin', "$plugin/block_swap_tables.pm", | 82 | '--plugin', "$plugin/block_swap_tables.pm", |
517 | 81 | )}, | 83 | )}, |
518 | 82 | stderr => 1, | 84 | stderr => 1, |
519 | 83 | 85 | ||
520 | === modified file 't/pt-online-schema-change/samples/stats-dry-run.txt' | |||
521 | --- t/pt-online-schema-change/samples/stats-dry-run.txt 2013-02-28 19:29:17 +0000 | |||
522 | +++ t/pt-online-schema-change/samples/stats-dry-run.txt 2013-03-05 23:44:21 +0000 | |||
523 | @@ -1,3 +1,9 @@ | |||
524 | 1 | Operation, tries, wait: | ||
525 | 2 | copy_rows, 10, 0.25 | ||
526 | 3 | create_triggers, 10, 1 | ||
527 | 4 | drop_triggers, 10, 1 | ||
528 | 5 | swap_tables, 10, 1 | ||
529 | 6 | update_foreign_keys, 10, 1 | ||
530 | 1 | Starting a dry run. `bug_1045317`.`bits` will not be altered. Specify --execute instead of --dry-run to alter the table. | 7 | Starting a dry run. `bug_1045317`.`bits` will not be altered. Specify --execute instead of --dry-run to alter the table. |
531 | 2 | Not dropping triggers because this is a dry run. | 8 | Not dropping triggers because this is a dry run. |
532 | 3 | Dropping new table... | 9 | Dropping new table... |
533 | 4 | 10 | ||
534 | === modified file 't/pt-online-schema-change/samples/stats-execute-5.5.txt' | |||
535 | --- t/pt-online-schema-change/samples/stats-execute-5.5.txt 2013-02-28 19:29:17 +0000 | |||
536 | +++ t/pt-online-schema-change/samples/stats-execute-5.5.txt 2013-03-05 23:44:21 +0000 | |||
537 | @@ -1,3 +1,9 @@ | |||
538 | 1 | Operation, tries, wait: | ||
539 | 2 | copy_rows, 10, 0.25 | ||
540 | 3 | create_triggers, 10, 1 | ||
541 | 4 | drop_triggers, 10, 1 | ||
542 | 5 | swap_tables, 10, 1 | ||
543 | 6 | update_foreign_keys, 10, 1 | ||
544 | 1 | Altering `bug_1045317`.`bits`... | 7 | Altering `bug_1045317`.`bits`... |
545 | 2 | Dropping triggers... | 8 | Dropping triggers... |
546 | 3 | Dropped triggers OK. | 9 | Dropped triggers OK. |
547 | 4 | 10 | ||
548 | === modified file 't/pt-online-schema-change/samples/stats-execute.txt' | |||
549 | --- t/pt-online-schema-change/samples/stats-execute.txt 2013-03-01 02:00:07 +0000 | |||
550 | +++ t/pt-online-schema-change/samples/stats-execute.txt 2013-03-05 23:44:21 +0000 | |||
551 | @@ -1,3 +1,9 @@ | |||
552 | 1 | Operation, tries, wait: | ||
553 | 2 | copy_rows, 10, 0.25 | ||
554 | 3 | create_triggers, 10, 1 | ||
555 | 4 | drop_triggers, 10, 1 | ||
556 | 5 | swap_tables, 10, 1 | ||
557 | 6 | update_foreign_keys, 10, 1 | ||
558 | 1 | Altering `bug_1045317`.`bits`... | 7 | Altering `bug_1045317`.`bits`... |
559 | 2 | Dropping triggers... | 8 | Dropping triggers... |
560 | 3 | Dropped triggers OK. | 9 | Dropped triggers OK. |
Tool's tests pass in all envs.