diff --git a/db/compaction_picker.cc b/db/compaction_picker.cc index e1abf3c45..d585e41ec 100644 --- a/db/compaction_picker.cc +++ b/db/compaction_picker.cc @@ -373,12 +373,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 6c3178523..3b7a74afd 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -461,6 +461,7 @@ Version::Version(VersionSet* vset, uint64_t version_number) prev_(this), refs_(0), num_levels_(vset->num_levels_), + finalized_(false), files_(new std::vector[num_levels_]), files_by_size_(num_levels_), next_file_to_compact_by_size_(num_levels_), @@ -478,6 +479,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 = vset_->icmp_.user_comparator(); @@ -642,6 +644,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 (vset_->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 19489701f..39bb7d414 100644 --- a/db/version_set.h +++ b/db/version_set.h @@ -227,6 +227,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