From: Kefu Chai Date: Tue, 21 Jul 2015 05:24:11 +0000 (+0800) Subject: mon: refactor OSDMonitor::send_incremental() X-Git-Tag: v9.1.0~330^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fec459dedef61140a998288d8cce3bcba4943aa8;p=ceph.git mon: refactor OSDMonitor::send_incremental() * remove the duplicated part of the two implementations of OSDMonitor::send_incremental() Signed-off-by: Kefu Chai --- diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index b770601e7ca1..e5be4b794f25 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -2329,68 +2329,29 @@ void OSDMonitor::send_full(MonOpRequestRef op) mon->send_reply(op, build_latest_full()); } -/* TBH, I'm fairly certain these two functions could somehow be using a single - * helper function to do the heavy lifting. As this is not our main focus right - * now, I'm leaving it to the next near-future iteration over the services' - * code. We should not forget it though. - * - * TODO: create a helper function and get rid of the duplicated code. - */ void OSDMonitor::send_incremental(MonOpRequestRef op, epoch_t first) { op->mark_osdmon_event(__func__); - dout(5) << "send_incremental [" << first << ".." << osdmap.get_epoch() << "]" - << " to " << op->get_req()->get_orig_source_inst() - << dendl; MonSession *s = op->get_session(); assert(s); - - if (first <= s->osd_epoch) { - dout(10) << __func__ << s->inst << " should already have epoch " - << s->osd_epoch << dendl; - first = s->osd_epoch + 1; - if (first > osdmap.get_epoch()) - return; - } - - if (first < get_first_committed()) { - first = get_first_committed(); - bufferlist bl; - int err = get_version_full(first, bl); - assert(err == 0); - assert(bl.length()); - - dout(20) << "send_incremental starting with base full " - << first << " " << bl.length() << " bytes" << dendl; - - MOSDMap *m = new MOSDMap(osdmap.get_fsid()); - m->oldest_map = first; - m->newest_map = osdmap.get_epoch(); - m->maps[first] = bl; - mon->send_reply(op, m); - - s->osd_epoch = osdmap.get_epoch(); - return; - } - - // send some maps. it may not be all of them, but it will get them - // started. - epoch_t last = MIN(first + g_conf->osd_map_message_max, osdmap.get_epoch()); - MOSDMap *m = build_incremental(first, last); - m->oldest_map = get_first_committed(); - m->newest_map = osdmap.get_epoch(); - mon->send_reply(op, m); - - s->osd_epoch = last; + send_incremental(first, s, false, op); } -void OSDMonitor::send_incremental(epoch_t first, MonSession *session, - bool onetime) +void OSDMonitor::send_incremental(epoch_t first, + MonSession *session, + bool onetime, + MonOpRequestRef req) { dout(5) << "send_incremental [" << first << ".." << osdmap.get_epoch() << "]" << " to " << session->inst << dendl; + if (first <= session->osd_epoch) { + dout(10) << __func__ << session->inst << " should already have epoch " + << session->osd_epoch << dendl; + first = session->osd_epoch + 1; + } + if (first < get_first_committed()) { first = get_first_committed(); bufferlist bl; @@ -2405,26 +2366,39 @@ void OSDMonitor::send_incremental(epoch_t first, MonSession *session, m->oldest_map = first; m->newest_map = osdmap.get_epoch(); m->maps[first] = bl; - session->con->send_message(m); - session->osd_epoch = first; + + if (req) { + mon->send_reply(req, m); + session->osd_epoch = first; + return; + } else { + session->con->send_message(m); + session->osd_epoch = first; + } first++; } while (first <= osdmap.get_epoch()) { epoch_t last = MIN(first + g_conf->osd_map_message_max, osdmap.get_epoch()); MOSDMap *m = build_incremental(first, last); - session->con->send_message(m); - first = last + 1; - session->osd_epoch = last; - if (onetime) + if (req) { + // send some maps. it may not be all of them, but it will get them + // started. + m->oldest_map = get_first_committed(); + m->newest_map = osdmap.get_epoch(); + mon->send_reply(req, m); + } else { + session->con->send_message(m); + first = last + 1; + } + session->osd_epoch = last; + if (onetime || req) break; } } - - epoch_t OSDMonitor::blacklist(const entity_addr_t& a, utime_t until) { dout(10) << "blacklist " << a << " until " << until << dendl; diff --git a/src/mon/OSDMonitor.h b/src/mon/OSDMonitor.h index f4dc8c6d5adf..ef9f15779c02 100644 --- a/src/mon/OSDMonitor.h +++ b/src/mon/OSDMonitor.h @@ -218,7 +218,10 @@ private: MOSDMap *build_incremental(epoch_t first, epoch_t last); void send_full(MonOpRequestRef op); void send_incremental(MonOpRequestRef op, epoch_t first); - void send_incremental(epoch_t first, MonSession *session, bool onetime); + // @param req an optional op request, if the osdmaps are replies to it. so + // @c Monitor::send_reply() can mark_event with it. + void send_incremental(epoch_t first, MonSession *session, bool onetime, + MonOpRequestRef req = MonOpRequestRef()); int reweight_by_utilization(int oload, std::string& out_str, bool by_pg, const set *pools);