From 854eb76a8c8533779da7eaf21bef6266d9cca6aa Mon Sep 17 00:00:00 2001 From: Changyu Bi <102700264+cbi42@users.noreply.github.com> Date: Mon, 10 Jul 2023 15:52:38 -0700 Subject: [PATCH] Improve error message when an SST file in MANIFEST is not found (#11573) Summary: I got the following error message when an SST file is recorded in MANIFEST but is missing from the db folder. It's confusing in two ways: 1. The part about file "./074837.ldb" which RocksDB will attempt to open only after ./074837.sst is not found. 2. The last part about "No such file or directory in file ./MANIFEST-074507" sounds like `074837.ldb` is not found in manifest. ``` ldb --hex --db=. get some_key Failed: Corruption: Corruption: IO error: No such file or directory: While open a file for random read: ./074837.ldb: No such file or directory in file ./MANIFEST-074507 ``` Improving the error message a little bit: Pull Request resolved: https://github.com/facebook/rocksdb/pull/11573 Test Plan: run the same command after this PR ``` Failed: Corruption: Corruption: IO error: No such file or directory: While open a file for random read: ./074837.sst: No such file or directory The file ./MANIFEST-074507 may be corrupted. ``` Reviewed By: ajkr Differential Revision: D47192056 Pulled By: cbi42 fbshipit-source-id: 06863f376cc4455803cffb2250c41399b4c39467 --- db/table_cache.cc | 14 +++++++++----- db/version_edit_handler.cc | 3 ++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/db/table_cache.cc b/db/table_cache.cc index 0bbec70e1d..00224fd818 100644 --- a/db/table_cache.cc +++ b/db/table_cache.cc @@ -111,13 +111,17 @@ Status TableCache::GetTableReader( RecordTick(ioptions_.stats, NO_FILE_OPENS); } else if (s.IsPathNotFound()) { fname = Rocks2LevelTableFileName(fname); - s = PrepareIOFromReadOptions(ro, ioptions_.clock, fopts.io_options); - if (s.ok()) { - s = ioptions_.fs->NewRandomAccessFile(fname, file_options, &file, - nullptr); + // If this file is also not found, we want to use the error message + // that contains the table file name which is less confusing. + Status temp_s = + PrepareIOFromReadOptions(ro, ioptions_.clock, fopts.io_options); + if (temp_s.ok()) { + temp_s = ioptions_.fs->NewRandomAccessFile(fname, file_options, &file, + nullptr); } - if (s.ok()) { + if (temp_s.ok()) { RecordTick(ioptions_.stats, NO_FILE_OPENS); + s = temp_s; } } diff --git a/db/version_edit_handler.cc b/db/version_edit_handler.cc index 965213b586..732723996a 100644 --- a/db/version_edit_handler.cc +++ b/db/version_edit_handler.cc @@ -86,7 +86,8 @@ void VersionEditHandlerBase::Iterate(log::Reader& reader, message << ' '; } // append the filename to the corruption message - message << "in file " << reader.file()->file_name(); + message << " The file " << reader.file()->file_name() + << " may be corrupted."; // overwrite the status with the extended status s = Status(s.code(), s.subcode(), s.severity(), message.str()); }