mirror of
https://github.com/ceph/ceph
synced 2024-12-19 09:57:05 +00:00
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:
parent
79e7db7505
commit
8fb2388d82
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user