MOSDMap *OSDService::build_incremental_map_msg(epoch_t since, epoch_t to,
OSDSuperblock& sblock)
{
+ auto get_map_and_adjust_counters = [] (
+ bufferlist& bl,
+ int& max,
+ ssize_t& max_bytes,
+ std::function<bool()> map_getter) {
+ if (!map_getter()) {
+ return false;
+ }
+ max--;
+ max_bytes -= bl.length();
+ return true;
+ };
+
MOSDMap *m = new MOSDMap(monc->get_fsid(),
osdmap->get_encoding_features());
m->cluster_osdmap_trim_lower_bound = sblock.cluster_osdmap_trim_lower_bound;
if (since < m->cluster_osdmap_trim_lower_bound) {
// we don't have the next map the target wants, so start with a
// full map.
- bufferlist bl;
dout(10) << __func__ << " cluster osdmap lower bound "
<< sblock.cluster_osdmap_trim_lower_bound
<< " > since " << since << ", starting with full map"
<< dendl;
since = m->cluster_osdmap_trim_lower_bound;
- if (!get_map_bl(since, bl)) {
- derr << __func__ << " missing full map " << since << dendl;
+ if (bufferlist bl;
+ get_map_and_adjust_counters(bl, max, max_bytes, [&] { return get_map_bl(since, bl);})) {
+ m->maps[since] = std::move(bl);
+ ++since;
+ } else {
+ derr << __func__ << " missing full map after map gap " << since << dendl;
goto panic;
}
- max--;
- max_bytes -= bl.length();
- m->maps[since] = std::move(bl);
}
- for (epoch_t e = since; e <= to; ++e) {
- bufferlist bl;
- if (get_inc_map_bl(e, bl)) {
- m->incremental_maps[e] = bl;
+
+ for (epoch_t e = since; e <= to && max > 0 && max_bytes > 0; ++e) {
+ if (bufferlist bl;
+ get_map_and_adjust_counters(bl, max, max_bytes, [&] { return get_inc_map_bl(e, bl);})) {
+ m->incremental_maps[e] = std::move(bl);
} else {
dout(10) << __func__ << " missing incremental map " << e << dendl;
- if (!get_map_bl(e, bl)) {
- derr << __func__ << " also missing full map " << e << dendl;
- goto panic;
+ if (bufferlist bl;
+ get_map_and_adjust_counters(bl, max, max_bytes, [&] { return get_map_bl(e, bl);})) {
+ m->maps[e] = std::move(bl);
+ } else {
+ derr << __func__ << " also missing full map " << e << dendl;
+ goto panic;
}
- m->maps[e] = bl;
- }
- max--;
- max_bytes -= bl.length();
- if (max <= 0 || max_bytes <= 0) {
- break;
}
}
return m;