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 $oktorun = 1;
my $dont_interrupt_now = 0;
my @drop_trigger_sqls;
my @triggers_not_dropped;
@@ -7983,6 +7984,7 @@ sub main {
$oktorun = 1;
@drop_trigger_sqls = ();
@triggers_not_dropped = ();
$dont_interrupt_now = 0;
my %stats = (
INSERT => 0,
@@ -10251,6 +10253,11 @@ sub drop_swap {
"DROP TABLE IF EXISTS $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 ) {
PTDEBUG && _d($sql);
@@ -10269,6 +10276,8 @@ sub drop_swap {
}
}
$dont_interrupt_now = 0;
if ( $o->get('execute') ) {
print ts("Dropped and swapped tables OK.\n");
}
@@ -10667,6 +10676,11 @@ sub ts {
# Catches signals so we can exit gracefully.
sub sig_int {
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
print STDERR "# Exiting on SIG$signal.\n";
# restore terminal to normal state in case CTL+C issued while