@@ -8262,7 +8262,64 @@ void OSD::handle_osd_map(MOSDMap *m)
82628262 superblock.clean_thru = last;
82638263 }
82648264
8265- // check for pg_num changes and deleted pools
8265+ track_pools_and_pg_num_changes (added_maps, t, last);
8266+
8267+ {
8268+ bufferlist bl;
8269+ ::encode (pg_num_history, bl);
8270+ auto oid = make_pg_num_history_oid ();
8271+ t.truncate (coll_t::meta (), oid, 0 ); // we don't need bytes left if new data
8272+ // block is shorter than the previous
8273+ // one. And better to trim them, e.g.
8274+ // this allows to avoid csum eroors
8275+ // when issuing overwrite
8276+ // (which happens to be partial)
8277+ // and original data is corrupted.
8278+ // Another side effect is that the
8279+ // superblock is not permanently
8280+ // anchored to a fixed disk location
8281+ // any more.
8282+ t.write (coll_t::meta (), oid, 0 , bl.length (), bl);
8283+ dout (20 ) << __func__ << " pg_num_history " << pg_num_history << dendl;
8284+ }
8285+
8286+ // record new purged_snaps
8287+ if (superblock.purged_snaps_last == start - 1 ) {
8288+ OSDriver osdriver{store.get (), service.meta_ch , make_purged_snaps_oid ()};
8289+ SnapMapper::record_purged_snaps (
8290+ cct,
8291+ osdriver,
8292+ osdriver.get_transaction (&t),
8293+ purged_snaps);
8294+ superblock.purged_snaps_last = last;
8295+ } else {
8296+ dout (10 ) << __func__ << " superblock purged_snaps_last is "
8297+ << superblock.purged_snaps_last
8298+ << " , not recording new purged_snaps" << dendl;
8299+ }
8300+
8301+ // superblock and commit
8302+ write_superblock (cct, superblock, t);
8303+ t.register_on_commit (new C_OnMapCommit (this , start, last, m));
8304+ store->queue_transaction (
8305+ service.meta_ch ,
8306+ std::move (t));
8307+ service.publish_superblock (superblock);
8308+ }
8309+
8310+ /*
8311+ * For each added map which was sent in this MOSDMap [first, last]:
8312+ *
8313+ * 1) Check if a pool was deleted
8314+ * 2) For existing pools, check if pg_num was changed
8315+ * 3) Check if a pool was created
8316+ *
8317+ * Track all of the changes above in pg_num_history
8318+ */
8319+ void OSD::track_pools_and_pg_num_changes (const map<epoch_t ,OSDMapRef>& added_maps,
8320+ ObjectStore::Transaction& t,
8321+ epoch_t last)
8322+ {
82668323 OSDMapRef lastmap;
82678324 for (auto & [added_map_epoch, added_map] : added_maps) {
82688325 if (!lastmap) {
@@ -8310,47 +8367,6 @@ void OSD::handle_osd_map(MOSDMap *m)
83108367 lastmap = added_map;
83118368 }
83128369 pg_num_history.epoch = last;
8313- {
8314- bufferlist bl;
8315- ::encode (pg_num_history, bl);
8316- auto oid = make_pg_num_history_oid ();
8317- t.truncate (coll_t::meta (), oid, 0 ); // we don't need bytes left if new data
8318- // block is shorter than the previous
8319- // one. And better to trim them, e.g.
8320- // this allows to avoid csum eroors
8321- // when issuing overwrite
8322- // (which happens to be partial)
8323- // and original data is corrupted.
8324- // Another side effect is that the
8325- // superblock is not permanently
8326- // anchored to a fixed disk location
8327- // any more.
8328- t.write (coll_t::meta (), oid, 0 , bl.length (), bl);
8329- dout (20 ) << __func__ << " pg_num_history " << pg_num_history << dendl;
8330- }
8331-
8332- // record new purged_snaps
8333- if (superblock.purged_snaps_last == start - 1 ) {
8334- OSDriver osdriver{store.get (), service.meta_ch , make_purged_snaps_oid ()};
8335- SnapMapper::record_purged_snaps (
8336- cct,
8337- osdriver,
8338- osdriver.get_transaction (&t),
8339- purged_snaps);
8340- superblock.purged_snaps_last = last;
8341- } else {
8342- dout (10 ) << __func__ << " superblock purged_snaps_last is "
8343- << superblock.purged_snaps_last
8344- << " , not recording new purged_snaps" << dendl;
8345- }
8346-
8347- // superblock and commit
8348- write_superblock (cct, superblock, t);
8349- t.register_on_commit (new C_OnMapCommit (this , start, last, m));
8350- store->queue_transaction (
8351- service.meta_ch ,
8352- std::move (t));
8353- service.publish_superblock (superblock);
83548370}
83558371
83568372void OSD::_committed_osd_maps (epoch_t first, epoch_t last, MOSDMap *m)
0 commit comments