From 46c0a61f578c02e8a5cf4e29415989ae6ec4681c Mon Sep 17 00:00:00 2001 From: Igor Fedotov Date: Thu, 2 Feb 2023 00:19:38 +0300 Subject: [PATCH] kv/RocksDBStore: don't use real wholespace iterator for prefixed access We can bound to default CF when here are no matching CF for a specified prefix. No need to use real wholespace iterator running over every CF. Hence we might benefit from not iterating over large but useless CFs, e.g. OMAP related ones. Signed-off-by: Igor Fedotov --- src/kv/KeyValueDB.h | 9 +++++++-- src/kv/RocksDBStore.cc | 8 +++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/kv/KeyValueDB.h b/src/kv/KeyValueDB.h index 98bf0c07c43f4..9cfb4482706c9 100644 --- a/src/kv/KeyValueDB.h +++ b/src/kv/KeyValueDB.h @@ -322,6 +322,12 @@ class KeyValueDB { return generic_iter->status(); } }; +protected: + Iterator make_iterator(const std::string &prefix, WholeSpaceIterator w_iter) { + return std::make_shared( + prefix, + w_iter); + } public: typedef uint32_t IteratorOpts; static const uint32_t ITERATOR_NOCACHE = 1; @@ -333,8 +339,7 @@ class KeyValueDB { virtual WholeSpaceIterator get_wholespace_iterator(IteratorOpts opts = 0) = 0; virtual Iterator get_iterator(const std::string &prefix, IteratorOpts opts = 0, IteratorBounds bounds = IteratorBounds()) { - return std::make_shared( - prefix, + return make_iterator(prefix, get_wholespace_iterator(opts)); } diff --git a/src/kv/RocksDBStore.cc b/src/kv/RocksDBStore.cc index bd716d2093f30..b421098f78cc3 100644 --- a/src/kv/RocksDBStore.cc +++ b/src/kv/RocksDBStore.cc @@ -3011,7 +3011,13 @@ KeyValueDB::Iterator RocksDBStore::get_iterator(const std::string& prefix, Itera std::move(bounds)); } } else { - return KeyValueDB::get_iterator(prefix, opts); + // use wholespace engine if no cfs are configured + // or use default cf otherwise as there is no + // matching cf for the specified prefix. + auto w_it = cf_handles.size() == 0 || prefix.empty() ? + get_wholespace_iterator(opts) : + get_default_cf_iterator(); + return KeyValueDB::make_iterator(prefix, w_it); } }