diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2018-01-30 23:00:05 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2018-01-30 23:06:11 +0200 |
commit | 4fef83230e851189fd3541f095c47a952968a411 (patch) | |
tree | 021413ec3602ca4d0e0a0ee0f588d0a2782155ae | |
parent | e946449ccf15a0f44f402b03812d31d5f8ef4f7b (diff) | |
download | vmod-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='
-rw-r--r-- | NEWS | 21 | ||||
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | doc/vmod-dbrw.3 | 14 | ||||
-rw-r--r-- | doc/vmod-dbrw.texi | 17 | ||||
-rw-r--r-- | src/dbrw.h | 8 | ||||
-rw-r--r-- | src/mysql.c | 68 | ||||
-rw-r--r-- | src/sql.c | 11 | ||||
-rw-r--r-- | src/vmod_dbrw.c | 38 |
8 files changed, 130 insertions, 51 deletions
@@ -1,9 +1,24 @@ | |||
1 | vmod-dbrw -- history of user-visible changes. 2017-08-10 | 1 | vmod-dbrw -- history of user-visible changes. 2018-01-30 |
2 | Copyright (C) 2013-2017 Sergey Poznyakoff | ||
3 | See the end of file for copying conditions. | 2 | See the end of file for copying conditions. |
4 | 3 | ||
5 | Please send vmod-dbrw bug reports to <gray@gnu.org> | 4 | Please send vmod-dbrw bug reports to <gray@gnu.org> |
6 | 5 | ||
6 | Version 2.2.90 (Git) | ||
7 | |||
8 | * SQL idle timeout | ||
9 | |||
10 | For MySQL backend, the default connection idle timeout is set equal to | ||
11 | the value of the MySQL variable 'wait_timeout'. For Postgres, default | ||
12 | idle timeout is not yet implemented. | ||
13 | |||
14 | Idle timeout can be configured using the timeout configuration option, | ||
15 | e.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 | |||
7 | Version 2.2, 2017-08-10 | 22 | Version 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 | ========================================================================= |
32 | Copyright information: | 47 | Copyright information: |
33 | 48 | ||
34 | Copyright (C) 2013-2017 Sergey Poznyakoff | 49 | Copyright (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/>. |
16 | AC_PREREQ(2.69) | 16 | AC_PREREQ(2.69) |
17 | AC_INIT([vmod-dbrw], 2.2, [gray@gnu.org]) | 17 | AC_INIT([vmod-dbrw], 2.2.90, [gray@gnu.org]) |
18 | AC_CONFIG_AUX_DIR([build-aux]) | 18 | AC_CONFIG_AUX_DIR([build-aux]) |
19 | AC_CONFIG_MACRO_DIR([m4]) | 19 | AC_CONFIG_MACRO_DIR([m4]) |
20 | AC_CONFIG_SRCDIR(src/vmod_dbrw.vcc) | 20 | AC_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 |
18 | vmod-dbrw \- Database-driven rewrite rules for Varnish Cache | 18 | vmod-dbrw \- Database-driven rewrite rules for Varnish Cache |
19 | .SH SYNOPSIS | 19 | .SH SYNOPSIS |
@@ -99,6 +99,18 @@ section name is \fBclient\fR. | |||
99 | Use secure connection to the database server via SSL. The \fIFILE\fR | 99 | Use secure connection to the database server via SSL. The \fIFILE\fR |
100 | is a full pathname to the certificate authority file. | 100 | is a full pathname to the certificate authority file. |
101 | .TP | 101 | .TP |
102 | \fBtimeout\fR=\fIN\fR | ||
103 | Sets idle timeout for a single connection (seconds). The connection | ||
104 | will 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 | ||
106 | disable idle timeout (sessions will remain open until the SQL | ||
107 | server closes them). Set \fBtimeout=0\fR to close the connection after | ||
108 | each request (not recommended). | ||
109 | |||
110 | The default depends on the selected SQL backend. For MySQL, it equals | ||
111 | the value of the \fBwait_timeout\fR global variable. For PostgreSQL, | ||
112 | it 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, | |||
30 | 51 Franklin Street, Fifth Floor, | 30 | 51 Franklin Street, Fifth Floor, |
31 | Boston, MA 02110-1301 USA | 31 | Boston, MA 02110-1301 USA |
32 | 32 | ||
33 | Copyright @copyright{} 2013-2017 Sergey Poznyakoff | 33 | Copyright @copyright{} 2013-2018 Sergey Poznyakoff |
34 | 34 | ||
35 | Permission is granted to copy, distribute and/or modify this document | 35 | Permission is granted to copy, distribute and/or modify this document |
36 | under the terms of the GNU Free Documentation License, Version 1.3 or | 36 | under 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 |
311 | authority file. | 311 | authority file. |
312 | 312 | ||
313 | @kwindex timeout | ||
314 | @cindex timeout, idle, SQL | ||
315 | @cindex idle timeout, SQL | ||
316 | @item timeout=@var{n} | ||
317 | Sets idle timeout for a single connection. The connection will be | ||
318 | closed and opened again if the module is to use it after @var{n} or | ||
319 | more seconds since its last use. Set @samp{timeout=-1} to disable idle | ||
320 | timeout (session will remain open until the SQL server closes it). Set | ||
321 | @samp{timeout=0} to close the connection after each request (not | ||
322 | recommended). | ||
323 | |||
324 | The default depends on the selected SQL backend. For MySQL, it equals | ||
325 | the value of the @samp{wait_timeout} global variable. For PostgreSQL, | ||
326 | it 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} |
@@ -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 | ||
48 | enum { | 49 | enum { |
@@ -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); | |||
105 | void sql_free_result(struct dbrw_connection *pd); | 108 | void sql_free_result(struct dbrw_connection *pd); |
106 | void sql_destroy(struct dbrw_connection *pd); | 109 | void sql_destroy(struct dbrw_connection *pd); |
107 | const char *sql_get_column(struct dbrw_connection *pd, unsigned row, unsigned col); | 110 | const char *sql_get_column(struct dbrw_connection *pd, unsigned row, unsigned col); |
111 | int sql_idle_timeout(struct dbrw_connection *conn); | ||
108 | 112 | ||
109 | char *findparam(char **params, char *name); | 113 | char *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 | ||
22 | struct vmod_mysql_data | 22 | struct 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: |