mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-10-21 10:17:18 +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 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 {
|
||||||
|
20
lib/Cxn.pm
20
lib/Cxn.pm
@@ -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();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user