From: Kefu Chai Date: Thu, 13 Oct 2016 05:19:27 +0000 (+0800) Subject: mon: send updated monmap to its subscribers X-Git-Tag: v11.1.0~544^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c2b348b12c47ba505f72228ae0ea9b1a1b674719;p=ceph.git mon: send updated monmap to its subscribers prior to this change, we sends monmap when serving the subscription requests, but the updates are not sent to the subscribers anymore. so we need to send latest monmap to subscribes and update the subscription status accordingly when the monmap is updated. http://tracker.ceph.com/issues/17558 Signed-off-by: Kefu Chai --- diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 4a0c1ac3dfaf..c8177fd58814 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -4332,7 +4332,7 @@ void Monitor::handle_subscribe(MonOpRequestRef op) pgmon()->check_sub(s->sub_map["osd_pg_creates"]); } } else if (p->first == "monmap") { - check_sub(s->sub_map["monmap"]); + monmon()->check_sub(s->sub_map[p->first]); } else if (logmon()->sub_name_to_id(p->first) >= 0) { logmon()->check_sub(s->sub_map[p->first]); } else if (p->first == "mgrmap" || p->first == "mgrdigest") { @@ -4430,32 +4430,6 @@ bool Monitor::ms_handle_refused(Connection *con) return false; } -void Monitor::check_subs() -{ - string type = "monmap"; - if (session_map.subs.count(type) == 0) - return; - xlist::iterator p = session_map.subs[type]->begin(); - while (!p.end()) { - Subscription *sub = *p; - ++p; - check_sub(sub); - } -} - -void Monitor::check_sub(Subscription *sub) -{ - dout(10) << "check_sub monmap next " << sub->next << " have " << monmap->get_epoch() << dendl; - if (sub->next <= monmap->get_epoch()) { - send_latest_monmap(sub->session->con.get()); - if (sub->onetime) - session_map.remove_sub(sub); - else - sub->next = monmap->get_epoch() + 1; - } -} - - // ----- void Monitor::send_latest_monmap(Connection *con) diff --git a/src/mon/Monitor.h b/src/mon/Monitor.h index a2beeade4a2e..49540f35ad0b 100644 --- a/src/mon/Monitor.h +++ b/src/mon/Monitor.h @@ -667,9 +667,6 @@ public: MonSessionMap session_map; AdminSocketHook *admin_hook; - void check_subs(); - void check_sub(Subscription *sub); - void send_latest_monmap(Connection *con); // messages diff --git a/src/mon/MonmapMonitor.cc b/src/mon/MonmapMonitor.cc index 3cd61a26ec51..a36679e4062e 100644 --- a/src/mon/MonmapMonitor.cc +++ b/src/mon/MonmapMonitor.cc @@ -70,6 +70,8 @@ void MonmapMonitor::update_from_paxos(bool *need_bootstrap) t->erase("mkfs", "monmap"); mon->store->apply_transaction(t); } + + check_subs(); } void MonmapMonitor::create_pending() @@ -574,3 +576,29 @@ int MonmapMonitor::get_monmap(bufferlist &bl) } return 0; } + +void MonmapMonitor::check_subs() +{ + const string type = "monmap"; + auto subs = mon->session_map.subs.find(type); + if (subs == mon->session_map.subs.end()) + return; + for (auto sub : *subs->second) { + check_sub(sub); + } +} + +void MonmapMonitor::check_sub(Subscription *sub) +{ + const auto epoch = mon->monmap->get_epoch(); + dout(10) << __func__ + << " monmap next " << sub->next + << " have " << epoch << dendl; + if (sub->next <= epoch) { + mon->send_latest_monmap(sub->session->con.get()); + if (sub->onetime) + mon->session_map.remove_sub(sub); + else + sub->next = epoch + 1; + } +} diff --git a/src/mon/MonmapMonitor.h b/src/mon/MonmapMonitor.h index ecfbe1e12259..42fd8afa9108 100644 --- a/src/mon/MonmapMonitor.h +++ b/src/mon/MonmapMonitor.h @@ -81,7 +81,12 @@ class MonmapMonitor : public PaxosService { void tick(); - private: + void check_sub(Subscription *sub); + +private: + void check_subs(); + +private: bufferlist monmap_bl; };