diff options
author | Sergei Petrunia <psergey@askmonty.org> | 2016-03-28 22:18:38 +0300 |
---|---|---|
committer | Sergei Petrunia <psergey@askmonty.org> | 2016-03-28 22:18:38 +0300 |
commit | 2bd4dc38e0d5eb257e2e29413dd01239ce075d42 (patch) | |
tree | dad0557b1d927d012aebd1c36c8c3e00462adcb1 /sql/threadpool_common.cc | |
parent | 44fdb56c977259b2801c612116813beda403df78 (diff) | |
parent | 3df261dc31ab18ee1537f327b07320b0a07fb8f5 (diff) | |
download | mariadb-git-2bd4dc38e0d5eb257e2e29413dd01239ce075d42.tar.gz |
Merge branch '10.2' into bb-10.2-mdev9543
Diffstat (limited to 'sql/threadpool_common.cc')
-rw-r--r-- | sql/threadpool_common.cc | 81 |
1 files changed, 54 insertions, 27 deletions
diff --git a/sql/threadpool_common.cc b/sql/threadpool_common.cc index 9fb38319096..2cfa3473222 100644 --- a/sql/threadpool_common.cc +++ b/sql/threadpool_common.cc @@ -94,7 +94,7 @@ struct Worker_thread_context /* Attach/associate the connection with the OS thread, */ -static bool thread_attach(THD* thd) +static void thread_attach(THD* thd) { pthread_setspecific(THR_KEY_mysys,thd->mysys_var); thd->thread_stack=(char*)&thd; @@ -103,13 +103,14 @@ static bool thread_attach(THD* thd) if (PSI_server) PSI_server->set_thread(thd->event_scheduler.m_psi); #endif - return 0; } -int threadpool_add_connection(THD *thd) +THD* threadpool_add_connection(CONNECT *connect, void *scheduler_data) { - int retval=1; + THD *thd= NULL; + int error=1; + Worker_thread_context worker_context; worker_context.save(); @@ -120,13 +121,29 @@ int threadpool_add_connection(THD *thd) pthread_setspecific(THR_KEY_mysys, 0); my_thread_init(); - thd->mysys_var= (st_my_thread_var *)pthread_getspecific(THR_KEY_mysys); - if (!thd->mysys_var) + st_my_thread_var* mysys_var= (st_my_thread_var *)pthread_getspecific(THR_KEY_mysys); + if (!mysys_var ||!(thd= connect->create_thd())) { /* Out of memory? */ + connect->close_and_delete(); + if (mysys_var) + { +#ifdef HAVE_PSI_INTERFACE + /* + current PSI is still from worker thread. + Set to 0, to avoid premature cleanup by my_thread_end + */ + if (PSI_server) PSI_server->set_thread(0); +#endif + my_thread_end(); + } worker_context.restore(); - return 1; + return NULL; } + delete connect; + add_to_active_threads(thd); + thd->mysys_var= mysys_var; + thd->event_scheduler.data= scheduler_data; /* Create new PSI thread for use with the THD. */ #ifdef HAVE_PSI_INTERFACE @@ -157,28 +174,19 @@ int threadpool_add_connection(THD *thd) */ if (thd_is_connection_alive(thd)) { - retval= 0; + error= 0; thd->net.reading_or_writing= 1; thd->skip_wait_timeout= true; } } } + if (error) + { + threadpool_remove_connection(thd); + thd= NULL; + } worker_context.restore(); - return retval; -} - -/* - threadpool_cleanup_connection() does the bulk of connection shutdown work. - Usually called from threadpool_remove_connection(), but rarely it might - be called also in the main polling thread if connection initialization fails. -*/ -void threadpool_cleanup_connection(THD *thd) -{ - thd->net.reading_or_writing = 0; - end_connection(thd); - close_connection(thd, 0); - unlink_thd(thd); - mysql_cond_broadcast(&COND_thread_count); + return thd; } @@ -188,7 +196,12 @@ void threadpool_remove_connection(THD *thd) worker_context.save(); thread_attach(thd); - threadpool_cleanup_connection(thd); + thd->net.reading_or_writing = 0; + end_connection(thd); + close_connection(thd, 0); + unlink_thd(thd); + mysql_cond_broadcast(&COND_thread_count); + /* Free resources associated with this connection: mysys thread_var and PSI thread. @@ -221,7 +234,8 @@ int threadpool_process_request(THD *thd) /* - In the loop below, the flow is essentially the copy of thead-per-connections + In the loop below, the flow is essentially the copy of + thead-per-connections logic, see do_handle_one_connection() in sql_connect.c The goal is to execute a single query, thus the loop is normally executed @@ -260,18 +274,31 @@ end: } + +/* Dummy functions, do nothing */ + +static bool tp_init_new_connection_thread() +{ + return 0; +} + +static bool tp_end_thread(THD *, bool) +{ + return 0; +} + static scheduler_functions tp_scheduler_functions= { 0, // max_threads NULL, NULL, tp_init, // init - NULL, // init_new_connection_thread + tp_init_new_connection_thread, // init_new_connection_thread tp_add_connection, // add_connection tp_wait_begin, // thd_wait_begin tp_wait_end, // thd_wait_end post_kill_notification, // post_kill_notification - NULL, // end_thread + tp_end_thread, // Dummy function tp_end // end }; |