Added configurable timeouts for the embedded MySQL connections.
This commit is contained in:
Markus Makela 2015-09-07 18:51:01 +03:00
parent ee19fbd41b
commit 5350a85e2b
5 changed files with 61 additions and 30 deletions

View File

@ -66,6 +66,18 @@ threads=1
It should be noted that additional threads will be created to execute other internal services within MaxScale. This setting is used to configure the number of threads that will be used to manage the user connections.
#### `auth_connect_timeout`
The connection timeout in seconds for the MySQL connections to the backend server when user authentication data is fetched. Increasing the value of this parameter will cause MaxScale to wait longer for a response from the backend server before aborting the connection process when creating a new connection is made.
#### `auth_read_timeout`
The read timeout in seconds for the MySQL connection to the backend database when user authentication data is fetched. Increasing the value of this parameter will cause MaxScale to wait longer for a response from the backend server when user data is being actively fetched. If you have a large number of database users and grants and the authentication is failing, it is a good idea. Slower networks will also benefit from an increased timeout value.
#### `auth_write_timeout`
The write timeout in seconds for the MySQL connection to the backend database when user authentication data is fetched. Currently MaxScale does not write or modify the data in the backend server.
#### `ms_timestamp`
Enable or disable the high precision timestamps in logfiles. Enabling this adds millisecond precision to all logfile timestamps.

View File

@ -74,6 +74,7 @@
#include <string.h>
#include <sys/utsname.h>
#include <pcre.h>
#include <dbusers.h>
/** According to the PCRE manual, this should be a multiple of 3 */
#define MAXSCALE_PCRE_BUFSZ 24
@ -1542,6 +1543,33 @@ int i;
{
skygw_set_highp(config_truth_value((char*)value));
}
else if (strcmp(name, "auth_connect_timeout") == 0)
{
char* endptr;
int intval = strtol(value, &endptr, 0);
if(*endptr == '\0' && intval > 0)
gateway.auth_conn_timeout = intval;
else
skygw_log_write(LE, "Invalid timeout value for 'auth_connect_timeout': %s", value);
}
else if (strcmp(name, "auth_read_timeout") == 0)
{
char* endptr;
int intval = strtol(value, &endptr, 0);
if(*endptr == '\0' && intval > 0)
gateway.auth_read_timeout = intval;
else
skygw_log_write(LE, "Invalid timeout value for 'auth_read_timeout': %s", value);
}
else if (strcmp(name, "auth_write_timeout") == 0)
{
char* endptr;
int intval = strtol(value, &endptr, 0);
if(*endptr == '\0' && intval > 0)
gateway.auth_write_timeout = intval;
else
skygw_log_write(LE, "Invalid timeout value for 'auth_write_timeout': %s", value);
}
else
{
for (i = 0; lognames[i].logname; i++)
@ -1607,6 +1635,9 @@ global_defaults()
gateway.n_threads = 1;
gateway.n_nbpoll = DEFAULT_NBPOLLS;
gateway.pollsleep = DEFAULT_POLLSLEEP;
gateway.auth_conn_timeout = DEFAULT_AUTH_CONNECT_TIMEOUT;
gateway.auth_read_timeout = DEFAULT_AUTH_READ_TIMEOUT;
gateway.auth_write_timeout = DEFAULT_AUTH_WRITE_TIMEOUT;
if (version_string != NULL)
gateway.version_string = strdup(version_string);
else

View File

@ -52,11 +52,6 @@
#include <mysqld_error.h>
#include <regex.h>
#define DEFAULT_CONNECT_TIMEOUT 3
#define DEFAULT_READ_TIMEOUT 1
#define DEFAULT_WRITE_TIMEOUT 2
#define USERS_QUERY_NO_ROOT " AND user NOT IN ('root')"
#if 0
@ -121,11 +116,7 @@ int add_wildcard_users(USERS *users,
char* db,
HASHTABLE* hash);
static int gw_mysql_set_timeouts(
MYSQL* handle,
int read_timeout,
int write_timeout,
int connect_timeout);
static int gw_mysql_set_timeouts(MYSQL* handle);
/**
* Load the user/passwd form mysql.user table into the service users' hashtable
@ -630,10 +621,7 @@ getAllUsers(SERVICE *service, USERS *users)
}
/** Set read, write and connect timeout values */
if (gw_mysql_set_timeouts(con,
DEFAULT_READ_TIMEOUT,
DEFAULT_WRITE_TIMEOUT,
DEFAULT_CONNECT_TIMEOUT))
if (gw_mysql_set_timeouts(con))
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
@ -702,10 +690,7 @@ getAllUsers(SERVICE *service, USERS *users)
}
/** Set read, write and connect timeout values */
if (gw_mysql_set_timeouts(con,
DEFAULT_READ_TIMEOUT,
DEFAULT_WRITE_TIMEOUT,
DEFAULT_CONNECT_TIMEOUT))
if (gw_mysql_set_timeouts(con))
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
@ -1156,10 +1141,7 @@ getUsers(SERVICE *service, USERS *users)
return -1;
}
/** Set read, write and connect timeout values */
if (gw_mysql_set_timeouts(con,
DEFAULT_READ_TIMEOUT,
DEFAULT_WRITE_TIMEOUT,
DEFAULT_CONNECT_TIMEOUT))
if (gw_mysql_set_timeouts(con))
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
@ -2026,17 +2008,15 @@ int useorig = 0;
*
* @return 0 if succeed, 1 if failed
*/
static int gw_mysql_set_timeouts(
MYSQL* handle,
int read_timeout,
int write_timeout,
int connect_timeout)
static int gw_mysql_set_timeouts(MYSQL* handle)
{
int rc;
GATEWAY_CONF* cnf = config_get_global_options();
if ((rc = mysql_options(handle,
MYSQL_OPT_READ_TIMEOUT,
(void *)&read_timeout)))
(void *)&cnf->auth_read_timeout)))
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
@ -2047,7 +2027,7 @@ static int gw_mysql_set_timeouts(
if ((rc = mysql_options(handle,
MYSQL_OPT_CONNECT_TIMEOUT,
(void *)&connect_timeout)))
(void *)&cnf->auth_conn_timeout)))
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
@ -2058,7 +2038,7 @@ static int gw_mysql_set_timeouts(
if ((rc = mysql_options(handle,
MYSQL_OPT_WRITE_TIMEOUT,
(void *)&write_timeout)))
(void *)&cnf->auth_write_timeout)))
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,

View File

@ -42,6 +42,11 @@
#define USERS_REFRESH_TIME 30 /* Allowed time interval (in seconds) after last update*/
#define USERS_REFRESH_MAX_PER_TIME 4 /* Max number of load calls within the time interval */
/** Default timeout values used by the connections which fetch user authentication data */
#define DEFAULT_AUTH_CONNECT_TIMEOUT 3
#define DEFAULT_AUTH_READ_TIMEOUT 1
#define DEFAULT_AUTH_WRITE_TIMEOUT 2
/* Max length of fields in the mysql.user table */
#define MYSQL_USER_MAXLEN 128
#define MYSQL_PASSWORD_LEN 41

View File

@ -106,6 +106,9 @@ typedef struct {
unsigned int pollsleep; /**< Wait time in blocking polls */
int syslog; /*< Log to syslog */
int maxlog; /*< Log to MaxScale's own logs */
unsigned int auth_conn_timeout; /*< Connection timeout for the user authentication */
unsigned int auth_read_timeout; /*< Read timeout for the user authentication */
unsigned int auth_write_timeout; /*< Write timeout for the user authentication */
} GATEWAY_CONF;
extern int config_load(char *);