osd_types: pg_t: add get_ancestor() method

Give us the ancestor for when the pool had a past value for pg_num.

Signed-off-by: Sage Weil <sage@inktank.com>
This commit is contained in:
Sage Weil 2014-04-17 21:05:49 -07:00
parent 79e7db7505
commit 8fb2388d82
3 changed files with 22 additions and 0 deletions

View File

@ -393,6 +393,15 @@ ostream& operator<<(ostream& out, const spg_t &pg)
return out;
}
pg_t pg_t::get_ancestor(unsigned old_pg_num) const
{
int old_bits = pg_pool_t::calc_bits_of(old_pg_num);
int old_mask = (1 << old_bits) - 1;
pg_t ret = *this;
ret.m_seed = ceph_stable_mod(m_seed, old_pg_num, old_mask);
return ret;
}
bool pg_t::is_split(unsigned old_pg_num, unsigned new_pg_num, set<pg_t> *children) const
{
assert(m_seed < old_pg_num);

View File

@ -311,6 +311,7 @@ struct pg_t {
}
pg_t get_parent() const;
pg_t get_ancestor(unsigned old_pg_num) const;
int print(char *o, int maxlen) const;
bool parse(const char *s);

View File

@ -558,6 +558,18 @@ TEST(pg_interval_t, check_new_interval)
}
}
TEST(pg_t, get_ancestor)
{
ASSERT_EQ(pg_t(0, 0, -1), pg_t(16, 0, -1).get_ancestor(16));
ASSERT_EQ(pg_t(1, 0, -1), pg_t(17, 0, -1).get_ancestor(16));
ASSERT_EQ(pg_t(0, 0, -1), pg_t(16, 0, -1).get_ancestor(8));
ASSERT_EQ(pg_t(16, 0, -1), pg_t(16, 0, -1).get_ancestor(80));
ASSERT_EQ(pg_t(16, 0, -1), pg_t(16, 0, -1).get_ancestor(83));
ASSERT_EQ(pg_t(1, 0, -1), pg_t(1321, 0, -1).get_ancestor(123).get_ancestor(8));
ASSERT_EQ(pg_t(3, 0, -1), pg_t(1323, 0, -1).get_ancestor(123).get_ancestor(8));
ASSERT_EQ(pg_t(3, 0, -1), pg_t(1323, 0, -1).get_ancestor(8));
}
TEST(pg_t, split)
{
pg_t pgid(0, 0, -1);