summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Vojtovich <svoj@mariadb.org>2019-05-17 00:38:35 +0400
committerSergey Vojtovich <svoj@mariadb.org>2019-05-21 17:55:09 +0400
commitce30c994781aa78a3cf3f028deefaf059f20f108 (patch)
treec5464adcd163363ee4b36eaba7fa69305020ae07
parentefb61c12a929ae176b495e95d8995d9cac649b2d (diff)
downloadmariadb-git-ce30c994781aa78a3cf3f028deefaf059f20f108.tar.gz
Moved vio allocation to connection thread
Part of MDEV-19515 - Improve connect speed
-rw-r--r--sql/handle_connections_win.cc8
-rw-r--r--sql/mysqld.cc33
-rw-r--r--sql/sql_connect.cc35
-rw-r--r--sql/sql_connect.h22
-rw-r--r--sql/threadpool_generic.cc9
-rw-r--r--sql/threadpool_win.cc7
6 files changed, 58 insertions, 56 deletions
diff --git a/sql/handle_connections_win.cc b/sql/handle_connections_win.cc
index 2e1e452ddc1..3b29ad439ac 100644
--- a/sql/handle_connections_win.cc
+++ b/sql/handle_connections_win.cc
@@ -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.*/
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 63238447e38..cd25593b51d 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -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
diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc
index b88cfcc5025..25a260b2eba 100644
--- a/sql/sql_connect.cc
+++ b/sql/sql_connect.cc
@@ -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()))
{
diff --git a/sql/sql_connect.h b/sql/sql_connect.h
index 60c6bd5497d..8b574bcf385 100644
--- a/sql/sql_connect.h
+++ b/sql/sql_connect.h
@@ -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);
diff --git a/sql/threadpool_generic.cc b/sql/threadpool_generic.cc
index e37fd6f0cf4..74c359a4153 100644
--- a/sql/threadpool_generic.cc
+++ b/sql/threadpool_generic.cc
@@ -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. */
diff --git a/sql/threadpool_win.cc b/sql/threadpool_win.cc
index 67a8e783208..5c12d53ab0e 100644
--- a/sql/threadpool_win.cc
+++ b/sql/threadpool_win.cc
@@ -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();