summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/include/test_fieldsize.inc2
-rw-r--r--mysql-test/suite/rpl/r/rpl_show_slave_running.result42
-rw-r--r--mysql-test/suite/rpl/t/rpl_show_slave_running.test76
-rw-r--r--sql/mysqld.cc3
-rw-r--r--sql/slave.cc1
5 files changed, 122 insertions, 2 deletions
diff --git a/mysql-test/include/test_fieldsize.inc b/mysql-test/include/test_fieldsize.inc
index cbe63e26318..606bc63779d 100644
--- a/mysql-test/include/test_fieldsize.inc
+++ b/mysql-test/include/test_fieldsize.inc
@@ -22,7 +22,7 @@ eval $test_insert;
connection slave;
START SLAVE;
-wait_for_slave_to_stop;
+--source include/wait_for_slave_sql_to_stop.inc
--replace_result $MASTER_MYPORT MASTER_PORT
--replace_column 1 # 4 # 7 # 8 # 9 # 16 # 22 # 23 # 33 # 35 # 36 #
--query_vertical SHOW SLAVE STATUS
diff --git a/mysql-test/suite/rpl/r/rpl_show_slave_running.result b/mysql-test/suite/rpl/r/rpl_show_slave_running.result
new file mode 100644
index 00000000000..d8450607185
--- /dev/null
+++ b/mysql-test/suite/rpl/r/rpl_show_slave_running.result
@@ -0,0 +1,42 @@
+stop slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+reset master;
+reset slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+start slave;
+include/stop_slave.inc
+SELECT GET_LOCK("debug_lock.before_get_running_status_yes", 1000);
+GET_LOCK("debug_lock.before_get_running_status_yes", 1000)
+1
+set global debug= 'd,debug_lock.before_get_running_status_yes';
+Slave_running, Slave_IO_Running, Slave_SQL_Running, must be OFF, NO, NO in three following queries
+SHOW STATUS LIKE 'Slave_running';
+Variable_name Value
+Slave_running OFF
+Slave_IO_Running= No
+Slave_IO_Running= No
+start slave io_thread;
+Slave_running, Slave_IO_Running, Slave_SQL_Running must be OFF NO NO in three following queries
+SHOW STATUS LIKE 'Slave_running';
+Variable_name Value
+Slave_running OFF
+Slave_IO_Running= No
+Slave_IO_Running= No
+SELECT RELEASE_LOCK("debug_lock.before_get_running_status_yes");
+RELEASE_LOCK("debug_lock.before_get_running_status_yes")
+1
+Slave_running, Slave_IO_Running, Slave_SQL_Running must be OFF YES NO in three following queries
+SHOW STATUS LIKE 'Slave_running';
+Variable_name Value
+Slave_running OFF
+Slave_IO_Running= Yes
+Slave_IO_Running= No
+start slave sql_thread;
+Slave_running, Slave_IO_Running, Slave_SQL_Running must be ON, YES, YES in three following queries
+SHOW STATUS LIKE 'Slave_running';
+Variable_name Value
+Slave_running ON
+Slave_IO_Running= Yes
+Slave_IO_Running= Yes
+set global debug= '';
+End of tests
diff --git a/mysql-test/suite/rpl/t/rpl_show_slave_running.test b/mysql-test/suite/rpl/t/rpl_show_slave_running.test
new file mode 100644
index 00000000000..9dc93ed7056
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_show_slave_running.test
@@ -0,0 +1,76 @@
+#
+# Bug #30703 SHOW STATUS LIKE 'Slave_running' is not compatible with `SHOW SLAVE STATUS'
+# The test verifies that SHOW STATUS LIKE 'Slave_running' displays ON
+# if and only if `SHOW SLAVE STATUS' displays YES for Slave_IO_Running and Slave_SQL_Running
+#
+source include/master-slave.inc;
+source include/have_debug.inc;
+
+connection slave;
+
+source include/stop_slave.inc;
+let $debug_saved= `select @@global.debug`;
+let $debug_lock= "debug_lock.before_get_running_status_yes";
+eval SELECT GET_LOCK($debug_lock, 1000);
+set global debug= 'd,debug_lock.before_get_running_status_yes';
+
+# Test 1. Slave is stopped
+
+--echo Slave_running, Slave_IO_Running, Slave_SQL_Running, must be OFF, NO, NO in three following queries
+
+SHOW STATUS LIKE 'Slave_running';
+let $status= query_get_value("show slave status", Slave_IO_Running, 1);
+echo Slave_IO_Running= $status;
+let $status= query_get_value("show slave status", Slave_SQL_Running, 1);
+echo Slave_IO_Running= $status;
+
+# Test 2. The slave IO thread is started but not yet got connected to master
+# and SQL thread is not started
+
+start slave io_thread;
+
+--echo Slave_running, Slave_IO_Running, Slave_SQL_Running must be OFF NO NO in three following queries
+
+SHOW STATUS LIKE 'Slave_running';
+let $status= query_get_value("show slave status", Slave_IO_Running, 1);
+echo Slave_IO_Running= $status;
+let $status= query_get_value("show slave status", Slave_SQL_Running, 1);
+echo Slave_IO_Running= $status;
+
+# Test 3. The slave IO thread is started and got connected to master
+# and SQL thread is still not started
+
+eval SELECT RELEASE_LOCK($debug_lock);
+let $slave_param= Slave_IO_Running;
+let $slave_param_value= YES;
+source include/wait_for_slave_param.inc;
+
+--echo Slave_running, Slave_IO_Running, Slave_SQL_Running must be OFF YES NO in three following queries
+
+SHOW STATUS LIKE 'Slave_running';
+let $status= query_get_value("show slave status", Slave_IO_Running, 1);
+echo Slave_IO_Running= $status;
+let $status= query_get_value("show slave status", Slave_SQL_Running, 1);
+echo Slave_IO_Running= $status;
+
+# Test 4. The slave IO thread is started and got connected to master
+# and SQL thread is started
+
+start slave sql_thread;
+source include/wait_for_slave_sql_to_start.inc;
+
+--echo Slave_running, Slave_IO_Running, Slave_SQL_Running must be ON, YES, YES in three following queries
+
+SHOW STATUS LIKE 'Slave_running';
+let $status= query_get_value("show slave status", Slave_IO_Running, 1);
+echo Slave_IO_Running= $status;
+let $status= query_get_value("show slave status", Slave_SQL_Running, 1);
+echo Slave_IO_Running= $status;
+
+# cleanup
+
+connection slave;
+
+eval set global debug= '$debug_saved';
+
+--echo End of tests
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index a483b9e2381..c4f459d9581 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -7162,7 +7162,8 @@ static int show_slave_running(THD *thd, SHOW_VAR *var, char *buff)
var->type= SHOW_MY_BOOL;
pthread_mutex_lock(&LOCK_active_mi);
var->value= buff;
- *((my_bool *)buff)= (my_bool) (active_mi && active_mi->slave_running &&
+ *((my_bool *)buff)= (my_bool) (active_mi &&
+ active_mi->slave_running == MYSQL_SLAVE_RUN_CONNECT &&
active_mi->rli.slave_running);
pthread_mutex_unlock(&LOCK_active_mi);
return 0;
diff --git a/sql/slave.cc b/sql/slave.cc
index 271b3635cf1..a89ac2e682b 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -2557,6 +2557,7 @@ pthread_handler_t handle_slave_io(void *arg)
connected:
+ DBUG_SYNC_POINT("debug_lock.before_get_running_status_yes", 10);
// TODO: the assignment below should be under mutex (5.0)
mi->slave_running= MYSQL_SLAVE_RUN_CONNECT;
thd->slave_net = &mysql->net;