From 98e6da670f8a2bc2d3272baf06c12678b8fdee19 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 21 Sep 2009 14:45:45 -0700 Subject: [PATCH] mon: allow sub for monmap --- src/mon/MonMap.h | 2 ++ src/mon/Monitor.cc | 38 +++++++++++++++++++++++++++++++++++--- src/mon/Monitor.h | 4 ++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/mon/MonMap.h b/src/mon/MonMap.h index ba63408bb4c..9313d9f0ec3 100644 --- a/src/mon/MonMap.h +++ b/src/mon/MonMap.h @@ -39,6 +39,8 @@ class MonMap { return mon_inst.size(); } + epoch_t get_epoch() { return epoch; } + void add_mon(entity_inst_t inst) { mon_inst.push_back(inst); } diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 39a727f285f..c342286858f 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -494,6 +494,8 @@ void Monitor::handle_subscribe(MMonSubscribe *m) mdsmon()->check_sub(s->sub_map["mdsmap"]); else if (p->first == "osdmap") osdmon()->check_sub(s->sub_map["osdmap"]); + else if (p->first == "monmap") + check_sub(s->sub_map["monmap"]); } // ??? @@ -518,12 +520,42 @@ bool Monitor::ms_handle_reset(Connection *con, const entity_addr_t& peer) return true; } +void Monitor::check_subs() +{ + nstring type = "monmap"; + xlist::iterator p = session_map.subs[type].begin(); + while (!p.end()) { + Subscription *sub = *p; + ++p; + check_sub(sub); + } +} + +void Monitor::check_sub(Subscription *sub) +{ + if (sub->last < monmap->get_epoch()) { + send_latest_monmap(sub->session->inst); + if (sub->onetime) + session_map.remove_sub(sub); + else + sub->last = monmap->get_epoch(); + } +} + + +// ----- + +void Monitor::send_latest_monmap(entity_inst_t i) +{ + bufferlist bl; + monmap->encode(bl); + messenger->send_message(new MMonMap(bl), i); +} + void Monitor::handle_mon_get_map(MMonGetMap *m) { dout(10) << "handle_mon_get_map" << dendl; - bufferlist bl; - monmap->encode(bl); - messenger->send_message(new MMonMap(bl), m->get_orig_source_inst()); + send_latest_monmap(m->get_orig_source_inst()); delete m; } diff --git a/src/mon/Monitor.h b/src/mon/Monitor.h index 96ee4f36f9e..b770b47fa2a 100644 --- a/src/mon/Monitor.h +++ b/src/mon/Monitor.h @@ -131,6 +131,10 @@ public: // -- sessions -- SessionMap session_map; + void check_subs(); + void check_sub(Subscription *sub); + + void send_latest_monmap(entity_inst_t i); // messages