diff --git a/src/kv/KeyValueDB.h b/src/kv/KeyValueDB.h index 98bf0c07c43..9cfb4482706 100644 --- a/src/kv/KeyValueDB.h +++ b/src/kv/KeyValueDB.h @@ -322,6 +322,12 @@ private: 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 @@ public: 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 c95e344e0bc..df48f62fe2f 100644 --- a/src/kv/RocksDBStore.cc +++ b/src/kv/RocksDBStore.cc @@ -667,11 +667,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) { @@ -3013,7 +3012,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( @@ -3029,7 +3028,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); } } diff --git a/src/kv/RocksDBStore.h b/src/kv/RocksDBStore.h index 7cc861c0444..35fb21a9658 100644 --- a/src/kv/RocksDBStore.h +++ b/src/kv/RocksDBStore.h @@ -122,6 +122,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; @@ -132,7 +133,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);