From 259547654123f16c7b080b904a0c10b3b8c7fe93 Mon Sep 17 00:00:00 2001 From: Peter Dillinger Date: Tue, 30 Jul 2024 17:38:30 -0700 Subject: [PATCH] Fix rare WAL handling crash (#12899) Summary: A crash test failure in log sync in DBImpl::WriteToWAL is due to a missed case in https://github.com/facebook/rocksdb/issues/12734. Just need to apply similar logic from DBImpl::SyncWalImpl to check for an already closed WAL (nullptr writer). This is extremely rare because it only comes from failed Sync on a closed WAL. Pull Request resolved: https://github.com/facebook/rocksdb/pull/12899 Test Plan: watch crash test Reviewed By: cbi42 Differential Revision: D60481652 Pulled By: pdillinger fbshipit-source-id: 4a176bb6a53dcf077f88344710a110c2f946c386 --- db/db_impl/db_impl_write.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/db/db_impl/db_impl_write.cc b/db/db_impl/db_impl_write.cc index 8045c1bd1a1..ec5283ad949 100644 --- a/db/db_impl/db_impl_write.cc +++ b/db/db_impl/db_impl_write.cc @@ -1484,9 +1484,14 @@ IOStatus DBImpl::WriteToWAL(const WriteThread::WriteGroup& write_group, if (!io_s.ok()) { break; } - io_s = log.writer->file()->Sync(opts, immutable_db_options_.use_fsync); - if (!io_s.ok()) { - break; + // If last sync failed on a later WAL, this could be a fully synced + // and closed WAL that just needs to be recorded as synced in the + // manifest. + if (auto* f = log.writer->file()) { + io_s = f->Sync(opts, immutable_db_options_.use_fsync); + if (!io_s.ok()) { + break; + } } } }