From 4b107ceb7ebdf0d2b04443f7ced89587adc291d8 Mon Sep 17 00:00:00 2001 From: Peter Dillinger Date: Mon, 6 Jul 2020 16:15:16 -0700 Subject: [PATCH] Improve code comments in EstimateLiveDataSize (#7072) Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/7072 Reviewed By: ajkr Differential Revision: D22391641 Pulled By: pdillinger fbshipit-source-id: 0ef355576454514263ab684eb1a5c06787f3242a --- db/version_set.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/db/version_set.cc b/db/version_set.cc index db282a51e..94fe7ba34 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -3407,22 +3407,23 @@ void VersionStorageInfo::CalculateBaseBytes(const ImmutableCFOptions& ioptions, } uint64_t VersionStorageInfo::EstimateLiveDataSize() const { - // Estimate the live data size by adding up the size of the last level for all - // key ranges. Note: Estimate depends on the ordering of files in level 0 - // because files in level 0 can be overlapping. + // Estimate the live data size by adding up the size of a maximal set of + // sst files with no range overlap in same or higher level. The less + // compacted, the more optimistic (smaller) this estimate is. Also, + // for multiple sorted runs within a level, file order will matter. uint64_t size = 0; auto ikey_lt = [this](InternalKey* x, InternalKey* y) { return internal_comparator_->Compare(*x, *y) < 0; }; - // (Ordered) map of largest keys in non-overlapping files + // (Ordered) map of largest keys in files being included in size estimate std::map ranges(ikey_lt); for (int l = num_levels_ - 1; l >= 0; l--) { bool found_end = false; for (auto file : files_[l]) { - // Find the first file where the largest key is larger than the smallest - // key of the current file. If this file does not overlap with the + // Find the first file already included with largest key is larger than + // the smallest key of `file`. If that file does not overlap with the // current file, none of the files in the map does. If there is // no potential overlap, we can safely insert the rest of this level // (if the level is not 0) into the map without checking again because