]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
osd/OSDMap: new calc_pg_role() that takes a pg_shard_t
authorSage Weil <sage@redhat.com>
Mon, 9 Dec 2019 15:41:31 +0000 (09:41 -0600)
committerSage Weil <sage@redhat.com>
Mon, 9 Dec 2019 15:50:13 +0000 (09:50 -0600)
If you have an acting set like [0,1,2,1] then osd.1 has two possible roles
(1 and 3).  If we simply return the first one we see then we can't
correctly calculate a role for a pg like 1.0s3.  Take pg_shard_t instead.

Signed-off-by: Sage Weil <sage@redhat.com>
src/osd/OSDMap.cc
src/osd/OSDMap.h

index 45af7ad7c28b3c8b2bd3db70410310a0fb5fd7c6..263d6fa7cc97e4028c460bd812d7c0015f5f4318 100644 (file)
@@ -2649,6 +2649,23 @@ int OSDMap::calc_pg_role(int osd, const vector<int>& acting, int nrep)
   return -1;
 }
 
+int OSDMap::calc_pg_role(pg_shard_t who, const vector<int>& acting)
+{
+  int nrep = acting.size();
+  if (who.shard == shard_id_t::NO_SHARD) {
+    for (int i=0; i<nrep; i++) {
+      if (acting[i] == who.osd) {
+       return i;
+      }
+    }
+  } else {
+    if (who.shard < nrep && acting[who.shard] == who.osd) {
+      return who.shard;
+    }
+  }
+  return -1;
+}
+
 bool OSDMap::primary_changed(
   int oldprimary,
   const vector<int> &oldacting,
index 3020aba2559ca5328514308079feaeb72fdc2e95..31cf9b2c8e0a549d3255709e405753ac621dffd7 100644 (file)
@@ -1395,6 +1395,7 @@ public:
 
 
   static int calc_pg_role(int osd, const std::vector<int>& acting, int nrep=0);
+  static int calc_pg_role(pg_shard_t who, const std::vector<int>& acting);
   static bool primary_changed(
     int oldprimary,
     const std::vector<int> &oldacting,