OSDMap: fill in get_primary_shard

Signed-off-by: Samuel Just <sam.just@inktank.com>
This commit is contained in:
Samuel Just 2014-01-23 14:52:01 -08:00
parent 285cf7728a
commit 109b3c9e7f
2 changed files with 22 additions and 1 deletions

View File

@ -627,7 +627,27 @@ public:
assert(i != pools.end());
return i->second.ec_pool();
}
spg_t get_primary_shard(pg_t pgid) const { return spg_t(); /* TODOSAM: fix */}
bool get_primary_shard(pg_t pgid, spg_t *out) const {
map<int64_t, pg_pool_t>::const_iterator i = get_pools().find(pgid.pool());
if (i == get_pools().end()) {
return false;
}
int primary;
vector<int> acting;
pg_to_acting_osds(pgid, &acting, &primary);
if (i->second.ec_pool()) {
for (shard_id_t i = 0; i < acting.size(); ++i) {
if (acting[i] == primary) {
*out = spg_t(pgid, i);
return true;
}
}
} else {
*out = spg_t(pgid);
return true;
}
return false;
}
int64_t lookup_pg_pool_name(const string& name) {
if (name_pool.count(name))

View File

@ -67,6 +67,7 @@ struct pg_shard_t {
int osd;
shard_id_t shard;
pg_shard_t() : osd(-1), shard(ghobject_t::NO_SHARD) {}
explicit pg_shard_t(int osd) : osd(osd), shard(ghobject_t::NO_SHARD) {}
pg_shard_t(int osd, shard_id_t shard) : osd(osd), shard(shard) {}
static pg_shard_t undefined_shard() {
return pg_shard_t(-1, ghobject_t::NO_SHARD);