Browse Source

fix lock_key bug

pull/3/head
dgy 9 months ago
parent
commit
ed72f6c2b0
2 changed files with 6 additions and 3 deletions
  1. +3
    -3
      db/db_impl.cc
  2. +3
    -0
      db/db_impl.h

+ 3
- 3
db/db_impl.cc View File

@ -170,6 +170,7 @@ DBImpl::~DBImpl() {
} }
background_garbage_collect_scheduled_=true; background_garbage_collect_scheduled_=true;
gc_mutex_.Unlock(); gc_mutex_.Unlock();
if(gc_thread&&gc_thread->joinable())gc_thread->join();
mutex_.Lock(); mutex_.Lock();
shutting_down_.store(true, std::memory_order_release); shutting_down_.store(true, std::memory_order_release);
while (background_compaction_scheduled_) { while (background_compaction_scheduled_) {
@ -725,8 +726,7 @@ void DBImpl::MaybeScheduleGarbageCollect() {
gc_mutex_.Lock(); gc_mutex_.Lock();
background_garbage_collect_scheduled_ = true; background_garbage_collect_scheduled_ = true;
gc_mutex_.Unlock(); 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; w.done = false;
MutexLock l(&mutex_); 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_); WriteBatchInternal::checkValueLog(updates, this,&valuelog_finding_key,&lock_valuelog_key_mutex_cond_);
} }
writers_.push_back(&w); writers_.push_back(&w);

+ 3
- 0
db/db_impl.h View File

@ -11,6 +11,7 @@
#include <atomic> #include <atomic>
#include <deque> #include <deque>
#include <map> #include <map>
#include <thread>
#include <unordered_map> #include <unordered_map>
#include <mutex> #include <mutex>
#include <shared_mutex> #include <shared_mutex>
@ -238,6 +239,8 @@ class DBImpl : public DB {
std::map<uint64_t, uint64_t> valuelog_usage; std::map<uint64_t, uint64_t> valuelog_usage;
std::map<uint64_t, uint64_t> valuelog_origin; std::map<uint64_t, uint64_t> valuelog_origin;
std::thread* gc_thread=nullptr;
uint32_t seed_ GUARDED_BY(mutex_); // For sampling. uint32_t seed_ GUARDED_BY(mutex_); // For sampling.
// Queue of writers. // Queue of writers.

Loading…
Cancel
Save