Commit dd13db6f authored by Michael Widenius's avatar Michael Widenius

MDEV-5829: STOP SLAVE resets global status variables

Reason for the bug was an optimization for higher connect speed where we moved when global status was updated,
but forgot to update states when slave thread dies.
Fixed by adding thd->add_status_to_global() before deleting slave thread's thd.


mysys/my_delete.c:
  Added missing newline
sql/mysqld.cc:
  Use add_status_to_global()
sql/slave.cc:
  Added missing add_status_to_global()
sql/sql_class.cc:
  Use add_status_to_global()
sql/sql_class.h:
  Simplify adding local status to global by adding add_status_to_global()
parent bde11c1a
......@@ -2,7 +2,13 @@ include/master-slave.inc
[connection master]
create table t1 (n int);
insert into t1 values(1);
show global status like 'com_insert';
Variable_name Value
Com_insert 1
stop slave;
show global status like 'com_insert';
Variable_name Value
Com_insert 1
include/wait_for_slave_to_stop.inc
start slave;
include/wait_for_slave_to_start.inc
......
#
# Test very simply slave replication (to ensure it works at all)
# In addition, test also:
# MDEV-5829 STOP SLAVE resets global status variables
#
source include/master-slave.inc;
create table t1 (n int);
insert into t1 values(1);
sync_slave_with_master;
show global status like 'com_insert';
stop slave;
show global status like 'com_insert';
--source include/wait_for_slave_to_stop.inc
start slave;
--source include/wait_for_slave_to_start.inc
......
......@@ -150,4 +150,4 @@ static int my_win_unlink(const char *name)
my_osmaperr(last_error);
DBUG_RETURN(-1);
}
#endif
\ No newline at end of file
#endif
......@@ -2483,9 +2483,7 @@ void unlink_thd(THD *thd)
thd_cleanup(thd);
dec_connection_count(thd);
mysql_mutex_lock(&LOCK_status);
add_to_status(&global_status_var, &thd->status_var);
mysql_mutex_unlock(&LOCK_status);
thd->add_status_to_global();
mysql_mutex_lock(&LOCK_thread_count);
thread_count--;
......
......@@ -3356,6 +3356,7 @@ log space");
}
write_ignored_events_info_to_relay_log(thd, mi);
thd_proc_info(thd, "Waiting for slave mutex on exit");
thd->add_status_to_global();
mysql_mutex_lock(&mi->run_lock);
err_during_init:
......@@ -3746,6 +3747,7 @@ the slave SQL thread with \"SLAVE START\". We stopped at log \
thd->catalog= 0;
thd->reset_query();
thd->reset_db(NULL, 0);
thd->add_status_to_global();
thd_proc_info(thd, "Waiting for slave mutex on exit");
mysql_mutex_lock(&rli->run_lock);
err_during_init:
......
......@@ -1360,9 +1360,7 @@ void THD::init_for_queries()
void THD::change_user(void)
{
mysql_mutex_lock(&LOCK_status);
add_to_status(&global_status_var, &status_var);
mysql_mutex_unlock(&LOCK_status);
add_status_to_global();
cleanup();
reset_killed();
......
......@@ -695,6 +695,11 @@ typedef struct system_status_var
#define last_system_status_var questions
void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var);
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
STATUS_VAR *dec_var);
void mark_transaction_to_rollback(THD *thd, bool all);
#ifdef MYSQL_SERVER
......@@ -3103,6 +3108,14 @@ class THD :public Statement,
void wait_for_wakeup_ready();
/* Wake this thread up from wait_for_wakeup_ready(). */
void signal_wakeup_ready();
void add_status_to_global()
{
mysql_mutex_lock(&LOCK_status);
add_to_status(&global_status_var, &status_var);
mysql_mutex_unlock(&LOCK_status);
}
private:
/** The current internal error handler for this thread, or NULL. */
......@@ -4145,10 +4158,6 @@ class select_dumpvar :public select_result_interceptor {
*/
#define CF_SKIP_QUESTIONS (1U << 1)
void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var);
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
STATUS_VAR *dec_var);
void mark_transaction_to_rollback(THD *thd, bool all);
/* Inline functions */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment