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 a28f9a9 commit b5d34ad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
47 changes: 23 additions & 24 deletions src/lsmtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,43 +55,43 @@ int lsmtree::get(const roptions &opt, const std::string &key, std::string &val){
int seqno = (opt.snap==nullptr)? versions_.last_sequence() : opt.snap->sequence();
memtable *mtab = nullptr;
memtable *imtab = nullptr;
version *ver = nullptr;
version *cur = nullptr;
{
std::unique_lock<std::mutex> lock{mutex_};
mtab = mutab_;
imtab = immutab_;
ver = versions_.current();
mutab_->ref();
if(immutab_!=nullptr){
immutab_->ref();
}
ver->ref();
mtab = mutab_;
imtab = immutab_;
cur = versions_.current();
cur->ref();
}

{
int err = mtab->get(seqno, key, val);
int err = mutab_->get(seqno, key, val);
mtab->unref();
if(err==0){
if(imtab!=nullptr){
imtab->unref();
}
ver->unref();
cur->unref();
return 0;
}
}

if(immutab_!=nullptr){
int err = immutab_->get(seqno, key, val);
immutab_->unref();
if(imtab!=nullptr){
int err = imtab->get(seqno, key, val);
imtab->unref();
if(err==0){
ver->unref();
cur->unref();
return 0;
}
}

{
int err = ver->get(seqno, key, val);
ver->unref();
int err = cur->get(seqno, key, val);
cur->unref();
schedule_compaction();
return err;
}
Expand Down Expand Up @@ -181,16 +181,19 @@ int lsmtree::minor_compact(){

fprintf(stderr, "minor compact into sst-%d range:[%s, %s]\n", sst->file_number, sst->smallest.c_str(), sst->largest.c_str());
edit.add(0, sst);

versions_.apply_logidx(persist_logidx);
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_};
immutab_->unref();
immutab_ = nullptr;
solid_cv_.notify_all();
}
versions_.appoint(neo);
solid_cv_.notify_all();

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

version * neo = versions_.apply(&edit);

{
//std::unique_lock<std::mutex> lock{mutex_};
versions_.appoint(neo);
}
versions_.appoint(neo);

versions_.current()->calculate();
fprintf(stderr, "major compact DONE!!!\n");
Expand Down
1 change: 0 additions & 1 deletion src/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ int versionset::recover(){
int level=0, fnumber=0, keynum=0;
char limit[2][64];
memset(limit, 0, sizeof(limit));
fprintf(stderr, "token:[%s]\n", token);
sscanf(token, "%d %d %s %s %s %d", &level, &fnumber, limit[0], limit[1], &keynum);
fprintf(stderr, "RECOVER sstable level-%d sst-%d <%s,%s>\n", level, fnumber, limit[0], limit[1]);

Expand Down

0 comments on commit b5d34ad

Please sign in to comment.