]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Objecter/OSDMap: factor out primary_changed() into static OSDMap method
authorSamuel Just <sam.just@inktank.com>
Sun, 23 Feb 2014 21:23:42 +0000 (13:23 -0800)
committerSamuel Just <sam.just@inktank.com>
Sun, 23 Feb 2014 21:35:16 +0000 (13:35 -0800)
We need to reuse this logic in OSD::project_pg_history.

Signed-off-by: Samuel Just <sam.just@inktank.com>
src/osd/OSDMap.cc
src/osd/OSDMap.h
src/osdc/Objecter.cc

index 2ca2351ac298436d70bc7cfe03f28e33e265394d..253e10d48a52466d0ae912ade8421db812488cbd 100644 (file)
@@ -1586,6 +1586,24 @@ int OSDMap::calc_pg_role(int osd, const vector<int>& acting, int nrep)
   return calc_pg_rank(osd, acting, nrep);
 }
 
+bool OSDMap::primary_changed(
+  int oldprimary,
+  const vector<int> &oldacting,
+  int newprimary,
+  const vector<int> &newacting)
+{
+  if (oldacting.empty() && newacting.empty())
+    return false;    // both still empty
+  if (oldacting.empty() ^ newacting.empty())
+    return true;     // was empty, now not, or vice versa
+  if (oldprimary != newprimary)
+    return true;     // primary changed
+  if (calc_pg_rank(oldprimary, oldacting) !=
+      calc_pg_rank(newprimary, newacting))
+    return true;
+  return false;      // same primary (tho replicas may have changed)
+}
+
 
 // serialize, unserialize
 void OSDMap::encode_client_old(bufferlist& bl) const
index c7098d981951a8f5b243696ddd008464b2587e77..44da1b0e2b9a82c721ef942df8168427e178683d 100644 (file)
@@ -714,6 +714,11 @@ public:
   /* what replica # is a given osd? 0 primary, -1 for none. */
   static int calc_pg_rank(int osd, const vector<int>& acting, int nrep=0);
   static int calc_pg_role(int osd, const vector<int>& acting, int nrep=0);
+  static bool primary_changed(
+    int oldprimary,
+    const vector<int> &oldacting,
+    int newprimary,
+    const vector<int> &newacting);
   
   /* rank is -1 (stray), 0 (primary), 1,2,3,... (replica) */
   int get_pg_acting_rank(pg_t pg, int osd) const {
index 155e7a0a43852601d8a7378edc11a2db26d9919b..7f64b00eca1da6265455df2e389c671204b69a4e 100644 (file)
@@ -1381,14 +1381,11 @@ bool Objecter::is_pg_changed(
   const vector<int>& newacting,
   bool any_change)
 {
-  if (oldacting.empty() && newacting.empty())
-    return false;    // both still empty
-  if (oldacting.empty() ^ newacting.empty())
-    return true;     // was empty, now not, or vice versa
-  if (oldprimary != newprimary)
-    return true;     // primary changed
-  if (OSDMap::calc_pg_rank(oldprimary, oldacting) !=
-      OSDMap::calc_pg_rank(newprimary, newacting))
+  if (OSDMap::primary_changed(
+       oldprimary,
+       oldacting,
+       newprimary,
+       newacting))
     return true;
   if (any_change && oldacting != newacting)
     return true;