From f6a0065d541a37fdab2870d171a411acc5efe013 Mon Sep 17 00:00:00 2001 From: Hui Xiao Date: Mon, 10 Oct 2022 15:52:10 -0700 Subject: [PATCH] Allow Flush(sync=true) not supported in DB::Open() and db_stress (#10784) Summary: **Context:** https://github.com/facebook/rocksdb/pull/10698 made `Flush(sync=true)` required for` DB::Open()` (to pass the original but now deleted assertion `impl->TEST_WALBufferIsEmpty()` under `manual_wal_flush=true`, see https://github.com/facebook/rocksdb/pull/10698 summary for more ) as well as db_stress to pass. However RocksDB users may not implement SyncWAL() (used inFlush(sync=true)). Therefore we replace such in DB::Open and db_stress in this PR and align with https://github.com/facebook/rocksdb/blob/main/db/db_impl/db_impl_open.cc#L1883-L1887 and https://github.com/facebook/rocksdb/blob/main/db_stress_tool/db_stress_test_base.cc#L847-L849 Pull Request resolved: https://github.com/facebook/rocksdb/pull/10784 Test Plan: make check Reviewed By: anand1976 Differential Revision: D40193354 Pulled By: anand1976 fbshipit-source-id: e80d53880799ae01bdd717641d07997d3bfe2b54 --- db/db_impl/db_impl_open.cc | 10 ++++++++-- db_stress_tool/db_stress_test_base.cc | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/db/db_impl/db_impl_open.cc b/db/db_impl/db_impl_open.cc index 199a066b3..3f5c3b29d 100644 --- a/db/db_impl/db_impl_open.cc +++ b/db/db_impl/db_impl_open.cc @@ -2080,9 +2080,15 @@ Status DBImpl::Open(const DBOptions& db_options, const std::string& dbname, impl); LogFlush(impl->immutable_db_options_.info_log); if (!impl->WALBufferIsEmpty()) { - impl->FlushWAL(true /* sync */); + s = impl->FlushWAL(false); + if (s.ok()) { + // Sync is needed otherwise WAL buffered data might get lost after a + // power reset. + log::Writer* log_writer = impl->logs_.back().writer; + s = log_writer->file()->Sync(impl->immutable_db_options_.use_fsync); + } } - if (!persist_options_status.ok()) { + if (s.ok() && !persist_options_status.ok()) { s = Status::IOError( "DB::Open() failed --- Unable to persist Options file", persist_options_status.ToString()); diff --git a/db_stress_tool/db_stress_test_base.cc b/db_stress_tool/db_stress_test_base.cc index aed00e8d5..4f2ce8b92 100644 --- a/db_stress_tool/db_stress_test_base.cc +++ b/db_stress_tool/db_stress_test_base.cc @@ -836,7 +836,7 @@ void StressTest::OperateDb(ThreadState* thread) { if (thread->rand.OneInOpt(FLAGS_manual_wal_flush_one_in)) { bool sync = thread->rand.OneIn(2) ? true : false; Status s = db_->FlushWAL(sync); - if (!s.ok()) { + if (!s.ok() && !(sync && s.IsNotSupported())) { fprintf(stderr, "FlushWAL(sync=%s) failed: %s\n", (sync ? "true" : "false"), s.ToString().c_str()); }