mirror of
https://gitee.com/wangbin579/cetus.git
synced 2024-12-03 12:27:42 +08:00
Merge pull request #62 from wangbin579/master
Add options for client idle timeout
This commit is contained in:
commit
3fecf07066
@ -141,7 +141,7 @@ NETWORK_MYSQLD_PLUGIN_PROTO(proxy_timeout)
|
||||
g_debug("%s, con:%p:call proxy_timeout", G_STRLOC, con);
|
||||
switch (con->state) {
|
||||
case ST_READ_QUERY:
|
||||
if (diff < 8 * HOURS) {
|
||||
if (diff < con->srv->client_idle_timeout) {
|
||||
if (con->server && !con->client->is_server_conn_reserved) {
|
||||
if (network_pool_add_conn(con, 0) != 0) {
|
||||
g_debug("%s, con:%p:conn to pool failed", G_STRLOC, con);
|
||||
@ -155,7 +155,7 @@ NETWORK_MYSQLD_PLUGIN_PROTO(proxy_timeout)
|
||||
}
|
||||
break;
|
||||
case ST_READ_QUERY_RESULT:
|
||||
if (diff < 8 * HOURS) {
|
||||
if (diff < con->srv->client_idle_timeout) {
|
||||
if (con->server && !con->client->is_server_conn_reserved) {
|
||||
con->server_to_be_closed = 1;
|
||||
g_critical("%s, con:%p read query result timeout, sql:%s", G_STRLOC, con, con->orig_sql->str);
|
||||
@ -171,7 +171,7 @@ NETWORK_MYSQLD_PLUGIN_PROTO(proxy_timeout)
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (diff >= 8 * HOURS) {
|
||||
if (diff >= con->srv->client_idle_timeout) {
|
||||
con->prev_state = con->state;
|
||||
con->state = ST_SEND_ERROR;
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ NETWORK_MYSQLD_PLUGIN_PROTO(proxy_timeout)
|
||||
break;
|
||||
default:
|
||||
diff = time(0) - con->client->create_or_update_time;
|
||||
if (diff < 8 * HOURS) {
|
||||
if (diff < con->srv->client_idle_timeout) {
|
||||
if (!con->client->is_server_conn_reserved) {
|
||||
g_debug("%s, is_server_conn_reserved is false", G_STRLOC);
|
||||
if (con->servers && con->servers->len > 0) {
|
||||
|
@ -136,6 +136,7 @@ struct chassis {
|
||||
unsigned int check_slave_delay;
|
||||
int complement_conn_cnt;
|
||||
int default_query_cache_timeout;
|
||||
int client_idle_timeout;
|
||||
double slave_delay_down_threshold_sec;
|
||||
double slave_delay_recover_threshold_sec;
|
||||
unsigned int long_query_time;
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
$%ENDLICENSE%$ */
|
||||
|
||||
#include "chassis-timings.h"
|
||||
#include "chassis-options-utils.h"
|
||||
#include "chassis-plugin.h"
|
||||
#include "cetus-util.h"
|
||||
@ -859,6 +860,49 @@ assign_default_query_cache_timeout(const gchar *newval, gpointer param) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
gchar*
|
||||
show_default_client_idle_timeout(gpointer param) {
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
chassis *srv = opt_param->chas;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_SHOW_OPTS_PROPERTY(opt_type)) {
|
||||
return g_strdup_printf("%d (ms)", srv->client_idle_timeout);
|
||||
}
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
if(srv->client_idle_timeout == 8 * HOURS) {
|
||||
return NULL;
|
||||
}
|
||||
return g_strdup_printf("%d", srv->client_idle_timeout);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gint
|
||||
assign_default_client_idle_timeout(const gchar *newval, gpointer param) {
|
||||
gint ret = ASSIGN_ERROR;
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
chassis *srv = opt_param->chas;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_ASSIGN_OPTS_PROPERTY(opt_type)) {
|
||||
if(NULL != newval) {
|
||||
int value = 0;
|
||||
if(try_get_int_value(newval, &value)) {
|
||||
if(value >= 0) {
|
||||
srv->client_idle_timeout = value;
|
||||
ret = ASSIGN_OK;
|
||||
} else {
|
||||
ret = ASSIGN_VALUE_INVALID;
|
||||
}
|
||||
} else {
|
||||
ret = ASSIGN_VALUE_INVALID;
|
||||
}
|
||||
} else {
|
||||
ret = ASSIGN_VALUE_INVALID;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
gchar* show_long_query_time(gpointer param) {
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
chassis *srv = opt_param->chas;
|
||||
|
@ -79,6 +79,7 @@ CHASSIS_API gchar* show_check_slave_delay(gpointer param);
|
||||
CHASSIS_API gchar* show_slave_delay_down(gpointer param);
|
||||
CHASSIS_API gchar* show_slave_delay_recover(gpointer param);
|
||||
CHASSIS_API gchar* show_default_query_cache_timeout(gpointer param);
|
||||
CHASSIS_API gchar* show_default_client_idle_timeout(gpointer param);
|
||||
CHASSIS_API gchar* show_long_query_time(gpointer param);
|
||||
CHASSIS_API gchar* show_enable_client_found_rows(gpointer param);
|
||||
CHASSIS_API gchar* show_reduce_connections(gpointer param);
|
||||
@ -104,6 +105,7 @@ CHASSIS_API gint assign_max_header_size(const gchar *newval, gpointer param);
|
||||
CHASSIS_API gint assign_slave_delay_recover(const gchar *newval, gpointer param);
|
||||
CHASSIS_API gint assign_slave_delay_down(const gchar *newval, gpointer param);
|
||||
CHASSIS_API gint assign_default_query_cache_timeout(const gchar *newval, gpointer param);
|
||||
CHASSIS_API gint assign_default_client_idle_timeout(const gchar *newval, gpointer param);
|
||||
CHASSIS_API gint assign_long_query_time(const gchar *newval, gpointer param);
|
||||
CHASSIS_API gint assign_max_allowed_packet(const gchar *newval, gpointer param);
|
||||
|
||||
|
@ -68,6 +68,7 @@
|
||||
#include "sys-pedantic.h"
|
||||
|
||||
#include "cetus-log.h"
|
||||
#include "chassis-timings.h"
|
||||
#include "chassis-log.h"
|
||||
#include "chassis-keyfile.h"
|
||||
#include "chassis-mainloop.h"
|
||||
@ -109,6 +110,7 @@ struct chassis_frontend_t {
|
||||
int xa_log_detailed;
|
||||
int cetus_max_allowed_packet;
|
||||
int default_query_cache_timeout;
|
||||
int client_idle_timeout;
|
||||
int query_cache_enabled;
|
||||
int disable_dns_cache;
|
||||
double slave_delay_down_threshold_sec;
|
||||
@ -169,6 +171,7 @@ chassis_frontend_new(void)
|
||||
|
||||
frontend->slave_delay_down_threshold_sec = 60.0;
|
||||
frontend->default_query_cache_timeout = 100;
|
||||
frontend->client_idle_timeout = 8 * HOURS;
|
||||
frontend->long_query_time = MAX_QUERY_TIME;
|
||||
frontend->cetus_max_allowed_packet = MAX_ALLOWED_PACKET_DEFAULT;
|
||||
frontend->disable_dns_cache = 0;
|
||||
@ -396,6 +399,12 @@ chassis_frontend_set_chassis_options(struct chassis_frontend_t *frontend, chassi
|
||||
"default query cache timeout in ms", "<integer>",
|
||||
assign_default_query_cache_timeout, show_default_query_cache_timeout, ALL_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"default-client-idle-timeout",
|
||||
0, 0, OPTION_ARG_INT, &(frontend->client_idle_timeout),
|
||||
"default client idle timeout in seconds", "<integer>",
|
||||
assign_default_client_idle_timeout, show_default_client_idle_timeout, ALL_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"long-query-time",
|
||||
0, 0, OPTION_ARG_INT, &(frontend->long_query_time), "Long query time in ms", "<integer>",
|
||||
@ -586,6 +595,7 @@ init_parameters(struct chassis_frontend_t *frontend, chassis *srv)
|
||||
}
|
||||
|
||||
srv->default_query_cache_timeout = MAX(frontend->default_query_cache_timeout, 1);
|
||||
srv->client_idle_timeout = MAX(frontend->client_idle_timeout, 1);
|
||||
srv->long_query_time = MIN(frontend->long_query_time, MAX_QUERY_TIME);
|
||||
srv->cetus_max_allowed_packet = CLAMP(frontend->cetus_max_allowed_packet,
|
||||
MAX_ALLOWED_PACKET_FLOOR, MAX_ALLOWED_PACKET_CEIL);
|
||||
|
Loading…
Reference in New Issue
Block a user