mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-10 05:00:45 +00:00
Fix lib/Cxn.pm that didn't merge correctly. Fix t/lib/OptionParser.t test failure. Update Cxn, OptionParser, and DSNParser in all tools.
This commit is contained in:
65
lib/Cxn.pm
65
lib/Cxn.pm
@@ -102,23 +102,24 @@ sub new {
|
||||
|| '';
|
||||
|
||||
my $self = {
|
||||
dsn => $dsn,
|
||||
dbh => $args{dbh},
|
||||
dsn_name => $dsn_name,
|
||||
hostname => '',
|
||||
set => $args{set},
|
||||
NAME_lc => defined($args{NAME_lc}) ? $args{NAME_lc} : 1,
|
||||
dbh_set => 0,
|
||||
ask_pass => $o->get('ask-pass'),
|
||||
DSNParser => $dp,
|
||||
dsn => $dsn,
|
||||
dbh => $args{dbh},
|
||||
dsn_name => $dsn_name,
|
||||
hostname => '',
|
||||
set => $args{set},
|
||||
NAME_lc => defined($args{NAME_lc}) ? $args{NAME_lc} : 1,
|
||||
dbh_set => 0,
|
||||
ask_pass => $o->get('ask-pass'),
|
||||
DSNParser => $dp,
|
||||
is_cluster_node => undef,
|
||||
parent => $args{parent},
|
||||
};
|
||||
|
||||
return bless $self, $class;
|
||||
}
|
||||
|
||||
sub connect {
|
||||
my ( $self ) = @_;
|
||||
my ( $self, %opts ) = @_;
|
||||
my $dsn = $self->{dsn};
|
||||
my $dp = $self->{DSNParser};
|
||||
|
||||
@@ -129,11 +130,18 @@ sub connect {
|
||||
$dsn->{p} = OptionParser::prompt_noecho("Enter MySQL password: ");
|
||||
$self->{asked_for_pass} = 1;
|
||||
}
|
||||
$dbh = $dp->get_dbh($dp->get_cxn_params($dsn), { AutoCommit => 1 });
|
||||
$dbh = $dp->get_dbh(
|
||||
$dp->get_cxn_params($dsn),
|
||||
{
|
||||
AutoCommit => 1,
|
||||
%opts,
|
||||
},
|
||||
);
|
||||
}
|
||||
PTDEBUG && _d($dbh, 'Connected dbh to', $self->{name});
|
||||
|
||||
return $self->set_dbh($dbh);
|
||||
$dbh = $self->set_dbh($dbh);
|
||||
PTDEBUG && _d($dbh, 'Connected dbh to', $self->{hostname},$self->{dsn_name});
|
||||
return $dbh;
|
||||
}
|
||||
|
||||
sub set_dbh {
|
||||
@@ -166,6 +174,11 @@ sub set_dbh {
|
||||
$self->{hostname} = $hostname;
|
||||
}
|
||||
|
||||
if ( $self->{parent} ) {
|
||||
PTDEBUG && _d($dbh, 'Setting InactiveDestroy=1 in parent');
|
||||
$dbh->{InactiveDestroy} = 1;
|
||||
}
|
||||
|
||||
# Call the set callback to let the caller SET any MySQL variables.
|
||||
if ( my $set = $self->{set}) {
|
||||
$set->($dbh);
|
||||
@@ -176,6 +189,15 @@ sub set_dbh {
|
||||
return $dbh;
|
||||
}
|
||||
|
||||
sub lost_connection {
|
||||
my ($self, $e) = @_;
|
||||
return 0 unless $e;
|
||||
return $e =~ m/MySQL server has gone away/
|
||||
|| $e =~ m/Lost connection to MySQL server/;
|
||||
# The 1st pattern means that MySQL itself died or was stopped.
|
||||
# The 2nd pattern means that our cxn was killed (KILL <id>).
|
||||
}
|
||||
|
||||
# Sub: dbh
|
||||
# Return the cxn's dbh.
|
||||
sub dbh {
|
||||
@@ -200,12 +222,21 @@ sub name {
|
||||
|
||||
sub DESTROY {
|
||||
my ($self) = @_;
|
||||
if ( $self->{dbh}
|
||||
&& blessed($self->{dbh})
|
||||
&& $self->{dbh}->can("disconnect") ) {
|
||||
PTDEBUG && _d('Disconnecting dbh', $self->{dbh}, $self->{name});
|
||||
|
||||
PTDEBUG && _d('Destroying cxn');
|
||||
|
||||
if ( $self->{parent} ) {
|
||||
PTDEBUG && _d($self->{dbh}, 'Not disconnecting dbh in parent');
|
||||
}
|
||||
elsif ( $self->{dbh}
|
||||
&& blessed($self->{dbh})
|
||||
&& $self->{dbh}->can("disconnect") )
|
||||
{
|
||||
PTDEBUG && _d($self->{dbh}, 'Disconnecting dbh on', $self->{hostname},
|
||||
$self->{dsn_name});
|
||||
$self->{dbh}->disconnect();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user