Browse Source

Moved server_threads.erase(thd) to end of handle_slave_sql()

The effect is that 'show processlist' will show the Slave SQL thread
until the thread ends. This may help finding cases where the Slave SQL
thread could hang for some time during the cleanup part.

The Slave SQL thread will have the state "Slave SQL thread ending' during
this stage.

Reviewed-by: Kristian Nielsen <knielsen@knielsen-hq.org>
bb-10.6-mdev-36221
Monty 8 months ago
parent
commit
1331c73243
  1. 2
      sql/mysqld.cc
  2. 1
      sql/mysqld.h
  3. 6
      sql/slave.cc

2
sql/mysqld.cc

@ -9209,6 +9209,7 @@ PSI_stage_info stage_preparing= { 0, "Preparing", 0};
PSI_stage_info stage_purging_old_relay_logs= { 0, "Purging old relay logs", 0};
PSI_stage_info stage_query_end= { 0, "Query end", 0};
PSI_stage_info stage_starting_cleanup= { 0, "Starting cleanup", 0};
PSI_stage_info stage_slave_sql_cleanup= { 0, "Slave SQL thread ending", 0};
PSI_stage_info stage_rollback= { 0, "Rollback", 0};
PSI_stage_info stage_rollback_implicit= { 0, "Rollback_implicit", 0};
PSI_stage_info stage_commit= { 0, "Commit", 0};
@ -9442,6 +9443,7 @@ PSI_stage_info *all_server_stages[]=
& stage_preparing,
& stage_purging_old_relay_logs,
& stage_starting_cleanup,
& stage_slave_sql_cleanup,
& stage_query_end,
& stage_queueing_master_event_to_the_relay_log,
& stage_reading_event_from_the_relay_log,

1
sql/mysqld.h

@ -604,6 +604,7 @@ extern PSI_stage_info stage_preparing;
extern PSI_stage_info stage_purging_old_relay_logs;
extern PSI_stage_info stage_query_end;
extern PSI_stage_info stage_starting_cleanup;
extern PSI_stage_info stage_slave_sql_cleanup;
extern PSI_stage_info stage_rollback;
extern PSI_stage_info stage_rollback_implicit;
extern PSI_stage_info stage_commit;

6
sql/slave.cc

@ -5404,6 +5404,7 @@ pthread_handler_t handle_slave_sql(void *arg)
THD *thd; /* needs to be first for thread_stack */
char saved_log_name[FN_REFLEN];
char saved_master_log_name[FN_REFLEN];
bool thd_initialized= 0;
my_off_t UNINIT_VAR(saved_log_pos);
my_off_t UNINIT_VAR(saved_master_log_pos);
String saved_skip_gtid_pos;
@ -5506,6 +5507,7 @@ pthread_handler_t handle_slave_sql(void *arg)
thd->variables.alter_algorithm= (ulong) Alter_info::ALTER_TABLE_ALGORITHM_DEFAULT;
server_threads.insert(thd);
thd_initialized= 1;
/*
We are going to set slave_running to 1. Assuming slave I/O thread is
alive and connected, this is going to make Seconds_Behind_Master be 0
@ -5883,7 +5885,7 @@ pthread_handler_t handle_slave_sql(void *arg)
}
THD_STAGE_INFO(thd, stage_waiting_for_slave_mutex_on_exit);
thd->add_status_to_global();
server_threads.erase(thd);
THD_STAGE_INFO(thd, stage_slave_sql_cleanup);
mysql_mutex_lock(&rli->run_lock);
err_during_init:
@ -5954,6 +5956,8 @@ err_during_init:
rpl_parallel_resize_pool_if_no_slaves();
delete serial_rgi;
if (thd_initialized)
server_threads.erase(thd);
delete thd;
DBUG_LEAVE; // Must match DBUG_ENTER()

Loading…
Cancel
Save