Cxn & pt-osc: Guard the cleanup tasks.

Does this twofold: By adding a __DIE__ hook to make sure they are
called, and by checking that the dbh is an actual database handle.
This commit is contained in:
Brian Fraser fraserb@gmail.com
2012-06-05 16:24:32 -03:00
parent c4a8a67204
commit e57b67f10e
2 changed files with 25 additions and 12 deletions

View File

@@ -2713,9 +2713,11 @@ package Cxn;
use strict; use strict;
use warnings FATAL => 'all'; use warnings FATAL => 'all';
use English qw(-no_match_vars); use English qw(-no_match_vars);
use constant PTDEBUG => $ENV{PTDEBUG} || 0; use Scalar::Util qw(blessed);
use constant {
use constant PERCONA_TOOLKIT_TEST_USE_DSN_NAMES => $ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} || 0; PTDEBUG => $ENV{PTDEBUG} || 0,
PERCONA_TOOLKIT_TEST_USE_DSN_NAMES => $ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} || 0,
};
sub new { sub new {
my ( $class, %args ) = @_; my ( $class, %args ) = @_;
@@ -2818,7 +2820,9 @@ sub name {
sub DESTROY { sub DESTROY {
my ($self) = @_; my ($self) = @_;
if ( $self->{dbh} && ref($self->{dbh}) ) { if ( $self->{dbh}
&& blessed($self->{dbh})
&& $self->{dbh}->can("disconnect") ) {
PTDEBUG && _d('Disconnecting dbh', $self->{dbh}, $self->{name}); PTDEBUG && _d('Disconnecting dbh', $self->{dbh}, $self->{name});
$self->{dbh}->disconnect(); $self->{dbh}->disconnect();
} }
@@ -5439,6 +5443,11 @@ sub main {
} }
); );
local $SIG{__DIE__} = sub {
local $EVAL_ERROR = $_[0];
undef $cleanup;
};
# The last cleanup task is to report whether or not the orig table # The last cleanup task is to report whether or not the orig table
# was altered. # was altered.
push @cleanup_tasks, sub { push @cleanup_tasks, sub {

View File

@@ -35,13 +35,15 @@ package Cxn;
use strict; use strict;
use warnings FATAL => 'all'; use warnings FATAL => 'all';
use English qw(-no_match_vars); use English qw(-no_match_vars);
use constant PTDEBUG => $ENV{PTDEBUG} || 0; use Scalar::Util qw(blessed);
use constant {
# Hostnames make testing less accurate. Tests need to see PTDEBUG => $ENV{PTDEBUG} || 0,
# that such-and-such happened on specific slave hosts, but # Hostnames make testing less accurate. Tests need to see
# the sandbox servers are all on one host so all slaves have # that such-and-such happened on specific slave hosts, but
# the same hostname. # the sandbox servers are all on one host so all slaves have
use constant PERCONA_TOOLKIT_TEST_USE_DSN_NAMES => $ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} || 0; # the same hostname.
PERCONA_TOOLKIT_TEST_USE_DSN_NAMES => $ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} || 0,
};
# Sub: new # Sub: new
# #
@@ -193,7 +195,9 @@ sub name {
sub DESTROY { sub DESTROY {
my ($self) = @_; my ($self) = @_;
if ( $self->{dbh} && ref($self->{dbh}) ) { if ( $self->{dbh}
&& blessed($self->{dbh})
&& $self->{dbh}->can("disconnect") ) {
PTDEBUG && _d('Disconnecting dbh', $self->{dbh}, $self->{name}); PTDEBUG && _d('Disconnecting dbh', $self->{dbh}, $self->{name});
$self->{dbh}->disconnect(); $self->{dbh}->disconnect();
} }