diff --git a/db/db_impl.cc b/db/db_impl.cc index f17d70290..97354ca5a 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -1026,10 +1026,13 @@ int DBImpl::FindMinimumEmptyLevelFitting( Status DBImpl::FlushWAL(bool sync) { if (manual_wal_flush_) { - // We need to lock log_write_mutex_ since logs_ might change concurrently - InstrumentedMutexLock wl(&log_write_mutex_); - log::Writer* cur_log_writer = logs_.back().writer; - auto s = cur_log_writer->WriteBuffer(); + Status s; + { + // We need to lock log_write_mutex_ since logs_ might change concurrently + InstrumentedMutexLock wl(&log_write_mutex_); + log::Writer* cur_log_writer = logs_.back().writer; + s = cur_log_writer->WriteBuffer(); + } if (!s.ok()) { ROCKS_LOG_ERROR(immutable_db_options_.info_log, "WAL flush error %s", s.ToString().c_str()); diff --git a/db/db_impl.h b/db/db_impl.h index ce90ab25e..53f42e20b 100644 --- a/db/db_impl.h +++ b/db/db_impl.h @@ -1261,6 +1261,8 @@ class DBImpl : public DB { // logfile_number_. With two_write_queues it also protects alive_log_files_, // and log_empty_. Refer to the definition of each variable below for more // details. + // Note: to avoid dealock, if needed to acquire both log_write_mutex_ and + // mutex_, the order should be first mutex_ and then log_write_mutex_. InstrumentedMutex log_write_mutex_; std::atomic shutting_down_;