Skip to content

Commit 1a69e15

Browse files
committed
MDEV-26511 Only allocate Innodb background purge thd, when it is safe.
Change logic to only allocate purge thds at startup, or in pre-shutdown (for slow shutdown).
1 parent 4b6ef03 commit 1a69e15

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

storage/innobase/srv/srv0srv.cc

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,10 +1861,13 @@ static bool srv_task_execute()
18611861
return false;
18621862
}
18631863

1864+
static void purge_create_background_thds(int );
1865+
18641866
std::mutex purge_thread_count_mtx;
18651867
void srv_update_purge_thread_count(uint n)
18661868
{
18671869
std::lock_guard<std::mutex> lk(purge_thread_count_mtx);
1870+
purge_create_background_thds(n);
18681871
srv_n_purge_threads = n;
18691872
srv_purge_thread_count_changed = 1;
18701873
}
@@ -1959,15 +1962,25 @@ static std::list<THD*> purge_thds;
19591962
static std::mutex purge_thd_mutex;
19601963
extern void* thd_attach_thd(THD*);
19611964
extern void thd_detach_thd(void *);
1965+
static int n_purge_thds;
19621966

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)
19641969
{
1970+
THD *thd= current_thd;
19651971
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+
{
19681974
purge_thds.push_back(innobase_create_background_thd("InnoDB purge worker"));
1969-
set_current_thd(thd);
1975+
n_purge_thds++;
19701976
}
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());
19711984
THD* thd = purge_thds.front();
19721985
purge_thds.pop_front();
19731986
lk.unlock();
@@ -2068,6 +2081,7 @@ static void purge_coordinator_callback(void*)
20682081

20692082
void srv_init_purge_tasks()
20702083
{
2084+
purge_create_background_thds(srv_n_purge_threads);
20712085
purge_coordinator_timer= srv_thread_pool->create_timer
20722086
(purge_coordinator_timer_callback, nullptr);
20732087
}
@@ -2078,11 +2092,13 @@ static void srv_shutdown_purge_tasks()
20782092
delete purge_coordinator_timer;
20792093
purge_coordinator_timer= nullptr;
20802094
purge_worker_task.wait();
2095+
std::unique_lock<std::mutex> lk(purge_thd_mutex);
20812096
while (!purge_thds.empty())
20822097
{
20832098
innobase_destroy_background_thd(purge_thds.front());
20842099
purge_thds.pop_front();
20852100
}
2101+
n_purge_thds= 0;
20862102
}
20872103

20882104
/**********************************************************************//**
@@ -2123,7 +2139,8 @@ ulint srv_get_task_queue_length()
21232139
void srv_purge_shutdown()
21242140
{
21252141
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);
21272144
while(!srv_purge_should_exit()) {
21282145
ut_a(!purge_sys.paused());
21292146
srv_wake_purge_thread_if_not_active();

0 commit comments

Comments
 (0)