@@ -1861,10 +1861,13 @@ static bool srv_task_execute()
1861
1861
return false ;
1862
1862
}
1863
1863
1864
+ static void purge_create_background_thds (int );
1865
+
1864
1866
std::mutex purge_thread_count_mtx;
1865
1867
void srv_update_purge_thread_count (uint n)
1866
1868
{
1867
1869
std::lock_guard<std::mutex> lk (purge_thread_count_mtx);
1870
+ purge_create_background_thds (n);
1868
1871
srv_n_purge_threads = n;
1869
1872
srv_purge_thread_count_changed = 1 ;
1870
1873
}
@@ -1959,15 +1962,25 @@ static std::list<THD*> purge_thds;
1959
1962
static std::mutex purge_thd_mutex;
1960
1963
extern void * thd_attach_thd (THD*);
1961
1964
extern void thd_detach_thd (void *);
1965
+ static int n_purge_thds;
1962
1966
1963
- static THD *acquire_thd (void **ctx)
1967
+ /* Ensure that we have at least n background THDs for purge */
1968
+ static void purge_create_background_thds (int n)
1964
1969
{
1970
+ THD *thd= current_thd;
1965
1971
std::unique_lock<std::mutex> lk (purge_thd_mutex);
1966
- if (purge_thds. empty ()) {
1967
- THD* thd = current_thd;
1972
+ while (n_purge_thds < n)
1973
+ {
1968
1974
purge_thds.push_back (innobase_create_background_thd (" InnoDB purge worker" ));
1969
- set_current_thd (thd) ;
1975
+ n_purge_thds++ ;
1970
1976
}
1977
+ set_current_thd (thd);
1978
+ }
1979
+
1980
+ static THD *acquire_thd (void **ctx)
1981
+ {
1982
+ std::unique_lock<std::mutex> lk (purge_thd_mutex);
1983
+ ut_a (!purge_thds.empty ());
1971
1984
THD* thd = purge_thds.front ();
1972
1985
purge_thds.pop_front ();
1973
1986
lk.unlock ();
@@ -2068,6 +2081,7 @@ static void purge_coordinator_callback(void*)
2068
2081
2069
2082
void srv_init_purge_tasks ()
2070
2083
{
2084
+ purge_create_background_thds (srv_n_purge_threads);
2071
2085
purge_coordinator_timer= srv_thread_pool->create_timer
2072
2086
(purge_coordinator_timer_callback, nullptr );
2073
2087
}
@@ -2078,11 +2092,13 @@ static void srv_shutdown_purge_tasks()
2078
2092
delete purge_coordinator_timer;
2079
2093
purge_coordinator_timer= nullptr ;
2080
2094
purge_worker_task.wait ();
2095
+ std::unique_lock<std::mutex> lk (purge_thd_mutex);
2081
2096
while (!purge_thds.empty ())
2082
2097
{
2083
2098
innobase_destroy_background_thd (purge_thds.front ());
2084
2099
purge_thds.pop_front ();
2085
2100
}
2101
+ n_purge_thds= 0 ;
2086
2102
}
2087
2103
2088
2104
/* *********************************************************************/ /* *
@@ -2123,7 +2139,8 @@ ulint srv_get_task_queue_length()
2123
2139
void srv_purge_shutdown ()
2124
2140
{
2125
2141
if (purge_sys.enabled ()) {
2126
- srv_update_purge_thread_count (innodb_purge_threads_MAX);
2142
+ if (!srv_fast_shutdown)
2143
+ srv_update_purge_thread_count (innodb_purge_threads_MAX);
2127
2144
while (!srv_purge_should_exit ()) {
2128
2145
ut_a (!purge_sys.paused ());
2129
2146
srv_wake_purge_thread_if_not_active ();
0 commit comments