From 6e4d8af18923ec4873d96228ccf24eda3da4577e Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Sun, 17 Mar 2013 19:41:36 +0100 Subject: db: store data in memory during database downtime This patch is adding a mechanism to store query in a backlog build in memory. This allow to store events during downtime in memory and realize the effective insertion when the database comes back. A memory cap is used to avoid any memory flooding. --- include/ulogd/db.h | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/ulogd/db.h b/include/ulogd/db.h index 1c910ff..a533902 100644 --- a/include/ulogd/db.h +++ b/include/ulogd/db.h @@ -20,6 +20,12 @@ struct db_driver { const char *stmt, unsigned int len); }; +struct db_stmt { + char *stmt; + int len; + struct llist_head list; +}; + struct db_instance { char *stmt; /* buffer for our insert statement */ char *stmt_val; /* pointer to the beginning of the "VALUES" part */ @@ -28,9 +34,15 @@ struct db_instance { time_t reconnect; int (*interp)(struct ulogd_pluginstance *upi); struct db_driver *driver; + unsigned int backlog_memcap; + unsigned int backlog_memusage; + unsigned int backlog_oneshot; + unsigned char backlog_full; + struct llist_head backlog; }; #define TIME_ERR ((time_t)-1) /* Be paranoid */ #define RECONNECT_DEFAULT 2 +#define MAX_ONESHOT_REQUEST 10 #define DB_CES \ { \ @@ -51,13 +63,25 @@ struct db_instance { .key = "procedure", \ .type = CONFIG_TYPE_STRING, \ .options = CONFIG_OPT_MANDATORY, \ + }, \ + { \ + .key = "backlog_memcap", \ + .type = CONFIG_TYPE_INT, \ + .u.value = 0, \ + }, \ + { \ + .key = "backlog_oneshot_requests", \ + .type = CONFIG_TYPE_INT, \ + .u.value = MAX_ONESHOT_REQUEST, \ } -#define DB_CE_NUM 4 -#define table_ce(x) (x->ces[0]) -#define reconnect_ce(x) (x->ces[1]) -#define timeout_ce(x) (x->ces[2]) -#define procedure_ce(x) (x->ces[3]) +#define DB_CE_NUM 6 +#define table_ce(x) (x->ces[0]) +#define reconnect_ce(x) (x->ces[1]) +#define timeout_ce(x) (x->ces[2]) +#define procedure_ce(x) (x->ces[3]) +#define backlog_memcap_ce(x) (x->ces[4]) +#define backlog_oneshot_ce(x) (x->ces[5]) void ulogd_db_signal(struct ulogd_pluginstance *upi, int signal); int ulogd_db_start(struct ulogd_pluginstance *upi); -- cgit v1.2.3