diff --git a/db/compaction_picker.cc b/db/compaction_picker.cc index 52499f301b..c58f699e41 100644 --- a/db/compaction_picker.cc +++ b/db/compaction_picker.cc @@ -369,12 +369,6 @@ Compaction* LevelCompactionPicker::PickCompaction(Version* version, Compaction* c = nullptr; int level = -1; - // Compute the compactions needed. It is better to do it here - // and also in LogAndApply(), otherwise the values could be stale. - std::vector size_being_compacted(NumberLevels() - 1); - SizeBeingCompacted(size_being_compacted); - version->Finalize(size_being_compacted); - // We prefer compactions triggered by too much data in a level over // the compactions triggered by seeks. // diff --git a/db/version_set.cc b/db/version_set.cc index 96bce4b9ee..a47d4e93fc 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -469,6 +469,7 @@ Version::Version(ColumnFamilyData* cfd, VersionSet* vset, refs_(0), // cfd is nullptr if Version is dummy num_levels_(cfd == nullptr ? 0 : cfd->NumberLevels()), + finalized_(false), files_(new std::vector[num_levels_]), files_by_size_(num_levels_), next_file_to_compact_by_size_(num_levels_), @@ -486,6 +487,7 @@ void Version::Get(const ReadOptions& options, GetStats* stats, const Options& db_options, bool* value_found) { + assert(finalized_); Slice ikey = k.internal_key(); Slice user_key = k.user_key(); const Comparator* ucmp = cfd_->internal_comparator().user_comparator(); @@ -651,6 +653,8 @@ bool Version::UpdateStats(const GetStats& stats) { } void Version::Finalize(std::vector& size_being_compacted) { + assert(!finalized_); + finalized_ = true; // Pre-sort level0 for Get() if (cfd_->options()->compaction_style == kCompactionStyleUniversal) { std::sort(files_[0].begin(), files_[0].end(), NewestFirstBySeqNo); diff --git a/db/version_set.h b/db/version_set.h index 11f1b34ebc..d4473a5040 100644 --- a/db/version_set.h +++ b/db/version_set.h @@ -234,6 +234,7 @@ class Version { Version* prev_; // Previous version in linked list int refs_; // Number of live refs to this version int num_levels_; // Number of levels + bool finalized_; // True if Finalized is called // List of files per level, files in each level are arranged // in increasing order of keys