From 14995a8ff3110bbcd19c34cd92a449ca3e435f5d Mon Sep 17 00:00:00 2001 From: Siying Dong Date: Wed, 11 Dec 2013 15:40:22 -0800 Subject: [PATCH] Move level0 sorting logic from Version::SaveTo() to Version::Finalize() 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 --- db/version_set.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/db/version_set.cc b/db/version_set.cc index 741752936..933affd18 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -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); } @@ -1681,6 +1675,12 @@ void VersionSet::MarkFileNumberUsed(uint64_t number) { void VersionSet::Finalize(Version* v, std::vector& 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;