MDEV-156 Threadpool - add thd_wait_begin/thd_wait_end to the network IO functions
This commit is contained in:
parent
35bc8f9f43
commit
41013f16a0
@ -43,7 +43,8 @@ typedef enum _thd_wait_type_e {
|
|||||||
THD_WAIT_BINLOG= 8,
|
THD_WAIT_BINLOG= 8,
|
||||||
THD_WAIT_GROUP_COMMIT= 9,
|
THD_WAIT_GROUP_COMMIT= 9,
|
||||||
THD_WAIT_SYNC= 10,
|
THD_WAIT_SYNC= 10,
|
||||||
THD_WAIT_LAST= 11
|
THD_WAIT_NET= 11,
|
||||||
|
THD_WAIT_LAST= 12
|
||||||
} thd_wait_type;
|
} thd_wait_type;
|
||||||
extern struct thd_wait_service_st {
|
extern struct thd_wait_service_st {
|
||||||
void (*thd_wait_begin_func)(void*, int);
|
void (*thd_wait_begin_func)(void*, int);
|
||||||
|
@ -43,7 +43,8 @@ typedef enum _thd_wait_type_e {
|
|||||||
THD_WAIT_BINLOG= 8,
|
THD_WAIT_BINLOG= 8,
|
||||||
THD_WAIT_GROUP_COMMIT= 9,
|
THD_WAIT_GROUP_COMMIT= 9,
|
||||||
THD_WAIT_SYNC= 10,
|
THD_WAIT_SYNC= 10,
|
||||||
THD_WAIT_LAST= 11
|
THD_WAIT_NET= 11,
|
||||||
|
THD_WAIT_LAST= 12
|
||||||
} thd_wait_type;
|
} thd_wait_type;
|
||||||
extern struct thd_wait_service_st {
|
extern struct thd_wait_service_st {
|
||||||
void (*thd_wait_begin_func)(void*, int);
|
void (*thd_wait_begin_func)(void*, int);
|
||||||
|
@ -43,7 +43,8 @@ typedef enum _thd_wait_type_e {
|
|||||||
THD_WAIT_BINLOG= 8,
|
THD_WAIT_BINLOG= 8,
|
||||||
THD_WAIT_GROUP_COMMIT= 9,
|
THD_WAIT_GROUP_COMMIT= 9,
|
||||||
THD_WAIT_SYNC= 10,
|
THD_WAIT_SYNC= 10,
|
||||||
THD_WAIT_LAST= 11
|
THD_WAIT_NET= 11,
|
||||||
|
THD_WAIT_LAST= 12
|
||||||
} thd_wait_type;
|
} thd_wait_type;
|
||||||
extern struct thd_wait_service_st {
|
extern struct thd_wait_service_st {
|
||||||
void (*thd_wait_begin_func)(void*, int);
|
void (*thd_wait_begin_func)(void*, int);
|
||||||
|
@ -74,7 +74,8 @@ typedef enum _thd_wait_type_e {
|
|||||||
THD_WAIT_BINLOG= 8,
|
THD_WAIT_BINLOG= 8,
|
||||||
THD_WAIT_GROUP_COMMIT= 9,
|
THD_WAIT_GROUP_COMMIT= 9,
|
||||||
THD_WAIT_SYNC= 10,
|
THD_WAIT_SYNC= 10,
|
||||||
THD_WAIT_LAST= 11
|
THD_WAIT_NET= 11,
|
||||||
|
THD_WAIT_LAST= 12
|
||||||
} thd_wait_type;
|
} thd_wait_type;
|
||||||
|
|
||||||
extern struct thd_wait_service_st {
|
extern struct thd_wait_service_st {
|
||||||
|
@ -105,7 +105,9 @@ my_bool vio_is_connected(Vio *vio);
|
|||||||
ssize_t vio_pending(Vio *vio);
|
ssize_t vio_pending(Vio *vio);
|
||||||
#endif
|
#endif
|
||||||
/* Set timeout for a network operation. */
|
/* Set timeout for a network operation. */
|
||||||
int vio_timeout(Vio *vio, uint which, int timeout_sec);
|
extern int vio_timeout(Vio *vio, uint which, int timeout_sec);
|
||||||
|
extern void vio_set_wait_callback(void (*before_wait)(void),
|
||||||
|
void (*after_wait)(void));
|
||||||
/* Connect to a peer. */
|
/* Connect to a peer. */
|
||||||
my_bool vio_socket_connect(Vio *vio, struct sockaddr *addr, socklen_t len,
|
my_bool vio_socket_connect(Vio *vio, struct sockaddr *addr, socklen_t len,
|
||||||
int timeout);
|
int timeout);
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "mysqld.h"
|
#include "mysqld.h"
|
||||||
#include "sql_class.h"
|
#include "sql_class.h"
|
||||||
#include "sql_callback.h"
|
#include "sql_callback.h"
|
||||||
|
#include <violite.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
End connection, in case when we are using 'no-threads'
|
End connection, in case when we are using 'no-threads'
|
||||||
@ -61,6 +62,15 @@ static void scheduler_wait_sync_begin(void) {
|
|||||||
static void scheduler_wait_sync_end(void) {
|
static void scheduler_wait_sync_end(void) {
|
||||||
thd_wait_end(NULL);
|
thd_wait_end(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void scheduler_wait_net_begin(void) {
|
||||||
|
thd_wait_begin(NULL, THD_WAIT_NET);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void scheduler_wait_net_end(void) {
|
||||||
|
thd_wait_end(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
/**@}*/
|
/**@}*/
|
||||||
|
|
||||||
@ -76,6 +86,9 @@ void scheduler_init() {
|
|||||||
scheduler_wait_lock_end);
|
scheduler_wait_lock_end);
|
||||||
thr_set_sync_wait_callback(scheduler_wait_sync_begin,
|
thr_set_sync_wait_callback(scheduler_wait_sync_begin,
|
||||||
scheduler_wait_sync_end);
|
scheduler_wait_sync_end);
|
||||||
|
|
||||||
|
vio_set_wait_callback(scheduler_wait_net_begin,
|
||||||
|
scheduler_wait_net_end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,6 +37,38 @@
|
|||||||
# include <sys/filio.h>
|
# include <sys/filio.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Network io wait callbacks for threadpool */
|
||||||
|
static void (*before_io_wait)(void)= 0;
|
||||||
|
static void (*after_io_wait)(void)= 0;
|
||||||
|
|
||||||
|
/* Wait callback macros (both performance schema and threadpool */
|
||||||
|
#define START_SOCKET_WAIT(locker, state_ptr, sock, which) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
MYSQL_START_SOCKET_WAIT(locker, state_ptr, sock, \
|
||||||
|
which, 0); \
|
||||||
|
if (before_io_wait) \
|
||||||
|
before_io_wait(); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
|
|
||||||
|
#define END_SOCKET_WAIT(locker) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
MYSQL_END_SOCKET_WAIT(locker, 0); \
|
||||||
|
if (after_io_wait) \
|
||||||
|
after_io_wait(); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void vio_set_wait_callback(void (*before_wait)(void),
|
||||||
|
void (*after_wait)(void))
|
||||||
|
{
|
||||||
|
before_io_wait= before_wait;
|
||||||
|
after_io_wait= after_wait;
|
||||||
|
}
|
||||||
|
|
||||||
int vio_errno(Vio *vio __attribute__((unused)))
|
int vio_errno(Vio *vio __attribute__((unused)))
|
||||||
{
|
{
|
||||||
/* These transport types are not Winsock based. */
|
/* These transport types are not Winsock based. */
|
||||||
@ -903,12 +935,12 @@ int vio_io_wait(Vio *vio, enum enum_vio_io_event event, int timeout)
|
|||||||
*/
|
*/
|
||||||
if (timeout != 0 && vio->async_context && vio->async_context->active)
|
if (timeout != 0 && vio->async_context && vio->async_context->active)
|
||||||
{
|
{
|
||||||
MYSQL_START_SOCKET_WAIT(locker, &state, vio->mysql_socket,
|
START_SOCKET_WAIT(locker, &state, vio->mysql_socket,
|
||||||
PSI_SOCKET_SELECT, 0);
|
PSI_SOCKET_SELECT);
|
||||||
ret= my_io_wait_async(vio->async_context, event, timeout);
|
ret= my_io_wait_async(vio->async_context, event, timeout);
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
errno= SOCKET_ETIMEDOUT;
|
errno= SOCKET_ETIMEDOUT;
|
||||||
MYSQL_END_SOCKET_WAIT(locker, 0);
|
END_SOCKET_WAIT(locker);
|
||||||
DBUG_RETURN(ret);
|
DBUG_RETURN(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -933,8 +965,7 @@ int vio_io_wait(Vio *vio, enum enum_vio_io_event event, int timeout)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
MYSQL_START_SOCKET_WAIT(locker, &state, vio->mysql_socket, PSI_SOCKET_SELECT, 0);
|
START_SOCKET_WAIT(locker, &state, vio->mysql_socket, PSI_SOCKET_SELECT);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Wait for the I/O event and return early in case of
|
Wait for the I/O event and return early in case of
|
||||||
error or timeout.
|
error or timeout.
|
||||||
@ -957,7 +988,7 @@ int vio_io_wait(Vio *vio, enum enum_vio_io_event event, int timeout)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
MYSQL_END_SOCKET_WAIT(locker, 0);
|
END_SOCKET_WAIT(locker);
|
||||||
DBUG_RETURN(ret);
|
DBUG_RETURN(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -978,12 +1009,12 @@ int vio_io_wait(Vio *vio, enum enum_vio_io_event event, int timeout)
|
|||||||
*/
|
*/
|
||||||
if (timeout != 0 && vio->async_context && vio->async_context->active)
|
if (timeout != 0 && vio->async_context && vio->async_context->active)
|
||||||
{
|
{
|
||||||
MYSQL_START_SOCKET_WAIT(locker, &state, vio->mysql_socket,
|
START_SOCKET_WAIT(locker, &state, vio->mysql_socket,
|
||||||
PSI_SOCKET_SELECT, 0);
|
PSI_SOCKET_SELECT);
|
||||||
ret= my_io_wait_async(vio->async_context, event, timeout);
|
ret= my_io_wait_async(vio->async_context, event, timeout);
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
WSASetLastError(SOCKET_ETIMEDOUT);
|
WSASetLastError(SOCKET_ETIMEDOUT);
|
||||||
MYSQL_END_SOCKET_WAIT(locker, 0);
|
END_SOCKET_WAIT(locker);
|
||||||
DBUG_RETURN(ret);
|
DBUG_RETURN(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1014,12 +1045,12 @@ int vio_io_wait(Vio *vio, enum enum_vio_io_event event, int timeout)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
MYSQL_START_SOCKET_WAIT(locker, &state, vio->mysql_socket, PSI_SOCKET_SELECT, 0);
|
START_SOCKET_WAIT(locker, &state, vio->mysql_socket, PSI_SOCKET_SELECT);
|
||||||
|
|
||||||
/* The first argument is ignored on Windows. */
|
/* The first argument is ignored on Windows. */
|
||||||
ret= select(0, &readfds, &writefds, &exceptfds, (timeout >= 0) ? &tm : NULL);
|
ret= select(0, &readfds, &writefds, &exceptfds, (timeout >= 0) ? &tm : NULL);
|
||||||
|
|
||||||
MYSQL_END_SOCKET_WAIT(locker, 0);
|
END_SOCKET_WAIT(locker);
|
||||||
|
|
||||||
/* Set error code to indicate a timeout error. */
|
/* Set error code to indicate a timeout error. */
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user