]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: refactor OSDMonitor::send_incremental() 5315/head
authorKefu Chai <kchai@redhat.com>
Tue, 21 Jul 2015 05:24:11 +0000 (13:24 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 11 Aug 2015 07:12:04 +0000 (15:12 +0800)
* remove the duplicated part of the two implementations of
  OSDMonitor::send_incremental()

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/mon/OSDMonitor.cc
src/mon/OSDMonitor.h

index b770601e7ca1f765f41681d10d83d7362f28ff39..e5be4b794f2520ebe302ee213d7098398a877495 100644 (file)
@@ -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;
index f4dc8c6d5adf3d34b4f488befd965e9d2fbf918d..ef9f15779c021710588a02c0a580872442413bb1 100644 (file)
@@ -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<int64_t> *pools);