From 986185ca02b48cfa1450f6fe3bc21188efeacb82 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 26 Jun 2013 17:34:39 -0700 Subject: [PATCH] mon/PGMonitor: avoid duplicating map_pg_create() effort on same maps If we have an election and refresh, but the osdmap does not change, there is no need to recalculate the pg create maps. However, if we register new creating pgs, we do... when the last_pg_scan update gets pulled out of paxos (i.e., on both leader and peon mons). Signed-off-by: Sage Weil --- src/mon/PGMonitor.cc | 21 ++++++++++++++++----- src/mon/PGMonitor.h | 6 +++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/mon/PGMonitor.cc b/src/mon/PGMonitor.cc index 88208354c8ea..ead42a05dcae 100644 --- a/src/mon/PGMonitor.cc +++ b/src/mon/PGMonitor.cc @@ -323,7 +323,12 @@ void PGMonitor::read_pgmap_meta() epoch_t last_pg_scan = mon->store->get(prefix, "last_pg_scan"); pg_map.set_version(version); pg_map.set_last_osdmap_epoch(last_osdmap_epoch); - pg_map.set_last_pg_scan(last_pg_scan); + + if (last_pg_scan != pg_map.get_last_pg_scan()) { + pg_map.set_last_pg_scan(last_pg_scan); + // clear our osdmap epoch so that map_pg_creates() will re-run + last_map_pg_create_osd_epoch = 0; + } float full_ratio, nearfull_ratio; { @@ -369,8 +374,7 @@ void PGMonitor::read_pgmap_full() prefix = "pgmap_osd"; for (KeyValueDB::Iterator i = mon->store->get_iterator(prefix); i->valid(); i->next()) { string key = i->key(); - int osd; - osd = atoi(key.c_str()); + int osd = atoi(key.c_str()); bufferlist bl = i->value(); pg_map.update_osd(osd, bl); dout(20) << " got osd." << osd << dendl; @@ -1004,7 +1008,14 @@ bool PGMonitor::register_new_pgs() void PGMonitor::map_pg_creates() { - dout(10) << "map_pg_creates to " << pg_map.creating_pgs.size() << " pgs" << dendl; + OSDMap *osdmap = &mon->osdmon()->osdmap; + if (osdmap->get_epoch() == last_map_pg_create_osd_epoch) { + dout(10) << "map_pg_creates to " << pg_map.creating_pgs.size() << " pgs -- no change" << dendl; + return; + } + + dout(10) << "map_pg_creates to " << pg_map.creating_pgs.size() << " pgs osdmap epoch " << osdmap->get_epoch() << dendl; + last_map_pg_create_osd_epoch = osdmap->get_epoch(); for (set::iterator p = pg_map.creating_pgs.begin(); p != pg_map.creating_pgs.end(); @@ -1015,7 +1026,7 @@ void PGMonitor::map_pg_creates() if (s.parent_split_bits) on = s.parent; vector acting; - int nrep = mon->osdmon()->osdmap.pg_to_acting_osds(on, acting); + int nrep = osdmap->pg_to_acting_osds(on, acting); if (s.acting.size()) { pg_map.creating_pgs_by_osd[s.acting[0]].erase(pgid); diff --git a/src/mon/PGMonitor.h b/src/mon/PGMonitor.h index 8117ee2bba8a..c6813eda3b13 100644 --- a/src/mon/PGMonitor.h +++ b/src/mon/PGMonitor.h @@ -47,6 +47,9 @@ public: bool need_check_down_pgs; + epoch_t last_map_pg_create_osd_epoch; + + private: PGMap::Incremental pending_inc; @@ -142,7 +145,8 @@ private: public: PGMonitor(Monitor *mn, Paxos *p, const string& service_name) : PaxosService(mn, p, service_name), - need_check_down_pgs(false) + need_check_down_pgs(false), + last_map_pg_create_osd_epoch(0) { } ~PGMonitor() { } -- 2.47.3