diff options
author | Monty <monty@mariadb.org> | 2016-04-07 19:51:40 +0300 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2016-06-04 09:06:00 +0200 |
commit | 89685d55d7329065607df5a5f19b641e5947e22f (patch) | |
tree | 9c2f48944f77c71043b35ed1bc39555588be383c /sql/sql_connect.cc | |
parent | 54f3e18f6e88bfae993749569104b4c89f0ea9ab (diff) | |
download | mariadb-git-89685d55d7329065607df5a5f19b641e5947e22f.tar.gz |
Reuse THD for new user connections
- To ensure that mallocs are marked for the correct THD, even if it's
allocated in another thread, I added the thread_id to the THD constructor
- Added st_my_thread_var to thr_lock_info_init() to avoid a call to my_thread_var
- Moved things from THD::THD() to THD::init()
- Moved some things to THD::cleanup()
- Added THD::free_connection() and THD::reset_for_reuse()
- Added THD to CONNECT::create_thd()
- Added THD::thread_dbug_id and st_my_thread_var->dbug_id. These are needed
to ensure that we have a constant thread_id used for debugging with a THD,
even if it changes thread_id (=connection_id)
- Set variables.pseudo_thread_id in constructor. Removed not needed sets.
Diffstat (limited to 'sql/sql_connect.cc')
-rw-r--r-- | sql/sql_connect.cc | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index 66564bd5e94..f210762db50 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -1299,7 +1299,7 @@ void do_handle_one_connection(CONNECT *connect) ulonglong thr_create_utime= microsecond_interval_timer(); THD *thd; if (connect->scheduler->init_new_connection_thread() || - !(thd= connect->create_thd())) + !(thd= connect->create_thd(NULL))) { scheduler_functions *scheduler= connect->scheduler; connect->close_with_error(0, 0, ER_OUT_OF_RESOURCES); @@ -1426,7 +1426,7 @@ void CONNECT::close_and_delete() void CONNECT::close_with_error(uint sql_errno, const char *message, uint close_error) { - THD *thd= create_thd(); + THD *thd= create_thd(NULL); if (thd) { if (sql_errno) @@ -1460,17 +1460,28 @@ CONNECT::~CONNECT() vio_delete(vio); } -/* Create a THD based on a CONNECT object */ -THD *CONNECT::create_thd() +/* Reuse or create a THD based on a CONNECT object */ + +THD *CONNECT::create_thd(THD *thd) { - my_bool res; - THD *thd; + bool res, thd_reused= thd != 0; DBUG_ENTER("create_thd"); DBUG_EXECUTE_IF("simulate_failed_connection_2", DBUG_RETURN(0); ); - if (!(thd= new THD)) + if (thd) + { + /* reuse old thd */ + thd->reset_for_reuse(); + /* + reset tread_id's, but not thread_dbug_id's as the later isn't allowed + to change as there is already structures in thd marked with the old + value. + */ + thd->thread_id= thd->variables.pseudo_thread_id= thread_id; + } + else if (!(thd= new THD(thread_id))) DBUG_RETURN(0); set_current_thd(thd); @@ -1479,7 +1490,8 @@ THD *CONNECT::create_thd() if (res) { - delete thd; + if (!thd_reused) + delete thd; set_current_thd(0); DBUG_RETURN(0); } @@ -1489,7 +1501,6 @@ THD *CONNECT::create_thd() thd->security_ctx->host= host; thd->extra_port= extra_port; thd->scheduler= scheduler; - thd->thread_id= thd->variables.pseudo_thread_id= thread_id; thd->real_id= real_id; DBUG_RETURN(thd); } |