Skip to content

Commit 6927459

Browse files
author
Nirbhay Choubey
committed
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.
1 parent 59037d9 commit 6927459

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

mysys/my_alloc.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ void init_alloc_root(MEM_ROOT *mem_root, size_t block_size,
105105
void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
106106
size_t pre_alloc_size __attribute__((unused)))
107107
{
108+
DBUG_ENTER("reset_root_defaults");
108109
DBUG_ASSERT(alloc_root_inited(mem_root));
109110

110111
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,
127128
{
128129
/* We found a suitable block, no need to do anything else */
129130
mem_root->pre_alloc= mem;
130-
return;
131+
DBUG_VOID_RETURN;
131132
}
132133
if (mem->left + ALIGN_SIZE(sizeof(USED_MEM)) == mem->size)
133134
{
@@ -157,6 +158,8 @@ void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
157158
else
158159
#endif
159160
mem_root->pre_alloc= 0;
161+
162+
DBUG_VOID_RETURN;
160163
}
161164

162165

sql/mysqld.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5215,7 +5215,17 @@ static int init_server_components()
52155215
{
52165216
if (tmp->wsrep_applier == true)
52175217
{
5218+
/*
5219+
Set THR_THD to temporally point to this THD to register all the
5220+
variables that allocates memory for this THD.
5221+
*/
5222+
THD *current_thd_saved= current_thd;
5223+
set_current_thd(tmp);
5224+
52185225
tmp->init_for_queries();
5226+
5227+
/* Restore current_thd. */
5228+
set_current_thd(current_thd_saved);
52195229
}
52205230
}
52215231
mysql_mutex_unlock(&LOCK_thread_count);

sql/wsrep_mysqld.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1801,7 +1801,7 @@ pthread_handler_t start_wsrep_THD(void *arg)
18011801
thd->proc_info= 0;
18021802
thd->set_command(COM_SLEEP);
18031803

1804-
if (plugins_are_initialized)
1804+
if (wsrep_creating_startup_threads == 0)
18051805
{
18061806
thd->init_for_queries();
18071807
}

0 commit comments

Comments
 (0)