mon/PGMap: add up_primary pg number field for "pg dump osds" cmd

As follows:
[root@tecs131 ~]# ceph pg dump osds
OSD_STAT USED  AVAIL  TOTAL  HB_PEERS                                                     PG_SUM UP_PRIMARY_PG_SUM
9         118G   822G   941G    [0,1,2,4,5,7,8,10,11,12,13,15,16,17,20,21,22,23,25,27,29]    299               101
8         122G   819G   941G     [3,4,6,7,9,10,11,14,16,18,19,20,22,23,24,25,26,27,28,29]    311               107
7         124G   817G   941G        [0,1,2,3,5,6,8,9,10,12,13,14,15,17,18,19,21,24,26,28]    314               102
6         119G   821G   941G       [0,1,2,4,5,7,8,11,12,13,15,16,17,20,21,22,23,25,27,29]    311               103
5         127G   813G   941G     [3,4,6,7,9,10,11,14,16,18,19,20,22,23,24,25,26,27,28,29]    333               113
4         118G   822G   941G        [0,1,2,3,5,6,8,9,10,12,13,14,15,17,18,19,21,24,26,28]    304               127
3         124G   816G   941G       [0,1,2,4,5,7,8,11,12,13,15,16,17,20,21,22,23,25,27,29]    324               106
29        111G   829G   941G        [0,1,2,3,5,6,8,9,10,12,13,14,15,17,18,19,21,24,26,28]    282               100
17        115G   825G   941G     [3,4,6,7,9,10,11,14,16,18,19,20,22,23,24,25,26,27,28,29]    291               101
16        122G   819G   941G        [0,1,2,3,5,6,8,9,10,12,13,14,15,17,18,19,21,24,26,28]    321               104
15        105G   836G   941G     [3,4,6,7,9,10,11,14,16,18,19,20,22,23,24,25,26,27,28,29]    273                77
14        122G   819G   941G       [0,1,2,4,5,7,8,11,12,13,15,16,17,20,21,22,23,25,27,29]    316               120
13        120G   821G   941G  [3,4,6,7,9,10,11,12,14,16,18,19,20,22,23,24,25,26,27,28,29]    305                98
10        111G   829G   941G     [0,1,2,4,5,7,8,9,11,12,13,15,16,17,20,21,22,23,25,27,29]    272                67
12        126G   814G   941G  [3,4,6,7,9,10,11,13,14,16,18,19,20,22,23,24,25,26,27,28,29]    321                97
1         127G   813G   941G [0,2,3,4,6,7,9,10,11,14,16,18,19,20,22,23,24,25,26,27,28,29]    326               104

Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
This commit is contained in:
xie xingguo 2017-02-16 09:50:27 +08:00
parent f91fa5ae96
commit 781bd5f05f
2 changed files with 22 additions and 0 deletions

View File

@ -342,6 +342,7 @@ void PGMap::calc_stats()
pg_sum = pool_stat_t();
osd_sum = osd_stat_t();
pg_by_osd.clear();
num_primary_pg_by_osd.clear();
for (ceph::unordered_map<pg_t,pg_stat_t>::iterator p = pg_stat.begin();
p != pg_stat.end();
@ -470,6 +471,9 @@ void PGMap::stat_pg_add(const pg_t &pgid, const pg_stat_t &s,
pg_by_osd[*p].insert(pgid);
for (vector<int>::const_iterator p = s.up.begin(); p != s.up.end(); ++p)
pg_by_osd[*p].insert(pgid);
if (s.up_primary >= 0)
num_primary_pg_by_osd[s.up_primary]++;
}
void PGMap::stat_pg_sub(const pg_t &pgid, const pg_stat_t &s,
@ -525,6 +529,12 @@ void PGMap::stat_pg_sub(const pg_t &pgid, const pg_stat_t &s,
if (oset.empty())
pg_by_osd.erase(*p);
}
if (s.up_primary >= 0) {
auto it = num_primary_pg_by_osd.find(s.up_primary);
if (it != num_primary_pg_by_osd.end() && it->second > 0)
it->second--;
}
}
void PGMap::stat_pg_update(const pg_t pgid, pg_stat_t& s,
@ -956,6 +966,7 @@ void PGMap::dump_osd_stats(ostream& ss) const
tab.define_column("TOTAL", TextTable::LEFT, TextTable::RIGHT);
tab.define_column("HB_PEERS", TextTable::LEFT, TextTable::RIGHT);
tab.define_column("PG_SUM", TextTable::LEFT, TextTable::RIGHT);
tab.define_column("PRIMARY_PG_SUM", TextTable::LEFT, TextTable::RIGHT);
for (ceph::unordered_map<int32_t,osd_stat_t>::const_iterator p = osd_stat.begin();
p != osd_stat.end();
@ -966,6 +977,7 @@ void PGMap::dump_osd_stats(ostream& ss) const
<< si_t(p->second.kb << 10)
<< p->second.hb_peers
<< get_num_pg_by_osd(p->first)
<< get_num_primary_pg_by_osd(p->first)
<< TextTable::endrow;
}

View File

@ -124,6 +124,7 @@ public:
mutable epoch_t min_last_epoch_clean;
ceph::unordered_map<int,int> blocked_by_sum;
ceph::unordered_map<int,set<pg_t> > pg_by_osd;
ceph::unordered_map<int,int> num_primary_pg_by_osd;
utime_t stamp;
@ -253,6 +254,15 @@ public:
return pool_stat_t();
}
int get_num_primary_pg_by_osd(int osd) const {
assert(osd >= 0);
int num = 0;
auto it = num_primary_pg_by_osd.find(osd);
if (it != num_primary_pg_by_osd.end())
num = it->second;
return num;
}
void update_pg(pg_t pgid, bufferlist& bl);
void remove_pg(pg_t pgid);
void update_osd(int osd, bufferlist& bl);