Retain previous trace file in db_stress for debugging purposes (#12978)

Summary:
There are several crash test failures due to DB verification failure. Retain some trace history in the expected state directory to make debugging easier.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/12978

Reviewed By: cbi42

Differential Revision: D61864921

Pulled By: anand1976

fbshipit-source-id: 9f3f37b7e1e958bc89a3cf0373182354c2c1aa3b
This commit is contained in:
anand76 2024-08-27 12:43:47 -07:00 committed by Facebook GitHub Bot
parent 0082907bf2
commit f31b4d80ff
1 changed files with 25 additions and 2 deletions

View File

@ -732,8 +732,31 @@ Status FileExpectedStateManager::Restore(DB* db) {
s = Env::Default()->DeleteFile(state_file_path);
}
if (s.ok()) {
saved_seqno_ = kMaxSequenceNumber;
s = Env::Default()->DeleteFile(trace_file_path);
std::vector<std::string> expected_state_dir_children;
s = Env::Default()->GetChildren(expected_state_dir_path_,
&expected_state_dir_children);
if (s.ok()) {
for (size_t i = 0; i < expected_state_dir_children.size(); ++i) {
const auto& filename = expected_state_dir_children[i];
if (filename.size() >= kTraceFilenameSuffix.size() &&
filename.rfind(kTraceFilenameSuffix) ==
filename.size() - kTraceFilenameSuffix.size()) {
SequenceNumber found_seqno = ParseUint64(filename.substr(
0, filename.size() - kTraceFilenameSuffix.size()));
// Delete older trace files, but keep the one we just replayed for
// debugging purposes
if (found_seqno < saved_seqno_) {
s = Env::Default()->DeleteFile(GetPathForFilename(filename));
}
}
if (!s.ok()) {
break;
}
}
}
if (s.ok()) {
saved_seqno_ = kMaxSequenceNumber;
}
}
return s;
}