Skip to content

Commit

Permalink
kv/RocksDBStore: don't use real wholespace iterator for prefixed access
Browse files Browse the repository at this point in the history
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 <igor.fedotov@croit.io>
  • Loading branch information
ifed01 committed Feb 1, 2023
1 parent deb2f97 commit 46c0a61
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/kv/KeyValueDB.h
Expand Up @@ -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<PrefixIteratorImpl>(
prefix,
w_iter);
}
public:
typedef uint32_t IteratorOpts;
static const uint32_t ITERATOR_NOCACHE = 1;
Expand All @@ -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<PrefixIteratorImpl>(
prefix,
return make_iterator(prefix,
get_wholespace_iterator(opts));
}

Expand Down
8 changes: 7 additions & 1 deletion src/kv/RocksDBStore.cc
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 46c0a61

Please sign in to comment.