]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
kv/RocksDBStore: use bounded iterators in rm_range_keys
authorIgor Fedotov <igor.fedotov@croit.io>
Sun, 15 Jan 2023 23:25:42 +0000 (02:25 +0300)
committerIgor Fedotov <ifedotov@suse.com>
Fri, 7 Apr 2023 09:29:06 +0000 (12:29 +0300)
Fixes: https://tracker.ceph.com/issues/58463
Signed-off-by: Igor Fedotov <igor.fedotov@croit.io>
(cherry picked from commit b8e669d9466f63d7523a535c7ff490478b162816)

src/kv/RocksDBStore.cc
src/kv/RocksDBStore.h

index c95e344e0bcb1b6215b00bc8e7221a2f102e9eb9..c35a08c85b2f1c7aec3b8e572003ecc07c7512b3 100644 (file)
@@ -1730,7 +1730,7 @@ void RocksDBStore::RocksDBTransactionImpl::rmkeys_by_prefix(const string &prefix
       uint64_t cnt = db->get_delete_range_threshold();
       bat.SetSavePoint();
       auto it = db->new_shard_iterator(cf);
-      for (it->SeekToFirst(); it->Valid() && (--cnt) != 0; it->Next()) {
+      for (it->seek_to_first(); it->valid() && (--cnt) != 0; it->next()) {
        bat.Delete(cf, it->key());
       }
       if (cnt == 0) {
@@ -1748,10 +1748,10 @@ void RocksDBStore::RocksDBTransactionImpl::rm_range_keys(const string &prefix,
                                                          const string &start,
                                                          const string &end)
 {
-  ldout(db->cct, 10) << __func__ 
+  ldout(db->cct, 10) << __func__
                      << " enter prefix=" << prefix
-                     << " start=" << start
-                    << " end=" << end << dendl;
+                     << " start=" << pretty_binary_string(start)
+                    << " end=" << pretty_binary_string(end) << dendl;
   auto p_iter = db->cf_handles.find(prefix);
   uint64_t cnt = db->get_delete_range_threshold();
   if (p_iter == db->cf_handles.end()) {
@@ -1763,8 +1763,8 @@ void RocksDBStore::RocksDBTransactionImpl::rm_range_keys(const string &prefix,
         it->next()) {
       bat.Delete(db->default_cf, combine_strings(prefix, it->key()));
     }
-    ldout(db->cct, 15) << __func__ << " count = "
-                       << cnt0 - cnt
+    ldout(db->cct, 15) << __func__
+                       << " count = " << cnt0 - cnt
                        << dendl;
     if (cnt == 0) {
       ldout(db->cct, 10) << __func__ << " p_iter == end(), resorting to DeleteRange"
@@ -1784,20 +1784,22 @@ void RocksDBStore::RocksDBTransactionImpl::rm_range_keys(const string &prefix,
        bat.DeleteRange(cf, rocksdb::Slice(start), rocksdb::Slice(end));
     }
   } else {
+    auto bounds = KeyValueDB::IteratorBounds();
+    bounds.lower_bound = start;
+    bounds.upper_bound = end;
     ceph_assert(p_iter->second.handles.size() >= 1);
     for (auto cf : p_iter->second.handles) {
       cnt = db->get_delete_range_threshold();
       uint64_t cnt0 = cnt;
       bat.SetSavePoint();
-      rocksdb::Iterator* it = db->new_shard_iterator(cf);
-      ceph_assert(it != nullptr);
-      for (it->Seek(start);
-          it->Valid() && db->comparator->Compare(it->key(), end) < 0 && (--cnt) != 0;
-          it->Next()) {
+      auto it = db->new_shard_iterator(cf, prefix, bounds);
+      for (it->lower_bound(start);
+          it->valid() && (--cnt) != 0;
+          it->next()) {
        bat.Delete(cf, it->key());
       }
-      ldout(db->cct, 10) << __func__ << " count = "
-                         << cnt0 - cnt
+      ldout(db->cct, 10) << __func__
+                         << " count = " << cnt0 - cnt
                          << dendl;
       if (cnt == 0) {
         ldout(db->cct, 10) << __func__ << " p_iter != end(), resorting to DeleteRange"
@@ -1807,7 +1809,6 @@ void RocksDBStore::RocksDBTransactionImpl::rm_range_keys(const string &prefix,
       } else {
        bat.PopSavePoint();
       }
-      delete it;
     }
   }
   ldout(db->cct, 10) << __func__ << " end" << dendl;
@@ -3033,9 +3034,23 @@ KeyValueDB::Iterator RocksDBStore::get_iterator(const std::string& prefix, Itera
   }
 }
 
-rocksdb::Iterator* RocksDBStore::new_shard_iterator(rocksdb::ColumnFamilyHandle* cf)
+RocksDBStore::WholeSpaceIterator RocksDBStore::new_shard_iterator(rocksdb::ColumnFamilyHandle* cf)
+{
+  return std::make_shared<RocksDBWholeSpaceIteratorImpl>(
+    this,
+    cf,
+    0);
+}
+
+KeyValueDB::Iterator RocksDBStore::new_shard_iterator(rocksdb::ColumnFamilyHandle* cf,
+                                                     const std::string& prefix,
+                                                     IteratorBounds bounds)
 {
-  return db->NewIterator(rocksdb::ReadOptions(), cf);
+  return std::make_shared<CFIteratorImpl>(
+    this,
+    prefix,
+    cf,
+    std::move(bounds));
 }
 
 RocksDBStore::WholeSpaceIterator RocksDBStore::get_wholespace_iterator(IteratorOpts opts)
index 7cc861c04449c21157ba6992033833bca8fc2cec..9d3c8cd9042ce87dfc787736ce5711fda03f0ae2 100644 (file)
@@ -389,7 +389,9 @@ public:
   Iterator get_iterator(const std::string& prefix, IteratorOpts opts = 0, IteratorBounds = IteratorBounds()) override;
 private:
   /// this iterator spans single cf
-  rocksdb::Iterator* new_shard_iterator(rocksdb::ColumnFamilyHandle* cf);
+  WholeSpaceIterator new_shard_iterator(rocksdb::ColumnFamilyHandle* cf);
+  Iterator new_shard_iterator(rocksdb::ColumnFamilyHandle* cf,
+                             const std::string& prefix, IteratorBounds bound);
 public:
   /// Utility
   static std::string combine_strings(const std::string &prefix, const std::string &value) {