We need to reuse this logic in OSD::project_pg_history.
Signed-off-by: Samuel Just <sam.just@inktank.com>
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
/* 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 {
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;