Changeset: 56baf90dcc60 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=56baf90dcc60 Modified Files: gdk/gdk_logger.c gdk/gdk_logger.h monetdb5/modules/kernel/logger.c sql/server/sql_mvc.c sql/storage/bat/bat_logger.c sql/storage/restrict/restrict_logger.c sql/storage/sql_storage.h sql/storage/store.c Branch: transaction-replication Log Message:
Preserve the WAL files already persisted in the BATs Add a flag to keep the older WAL files and propagate down to logger_cleanup diffs (243 lines): diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c --- a/gdk/gdk_logger.c +++ b/gdk/gdk_logger.c @@ -1461,7 +1461,7 @@ logger_load(int debug, char* fn, char fi /* Initialize a new logger * It will load any data in the logdir and persist it in the BATs*/ static logger * -logger_new(int debug, char *fn, char *logdir, int version, preversionfix_fptr prefuncp, postversionfix_fptr postfuncp, int readonly) +logger_new(int debug, char *fn, char *logdir, int version, preversionfix_fptr prefuncp, postversionfix_fptr postfuncp, int readonly, int keep_logs_files) { logger *lg = (struct logger *) GDKmalloc(sizeof(struct logger)); char filename[BUFSIZ]; @@ -1473,6 +1473,7 @@ logger_new(int debug, char *fn, char *lo lg->debug = debug; lg->readonly = readonly; + lg->keep_logs_files = keep_logs_files; lg->changes = 0; lg->version = version; @@ -1530,9 +1531,9 @@ logger_reload(logger *lg) /* Create a logger */ logger * -logger_create(int debug, char *fn, char *logdir, int version, preversionfix_fptr prefuncp, postversionfix_fptr postfuncp) +logger_create(int debug, char *fn, char *logdir, int version, int keep_logs_files, preversionfix_fptr prefuncp, postversionfix_fptr postfuncp) { - logger *lg = logger_new(debug, fn, logdir, version, prefuncp, postfuncp, 0); + logger *lg = logger_new(debug, fn, logdir, version, prefuncp, postfuncp, 0, keep_logs_files); if (!lg) return NULL; @@ -1554,11 +1555,11 @@ logger_create(int debug, char *fn, char /* Create new read-only logger * Usually reserved for shared log directories */ logger * -logger_create_ro(int debug, char *fn, char *logdir, int version, preversionfix_fptr prefuncp, postversionfix_fptr postfuncp) +logger_create_ro(int debug, char *fn, char *logdir, int version, int keep_logs_files, preversionfix_fptr prefuncp, postversionfix_fptr postfuncp) { logger *lg = NULL; - lg = logger_new(debug, fn, logdir, version, prefuncp, postfuncp, 1); + lg = logger_new(debug, fn, logdir, version, prefuncp, postfuncp, 1, keep_logs_files); return lg; } @@ -1669,36 +1670,38 @@ logger_restart(logger *lg) int logger_cleanup(logger *lg) { - char buf[BUFSIZ]; - char id[BUFSIZ]; - FILE *fp = NULL; + if (!lg->keep_logs_files) { + char buf[BUFSIZ]; + char id[BUFSIZ]; + FILE *fp = NULL; - snprintf(buf, BUFSIZ, "%s%s.bak-" LLFMT, lg->dir, LOGFILE, lg->id); + snprintf(buf, BUFSIZ, "%s%s.bak-" LLFMT, lg->dir, LOGFILE, lg->id); - if (lg->debug & 1) - fprintf(stderr, "#logger_cleanup %s\n", buf); + if (lg->debug & 1) + fprintf(stderr, "#logger_cleanup %s\n", buf); - if ((fp = fopen(buf, "r")) == NULL) { - fprintf(stderr, "!ERROR: logger_cleanup: cannot open file %s\n", buf); - return LOG_ERR; + if ((fp = fopen(buf, "r")) == NULL) { + fprintf(stderr, "!ERROR: logger_cleanup: cannot open file %s\n", buf); + return LOG_ERR; + } + + /* skip catalog */ + while (fgets(id, BUFSIZ, fp) != NULL && id[0] != '\n') + ; + + while (fgets(id, BUFSIZ, fp) != NULL) { + char *e = strchr(id, '\n'); + + if (e) + *e = 0; + GDKunlink(lg->dir, LOGFILE, id); + } + fclose(fp); + snprintf(buf, BUFSIZ, "bak-" LLFMT, lg->id); + + GDKunlink(lg->dir, LOGFILE, buf); + } - - /* skip catalog */ - while (fgets(id, BUFSIZ, fp) != NULL && id[0] != '\n') - ; - - while (fgets(id, BUFSIZ, fp) != NULL) { - char *e = strchr(id, '\n'); - - if (e) - *e = 0; - GDKunlink(lg->dir, LOGFILE, id); - } - fclose(fp); - snprintf(buf, BUFSIZ, "bak-" LLFMT, lg->id); - - GDKunlink(lg->dir, LOGFILE, buf); - return LOG_OK; } diff --git a/gdk/gdk_logger.h b/gdk/gdk_logger.h --- a/gdk/gdk_logger.h +++ b/gdk/gdk_logger.h @@ -61,6 +61,7 @@ typedef struct logger { char *fn; char *dir; int readonly; /* a flag to indicate if the logger is read-only */ + int keep_logs_files; /* a flag if old WAL files should be preserved */ preversionfix_fptr prefuncp; postversionfix_fptr postfuncp; stream *log; @@ -86,6 +87,7 @@ typedef struct logger_settings { char *logdir; /* (the regular) server write-ahead log directory */ char *shared_logdir; /* shared write-ahead log directory */ int shared_drift_threshold; /* shared write-ahead log drift threshold */ + int keep_logs_files; /* a flag if old WAL files should be preserved */ } logger_settings; #define BATSIZE 0 @@ -109,8 +111,8 @@ typedef int log_bid; /* the sequence identifier for frontend objects */ #define OBJ_SID 1 -gdk_export logger *logger_create(int debug, char *fn, char *logdir, int version, preversionfix_fptr prefuncp, postversionfix_fptr postfuncp); -gdk_export logger *logger_create_ro(int debug, char *fn, char *logdir, int version, preversionfix_fptr prefuncp, postversionfix_fptr postfuncp); +gdk_export logger *logger_create(int debug, char *fn, char *logdir, int version, int keep_logs_files, preversionfix_fptr prefuncp, postversionfix_fptr postfuncp); +gdk_export logger *logger_create_ro(int debug, char *fn, char *logdir, int version, int keep_logs_files, preversionfix_fptr prefuncp, postversionfix_fptr postfuncp); gdk_export void logger_destroy(logger *lg); gdk_export int logger_exit(logger *lg); gdk_export int logger_restart(logger *lg); diff --git a/monetdb5/modules/kernel/logger.c b/monetdb5/modules/kernel/logger.c --- a/monetdb5/modules/kernel/logger.c +++ b/monetdb5/modules/kernel/logger.c @@ -90,7 +90,7 @@ logger_export str logger_create_wrap( lo str logger_create_wrap( logger *L, int *debug, str *fn, str *dirname, int *version) { - logger *l = logger_create(*debug, *fn, *dirname, *version, NULL, NULL); + logger *l = logger_create(*debug, *fn, *dirname, *version, 0, NULL, NULL); if (l) { *(logger**)L = l; diff --git a/sql/server/sql_mvc.c b/sql/server/sql_mvc.c --- a/sql/server/sql_mvc.c +++ b/sql/server/sql_mvc.c @@ -51,6 +51,9 @@ mvc_init(int debug, store_type store, in * -1 by default, meaning it should be ignored, since it is not set */ log_settings->shared_drift_threshold = GDKgetenv_int("gdk_shared_drift_threshold", -1); + /* Get and pass on the flag if old WAL files should be preserved. 0 (no) by default */ + log_settings->keep_logs_files = GDKgetenv_int("gdk_keep_logs_files", 0); + mvc_debug = debug&4; if (mvc_debug) { fprintf(stderr, "#mvc_init logdir %s\n", log_settings->logdir); diff --git a/sql/storage/bat/bat_logger.c b/sql/storage/bat/bat_logger.c --- a/sql/storage/bat/bat_logger.c +++ b/sql/storage/bat/bat_logger.c @@ -276,22 +276,22 @@ bl_postversion( void *lg) } static int -bl_create(int debug, char *logdir, int cat_version) +bl_create(int debug, char *logdir, int cat_version, int keep_logs_files) { if (bat_logger) return LOG_ERR; - bat_logger = logger_create(debug, "sql", logdir, cat_version, bl_preversion, bl_postversion); + bat_logger = logger_create(debug, "sql", logdir, cat_version, keep_logs_files, bl_preversion, bl_postversion); if (bat_logger) return LOG_OK; return LOG_ERR; } static int -bl_create_shared(int debug, char *logdir, int cat_version) +bl_create_shared(int debug, char *logdir, int cat_version, int keep_logs_files) { if (bat_logger_shared) return LOG_ERR; - bat_logger_shared = logger_create_ro(debug, "sql", logdir, cat_version, bl_preversion, bl_postversion); + bat_logger_shared = logger_create_ro(debug, "sql", logdir, cat_version, keep_logs_files, bl_preversion, bl_postversion); if (bat_logger_shared) return LOG_OK; return LOG_ERR; diff --git a/sql/storage/restrict/restrict_logger.c b/sql/storage/restrict/restrict_logger.c --- a/sql/storage/restrict/restrict_logger.c +++ b/sql/storage/restrict/restrict_logger.c @@ -27,7 +27,7 @@ bl_create(int debug, char *logdir, int c { if (restrict_logger) return LOG_ERR; - restrict_logger = logger_create(debug, "sql", logdir, catalog_version, NULL, NULL, 0); + restrict_logger = logger_create(debug, "sql", logdir, catalog_version, 0, NULL, NULL); if (restrict_logger) return LOG_OK; return LOG_ERR; diff --git a/sql/storage/sql_storage.h b/sql/storage/sql_storage.h --- a/sql/storage/sql_storage.h +++ b/sql/storage/sql_storage.h @@ -247,8 +247,8 @@ typedef struct store_functions { extern store_functions store_funcs; -typedef int (*logger_create_fptr) (int debug, char *logdir, int catalog_version); -typedef int (*logger_create_shared_fptr) (int debug, char *logdir, int catalog_version); +typedef int (*logger_create_fptr) (int debug, char *logdir, int catalog_version, int keep_logs_files); +typedef int (*logger_create_shared_fptr) (int debug, char *logdir, int catalog_version, int keep_logs_files); typedef void (*logger_destroy_fptr) (void); typedef int (*logger_restart_fptr) (void); diff --git a/sql/storage/store.c b/sql/storage/store.c --- a/sql/storage/store.c +++ b/sql/storage/store.c @@ -1331,7 +1331,7 @@ store_init(int debug, store_type store, } active_store_type = store; if (!logger_funcs.create || - logger_funcs.create(debug, log_settings->logdir, CATALOG_VERSION*v) == LOG_ERR) { + logger_funcs.create(debug, log_settings->logdir, CATALOG_VERSION*v, log_settings->keep_logs_files) == LOG_ERR) { MT_lock_unset(&bs_lock, "store_init"); return -1; } @@ -1341,7 +1341,7 @@ store_init(int debug, store_type store, #ifdef STORE_DEBUG fprintf(stderr, "#store_init creating read-only logger\n"); #endif - if (!shared_logger_funcs.create || shared_logger_funcs.create(debug, log_settings->shared_logdir, CATALOG_VERSION*v) == LOG_ERR) { + if (!shared_logger_funcs.create || shared_logger_funcs.create(debug, log_settings->shared_logdir, CATALOG_VERSION*v, log_settings->keep_logs_files) == LOG_ERR) { MT_lock_unset(&bs_lock, "store_init"); return -1; } _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list