merged pt-osc-alter-foreign-keys-method-drop-swap-is-vulnerable-to-interruption-1368244

This commit is contained in:
Frank Cizmich
2015-04-09 11:57:11 -03:00

View File

@@ -7970,6 +7970,7 @@ use sigtrap 'handler', \&sig_int, 'normal-signals';
my $exit_status = 0; my $exit_status = 0;
my $oktorun = 1; my $oktorun = 1;
my $dont_interrupt_now = 0;
my @drop_trigger_sqls; my @drop_trigger_sqls;
my @triggers_not_dropped; my @triggers_not_dropped;
@@ -7983,6 +7984,7 @@ sub main {
$oktorun = 1; $oktorun = 1;
@drop_trigger_sqls = (); @drop_trigger_sqls = ();
@triggers_not_dropped = (); @triggers_not_dropped = ();
$dont_interrupt_now = 0;
my %stats = ( my %stats = (
INSERT => 0, INSERT => 0,
@@ -10252,6 +10254,11 @@ sub drop_swap {
"RENAME TABLE $new_tbl->{name} TO $orig_tbl->{name}", "RENAME TABLE $new_tbl->{name} TO $orig_tbl->{name}",
); );
# we don't want to be interrupted during the swap!
# since it might leave original table dropped
# https://bugs.launchpad.net/percona-toolkit/+bug/1368244
$dont_interrupt_now = 1;
foreach my $sql ( @sqls ) { foreach my $sql ( @sqls ) {
PTDEBUG && _d($sql); PTDEBUG && _d($sql);
print $sql, "\n" if $o->get('print'); print $sql, "\n" if $o->get('print');
@@ -10269,6 +10276,8 @@ sub drop_swap {
} }
} }
$dont_interrupt_now = 0;
if ( $o->get('execute') ) { if ( $o->get('execute') ) {
print ts("Dropped and swapped tables OK.\n"); print ts("Dropped and swapped tables OK.\n");
} }
@@ -10667,6 +10676,11 @@ sub ts {
# Catches signals so we can exit gracefully. # Catches signals so we can exit gracefully.
sub sig_int { sub sig_int {
my ( $signal ) = @_; my ( $signal ) = @_;
if ( $dont_interrupt_now ) {
# we're in the middle of something that shouldn't be interrupted
PTDEBUG && _d("Received Signal: \"$signal\" in middle of critical operation. Continuing anyway.");
return;
}
$oktorun = 0; # flag for cleanup tasks $oktorun = 0; # flag for cleanup tasks
print STDERR "# Exiting on SIG$signal.\n"; print STDERR "# Exiting on SIG$signal.\n";
# restore terminal to normal state in case CTL+C issued while # restore terminal to normal state in case CTL+C issued while