db/log_reader: move kBadRecord{Len,Checksum} handling into ReadRecord

The behavior here needs to depend on the WAL recovery mode.  No functional
change in this patch.

Signed-off-by: Sage Weil <sage@redhat.com>
main
Sage Weil 9 years ago committed by krad
parent 847e471db6
commit 7947aba68c
  1. 24
      db/log_reader.cc
  2. 4
      db/log_reader.h

@ -191,6 +191,24 @@ bool Reader::ReadRecord(Slice* record, std::string* scratch,
}
break;
case kBadRecordLen:
ReportCorruption(drop_size, "bad record length");
if (in_fragmented_record) {
ReportCorruption(scratch->size(), "error in middle of record");
in_fragmented_record = false;
scratch->clear();
}
break;
case kBadRecordChecksum:
ReportCorruption(drop_size, "checksum mismatch");
if (in_fragmented_record) {
ReportCorruption(scratch->size(), "error in middle of record");
in_fragmented_record = false;
scratch->clear();
}
break;
default: {
char buf[40];
snprintf(buf, sizeof(buf), "unknown record type %u", record_type);
@ -355,8 +373,7 @@ unsigned int Reader::ReadPhysicalRecord(Slice* result, size_t* drop_size) {
*drop_size = buffer_.size();
buffer_.clear();
if (!eof_) {
ReportCorruption(*drop_size, "bad record length");
return kBadRecord;
return kBadRecordLen;
}
// If the end of the file has been reached without reading |length| bytes
// of payload, assume the writer died in the middle of writing the record.
@ -388,8 +405,7 @@ unsigned int Reader::ReadPhysicalRecord(Slice* result, size_t* drop_size) {
// like a valid log record.
*drop_size = buffer_.size();
buffer_.clear();
ReportCorruption(*drop_size, "checksum mismatch");
return kBadRecord;
return kBadRecordChecksum;
}
}

@ -126,6 +126,10 @@ class Reader {
kBadHeader = kMaxRecordType + 3,
// Returned when we read an old record from a previous user of the log.
kOldRecord = kMaxRecordType + 4,
// Returned when we get a bad record length
kBadRecordLen = kMaxRecordType + 5,
// Returned when we get a bad record checksum
kBadRecordChecksum = kMaxRecordType + 6,
};
// Skips all blocks that are completely before "initial_offset_".

Loading…
Cancel
Save