Commit 6927459e authored by Nirbhay Choubey's avatar Nirbhay Choubey

MDEV-8208: Sporadic SEGFAULT on startup

Addendum:
* Before calling THD::init_for_queries(), flip the current_thd to wsrep
thread so that memory gets allocated for the right THD.
* Use wsrep_creating_startup_threads instead of plugins_are_initialized
as the condition for the execution of THD::init_for_queries() within
start_wsrep_THD(), as use of latter could still leave some room for
race.
parent 59037d96
...@@ -105,6 +105,7 @@ void init_alloc_root(MEM_ROOT *mem_root, size_t block_size, ...@@ -105,6 +105,7 @@ void init_alloc_root(MEM_ROOT *mem_root, size_t block_size,
void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size, void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
size_t pre_alloc_size __attribute__((unused))) size_t pre_alloc_size __attribute__((unused)))
{ {
DBUG_ENTER("reset_root_defaults");
DBUG_ASSERT(alloc_root_inited(mem_root)); DBUG_ASSERT(alloc_root_inited(mem_root));
mem_root->block_size= (((block_size - ALLOC_ROOT_MIN_BLOCK_SIZE) & ~1) | mem_root->block_size= (((block_size - ALLOC_ROOT_MIN_BLOCK_SIZE) & ~1) |
...@@ -127,7 +128,7 @@ void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size, ...@@ -127,7 +128,7 @@ void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
{ {
/* We found a suitable block, no need to do anything else */ /* We found a suitable block, no need to do anything else */
mem_root->pre_alloc= mem; mem_root->pre_alloc= mem;
return; DBUG_VOID_RETURN;
} }
if (mem->left + ALIGN_SIZE(sizeof(USED_MEM)) == mem->size) if (mem->left + ALIGN_SIZE(sizeof(USED_MEM)) == mem->size)
{ {
...@@ -157,6 +158,8 @@ void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size, ...@@ -157,6 +158,8 @@ void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
else else
#endif #endif
mem_root->pre_alloc= 0; mem_root->pre_alloc= 0;
DBUG_VOID_RETURN;
} }
......
...@@ -5215,7 +5215,17 @@ static int init_server_components() ...@@ -5215,7 +5215,17 @@ static int init_server_components()
{ {
if (tmp->wsrep_applier == true) if (tmp->wsrep_applier == true)
{ {
/*
Set THR_THD to temporally point to this THD to register all the
variables that allocates memory for this THD.
*/
THD *current_thd_saved= current_thd;
set_current_thd(tmp);
tmp->init_for_queries(); tmp->init_for_queries();
/* Restore current_thd. */
set_current_thd(current_thd_saved);
} }
} }
mysql_mutex_unlock(&LOCK_thread_count); mysql_mutex_unlock(&LOCK_thread_count);
......
...@@ -1801,7 +1801,7 @@ pthread_handler_t start_wsrep_THD(void *arg) ...@@ -1801,7 +1801,7 @@ pthread_handler_t start_wsrep_THD(void *arg)
thd->proc_info= 0; thd->proc_info= 0;
thd->set_command(COM_SLEEP); thd->set_command(COM_SLEEP);
if (plugins_are_initialized) if (wsrep_creating_startup_threads == 0)
{ {
thd->init_for_queries(); thd->init_for_queries();
} }
......
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