From 0442b456b989282dcf5eeb77c4a787099c14e8ae Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Sun, 23 Feb 2014 13:23:42 -0800 Subject: [PATCH] Objecter/OSDMap: factor out primary_changed() into static OSDMap method We need to reuse this logic in OSD::project_pg_history. Signed-off-by: Samuel Just --- src/osd/OSDMap.cc | 18 ++++++++++++++++++ src/osd/OSDMap.h | 5 +++++ src/osdc/Objecter.cc | 13 +++++-------- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index 2ca2351ac2984..253e10d48a524 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -1586,6 +1586,24 @@ int OSDMap::calc_pg_role(int osd, const vector& acting, int nrep) return calc_pg_rank(osd, acting, nrep); } +bool OSDMap::primary_changed( + int oldprimary, + const vector &oldacting, + int newprimary, + const vector &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 diff --git a/src/osd/OSDMap.h b/src/osd/OSDMap.h index c7098d981951a..44da1b0e2b9a8 100644 --- a/src/osd/OSDMap.h +++ b/src/osd/OSDMap.h @@ -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& acting, int nrep=0); static int calc_pg_role(int osd, const vector& acting, int nrep=0); + static bool primary_changed( + int oldprimary, + const vector &oldacting, + int newprimary, + const vector &newacting); /* rank is -1 (stray), 0 (primary), 1,2,3,... (replica) */ int get_pg_acting_rank(pg_t pg, int osd) const { diff --git a/src/osdc/Objecter.cc b/src/osdc/Objecter.cc index 155e7a0a43852..7f64b00eca1da 100644 --- a/src/osdc/Objecter.cc +++ b/src/osdc/Objecter.cc @@ -1381,14 +1381,11 @@ bool Objecter::is_pg_changed( const vector& 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; -- 2.39.5