Commit ebc55c85 authored by Sergey Vojtovich's avatar Sergey Vojtovich

Simplified away scheduler_functions::end_thread()

Code properly integrated into callers instead.

do_handle_one_connection(): no need to reset thd and thd->thread_stack
as they're not updated by cache_thread().

Part of MDEV-19515 - Improve connect speed
parent 6900aaf4
......@@ -2663,7 +2663,7 @@ void unlink_thd(THD *thd)
*/
static bool cache_thread(THD *thd)
bool cache_thread(THD *thd)
{
struct timespec abstime;
DBUG_ENTER("cache_thread");
......@@ -2748,51 +2748,6 @@ static bool cache_thread(THD *thd)
}
/*
End thread for the current connection
SYNOPSIS
one_thread_per_connection_end()
thd Thread handler. This may be null if we run out of resources.
put_in_cache Store thread in cache, if there is room in it
Normally this is true in all cases except when we got
out of resources initializing the current thread
NOTES
If thread is cached, we will wait until thread is scheduled to be
reused and then we will return.
If thread is not cached, we end the thread.
RETURN
0 Signal to handle_one_connection to reuse connection
*/
bool one_thread_per_connection_end(THD *thd, bool put_in_cache)
{
DBUG_ENTER("one_thread_per_connection_end");
if (thd)
{
const bool wsrep_applier= IF_WSREP(thd->wsrep_applier, false);
unlink_thd(thd);
if (!wsrep_applier && put_in_cache && cache_thread(thd))
DBUG_RETURN(0); // Thread is reused
delete thd;
}
DBUG_PRINT("info", ("killing thread"));
DBUG_LEAVE; // Must match DBUG_ENTER()
#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
ERR_remove_state(0);
#endif
my_thread_end();
pthread_exit(0);
return 0; // Avoid compiler warnings
}
void flush_thread_cache()
{
DBUG_ENTER("flush_thread_cache");
......@@ -6177,8 +6132,7 @@ void inc_thread_created(void)
void handle_connection_in_main_thread(CONNECT *connect)
{
thread_cache_size= 0; // Safety
do_handle_one_connection(connect);
do_handle_one_connection(connect, false);
}
......
......@@ -79,7 +79,7 @@ void close_connection(THD *thd, uint sql_errno= 0);
void handle_connection_in_main_thread(CONNECT *thd);
void create_thread_to_handle_connection(CONNECT *connect);
void unlink_thd(THD *thd);
bool one_thread_per_connection_end(THD *thd, bool put_in_cache);
bool cache_thread(THD *thd);
void flush_thread_cache();
void refresh_status(THD *thd);
bool is_secure_file_path(char *path);
......
......@@ -29,20 +29,6 @@
#include "sql_callback.h"
#include <violite.h>
/*
End connection, in case when we are using 'no-threads'
*/
static bool no_threads_end(THD *thd, bool put_in_cache)
{
if (thd)
{
unlink_thd(thd);
delete thd;
}
return 1; // Abort handle_one_connection
}
/** @internal
Helper functions to allow mysys to call the thread scheduler when
waiting for locks.
......@@ -133,7 +119,6 @@ void one_thread_per_connection_scheduler(scheduler_functions *func,
func->max_connections= arg_max_connections;
func->connection_count= arg_connection_count;
func->add_connection= create_thread_to_handle_connection;
func->end_thread= one_thread_per_connection_end;
func->post_kill_notification= post_kill_notification;
}
#else
......@@ -153,5 +138,4 @@ void one_thread_scheduler(scheduler_functions *func)
func->max_connections= &max_connections;
func->connection_count= &connection_count;
func->add_connection= handle_connection_in_main_thread;
func->end_thread= no_threads_end;
}
......@@ -38,7 +38,6 @@ struct scheduler_functions
void (*thd_wait_begin)(THD *thd, int wait_type);
void (*thd_wait_end)(THD *thd);
void (*post_kill_notification)(THD *thd);
bool (*end_thread)(THD *thd, bool cache_thread);
void (*end)(void);
};
......
......@@ -1112,7 +1112,6 @@ bool setup_connection_thread_globals(THD *thd)
close_connection(thd, ER_OUT_OF_RESOURCES);
statistic_increment(aborted_connects,&LOCK_status);
statistic_increment(connection_errors_internal, &LOCK_status);
thd->scheduler->end_thread(thd, 0);
return 1; // Error
}
return 0;
......@@ -1304,14 +1303,15 @@ pthread_handler_t handle_one_connection(void *arg)
mysql_thread_set_psi_id(connect->thread_id);
if (init_new_connection_handler_thread())
{
scheduler_functions *scheduler= connect->scheduler;
connect->close_with_error(0, 0, ER_OUT_OF_RESOURCES);
scheduler->end_thread(0, 0);
return 0;
}
else
do_handle_one_connection(connect, true);
do_handle_one_connection(connect);
DBUG_PRINT("info", ("killing thread"));
#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
ERR_remove_state(0);
#endif
my_thread_end();
return 0;
}
......@@ -1344,15 +1344,13 @@ bool thd_is_connection_alive(THD *thd)
}
void do_handle_one_connection(CONNECT *connect)
void do_handle_one_connection(CONNECT *connect, bool put_in_cache)
{
ulonglong thr_create_utime= microsecond_interval_timer();
THD *thd;
if (!(thd= connect->create_thd(NULL)))
{
scheduler_functions *scheduler= connect->scheduler;
connect->close_with_error(0, 0, ER_OUT_OF_RESOURCES);
scheduler->end_thread(0, 0);
return;
}
......@@ -1388,7 +1386,11 @@ void do_handle_one_connection(CONNECT *connect)
*/
thd->thread_stack= (char*) &thd;
if (setup_connection_thread_globals(thd))
{
unlink_thd(thd);
delete thd;
return;
}
for (;;)
{
......@@ -1422,16 +1424,12 @@ void do_handle_one_connection(CONNECT *connect)
if (thd->userstat_running)
update_global_user_stats(thd, create_user, time(NULL));
if (thd->scheduler->end_thread(thd, 1))
return; // Probably no-threads
/*
If end_thread() returns, this thread has been schedule to
handle the next connection.
*/
thd= current_thd;
thd->thread_stack= (char*) &thd;
unlink_thd(thd);
if (IF_WSREP(thd->wsrep_applier, false) || !put_in_cache ||
!cache_thread(thd))
break;
}
delete thd;
}
#endif /* EMBEDDED_LIBRARY */
......
......@@ -73,7 +73,7 @@ void free_global_index_stats(void);
void free_global_client_stats(void);
pthread_handler_t handle_one_connection(void *arg);
void do_handle_one_connection(CONNECT *connect);
void do_handle_one_connection(CONNECT *connect, bool put_in_cache);
bool init_new_connection_handler_thread();
void reset_mqh(LEX_USER *lu, bool get_them);
bool check_mqh(THD *thd, uint check_command);
......
......@@ -380,14 +380,6 @@ static int threadpool_process_request(THD *thd)
}
/* Dummy functions, do nothing */
static bool tp_end_thread(THD *, bool)
{
return 0;
}
static TP_pool *pool;
static bool tp_init()
......@@ -511,7 +503,6 @@ static scheduler_functions tp_scheduler_functions=
tp_wait_begin, // thd_wait_begin
tp_wait_end, // thd_wait_end
tp_post_kill_notification, // post kill notification
tp_end_thread, // Dummy function
tp_end // end
};
......
......@@ -2638,7 +2638,7 @@ void* start_wsrep_THD(void *arg)
{
close_connection(thd, ER_OUT_OF_RESOURCES);
statistic_increment(aborted_connects,&LOCK_status);
MYSQL_CALLBACK(thread_scheduler, end_thread, (thd, 0));
unlink_thd(thd);
delete thd;
delete thd_args;
goto error;
......@@ -2685,7 +2685,7 @@ void* start_wsrep_THD(void *arg)
if (plugins_are_initialized)
{
net_end(&thd->net);
MYSQL_CALLBACK(thread_scheduler, end_thread, (thd, 1));
unlink_thd(thd);
}
else
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment