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>
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,
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,