From: Alex Ainscow Date: Thu, 5 Feb 2026 13:12:47 +0000 (+0000) Subject: erasure-code/consistency: Extend get shard/osd to specify namespace. X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bdac915e92af638e7098e10ddc13624dd244ebc6;p=ceph-ci.git erasure-code/consistency: Extend get shard/osd to specify namespace. Signed-off-by: Alex Ainscow --- diff --git a/src/erasure-code/consistency/RadosCommands.cc b/src/erasure-code/consistency/RadosCommands.cc index cf20b917f37..72319129cbe 100644 --- a/src/erasure-code/consistency/RadosCommands.cc +++ b/src/erasure-code/consistency/RadosCommands.cc @@ -21,9 +21,10 @@ RadosCommands::RadosCommands(librados::Rados& rados) : * @returns int ID of the acting primary OSD */ int RadosCommands::get_primary_osd(const std::string& pool_name, - const std::string& oid) + const std::string& oid, + const std::string& nspace) { - ceph::messaging::osd::OSDMapRequest osd_map_request{pool_name, oid, ""}; + ceph::messaging::osd::OSDMapRequest osd_map_request{pool_name, oid, nspace}; encode_json("OSDMapRequest", osd_map_request, formatter.get()); std::ostringstream oss; @@ -45,6 +46,47 @@ int RadosCommands::get_primary_osd(const std::string& pool_name, return osd; } +/** + * Return the OSD for a specific shard of the given pool and object. + * Assert on failure. + * + * @param pool_name string Name of the pool + * @param oid string OID of the object + * @param shard_id shard_id_t The shard ID to get the OSD for + * @param nspace string Namespace (optional) + * @returns int ID of the OSD for the specified shard + */ +int RadosCommands::get_shard_osd(const std::string& pool_name, + const std::string& oid, + shard_id_t shard_id, + const std::string& nspace) +{ + ceph::messaging::osd::OSDMapRequest osd_map_request{pool_name, oid, nspace}; + encode_json("OSDMapRequest", osd_map_request, formatter.get()); + + std::ostringstream oss; + formatter.get()->flush(oss); + + ceph::bufferlist outbl; + int rc = rados.mon_command(oss.str(), {}, &outbl, nullptr); + ceph_assert(rc == 0); + + JSONParser p; + bool success = p.parse(outbl.c_str(), outbl.length()); + ceph_assert(success); + + ceph::messaging::osd::OSDMapReply reply; + reply.decode_json(&p); + + ceph_assert(shard_id.id >= 0); + ceph_assert((size_t)shard_id.id < reply.acting.size()); + + int osd = reply.acting[shard_id.id]; + ceph_assert(osd >= 0); + + return osd; +} + /** * Send a mon command to fetch the value of the 'allow_ec_optimizations' flag for the * specified pool and return it. diff --git a/src/erasure-code/consistency/RadosCommands.h b/src/erasure-code/consistency/RadosCommands.h index 89b7eb06f85..f8e5670e199 100644 --- a/src/erasure-code/consistency/RadosCommands.h +++ b/src/erasure-code/consistency/RadosCommands.h @@ -20,7 +20,12 @@ class RadosCommands { public: RadosCommands(librados::Rados& rados); int get_primary_osd(const std::string& pool_name, - const std::string& oid); + const std::string& oid, + const std::string& nspace = ""); + int get_shard_osd(const std::string& pool_name, + const std::string& oid, + shard_id_t shard_id, + const std::string& nspace = ""); std::string get_pool_ec_profile_name(const std::string& pool_name); bool get_pool_allow_ec_optimizations(const std::string& pool_name); ceph::ErasureCodeProfile get_ec_profile_for_pool(const std::string& pool_name);