summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rw-r--r--sql/mysqld.cc49
-rw-r--r--sql/wsrep_mysqld.cc21
-rw-r--r--sql/wsrep_mysqld.h2
-rw-r--r--sql/wsrep_thd.cc11
4 files changed, 16 insertions, 67 deletions
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 8f2feed2eb9..fa8fb3f0a9a 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -5207,49 +5207,6 @@ static int init_server_components()
}
plugins_are_initialized= TRUE; /* Don't separate from init function */
-#ifdef WITH_WSREP
- /* Wait for wsrep threads to get created. */
- if (wsrep_creating_startup_threads == 1) {
- mysql_mutex_lock(&LOCK_thread_count);
- while (wsrep_running_threads < 2)
- {
- mysql_cond_wait(&COND_thread_count, &LOCK_thread_count);
- }
-
- /* Now is the time to initialize threads for queries. */
- THD *tmp;
- I_List_iterator<THD> it(threads);
- while ((tmp= it++))
- {
- if (tmp->wsrep_applier == true)
- {
- /*
- Save/restore server_status and variables.option_bits and they get
- altered during init_for_queries().
- */
- unsigned int server_status_saved= tmp->server_status;
- ulonglong option_bits_saved= tmp->variables.option_bits;
-
- /*
- Set THR_THD to temporarily 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();
-
- /* Restore current_thd. */
- set_current_thd(current_thd_saved);
-
- tmp->server_status= server_status_saved;
- tmp->variables.option_bits= option_bits_saved;
- }
- }
- mysql_mutex_unlock(&LOCK_thread_count);
- }
-#endif
-
/* we do want to exit if there are any other unknown options */
if (remaining_argc > 1)
{
@@ -5897,6 +5854,9 @@ int mysqld_main(int argc, char **argv)
if (Events::init((THD*) 0, opt_noacl || opt_bootstrap))
unireg_abort(1);
+ /* It's now safe to use thread specific memory */
+ mysqld_server_initialized= 1;
+
if (WSREP_ON)
{
if (opt_bootstrap)
@@ -5937,9 +5897,6 @@ int mysqld_main(int argc, char **argv)
}
}
- /* It's now safe to use thread specific memory */
- mysqld_server_initialized= 1;
-
create_shutdown_thread();
start_handle_manager();
diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc
index b922d2b2857..03524c8ad5c 100644
--- a/sql/wsrep_mysqld.cc
+++ b/sql/wsrep_mysqld.cc
@@ -91,12 +91,6 @@ my_bool wsrep_slave_UK_checks = 0; // slave thread does UK checks
my_bool wsrep_slave_FK_checks = 0; // slave thread does FK checks
bool wsrep_new_cluster = false; // Bootstrap the cluster ?
-/*
- Set during the creation of first wsrep applier and rollback threads.
- Since these threads are critical, abort if the thread creation fails.
-*/
-my_bool wsrep_creating_startup_threads = 0;
-
// Use wsrep_gtid_domain_id for galera transactions?
bool wsrep_gtid_mode = 0;
// gtid_domain_id for galera transactions.
@@ -798,7 +792,6 @@ void wsrep_init_startup (bool first)
if (!wsrep_start_replication()) unireg_abort(1);
- wsrep_creating_startup_threads= 1;
wsrep_create_rollbacker();
wsrep_create_appliers(1);
@@ -1820,21 +1813,11 @@ pthread_handler_t start_wsrep_THD(void *arg)
//thd->version= refresh_version;
thd->proc_info= 0;
thd->set_command(COM_SLEEP);
-
- if (wsrep_creating_startup_threads == 0)
- {
- thd->init_for_queries();
- }
+ thd->init_for_queries();
mysql_mutex_lock(&LOCK_thread_count);
wsrep_running_threads++;
mysql_cond_broadcast(&COND_thread_count);
-
- if (wsrep_running_threads > 2)
- {
- wsrep_creating_startup_threads= 0;
- }
-
mysql_mutex_unlock(&LOCK_thread_count);
processor(thd);
@@ -1877,7 +1860,7 @@ error:
WSREP_ERROR("Failed to create/initialize system thread");
/* Abort if its the first applier/rollbacker thread. */
- if (wsrep_creating_startup_threads == 1)
+ if (!mysqld_server_initialized)
unireg_abort(1);
else
return NULL;
diff --git a/sql/wsrep_mysqld.h b/sql/wsrep_mysqld.h
index 26d3484b3b4..a22eb1a0b64 100644
--- a/sql/wsrep_mysqld.h
+++ b/sql/wsrep_mysqld.h
@@ -86,7 +86,6 @@ extern my_bool wsrep_slave_FK_checks;
extern my_bool wsrep_slave_UK_checks;
extern ulong wsrep_running_threads;
extern bool wsrep_new_cluster;
-extern my_bool wsrep_creating_startup_threads;
extern bool wsrep_gtid_mode;
extern uint32 wsrep_gtid_domain_id;
@@ -341,7 +340,6 @@ int wsrep_create_trigger_query(THD *thd, uchar** buf, size_t* buf_len);
#define wsrep_thr_init() do {} while(0)
#define wsrep_thr_deinit() do {} while(0)
#define wsrep_running_threads (0)
-#define wsrep_creating_startup_threads (0)
#endif /* WITH_WSREP */
#endif /* WSREP_MYSQLD_H */
diff --git a/sql/wsrep_thd.cc b/sql/wsrep_thd.cc
index cb9822d1599..fb48c1ad60e 100644
--- a/sql/wsrep_thd.cc
+++ b/sql/wsrep_thd.cc
@@ -371,9 +371,20 @@ static void wsrep_replication_process(THD *thd)
static bool create_wsrep_THD(wsrep_thd_processor_fun processor)
{
+ ulong old_wsrep_running_threads= wsrep_running_threads;
pthread_t unused;
+ mysql_mutex_lock(&LOCK_thread_count);
bool res= pthread_create(&unused, &connection_attrib, start_wsrep_THD,
(void*)processor);
+ /*
+ if starting a thread on server startup, wait until the this thread's THD
+ is fully initialized (otherwise a THD initialization code might
+ try to access a partially initialized server data structure - MDEV-8208).
+ */
+ if (!mysqld_server_initialized)
+ while (old_wsrep_running_threads == wsrep_running_threads)
+ mysql_cond_wait(&COND_thread_count, &LOCK_thread_count);
+ mysql_mutex_unlock(&LOCK_thread_count);
return res;
}