@@ -72,7 +72,7 @@ seastar::future<> PerShardState::stop_pgs()
7272 });
7373}
7474
75- std::map<pg_t , pg_stat_t > PerShardState::get_pg_stats () const
75+ std::map<pg_t , pg_stat_t > PerShardState::get_pg_stats ()
7676{
7777 assert_core ();
7878 std::map<pg_t , pg_stat_t > ret;
@@ -119,6 +119,13 @@ HeartbeatStampsRef PerShardState::get_hb_stamps(int peer)
119119 return stamps->second ;
120120}
121121
122+ seastar::future<> PerShardState::update_shard_superblock (OSDSuperblock superblock)
123+ {
124+ assert_core ();
125+ per_shard_superblock = std::move (superblock);
126+ return seastar::now ();
127+ }
128+
122129OSDSingletonState::OSDSingletonState (
123130 int whoami,
124131 crimson::net::Messenger &cluster_msgr,
@@ -352,7 +359,6 @@ void OSDSingletonState::handle_conf_change(
352359seastar::future<OSDSingletonState::local_cached_map_t >
353360OSDSingletonState::get_local_map (epoch_t e)
354361{
355- // TODO: use LRU cache for managing osdmap, fallback to disk if we have to
356362 if (auto found = osdmaps.find (e); found) {
357363 logger ().debug (" {} osdmap.{} found in cache" , __func__, e);
358364 return seastar::make_ready_future<local_cached_map_t >(std::move (found));
@@ -392,6 +398,9 @@ seastar::future<std::map<epoch_t, bufferlist>> OSDSingletonState::load_map_bls(
392398 logger ().debug (" {} loading maps [{},{}]" ,
393399 __func__, first, last);
394400 ceph_assert (first <= last);
401+ // TODO: take osd_map_max into account
402+ // int max = cct->_conf->osd_map_message_max;
403+ // ssize_t max_bytes = cct->_conf->osd_map_message_max_bytes;
395404 return seastar::map_reduce (boost::make_counting_iterator<epoch_t >(first),
396405 boost::make_counting_iterator<epoch_t >(last + 1 ),
397406 [this ](epoch_t e) {
@@ -458,6 +467,34 @@ seastar::future<> OSDSingletonState::store_maps(ceph::os::Transaction& t,
458467 });
459468}
460469
470+ // Note: store/set_superblock is called in later OSD::handle_osd_map
471+ // so we use the OSD's superblock reference meanwhile.
472+ void OSDSingletonState::trim_maps (ceph::os::Transaction& t,
473+ OSDSuperblock& superblock)
474+ {
475+ epoch_t min =
476+ std::min (superblock.cluster_osdmap_trim_lower_bound ,
477+ osdmaps.cached_key_lower_bound ());
478+
479+ if (min <= superblock.get_oldest_map ()) {
480+ return ;
481+ }
482+ logger ().debug (" {}: min={} oldest_map={}" , __func__, min, superblock.get_oldest_map ());
483+
484+ // Trim from the superblock's oldest_map up to `min`.
485+ // Break if we have exceeded the txn target size.
486+ while (superblock.get_oldest_map () < min &&
487+ t.get_num_ops () < crimson::common::local_conf ()->osd_target_transaction_size ) {
488+ logger ().debug (" {}: removing old osdmap epoch {}" , __func__, superblock.get_oldest_map ());
489+ meta_coll->remove_map (t, superblock.get_oldest_map ());
490+ superblock.maps .erase (superblock.get_oldest_map ());
491+ }
492+
493+ // we should not trim past osdmaps.cached_key_lower_bound()
494+ // as there may still be PGs with those map epochs recorded.
495+ ceph_assert (min <= osdmaps.cached_key_lower_bound ());
496+ }
497+
461498seastar::future<Ref<PG>> ShardServices::make_pg (
462499 OSDMapService::cached_map_t create_map,
463500 spg_t pgid,
@@ -716,30 +753,36 @@ seastar::future<> OSDSingletonState::send_incremental_map(
716753 " superblock's oldest map: {}" ,
717754 __func__, first, superblock.get_oldest_map ());
718755 if (first >= superblock.get_oldest_map ()) {
756+ // TODO: osd_map_share_max_epochs
757+ // See OSDService::build_incremental_map_msg
758+ if (first < superblock.cluster_osdmap_trim_lower_bound ) {
759+ logger ().info (" {}: cluster osdmap lower bound: {} "
760+ " > first {}, starting with full map" ,
761+ __func__, superblock.cluster_osdmap_trim_lower_bound , first);
762+ // we don't have the next map the target wants,
763+ // so start with a full map.
764+ first = superblock.cluster_osdmap_trim_lower_bound ;
765+ }
719766 return load_map_bls (
720767 first, superblock.get_newest_map ()
721- ).then ([this , &conn, first ](auto && bls) {
768+ ).then ([this , &conn](auto && bls) {
722769 auto m = crimson::make_message<MOSDMap>(
723770 monc.get_fsid (),
724771 osdmap->get_encoding_features ());
725- m->cluster_osdmap_trim_lower_bound = first ;
772+ m->cluster_osdmap_trim_lower_bound = superblock. cluster_osdmap_trim_lower_bound ;
726773 m->newest_map = superblock.get_newest_map ();
727774 m->maps = std::move (bls);
728775 return conn.send (std::move (m));
729776 });
730777 } else {
778+ // See OSDService::send_incremental_map
779+ // just send latest full map
731780 return load_map_bl (osdmap->get_epoch ()
732781 ).then ([this , &conn](auto && bl) mutable {
733782 auto m = crimson::make_message<MOSDMap>(
734783 monc.get_fsid (),
735784 osdmap->get_encoding_features ());
736- /* TODO: once we support the tracking of superblock's
737- * cluster_osdmap_trim_lower_bound, the MOSDMap should
738- * be populated with this value instead of the oldest_map.
739- * See: OSD::handle_osd_map for how classic updates the
740- * cluster's trim lower bound.
741- */
742- m->cluster_osdmap_trim_lower_bound = superblock.get_oldest_map ();
785+ m->cluster_osdmap_trim_lower_bound = superblock.cluster_osdmap_trim_lower_bound ;
743786 m->newest_map = superblock.get_newest_map ();
744787 m->maps .emplace (osdmap->get_epoch (), std::move (bl));
745788 return conn.send (std::move (m));
0 commit comments