Commit 7f498fba authored by Kristian Nielsen's avatar Kristian Nielsen

Fix "Assertion `THR_PFS_initialized' failed" in main.bootstrap

This patch makes the server wait for the manager thread to actually start
before proceeding with server startup.

Without this, if thread scheduling is really slow and the server shutdowns
quickly, then it is possible that the manager thread is not yet started when
shutdown_performance_schema() is called. If the manager thread starts at just
the wrong moment and just before the main server reaches exit(), the thread
can try to access no longer available performance schema data. This was seen
as occasional assertion in the main.bootstrap test.

As an additional improvement, make sure to run all pending actions before
exiting the manager thread.
Reviewed-by: default avatarMonty <monty@mariadb.org>
Signed-off-by: default avatarKristian Nielsen <knielsen@knielsen-hq.org>
parent 51e3f1da
...@@ -76,7 +76,9 @@ pthread_handler_t handle_manager(void *arg __attribute__((unused))) ...@@ -76,7 +76,9 @@ pthread_handler_t handle_manager(void *arg __attribute__((unused)))
pthread_detach_this_thread(); pthread_detach_this_thread();
manager_thread = pthread_self(); manager_thread = pthread_self();
mysql_mutex_lock(&LOCK_manager); mysql_mutex_lock(&LOCK_manager);
while (!abort_manager) manager_thread_in_use = 1;
mysql_cond_signal(&COND_manager);
while (!abort_manager || cb_list)
{ {
/* XXX: This will need to be made more general to handle different /* XXX: This will need to be made more general to handle different
* polling needs. */ * polling needs. */
...@@ -116,6 +118,7 @@ pthread_handler_t handle_manager(void *arg __attribute__((unused))) ...@@ -116,6 +118,7 @@ pthread_handler_t handle_manager(void *arg __attribute__((unused)))
} }
mysql_mutex_lock(&LOCK_manager); mysql_mutex_lock(&LOCK_manager);
} }
DBUG_ASSERT(cb_list == NULL);
manager_thread_in_use = 0; manager_thread_in_use = 0;
mysql_mutex_unlock(&LOCK_manager); mysql_mutex_unlock(&LOCK_manager);
mysql_mutex_destroy(&LOCK_manager); mysql_mutex_destroy(&LOCK_manager);
...@@ -135,12 +138,19 @@ void start_handle_manager() ...@@ -135,12 +138,19 @@ void start_handle_manager()
pthread_t hThread; pthread_t hThread;
int err; int err;
DBUG_EXECUTE_IF("delay_start_handle_manager", my_sleep(1000);); DBUG_EXECUTE_IF("delay_start_handle_manager", my_sleep(1000););
manager_thread_in_use = 1;
mysql_cond_init(key_COND_manager, &COND_manager,NULL); mysql_cond_init(key_COND_manager, &COND_manager,NULL);
mysql_mutex_init(key_LOCK_manager, &LOCK_manager, NULL); mysql_mutex_init(key_LOCK_manager, &LOCK_manager, NULL);
if ((err= mysql_thread_create(key_thread_handle_manager, &hThread, if ((err= mysql_thread_create(key_thread_handle_manager, &hThread,
&connection_attrib, handle_manager, 0))) &connection_attrib, handle_manager, 0)))
{
sql_print_warning("Can't create handle_manager thread (errno: %M)", err); sql_print_warning("Can't create handle_manager thread (errno: %M)", err);
DBUG_VOID_RETURN;
}
mysql_mutex_lock(&LOCK_manager);
while (!manager_thread_in_use)
mysql_cond_wait(&COND_manager, &LOCK_manager);
mysql_mutex_unlock(&LOCK_manager);
} }
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment