aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2018-01-30 23:00:05 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2018-01-30 23:06:11 +0200
commit4fef83230e851189fd3541f095c47a952968a411 (patch)
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='
-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.h6
-rw-r--r--src/mysql.c68
-rw-r--r--src/sql.c11
-rw-r--r--src/vmod_dbrw.c36
8 files changed, 128 insertions, 49 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,6 +79,7 @@ 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 */
82 time_t timestamp; /* Last used at */
80 void *data; /* Backend-specific data */ 83 void *data; /* Backend-specific data */
81 VTAILQ_ENTRY(dbrw_connection) list; 84 VTAILQ_ENTRY(dbrw_connection) list;
82}; 85};
@@ -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</