1
0
mirror of https://github.com/ceph/ceph synced 2025-02-22 18:47:18 +00:00

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 <sam.just@inktank.com>
This commit is contained in:
Samuel Just 2014-02-23 13:23:42 -08:00
parent d0359f7c1c
commit 0442b456b9
3 changed files with 28 additions and 8 deletions

View 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

View 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 {

View 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;