@@ -1377,6 +1377,19 @@ void OSDService::got_stop_ack()
13771377MOSDMap *OSDService::build_incremental_map_msg (epoch_t since, epoch_t to,
13781378 OSDSuperblock& sblock)
13791379{
1380+ auto get_map_and_adjust_counters = [] (
1381+ bufferlist& bl,
1382+ int & max,
1383+ ssize_t & max_bytes,
1384+ std::function<bool ()> map_getter) {
1385+ if (!map_getter ()) {
1386+ return false ;
1387+ }
1388+ max--;
1389+ max_bytes -= bl.length ();
1390+ return true ;
1391+ };
1392+
13801393 MOSDMap *m = new MOSDMap (monc->get_fsid (),
13811394 osdmap->get_encoding_features ());
13821395 m->cluster_osdmap_trim_lower_bound = sblock.cluster_osdmap_trim_lower_bound ;
@@ -1388,36 +1401,34 @@ MOSDMap *OSDService::build_incremental_map_msg(epoch_t since, epoch_t to,
13881401 if (since < m->cluster_osdmap_trim_lower_bound ) {
13891402 // we don't have the next map the target wants, so start with a
13901403 // full map.
1391- bufferlist bl;
13921404 dout (10 ) << __func__ << " cluster osdmap lower bound "
13931405 << sblock.cluster_osdmap_trim_lower_bound
13941406 << " > since " << since << " , starting with full map"
13951407 << dendl;
13961408 since = m->cluster_osdmap_trim_lower_bound ;
1397- if (!get_map_bl (since, bl)) {
1398- derr << __func__ << " missing full map " << since << dendl;
1409+ if (bufferlist bl;
1410+ get_map_and_adjust_counters (bl, max, max_bytes, [&] { return get_map_bl (since, bl);})) {
1411+ m->maps [since] = std::move (bl);
1412+ ++since;
1413+ } else {
1414+ derr << __func__ << " missing full map after map gap " << since << dendl;
13991415 goto panic;
14001416 }
1401- max--;
1402- max_bytes -= bl.length ();
1403- m->maps [since] = std::move (bl);
14041417 }
1405- for (epoch_t e = since + 1 ; e <= to; ++e) {
1406- bufferlist bl;
1407- if (get_inc_map_bl (e, bl)) {
1408- m->incremental_maps [e] = bl;
1418+
1419+ for (epoch_t e = since; e <= to && max > 0 && max_bytes > 0 ; ++e) {
1420+ if (bufferlist bl;
1421+ get_map_and_adjust_counters (bl, max, max_bytes, [&] { return get_inc_map_bl (e, bl);})) {
1422+ m->incremental_maps [e] = std::move (bl);
14091423 } else {
14101424 dout (10 ) << __func__ << " missing incremental map " << e << dendl;
1411- if (!get_map_bl (e, bl)) {
1412- derr << __func__ << " also missing full map " << e << dendl;
1413- goto panic;
1425+ if (bufferlist bl;
1426+ get_map_and_adjust_counters (bl, max, max_bytes, [&] { return get_map_bl (e, bl);})) {
1427+ m->maps [e] = std::move (bl);
1428+ } else {
1429+ derr << __func__ << " also missing full map " << e << dendl;
1430+ goto panic;
14141431 }
1415- m->maps [e] = bl;
1416- }
1417- max--;
1418- max_bytes -= bl.length ();
1419- if (max <= 0 || max_bytes <= 0 ) {
1420- break ;
14211432 }
14221433 }
14231434 return m;
@@ -1444,41 +1455,23 @@ MOSDMap *OSDService::build_incremental_map_msg(epoch_t since, epoch_t to,
14441455 return m;
14451456}
14461457
1447- void OSDService::send_map (MOSDMap *m, Connection *con)
1448- {
1449- con->send_message (m);
1450- }
1451-
14521458void OSDService::send_incremental_map (epoch_t since, Connection *con,
14531459 const OSDMapRef& osdmap)
14541460{
14551461 epoch_t to = osdmap->get_epoch ();
1456- dout (10 ) << " send_incremental_map " << since << " -> " << to
1457- << " to " << con << " " << con->get_peer_addr () << dendl;
1458-
1459- MOSDMap *m = NULL ;
1460- while (!m) {
1461- OSDSuperblock sblock (get_superblock ());
1462- if (since < sblock.get_oldest_map ()) {
1463- // just send latest full map
1464- MOSDMap *m = new MOSDMap (monc->get_fsid (),
1465- osdmap->get_encoding_features ());
1466- m->cluster_osdmap_trim_lower_bound = sblock.cluster_osdmap_trim_lower_bound ;
1467- m->newest_map = sblock.get_newest_map ();
1468- get_map_bl (to, m->maps [to]);
1469- send_map (m, con);
1470- return ;
1471- }
1472-
1473- if (to > since && (int64_t )(to - since) > cct->_conf ->osd_map_share_max_epochs ) {
1474- dout (10 ) << " " << (to - since) << " > max " << cct->_conf ->osd_map_share_max_epochs
1475- << " , only sending most recent" << dendl;
1476- since = to - cct->_conf ->osd_map_share_max_epochs ;
1477- }
1462+ dout (10 ) << fmt::format (" {} epoch range: ({}, {}] to {} {}" ,
1463+ __func__, since, to,
1464+ con->get_peer_entity_name ().to_str (),
1465+ con->get_peer_addr ()) << dendl;
14781466
1479- m = build_incremental_map_msg (since, to, sblock);
1467+ OSDSuperblock sblock (get_superblock ());
1468+ if (to > since && (int64_t )(to - since) > cct->_conf ->osd_map_share_max_epochs ) {
1469+ dout (10 ) << " " << (to - since) << " > max "
1470+ << cct->_conf ->osd_map_share_max_epochs
1471+ << " , only sending most recent" << dendl;
1472+ since = to - cct->_conf ->osd_map_share_max_epochs ;
14801473 }
1481- send_map (m, con );
1474+ con-> send_message ( build_incremental_map_msg (since, to, sblock) );
14821475}
14831476
14841477bool OSDService::_get_map_bl (epoch_t e, bufferlist& bl)
@@ -7453,8 +7446,9 @@ void OSDService::maybe_share_map(
74537446 << session->projected_epoch << dendl;
74547447 return ;
74557448 }
7456-
7457- send_from = session->projected_epoch ;
7449+ // send incremental maps in the range of:
7450+ // (projected_epoch, osdmap]
7451+ send_from = session->projected_epoch + 1 ;
74587452 dout (10 ) << __func__ << " : con " << con->get_peer_addr ()
74597453 << " map epoch " << session->projected_epoch
74607454 << " -> " << osdmap->get_epoch ()
0 commit comments