mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-10-21 01:54:44 +00:00
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:
@@ -2713,9 +2713,11 @@ package Cxn;
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
|
||||
|
||||
use constant PERCONA_TOOLKIT_TEST_USE_DSN_NAMES => $ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} || 0;
|
||||
use Scalar::Util qw(blessed);
|
||||
use constant {
|
||||
PTDEBUG => $ENV{PTDEBUG} || 0,
|
||||
PERCONA_TOOLKIT_TEST_USE_DSN_NAMES => $ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} || 0,
|
||||
};
|
||||
|
||||
sub new {
|
||||
my ( $class, %args ) = @_;
|
||||
@@ -2818,7 +2820,9 @@ sub name {
|
||||
|
||||
sub DESTROY {
|
||||
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});
|
||||
$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
|
||||
# was altered.
|
||||
push @cleanup_tasks, sub {
|
||||
|
12
lib/Cxn.pm
12
lib/Cxn.pm
@@ -35,13 +35,15 @@ package Cxn;
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
|
||||
|
||||
use Scalar::Util qw(blessed);
|
||||
use constant {
|
||||
PTDEBUG => $ENV{PTDEBUG} || 0,
|
||||
# Hostnames make testing less accurate. Tests need to see
|
||||
# that such-and-such happened on specific slave hosts, but
|
||||
# the sandbox servers are all on one host so all slaves have
|
||||
# the same hostname.
|
||||
use constant PERCONA_TOOLKIT_TEST_USE_DSN_NAMES => $ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} || 0;
|
||||
PERCONA_TOOLKIT_TEST_USE_DSN_NAMES => $ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} || 0,
|
||||
};
|
||||
|
||||
# Sub: new
|
||||
#
|
||||
@@ -193,7 +195,9 @@ sub name {
|
||||
|
||||
sub DESTROY {
|
||||
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});
|
||||
$self->{dbh}->disconnect();
|
||||
}
|
||||
|
Reference in New Issue
Block a user