diff options
author | Eric Leblond <eric@regit.org> | 2013-03-17 19:41:36 +0100 |
---|---|---|
committer | Eric Leblond <eric@regit.org> | 2013-05-21 19:47:53 +0200 |
commit | 6e4d8af18923ec4873d96228ccf24eda3da4577e (patch) | |
tree | 3e62f9de5e185124928578454f29d8586d59fb85 /include | |
parent | 33136bc95407aab889778bc4ebba9622bc4c8f63 (diff) |
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.
Diffstat (limited to 'include')
-rw-r--r-- | include/ulogd/db.h | 34 |
1 files changed, 29 insertions, 5 deletions
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); |