aboutsummaryrefslogtreecommitdiff
path: root/src/vmod_dbrw.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vmod_dbrw.c')
-rw-r--r--src/vmod_dbrw.c38
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,8 +1,8 @@
/* 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
the Free Software Foundation; either version 3, or (at your option)
any later version.
@@ -73,14 +73,26 @@ dbrw_connection_get(struct dbrw_config *cfg)
if (sql_init(cp)) {
free(cp);
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;
}
static void
dbrw_connection_release(struct dbrw_connection *cp)
@@ -186,31 +198,24 @@ parse_flags(const char *arg, int *qdisp, int *flags, char status[])
ws.ws_wordv[i] + 2);
rc = 1;
} else
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;
}
}
wordsplit_free(&ws);
return rc;
}
/* 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
vmod_config(VRT_CTX, struct vmod_priv *priv,
VCL_STRING bkname, VCL_STRING param, VCL_STRING query)
{
@@ -255,22 +260,29 @@ vmod_config(VRT_CTX, struct vmod_priv *priv,
conf->param_str = strdup(param);
AN(conf->param_str);
conf->query = strdup(query);
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;
conf->status[0] = 0;
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));
VTAILQ_INSERT_HEAD(&config_pool, conf, list);
pthread_mutex_unlock(&config_pool_mtx);
}

Return to:

Send suggestions and report system problems to the System administrator.