@@ -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; 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;
0 commit comments