]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson/osd: share map with clients when osdmap epoch doesn't match
authorXuehan Xu <xxhdx1985126@163.com>
Mon, 8 Jun 2020 06:41:54 +0000 (14:41 +0800)
committerXuehan Xu <xxhdx1985126@163.com>
Thu, 18 Jun 2020 01:52:59 +0000 (09:52 +0800)
Signed-off-by: Xuehan Xu <xxhdx1985126@163.com>
src/crimson/osd/osd.cc
src/crimson/osd/osd.h
src/crimson/osd/osd_operations/client_request.cc

index 0bf20f0f2b3a36f5a737ef2b12b674e1427c64bf..62a02c8445782206c58046d9b6d0015f76ad8c30 100644 (file)
@@ -735,6 +735,25 @@ seastar::future<bufferlist> OSD::load_map_bl(epoch_t e)
   }
 }
 
+seastar::future<std::map<epoch_t, bufferlist>> OSD::load_map_bls(
+  epoch_t first,
+  epoch_t last)
+{
+  return seastar::map_reduce(boost::make_counting_iterator<epoch_t>(first),
+                            boost::make_counting_iterator<epoch_t>(last + 1),
+                            [this](epoch_t e) {
+    return load_map_bl(e).then([e](auto&& bl) {
+       return seastar::make_ready_future<pair<epoch_t, bufferlist>>(
+           std::make_pair(e, std::move(bl)));
+    });
+  },
+  std::map<epoch_t, bufferlist>{},
+  [](auto&& bls, auto&& epoch_bl) {
+    bls.emplace(std::move(epoch_bl));
+    return std::move(bls);
+  });
+}
+
 seastar::future<std::unique_ptr<OSDMap>> OSD::load_map(epoch_t e)
 {
   auto o = std::make_unique<OSDMap>();
@@ -1023,6 +1042,32 @@ seastar::future<> OSD::handle_osd_op(crimson::net::Connection* conn,
   return seastar::now();
 }
 
+seastar::future<> OSD::send_incremental_map(crimson::net::Connection* conn,
+                                           epoch_t first)
+{
+  if (first >= superblock.oldest_map) {
+    return load_map_bls(first, superblock.newest_map)
+    .then([this, conn, first](auto&& bls) {
+      auto m = make_message<MOSDMap>(monc->get_fsid(),
+         osdmap->get_encoding_features());
+      m->oldest_map = first;
+      m->newest_map = superblock.newest_map;
+      m->maps = std::move(bls);
+      return conn->send(m);
+    });
+  } else {
+    return load_map_bl(osdmap->get_epoch())
+    .then([this, conn, first](auto&& bl) mutable {
+      auto m = make_message<MOSDMap>(monc->get_fsid(),
+         osdmap->get_encoding_features());
+      m->oldest_map = superblock.oldest_map;
+      m->newest_map = superblock.newest_map;
+      m->maps.emplace(osdmap->get_epoch(), std::move(bl));
+      return conn->send(m);
+    });
+  }
+}
+
 seastar::future<> OSD::handle_rep_op(crimson::net::Connection* conn,
                                     Ref<MOSDRepOp> m)
 {
index cb6c0db3b0423dc683a2b1b4b718d9366365afa5..18197aa8cd7f3216b2d87f868d0f78f2584358fd 100644 (file)
@@ -132,6 +132,9 @@ public:
   void dump_status(Formatter*) const;
 
   void print(std::ostream&) const;
+
+  seastar::future<> send_incremental_map(crimson::net::Connection* conn,
+                                        epoch_t first);
 private:
   seastar::future<> start_boot();
   seastar::future<> _preboot(version_t oldest_osdmap, version_t newest_osdmap);
@@ -155,6 +158,8 @@ private:
   cached_map_t get_map() const final;
   seastar::future<std::unique_ptr<OSDMap>> load_map(epoch_t e);
   seastar::future<bufferlist> load_map_bl(epoch_t e);
+  seastar::future<std::map<epoch_t, bufferlist>>
+  load_map_bls(epoch_t first, epoch_t last);
   void store_map_bl(ceph::os::Transaction& t,
                     epoch_t e, bufferlist&& bl);
   seastar::future<> store_maps(ceph::os::Transaction& t,
index 142a2f0af06bf2971d05906355d37b47dbcc3461..0d7123181fbd3d48fb177ee562bcade4462ed9f5 100644 (file)
@@ -69,6 +69,11 @@ seastar::future<> ClientRequest::start()
        return with_blocking_future(osd.wait_for_pg(m->get_spg()));
       }).then([this, opref](Ref<PG> pgref) {
        PG &pg = *pgref;
+       if (__builtin_expect(m->get_map_epoch()
+                             < pg.get_info().history.same_primary_since,
+                            false)) {
+         return osd.send_incremental_map(conn.get(), m->get_map_epoch());
+       }
        return with_blocking_future(
          handle.enter(pp(pg).await_map)
        ).then([this, &pg]() mutable {