]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: Refactor foreach_shared_blob in fsck
authorAdam Kupczyk <akupczyk@redhat.com>
Tue, 10 Jan 2023 10:50:54 +0000 (10:50 +0000)
committerAdam Kupczyk <akupczyk@ibm.com>
Wed, 10 May 2023 11:47:46 +0000 (11:47 +0000)
Upgrade local foreach_shared_blob into _fsck_foreach_shared_blob
that can be used on entire BlueStore scope.

Signed-off-by: Adam Kupczyk <akupczyk@redhat.com>
src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h

index c163ecc365e075c61011789480b2c11e71308d3c..1b29ff031a86ee36c7037857115ea9ffb6413e1f 100644 (file)
@@ -8032,6 +8032,65 @@ void BlueStore::_fsck_check_statfs(
   }
 }
 
+void BlueStore::_fsck_foreach_shared_blob(
+  std::function< void (coll_t, ghobject_t, uint64_t, const bluestore_blob_t&)> cb) {
+  auto it = db->get_iterator(PREFIX_OBJ, KeyValueDB::ITERATOR_NOCACHE);
+  if (it) {
+    CollectionRef c;
+    spg_t pgid;
+    for (it->lower_bound(string()); it->valid(); it->next()) {
+      dout(30) << __func__ << " key "
+              << pretty_binary_string(it->key())
+              << dendl;
+      if (is_extent_shard_key(it->key())) {
+       continue;
+      }
+
+      ghobject_t oid;
+      int r = get_key_object(it->key(), &oid);
+      if (r < 0) {
+       continue;
+      }
+
+      if (!c ||
+         oid.shard_id != pgid.shard ||
+         oid.hobj.get_logical_pool() != (int64_t)pgid.pool() ||
+         !c->contains(oid)) {
+       c = nullptr;
+       for (auto& p : coll_map) {
+         if (p.second->contains(oid)) {
+           c = p.second;
+           break;
+         }
+       }
+       if (!c) {
+         continue;
+       }
+      }
+      dout(20) << __func__
+              << " inspecting shared blob refs for col:" << c->cid
+              << " obj:" << oid
+              << dendl;
+
+      OnodeRef o;
+      o.reset(Onode::create_decode(c, oid, it->key(), it->value()));
+      o->extent_map.fault_range(db, 0, OBJECT_MAX_SIZE);
+
+      _dump_onode<30>(cct, *o);
+
+      mempool::bluestore_fsck::set<BlobRef> passed_sbs;
+      for (auto& e : o->extent_map.extent_map) {
+       auto& b = e.blob->get_blob();
+       if (b.is_shared() && passed_sbs.count(e.blob) == 0) {
+         auto sbid = e.blob->shared_blob->get_sbid();
+         cb(c->cid, oid, sbid, b);
+         passed_sbs.emplace(e.blob);
+       }
+      } // for ... extent_map
+    } // for ... it->valid
+  } //if (it(PREFIX_OBJ))
+}
+
 void BlueStore::_fsck_repair_shared_blobs(
   BlueStoreRepairer& repairer,
   shared_blob_2hash_tracker_t& sb_ref_counts,
@@ -8043,73 +8102,10 @@ void BlueStore::_fsck_repair_shared_blobs(
   if (!sb_ref_mismatches) // not expected to succeed, just in case
     return;
 
-
-  auto foreach_shared_blob = [&](std::function<
-    void (coll_t,
-          ghobject_t,
-          uint64_t,
-          const bluestore_blob_t&)> cb) {
-      auto it = db->get_iterator(PREFIX_OBJ, KeyValueDB::ITERATOR_NOCACHE);
-      if (it) {
-        CollectionRef c;
-        spg_t pgid;
-        for (it->lower_bound(string()); it->valid(); it->next()) {
-          dout(30) << __func__ << " key "
-                  << pretty_binary_string(it->key())
-                  << dendl;
-          if (is_extent_shard_key(it->key())) {
-           continue;
-          }
-
-          ghobject_t oid;
-          int r = get_key_object(it->key(), &oid);
-          if (r < 0) {
-           continue;
-          }
-
-          if (!c ||
-           oid.shard_id != pgid.shard ||
-           oid.hobj.get_logical_pool() != (int64_t)pgid.pool() ||
-           !c->contains(oid)) {
-           c = nullptr;
-           for (auto& p : coll_map) {
-             if (p.second->contains(oid)) {
-               c = p.second;
-               break;
-             }
-           }
-           if (!c) {
-             continue;
-           }
-          }
-          dout(20) << __func__
-                   << " inspecting shared blob refs for col:" << c->cid
-                  << " obj:" << oid
-                  << dendl;
-
-          OnodeRef o;
-          o.reset(Onode::create_decode(c, oid, it->key(), it->value()));
-          o->extent_map.fault_range(db, 0, OBJECT_MAX_SIZE);
-
-          _dump_onode<30>(cct, *o);
-
-          mempool::bluestore_fsck::set<BlobRef> passed_sbs;
-          for (auto& e : o->extent_map.extent_map) {
-           auto& b = e.blob->get_blob();
-           if (b.is_shared() && passed_sbs.count(e.blob) == 0) {
-             auto sbid = e.blob->shared_blob->get_sbid();
-             cb(c->cid, oid, sbid, b);
-             passed_sbs.emplace(e.blob);
-           }
-          } // for ... extent_map
-        } // for ... it->valid
-      } //if (it(PREFIX_OBJ))
-    }; //foreach_shared_blob fn declaration
-
   mempool::bluestore_fsck::map<uint64_t, bluestore_extent_ref_map_t> refs_map;
 
   // first iteration over objects to identify all the broken sbids
-  foreach_shared_blob( [&](coll_t cid,
+  _fsck_foreach_shared_blob( [&](coll_t cid,
                            ghobject_t oid,
                            uint64_t sbid,
                            const bluestore_blob_t& b) {
@@ -8134,7 +8130,7 @@ void BlueStore::_fsck_repair_shared_blobs(
   });
 
   // second iteration over objects to build new ref map for the broken sbids
-  foreach_shared_blob( [&](coll_t cid,
+  _fsck_foreach_shared_blob( [&](coll_t cid,
                            ghobject_t oid,
                            uint64_t sbid,
                            const bluestore_blob_t& b) {
index a0e8f324c0829480be43d379c2a71b8e7aca4180..a453b92e422ee5d968e2f3264857d8ad23669dd3 100644 (file)
@@ -2797,6 +2797,8 @@ private:
     int64_t& errors,
     int64_t &warnings,
     BlueStoreRepairer* repairer);
+  void _fsck_foreach_shared_blob(
+    std::function< void (coll_t, ghobject_t, uint64_t, const bluestore_blob_t&)> cb);
   void _fsck_repair_shared_blobs(
     BlueStoreRepairer& repairer,
     shared_blob_2hash_tracker_t& sb_ref_counts,