Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix DBI:mysql connection error #124

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/MHA/DBHelper.pm
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,12 @@ sub connect_util {
my $port = shift;
my $user = shift;
my $password = shift;
<<<<<<< HEAD
my $dsn = "DBI:mysql:;host=$host;port=$port;mysql_connect_timeout=1";
=======
my $dsn_host = $host =~ m{:} ? '[' . $host . ']' : $host;
my $dsn = "DBI:mysql:;host=$dsn_host;port=$port;mysql_connect_timeout=1";
>>>>>>> upstream/master
my $dbh = DBI->connect( $dsn, $user, $password, { PrintError => 0 } );
return $dbh;
}
Expand Down Expand Up @@ -196,8 +200,12 @@ sub connect {

$self->{dbh} = undef;
unless ( $self->{dsn} ) {
<<<<<<< HEAD
$self->{dsn} = "DBI:mysql:;host=$host;port=$port;mysql_connect_timeout=4";
=======
my $dsn_host = $host =~ m{:} ? '[' . $host . ']' : $host;
$self->{dsn} = "DBI:mysql:;host=$dsn_host;port=$port;mysql_connect_timeout=4";
>>>>>>> upstream/master
}
my $defaults = {
PrintError => 0,
Expand Down
4 changes: 4 additions & 0 deletions lib/MHA/HealthCheck.pm
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ sub connect {
my $log = $self->{logger};
my $dsn_host = $self->{ip} =~ m{:} ? '[' . $self->{ip} . ']' : $self->{ip};
$self->{dbh} = DBI->connect(
<<<<<<< HEAD
"DBI:mysql:;host=$self->{ip};"
=======
"DBI:mysql:;host=$dsn_host;"
>>>>>>> upstream/master
. "port=$self->{port};mysql_connect_timeout=$connect_timeout",
$self->{user},
$self->{password},
Expand Down
20 changes: 15 additions & 5 deletions lib/MHA/MasterFailover.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1418,8 +1418,15 @@ sub recover_slave {
sub apply_binlog_to_master($) {
my $target = shift;
my $err_file = "$g_workdir/mysql_from_binlog.err";
#在GTID模式下只能是少丢,原失处理的GTID日志重放会报错
if ($is_gtid_auto_pos_enabled){
my $command =
"cat $_diff_binary_log | mysql --binary-mode --user=$target->{mysql_escaped_user} --password=$target->{mysql_escaped_password} --host=$target->{ip} --port=$target->{port} -vvv --unbuffered > $err_file 2>&1";
"mysqlbinlog $_diff_binary_log | mysql -f --binary-mode --user=$target->{mysql_escaped_user} --password=$target->{mysql_escaped_password} --host=$target->{ip} --port=$target->{port} -vvv --unbuffered > $err_file 2>&1";
}else{
my $command =
"cat $_diff_binary_log | mysql --binary-mode --user=$target->{mysql_escaped_user} --password=$target->{mysql_escaped_password} --host=$target->{ip} --port=$target->{port} -vvv --unbuffered > $err_file 2>&1";
}


$log->info("Checking if super_read_only is defined and turned on..");
my ($super_read_only_enabled, $dbh) =
Expand Down Expand Up @@ -1512,7 +1519,10 @@ sub recover_master_gtid_internal($$$) {
$relay_master_log_file = $target->{Relay_Master_Log_File};
$exec_master_log_pos = $target->{Exec_Master_Log_Pos};
}
if (
#first use master binlog to recover new master
if ($_has_saved_binlog){
apply_binlog_to_master($target);
}elsif(
save_from_binlog_server(
$relay_master_log_file, $exec_master_log_pos, $binlog_server_ref
)
Expand Down Expand Up @@ -2127,13 +2137,13 @@ sub do_master_failover {
$log->info("* Phase 3.1: Getting Latest Slaves Phase..\n");
$log->info();
check_set_latest_slaves();

if ( !$_server_manager->is_gtid_auto_pos_enabled() ) {
#gtid mode maybe save binlog from master add [email protected]
# if ( !$_server_manager->is_gtid_auto_pos_enabled() ) {
$log->info();
$log->info("* Phase 3.2: Saving Dead Master's Binlog Phase..\n");
$log->info();
save_master_binlog($dead_master);
}
# }

$log->info();
$log->info("* Phase 3.3: Determining New Master Phase..\n");
Expand Down