]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
erasure-code/consistency: Extend get shard/osd to specify namespace.
authorAlex Ainscow <aainscow@uk.ibm.com>
Thu, 5 Feb 2026 13:12:47 +0000 (13:12 +0000)
committerAlex Ainscow <aainscow@uk.ibm.com>
Fri, 6 Feb 2026 10:31:30 +0000 (10:31 +0000)
Signed-off-by: Alex Ainscow <aainscow@uk.ibm.com>
src/erasure-code/consistency/RadosCommands.cc
src/erasure-code/consistency/RadosCommands.h

index cf20b917f37d35e6ce5f5faa0a7692237c6b90a3..72319129cbebaef223508dec240f1d7924ec8283 100644 (file)
@@ -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.
index 89b7eb06f858867ef8dfcc88f3c726510401a798..f8e5670e199e501fc1e40cc96bcc8dcaf80f26be 100644 (file)
@@ -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);