@@ -417,25 +417,34 @@ read_errorator::future<ceph::bufferlist> OSDSingletonState::load_inc_map_bl(
417417 }
418418}
419419
420- seastar::future<std::map< epoch_t , bufferlist> > OSDSingletonState::load_map_bls (
420+ seastar::future<OSDMapService:: bls_map_t > OSDSingletonState::load_map_bls (
421421 epoch_t first,
422422 epoch_t last)
423423{
424424 logger ().debug (" {} loading maps [{},{}]" ,
425425 __func__, first, last);
426426 ceph_assert (first <= last);
427- // TODO: take osd_map_max into account
428- // int max = cct->_conf->osd_map_message_max;
429- // ssize_t max_bytes = cct->_conf->osd_map_message_max_bytes;
430427 return seastar::map_reduce (boost::make_counting_iterator<epoch_t >(first),
431428 boost::make_counting_iterator<epoch_t >(last + 1 ),
432429 [this ](epoch_t e) {
433- return load_map_bl (e).then ([e](auto && bl) {
434- return seastar::make_ready_future<std::pair<epoch_t , bufferlist>>(
435- std::make_pair (e, std::move (bl)));
430+ return load_inc_map_bl (e).safe_then ([](auto && bl) {
431+ return seastar::make_ready_future<OSDMapService::bls_pair>(
432+ std::make_pair (OSDMapService::encoded_osdmap_type_t ::INCMAP,
433+ std::move (bl)));
434+ }, read_errorator::all_same_way ([this , e] {
435+ logger ().debug (" load_map_bls: can't load inc map {}, attempting full map instread" ,
436+ e);
437+ return load_map_bl (e).then ([](auto && bl) {
438+ return seastar::make_ready_future<OSDMapService::bls_pair>(
439+ std::make_pair (OSDMapService::encoded_osdmap_type_t ::FULLMAP,
440+ std::move (bl)));
441+ });
442+ })).then ([e] (auto && loaded_map) {
443+ return seastar::make_ready_future<OSDMapService::bls_map_pair_t >(
444+ std::make_pair (e, std::move (loaded_map)));
436445 });
437446 },
438- std::map< epoch_t , bufferlist> {},
447+ OSDMapService:: bls_map_t {},
439448 [](auto && bls, auto && epoch_bl) {
440449 bls.emplace (std::move (epoch_bl));
441450 return std::move (bls);
@@ -479,7 +488,7 @@ seastar::future<> OSDSingletonState::store_maps(ceph::os::Transaction& t,
479488 " loading osdmap.{}" , e, e - 1 );
480489 ceph_assert (std::cmp_greater (e, 0u ));
481490 return load_map (e - 1 ).then (
482- [&added_maps, e, bl=p->second , &t, this ](auto o) {
491+ [&added_maps, e, bl=p->second , &t, this ](auto o) mutable {
483492 OSDMap::Incremental inc;
484493 auto i = bl.cbegin ();
485494 inc.decode (i);
@@ -783,49 +792,80 @@ seastar::future<> ShardServices::dispatch_context(
783792 });
784793}
785794
786- seastar::future<> OSDSingletonState::send_incremental_map (
787- crimson::net::Connection &conn ,
788- epoch_t first )
795+ seastar::future<MURef<MOSDMap>> OSDSingletonState::build_incremental_map_msg (
796+ epoch_t first ,
797+ epoch_t last )
789798{
790- logger ().info (" {}: first osdmap: {} "
791- " superblock's oldest map: {}" ,
792- __func__, first, superblock.get_oldest_map ());
793- if (first >= superblock.get_oldest_map ()) {
794- // TODO: osd_map_share_max_epochs
795- // See OSDService::build_incremental_map_msg
799+ return seastar::do_with (crimson::common::local_conf ()->osd_map_message_max ,
800+ crimson::make_message<MOSDMap>(
801+ monc.get_fsid (),
802+ osdmap->get_encoding_features ()),
803+ [this , &first, last](unsigned int map_message_max,
804+ auto & m) {
805+ m->cluster_osdmap_trim_lower_bound = superblock.cluster_osdmap_trim_lower_bound ;
806+ m->newest_map = superblock.get_newest_map ();
807+ auto maybe_handle_mapgap = seastar::now ();
796808 if (first < superblock.cluster_osdmap_trim_lower_bound ) {
797809 logger ().info (" {}: cluster osdmap lower bound: {} "
798- " > first {}, starting with full map" ,
799- __func__, superblock.cluster_osdmap_trim_lower_bound , first);
810+ " > first {}, starting with full map" ,
811+ __func__, superblock.cluster_osdmap_trim_lower_bound , first);
800812 // we don't have the next map the target wants,
801813 // so start with a full map.
802814 first = superblock.cluster_osdmap_trim_lower_bound ;
815+ maybe_handle_mapgap = load_map_bl (first).then (
816+ [&first, &map_message_max, &m](auto && bl) {
817+ m->maps [first] = std::move (bl);
818+ --map_message_max;
819+ ++first;
820+ });
803821 }
804- return load_map_bls (
805- first, superblock.get_newest_map ()
806- ).then ([this , &conn](auto && bls) {
807- auto m = crimson::make_message<MOSDMap>(
808- monc.get_fsid (),
809- osdmap->get_encoding_features ());
810- m->cluster_osdmap_trim_lower_bound = superblock.cluster_osdmap_trim_lower_bound ;
811- m->newest_map = superblock.get_newest_map ();
812- m->maps = std::move (bls);
813- return conn.send (std::move (m));
814- });
815- } else {
816- // See OSDService::send_incremental_map
817- // just send latest full map
818- return load_map_bl (osdmap->get_epoch ()
819- ).then ([this , &conn](auto && bl) mutable {
820- auto m = crimson::make_message<MOSDMap>(
821- monc.get_fsid (),
822- osdmap->get_encoding_features ());
823- m->cluster_osdmap_trim_lower_bound = superblock.cluster_osdmap_trim_lower_bound ;
824- m->newest_map = superblock.get_newest_map ();
825- m->maps .emplace (osdmap->get_epoch (), std::move (bl));
826- return conn.send (std::move (m));
822+ return maybe_handle_mapgap.then ([this , first, last, &map_message_max, &m] {
823+ if (first > last) {
824+ // first may be later than last in the case of map gap
825+ ceph_assert (!m->maps .empty ());
826+ return seastar::make_ready_future<MURef<MOSDMap>>(std::move (m));
827+ }
828+ return load_map_bls (
829+ first,
830+ ((last - first) > map_message_max) ? (first + map_message_max) : last
831+ ).then ([&m](auto && bls) {
832+ ssize_t map_message_max_bytes = crimson::common::local_conf ()->osd_map_message_max_bytes ;
833+ for (auto const & [e, val] : bls) {
834+ map_message_max_bytes -= val.second .length ();
835+ if (map_message_max_bytes < 0 ) {
836+ break ;
837+ }
838+ if (val.first == OSDMapService::encoded_osdmap_type_t ::FULLMAP) {
839+ m->maps .emplace (e, std::move (val.second ));
840+ } else if (val.first == OSDMapService::encoded_osdmap_type_t ::INCMAP) {
841+ m->incremental_maps .emplace (e, std::move (val.second ));
842+ } else {
843+ ceph_abort ();
844+ }
845+ }
846+ return seastar::make_ready_future<MURef<MOSDMap>>(std::move (m));
847+ });
827848 });
849+ });
850+ }
851+
852+ seastar::future<> OSDSingletonState::send_incremental_map (
853+ crimson::net::Connection &conn,
854+ epoch_t first)
855+ {
856+ epoch_t to = osdmap->get_epoch ();
857+ logger ().info (" {}: first osdmap: {} "
858+ " superblock's oldest map: {}, "
859+ " to {}" ,
860+ __func__, first, superblock.get_oldest_map (), to);
861+ if (to > first && (int64_t )(to - first) > crimson::common::local_conf ()->osd_map_share_max_epochs ) {
862+ logger ().debug (" {} {} > max epochs to send of {}, only sending most recent," ,
863+ __func__, (to - first), crimson::common::local_conf ()->osd_map_share_max_epochs );
864+ first = to - crimson::common::local_conf ()->osd_map_share_max_epochs ;
828865 }
866+ return build_incremental_map_msg (first, to).then ([&conn](auto && m) {
867+ return conn.send (std::move (m));
868+ });
829869}
830870
831871seastar::future<> OSDSingletonState::send_incremental_map_to_osd (
0 commit comments