From 2e8a1a14eff1ef1532be92face831e76d4d1fcf0 Mon Sep 17 00:00:00 2001 From: Levi Tamasi Date: Fri, 2 Aug 2024 14:11:08 -0700 Subject: Fix a data race affecting the background error status (#12910) Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/12910 There is currently a call to `GetBGError()` in `DBImpl::WriteImplWALOnly()` where the DB mutex is (incorrectly) not held, leading to a data race. Technically, we could acquire the mutex here but instead, the patch removes the affected check altogether, since the same check is already performed (in a thread-safe manner) in the subsequent call to `PreprocessWrite()`. Reviewed By: cbi42 Differential Revision: D60682008 fbshipit-source-id: 54b67975dcf57d67c068cac71e8ada09a1793ec5 --- db/db_impl/db_impl_write.cc | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'db/db_impl/db_impl_write.cc') diff --git a/db/db_impl/db_impl_write.cc b/db/db_impl/db_impl_write.cc index ec5283ad9..d6899502a 100644 --- a/db/db_impl/db_impl_write.cc +++ b/db/db_impl/db_impl_write.cc @@ -969,21 +969,17 @@ Status DBImpl::WriteImplWALOnly( assert(w.state == WriteThread::STATE_GROUP_LEADER); if (publish_last_seq == kDoPublishLastSeq) { - Status status; - // Currently we only use kDoPublishLastSeq in unordered_write assert(immutable_db_options_.unordered_write); - WriteContext write_context; - if (error_handler_.IsDBStopped()) { - status = error_handler_.GetBGError(); - } + // TODO(myabandeh): Make preliminary checks thread-safe so we could do them // without paying the cost of obtaining the mutex. - if (status.ok()) { - LogContext log_context; - status = PreprocessWrite(write_options, &log_context, &write_context); - WriteStatusCheckOnLocked(status); - } + LogContext log_context; + WriteContext write_context; + Status status = + PreprocessWrite(write_options, &log_context, &write_context); + WriteStatusCheckOnLocked(status); + if (!status.ok()) { WriteThread::WriteGroup write_group; write_thread->EnterAsBatchGroupLeader(&w, &write_group); -- cgit v1.2.3-70-g09d2