Fail DB::Open() on WAL corruption

Summary:
This is a serious bug. If paranod_check == true and WAL is corrupted, we don't fail DB::Open(). I tried going into history and it seems we've been doing this for a long long time.

I found this when investigating t5852041.

Test Plan: Added unit test to verify correct behavior.

Reviewers: yhchiang, rven, sdong

Reviewed By: sdong

Subscribers: dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D30597
This commit is contained in:
Igor Canadi 2015-01-05 10:26:34 -08:00
parent 9619081d9b
commit d7b4bb62a7
2 changed files with 4 additions and 2 deletions

View File

@ -231,7 +231,9 @@ TEST(CorruptionTest, Recovery) {
Check(100, 100); Check(100, 100);
Corrupt(kLogFile, 19, 1); // WriteBatch tag for first record Corrupt(kLogFile, 19, 1); // WriteBatch tag for first record
Corrupt(kLogFile, log::kBlockSize + 1000, 1); // Somewhere in second block Corrupt(kLogFile, log::kBlockSize + 1000, 1); // Somewhere in second block
Reopen(); ASSERT_TRUE(!TryReopen().ok());
options_.paranoid_checks = false;
Reopen(&options_);
// The 64 records in the first two log blocks are completely lost. // The 64 records in the first two log blocks are completely lost.
Check(36, 36); Check(36, 36);

View File

@ -905,7 +905,7 @@ Status DBImpl::RecoverLogFiles(const std::vector<uint64_t>& log_numbers,
std::string scratch; std::string scratch;
Slice record; Slice record;
WriteBatch batch; WriteBatch batch;
while (reader.ReadRecord(&record, &scratch)) { while (reader.ReadRecord(&record, &scratch) && status.ok()) {
if (record.size() < 12) { if (record.size() < 12) {
reporter.Corruption(record.size(), reporter.Corruption(record.size(),
Status::Corruption("log record too small")); Status::Corruption("log record too small"));