@@ -1982,6 +1982,33 @@ srv_get_active_thread_type(void)
19821982return (ret);
19831983}
19841984
1985+ /* * Wake up the InnoDB master thread if it was suspended (not sleeping). */
1986+ void
1987+ srv_active_wake_master_thread_low ()
1988+ {
1989+ ut_ad (!srv_read_only_mode);
1990+ ut_ad (!srv_sys_mutex_own ());
1991+
1992+ srv_inc_activity_count ();
1993+
1994+ if (my_atomic_loadlint (&srv_sys.n_threads_active [SRV_MASTER]) == 0 ) {
1995+ srv_slot_t * slot;
1996+
1997+ srv_sys_mutex_enter ();
1998+
1999+ slot = &srv_sys.sys_threads [SRV_MASTER_SLOT];
2000+
2001+ /* Only if the master thread has been started. */
2002+
2003+ if (slot->in_use ) {
2004+ ut_a (srv_slot_get_type (slot) == SRV_MASTER);
2005+ os_event_set (slot->event );
2006+ }
2007+
2008+ srv_sys_mutex_exit ();
2009+ }
2010+ }
2011+
19852012/* * Wake up the purge threads if there is work to do. */
19862013void
19872014srv_wake_purge_thread_if_not_active ()
@@ -1996,6 +2023,14 @@ srv_wake_purge_thread_if_not_active()
19962023}
19972024}
19982025
2026+ /* * Wake up the master thread if it is suspended or being suspended. */
2027+ void
2028+ srv_wake_master_thread ()
2029+ {
2030+ srv_inc_activity_count ();
2031+ srv_release_threads (SRV_MASTER, 1 );
2032+ }
2033+
19992034/* ******************************************************************/ /* *
20002035Get current server activity count. We don't hold srv_sys::mutex while
20012036reading this value as it is only used in heuristics.
@@ -2007,20 +2042,15 @@ srv_get_activity_count(void)
20072042return (srv_sys.activity_count );
20082043}
20092044
2010- /* * Check if there has been any activity.
2011- @param[in,out] activity_count recent activity count to be returned
2012- if there is a change
2045+ /* ******************************************************************/ /* *
2046+ Check if there has been any activity.
20132047@return FALSE if no change in activity counter. */
2014- bool srv_check_activity (ulint *activity_count)
2048+ ibool
2049+ srv_check_activity (
2050+ /* ===============*/
2051+ ulint old_activity_count)/* !< in: old activity count */
20152052{
2016- ulint new_activity_count= srv_sys.activity_count ;
2017- if (new_activity_count != *activity_count)
2018- {
2019- *activity_count= new_activity_count;
2020- return true ;
2021- }
2022-
2023- return false ;
2053+ return (srv_sys.activity_count != old_activity_count);
20242054}
20252055
20262056/* *******************************************************************/ /* *
@@ -2427,30 +2457,52 @@ DECLARE_THREAD(srv_master_thread)(
24272457slot = srv_reserve_slot (SRV_MASTER);
24282458ut_a (slot == srv_sys.sys_threads );
24292459
2460+ loop:
24302461while (srv_shutdown_state <= SRV_SHUTDOWN_INITIATED) {
24312462srv_master_sleep ();
24322463
24332464MONITOR_INC (MONITOR_MASTER_THREAD_SLEEP);
24342465
2435- if (srv_check_activity (&old_activity_count)) {
2466+ if (srv_check_activity (old_activity_count)) {
2467+ old_activity_count = srv_get_activity_count ();
24362468srv_master_do_active_tasks ();
24372469} else {
24382470srv_master_do_idle_tasks ();
24392471}
24402472}
24412473
2442- ut_ad (srv_shutdown_state == SRV_SHUTDOWN_EXIT_THREADS
2443- || srv_shutdown_state == SRV_SHUTDOWN_CLEANUP);
2444-
2445- if (srv_shutdown_state == SRV_SHUTDOWN_CLEANUP
2446- && srv_fast_shutdown < 2 ) {
2447- srv_shutdown (srv_fast_shutdown == 0 );
2474+ switch (srv_shutdown_state) {
2475+ case SRV_SHUTDOWN_NONE:
2476+ case SRV_SHUTDOWN_INITIATED:
2477+ break ;
2478+ case SRV_SHUTDOWN_FLUSH_PHASE:
2479+ case SRV_SHUTDOWN_LAST_PHASE:
2480+ ut_ad (0 );
2481+ /* fall through */
2482+ case SRV_SHUTDOWN_EXIT_THREADS:
2483+ /* srv_init_abort() must have been invoked */
2484+ case SRV_SHUTDOWN_CLEANUP:
2485+ if (srv_shutdown_state == SRV_SHUTDOWN_CLEANUP
2486+ && srv_fast_shutdown < 2 ) {
2487+ srv_shutdown (srv_fast_shutdown == 0 );
2488+ }
2489+ srv_suspend_thread (slot);
2490+ my_thread_end ();
2491+ os_thread_exit ();
24482492}
24492493
2494+ srv_main_thread_op_info = " suspending" ;
2495+
24502496srv_suspend_thread (slot);
2451- my_thread_end ();
2452- os_thread_exit ();
2453- OS_THREAD_DUMMY_RETURN;
2497+
2498+ /* DO NOT CHANGE THIS STRING. innobase_start_or_create_for_mysql()
2499+ waits for database activity to die down when converting < 4.1.x
2500+ databases, and relies on this string being exactly as it is. InnoDB
2501+ manual also mentions this string in several places. */
2502+ srv_main_thread_op_info = " waiting for server activity" ;
2503+
2504+ srv_resume_thread (slot);
2505+ goto loop;
24542506}
24552507
24562508/* * Check if purge should stop.
@@ -2647,13 +2699,15 @@ srv_do_purge(ulint* n_total_purged
26472699++n_use_threads;
26482700}
26492701
2650- } else if (srv_check_activity (& old_activity_count)
2702+ } else if (srv_check_activity (old_activity_count)
26512703 && n_use_threads > 1 ) {
26522704
26532705/* History length same or smaller since last snapshot,
26542706use fewer threads. */
26552707
26562708--n_use_threads;
2709+
2710+ old_activity_count = srv_get_activity_count ();
26572711}
26582712
26592713/* Ensure that the purge threads are less than what
0 commit comments