Skip to content

Commit

Permalink
Move level0 sorting logic from Version::SaveTo() to Version::Finalize()
Browse files Browse the repository at this point in the history
Summary: I realized that "D14409 Avoid sorting in Version::Get() by presorting them in VersionSet::Builder::SaveTo()" is not done in an optimized place. SaveTo() is usually inside mutex. Move it to Finalize(), which is called out of mutex.

Test Plan: make all check

Reviewers: dhruba, haobo, kailiu

Reviewed By: dhruba

CC: igor, leveldb

Differential Revision: https://reviews.facebook.net/D14607
  • Loading branch information
siying committed Dec 18, 2013
1 parent a8b8b11 commit 14995a8
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions db/version_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1110,12 +1110,6 @@ class VersionSet::Builder {
MaybeAddFile(v, level, *base_iter);
}
}
// Pre-sort level0 for Get()
if (vset_->options_->compaction_style == kCompactionStyleUniversal) {
std::sort(v->files_[0].begin(), v->files_[0].end(), NewestFirstBySeqNo);
} else {
std::sort(v->files_[0].begin(), v->files_[0].end(), NewestFirst);
}

CheckConsistency(v);
}
Expand Down Expand Up @@ -1681,6 +1675,12 @@ void VersionSet::MarkFileNumberUsed(uint64_t number) {

void VersionSet::Finalize(Version* v,
std::vector<uint64_t>& size_being_compacted) {
// Pre-sort level0 for Get()
if (options_->compaction_style == kCompactionStyleUniversal) {
std::sort(v->files_[0].begin(), v->files_[0].end(), NewestFirstBySeqNo);
} else {
std::sort(v->files_[0].begin(), v->files_[0].end(), NewestFirst);
}

double max_score = 0;
int max_score_level = 0;
Expand Down

0 comments on commit 14995a8

Please sign in to comment.