Merge lp:~percona-toolkit-dev/percona-toolkit/pt-osc-alter-foreign-keys-method-drop-swap-is-vulnerable-to-interruption-1368244 into lp:~percona-toolkit-dev/percona-toolkit/release-2.2.14

Proposed by Frank Cizmich
Status: Merged
Approved by: Daniel Nichter
Approved revision: 614
Merged at revision: 619
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/pt-osc-alter-foreign-keys-method-drop-swap-is-vulnerable-to-interruption-1368244
Merge into: lp:~percona-toolkit-dev/percona-toolkit/release-2.2.14
Diff against target: 52 lines (+14/-0)
1 file modified
bin/pt-online-schema-change (+14/-0)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/pt-osc-alter-foreign-keys-method-drop-swap-is-vulnerable-to-interruption-1368244
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+253412@code.launchpad.net

Description of the change

Problem:
when pt-osc --alter-foreign-keys-method is drop_swap, a "normal-signal" (HUP, INT, PIPE, TERM) issued during the drop_swap phase interrupts the procedure, dropping the original table without renaming the new one.

Solution:
have the handler ignore those signals during the drop_swap function, reinstating them afterwards.

Note:
Tested manually adding pauses in between different stages of drop_swap and sending different signals with kill command.

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 2015-01-23 10:19:56 +0000
3+++ bin/pt-online-schema-change 2015-03-18 17:54:46 +0000
4@@ -7970,6 +7970,7 @@
5
6 my $exit_status = 0;
7 my $oktorun = 1;
8+my $dont_interrupt_now = 0;
9 my @drop_trigger_sqls;
10 my @triggers_not_dropped;
11
12@@ -7983,6 +7984,7 @@
13 $oktorun = 1;
14 @drop_trigger_sqls = ();
15 @triggers_not_dropped = ();
16+ $dont_interrupt_now = 0;
17
18 my %stats = (
19 INSERT => 0,
20@@ -10251,6 +10253,11 @@
21 "DROP TABLE IF EXISTS $orig_tbl->{name}",
22 "RENAME TABLE $new_tbl->{name} TO $orig_tbl->{name}",
23 );
24+
25+ # we don't want to be interrupted during the swap!
26+ # since it might leave original table dropped
27+ # https://bugs.launchpad.net/percona-toolkit/+bug/1368244
28+ $dont_interrupt_now = 1;
29
30 foreach my $sql ( @sqls ) {
31 PTDEBUG && _d($sql);
32@@ -10269,6 +10276,8 @@
33 }
34 }
35
36+ $dont_interrupt_now = 0;
37+
38 if ( $o->get('execute') ) {
39 print ts("Dropped and swapped tables OK.\n");
40 }
41@@ -10667,6 +10676,11 @@
42 # Catches signals so we can exit gracefully.
43 sub sig_int {
44 my ( $signal ) = @_;
45+ if ( $dont_interrupt_now ) {
46+ # we're in the middle of something that shouldn't be interrupted
47+ PTDEBUG && _d("Received Signal: \"$signal\" in middle of critical operation. Continuing anyway.");
48+ return;
49+ }
50 $oktorun = 0; # flag for cleanup tasks
51 print STDERR "# Exiting on SIG$signal.\n";
52 # restore terminal to normal state in case CTL+C issued while

Subscribers

People subscribed via source and target branches

to all changes: