Skip to content

Commit

Permalink
mod
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuichao001 committed Mar 11, 2022
1 parent b5d34ad commit 5d0a375
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
25 changes: 11 additions & 14 deletions src/lsmtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,16 @@ void lsmtree::schedule_compaction(){
{
if(immutab_!=nullptr){
this->minor_compact();
}
bool compacted = false;
}
if(versions_.need_compact()){
compaction *c = versions_.plan_compact();
if(c!=nullptr){ //do nothing
this->major_compact(c);
compacted = true;
}
}
compacting = false;
if(compacted){
schedule_compaction();
}
}
schedule_compaction();
});
}

Expand All @@ -132,7 +128,7 @@ int lsmtree::sweep_space(){
std::unique_lock<std::mutex> lock{mutex_};
if (immutab_!=nullptr) {
fprintf(stderr, "level-0 wait\n");
solid_cv_.wait(lock);
solidify_.wait(lock);
return 0;
} else {
immutab_ = mutab_;
Expand Down Expand Up @@ -184,16 +180,14 @@ int lsmtree::minor_compact(){
version *neo = versions_.apply(&edit);
versions_.apply_logidx(persist_logidx);

versions_.appoint(neo);
memtable *imtab = immutab_;
immutab_ = nullptr;

{
std::unique_lock<std::mutex> lock{mutex_};
solid_cv_.notify_all();
versions_.appoint(neo);
immutab_->unref();
immutab_ = nullptr;
solidify_.notify_all();
}

imtab->unref();
versions_.current()->calculate();
return 0;
}
Expand Down Expand Up @@ -260,7 +254,10 @@ int lsmtree::major_compact(compaction* c){
}

version * neo = versions_.apply(&edit);
versions_.appoint(neo);
{
std::unique_lock<std::mutex> lock{mutex_};
versions_.appoint(neo);
}

versions_.current()->calculate();
fprintf(stderr, "major compact DONE!!!\n");
Expand Down
2 changes: 1 addition & 1 deletion src/lsmtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class lsmtree{
memtable *mutab_;
memtable *immutab_;
std::mutex mutex_;
std::condition_variable solid_cv_;
std::condition_variable solidify_; //sync wait immutab become primarysst

std::atomic<bool> compacting;
versionset versions_;
Expand Down

0 comments on commit 5d0a375

Please sign in to comment.