Skip to content

Commit

Permalink
PT-2340 - Support MySQL 8.4
Browse files Browse the repository at this point in the history
- Implemented functions get_replica_name and get_source_name in lib/MasterSlave.pm I did not implement similar functions in other places, because they set other variables as well, not only replica_name or source_name.
  • Loading branch information
svetasmirnova committed Nov 12, 2024
1 parent a1093ff commit bb66ab0
Show file tree
Hide file tree
Showing 14 changed files with 281 additions and 620 deletions.
84 changes: 26 additions & 58 deletions bin/pt-archiver
Original file line number Diff line number Diff line change
Expand Up @@ -3999,13 +3999,8 @@ sub get_connected_replicas {
sub is_source_of {
my ( $self, $source, $replica ) = @_;

my $replica_version = VersionParser->new($replica);
my $source_name = 'source';
my $source_port = 'source_port';
if ( $replica_version lt '8.1' || $replica_version->flavor() =~ m/maria/ ) {
$source_name = 'master';
$source_port = 'master_port';
}
my $source_name = get_source_name($replica);
my $source_port = "${source_name}_port";

my $source_status = $self->get_source_status($source)
or die "The server specified as a source is not a source";
Expand Down Expand Up @@ -4064,11 +4059,7 @@ sub get_source_dsn {
sub get_replica_status {
my ( $self, $dbh ) = @_;

my $server_version = VersionParser->new($dbh);
my $replica_name = 'replica';
if ( $server_version lt '8.1' || $server_version->flavor() =~ m/maria/ ) {
$replica_name = 'slave';
}
my $replica_name = get_replica_name($dbh);

if ( !$self->{not_a_replica}->{$dbh} ) {
my $sth = $self->{sths}->{$dbh}->{REPLICA_STATUS}
Expand Down Expand Up @@ -4179,11 +4170,8 @@ sub wait_for_source {
error =>'Wait for source: this is a multi-source replica but "channel" was not specified on the command line',
};
}
my $source_name = get_source_name($replica_dbh);
my $vp = VersionParser->new($replica_dbh);
my $source_name = 'source';
if ( $vp lt '8.1' || $vp->flavor() =~ m/maria/ ) {
$source_name = 'master';
}
my $channel_sql = $vp > '5.6' && $self->{channel} ? ", '$self->{channel}'" : '';
my $sql = "SELECT ${source_name}_POS_WAIT('$source_status->{file}', $source_status->{position}, $timeout $channel_sql)";
PTDEBUG && _d($replica_dbh, $sql);
Expand All @@ -4207,11 +4195,8 @@ sub wait_for_source {

sub stop_replica {
my ( $self, $dbh ) = @_;
my $vp = VersionParser->new($dbh);
my $replica_name = 'replica';
if ( $vp lt '8.1' || $vp->flavor() =~ m/maria/ ) {
$replica_name = 'slave';
}
my $replica_name = get_replica_name($dbh);

my $sth = $self->{sths}->{$dbh}->{STOP_REPLICA}
||= $dbh->prepare("STOP ${replica_name}");
PTDEBUG && _d($dbh, $sth->{Statement});
Expand All @@ -4221,13 +4206,8 @@ sub stop_replica {
sub start_replica {
my ( $self, $dbh, $pos ) = @_;

my $vp = VersionParser->new($dbh);
my $source_name = 'source';
my $replica_name = 'replica';
if ( $vp lt '8.1' || $vp->flavor() =~ m/maria/ ) {
$source_name = 'master';
$replica_name = 'slave';
}
my $source_name = get_source_name($dbh);
my $replica_name = get_replica_name($dbh);

if ( $pos ) {
my $sql = "START ${replica_name} UNTIL ${source_name}_LOG_FILE='$pos->{file}', "
Expand Down Expand Up @@ -4271,11 +4251,7 @@ sub catchup_to_source {
if ( !defined $result->{result} ) {
$replica_status = $self->get_replica_status($replica);

my $vp = VersionParser->new($replica);
my $replica_name = 'replica';
if ( $vp lt '8.1' || $vp->flavor() =~ m/maria/ ) {
$replica_name = 'slave';
}
my $replica_name = get_replica_name($replica);

if ( !$self->replica_is_running($replica_status, $replica_name) ) {
PTDEBUG && _d('Source position:',
Expand Down Expand Up @@ -4320,17 +4296,9 @@ sub catchup_to_same_pos {
$s1_pos = $self->repl_posn($s1_status);
$s2_pos = $self->repl_posn($s2_status);

my $vp1 = VersionParser->new($s1_dbh);
my $replica1_name = 'replica';
if ( $vp1 lt '8.1' || $vp1->flavor() =~ m/maria/ ) {
$replica1_name = 'slave';
}
my $replica1_name = get_replica_name($s1_dbh);

my $vp2 = VersionParser->new($s2_dbh);
my $replica2_name = 'replica';
if ( $vp2 lt '8.1' || $vp2->flavor() =~ m/maria/ ) {
$replica2_name = 'slave';
}
my $replica2_name = get_replica_name($s2_dbh);

if ( $self->replica_is_running($s1_status, $replica1_name)
|| $self->replica_is_running($s2_status, $replica2_name)
Expand All @@ -4349,11 +4317,7 @@ sub replica_is_running {
sub has_replica_updates {
my ( $self, $dbh ) = @_;

my $vp = VersionParser->new($dbh);
my $replica_name = 'replica';
if ( $vp lt '8.1' || $vp->flavor() =~ m/maria/ ) {
$replica_name = 'slave';
}
my $replica_name = get_replica_name($dbh);

my $sql = qq{SHOW VARIABLES LIKE 'log_${replica_name}_updates'};
PTDEBUG && _d($dbh, $sql);
Expand Down Expand Up @@ -4386,11 +4350,7 @@ sub repl_posn {
sub get_replica_lag {
my ( $self, $dbh ) = @_;

my $vp = VersionParser->new($dbh);
my $source_name = 'source';
if ( $vp lt '8.1' || $vp->flavor() =~ m/maria/ ) {
$source_name = 'master';
}
my $source_name = get_source_name($dbh);

my $stat = $self->get_replica_status($dbh);
return unless $stat; # server is not a replica
Expand Down Expand Up @@ -4490,11 +4450,7 @@ sub get_replication_filters {
}
my ($dbh) = @args{@required_args};

my $vp = VersionParser->new($dbh);
my $replica_name = 'replica';
if ( $vp lt '8.1' || $vp->flavor() =~ m/maria/ ) {
$replica_name = 'slave';
}
my $replica_name = get_replica_name($dbh);

my %filters = ();

Expand Down Expand Up @@ -4604,6 +4560,18 @@ sub get_cxn_from_dsn_table {
return \@cxn;
}

sub get_source_name {
my ($dbh) = @_;
my $vp = VersionParser->new($dbh);
return ($vp lt '8.1' || $vp->flavor() =~ m/maria/) ? 'master' : 'source';
}

sub get_replica_name {
my ($dbh) = @_;
my $vp = VersionParser->new($dbh);
return ($vp lt '8.1' || $vp->flavor() =~ m/maria/) ? 'slave' : 'replica';
}

sub _d {
my ($package, undef, $line) = caller 0;
@_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
Expand Down
84 changes: 26 additions & 58 deletions bin/pt-heartbeat
Original file line number Diff line number Diff line change
Expand Up @@ -460,13 +460,8 @@ sub get_connected_replicas {
sub is_source_of {
my ( $self, $source, $replica ) = @_;

my $replica_version = VersionParser->new($replica);
my $source_name = 'source';
my $source_port = 'source_port';
if ( $replica_version lt '8.1' || $replica_version->flavor() =~ m/maria/ ) {
$source_name = 'master';
$source_port = 'master_port';
}
my $source_name = get_source_name($replica);
my $source_port = "${source_name}_port";

my $source_status = $self->get_source_status($source)
or die "The server specified as a source is not a source";
Expand Down Expand Up @@ -525,11 +520,7 @@ sub get_source_dsn {
sub get_replica_status {
my ( $self, $dbh ) = @_;

my $server_version = VersionParser->new($dbh);
my $replica_name = 'replica';
if ( $server_version lt '8.1' || $server_version->flavor() =~ m/maria/ ) {
$replica_name = 'slave';
}
my $replica_name = get_replica_name($dbh);

if ( !$self->{not_a_replica}->{$dbh} ) {
my $sth = $self->{sths}->{$dbh}->{REPLICA_STATUS}
Expand Down Expand Up @@ -640,11 +631,8 @@ sub wait_for_source {
error =>'Wait for source: this is a multi-source replica but "channel" was not specified on the command line',
};
}
my $source_name = get_source_name($replica_dbh);
my $vp = VersionParser->new($replica_dbh);
my $source_name = 'source';
if ( $vp lt '8.1' || $vp->flavor() =~ m/maria/ ) {
$source_name = 'master';
}
my $channel_sql = $vp > '5.6' && $self->{channel} ? ", '$self->{channel}'" : '';
my $sql = "SELECT ${source_name}_POS_WAIT('$source_status->{file}', $source_status->{position}, $timeout $channel_sql)";
PTDEBUG && _d($replica_dbh, $sql);
Expand All @@ -668,11 +656,8 @@ sub wait_for_source {

sub stop_replica {
my ( $self, $dbh ) = @_;
my $vp = VersionParser->new($dbh);
my $replica_name = 'replica';
if ( $vp lt '8.1' || $vp->flavor() =~ m/maria/ ) {
$replica_name = 'slave';
}
my $replica_name = get_replica_name($dbh);

my $sth = $self->{sths}->{$dbh}->{STOP_REPLICA}
||= $dbh->prepare("STOP ${replica_name}");
PTDEBUG && _d($dbh, $sth->{Statement});
Expand All @@ -682,13 +667,8 @@ sub stop_replica {
sub start_replica {
my ( $self, $dbh, $pos ) = @_;

my $vp = VersionParser->new($dbh);
my $source_name = 'source';
my $replica_name = 'replica';
if ( $vp lt '8.1' || $vp->flavor() =~ m/maria/ ) {
$source_name = 'master';
$replica_name = 'slave';
}
my $source_name = get_source_name($dbh);
my $replica_name = get_replica_name($dbh);

if ( $pos ) {
my $sql = "START ${replica_name} UNTIL ${source_name}_LOG_FILE='$pos->{file}', "
Expand Down Expand Up @@ -732,11 +712,7 @@ sub catchup_to_source {
if ( !defined $result->{result} ) {
$replica_status = $self->get_replica_status($replica);

my $vp = VersionParser->new($replica);
my $replica_name = 'replica';
if ( $vp lt '8.1' || $vp->flavor() =~ m/maria/ ) {
$replica_name = 'slave';
}
my $replica_name = get_replica_name($replica);

if ( !$self->replica_is_running($replica_status, $replica_name) ) {
PTDEBUG && _d('Source position:',
Expand Down Expand Up @@ -781,17 +757,9 @@ sub catchup_to_same_pos {
$s1_pos = $self->repl_posn($s1_status);
$s2_pos = $self->repl_posn($s2_status);

my $vp1 = VersionParser->new($s1_dbh);
my $replica1_name = 'replica';
if ( $vp1 lt '8.1' || $vp1->flavor() =~ m/maria/ ) {
$replica1_name = 'slave';
}
my $replica1_name = get_replica_name($s1_dbh);

my $vp2 = VersionParser->new($s2_dbh);
my $replica2_name = 'replica';
if ( $vp2 lt '8.1' || $vp2->flavor() =~ m/maria/ ) {
$replica2_name = 'slave';
}
my $replica2_name = get_replica_name($s2_dbh);

if ( $self->replica_is_running($s1_status, $replica1_name)
|| $self->replica_is_running($s2_status, $replica2_name)
Expand All @@ -810,11 +778,7 @@ sub replica_is_running {
sub has_replica_updates {
my ( $self, $dbh ) = @_;

my $vp = VersionParser->new($dbh);
my $replica_name = 'replica';
if ( $vp lt '8.1' || $vp->flavor() =~ m/maria/ ) {
$replica_name = 'slave';
}
my $replica_name = get_replica_name($dbh);

my $sql = qq{SHOW VARIABLES LIKE 'log_${replica_name}_updates'};
PTDEBUG && _d($dbh, $sql);
Expand Down Expand Up @@ -847,11 +811,7 @@ sub repl_posn {
sub get_replica_lag {
my ( $self, $dbh ) = @_;

my $vp = VersionParser->new($dbh);
my $source_name = 'source';
if ( $vp lt '8.1' || $vp->flavor() =~ m/maria/ ) {
$source_name = 'master';
}
my $source_name = get_source_name($dbh);

my $stat = $self->get_replica_status($dbh);
return unless $stat; # server is not a replica
Expand Down Expand Up @@ -951,11 +911,7 @@ sub get_replication_filters {
}
my ($dbh) = @args{@required_args};

my $vp = VersionParser->new($dbh);
my $replica_name = 'replica';
if ( $vp lt '8.1' || $vp->flavor() =~ m/maria/ ) {
$replica_name = 'slave';
}
my $replica_name = get_replica_name($dbh);

my %filters = ();

Expand Down Expand Up @@ -1065,6 +1021,18 @@ sub get_cxn_from_dsn_table {
return \@cxn;
}

sub get_source_name {
my ($dbh) = @_;
my $vp = VersionParser->new($dbh);
return ($vp lt '8.1' || $vp->flavor() =~ m/maria/) ? 'master' : 'source';
}

sub get_replica_name {
my ($dbh) = @_;
my $vp = VersionParser->new($dbh);
return ($vp lt '8.1' || $vp->flavor() =~ m/maria/) ? 'slave' : 'replica';
}

sub _d {
my ($package, undef, $line) = caller 0;
@_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
Expand Down
Loading

0 comments on commit bb66ab0

Please sign in to comment.