Merge pull request #408 from percona/PT-1344

PBM-144 Updated MasterSlave to support hosts without port
This commit is contained in:
Carlos Salguero
2019-07-18 12:08:00 -03:00
committed by GitHub
10 changed files with 32 additions and 23 deletions

View File

@@ -3745,6 +3745,7 @@ sub _find_slaves_by_processlist {
grep { $_ } grep { $_ }
map { map {
my ( $host ) = $_->{host} =~ m/^([^:]+):/; my ( $host ) = $_->{host} =~ m/^([^:]+):/;
$host ||= $_->{host};
if ( $host eq 'localhost' ) { if ( $host eq 'localhost' ) {
$host = '127.0.0.1'; # Replication never uses sockets. $host = '127.0.0.1'; # Replication never uses sockets.
} }

View File

@@ -112,22 +112,22 @@ use warnings FATAL => 'all';
use English qw(-no_match_vars); use English qw(-no_match_vars);
use constant PTDEBUG => $ENV{PTDEBUG} || 0; use constant PTDEBUG => $ENV{PTDEBUG} || 0;
sub check_recursion_method { sub check_recursion_method {
my ($methods) = @_; my ($methods) = @_;
if ( @$methods != 1 ) { if ( @$methods != 1 ) {
if ( grep({ !m/processlist|hosts/i } @$methods) if ( grep({ !m/processlist|hosts/i } @$methods)
&& $methods->[0] !~ /^dsn=/i ) && $methods->[0] !~ /^dsn=/i )
{ {
die "Invalid combination of recursion methods: " die "Invalid combination of recursion methods: "
. join(", ", map { defined($_) ? $_ : 'undef' } @$methods) . ". " . join(", ", map { defined($_) ? $_ : 'undef' } @$methods) . ". "
. "Only hosts and processlist may be combined.\n" . "Only hosts and processlist may be combined.\n"
} }
} }
else { else {
my ($method) = @$methods; my ($method) = @$methods;
die "Invalid recursion method: " . ( $method || 'undef' ) die "Invalid recursion method: " . ( $method || 'undef' )
unless $method && $method =~ m/^(?:processlist$|hosts$|none$|cluster$|dsn=)/i; unless $method && $method =~ m/^(?:processlist$|hosts$|none$|cluster$|dsn=)/i;
} }
} }
sub new { sub new {
@@ -156,7 +156,7 @@ sub get_slaves {
my $methods = $self->_resolve_recursion_methods($args{dsn}); my $methods = $self->_resolve_recursion_methods($args{dsn});
return $slaves unless @$methods; return $slaves unless @$methods;
if ( grep { m/processlist|hosts/i } @$methods ) { if ( grep { m/processlist|hosts/i } @$methods ) {
my @required_args = qw(dbh dsn); my @required_args = qw(dbh dsn);
foreach my $arg ( @required_args ) { foreach my $arg ( @required_args ) {
@@ -201,7 +201,7 @@ sub get_slaves {
else { else {
die "Unexpected recursion methods: @$methods"; die "Unexpected recursion methods: @$methods";
} }
return $slaves; return $slaves;
} }
@@ -321,6 +321,7 @@ sub _find_slaves_by_processlist {
grep { $_ } grep { $_ }
map { map {
my ( $host ) = $_->{host} =~ m/^([^:]+):/; my ( $host ) = $_->{host} =~ m/^([^:]+):/;
$host ||= $_->{host};
if ( $host eq 'localhost' ) { if ( $host eq 'localhost' ) {
$host = '127.0.0.1'; # Replication never uses sockets. $host = '127.0.0.1'; # Replication never uses sockets.
} }
@@ -719,7 +720,7 @@ sub short_host {
} }
sub is_replication_thread { sub is_replication_thread {
my ( $self, $query, %args ) = @_; my ( $self, $query, %args ) = @_;
return unless $query; return unless $query;
my $type = lc($args{type} || 'all'); my $type = lc($args{type} || 'all');
@@ -734,7 +735,7 @@ sub is_replication_thread {
if ( !$match ) { if ( !$match ) {
if ( ($query->{User} || $query->{user} || '') eq "system user" ) { if ( ($query->{User} || $query->{user} || '') eq "system user" ) {
PTDEBUG && _d("Slave replication thread"); PTDEBUG && _d("Slave replication thread");
if ( $type ne 'all' ) { if ( $type ne 'all' ) {
my $state = $query->{State} || $query->{state} || ''; my $state = $query->{State} || $query->{state} || '';
if ( $state =~ m/^init|end$/ ) { if ( $state =~ m/^init|end$/ ) {
@@ -747,7 +748,7 @@ sub is_replication_thread {
|Reading\sevent\sfrom\sthe\srelay\slog |Reading\sevent\sfrom\sthe\srelay\slog
|Has\sread\sall\srelay\slog;\swaiting |Has\sread\sall\srelay\slog;\swaiting
|Making\stemp\sfile |Making\stemp\sfile
|Waiting\sfor\sslave\smutex\son\sexit)/xi; |Waiting\sfor\sslave\smutex\son\sexit)/xi;
$match = $type eq 'slave_sql' && $slave_sql ? 1 $match = $type eq 'slave_sql' && $slave_sql ? 1
: $type eq 'slave_io' && !$slave_sql ? 1 : $type eq 'slave_io' && !$slave_sql ? 1
@@ -811,7 +812,7 @@ sub get_replication_filters {
replicate_do_db replicate_do_db
replicate_ignore_db replicate_ignore_db
replicate_do_table replicate_do_table
replicate_ignore_table replicate_ignore_table
replicate_wild_do_table replicate_wild_do_table
replicate_wild_ignore_table replicate_wild_ignore_table
); );
@@ -822,7 +823,7 @@ sub get_replication_filters {
$filters{slave_skip_errors} = $row->[1] if $row->[1] && $row->[1] ne 'OFF'; $filters{slave_skip_errors} = $row->[1] if $row->[1] && $row->[1] ne 'OFF';
} }
return \%filters; return \%filters;
} }

View File

@@ -4027,6 +4027,7 @@ sub _find_slaves_by_processlist {
grep { $_ } grep { $_ }
map { map {
my ( $host ) = $_->{host} =~ m/^([^:]+):/; my ( $host ) = $_->{host} =~ m/^([^:]+):/;
$host ||= $_->{host};
if ( $host eq 'localhost' ) { if ( $host eq 'localhost' ) {
$host = '127.0.0.1'; # Replication never uses sockets. $host = '127.0.0.1'; # Replication never uses sockets.
} }

View File

@@ -4281,8 +4281,7 @@ sub recurse_to_slaves {
PTDEBUG && _d('Connected to', $dp->as_string($slave_dsn)); PTDEBUG && _d('Connected to', $dp->as_string($slave_dsn));
}; };
if ( $EVAL_ERROR ) { if ( $EVAL_ERROR ) {
#TODO REMOVE DEBUG print STDERR "Cannot connect to ", $dp->as_string($slave_dsn), "\n"
print STDERR "1> Cannot connect to ", $dp->as_string($slave_dsn), "\n"
or die "Cannot print: $OS_ERROR"; or die "Cannot print: $OS_ERROR";
return; return;
} }
@@ -4350,6 +4349,7 @@ sub _find_slaves_by_processlist {
grep { $_ } grep { $_ }
map { map {
my ( $host ) = $_->{host} =~ m/^([^:]+):/; my ( $host ) = $_->{host} =~ m/^([^:]+):/;
$host ||= $_->{host};
if ( $host eq 'localhost' ) { if ( $host eq 'localhost' ) {
$host = '127.0.0.1'; # Replication never uses sockets. $host = '127.0.0.1'; # Replication never uses sockets.
} }

View File

@@ -10675,6 +10675,7 @@ sub _find_slaves_by_processlist {
grep { $_ } grep { $_ }
map { map {
my ( $host ) = $_->{host} =~ m/^([^:]+):/; my ( $host ) = $_->{host} =~ m/^([^:]+):/;
$host ||= $_->{host};
if ( $host eq 'localhost' ) { if ( $host eq 'localhost' ) {
$host = '127.0.0.1'; # Replication never uses sockets. $host = '127.0.0.1'; # Replication never uses sockets.
} }

View File

@@ -2435,6 +2435,7 @@ sub _find_slaves_by_processlist {
grep { $_ } grep { $_ }
map { map {
my ( $host ) = $_->{host} =~ m/^([^:]+):/; my ( $host ) = $_->{host} =~ m/^([^:]+):/;
$host ||= $_->{host};
if ( $host eq 'localhost' ) { if ( $host eq 'localhost' ) {
$host = '127.0.0.1'; # Replication never uses sockets. $host = '127.0.0.1'; # Replication never uses sockets.
} }

View File

@@ -2846,6 +2846,7 @@ sub _find_slaves_by_processlist {
grep { $_ } grep { $_ }
map { map {
my ( $host ) = $_->{host} =~ m/^([^:]+):/; my ( $host ) = $_->{host} =~ m/^([^:]+):/;
$host ||= $_->{host};
if ( $host eq 'localhost' ) { if ( $host eq 'localhost' ) {
$host = '127.0.0.1'; # Replication never uses sockets. $host = '127.0.0.1'; # Replication never uses sockets.
} }

View File

@@ -5299,6 +5299,7 @@ sub _find_slaves_by_processlist {
grep { $_ } grep { $_ }
map { map {
my ( $host ) = $_->{host} =~ m/^([^:]+):/; my ( $host ) = $_->{host} =~ m/^([^:]+):/;
$host ||= $_->{host};
if ( $host eq 'localhost' ) { if ( $host eq 'localhost' ) {
$host = '127.0.0.1'; # Replication never uses sockets. $host = '127.0.0.1'; # Replication never uses sockets.
} }

View File

@@ -6844,6 +6844,7 @@ sub _find_slaves_by_processlist {
grep { $_ } grep { $_ }
map { map {
my ( $host ) = $_->{host} =~ m/^([^:]+):/; my ( $host ) = $_->{host} =~ m/^([^:]+):/;
$host ||= $_->{host};
if ( $host eq 'localhost' ) { if ( $host eq 'localhost' ) {
$host = '127.0.0.1'; # Replication never uses sockets. $host = '127.0.0.1'; # Replication never uses sockets.
} }

View File

@@ -272,6 +272,7 @@ sub _find_slaves_by_processlist {
grep { $_ } grep { $_ }
map { map {
my ( $host ) = $_->{host} =~ m/^([^:]+):/; my ( $host ) = $_->{host} =~ m/^([^:]+):/;
$host ||= $_->{host};
if ( $host eq 'localhost' ) { if ( $host eq 'localhost' ) {
$host = '127.0.0.1'; # Replication never uses sockets. $host = '127.0.0.1'; # Replication never uses sockets.
} }