diff --git a/db/version_edit_handler.cc b/db/version_edit_handler.cc index c944a46ca..3fc25a010 100644 --- a/db/version_edit_handler.cc +++ b/db/version_edit_handler.cc @@ -10,6 +10,7 @@ #include "db/version_edit_handler.h" #include +#include #include "db/blob/blob_file_cache.h" #include "db/blob/blob_file_reader.h" @@ -68,6 +69,26 @@ void VersionEditHandlerBase::Iterate(log::Reader& reader, CheckIterationResult(reader, &s); if (!s.ok()) { + if (s.IsCorruption()) { + // when we find a Corruption error, something is + // wrong with the underlying file. in this case we + // want to report the filename, so in here we append + // the filename to the Corruption message + assert(reader.file()); + + // build a new error message + std::stringstream message; + // append previous dynamic state message + const char* state = s.getState(); + if (state != nullptr) { + message << state; + message << ' '; + } + // append the filename to the corruption message + message << "in file " << reader.file()->file_name(); + // overwrite the status with the extended status + s = Status(s.code(), s.subcode(), s.severity(), message.str()); + } status_ = s; } TEST_SYNC_POINT_CALLBACK("VersionEditHandlerBase::Iterate:Finish", diff --git a/db/version_set_test.cc b/db/version_set_test.cc index 9f5bd272e..bb3df039b 100644 --- a/db/version_set_test.cc +++ b/db/version_set_test.cc @@ -2629,6 +2629,7 @@ TEST_P(VersionSetTestEmptyDb, OpenFromIncompleteManifest0) { if (iter == cf_names.end()) { ASSERT_TRUE(s.IsInvalidArgument()); } else { + ASSERT_NE(s.ToString().find(manifest_path), std::string::npos); ASSERT_TRUE(s.IsCorruption()); } } @@ -2670,6 +2671,7 @@ TEST_P(VersionSetTestEmptyDb, OpenFromIncompleteManifest1) { if (iter == cf_names.end()) { ASSERT_TRUE(s.IsInvalidArgument()); } else { + ASSERT_NE(s.ToString().find(manifest_path), std::string::npos); ASSERT_TRUE(s.IsCorruption()); } } @@ -2716,6 +2718,7 @@ TEST_P(VersionSetTestEmptyDb, OpenFromInCompleteManifest2) { if (iter == cf_names.end()) { ASSERT_TRUE(s.IsInvalidArgument()); } else { + ASSERT_NE(s.ToString().find(manifest_path), std::string::npos); ASSERT_TRUE(s.IsCorruption()); } } @@ -2773,6 +2776,7 @@ TEST_P(VersionSetTestEmptyDb, OpenManifestWithUnknownCF) { if (iter == cf_names.end()) { ASSERT_TRUE(s.IsInvalidArgument()); } else { + ASSERT_NE(s.ToString().find(manifest_path), std::string::npos); ASSERT_TRUE(s.IsCorruption()); } }