From f802ff8f0ba430abd2bd6baadb6a94e571b21e0c Mon Sep 17 00:00:00 2001 From: Igor Fedotov Date: Wed, 1 Feb 2023 23:53:41 +0300 Subject: [PATCH] kv/RocksDBStore: avoid redundant prefix lookup. Signed-off-by: Igor Fedotov (cherry picked from commit deb2f9703b1e10dc90d978506c241e912c36f5e9) --- src/kv/RocksDBStore.cc | 5 ++--- src/kv/RocksDBStore.h | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/kv/RocksDBStore.cc b/src/kv/RocksDBStore.cc index 8e8983c18e5..f1be9195a08 100644 --- a/src/kv/RocksDBStore.cc +++ b/src/kv/RocksDBStore.cc @@ -670,11 +670,10 @@ rocksdb::ColumnFamilyHandle *RocksDBStore::get_cf_handle(const std::string& pref * CF handle. In all other cases, we return a nullptr to indicate that the specified bounds cannot necessarily be mapped * to a single CF. */ -rocksdb::ColumnFamilyHandle *RocksDBStore::get_cf_handle(const std::string& prefix, const IteratorBounds& bounds) { +rocksdb::ColumnFamilyHandle *RocksDBStore::check_cf_handle_bounds(const cf_handles_iterator& iter, const IteratorBounds& bounds) { if (!bounds.lower_bound || !bounds.upper_bound) { return nullptr; } - auto iter = cf_handles.find(prefix); ceph_assert(iter != cf_handles.end()); ceph_assert(iter->second.handles.size() != 1); if (iter->second.hash_l != 0) { @@ -2998,7 +2997,7 @@ KeyValueDB::Iterator RocksDBStore::get_iterator(const std::string& prefix, Itera if (cf_it->second.handles.size() == 1) { cf = cf_it->second.handles[0]; } else if (cct->_conf->osd_rocksdb_iterator_bounds_enabled) { - cf = get_cf_handle(prefix, bounds); + cf = check_cf_handle_bounds(cf_it, bounds); } if (cf) { return std::make_shared( diff --git a/src/kv/RocksDBStore.h b/src/kv/RocksDBStore.h index 50f2b4488f4..9a50b8538e6 100644 --- a/src/kv/RocksDBStore.h +++ b/src/kv/RocksDBStore.h @@ -123,6 +123,7 @@ private: std::vector handles; }; std::unordered_map cf_handles; + typedef decltype(cf_handles)::iterator cf_handles_iterator; std::unordered_map cf_ids_to_prefix; std::unordered_map cf_bbt_opts; @@ -133,7 +134,7 @@ private: rocksdb::ColumnFamilyHandle *get_key_cf(const prefix_shards& shards, const char* key, const size_t keylen); rocksdb::ColumnFamilyHandle *get_cf_handle(const std::string& prefix, const std::string& key); rocksdb::ColumnFamilyHandle *get_cf_handle(const std::string& prefix, const char* key, size_t keylen); - rocksdb::ColumnFamilyHandle *get_cf_handle(const std::string& prefix, const IteratorBounds& bounds); + rocksdb::ColumnFamilyHandle *check_cf_handle_bounds(const cf_handles_iterator& it, const IteratorBounds& bounds); int submit_common(rocksdb::WriteOptions& woptions, KeyValueDB::Transaction t); int install_cf_mergeop(const std::string &cf_name, rocksdb::ColumnFamilyOptions *cf_opt); -- 2.47.3