summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2018-01-30 21:00:05 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2018-01-30 21:06:11 (GMT)
commit4fef83230e851189fd3541f095c47a952968a411 (patch) (unidiff)
tree021413ec3602ca4d0e0a0ee0f588d0a2782155ae
parente946449ccf15a0f44f402b03812d31d5f8ef4f7b (diff)
downloadvmod-dbrw-4fef83230e851189fd3541f095c47a952968a411.tar.gz
vmod-dbrw-4fef83230e851189fd3541f095c47a952968a411.tar.bz2
Introduce connection idle timeout.
* NEWS: Updated. * configure.ac: Version 2.2.90 * doc/vmod-dbrw.3: Document connection idle timeout. * doc/vmod-dbrw.texi: Likewise. * src/dbrw.h (dbrw_backend) <sql_idle_timeout>: New method. (dbrw_config)<idle_timeout>: New member. (dbrw_connection)<timestamp>: New member. (sql_idle_timeout): New proto. * src/mysql.c (vmod_mysql_data) <mysql>: Change storage. All uses changed. (s_mysql_idle_timeout): New function. * src/sql.c (sql_idle_timeout): New function. (sql_query): Update connection timestamp. (sql_idle_timeout): New function. * src/vmod_dbrw.c (dbrw_connection_get): Force disconnect if connection remained idle for too long. Initialize cfg->idle_timeout. (vmod_config): New parameter 'timeout='
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--NEWS21
-rw-r--r--configure.ac4
-rw-r--r--doc/vmod-dbrw.314
-rw-r--r--doc/vmod-dbrw.texi17
-rw-r--r--src/dbrw.h8
-rw-r--r--src/mysql.c68
-rw-r--r--src/sql.c11
-rw-r--r--src/vmod_dbrw.c38
8 files changed, 130 insertions, 51 deletions
diff --git a/NEWS b/NEWS
index 6895824..913b0f9 100644
--- a/NEWS
+++ b/NEWS
@@ -1,9 +1,24 @@
1vmod-dbrw -- history of user-visible changes. 2017-08-10 1vmod-dbrw -- history of user-visible changes. 2018-01-30
2Copyright (C) 2013-2017 Sergey Poznyakoff
3See the end of file for copying conditions. 2See the end of file for copying conditions.
4 3
5Please send vmod-dbrw bug reports to <gray@gnu.org> 4Please send vmod-dbrw bug reports to <gray@gnu.org>
6 5
6Version 2.2.90 (Git)
7
8* SQL idle timeout
9
10For MySQL backend, the default connection idle timeout is set equal to
11the value of the MySQL variable 'wait_timeout'. For Postgres, default
12idle timeout is not yet implemented.
13
14Idle timeout can be configured using the timeout configuration option,
15e.g.:
16
17 dbrw.config("mysql", "database=dbrw;user=proxy;timeout=600",
18 {"select dest,pattern,value,flags from rewrite where
19 locate(url,'$url') = 1 order by weight asc;"});
20
21
7Version 2.2, 2017-08-10 22Version 2.2, 2017-08-10
8 23
9* Support for Varnish 5.1 24* Support for Varnish 5.1
@@ -31,7 +46,7 @@ Initial release
31========================================================================= 46=========================================================================
32Copyright information: 47Copyright information:
33 48
34Copyright (C) 2013-2017 Sergey Poznyakoff 49Copyright (C) 2013-2018 Sergey Poznyakoff
35 50
36 Permission is granted to anyone to make or distribute verbatim copies 51 Permission is granted to anyone to make or distribute verbatim copies
37 of this document as received, in any medium, provided that the 52 of this document as received, in any medium, provided that the
diff --git a/configure.ac b/configure.ac
index 81a5390..7a1272c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,5 @@
1# This file is part of vmod-dbrw -*- autoconf -*- 1# This file is part of vmod-dbrw -*- autoconf -*-
2# Copyright (C) 2013-2017 Sergey Poznyakoff 2# Copyright (C) 2013-2018 Sergey Poznyakoff
3# 3#
4# Vmod-dbrw is free software; you can redistribute it and/or modify 4# Vmod-dbrw is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by 5# it under the terms of the GNU General Public License as published by
@@ -14,7 +14,7 @@
14# You should have received a copy of the GNU General Public License 14# You should have received a copy of the GNU General Public License
15# along with vmod-dbrw. If not, see <http://www.gnu.org/licenses/>. 15# along with vmod-dbrw. If not, see <http://www.gnu.org/licenses/>.
16AC_PREREQ(2.69) 16AC_PREREQ(2.69)
17AC_INIT([vmod-dbrw], 2.2, [gray@gnu.org]) 17AC_INIT([vmod-dbrw], 2.2.90, [gray@gnu.org])
18AC_CONFIG_AUX_DIR([build-aux]) 18AC_CONFIG_AUX_DIR([build-aux])
19AC_CONFIG_MACRO_DIR([m4]) 19AC_CONFIG_MACRO_DIR([m4])
20AC_CONFIG_SRCDIR(src/vmod_dbrw.vcc) 20AC_CONFIG_SRCDIR(src/vmod_dbrw.vcc)
diff --git a/doc/vmod-dbrw.3 b/doc/vmod-dbrw.3
index 139fbab..6f1dba8 100644
--- a/doc/vmod-dbrw.3
+++ b/doc/vmod-dbrw.3
@@ -13,7 +13,7 @@
13.\" 13.\"
14.\" You should have received a copy of the GNU General Public License 14.\" You should have received a copy of the GNU General Public License
15.\" along with vmod-dbrw. If not, see <http://www.gnu.org/licenses/>. 15.\" along with vmod-dbrw. If not, see <http://www.gnu.org/licenses/>.
16.TH VMOD-DBRW 1 "August 5, 2017" "VMOD-DBRW" "User Reference" 16.TH VMOD-DBRW 1 "January 30, 2018" "VMOD-DBRW" "User Reference"
17.SH NAME 17.SH NAME
18vmod-dbrw \- Database-driven rewrite rules for Varnish Cache 18vmod-dbrw \- Database-driven rewrite rules for Varnish Cache
19.SH SYNOPSIS 19.SH SYNOPSIS
@@ -99,6 +99,18 @@ section name is \fBclient\fR.
99Use secure connection to the database server via SSL. The \fIFILE\fR 99Use secure connection to the database server via SSL. The \fIFILE\fR
100is a full pathname to the certificate authority file. 100is a full pathname to the certificate authority file.
101.TP 101.TP
102\fBtimeout\fR=\fIN\fR
103Sets idle timeout for a single connection (seconds). The connection
104will be closed and opened again if the module is to use it after
105\fIN\fR or more seconds since its last use. Set \fBtimeout=-1\fR to
106disable idle timeout (sessions will remain open until the SQL
107server closes them). Set \fBtimeout=0\fR to close the connection after
108each request (not recommended).
109
110The default depends on the selected SQL backend. For MySQL, it equals
111the value of the \fBwait_timeout\fR global variable. For PostgreSQL,
112it is \fB-1\fR.
113.TP
102\fBoptions\fR=\fISTRING\fR 114\fBoptions\fR=\fISTRING\fR
103(\fBPostgres\fR-specific) Connection options. 115(\fBPostgres\fR-specific) Connection options.
104.TP 116.TP
diff --git a/doc/vmod-dbrw.texi b/doc/vmod-dbrw.texi
index 82adda2..40fc84d 100644
--- a/doc/vmod-dbrw.texi
+++ b/doc/vmod-dbrw.texi
@@ -30,7 +30,7 @@ Published by the Free Software Foundation,
3051 Franklin Street, Fifth Floor, 3051 Franklin Street, Fifth Floor,
31Boston, MA 02110-1301 USA 31Boston, MA 02110-1301 USA
32 32
33Copyright @copyright{} 2013-2017 Sergey Poznyakoff 33Copyright @copyright{} 2013-2018 Sergey Poznyakoff
34 34
35Permission is granted to copy, distribute and/or modify this document 35Permission is granted to copy, distribute and/or modify this document
36under the terms of the GNU Free Documentation License, Version 1.3 or 36under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -310,6 +310,21 @@ Use secure connection to the database server via SSL. The
310@var{filename} argument is a full pathname of the certificate 310@var{filename} argument is a full pathname of the certificate
311authority file. 311authority file.
312 312
313@kwindex timeout
314@cindex timeout, idle, SQL
315@cindex idle timeout, SQL
316@item timeout=@var{n}
317Sets idle timeout for a single connection. The connection will be
318closed and opened again if the module is to use it after @var{n} or
319more seconds since its last use. Set @samp{timeout=-1} to disable idle
320timeout (session will remain open until the SQL server closes it). Set
321@samp{timeout=0} to close the connection after each request (not
322recommended).
323
324The default depends on the selected SQL backend. For MySQL, it equals
325the value of the @samp{wait_timeout} global variable. For PostgreSQL,
326it is @samp{-1}.
327
313@kindex options 328@kindex options
314@cindex options, PostgreSQL 329@cindex options, PostgreSQL
315@item options=@var{string} 330@item options=@var{string}
diff --git a/src/dbrw.h b/src/dbrw.h
index 438d963..7a0ee52 100644
--- a/src/dbrw.h
+++ b/src/dbrw.h
@@ -1,5 +1,5 @@
1/* This file is part of vmod-dbrw 1/* This file is part of vmod-dbrw
2 Copyright (C) 2013-2017 Sergey Poznyakoff 2 Copyright (C) 2013-2018 Sergey Poznyakoff
3 3
4 Vmod-dbrw is free software; you can redistribute it and/or modify 4 Vmod-dbrw is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
@@ -43,6 +43,7 @@ struct dbrw_backend {
43 int (*sql_free_result) (struct dbrw_connection *); 43 int (*sql_free_result) (struct dbrw_connection *);
44 const char *(*sql_get_column)(struct dbrw_connection *, unsigned, 44 const char *(*sql_get_column)(struct dbrw_connection *, unsigned,
45 unsigned); 45 unsigned);
46 int (*sql_idle_timeout)(struct dbrw_connection *);
46}; 47};
47 48
48enum { 49enum {
@@ -66,6 +67,7 @@ struct dbrw_config {
66 int qdisp; 67 int qdisp;
67 int regflags; 68 int regflags;
68 char status[HTTP_STATUS_LEN+1]; 69 char status[HTTP_STATUS_LEN+1];
70 int idle_timeout;
69 VTAILQ_ENTRY(dbrw_config) list; 71 VTAILQ_ENTRY(dbrw_config) list;
70}; 72};
71 73
@@ -77,7 +79,8 @@ struct dbrw_connection {
77 struct dbrw_config *conf; /* Pointer to the configuration data */ 79 struct dbrw_config *conf; /* Pointer to the configuration data */
78 regmatch_t *matches; /* Match map */ 80 regmatch_t *matches; /* Match map */
79 size_t matchsize; /* Total number of entries in match map */ 81 size_t matchsize; /* Total number of entries in match map */
80 void *data; /* Backend-specific data */ 82 time_t timestamp; /* Last used at */
83 void *data; /* Backend-specific data */
81 VTAILQ_ENTRY(dbrw_connection) list; 84 VTAILQ_ENTRY(dbrw_connection) list;
82}; 85};
83 86
@@ -105,6 +108,7 @@ unsigned sql_num_fields(struct dbrw_connection *pd);
105void sql_free_result(struct dbrw_connection *pd); 108void sql_free_result(struct dbrw_connection *pd);
106void sql_destroy(struct dbrw_connection *pd); 109void sql_destroy(struct dbrw_connection *pd);
107const char *sql_get_column(struct dbrw_connection *pd, unsigned row, unsigned col); 110const char *sql_get_column(struct dbrw_connection *pd, unsigned row, unsigned col);
111int sql_idle_timeout(struct dbrw_connection *conn);
108 112
109char *findparam(char **params, char *name); 113char *findparam(char **params, char *name);
110 114
diff --git a/src/mysql.c b/src/mysql.c
index d7406ca..d97200a 100644
--- a/src/mysql.c
+++ b/src/mysql.c
@@ -1,5 +1,5 @@
1/* This file is part of vmod-dbrw 1/* This file is part of vmod-dbrw
2 Copyright (C) 2013-2014 Sergey Poznyakoff 2 Copyright (C) 2013-2018 Sergey Poznyakoff
3 3
4 Vmod-dbrw is free software; you can redistribute it and/or modify 4 Vmod-dbrw is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
@@ -21,7 +21,7 @@
21 21
22struct vmod_mysql_data 22struct vmod_mysql_data
23{ 23{
24 MYSQL *mysql; 24 MYSQL mysql;
25 MYSQL_RES *result; 25 MYSQL_RES *result;
26 char *buffer; 26 char *buffer;
27 size_t bufsize; 27 size_t bufsize;
@@ -33,12 +33,12 @@ check_errno(struct dbrw_connection *conn)
33{ 33{
34 struct vmod_mysql_data *mp = conn->data; 34 struct vmod_mysql_data *mp = conn->data;
35 35
36 switch (mysql_errno(mp->mysql)) { 36 switch (mysql_errno(&mp->mysql)) {
37 case CR_SERVER_GONE_ERROR: 37 case CR_SERVER_GONE_ERROR:
38 case CR_SERVER_LOST: 38 case CR_SERVER_LOST:
39 case ER_SERVER_SHUTDOWN: 39 case ER_SERVER_SHUTDOWN:
40 case ER_ABORTING_CONNECTION: 40 case ER_ABORTING_CONNECTION:
41 dbrw_error("query failed: %s", mysql_error(mp->mysql)); 41 dbrw_error("query failed: %s", mysql_error(&mp->mysql));
42 sql_disconnect(conn); 42 sql_disconnect(conn);
43 if (conn->state == state_error) { 43 if (conn->state == state_error) {
44 conn->state = state_disabled; 44 conn->state = state_disabled;
@@ -58,13 +58,13 @@ check_errno(struct dbrw_connection *conn)
58 case ER_FIELD_SPECIFIED_TWICE: 58 case ER_FIELD_SPECIFIED_TWICE:
59 case ER_NO_SUCH_TABLE: 59 case ER_NO_SUCH_TABLE:
60 case ER_NOT_ALLOWED_COMMAND: 60 case ER_NOT_ALLOWED_COMMAND:
61 dbrw_error("query failed: %s", mysql_error(mp->mysql)); 61 dbrw_error("query failed: %s", mysql_error(&mp->mysql));
62 dbrw_error("disabling MySQL connection"); 62 dbrw_error("disabling MySQL connection");
63 sql_disconnect(conn); 63 sql_disconnect(conn);
64 conn->state = state_disabled; 64 conn->state = state_disabled;
65 break; 65 break;
66 default: 66 default:
67 dbrw_error("query failed: %s", mysql_error(mp->mysql)); 67 dbrw_error("query failed: %s", mysql_error(&mp->mysql));
68 } 68 }
69} 69}
70 70
@@ -88,7 +88,6 @@ s_mysql_destroy(struct dbrw_connection *conn)
88{ 88{
89 struct vmod_mysql_data *mp = conn->data; 89 struct vmod_mysql_data *mp = conn->data;
90 free(mp->buffer); 90 free(mp->buffer);
91 free(mp->mysql);
92 free(mp); 91 free(mp);
93 conn->data = NULL; 92 conn->data = NULL;
94} 93}
@@ -102,14 +101,7 @@ s_mysql_connect(struct dbrw_connection *conn)
102 char *s; 101 char *s;
103 int port = 0; 102 int port = 0;
104 103
105 mp->mysql = malloc(sizeof(MYSQL)); 104 mysql_init(&mp->mysql);
106 if (!mp->mysql) {
107 dbrw_error("not enough memory");
108 conn->state = state_disabled;
109 return -1;
110 }
111
112 mysql_init(mp->mysql);
113 105
114 host = findparam(conn->conf->param, "server"); 106 host = findparam(conn->conf->param, "server");
115 if (host && host[0] == '/') { 107 if (host && host[0] == '/') {
@@ -123,17 +115,17 @@ s_mysql_connect(struct dbrw_connection *conn)
123 115
124 s = findparam(conn->conf->param, "config"); 116 s = findparam(conn->conf->param, "config");
125 if (s) 117 if (s)
126 mysql_options(mp->mysql, MYSQL_READ_DEFAULT_FILE, s); 118 mysql_options(&mp->mysql, MYSQL_READ_DEFAULT_FILE, s);
127 119
128 s = findparam(conn->conf->param, "group"); 120 s = findparam(conn->conf->param, "group");
129 if (s) 121 if (s)
130 mysql_options(mp->mysql, MYSQL_READ_DEFAULT_GROUP, s); 122 mysql_options(&mp->mysql, MYSQL_READ_DEFAULT_GROUP, s);
131 123
132 s = findparam(conn->conf->param, "cacert"); 124 s = findparam(conn->conf->param, "cacert");
133 if (s) 125 if (s)
134 mysql_ssl_set(mp->mysql, NULL, NULL, s, NULL, NULL); 126 mysql_ssl_set(&mp->mysql, NULL, NULL, s, NULL, NULL);
135 debug(conn->conf, 1, ("connecting to database")); 127 debug(conn->conf, 1, ("connecting to database"));
136 if (!mysql_real_connect(mp->mysql, 128 if (!mysql_real_connect(&mp->mysql,
137 host, 129 host,
138 findparam(conn->conf->param, "user"), 130 findparam(conn->conf->param, "user"),
139 findparam(conn->conf->param, "password"), 131 findparam(conn->conf->param, "password"),
@@ -141,7 +133,7 @@ s_mysql_connect(struct dbrw_connection *conn)
141 port, 133 port,
142 socket_name, 134 socket_name,
143 CLIENT_MULTI_RESULTS)) { 135 CLIENT_MULTI_RESULTS)) {
144 dbrw_error("cannot connect: %s", mysql_error(mp->mysql)); 136 dbrw_error("cannot connect: %s", mysql_error(&mp->mysql));
145 return -1; 137 return -1;
146 } 138 }
147 debug(conn->conf, 1, ("connected to database")); 139 debug(conn->conf, 1, ("connected to database"));
@@ -153,7 +145,7 @@ static int
153s_mysql_disconnect(struct dbrw_connection *conn) 145s_mysql_disconnect(struct dbrw_connection *conn)
154{ 146{
155 struct vmod_mysql_data *mp = conn->data; 147 struct vmod_mysql_data *mp = conn->data;
156 mysql_close(mp->mysql); 148 mysql_close(&mp->mysql);
157 return 0; 149 return 0;
158} 150}
159 151
@@ -166,8 +158,7 @@ s_mysql_query(struct dbrw_connection *conn, const char *query)
166 MYSQL *mysql; 158 MYSQL *mysql;
167 159
168 for (i = 0; i < 10; i++) { 160 for (i = 0; i < 10; i++) {
169 mysql = mp->mysql; 161 rc = mysql_query(&mp->mysql, query);
170 rc = mysql_query(mysql, query);
171 if (rc) { 162 if (rc) {
172 check_errno(conn); 163 check_errno(conn);
173 if (conn->state != state_init) 164 if (conn->state != state_init)
@@ -177,13 +168,13 @@ s_mysql_query(struct dbrw_connection *conn, const char *query)
177 return -1; 168 return -1;
178 continue; 169 continue;
179 } 170 }
180 mp->result = mysql_store_result(mp->mysql); 171 mp->result = mysql_store_result(&mp->mysql);
181 if (mp->result) { 172 if (mp->result) {
182 conn->state = state_result; 173 conn->state = state_result;
183 rc = 0; 174 rc = 0;
184 } else if (mysql_field_count(mp->mysql)) { 175 } else if (mysql_field_count(&mp->mysql)) {
185 dbrw_error("cannot store result: %s", 176 dbrw_error("cannot store result: %s",
186 mysql_error(mp->mysql)); 177 mysql_error(&mp->mysql));
187 conn->state = state_error; 178 conn->state = state_error;
188 rc = 1; 179 rc = 1;
189 } else 180 } else
@@ -267,7 +258,7 @@ s_mysql_escape (struct dbrw_connection *conn, const char *arg)
267 mp->bufsize = size; 258 mp->bufsize = size;
268 } 259 }
269 260
270 mysql_real_escape_string(mp->mysql, mp->buffer, arg, len); 261 mysql_real_escape_string(&mp->mysql, mp->buffer, arg, len);
271 262
272 p = strdup(mp->buffer); 263 p = strdup(mp->buffer);
273 if (!p) 264 if (!p)
@@ -275,6 +266,26 @@ s_mysql_escape (struct dbrw_connection *conn, const char *arg)
275 return p; 266 return p;
276} 267}
277 268
269static int
270s_mysql_idle_timeout(struct dbrw_connection *conn)
271{
272 const char *res;
273 int n;
274 if (sql_connect(conn) || conn->state != state_connected)
275 return -1;
276 if (sql_query(conn,
277 "SHOW VARIABLES WHERE Variable_name = 'wait_timeout'"))
278 return -1;
279 res = sql_get_column(conn, 0, 1);
280 if (res)
281 n = atoi(res);
282 else
283 n = -1;
284 sql_free_result(conn);
285 return n;
286}
287
288
278struct dbrw_backend mysql_backend = { 289struct dbrw_backend mysql_backend = {
279 "mysql", 290 "mysql",
280 s_mysql_init, 291 s_mysql_init,
@@ -286,5 +297,6 @@ struct dbrw_backend mysql_backend = {
286 s_mysql_num_tuples, 297 s_mysql_num_tuples,
287 s_mysql_num_fields, 298 s_mysql_num_fields,
288 s_mysql_free_result, 299 s_mysql_free_result,
289 s_mysql_get_column 300 s_mysql_get_column,
301 s_mysql_idle_timeout
290}; 302};
diff --git a/src/sql.c b/src/sql.c
index c42c5de..3acd9de 100644
--- a/src/sql.c
+++ b/src/sql.c
@@ -1,5 +1,5 @@
1/* This file is part of vmod-dbrw 1/* This file is part of vmod-dbrw
2 Copyright (C) 2013-2014 Sergey Poznyakoff 2 Copyright (C) 2013-2018 Sergey Poznyakoff
3 3
4 Vmod-dbrw is free software; you can redistribute it and/or modify 4 Vmod-dbrw is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
@@ -143,6 +143,7 @@ sql_query(struct dbrw_connection *conn, const char *input)
143 return 1; 143 return 1;
144 } 144 }
145 } while (conn->state != state_connected); 145 } while (conn->state != state_connected);
146 conn->timestamp = time(NULL);
146 if (conn->conf->backend->sql_query(conn, input) == 0) 147 if (conn->conf->backend->sql_query(conn, input) == 0)
147 return 0; 148 return 0;
148 return 1; 149 return 1;
@@ -185,3 +186,11 @@ sql_get_column(struct dbrw_connection *conn, unsigned row, unsigned col)
185 return conn->conf->backend->sql_get_column(conn, row, col); 186 return conn->conf->backend->sql_get_column(conn, row, col);
186} 187}
187 188
189int
190sql_idle_timeout(struct dbrw_connection *conn)
191{
192 CONN_ASSERT_VAL(conn, -1);
193 if (!conn->conf->backend->sql_idle_timeout)
194 return -1;
195 return conn->conf->backend->sql_idle_timeout(conn);
196}
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 @@
1/* This file is part of vmod-dbrw 1/* This file is part of vmod-dbrw
2 Copyright (C) 2013-2017 Sergey Poznyakoff 2 Copyright (C) 2013-2018 Sergey Poznyakoff
3 3
4 Vmod-dbrw is free software; you can redistribute it and/or modify 4 Vmod-dbrw is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
@@ -76,8 +76,20 @@ dbrw_connection_get(struct dbrw_config *cfg)
76 cp = NULL; 76 cp = NULL;
77 } else 77 } else
78 VTAILQ_INSERT_HEAD(&connect_pool, cp, list); 78 VTAILQ_INSERT_HEAD(&connect_pool, cp, list);
79 } else if (cp->state == state_connected
80 && cfg->idle_timeout >= 0
81 && cp->timestamp + cfg->idle_timeout < time(NULL)) {
82 sql_disconnect(cp);
79 } 83 }
84
80 cp->busy = 1; 85 cp->busy = 1;
86
87 if (cfg->idle_timeout == -2) {
88 cfg->idle_timeout = sql_idle_timeout(cp);
89 if (cfg->idle_timeout < -1)
90 cfg->idle_timeout = -1;
91 }
92
81 pthread_mutex_unlock(&connect_pool_mtx); 93 pthread_mutex_unlock(&connect_pool_mtx);
82 return cp; 94 return cp;
83} 95}
@@ -189,7 +201,7 @@ parse_flags(const char *arg, int *qdisp, int *flags, char status[])
189 strncpy(status, ws.ws_wordv[i] + 2, 201 strncpy(status, ws.ws_wordv[i] + 2,
190 HTTP_STATUS_LEN); 202 HTTP_STATUS_LEN);
191 } else { 203 } else {
192 dbrw_error("unrecognized flag: %s", ws.ws_wordv[i]); 204 dbrw_error("unrecognized flag: %s", ws.ws_wordv[i]);
193 rc = 1; 205 rc = 1;
194 } 206 }
195 } 207 }
@@ -200,14 +212,7 @@ parse_flags(const char *arg, int *qdisp, int *flags, char status[])
200 212
201/* Configure the module. 213/* Configure the module.
202 BACKEND - "mysql" or "pgsql" 214 BACKEND - "mysql" or "pgsql"
203 PARAM - VAR=VALUE*: 215 PARAM - VAR=VALUE*
204 db=S
205 port=N
206 socket=S
207 user=S
208 password=S
209 options=S
210 debug=N
211 QUERY - Query to obtain the redirection target 216 QUERY - Query to obtain the redirection target
212 */ 217 */
213VCL_VOID 218VCL_VOID
@@ -258,8 +263,13 @@ vmod_config(VRT_CTX, struct vmod_priv *priv,
258 AN(conf->query); 263 AN(conf->query);
259 conf->backend = backend; 264 conf->backend = backend;
260 265
261 s = findparam(conf->param, "debug"); 266 if ((s = findparam(conf->param, "debug")) != NULL)
262 conf->debug_level = s ? atoi(s) : 0; 267 conf->debug_level = atoi(s);
268
269 if ((s = findparam(conf->param, "timeout")) != NULL)
270 conf->idle_timeout = atoi(s);
271 else
272 conf->idle_timeout = -2;
263 273
264 conf->qdisp = QDISP_NONE; 274 conf->qdisp = QDISP_NONE;
265 conf->regflags = REG_EXTENDED; 275 conf->regflags = REG_EXTENDED;
@@ -267,7 +277,9 @@ vmod_config(VRT_CTX, struct vmod_priv *priv,
267 277
268 s = findparam(conf->param, "flags"); 278 s = findparam(conf->param, "flags");
269 if (s) 279 if (s)
270 parse_flags(s, &conf->qdisp, &conf->regflags, 280 parse_flags(s,
281 &conf->qdisp,
282 &conf->regflags,
271 conf->status); 283 conf->status);
272 284
273 AZ(pthread_mutex_lock(&config_pool_mtx)); 285 AZ(pthread_mutex_lock(&config_pool_mtx));

Return to:

Send suggestions and report system problems to the System administrator.