From 87649d3288094c528611fdbb25140a83482b8643 Mon Sep 17 00:00:00 2001 From: Jay Zhuang Date: Wed, 27 Jul 2022 20:16:38 -0700 Subject: [PATCH] Best efforts recovery to skip empty MANIFEST (#10416) Summary: Skip empty MANIFEST fie during best_efforts_recovery. Pull Request resolved: https://github.com/facebook/rocksdb/pull/10416 Test Plan: make failed db_stress test pass Reviewed By: riversand963 Differential Revision: D38126273 Pulled By: jay-zhuang fbshipit-source-id: 4498d322b09eaa194dd2cbf9c683d62ab54bfb01 --- HISTORY.md | 1 + db/db_impl/db_impl_open.cc | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index a38f5ad54..0a976033e 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -16,6 +16,7 @@ * Fix race conditions in `GenericRateLimiter`. * Fix a bug in `FIFOCompactionPicker::PickTTLCompaction` where total_size calculating might cause underflow * Fix data race bug in hash linked list memtable. With this bug, read request might temporarily miss an old record in the memtable in a race condition to the hash bucket. +* Fix a bug that `best_efforts_recovery` may fail to open the db with mmap read. ### Behavior Change * Added checksum handshake during the copying of decompressed WAL fragment. This together with #9875, #10037, #10212, #10114 and #10319 provides end-to-end integrity protection for write batch during recovery. diff --git a/db/db_impl/db_impl_open.cc b/db/db_impl/db_impl_open.cc index 47d558e57..afeb8de50 100644 --- a/db/db_impl/db_impl_open.cc +++ b/db/db_impl/db_impl_open.cc @@ -441,11 +441,14 @@ Status DBImpl::Recover( uint64_t number = 0; FileType type = kWalFile; // initialize if (ParseFileName(file, &number, &type) && type == kDescriptorFile) { - // Found MANIFEST (descriptor log), thus best-efforts recovery does - // not have to treat the db as empty. - s = Status::OK(); - manifest_path = dbname_ + "/" + file; - break; + uint64_t bytes; + s = env_->GetFileSize(DescriptorFileName(dbname_, number), &bytes); + if (s.ok() && bytes != 0) { + // Found non-empty MANIFEST (descriptor log), thus best-efforts + // recovery does not have to treat the db as empty. + manifest_path = dbname_ + "/" + file; + break; + } } } }