Skip to content

Commit 7480bae

Browse files
committed
crimson/osd: rewrite build_incremental_map_msg
* load_map_bls() to load inc maps first (if possible). * build_incremental_map_msg() to load full map in case of a map gap. * Conf options are now maintained: * osd_map_share_max_epochs * osd_map_message_max * osd_map_message_max_bytes Signed-off-by: Matan Breizman <[email protected]>
1 parent 42a6221 commit 7480bae

File tree

3 files changed

+96
-44
lines changed

3 files changed

+96
-44
lines changed

src/crimson/osd/osdmap_service.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ class OSDMapService {
1212
public:
1313
using cached_map_t = OSDMapRef;
1414
using local_cached_map_t = LocalOSDMapRef;
15+
enum class encoded_osdmap_type_t {
16+
FULLMAP,
17+
INCMAP
18+
};
19+
using bls_pair = std::pair<encoded_osdmap_type_t, bufferlist>;
20+
using bls_map_pair_t = std::pair<epoch_t, bls_pair>;
21+
using bls_map_t = std::map<epoch_t, bls_pair>;
1522

1623
virtual ~OSDMapService() = default;
1724
virtual seastar::future<cached_map_t> get_map(epoch_t e) = 0;

src/crimson/osd/shard_services.cc

Lines changed: 83 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -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

831871
seastar::future<> OSDSingletonState::send_incremental_map_to_osd(

src/crimson/osd/shard_services.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ class OSDSingletonState : public md_config_obs_t {
270270
superblock = std::move(_superblock);
271271
}
272272

273+
seastar::future<MURef<MOSDMap>> build_incremental_map_msg(
274+
epoch_t first,
275+
epoch_t last);
276+
273277
seastar::future<> send_incremental_map(
274278
crimson::net::Connection &conn,
275279
epoch_t first);
@@ -320,8 +324,8 @@ class OSDSingletonState : public md_config_obs_t {
320324
seastar::future<local_cached_map_t> get_local_map(epoch_t e);
321325
seastar::future<std::unique_ptr<OSDMap>> load_map(epoch_t e);
322326
seastar::future<bufferlist> load_map_bl(epoch_t e);
323-
seastar::future<std::map<epoch_t, bufferlist>>
324327
read_errorator::future<ceph::bufferlist> load_inc_map_bl(epoch_t e);
328+
seastar::future<OSDMapService::bls_map_t>
325329
load_map_bls(epoch_t first, epoch_t last);
326330
void store_map_bl(ceph::os::Transaction& t,
327331
epoch_t e, bufferlist&& bl);
@@ -510,6 +514,7 @@ class ShardServices : public OSDMapService {
510514
FORWARD_TO_OSD_SINGLETON(get_pool_info)
511515
FORWARD(with_throttle_while, with_throttle_while, local_state.throttler)
512516

517+
FORWARD_TO_OSD_SINGLETON(build_incremental_map_msg)
513518
FORWARD_TO_OSD_SINGLETON(send_incremental_map)
514519
FORWARD_TO_OSD_SINGLETON(send_incremental_map_to_osd)
515520

0 commit comments

Comments
 (0)