From 51dc17d1c3aeabc2142ea90efad5fd206d612992 Mon Sep 17 00:00:00 2001 From: Sears Russell Date: Thu, 21 Jan 2010 23:48:04 +0000 Subject: [PATCH] fail earlier on mismatched truncation file. One run of check_multiplexer saw truncation leave a zero byte log --- src/stasis/logger/safeWrites.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/stasis/logger/safeWrites.c b/src/stasis/logger/safeWrites.c index 78dca57..4ffbe36 100644 --- a/src/stasis/logger/safeWrites.c +++ b/src/stasis/logger/safeWrites.c @@ -695,6 +695,21 @@ static int truncateLog_LogWriter(stasis_log_t* log, lsn_t LSN) { */ fclose(sw->fp); close(sw->ro_fd); + + lsn_t tmpLen = myFseek(tmpLog, 0, SEEK_END); + if(tmpLen != sw->nextAvailableLSN - sw->global_offset) { + if(tmpLen == -1) { + perror("Truncation couldn't seek"); + } else { + printf("Temporary logfile was wrong length after copying, but before truncation. No data has been lost. Aborting. " + "Expected %lld, copied %lld, found %lld\n", + sw->nextAvailableLSN - sw->global_offset, lengthOfCopiedLog+sizeof(lsn_t), tmpLen); + fflush(stdout); + abort(); + } + } + + fclose(tmpLog); if(rename(sw->scratch_filename, sw->filename)) { @@ -738,7 +753,7 @@ static int truncateLog_LogWriter(stasis_log_t* log, lsn_t LSN) { } else { printf("logfile was wrong length after truncation. " "Expected %lld, copied %lld, found %lld\n", - sw->nextAvailableLSN - sw->global_offset, lengthOfCopiedLog, logPos); + sw->nextAvailableLSN - sw->global_offset, lengthOfCopiedLog+sizeof(lsn_t), logPos); fflush(stdout); abort(); }