From aaff2e129571c44225077dfe3eaa51cca8f12783 Mon Sep 17 00:00:00 2001 From: leipeng Date: Sun, 28 Aug 2022 08:52:25 +0800 Subject: [PATCH] ForwardIterator: used newly added VersionStorageInfo::FindFileInRange --- db/forward_iterator.cc | 14 +------------- db/forward_iterator.h | 4 ---- db/version_set.cc | 6 ++++++ db/version_set.h | 2 ++ 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/db/forward_iterator.cc b/db/forward_iterator.cc index 683a15164..2bf280f69 100644 --- a/db/forward_iterator.cc +++ b/db/forward_iterator.cc @@ -464,7 +464,7 @@ void ForwardIterator::SeekInternal(const Slice& internal_key, } uint32_t f_idx = 0; if (!seek_to_first) { - f_idx = FindFileInRange(level_files, internal_key, 0, + f_idx = vstorage->FindFileInRange(level, internal_key, 0, static_cast(level_files.size())); } @@ -991,18 +991,6 @@ bool ForwardIterator::TEST_CheckDeletedIters(int* pdeleted_iters, return retval; } -uint32_t ForwardIterator::FindFileInRange( - const std::vector& files, const Slice& internal_key, - uint32_t left, uint32_t right) { - auto cmp = [&](const FileMetaData* f, const Slice& k) -> bool { - return cfd_->internal_comparator().InternalKeyComparator::Compare( - f->largest.Encode(), k) < 0; - }; - const auto &b = files.begin(); - return static_cast(std::lower_bound(b + left, - b + right, internal_key, cmp) - b); -} - void ForwardIterator::DeleteIterator(InternalIterator* iter, bool is_arena) { if (iter == nullptr) { return; diff --git a/db/forward_iterator.h b/db/forward_iterator.h index 00823cd45..c1065fd4e 100644 --- a/db/forward_iterator.h +++ b/db/forward_iterator.h @@ -105,10 +105,6 @@ class ForwardIterator : public InternalIterator { void UpdateCurrent(); bool NeedToSeekImmutable(const Slice& internal_key); void DeleteCurrentIter(); - uint32_t FindFileInRange( - const std::vector& files, const Slice& internal_key, - uint32_t left, uint32_t right); - bool IsOverUpperBound(const Slice& internal_key) const; // Set PinnedIteratorsManager for all children Iterators, this function should diff --git a/db/version_set.cc b/db/version_set.cc index a887bbf20..5aca09f2a 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -3823,6 +3823,12 @@ uint64_t VersionStorageInfo::NumLevelBytes(int level) const { return TotalFileSize(files_[level]); } +int VersionStorageInfo::FindFileInRange(int level, const Slice& key, + uint32_t left, uint32_t right) const { + return ROCKSDB_NAMESPACE::FindFileInRange(*internal_comparator_, + level_files_brief_[level], key, left, right); +} + const char* VersionStorageInfo::LevelSummary( LevelSummaryStorage* scratch) const { int len = 0; diff --git a/db/version_set.h b/db/version_set.h index 46e716c6e..a9d27bfcd 100644 --- a/db/version_set.h +++ b/db/version_set.h @@ -315,6 +315,8 @@ class VersionStorageInfo { return files_[level]; } + int FindFileInRange(int level, const Slice& key, uint32_t left, uint32_t right) const; + class FileLocation { public: FileLocation() = default;