mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-10 05:00:45 +00:00
Test and fix typo in MasterSlave.pm and update that module in all tools.
This commit is contained in:
@@ -1414,6 +1414,54 @@ sub new {
|
||||
return bless $self, $class;
|
||||
}
|
||||
|
||||
sub get_slaves {
|
||||
my ($self, %args) = @_;
|
||||
my @required_args = qw(make_cxn OptionParser DSNParser Quoter);
|
||||
foreach my $arg ( @required_args ) {
|
||||
die "I need a $arg argument" unless $args{$arg};
|
||||
}
|
||||
my ($make_cxn, $o, $dp) = @args{@required_args};
|
||||
|
||||
my $slaves = [];
|
||||
my $method = $o->get('recursion-method');
|
||||
PTDEBUG && _d('Slave recursion method:', $method);
|
||||
if ( !$method || $method =~ m/processlist|hosts/i ) {
|
||||
my @required_args = qw(dbh dsn);
|
||||
foreach my $arg ( @required_args ) {
|
||||
die "I need a $arg argument" unless $args{$arg};
|
||||
}
|
||||
my ($dbh, $dsn) = @args{@required_args};
|
||||
$self->recurse_to_slaves(
|
||||
{ dbh => $dbh,
|
||||
dsn => $dsn,
|
||||
dsn_parser => $dp,
|
||||
recurse => $o->get('recurse'),
|
||||
method => $o->get('recursion-method'),
|
||||
callback => sub {
|
||||
my ( $dsn, $dbh, $level, $parent ) = @_;
|
||||
return unless $level;
|
||||
PTDEBUG && _d('Found slave:', $dp->as_string($dsn));
|
||||
push @$slaves, $make_cxn->(dsn => $dsn, dbh => $dbh);
|
||||
return;
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
elsif ( $method =~ m/^dsn=/i ) {
|
||||
my ($dsn_table_dsn) = $method =~ m/^dsn=(.+)/i;
|
||||
$slaves = $self->get_cxn_from_dsn_table(
|
||||
%args,
|
||||
dsn_table_dsn => $dsn_table_dsn,
|
||||
);
|
||||
}
|
||||
else {
|
||||
die "Invalid --recursion-method: $method. Valid values are: "
|
||||
. "dsn=DSN, hosts, or processlist.\n";
|
||||
}
|
||||
|
||||
return $slaves;
|
||||
}
|
||||
|
||||
sub recurse_to_slaves {
|
||||
my ( $self, $args, $level ) = @_;
|
||||
$level ||= 0;
|
||||
@@ -1990,6 +2038,43 @@ sub reset_known_replication_threads {
|
||||
return;
|
||||
}
|
||||
|
||||
sub get_cxn_from_dsn_table {
|
||||
my ($self, %args) = @_;
|
||||
my @required_args = qw(dsn_table_dsn make_cxn DSNParser Quoter);
|
||||
foreach my $arg ( @required_args ) {
|
||||
die "I need a $arg argument" unless $args{$arg};
|
||||
}
|
||||
my ($dsn_table_dsn, $make_cxn, $dp, $q) = @args{@required_args};
|
||||
PTDEBUG && _d('DSN table DSN:', $dsn_table_dsn);
|
||||
|
||||
my $dsn = $dp->parse($dsn_table_dsn);
|
||||
my $dsn_table;
|
||||
if ( $dsn->{D} && $dsn->{t} ) {
|
||||
$dsn_table = $q->quote($dsn->{D}, $dsn->{t});
|
||||
}
|
||||
elsif ( $dsn->{t} && $dsn->{t} =~ m/\./ ) {
|
||||
$dsn_table = $q->quote($q->split_unquote($dsn->{t}));
|
||||
}
|
||||
else {
|
||||
die "DSN table DSN does not specify a database (D) "
|
||||
. "or a database-qualified table (t)";
|
||||
}
|
||||
|
||||
my $dsn_tbl_cxn = $make_cxn->(dsn => $dsn);
|
||||
my $dbh = $dsn_tbl_cxn->connect();
|
||||
my $sql = "SELECT dsn FROM $dsn_table ORDER BY id";
|
||||
PTDEBUG && _d($sql);
|
||||
my $dsn_strings = $dbh->selectcol_arrayref($sql);
|
||||
my @cxn;
|
||||
if ( $dsn_strings ) {
|
||||
foreach my $dsn_string ( @$dsn_strings ) {
|
||||
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
|
||||
push @cxn, $make_cxn->(dsn_string => $dsn_string);
|
||||
}
|
||||
}
|
||||
return \@cxn;
|
||||
}
|
||||
|
||||
sub _d {
|
||||
my ($package, undef, $line) = caller 0;
|
||||
@_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
|
||||
|
Reference in New Issue
Block a user