Changeset: 13db52d6c282 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/13db52d6c282 Modified Files: gdk/gdk_logger.c gdk/gdk_logger_internals.h Branch: pax-log Log Message:
Check WAL consistency: While replaying the WAL, if the number of transactions doesn't match the sum of the transaction counts in the LOG_COMMIT messages, return a fatal error. diffs (85 lines): diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c --- a/gdk/gdk_logger.c +++ b/gdk/gdk_logger.c @@ -992,6 +992,7 @@ tr_commit(logger *lg, trans *tr) la_destroy(&tr->changes[i]); } lg->saved_tid = tr->tid; + lg->transaction_count++; return tr_destroy(tr); } @@ -1266,8 +1267,13 @@ log_read_transaction(logger *lg) } break; case LOG_COMMIT: - assert(l.id > 0); - // TODO + if(l.id < 0) { + err = LOG_ERR; + break; + } + lg->commit_count += (ulng) l.id; + if (lg->transaction_count == lg->commit_count) + lg->committed_tid = lg->saved_tid; break; default: err = LOG_ERR; @@ -1363,6 +1369,14 @@ log_readlogs(logger *lg, char *filename) if (lg->debug & 1) fprintf(stderr, "#log_readlogs logger id is " LLFMT " last logger id is " LLFMT "\n", lg->id, lg->saved_id); + /* simple consistency based on + * running counts of transactions and + * running sums of transaction counts in commit messages + */ + lg->committed_tid = 0; + lg->transaction_count = 0; + lg->commit_count = 0; + char log_filename[FILENAME_MAX]; if (lg->saved_id >= lg->id) { bool filemissing = false; @@ -1380,6 +1394,17 @@ log_readlogs(logger *lg, char *filename) } } } + + if (res == GDK_SUCCEED && lg->transaction_count != lg->commit_count) { + + GDKfatal( + "The last consistent transaction has id %d.\n" + "The transactions written after this transaction " + "are not followed by a correct set of commit messages.\n" + "This might indicate corruption of the Write-ahead log file(s) and/or\n" + "it might indicate that one or more following log files are missing.\n", lg->committed_tid); + } + return res; } @@ -2985,7 +3010,10 @@ log_tcommit(logger *lg, ulng commit_ts, gdk_return result; logformat l; l.flag = LOG_COMMIT; - l.id = cql; // number of transactions to be committed; + + /* number of transactions to be committed in this commit message. + * Only used for checking consistency when replaying the log.*/ + l.id = cql; /* if the log file being rotated at the moment, * wait for it to finish*/ diff --git a/gdk/gdk_logger_internals.h b/gdk/gdk_logger_internals.h --- a/gdk/gdk_logger_internals.h +++ b/gdk/gdk_logger_internals.h @@ -35,6 +35,9 @@ struct logger { ulng saved_id; /* id of last fully handled log file */ int tid; /* current transaction id */ int saved_tid; /* id of transaction which was flushed out (into BBP storage) */ + ulng transaction_count; + ulng commit_count; + int committed_tid; /*id of flushed transaction for which the proper commit messages are also flushed*/ bool flushing; bool flushnow; bool request_rotation; _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org