From 5dad9d6d28cef6a3df1070a6f2f09de170b22bf2 Mon Sep 17 00:00:00 2001 From: sdong Date: Wed, 25 Jan 2017 15:48:19 -0800 Subject: [PATCH] Avoid logs_ operation out of DB mutex Summary: logs_.back() is called out of DB mutex, which can cause data race. We move the access into the DB mutex protection area. Closes https://github.com/facebook/rocksdb/pull/1774 Reviewed By: AsyncDBConnMarkedDownDBException Differential Revision: D4417472 Pulled By: AsyncDBConnMarkedDownDBException fbshipit-source-id: 2da1f1e --- db/db_impl.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/db_impl.cc b/db/db_impl.cc index eec62be1a..b68694721 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -4807,6 +4807,7 @@ Status DBImpl::WriteImpl(const WriteOptions& write_options, // and protects against concurrent loggers and concurrent writes // into memtables } + log::Writer* cur_log_writer = logs_.back().writer; mutex_.Unlock(); @@ -4894,7 +4895,7 @@ Status DBImpl::WriteImpl(const WriteOptions& write_options, WriteBatchInternal::SetSequence(merged_batch, current_sequence); Slice log_entry = WriteBatchInternal::Contents(merged_batch); - status = logs_.back().writer->AddRecord(log_entry); + status = cur_log_writer->AddRecord(log_entry); total_log_size_ += log_entry.size(); alive_log_files_.back().AddSize(log_entry.size()); log_empty_ = false;