mon/PGMap: fix incorrect pg_pool_sum when delete pool

We found the pools num diplayed by "ceph -s" is not the same with
"ceph osd lspools" after deleting a pool sometime. The result is
Mgr ClusterState::ingest_pgstats get the old pg_stat which pg is
not deleted in some osd before the pool deleted and add to
pending_inc.pool_statfs_updates. The deleted pool will be added to
pg_pool_sum unconsciously by PGMap::apply_incremental and which has
been deleted in OSDMap. This will also casue MON's Segmentation
fault.

Fixes: https://tracker.ceph.com/issues/42689
Fixes: https://tracker.ceph.com/issues/42592
Fixes: https://tracker.ceph.com/issues/41228
Fixes: https://tracker.ceph.com/issues/40011
Signed-off-by: luo rixin <luorixin@huawei.com>
This commit is contained in:
luo rixin 2019-11-12 16:36:53 +08:00
parent 8819c3c37a
commit 446eca8def

View File

@ -1175,14 +1175,16 @@ void PGMap::apply_incremental(CephContext *cct, const Incremental& inc)
auto pool_statfs_iter =
pool_statfs.find(std::make_pair(update_pool, update_osd));
pool_stat_t &pool_sum_ref = pg_pool_sum[update_pool];
if (pool_statfs_iter == pool_statfs.end()) {
pool_statfs.emplace(std::make_pair(update_pool, update_osd), statfs_inc);
} else {
pool_sum_ref.sub(pool_statfs_iter->second);
pool_statfs_iter->second = statfs_inc;
if (pg_pool_sum.count(update_pool)) {
pool_stat_t &pool_sum_ref = pg_pool_sum[update_pool];
if (pool_statfs_iter == pool_statfs.end()) {
pool_statfs.emplace(std::make_pair(update_pool, update_osd), statfs_inc);
} else {
pool_sum_ref.sub(pool_statfs_iter->second);
pool_statfs_iter->second = statfs_inc;
}
pool_sum_ref.add(statfs_inc);
}
pool_sum_ref.add(statfs_inc);
}
for (auto p = inc.get_osd_stat_updates().begin();