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