fail earlier on mismatched truncation file. One run of check_multiplexer saw truncation leave a zero byte log

This commit is contained in:
Sears Russell 2010-01-21 23:48:04 +00:00
parent bb92d86c85
commit 51dc17d1c3

View file

@ -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();
}