Fix possible crash test segfault in FileExpectedStateManager::Restore() (#12314)

Summary:
`replayer` could be `nullptr` if `!s.ok()` from an earlier failure. Also consider status returned from `record->Accept()`.

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

Test Plan: blackbox_crash_test run

Reviewed By: hx235

Differential Revision: D53241506

Pulled By: pdillinger

fbshipit-source-id: fd330417c23391ca819c3ee0f69e4156d81934dc
This commit is contained in:
Peter Dillinger
2024-01-30 16:16:04 -08:00
committed by Facebook GitHub Bot
parent 377eee77f8
commit acf77e1bfe
+14 -14
View File
@@ -660,26 +660,26 @@ Status FileExpectedStateManager::Restore(DB* db) {
if (s.ok()) {
s = replayer->Prepare();
}
for (;;) {
for (; s.ok();) {
std::unique_ptr<TraceRecord> record;
s = replayer->Next(&record);
if (!s.ok()) {
if (s.IsCorruption() && handler->IsDone()) {
// There could be a corruption reading the tail record of the trace
// due to `db_stress` crashing while writing it. It shouldn't matter
// as long as we already found all the write ops we need to catch up
// the expected state.
s = Status::OK();
}
if (s.IsIncomplete()) {
// OK because `Status::Incomplete` is expected upon finishing all the
// trace records.
s = Status::OK();
}
break;
}
std::unique_ptr<TraceRecordResult> res;
record->Accept(handler.get(), &res);
}
if (s.IsCorruption() && handler->IsDone()) {
// There could be a corruption reading the tail record of the trace due to
// `db_stress` crashing while writing it. It shouldn't matter as long as
// we already found all the write ops we need to catch up the expected
// state.
s = Status::OK();
}
if (s.IsIncomplete()) {
// OK because `Status::Incomplete` is expected upon finishing all the
// trace records.
s = Status::OK();
s = record->Accept(handler.get(), &res);
}
}