mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-04 11:37:16 +00:00
Update Cxn in all tools and set parent accordingly.
This commit is contained in:
@@ -1639,23 +1639,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};
|
||||
@@ -1666,11 +1667,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 {
|
||||
@@ -1693,6 +1701,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);
|
||||
}
|
||||
@@ -1727,12 +1740,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;
|
||||
}
|
||||
|
||||
@@ -3705,6 +3727,7 @@ sub main {
|
||||
if ( my $src_dsn_string = shift @ARGV ) {
|
||||
$src = Cxn->new(
|
||||
dsn_string => $src_dsn_string,
|
||||
parent => $o->get('daemonize'),
|
||||
DSNParser => $dp,
|
||||
OptionParser => $o,
|
||||
);
|
||||
@@ -3714,7 +3737,8 @@ sub main {
|
||||
if ( my $dst_dsn = $o->get('dest') ) {
|
||||
$dst = Cxn->new(
|
||||
dsn => $dst_dsn,
|
||||
prev_dsn => $src ? $src->dsn : undef,
|
||||
prev_dsn => ($src ? $src->dsn : undef),
|
||||
parent => $o->get('daemonize'),
|
||||
DSNParser => $dp,
|
||||
OptionParser => $o,
|
||||
);
|
||||
@@ -3765,6 +3789,16 @@ 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.
|
||||
$src->{parent} = 0;
|
||||
$dst->{parent} = 0 if $dst;
|
||||
|
||||
# ########################################################################
|
||||
# Do the version-check
|
||||
# ########################################################################
|
||||
|
Reference in New Issue
Block a user