mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-22 20:19:00 +00:00
Add parent attrib to Cxn to fix forking after --daemonize.
This commit is contained in:
26
lib/Cxn.pm
26
lib/Cxn.pm
@@ -108,13 +108,14 @@ sub new {
|
|||||||
OptionParser => $o,
|
OptionParser => $o,
|
||||||
DSNParser => $dp,
|
DSNParser => $dp,
|
||||||
is_cluster_node => undef,
|
is_cluster_node => undef,
|
||||||
|
parent => $args{parent},
|
||||||
};
|
};
|
||||||
|
|
||||||
return bless $self, $class;
|
return bless $self, $class;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub connect {
|
sub connect {
|
||||||
my ( $self ) = @_;
|
my ( $self, %opts ) = @_;
|
||||||
my $dsn = $self->{dsn};
|
my $dsn = $self->{dsn};
|
||||||
my $dp = $self->{DSNParser};
|
my $dp = $self->{DSNParser};
|
||||||
my $o = $self->{OptionParser};
|
my $o = $self->{OptionParser};
|
||||||
@@ -126,7 +127,13 @@ sub connect {
|
|||||||
$dsn->{p} = OptionParser::prompt_noecho("Enter MySQL password: ");
|
$dsn->{p} = OptionParser::prompt_noecho("Enter MySQL password: ");
|
||||||
$self->{asked_for_pass} = 1;
|
$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});
|
PTDEBUG && _d($dbh, 'Connected dbh to', $self->{name});
|
||||||
|
|
||||||
@@ -163,6 +170,11 @@ sub set_dbh {
|
|||||||
$self->{hostname} = $hostname;
|
$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.
|
# Call the set callback to let the caller SET any MySQL variables.
|
||||||
if ( my $set = $self->{set}) {
|
if ( my $set = $self->{set}) {
|
||||||
$set->($dbh);
|
$set->($dbh);
|
||||||
@@ -206,12 +218,18 @@ sub name {
|
|||||||
|
|
||||||
sub DESTROY {
|
sub DESTROY {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
if ( $self->{dbh}
|
|
||||||
|
if ( $self->{parent} ) {
|
||||||
|
PTDEBUG && _d('Not disconnecting dbh in parent');
|
||||||
|
}
|
||||||
|
elsif ( $self->{dbh}
|
||||||
&& blessed($self->{dbh})
|
&& blessed($self->{dbh})
|
||||||
&& $self->{dbh}->can("disconnect") ) {
|
&& $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();
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user