MasterFailover.pm
1473 $ret =
1474 $_server_manager->change_master_and_start_slave( $target, $latest_slave,
1475 undef, undef, $log );
===========================
vim ServerManager.pm
-------------------------
sub change_master_and_start_slave {
my ( $self, $target, $master, $master_log_file, $master_log_pos, $log ) = @_;
$log = $self->{logger} unless ($log);
return if ( $target->{id} eq $master->{id} );
my $dbhelper = $target->{dbhelper};
$log->info(
sprintf(
" Resetting slave %s and starting replication from the new master %s..",
$target->get_hostinfo(),
$master->get_hostinfo()
)
);
$target->stop_slave($log) unless ( $target->{not_slave} );
$dbhelper->reset_slave() unless ( $target->{not_slave} );
my $addr =
$target->{use_ip_for_change_master}
? $master->{ip}
: $master->{hostname};
if ( $self->is_gtid_auto_pos_enabled() && !$target->{is_mariadb} ) {
$dbhelper->change_master_gtid( $addr, $master->{port},
$master->{repl_user}, $master->{repl_password} );
}
else {
$dbhelper->change_master( $addr,
$master->{port}, $master_log_file, $master_log_pos, $master->{repl_user},
$master->{repl_password} );
}
$log->info(" Executed CHANGE MASTER.");
# After executing CHANGE MASTER, relay_log_purge is automatically disabled.
# If the original value is 0, we should turn to 0 explicitly.
if ( !$target->{has_gtid} ) {
unless ( $target->{relay_purge} ) {
$target->disable_relay_log_purge();
}
}
my $ret = $target->start_slave($log);
unless ($ret) {
$log->info(" Slave started.");
}
return $ret;
}