[netfilter-cvslog] r7429 - in branches/ulog/ulogd2: include/ulogd util

pablo at netfilter.org pablo at netfilter.org
Sat Apr 5 16:02:57 CEST 2008


Author: pablo at netfilter.org
Date: 2008-04-05 16:02:56 +0200 (Sat, 05 Apr 2008)
New Revision: 7429

Modified:
   branches/ulog/ulogd2/include/ulogd/db.h
   branches/ulog/ulogd2/util/db.c
Log:
This patch fixes a problem in SQL reconnection algorithm which is managed in
the db.c file for PgSQL and MySQL. In case of problem during request execution
a new connection to the database was immediatly started without closing the
previous one. The consequence was to block the database by having too much
simultaneous open connections.

This patch fixes the problem by disconnectinng from the database after a
request failure and trying to reconnect after a delay which is by default
of 2 secondes. This delay can be customized via the reconnect configuration
variable in the database configuration section.

Signed-off-by: Eric Leblond <eric at inl.fr>


Modified: branches/ulog/ulogd2/include/ulogd/db.h
===================================================================
--- branches/ulog/ulogd2/include/ulogd/db.h	2008-04-04 18:31:41 UTC (rev 7428)
+++ branches/ulog/ulogd2/include/ulogd/db.h	2008-04-05 14:02:56 UTC (rev 7429)
@@ -23,6 +23,7 @@
 	struct db_driver *driver;
 };
 #define TIME_ERR		((time_t)-1)	/* Be paranoid */
+#define RECONNECT_DEFAULT	2
 
 #define DB_CES							\
 		{						\
@@ -33,6 +34,7 @@
 		{						\
 			.key = "reconnect",			\
 			.type = CONFIG_TYPE_INT,		\
+			.u.value = RECONNECT_DEFAULT,		\
 		},						\
 		{						\
 			.key = "ip_as_string",			\

Modified: branches/ulog/ulogd2/util/db.c
===================================================================
--- branches/ulog/ulogd2/util/db.c	2008-04-04 18:31:41 UTC (rev 7428)
+++ branches/ulog/ulogd2/util/db.c	2008-04-05 14:02:56 UTC (rev 7429)
@@ -176,6 +176,8 @@
 	struct db_instance *di = (struct db_instance *) upi->private;
 
 	if (reconnect_ce(upi->config_kset).u.value) {
+		if (time(NULL) < di->reconnect)
+			return -1;
 		di->reconnect = time(NULL);
 		if (di->reconnect != TIME_ERR) {
 			ulogd_log(ULOGD_ERROR, "no connection to database, "
@@ -312,8 +314,11 @@
 
 	/* now we have created our statement, insert it */
 
-	if (di->driver->execute(upi, di->stmt, strlen(di->stmt)) < 0)
-		return _init_db(upi);
+	if (di->driver->execute(upi, di->stmt, strlen(di->stmt)) < 0) {
+		/* error occur, database connexion need to be closed */
+		di->driver->close_db(upi);
+		return _init_reconnect(upi);
+	}
 
 	return 0;
 }




More information about the netfilter-cvslog mailing list