From c7254903768cdb38b5aa450064f71712636e92a0 Mon Sep 17 00:00:00 2001 From: Ronen Friedman Date: Tue, 11 Feb 2025 06:52:38 -0600 Subject: [PATCH] osd/scrub: clean-up scrub-store IDs generation The Scrub Store IDs (used to identify OMAP entries used for storing object-specific error data) are generated by attaching some prefix to the text representation of virtual (invented) hobjects. This commit cleans up the code by moving the name generation process (creating temporary un-needed objects, then extracting the to_str() representation of their identity) into separate functions. Signed-off-by: Ronen Friedman --- src/osd/scrubber/ScrubStore.cc | 61 ++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/src/osd/scrubber/ScrubStore.cc b/src/osd/scrubber/ScrubStore.cc index 7f28ca2d642a..d9b9e963823e 100644 --- a/src/osd/scrubber/ScrubStore.cc +++ b/src/osd/scrubber/ScrubStore.cc @@ -15,31 +15,47 @@ using std::vector; using ceph::bufferlist; namespace { + +/// the 'to_str()' representation of an hobject, if created with the specific +/// parameters, prefixed with 'prefix'. +std::string virtual_hobject_w_prefix(std::string_view prefix, + const std::string& key, + snapid_t snap, + uint32_t hash, + int64_t pool) +{ + return fmt::format("{}_{}", prefix, + hobject_t(object_t(), key, snap, hash, pool, "").to_str()); +} + +/// the 'to_str()' representation of an hobject, if created with the specific +/// parameters, prefixed with 'prefix'. +std::string virtual_hobject_w_prefix(std::string_view prefix, + const librados::object_id_t& oid, + uint32_t hash, + int64_t pool) { + return fmt::format("{}_{}", prefix, + hobject_t(object_t{oid.name}, oid.locator, oid.snap, hash, + pool, oid.nspace) + .to_str()); +} + string first_object_key(int64_t pool) { - auto hoid = hobject_t(object_t(), "", CEPH_NOSNAP, 0x00000000, pool, ""); - hoid.build_hash_cache(); - return "SCRUB_OBJ_" + hoid.to_str(); + return virtual_hobject_w_prefix("SCRUB_OBJ", "", CEPH_NOSNAP, 0x00000000, + pool); } // the object_key should be unique across pools string to_object_key(int64_t pool, const librados::object_id_t& oid) { - auto hoid = hobject_t(object_t(oid.name), - oid.locator, // key - oid.snap, - 0, // hash - pool, - oid.nspace); - hoid.build_hash_cache(); - return "SCRUB_OBJ_" + hoid.to_str(); + return virtual_hobject_w_prefix("SCRUB_OBJ", oid, 0x00000000, pool); } string last_object_key(int64_t pool) { - auto hoid = hobject_t(object_t(), "", CEPH_NOSNAP, 0xffffffff, pool, ""); - hoid.build_hash_cache(); - return "SCRUB_OBJ_" + hoid.to_str(); + return virtual_hobject_w_prefix("SCRUB_OBJ", "", CEPH_NOSNAP, 0xffffffff, + pool); } string first_snap_key(int64_t pool) @@ -47,28 +63,17 @@ string first_snap_key(int64_t pool) // scrub object is per spg_t object, so we can misuse the hash (pg.seed) for // representing the minimal and maximum keys. and this relies on how // hobject_t::to_str() works: hex(pool).hex(revhash). - auto hoid = hobject_t(object_t(), "", 0, 0x00000000, pool, ""); - hoid.build_hash_cache(); - return "SCRUB_SS_" + hoid.to_str(); + return virtual_hobject_w_prefix("SCRUB_SS", "", 0, 0x00000000, pool); } string to_snap_key(int64_t pool, const librados::object_id_t& oid) { - auto hoid = hobject_t(object_t(oid.name), - oid.locator, // key - oid.snap, - 0x77777777, // hash - pool, - oid.nspace); - hoid.build_hash_cache(); - return "SCRUB_SS_" + hoid.to_str(); + return virtual_hobject_w_prefix("SCRUB_SS", oid, 0x77777777, pool); } string last_snap_key(int64_t pool) { - auto hoid = hobject_t(object_t(), "", 0, 0xffffffff, pool, ""); - hoid.build_hash_cache(); - return "SCRUB_SS_" + hoid.to_str(); + return virtual_hobject_w_prefix("SCRUB_SS", "", 0, 0xffffffff, pool); } } // namespace -- 2.47.3