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
=== modified file 'bin/pt-online-schema-change'
--- bin/pt-online-schema-change 2015-01-23 10:19:56 +0000
+++ bin/pt-online-schema-change 2015-03-18 17:54:46 +0000
@@ -7970,6 +7970,7 @@
79707970
7971my $exit_status = 0;7971my $exit_status = 0;
7972my $oktorun = 1;7972my $oktorun = 1;
7973my $dont_interrupt_now = 0;
7973my @drop_trigger_sqls;7974my @drop_trigger_sqls;
7974my @triggers_not_dropped;7975my @triggers_not_dropped;
79757976
@@ -7983,6 +7984,7 @@
7983 $oktorun = 1;7984 $oktorun = 1;
7984 @drop_trigger_sqls = ();7985 @drop_trigger_sqls = ();
7985 @triggers_not_dropped = ();7986 @triggers_not_dropped = ();
7987 $dont_interrupt_now = 0;
79867988
7987 my %stats = (7989 my %stats = (
7988 INSERT => 0,7990 INSERT => 0,
@@ -10251,6 +10253,11 @@
10251 "DROP TABLE IF EXISTS $orig_tbl->{name}",10253 "DROP TABLE IF EXISTS $orig_tbl->{name}",
10252 "RENAME TABLE $new_tbl->{name} TO $orig_tbl->{name}",10254 "RENAME TABLE $new_tbl->{name} TO $orig_tbl->{name}",
10253 );10255 );
10256
10257 # we don't want to be interrupted during the swap!
10258 # since it might leave original table dropped
10259 # https://bugs.launchpad.net/percona-toolkit/+bug/1368244
10260 $dont_interrupt_now = 1;
1025410261
10255 foreach my $sql ( @sqls ) {10262 foreach my $sql ( @sqls ) {
10256 PTDEBUG && _d($sql);10263 PTDEBUG && _d($sql);
@@ -10269,6 +10276,8 @@
10269 }10276 }
10270 }10277 }
1027110278
10279 $dont_interrupt_now = 0;
10280
10272 if ( $o->get('execute') ) {10281 if ( $o->get('execute') ) {
10273 print ts("Dropped and swapped tables OK.\n");10282 print ts("Dropped and swapped tables OK.\n");
10274 }10283 }
@@ -10667,6 +10676,11 @@
10667# Catches signals so we can exit gracefully.10676# Catches signals so we can exit gracefully.
10668sub sig_int {10677sub sig_int {
10669 my ( $signal ) = @_;10678 my ( $signal ) = @_;
10679 if ( $dont_interrupt_now ) {
10680 # we're in the middle of something that shouldn't be interrupted
10681 PTDEBUG && _d("Received Signal: \"$signal\" in middle of critical operation. Continuing anyway.");
10682 return;
10683 }
10670 $oktorun = 0; # flag for cleanup tasks10684 $oktorun = 0; # flag for cleanup tasks
10671 print STDERR "# Exiting on SIG$signal.\n";10685 print STDERR "# Exiting on SIG$signal.\n";
10672 # restore terminal to normal state in case CTL+C issued while 10686 # restore terminal to normal state in case CTL+C issued while

Subscribers

People subscribed via source and target branches

to all changes: