From 41db5d164fe6fcd7e9454af8713e6e3643b3ebfa Mon Sep 17 00:00:00 2001 From: Xuehan Xu Date: Mon, 8 Jun 2020 14:41:54 +0800 Subject: [PATCH] crimson/osd: share map with clients when osdmap epoch doesn't match Signed-off-by: Xuehan Xu --- src/crimson/osd/osd.cc | 45 +++++++++++++++++++ src/crimson/osd/osd.h | 5 +++ .../osd/osd_operations/client_request.cc | 5 +++ 3 files changed, 55 insertions(+) diff --git a/src/crimson/osd/osd.cc b/src/crimson/osd/osd.cc index 0bf20f0f2b3..62a02c84457 100644 --- a/src/crimson/osd/osd.cc +++ b/src/crimson/osd/osd.cc @@ -735,6 +735,25 @@ seastar::future OSD::load_map_bl(epoch_t e) } } +seastar::future> OSD::load_map_bls( + epoch_t first, + epoch_t last) +{ + return seastar::map_reduce(boost::make_counting_iterator(first), + boost::make_counting_iterator(last + 1), + [this](epoch_t e) { + return load_map_bl(e).then([e](auto&& bl) { + return seastar::make_ready_future>( + std::make_pair(e, std::move(bl))); + }); + }, + std::map{}, + [](auto&& bls, auto&& epoch_bl) { + bls.emplace(std::move(epoch_bl)); + return std::move(bls); + }); +} + seastar::future> OSD::load_map(epoch_t e) { auto o = std::make_unique(); @@ -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(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(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 m) { diff --git a/src/crimson/osd/osd.h b/src/crimson/osd/osd.h index cb6c0db3b04..18197aa8cd7 100644 --- a/src/crimson/osd/osd.h +++ b/src/crimson/osd/osd.h @@ -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> load_map(epoch_t e); seastar::future load_map_bl(epoch_t e); + seastar::future> + 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, diff --git a/src/crimson/osd/osd_operations/client_request.cc b/src/crimson/osd/osd_operations/client_request.cc index 142a2f0af06..0d7123181fb 100644 --- a/src/crimson/osd/osd_operations/client_request.cc +++ b/src/crimson/osd/osd_operations/client_request.cc @@ -69,6 +69,11 @@ seastar::future<> ClientRequest::start() return with_blocking_future(osd.wait_for_pg(m->get_spg())); }).then([this, opref](Ref 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 { -- 2.39.5