diff options
Diffstat (limited to 'src/vmod_dbrw.c')
-rw-r--r-- | src/vmod_dbrw.c | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/src/vmod_dbrw.c b/src/vmod_dbrw.c index b6fe70c..d6785d7 100644 --- a/src/vmod_dbrw.c +++ b/src/vmod_dbrw.c @@ -1,5 +1,5 @@ /* This file is part of vmod-dbrw - Copyright (C) 2013-2017 Sergey Poznyakoff + Copyright (C) 2013-2018 Sergey Poznyakoff Vmod-dbrw is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -76,8 +76,20 @@ dbrw_connection_get(struct dbrw_config *cfg) cp = NULL; } else VTAILQ_INSERT_HEAD(&connect_pool, cp, list); + } else if (cp->state == state_connected + && cfg->idle_timeout >= 0 + && cp->timestamp + cfg->idle_timeout < time(NULL)) { + sql_disconnect(cp); } + cp->busy = 1; + + if (cfg->idle_timeout == -2) { + cfg->idle_timeout = sql_idle_timeout(cp); + if (cfg->idle_timeout < -1) + cfg->idle_timeout = -1; + } + pthread_mutex_unlock(&connect_pool_mtx); return cp; } @@ -189,7 +201,7 @@ parse_flags(const char *arg, int *qdisp, int *flags, char status[]) strncpy(status, ws.ws_wordv[i] + 2, HTTP_STATUS_LEN); } else { - dbrw_error("unrecognized flag: %s", ws.ws_wordv[i]); + dbrw_error("unrecognized flag: %s", ws.ws_wordv[i]); rc = 1; } } @@ -200,14 +212,7 @@ parse_flags(const char *arg, int *qdisp, int *flags, char status[]) /* Configure the module. BACKEND - "mysql" or "pgsql" - PARAM - VAR=VALUE*: - db=S - port=N - socket=S - user=S - password=S - options=S - debug=N + PARAM - VAR=VALUE* QUERY - Query to obtain the redirection target */ VCL_VOID @@ -258,8 +263,13 @@ vmod_config(VRT_CTX, struct vmod_priv *priv, AN(conf->query); conf->backend = backend; - s = findparam(conf->param, "debug"); - conf->debug_level = s ? atoi(s) : 0; + if ((s = findparam(conf->param, "debug")) != NULL) + conf->debug_level = atoi(s); + + if ((s = findparam(conf->param, "timeout")) != NULL) + conf->idle_timeout = atoi(s); + else + conf->idle_timeout = -2; conf->qdisp = QDISP_NONE; conf->regflags = REG_EXTENDED; @@ -267,7 +277,9 @@ vmod_config(VRT_CTX, struct vmod_priv *priv, s = findparam(conf->param, "flags"); if (s) - parse_flags(s, &conf->qdisp, &conf->regflags, + parse_flags(s, + &conf->qdisp, + &conf->regflags, conf->status); AZ(pthread_mutex_lock(&config_pool_mtx)); |