From cc6c883f59bbca6008362bc10b2f44c8a5c570d7 Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Mon, 13 Oct 2014 14:25:55 -0700 Subject: [PATCH] Stop stopping writes on bg_error_ Summary: This might have caused https://github.com/facebook/rocksdb/issues/345. If we're stopping writes and bg_error comes along, we will never unblock the write. Test Plan: compiles Reviewers: ljin Reviewed By: ljin Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D24807 --- db/db_impl.cc | 10 ++++++---- db/db_impl.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/db/db_impl.cc b/db/db_impl.cc index 5abfb4ac2..dc9399fd8 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -4036,7 +4036,7 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* my_batch) { if (UNLIKELY(status.ok()) && (write_controller_.IsStopped() || write_controller_.GetDelay() > 0)) { - DelayWrite(expiration_time); + status = DelayWrite(expiration_time); } if (UNLIKELY(status.ok() && has_timeout && @@ -4151,7 +4151,7 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* my_batch) { // REQUIRES: mutex_ is held // REQUIRES: this thread is currently at the front of the writer queue -void DBImpl::DelayWrite(uint64_t expiration_time) { +Status DBImpl::DelayWrite(uint64_t expiration_time) { StopWatch sw(env_, stats_, WRITE_STALL); bool has_timeout = (expiration_time > 0); auto delay = write_controller_.GetDelay(); @@ -4161,16 +4161,18 @@ void DBImpl::DelayWrite(uint64_t expiration_time) { mutex_.Lock(); } - while (write_controller_.IsStopped()) { + while (bg_error_.ok() && write_controller_.IsStopped()) { if (has_timeout) { bg_cv_.TimedWait(expiration_time); if (env_->NowMicros() > expiration_time) { - break; + return Status::TimedOut(); } } else { bg_cv_.Wait(); } } + + return bg_error_; } Status DBImpl::ScheduleFlushes(WriteContext* context) { diff --git a/db/db_impl.h b/db/db_impl.h index 622df4293..149958315 100644 --- a/db/db_impl.h +++ b/db/db_impl.h @@ -367,7 +367,7 @@ class DBImpl : public DB { const autovector& mems, VersionEdit* edit, uint64_t* filenumber, LogBuffer* log_buffer); - void DelayWrite(uint64_t expiration_time); + Status DelayWrite(uint64_t expiration_time); Status ScheduleFlushes(WriteContext* context);