mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Sanity check on Open
Summary: Everytime a client opens a DB, we do a sanity check that: * checks the existance of all the necessary files * verifies that file sizes are correct Some of the code was stolen from https://reviews.facebook.net/D16935 Test Plan: added a unit test Reviewers: dhruba, haobo, sdong Reviewed By: dhruba CC: leveldb Differential Revision: https://reviews.facebook.net/D17097
This commit is contained in:
@@ -99,46 +99,4 @@ Status DB::OpenForReadOnly(const Options& options, const std::string& dbname,
|
||||
return s;
|
||||
}
|
||||
|
||||
Status DB::CheckConsistency(const Options& options,
|
||||
const std::string& name) {
|
||||
DB *db = nullptr;
|
||||
Status st;
|
||||
|
||||
st = DB::OpenForReadOnly(options, name, &db);
|
||||
if (!st.ok()) {
|
||||
return st;
|
||||
}
|
||||
|
||||
std::vector<LiveFileMetaData> metadata;
|
||||
db->GetLiveFilesMetaData(&metadata);
|
||||
|
||||
for (const auto& md : metadata) {
|
||||
std::string file_path = name + md.name;
|
||||
|
||||
if (!db->GetEnv()->FileExists(file_path)) {
|
||||
st = Status::Corruption("sst file " + md.name + " doesn't exist");
|
||||
break;
|
||||
}
|
||||
|
||||
uint64_t fsize = 0;
|
||||
st = db->GetEnv()->GetFileSize(file_path, &fsize);
|
||||
if (!st.ok()) {
|
||||
st = Status::Corruption(
|
||||
"Failed to determine the actual size of file " + md.name +
|
||||
": " + st.ToString());
|
||||
break;
|
||||
}
|
||||
if (fsize != md.size) {
|
||||
st = Status::Corruption(
|
||||
"sst file size mismatch: " + md.name +
|
||||
". Size recorded in manifest " + std::to_string(md.size) +
|
||||
", actual size " + std::to_string(fsize));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delete db;
|
||||
return st;
|
||||
}
|
||||
|
||||
} // namespace rocksdb
|
||||
|
||||
Reference in New Issue
Block a user