From 0c785a442bb240bc31c5cc4eb85d955b82a32a23 Mon Sep 17 00:00:00 2001 From: Yanqin Jin Date: Tue, 16 Jun 2020 12:56:43 -0700 Subject: [PATCH] Fix a bug of overwriting return code (#6989) Summary: In best-efforts recovery, an error that is not Corruption or IOError::kNotFound or IOError::kPathNotFound will be overwritten silently. Fix this by checking all non-ok cases and return early. Pull Request resolved: https://github.com/facebook/rocksdb/pull/6989 Test Plan: make check Reviewed By: ajkr Differential Revision: D22071418 Pulled By: riversand963 fbshipit-source-id: 5a4ea5dfb1a41f41c7a3fdaf62b163007b42f04b --- HISTORY.md | 1 + db/version_edit_handler.cc | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 85d2fa5b2..e8c8ada8f 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,7 @@ ## 6.10.3 (6/16/2020) ### Bug fix * Best-efforts recovery ignores CURRENT file completely. If CURRENT file is missing during recovery, best-efforts recovery still proceeds with MANIFEST file(s). +* In best-efforts recovery, an error that is not Corruption or IOError::kNotFound or IOError::kPathNotFound will be overwritten silently. Fix this by checking all non-ok cases and return early. ## 6.10.2 (6/5/2020) ### Bug fix diff --git a/db/version_edit_handler.cc b/db/version_edit_handler.cc index 3d03614c4..cd5197878 100644 --- a/db/version_edit_handler.cc +++ b/db/version_edit_handler.cc @@ -404,13 +404,12 @@ Status VersionEditHandler::LoadTables(ColumnFamilyData* cfd, bool is_initial_load) { assert(cfd != nullptr); assert(!cfd->IsDropped()); - Status s; auto builder_iter = builders_.find(cfd->GetID()); assert(builder_iter != builders_.end()); assert(builder_iter->second != nullptr); VersionBuilder* builder = builder_iter->second->version_builder(); assert(builder); - s = builder->LoadTableHandlers( + Status s = builder->LoadTableHandlers( cfd->internal_stats(), version_set_->db_options_->max_file_opening_threads, prefetch_index_and_filter_in_cache, is_initial_load, @@ -550,6 +549,8 @@ Status VersionEditHandlerPointInTime::MaybeCreateVersion( if (s.IsPathNotFound() || s.IsNotFound() || s.IsCorruption()) { missing_files.insert(file_num); s = Status::OK(); + } else if (!s.ok()) { + break; } } bool missing_info = !version_edit_params_.has_log_number_ || @@ -557,8 +558,9 @@ Status VersionEditHandlerPointInTime::MaybeCreateVersion( !version_edit_params_.has_last_sequence_; // Create version before apply edit - if (!missing_info && ((!missing_files.empty() && !prev_has_missing_files) || - (missing_files.empty() && force_create_version))) { + if (s.ok() && !missing_info && + ((!missing_files.empty() && !prev_has_missing_files) || + (missing_files.empty() && force_create_version))) { auto builder_iter = builders_.find(cfd->GetID()); assert(builder_iter != builders_.end()); auto* builder = builder_iter->second->version_builder();