From fc70e99444b2852f45303d9bf55332f247ec6b4f Mon Sep 17 00:00:00 2001 From: Edward Rudd Date: Sun, 26 Oct 2008 01:53:49 +0000 Subject: finish transaction implementation if a single log file aborts DO NOT keep going switch to using libtool for linking (so rpath is set) --- diff --git a/utility/Makefile.in b/utility/Makefile.in index c7a5e3d..fdc3846 100644 --- a/utility/Makefile.in +++ b/utility/Makefile.in @@ -2,14 +2,15 @@ top_srcdir = @top_srcdir@ srcdir = @abs_srcdir@ +top_builddir = @top_builddir@ builddir = @abs_builddir@ -#@APR_CFLAGS@ +LIBTOOL=@LIBTOOL@ CFLAGS = -g3 -Wall -fno-strict-aliasing \ @APR_INCLUDES@ @APU_INCLUDES@ @PCRE_CFLAGS@ \ -I$(top_srcdir)/include CPPFLAGS = @APR_CPPFLAGS@ -LDFLAGS = @APR_LDFLAGS@ @APU_LDFLAGS@ @PCRE_LIBS@ +LDFLAGS = @APR_LIBTOOL@ @APU_LIBTOOL@ @PCRE_LIBS@ ifeq (@OOO_MAINTAIN@,1) CFLAGS += -Werror @@ -28,7 +29,7 @@ TARGETS = mod_log_sql all: $(TARGETS) mod_log_sql: $(OBJECTS) $(HEADERS) - $(CC) -o $@ $(OBJECTS) $(LDFLAGS) + $(LIBTOOL) --tag=CC --mode=link $(CC) -o $@ $(OBJECTS) $(LDFLAGS) %.o: %.c %.d gcc -c $(CFLAGS) $(CPPFLAGS) $< -o $@ diff --git a/utility/database.c b/utility/database.c index af8db97..98c203b 100644 --- a/utility/database.c +++ b/utility/database.c @@ -10,6 +10,7 @@ struct config_dbd_t { const apr_dbd_driver_t *driver; apr_dbd_t *dbd; apr_dbd_prepared_t *stmt; + apr_dbd_transaction_t *txn; const char **args; }; @@ -30,8 +31,8 @@ apr_status_t database_connect(config_t *cfg) if (rv) { logging_log(cfg, LOGLEVEL_ERROR, - "DB: Could not load database driver %s. Error %s", cfg->dbdriver, - logging_strerror(rv)); + "DB: Could not load database driver %s. Error %s", + cfg->dbdriver, logging_strerror(rv)); return rv; } @@ -39,7 +40,8 @@ apr_status_t database_connect(config_t *cfg) &(cfg->dbconn->dbd)); if (rv) { logging_log(cfg, LOGLEVEL_ERROR, - "DB: Could not connect to database. Error (%d)%s", rv, logging_strerror(rv)); + "DB: Could not connect to database. Error (%d)%s", rv, + logging_strerror(rv)); return rv; } @@ -57,7 +59,7 @@ static apr_dbd_prepared_t *database_prepare_insert(config_t *cfg, apr_pool_t *p) char *sql; int i, f; struct iovec *vec; - apr_dbd_prepared_t *stmt = NULL; + apr_dbd_prepared_t *stmt= NULL; int nfs = cfg->output_fields->nelts; config_output_field_t *ofields; @@ -95,12 +97,14 @@ static apr_dbd_prepared_t *database_prepare_insert(config_t *cfg, apr_pool_t *p) "INSERT", &stmt); if (rv) { - logging_log(cfg, LOGLEVEL_NOISE, "DB: Unable to Prepare SQL insert: %s", - apr_dbd_error(cfg->dbconn->driver, cfg->dbconn->dbd, rv)); + logging_log(cfg, LOGLEVEL_NOISE, + "DB: Unable to Prepare SQL insert: %s", apr_dbd_error( + cfg->dbconn->driver, cfg->dbconn->dbd, rv)); return NULL; } return stmt; } + apr_status_t database_insert(config_t *cfg, apr_pool_t *p, apr_table_t *data) { apr_status_t rv; @@ -129,10 +133,25 @@ apr_status_t database_insert(config_t *cfg, apr_pool_t *p, apr_table_t *data) return APR_SUCCESS; } -/** @todo implement transactions */ apr_status_t database_trans_start(config_t *cfg, apr_pool_t *p) { #if HAVE_APR_DBD_TRANSACTION_MODE_GET + apr_status_t rv; + if (!cfg->transactions) + return APR_SUCCESS; + if (cfg->dbconn->txn) { + logging_log(cfg, LOGLEVEL_NOISE, + "Transaction Already Started. Something is BROKE"); + return APR_EINVAL; + } + logging_log(cfg, LOGLEVEL_DEBUG, "DB: Starting Transaction"); + rv = apr_dbd_transaction_start(cfg->dbconn->driver, p, cfg->dbconn->dbd, + &cfg->dbconn->txn); + if (rv) + logging_log(cfg, LOGLEVEL_NOISE, + "DB: Error Starting Transaction: (%d)%s", rv, apr_dbd_error( + cfg->dbconn->driver, cfg->dbconn->dbd, rv)); + return rv; #else return APR_SUCCESS; #endif @@ -141,6 +160,23 @@ apr_status_t database_trans_start(config_t *cfg, apr_pool_t *p) apr_status_t database_trans_stop(config_t *cfg, apr_pool_t *p) { #if HAVE_APR_DBD_TRANSACTION_MODE_GET + apr_status_t rv; + if (!cfg->transactions) + return APR_SUCCESS; + if (!cfg->dbconn->txn) { + logging_log(cfg, LOGLEVEL_NOISE, + "No Transaction Started. Something is BROKE"); + return APR_EINVAL; + } + logging_log(cfg, LOGLEVEL_DEBUG, "DB: Stopping Transaction"); + rv = apr_dbd_transaction_end(cfg->dbconn->driver, p, cfg->dbconn->txn); + if (rv) + logging_log(cfg, LOGLEVEL_NOISE, + "DB: Error Stopping Transaction: (%d)%s", rv, apr_dbd_error( + cfg->dbconn->driver, cfg->dbconn->dbd, rv)); + + cfg->dbconn->txn = NULL; + return rv; #else return APR_SUCCESS; #endif @@ -149,6 +185,22 @@ apr_status_t database_trans_stop(config_t *cfg, apr_pool_t *p) apr_status_t database_trans_abort(config_t *cfg) { #if HAVE_APR_DBD_TRANSACTION_MODE_GET + apr_status_t rv; + if (!cfg->transactions) + return APR_SUCCESS; + if (!cfg->dbconn->txn) { + logging_log(cfg, LOGLEVEL_NOISE, + "No Transaction Started. Something is BROKE"); + return APR_EINVAL; + } + logging_log(cfg, LOGLEVEL_NOTICE, "DB: Aborting Transaction"); + rv = apr_dbd_transaction_mode_set(cfg->dbconn->driver, cfg->dbconn->txn, + APR_DBD_TRANSACTION_ROLLBACK); + if (rv) + logging_log(cfg, LOGLEVEL_NOISE, + "DB: Error Aborting Transaction: (%d)%s", rv, apr_dbd_error( + cfg->dbconn->driver, cfg->dbconn->dbd, rv)); + return rv; #else return APR_SUCCESS; #endif diff --git a/utility/logparse.c b/utility/logparse.c index ac70ee2..923b581 100644 --- a/utility/logparse.c +++ b/utility/logparse.c @@ -359,6 +359,9 @@ apr_status_t parse_logfile(config_t *cfg, const char *filename) } line = 0; + // Start Transaction + database_trans_start(cfg,tp); + do { rv = apr_file_gets(buff, 1024, file); if (rv == APR_SUCCESS) { @@ -396,6 +399,7 @@ apr_status_t parse_logfile(config_t *cfg, const char *filename) rv = parse_processline(targp, cfg, line, targv, targc); if (rv != APR_SUCCESS) { int i; + database_trans_abort(cfg); logging_log(cfg, LOGLEVEL_ERROR, "Line %d(%d): %s", line, targc, buff); for (i = 0; targv[i]; i++) { @@ -403,14 +407,20 @@ apr_status_t parse_logfile(config_t *cfg, const char *filename) targv[i]); } } + } else { + rv = APR_SUCCESS; + break; } } while (rv == APR_SUCCESS); apr_file_close(file); + // Finish Transaction + database_trans_stop(cfg,tp); + apr_pool_destroy(tp); logging_log(cfg, LOGLEVEL_NOTICE, "PARSER: Finish Parsing Log File '%s'. Lines: %d", filename, line); - return APR_SUCCESS; + return rv; } apr_status_t parse_processline(apr_pool_t *ptemp, config_t *cfg, int line, diff --git a/utility/mod_log_sql.conf b/utility/mod_log_sql.conf index fde7cc6..54ac85d 100644 --- a/utility/mod_log_sql.conf +++ b/utility/mod_log_sql.conf @@ -29,13 +29,13 @@ LogFormatConfig Combined agent String LogFormat Combined -Linefilter - "BAD" -LineFilter "GOOD" -LineFilter + "BETTER" +#Linefilter - "BAD" +#LineFilter "GOOD" +#LineFilter + "BETTER" # the next filter ignores ALL lines -LineFilter - -PreFilter request + "Rebuild" -PostFilter request_method "GET" +#LineFilter - +#PreFilter request + "Rebuild" +#PostFilter request_method "GET" # Usage field datatype(size) default source [function [param]...] OutputField bytes_sent int 0 bytes_sent diff --git a/utility/shell.c b/utility/shell.c index 3de65b3..5f011a6 100644 --- a/utility/shell.c +++ b/utility/shell.c @@ -21,7 +21,7 @@ const apr_getopt_option_t _opt_config[] = { {"config", 'c', 1, "Configuration file to use (default mod_log_sql.conf)"}, {"dryrun", 'n', 0, "Perform a dry run (do not actually alter the databse)"}, {"dump", 'd', 0, "Dump the configuration after parsing and quit"}, - {"loglevel", 'l', 1, "Log Level (deubg, warn, error)"}, + {"loglevel", 'l', 1, "Log Level (deubg, notice, error)"}, {"summary", 's', 1, "Summary (yes,no)"}, {"help", 'h', 0, "Show Help"}, {NULL} @@ -170,7 +170,12 @@ int main(int argc, const char *const argv[]) int f, l; filelist = (char **)cfg->input_files->elts; for (f=0, l=cfg->input_files->nelts; f < l; f++) { - parse_logfile(cfg, filelist[f]); + rv = parse_logfile(cfg, filelist[f]); + if (rv) { + logging_log(cfg, LOGLEVEL_NOISE, + "Error occured parsing log files. Aborting"); + break; + } } } else { logging_log(cfg,LOGLEVEL_NOISE,"No log files found to parse"); -- cgit v0.9.2