mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
Moved vio allocation to connection thread
Part of MDEV-19515 - Improve connect speed
This commit is contained in:
@ -367,16 +367,14 @@ struct Pipe_Listener : public Listener
|
||||
|
||||
static void create_pipe_connection(HANDLE pipe)
|
||||
{
|
||||
CONNECT *connect;
|
||||
if (!(connect= new CONNECT) || !(connect->vio= vio_new_win32pipe(pipe)))
|
||||
if (auto connect= new CONNECT(pipe))
|
||||
create_new_thread(connect);
|
||||
else
|
||||
{
|
||||
CloseHandle(pipe);
|
||||
delete connect;
|
||||
statistic_increment(aborted_connects, &LOCK_status);
|
||||
statistic_increment(connection_errors_internal, &LOCK_status);
|
||||
return;
|
||||
}
|
||||
create_new_thread(connect);
|
||||
}
|
||||
|
||||
/* Threadpool callback.*/
|
||||
|
@ -6293,8 +6293,6 @@ void create_new_thread(CONNECT *connect)
|
||||
|
||||
void handle_accepted_socket(MYSQL_SOCKET new_sock, MYSQL_SOCKET sock)
|
||||
{
|
||||
CONNECT *connect;
|
||||
|
||||
#ifdef HAVE_LIBWRAP
|
||||
{
|
||||
if (mysql_socket_getfd(sock) == mysql_socket_getfd(base_ip_sock) ||
|
||||
@ -6340,34 +6338,21 @@ void handle_accepted_socket(MYSQL_SOCKET new_sock, MYSQL_SOCKET sock)
|
||||
|
||||
DBUG_PRINT("info", ("Creating CONNECT for new connection"));
|
||||
|
||||
if ((connect= new CONNECT()))
|
||||
{
|
||||
bool is_unix_sock= mysql_socket_getfd(sock) ==
|
||||
mysql_socket_getfd(unix_sock);
|
||||
|
||||
if (!(connect->vio=
|
||||
mysql_socket_vio_new(new_sock,
|
||||
is_unix_sock ? VIO_TYPE_SOCKET :
|
||||
VIO_TYPE_TCPIP,
|
||||
is_unix_sock ? VIO_LOCALHOST : 0)))
|
||||
{
|
||||
delete connect;
|
||||
connect= 0; // Error handling below
|
||||
}
|
||||
}
|
||||
|
||||
if (!connect)
|
||||
if (auto connect= new CONNECT(new_sock,
|
||||
mysql_socket_getfd(sock) ==
|
||||
mysql_socket_getfd(unix_sock) ?
|
||||
VIO_TYPE_SOCKET : VIO_TYPE_TCPIP,
|
||||
mysql_socket_getfd(sock) ==
|
||||
mysql_socket_getfd(extra_ip_sock) ?
|
||||
extra_thread_scheduler : thread_scheduler))
|
||||
create_new_thread(connect);
|
||||
else
|
||||
{
|
||||
/* Connect failure */
|
||||
(void)mysql_socket_close(new_sock);
|
||||
statistic_increment(aborted_connects, &LOCK_status);
|
||||
statistic_increment(connection_errors_internal, &LOCK_status);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mysql_socket_getfd(sock) == mysql_socket_getfd(extra_ip_sock))
|
||||
connect->scheduler= extra_thread_scheduler;
|
||||
create_new_thread(connect);
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
|
@ -1441,8 +1441,15 @@ void CONNECT::close_and_delete()
|
||||
{
|
||||
DBUG_ENTER("close_and_delete");
|
||||
|
||||
if (vio)
|
||||
vio_close(vio);
|
||||
#if _WIN32
|
||||
if (vio_type == VIO_TYPE_NAMEDPIPE)
|
||||
CloseHandle(pipe);
|
||||
else
|
||||
#endif
|
||||
if (vio_type != VIO_CLOSED)
|
||||
mysql_socket_close(sock);
|
||||
vio_type= VIO_CLOSED;
|
||||
|
||||
if (thread_count_incremented)
|
||||
dec_connection_count(scheduler);
|
||||
statistic_increment(connection_errors_internal, &LOCK_status);
|
||||
@ -1473,18 +1480,12 @@ void CONNECT::close_with_error(uint sql_errno,
|
||||
}
|
||||
|
||||
|
||||
CONNECT::~CONNECT()
|
||||
{
|
||||
if (vio)
|
||||
vio_delete(vio);
|
||||
}
|
||||
|
||||
|
||||
/* Reuse or create a THD based on a CONNECT object */
|
||||
|
||||
THD *CONNECT::create_thd(THD *thd)
|
||||
{
|
||||
bool res, thd_reused= thd != 0;
|
||||
Vio *vio;
|
||||
DBUG_ENTER("create_thd");
|
||||
|
||||
DBUG_EXECUTE_IF("simulate_failed_connection_2", DBUG_RETURN(0); );
|
||||
@ -1503,9 +1504,23 @@ THD *CONNECT::create_thd(THD *thd)
|
||||
else if (!(thd= new THD(thread_id)))
|
||||
DBUG_RETURN(0);
|
||||
|
||||
#if _WIN32
|
||||
if (vio_type == VIO_TYPE_NAMEDPIPE)
|
||||
vio= vio_new_win32pipe(pipe);
|
||||
else
|
||||
#endif
|
||||
vio= mysql_socket_vio_new(sock, vio_type, vio_type == VIO_TYPE_SOCKET ?
|
||||
VIO_LOCALHOST : 0);
|
||||
if (!vio)
|
||||
{
|
||||
if (!thd_reused)
|
||||
delete thd;
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
|
||||
set_current_thd(thd);
|
||||
res= my_net_init(&thd->net, vio, thd, MYF(MY_THREAD_SPECIFIC));
|
||||
vio= 0; // Vio now handled by thd
|
||||
vio_type= VIO_CLOSED; // Vio now handled by thd
|
||||
|
||||
if (unlikely(res || thd->is_error()))
|
||||
{
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "structs.h"
|
||||
#include <mysql/psi/mysql_socket.h>
|
||||
#include <hash.h>
|
||||
#include "violite.h"
|
||||
|
||||
/*
|
||||
Object to hold connect information to be given to the newly created thread
|
||||
@ -30,8 +31,14 @@ struct scheduler_functions;
|
||||
|
||||
class CONNECT : public ilink {
|
||||
public:
|
||||
/* To be copied to THD */
|
||||
Vio *vio; /* Copied to THD with my_net_init() */
|
||||
MYSQL_SOCKET sock;
|
||||
#ifdef _WIN32
|
||||
HANDLE pipe;
|
||||
CONNECT(HANDLE pipe_arg): pipe(pipe_arg), vio_type(VIO_TYPE_NAMEDPIPE),
|
||||
scheduler(thread_scheduler), thread_id(0), thread_count_incremented(0),
|
||||
prior_thr_create_utime(0) {}
|
||||
#endif
|
||||
enum enum_vio_type vio_type;
|
||||
scheduler_functions *scheduler;
|
||||
my_thread_id thread_id;
|
||||
|
||||
@ -39,12 +46,11 @@ public:
|
||||
bool thread_count_incremented;
|
||||
ulonglong prior_thr_create_utime;
|
||||
|
||||
CONNECT()
|
||||
:vio(0), scheduler(thread_scheduler), thread_id(0),
|
||||
thread_count_incremented(0), prior_thr_create_utime(0)
|
||||
{
|
||||
};
|
||||
~CONNECT();
|
||||
CONNECT(MYSQL_SOCKET sock_arg, enum enum_vio_type vio_type_arg,
|
||||
scheduler_functions *scheduler_arg): sock(sock_arg),
|
||||
vio_type(vio_type_arg), scheduler(scheduler_arg), thread_id(0),
|
||||
thread_count_incremented(0), prior_thr_create_utime(0) {}
|
||||
~CONNECT() { DBUG_ASSERT(vio_type == VIO_CLOSED); }
|
||||
void close_and_delete();
|
||||
void close_with_error(uint sql_errno,
|
||||
const char *message, uint close_error);
|
||||
|
@ -1433,14 +1433,13 @@ TP_connection_generic::TP_connection_generic(CONNECT *c):
|
||||
, overlapped()
|
||||
#endif
|
||||
{
|
||||
DBUG_ASSERT(c->vio);
|
||||
DBUG_ASSERT(c->vio_type != VIO_CLOSED);
|
||||
|
||||
#ifdef _WIN32
|
||||
vio_type= c->vio->type;
|
||||
fd= (vio_type == VIO_TYPE_NAMEDPIPE) ?
|
||||
c->vio->hPipe: (TP_file_handle)mysql_socket_getfd(c->vio->mysql_socket);
|
||||
fd= (c->vio_type == VIO_TYPE_NAMEDPIPE) ?
|
||||
c->pipe: (TP_file_handle) mysql_socket_getfd(c->sock);
|
||||
#else
|
||||
fd= mysql_socket_getfd(c->vio->mysql_socket);
|
||||
fd= mysql_socket_getfd(c->sock);
|
||||
#endif
|
||||
|
||||
/* Assign connection to a group. */
|
||||
|
@ -167,15 +167,14 @@ int TP_connection_win::init()
|
||||
{
|
||||
|
||||
memset(&overlapped, 0, sizeof(OVERLAPPED));
|
||||
Vio *vio = connect->vio;
|
||||
switch ((vio_type = vio->type))
|
||||
switch ((vio_type = connect->vio_type))
|
||||
{
|
||||
case VIO_TYPE_SSL:
|
||||
case VIO_TYPE_TCPIP:
|
||||
handle= (HANDLE)mysql_socket_getfd(vio->mysql_socket);
|
||||
handle= (HANDLE) mysql_socket_getfd(connect->sock);
|
||||
break;
|
||||
case VIO_TYPE_NAMEDPIPE:
|
||||
handle= (HANDLE)vio->hPipe;
|
||||
handle= connect->pipe;
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
|
Reference in New Issue
Block a user