diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index b8e72f398f188..869c25b46d375 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -305,7 +305,7 @@ is_partition( /** Signal to shut down InnoDB (NULL if shutdown was signaled, or if running in innodb_read_only mode, srv_read_only_mode) */ -volatile st_my_thread_var *srv_running; +st_my_thread_var *srv_running; /** Service thread that waits for the server shutdown and stops purge threads. Purge workers have THDs that are needed to calculate virtual columns. This THDs must be destroyed rather early in the server shutdown sequence. @@ -332,12 +332,16 @@ thd_destructor_proxy(void *) myvar->current_cond = &thd_destructor_cond; mysql_mutex_lock(&thd_destructor_mutex); - srv_running = myvar; + my_atomic_storeptr_explicit(&srv_running, myvar, + MY_MEMORY_ORDER_RELAXED); /* wait until the server wakes the THD to abort and die */ - while (!srv_running->abort) + while (!my_atomic_loadptr_explicit(&srv_running, + MY_MEMORY_ORDER_RELAXED) + ->abort) mysql_cond_wait(&thd_destructor_cond, &thd_destructor_mutex); mysql_mutex_unlock(&thd_destructor_mutex); - srv_running = NULL; + my_atomic_storeptr_explicit(&srv_running, NULL, + MY_MEMORY_ORDER_RELAXED); while (srv_fast_shutdown == 0 && (trx_sys_any_active_transactions() || @@ -4333,7 +4337,8 @@ innobase_init( mysql_thread_create(thd_destructor_thread_key, &thd_destructor_thread, NULL, thd_destructor_proxy, NULL); - while (!srv_running) + while (!my_atomic_loadptr_explicit(&srv_running, + MY_MEMORY_ORDER_RELAXED)) os_thread_sleep(20); } @@ -4427,10 +4432,12 @@ innobase_end(handlerton*, ha_panic_function) hash_table_free(innobase_open_tables); innobase_open_tables = NULL; - if (!abort_loop && srv_running) { + st_my_thread_var* running = my_atomic_loadptr_explicit( + &srv_running, MY_MEMORY_ORDER_RELAXED); + if (!abort_loop && running) { // may be UNINSTALL PLUGIN statement - srv_running->abort = 1; - mysql_cond_broadcast(srv_running->current_cond); + running->abort = 1; + mysql_cond_broadcast(running->current_cond); } if (!srv_read_only_mode) { @@ -17764,7 +17771,9 @@ fast_shutdown_validate( uint new_val = *reinterpret_cast(save); - if (srv_fast_shutdown && !new_val && !srv_running) { + if (srv_fast_shutdown && !new_val + && !my_atomic_loadptr_explicit(&srv_running, + MY_MEMORY_ORDER_RELAXED)) { return(1); } diff --git a/storage/innobase/include/ib0mutex.h b/storage/innobase/include/ib0mutex.h index 76f02cc152115..afa8f295e1c8b 100644 --- a/storage/innobase/include/ib0mutex.h +++ b/storage/innobase/include/ib0mutex.h @@ -527,7 +527,8 @@ struct TTASEventMutex { int32 state() const UNIV_NOTHROW { - return(m_lock_word); + return(my_atomic_load32_explicit(&m_lock_word, + MY_MEMORY_ORDER_RELAXED)); } /** The event that the mutex will wait in sync0arr.cc diff --git a/storage/innobase/include/srv0srv.h b/storage/innobase/include/srv0srv.h index e24aa89f046e0..9ba65d8097ea8 100644 --- a/storage/innobase/include/srv0srv.h +++ b/storage/innobase/include/srv0srv.h @@ -476,7 +476,7 @@ extern uint srv_fast_shutdown; /*!< If this is 1, do not do a /** Signal to shut down InnoDB (NULL if shutdown was signaled, or if running in innodb_read_only mode, srv_read_only_mode) */ -extern volatile st_my_thread_var *srv_running; +extern st_my_thread_var *srv_running; extern ibool srv_innodb_status; diff --git a/storage/innobase/srv/srv0srv.cc b/storage/innobase/srv/srv0srv.cc index 90196516651ce..9050061d56c30 100644 --- a/storage/innobase/srv/srv0srv.cc +++ b/storage/innobase/srv/srv0srv.cc @@ -1170,7 +1170,16 @@ srv_refresh_innodb_monitor_stats(void) { mutex_enter(&srv_innodb_monitor_mutex); - srv_last_monitor_time = time(NULL); + time_t current_time = time(NULL); + + if (difftime(current_time, srv_last_monitor_time) > 60) { + /* We referesh InnoDB Monitor values so that averages are + printed from at most 60 last seconds */ + mutex_exit(&srv_innodb_monitor_mutex); + return; + } + + srv_last_monitor_time = current_time; os_aio_refresh_stats(); @@ -1792,6 +1801,8 @@ DECLARE_THREAD(srv_monitor_thread)(void*) } } + srv_refresh_innodb_monitor_stats(); + if (srv_shutdown_state != SRV_SHUTDOWN_NONE) { goto exit_func; } @@ -1863,13 +1874,6 @@ DECLARE_THREAD(srv_error_monitor_thread)(void*) old_lsn = new_lsn; } - if (difftime(time(NULL), srv_last_monitor_time) > 60) { - /* We referesh InnoDB Monitor values so that averages are - printed from at most 60 last seconds */ - - srv_refresh_innodb_monitor_stats(); - } - /* Update the statistics collected for deciding LRU eviction policy. */ buf_LRU_stat_update(); @@ -2938,7 +2942,8 @@ srv_purge_wakeup() srv_release_threads(SRV_WORKER, n_workers); } - } while (!srv_running + } while (!my_atomic_loadptr_explicit(&srv_running, + MY_MEMORY_ORDER_RELAXED) && (srv_sys.n_threads_active[SRV_WORKER] || srv_sys.n_threads_active[SRV_PURGE])); } diff --git a/storage/innobase/srv/srv0start.cc b/storage/innobase/srv/srv0start.cc index 8c2d0dc8871b0..424b45e8def9a 100644 --- a/storage/innobase/srv/srv0start.cc +++ b/storage/innobase/srv/srv0start.cc @@ -2840,7 +2840,8 @@ srv_shutdown_bg_undo_sources() void innodb_shutdown() { - ut_ad(!srv_running); + ut_ad(!my_atomic_loadptr_explicit(&srv_running, + MY_MEMORY_ORDER_RELAXED)); ut_ad(!srv_undo_sources); switch (srv_operation) {