From 86f0b811882de334f0d7e577b6c47bef6aba2422 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 12 Oct 2017 21:57:48 -0500 Subject: [PATCH] mon/PGMap: add purged_snaps map to PGMapDigest Signed-off-by: Sage Weil --- src/mgr/ClusterState.h | 8 +++++++ src/mgr/DaemonServer.cc | 2 +- src/mon/PGMap.cc | 50 ++++++++++++++++++++++++++++++++++++++--- src/mon/PGMap.h | 5 ++++- 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/src/mgr/ClusterState.h b/src/mgr/ClusterState.h index edc911ba6a63f..a270861e80b48 100644 --- a/src/mgr/ClusterState.h +++ b/src/mgr/ClusterState.h @@ -103,6 +103,14 @@ public: return std::forward(cb)(pg_map, std::forward(args)...); } + template + auto with_mutable_pgmap(Callback&& cb, Args&&...args) -> + decltype(cb(pg_map, std::forward(args)...)) + { + Mutex::Locker l(lock); + return std::forward(cb)(pg_map, std::forward(args)...); + } + template void with_monmap(Args &&... args) const { diff --git a/src/mgr/DaemonServer.cc b/src/mgr/DaemonServer.cc index 2fe220b50b38a..e46631ca42dc8 100644 --- a/src/mgr/DaemonServer.cc +++ b/src/mgr/DaemonServer.cc @@ -1422,7 +1422,7 @@ void DaemonServer::send_report() auto m = new MMonMgrReport(); py_modules.get_health_checks(&m->health_checks); - cluster_state.with_pgmap([&](const PGMap& pg_map) { + cluster_state.with_mutable_pgmap([&](PGMap& pg_map) { cluster_state.update_delta_stats(); if (pending_service_map.epoch) { diff --git a/src/mon/PGMap.cc b/src/mon/PGMap.cc index bfa3b611f25af..c5107af996c7f 100644 --- a/src/mon/PGMap.cc +++ b/src/mon/PGMap.cc @@ -27,7 +27,7 @@ MEMPOOL_DEFINE_OBJECT_FACTORY(PGMap::Incremental, pgmap_inc, pgmap); void PGMapDigest::encode(bufferlist& bl, uint64_t features) const { // NOTE: see PGMap::encode_digest - uint8_t v = 2; + uint8_t v = 3; if (!HAVE_FEATURE(features, SERVER_MIMIC)) { v = 1; } @@ -57,12 +57,15 @@ void PGMapDigest::encode(bufferlist& bl, uint64_t features) const ::encode(pg_sum_delta, bl, features); ::encode(stamp_delta, bl); ::encode(avail_space_by_rule, bl); + if (struct_v >= 3) { + ::encode(purged_snaps, bl); + } ENCODE_FINISH(bl); } void PGMapDigest::decode(bufferlist::iterator& p) { - DECODE_START(2, p); + DECODE_START(3, p); ::decode(num_pg, p); ::decode(num_pg_active, p); ::decode(num_pg_unknown, p); @@ -87,6 +90,9 @@ void PGMapDigest::decode(bufferlist::iterator& p) ::decode(pg_sum_delta, p); ::decode(stamp_delta, p); ::decode(avail_space_by_rule, p); + if (struct_v >= 3) { + ::decode(purged_snaps, p); + } DECODE_FINISH(p); } @@ -139,6 +145,21 @@ void PGMapDigest::dump(Formatter *f) const f->close_section(); } f->close_section(); + f->open_array_section("purged_snaps"); + for (auto& j : purged_snaps) { + f->open_object_section("pool"); + f->dump_int("pool", j.first); + f->open_object_section("purged_snaps"); + for (auto i = j.second.begin(); i != j.second.end(); ++i) { + f->open_object_section("interval"); + f->dump_stream("start") << i.get_start(); + f->dump_stream("length") << i.get_len(); + f->close_section(); + } + f->close_section(); + f->close_section(); + } + f->close_section(); } void PGMapDigest::generate_test_instances(list& ls) @@ -1266,6 +1287,28 @@ void PGMap::stat_pg_sub(const pg_t &pgid, const pg_stat_t &s, } } +void PGMap::calc_purged_snaps() +{ + purged_snaps.clear(); + set unknown; + for (auto& i : pg_stat) { + if (i.second.state == 0) { + unknown.insert(i.first.pool()); + purged_snaps.erase(i.first.pool()); + continue; + } else if (unknown.count(i.first.pool())) { + continue; + } + auto j = purged_snaps.find(i.first.pool()); + if (j == purged_snaps.end()) { + // base case + purged_snaps[i.first.pool()] = i.second.purged_snaps; + } else { + j->second.intersection_of(i.second.purged_snaps); + } + } +} + void PGMap::stat_osd_add(int osd, const osd_stat_t &s) { num_osd++; @@ -1285,9 +1328,10 @@ void PGMap::stat_osd_sub(int osd, const osd_stat_t &s) } void PGMap::encode_digest(const OSDMap& osdmap, - bufferlist& bl, uint64_t features) const + bufferlist& bl, uint64_t features) { get_rules_avail(osdmap, &avail_space_by_rule); + calc_purged_snaps(); PGMapDigest::encode(bl, features); } diff --git a/src/mon/PGMap.h b/src/mon/PGMap.h index b7532b9ebe7d5..ea43ba3dc41b0 100644 --- a/src/mon/PGMap.h +++ b/src/mon/PGMap.h @@ -70,6 +70,8 @@ public: }; mempool::pgmap::unordered_map num_pg_by_osd; + mempool::pgmap::map> purged_snaps; + // recent deltas, and summation /** * keep track of last deltas for each pool, calculated using @@ -378,6 +380,7 @@ public: bool sameosds=false); void stat_pg_sub(const pg_t &pgid, const pg_stat_t &s, bool sameosds=false); + void calc_purged_snaps(); void stat_osd_add(int osd, const osd_stat_t &s); void stat_osd_sub(int osd, const osd_stat_t &s); @@ -386,7 +389,7 @@ public: /// encode subset of our data to a PGMapDigest void encode_digest(const OSDMap& osdmap, - bufferlist& bl, uint64_t features) const; + bufferlist& bl, uint64_t features); int64_t get_rule_avail(const OSDMap& osdmap, int ruleno) const; void get_rules_avail(const OSDMap& osdmap, -- 2.39.5