Added session timeouts.
The parameter 'connection_timeout' for services takes a value as seconds. All sessions that have been idle for longer than this will be disconnected.
This commit is contained in:
parent
3145ebac43
commit
c47d2f3791
@ -40,6 +40,7 @@
|
||||
* internal router suppression of messages
|
||||
* 30/10/14 Massimiliano Pinto Added disable_master_failback parameter
|
||||
* 07/11/14 Massimiliano Pinto Addition of monitor timeouts for connect/read/write
|
||||
* 20/02/15 Markus Mäkelä Added connection_timeout parameter for services
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
@ -278,6 +279,7 @@ int error_count = 0;
|
||||
char *user;
|
||||
char *auth;
|
||||
char *enable_root_user;
|
||||
char *connection_timeout;
|
||||
char *weightby;
|
||||
char *version_string;
|
||||
bool is_rwsplit = false;
|
||||
@ -288,6 +290,9 @@ int error_count = 0;
|
||||
enable_root_user = config_get_value(
|
||||
obj->parameters,
|
||||
"enable_root_user");
|
||||
connection_timeout = config_get_value(
|
||||
obj->parameters,
|
||||
"connection_timeout");
|
||||
weightby = config_get_value(obj->parameters, "weightby");
|
||||
|
||||
version_string = config_get_value(obj->parameters,
|
||||
@ -332,6 +337,11 @@ int error_count = 0;
|
||||
serviceEnableRootUser(
|
||||
obj->element,
|
||||
config_truth_value(enable_root_user));
|
||||
if (connection_timeout)
|
||||
serviceSetTimeout(
|
||||
obj->element,
|
||||
atoi(connection_timeout));
|
||||
|
||||
if (weightby)
|
||||
serviceWeightBy(obj->element, weightby);
|
||||
|
||||
@ -1281,13 +1291,15 @@ SERVER *server;
|
||||
char *user;
|
||||
char *auth;
|
||||
char *enable_root_user;
|
||||
char *connection_timeout;
|
||||
char* max_slave_conn_str;
|
||||
char* max_slave_rlag_str;
|
||||
char *version_string;
|
||||
char *allow_localhost_match_wildcard_host;
|
||||
|
||||
enable_root_user = config_get_value(obj->parameters, "enable_root_user");
|
||||
|
||||
connection_timeout = config_get_value(obj->parameters, "connection_timeout");
|
||||
|
||||
user = config_get_value(obj->parameters,
|
||||
"user");
|
||||
auth = config_get_value(obj->parameters,
|
||||
@ -1310,6 +1322,8 @@ SERVER *server;
|
||||
auth);
|
||||
if (enable_root_user)
|
||||
serviceEnableRootUser(service, atoi(enable_root_user));
|
||||
if (connection_timeout)
|
||||
serviceSetTimeout(service, atoi(connection_timeout));
|
||||
|
||||
if (allow_localhost_match_wildcard_host)
|
||||
serviceEnableLocalhostMatchWildcardHost(
|
||||
@ -1415,11 +1429,17 @@ SERVER *server;
|
||||
char *user;
|
||||
char *auth;
|
||||
char *enable_root_user;
|
||||
char *connection_timeout;
|
||||
char *allow_localhost_match_wildcard_host;
|
||||
|
||||
enable_root_user =
|
||||
config_get_value(obj->parameters,
|
||||
"enable_root_user");
|
||||
|
||||
connection_timeout =
|
||||
config_get_value(obj->parameters,
|
||||
"connection_timeout");
|
||||
|
||||
allow_localhost_match_wildcard_host =
|
||||
config_get_value(obj->parameters, "localhost_match_wildcard_host");
|
||||
|
||||
@ -1438,6 +1458,9 @@ SERVER *server;
|
||||
if (enable_root_user)
|
||||
serviceEnableRootUser(obj->element, atoi(enable_root_user));
|
||||
|
||||
if (connection_timeout)
|
||||
serviceSetTimeout(obj->element, atoi(connection_timeout));
|
||||
|
||||
if (allow_localhost_match_wildcard_host)
|
||||
serviceEnableLocalhostMatchWildcardHost(
|
||||
obj->element,
|
||||
@ -1661,6 +1684,7 @@ static char *service_params[] =
|
||||
"user",
|
||||
"passwd",
|
||||
"enable_root_user",
|
||||
"connection_timeout",
|
||||
"localhost_match_wildcard_host",
|
||||
"max_slave_connections",
|
||||
"max_slave_replication_lag",
|
||||
|
@ -57,6 +57,7 @@
|
||||
#include <log_manager.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <housekeeper.h>
|
||||
|
||||
/** Defined in log_manager.cc */
|
||||
extern int lm_enabled_logfiles_bitmask;
|
||||
@ -431,6 +432,8 @@ int listeners = 0;
|
||||
service->stats.started = time(0);
|
||||
}
|
||||
|
||||
hktask_add("connection_timeout",session_close_timeouts,NULL,5);
|
||||
|
||||
return listeners;
|
||||
}
|
||||
|
||||
@ -803,6 +806,23 @@ serviceEnableRootUser(SERVICE *service, int action)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the session timeout for the service.
|
||||
* @param service Service to configure
|
||||
* @param val Timeout in seconds
|
||||
* @return 1 on success, 0 when the value is invalid
|
||||
*/
|
||||
int
|
||||
serviceSetTimeout(SERVICE *service, int val)
|
||||
{
|
||||
|
||||
if(val < 0)
|
||||
return 0;
|
||||
service->conn_timeout = val;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim whitespace from the from an rear of a string
|
||||
*
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include <atomic.h>
|
||||
#include <skygw_utils.h>
|
||||
#include <log_manager.h>
|
||||
#include <housekeeper.h>
|
||||
|
||||
/** Defined in log_manager.cc */
|
||||
extern int lm_enabled_logfiles_bitmask;
|
||||
@ -909,3 +910,35 @@ SESSION *get_all_sessions()
|
||||
{
|
||||
return allSessions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close sessions that have been idle for too long.
|
||||
*
|
||||
* If the time since a session last sent data is grater than the set value in the
|
||||
* service, it is disconnected. The default value for the timeout for a service is 0.
|
||||
* This means that connections are never timed out.
|
||||
* @param data NULL, this is only here to satisfy the housekeeper function requirements.
|
||||
*/
|
||||
void session_close_timeouts(void* data)
|
||||
{
|
||||
SESSION* ses;
|
||||
|
||||
spinlock_acquire(&session_spin);
|
||||
ses = get_all_sessions();
|
||||
spinlock_release(&session_spin);
|
||||
|
||||
while(ses)
|
||||
{
|
||||
if(ses->client && ses->client->state == DCB_STATE_POLLING &&
|
||||
ses->service->conn_timeout > 0 &&
|
||||
hkheartbeat - ses->client->last_read > ses->service->conn_timeout * 10)
|
||||
{
|
||||
ses->client->func.hangup(ses->client);
|
||||
}
|
||||
|
||||
spinlock_acquire(&session_spin);
|
||||
ses = ses->next;
|
||||
spinlock_release(&session_spin);
|
||||
|
||||
}
|
||||
}
|
@ -261,7 +261,7 @@ typedef struct dcb {
|
||||
SPINLOCK polloutlock;
|
||||
int polloutbusy;
|
||||
int writecheck;
|
||||
|
||||
time_t last_read; /*< Last time the DCB received data */
|
||||
unsigned int high_water; /**< High water mark */
|
||||
unsigned int low_water; /**< Low water mark */
|
||||
struct server *server; /**< The associated backend server */
|
||||
|
@ -142,6 +142,7 @@ typedef struct service {
|
||||
rate_limit; /**< The refresh rate limit for users table */
|
||||
FILTER_DEF **filters; /**< Ordered list of filters */
|
||||
int n_filters; /**< Number of filters */
|
||||
int conn_timeout; /*< Session timeout in seconds */
|
||||
char *weightby;
|
||||
struct service *next; /**< The next service in the linked list */
|
||||
} SERVICE;
|
||||
@ -172,6 +173,7 @@ extern int serviceSetUser(SERVICE *, char *, char *);
|
||||
extern int serviceGetUser(SERVICE *, char **, char **);
|
||||
extern void serviceSetFilters(SERVICE *, char *);
|
||||
extern int serviceEnableRootUser(SERVICE *, int );
|
||||
extern int serviceSetTimeout(SERVICE *, int );
|
||||
extern void serviceWeightBy(SERVICE *, char *);
|
||||
extern char *serviceGetWeightingParameter(SERVICE *);
|
||||
extern int serviceEnableLocalhostMatchWildcardHost(SERVICE *, int);
|
||||
|
@ -33,6 +33,7 @@
|
||||
* 02-09-2013 Massimiliano Pinto Added session ref counter
|
||||
* 29-05-2014 Mark Riddoch Support for filter mechanism
|
||||
* added
|
||||
* 20-02-2015 Markus Mäkelä Added session timeouts
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
@ -167,5 +168,6 @@ bool session_link_dcb(SESSION *, struct dcb *);
|
||||
SESSION* get_session_by_router_ses(void* rses);
|
||||
void session_enable_log(SESSION* ses, logfile_id_t id);
|
||||
void session_disable_log(SESSION* ses, logfile_id_t id);
|
||||
void session_close_timeouts(void* data);
|
||||
|
||||
#endif
|
||||
|
@ -31,7 +31,7 @@
|
||||
*/
|
||||
#include <dcb.h>
|
||||
#include <spinlock.h>
|
||||
|
||||
#include <housekeeper.h>
|
||||
/**
|
||||
* The telnetd specific protocol structure to put in the DCB.
|
||||
*/
|
||||
|
@ -61,6 +61,7 @@
|
||||
#include <users.h>
|
||||
#include <dbusers.h>
|
||||
#include <version.h>
|
||||
#include <housekeeper.h>
|
||||
|
||||
#define GW_MYSQL_VERSION "MaxScale " MAXSCALE_VERSION
|
||||
#define GW_MYSQL_LOOP_TIMEOUT 300000000
|
||||
|
@ -30,7 +30,7 @@
|
||||
* @endverbatim
|
||||
*/
|
||||
#include <dcb.h>
|
||||
|
||||
#include <housekeeper.h>
|
||||
/**
|
||||
* The telnetd specific protocol structure to put in the DCB.
|
||||
*/
|
||||
|
@ -144,6 +144,9 @@ char *password;
|
||||
|
||||
if ((n = dcb_read(dcb, &head)) != -1)
|
||||
{
|
||||
|
||||
dcb->last_read = hkheartbeat;
|
||||
|
||||
if (head)
|
||||
{
|
||||
unsigned char *ptr = GWBUF_DATA(head);
|
||||
|
@ -448,6 +448,8 @@ static int gw_read_backend_event(DCB *dcb) {
|
||||
/* read available backend data */
|
||||
rc = dcb_read(dcb, &read_buffer);
|
||||
|
||||
dcb->last_read = hkheartbeat;
|
||||
|
||||
if (rc < 0)
|
||||
{
|
||||
GWBUF* errbuf;
|
||||
|
@ -576,6 +576,8 @@ int gw_read_client_event(
|
||||
CHK_PROTOCOL(protocol);
|
||||
rc = dcb_read(dcb, &read_buffer);
|
||||
|
||||
dcb->last_read = hkheartbeat;
|
||||
|
||||
if (rc < 0)
|
||||
{
|
||||
dcb_close(dcb);
|
||||
|
@ -170,6 +170,9 @@ int gw_read_backend_handshake(
|
||||
|
||||
if ((n = dcb_read(dcb, &head)) != -1)
|
||||
{
|
||||
|
||||
dcb->last_read = hkheartbeat;
|
||||
|
||||
if (head)
|
||||
{
|
||||
payload = GWBUF_DATA(head);
|
||||
@ -420,6 +423,8 @@ int gw_receive_backend_auth(
|
||||
|
||||
n = dcb_read(dcb, &head);
|
||||
|
||||
dcb->last_read = hkheartbeat;
|
||||
|
||||
/*<
|
||||
* Read didn't fail and there is enough data for mysql packet.
|
||||
*/
|
||||
|
@ -156,6 +156,9 @@ char *password, *t;
|
||||
|
||||
if ((n = dcb_read(dcb, &head)) != -1)
|
||||
{
|
||||
|
||||
dcb->last_read = hkheartbeat;
|
||||
|
||||
if (head)
|
||||
{
|
||||
unsigned char *ptr = GWBUF_DATA(head);
|
||||
|
Loading…
x
Reference in New Issue
Block a user