#At file:///home/lsoares/Workspace/bzr/work/bugfixing/58324/mysql-trunk-bugfixing/ based on revid:mattias.jonsson@stripped
3410 Luis Soares 2010-12-03
BUG#58324: Slave I/O thread still retries to connect master after
verifying user ID fails.
The slave would try to reconnect to the master, even when
facing FATAL connection errors.
The fix is to make the IO thread only to attempt reconnections
on potentially transient network errors.
@ sql/rpl_slave.cc
Apart from the fix, added error injection hooks to be used
from within the test case.
modified:
mysql-test/suite/rpl/r/rpl_change_master_dbug.result
mysql-test/suite/rpl/t/rpl_change_master_dbug.test
sql/rpl_slave.cc
=== modified file 'mysql-test/suite/rpl/r/rpl_change_master_dbug.result'
--- a/mysql-test/suite/rpl/r/rpl_change_master_dbug.result 2010-09-26 23:56:20 +0000
+++ b/mysql-test/suite/rpl/r/rpl_change_master_dbug.result 2010-12-03 15:52:30 +0000
@@ -4,9 +4,17 @@ reset master;
reset slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
start slave;
+SET @old_debug= @@global.debug;
include/stop_slave.inc
-CHANGE MASTER TO master_retry_count=3, master_host='dummy', master_connect_retry=1;
+CHANGE MASTER TO master_user='fake';
START SLAVE io_thread;
+SET GLOBAL DEBUG="+d,inject_io_thd_network_error";
+Warnings:
+Note 1255 Slave already has been stopped
+include/stop_slave.inc
+CHANGE MASTER TO master_host='127.0.0.1', master_retry_count=3, master_connect_retry=1;
+START SLAVE io_thread;
+SET GLOBAL DEBUG=@old_debug;
stop slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
reset master;
=== modified file 'mysql-test/suite/rpl/t/rpl_change_master_dbug.test'
--- a/mysql-test/suite/rpl/t/rpl_change_master_dbug.test 2010-09-26 23:56:20 +0000
+++ b/mysql-test/suite/rpl/t/rpl_change_master_dbug.test 2010-12-03 15:52:30 +0000
@@ -3,7 +3,8 @@
-- source include/have_binlog_format_row.inc
-- source include/have_debug.inc
-#
+SET @old_debug= @@global.debug;
+
# BUG#44209: MASTER_CONNECT_RETRY and --master-retry-count disconnected from each other
#
# BUG#56416
@@ -12,18 +13,38 @@
#
## Checks that the slave actually gives up after retrying N times, where
-## N was set with CHANGE MASTER TO master_retry_count=N
+## N was set with CHANGE MASTER TO master_retry_count=N, or just retries
+## once, ie, when it faces a FATAL error (not potentially network error)
+
+# We wait for slave to stop and inspect the number of retries in
+# the error message. We should get 1 retry - the IO thread gives
+# up when it faces a FATAL error.
-- connection slave
-- source include/stop_slave.inc
-CHANGE MASTER TO master_retry_count=3, master_host='dummy', master_connect_retry=1;
+CHANGE MASTER TO master_user='fake';
START SLAVE io_thread;
+-- source include/wait_for_slave_io_to_stop.inc
+-- let $error= query_get_value("SHOW SLAVE STATUS", Last_IO_Error, 1)
+if (!`SELECT "$error" LIKE "%retries: 1"`)
+{
+ -- echo Unexpected retry count value! Got: $error
+ -- echo Expected number of retries was: 1
+ -- die
+}
+
# We wait for slave to stop and inspect the number of retries in
-# the error message. Given that we force the slave to always report
-# the error with the err_count exported in the retries field, we should
-# get 3 retries (one per second) when the IO thread gives up, ie,
-# when it stops.
+# the error message. We should get 3 retries (one per second)
+# when the IO thread gives up, ie, when it stops.
+
+-- connection slave
+SET GLOBAL DEBUG="+d,inject_io_thd_network_error";
+
+-- source include/stop_slave.inc
+CHANGE MASTER TO master_host='127.0.0.1', master_retry_count=3, master_connect_retry=1;
+START SLAVE io_thread;
+
-- source include/wait_for_slave_io_to_stop.inc
-- let $error= query_get_value("SHOW SLAVE STATUS", Last_IO_Error, 1)
if (!`SELECT "$error" LIKE "%retries: 3"`)
@@ -33,5 +54,7 @@ if (!`SELECT "$error" LIKE "%retries: 3"
-- die
}
+SET GLOBAL DEBUG=@old_debug;
+
-- source include/master-slave-reset.inc
-- source include/master-slave-end.inc
=== modified file 'sql/rpl_slave.cc'
--- a/sql/rpl_slave.cc 2010-11-29 18:35:56 +0000
+++ b/sql/rpl_slave.cc 2010-12-03 15:52:30 +0000
@@ -4786,17 +4786,20 @@ static int connect_to_master(THD* thd, M
/* This one is not strictly needed but we have it here for completeness */
mysql_options(mysql, MYSQL_SET_CHARSET_DIR, (char *) charsets_dir);
- while (!(slave_was_killed = io_slave_killed(thd,mi)) &&
+ while ((!(slave_was_killed = io_slave_killed(thd,mi)) &&
(reconnect ? mysql_reconnect(mysql) != 0 :
mysql_real_connect(mysql, mi->host, mi->user, mi->password, 0,
- mi->port, 0, client_flag) == 0))
+ mi->port, 0, client_flag) == 0)) ||
+ DBUG_EVALUATE_IF("inject_io_thd_network_error", TRUE, FALSE))
{
/*
SHOW SLAVE STATUS will display the number of retries which
would be real retry counts instead of mi->retry_count for
each connection attempt by 'Last_IO_Error' entry.
*/
- last_errno=mysql_errno(mysql);
+ last_errno=DBUG_EVALUATE_IF("inject_io_thd_network_error",
+ CR_CONNECTION_ERROR,
+ mysql_errno(mysql));
suppress_warnings= 0;
mi->report(ERROR_LEVEL, last_errno,
"error %s to master '%s@%s:%d'"
@@ -4810,7 +4813,7 @@ static int connect_to_master(THD* thd, M
do not want to have election triggered on the first failure to
connect
*/
- if (++err_count == mi->retry_count)
+ if ((++err_count == mi->retry_count) || !is_network_error(last_errno))
{
slave_was_killed=1;
break;
Attachment: [text/bzr-bundle] bzr/luis.soares@oracle.com-20101203155230-phy6byd9ukgc5spy.bundle