diff options
Diffstat (limited to 'sql/wsrep_thd.cc')
-rw-r--r-- | sql/wsrep_thd.cc | 66 |
1 files changed, 42 insertions, 24 deletions
diff --git a/sql/wsrep_thd.cc b/sql/wsrep_thd.cc index ab09a9e3a99..3835c925745 100644 --- a/sql/wsrep_thd.cc +++ b/sql/wsrep_thd.cc @@ -50,8 +50,8 @@ int wsrep_show_bf_aborts (THD *thd, SHOW_VAR *var, char *buff, /* must have (&thd->LOCK_wsrep_thd) */ void wsrep_client_rollback(THD *thd) { - WSREP_DEBUG("client rollback due to BF abort for (%ld), query: %s", - thd->thread_id, thd->query()); + WSREP_DEBUG("client rollback due to BF abort for (%lld), query: %s", + (longlong) thd->thread_id, thd->query()); WSREP_ATOMIC_ADD_LONG(&wsrep_bf_aborts_counter, 1); @@ -61,14 +61,16 @@ void wsrep_client_rollback(THD *thd) if (thd->locked_tables_mode && thd->lock) { - WSREP_DEBUG("unlocking tables for BF abort (%ld)", thd->thread_id); + WSREP_DEBUG("unlocking tables for BF abort (%lld)", + (longlong) thd->thread_id); thd->locked_tables_list.unlock_locked_tables(thd); thd->variables.option_bits&= ~(OPTION_TABLE_LOCK); } if (thd->global_read_lock.is_acquired()) { - WSREP_DEBUG("unlocking GRL for BF abort (%ld)", thd->thread_id); + WSREP_DEBUG("unlocking GRL for BF abort (%lld)", + (longlong) thd->thread_id); thd->global_read_lock.unlock_global_read_lock(thd); } @@ -80,7 +82,8 @@ void wsrep_client_rollback(THD *thd) if (thd->get_binlog_table_maps()) { - WSREP_DEBUG("clearing binlog table map for BF abort (%ld)", thd->thread_id); + WSREP_DEBUG("clearing binlog table map for BF abort (%lld)", + (longlong) thd->thread_id); thd->clear_binlog_table_maps(); } mysql_mutex_lock(&thd->LOCK_wsrep_thd); @@ -202,8 +205,8 @@ void wsrep_replay_transaction(THD *thd) close_thread_tables(thd); if (thd->locked_tables_mode && thd->lock) { - WSREP_DEBUG("releasing table lock for replaying (%ld)", - thd->thread_id); + WSREP_DEBUG("releasing table lock for replaying (%lld)", + (longlong) thd->thread_id); thd->locked_tables_list.unlock_locked_tables(thd); thd->variables.option_bits&= ~(OPTION_TABLE_LOCK); } @@ -242,8 +245,8 @@ void wsrep_replay_transaction(THD *thd) case WSREP_OK: thd->wsrep_conflict_state= NO_CONFLICT; wsrep->post_commit(wsrep, &thd->wsrep_ws_handle); - WSREP_DEBUG("trx_replay successful for: %ld %llu", - thd->thread_id, (long long)thd->real_id); + WSREP_DEBUG("trx_replay successful for: %lld %lld", + (longlong) thd->thread_id, (longlong) thd->real_id); if (thd->get_stmt_da()->is_sent()) { WSREP_WARN("replay ok, thd has reported status"); @@ -292,8 +295,8 @@ void wsrep_replay_transaction(THD *thd) mysql_mutex_lock(&LOCK_wsrep_replaying); wsrep_replaying--; - WSREP_DEBUG("replaying decreased: %d, thd: %lu", - wsrep_replaying, thd->thread_id); + WSREP_DEBUG("replaying decreased: %d, thd: %lld", + wsrep_replaying, (longlong) thd->thread_id); mysql_cond_broadcast(&COND_wsrep_replaying); mysql_mutex_unlock(&LOCK_wsrep_replaying); } @@ -360,15 +363,34 @@ static void wsrep_replication_process(THD *thd) TABLE *tmp; while ((tmp = thd->temporary_tables)) { - WSREP_WARN("Applier %lu, has temporary tables at exit: %s.%s", - thd->thread_id, - (tmp->s) ? tmp->s->db.str : "void", - (tmp->s) ? tmp->s->table_name.str : "void"); + WSREP_WARN("Applier %lld, has temporary tables at exit: %s.%s", + (longlong) thd->thread_id, + (tmp->s) ? tmp->s->db.str : "void", + (tmp->s) ? tmp->s->table_name.str : "void"); } wsrep_return_from_bf_mode(thd, &shadow); DBUG_VOID_RETURN; } +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; +} + void wsrep_create_appliers(long threads) { if (!wsrep_connected) @@ -385,11 +407,8 @@ void wsrep_create_appliers(long threads) } long wsrep_threads=0; - pthread_t hThread; while (wsrep_threads++ < threads) { - if (pthread_create( - &hThread, &connection_attrib, - start_wsrep_THD, (void*)wsrep_replication_process)) + if (create_wsrep_THD(wsrep_replication_process)) WSREP_WARN("Can't create thread to manage wsrep replication"); } } @@ -454,8 +473,9 @@ static void wsrep_rollback_process(THD *thd) mysql_mutex_lock(&aborting->LOCK_wsrep_thd); wsrep_client_rollback(aborting); - WSREP_DEBUG("WSREP rollbacker aborted thd: (%lu %llu)", - aborting->thread_id, (long long)aborting->real_id); + WSREP_DEBUG("WSREP rollbacker aborted thd: (%lld %lld)", + (longlong) aborting->thread_id, + (longlong) aborting->real_id); mysql_mutex_unlock(&aborting->LOCK_wsrep_thd); set_current_thd(thd); @@ -476,10 +496,8 @@ void wsrep_create_rollbacker() { if (wsrep_provider && strcasecmp(wsrep_provider, "none")) { - pthread_t hThread; /* create rollbacker */ - if (pthread_create( &hThread, &connection_attrib, - start_wsrep_THD, (void*)wsrep_rollback_process)) + if (create_wsrep_THD(wsrep_rollback_process)) WSREP_WARN("Can't create thread to manage wsrep rollback"); } } |