diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2014-05-09 18:23:34 +0200 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2014-05-09 18:23:34 +0200 |
commit | aca47d2a24e39e6a05d85055ce3c6cbcabd8d50b (patch) | |
tree | 13b439a32f0486c910f59be32a009066193cb208 /src/leveldb/db/log_reader.cc | |
parent | 605d5b55582f00ea8a089fe632cd8a52e951126b (diff) | |
parent | 938b68984668445035b2505e1b7ec07649dd2bbc (diff) |
Merge src/leveldb changes for LevelDB 1.17.
Diffstat (limited to 'src/leveldb/db/log_reader.cc')
-rw-r--r-- | src/leveldb/db/log_reader.cc | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/leveldb/db/log_reader.cc b/src/leveldb/db/log_reader.cc index b35f115aad..4919216d04 100644 --- a/src/leveldb/db/log_reader.cc +++ b/src/leveldb/db/log_reader.cc @@ -133,7 +133,9 @@ bool Reader::ReadRecord(Slice* record, std::string* scratch) { case kEof: if (in_fragmented_record) { - ReportCorruption(scratch->size(), "partial record without end(3)"); + // This can be caused by the writer dying immediately after + // writing a physical record but before completing the next; don't + // treat it as a corruption, just ignore the entire logical record. scratch->clear(); } return false; @@ -193,13 +195,12 @@ unsigned int Reader::ReadPhysicalRecord(Slice* result) { eof_ = true; } continue; - } else if (buffer_.size() == 0) { - // End of file - return kEof; } else { - size_t drop_size = buffer_.size(); + // Note that if buffer_ is non-empty, we have a truncated header at the + // end of the file, which can be caused by the writer crashing in the + // middle of writing the header. Instead of considering this an error, + // just report EOF. buffer_.clear(); - ReportCorruption(drop_size, "truncated record at end of file"); return kEof; } } @@ -213,8 +214,14 @@ unsigned int Reader::ReadPhysicalRecord(Slice* result) { if (kHeaderSize + length > buffer_.size()) { size_t drop_size = buffer_.size(); buffer_.clear(); - ReportCorruption(drop_size, "bad record length"); - return kBadRecord; + if (!eof_) { + ReportCorruption(drop_size, "bad record length"); + return kBadRecord; + } + // 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. + // Don't report a corruption. + return kEof; } if (type == kZeroType && length == 0) { |