mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-19 18:34:59 +00:00
Update Cxn in all tools and set parent accordingly.
This commit is contained in:
73
bin/pt-kill
73
bin/pt-kill
@@ -4969,23 +4969,24 @@ sub new {
|
||||
}
|
||||
|
||||
my $self = {
|
||||
dsn => $dsn,
|
||||
dbh => $args{dbh},
|
||||
dsn_name => $dp->as_string($dsn, [qw(h P S)]),
|
||||
hostname => '',
|
||||
set => $args{set},
|
||||
NAME_lc => defined($args{NAME_lc}) ? $args{NAME_lc} : 1,
|
||||
dbh_set => 0,
|
||||
OptionParser => $o,
|
||||
DSNParser => $dp,
|
||||
dsn => $dsn,
|
||||
dbh => $args{dbh},
|
||||
dsn_name => $dp->as_string($dsn, [qw(h P S)]),
|
||||
hostname => '',
|
||||
set => $args{set},
|
||||
NAME_lc => defined($args{NAME_lc}) ? $args{NAME_lc} : 1,
|
||||
dbh_set => 0,
|
||||
OptionParser => $o,
|
||||
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};
|
||||
my $o = $self->{OptionParser};
|
||||
@@ -4996,11 +4997,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 {
|
||||
@@ -5023,6 +5031,11 @@ sub set_dbh {
|
||||
$self->{hostname} = $hostname;
|
||||
}
|
||||
|
||||
if ( $self->{parent} ) {
|
||||
PTDEBUG && _d($dbh, 'Setting InactiveDestroy=1 in parent');
|
||||
$dbh->{InactiveDestroy} = 1;
|
||||
}
|
||||
|
||||
if ( my $set = $self->{set}) {
|
||||
$set->($dbh);
|
||||
}
|
||||
@@ -5032,6 +5045,13 @@ 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/;
|
||||
}
|
||||
|
||||
sub dbh {
|
||||
my ($self) = @_;
|
||||
return $self->{dbh};
|
||||
@@ -5050,12 +5070,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;
|
||||
}
|
||||
|
||||
@@ -6464,6 +6493,7 @@ sub main {
|
||||
$cxn = Cxn->new(
|
||||
dsn_string => shift @ARGV,
|
||||
NAME_lc => 0,
|
||||
parent => $o->get('daemonize'),
|
||||
DSNParser => $dp,
|
||||
OptionParser => $o,
|
||||
);
|
||||
@@ -6643,6 +6673,15 @@ sub main {
|
||||
$daemon->make_PID_file();
|
||||
}
|
||||
|
||||
# If we daemonized, the parent has already exited and we're the child.
|
||||
# We shared a copy of every Cxn with the parent, and the parent's copies
|
||||
# were destroyed but the dbhs were not disconnected because the parent
|
||||
# attrib was true. Now, as the child, set it false so the dbhs will be
|
||||
# disconnected when our Cxn copies are destroyed. If we didn't daemonize,
|
||||
# then we're not really a parent (since we have no children), so set it
|
||||
# false to auto-disconnect the dbhs when our Cxns are destroyed.
|
||||
$cxn->{parent} = 0 if $cxn;
|
||||
|
||||
# ########################################################################
|
||||
# Do the version-check
|
||||
# ########################################################################
|
||||
|
Reference in New Issue
Block a user