From ed72f6c2b0e95a999c82dbd9f82847cdf9db924a Mon Sep 17 00:00:00 2001 From: dgy Date: Mon, 23 Dec 2024 05:19:10 +0000 Subject: [PATCH] fix lock_key bug --- db/db_impl.cc | 6 +++--- db/db_impl.h | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/db/db_impl.cc b/db/db_impl.cc index be8f9c4..d9af970 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -170,6 +170,7 @@ DBImpl::~DBImpl() { } background_garbage_collect_scheduled_=true; gc_mutex_.Unlock(); + if(gc_thread&&gc_thread->joinable())gc_thread->join(); mutex_.Lock(); shutting_down_.store(true, std::memory_order_release); while (background_compaction_scheduled_) { @@ -725,8 +726,7 @@ void DBImpl::MaybeScheduleGarbageCollect() { gc_mutex_.Lock(); background_garbage_collect_scheduled_ = true; gc_mutex_.Unlock(); - auto bg_thread_ = std::thread(&DBImpl::BGWorkGC, this); - bg_thread_.detach(); + gc_thread =new std::thread(&DBImpl::BGWorkGC, this); } } @@ -1345,7 +1345,7 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* updates) { w.done = false; MutexLock l(&mutex_); - if(!options.valuelog_write&&valuelog_finding_key.size()>0){ + if(!options.valuelog_write&&updates&&valuelog_finding_key.size()>0){ WriteBatchInternal::checkValueLog(updates, this,&valuelog_finding_key,&lock_valuelog_key_mutex_cond_); } writers_.push_back(&w); diff --git a/db/db_impl.h b/db/db_impl.h index df723b7..658ca0b 100644 --- a/db/db_impl.h +++ b/db/db_impl.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -238,6 +239,8 @@ class DBImpl : public DB { std::map valuelog_usage; std::map valuelog_origin; + std::thread* gc_thread=nullptr; + uint32_t seed_ GUARDED_BY(mutex_); // For sampling. // Queue of writers.