2424#define dout_context cct
2525#define dout_subsys ceph_subsys_osd
2626#undef dout_prefix
27- #define dout_prefix *_dout << " snap_mapper. "
27+ #define dout_prefix *_dout << " snap_mapper "
2828
2929using std::make_pair;
3030using std::map;
@@ -205,6 +205,20 @@ int OSDriver::get_next_or_current(
205205}
206206#endif // WITH_SEASTAR
207207
208+ SnapMapper::SnapMapper (
209+ CephContext* cct,
210+ MapCacher::StoreDriver<std::string, ceph::buffer::list> *driver,
211+ uint32_t match, // /< [in] pgid
212+ uint32_t bits, // /< [in] current split bits
213+ int64_t pool, // /< [in] pool
214+ shard_id_t shard // /< [in] shard
215+ )
216+ : cct(cct), backend(driver), mask_bits(bits), match(match), pool(pool),
217+ shard(shard), shard_prefix(make_shard_prefix(shard)) {
218+ dout (10 ) << *this << __func__ << dendl;
219+ update_bits (mask_bits);
220+ }
221+
208222string SnapMapper::get_prefix (int64_t pool, snapid_t snap)
209223{
210224 static_assert (sizeof (pool) == 8 , " assumed by the formatting code" );
@@ -483,13 +497,31 @@ void SnapMapper::set_snaps(
483497 backend.set_keys (to_set, t);
484498}
485499
500+ void SnapMapper::update_bits (
501+ uint32_t new_bits) // /< [in] new split bits
502+ {
503+ dout (20 ) << *this << __func__ << " new_bits: " << new_bits << dendl;
504+ mask_bits = new_bits;
505+ std::set<std::string> _prefixes = hobject_t::get_prefixes (
506+ mask_bits,
507+ match,
508+ pool);
509+ prefixes.clear ();
510+ for (auto i = _prefixes.begin (); i != _prefixes.end (); ++i) {
511+ prefixes.insert (shard_prefix + *i);
512+ }
513+ dout (20 ) << *this <<__func__ << " prefix updated" << dendl;
514+
515+ reset_prefix_itr (CEPH_NOSNAP, " update_bits" );
516+ }
517+
486518int SnapMapper::update_snaps (
487519 const hobject_t &oid,
488520 const set<snapid_t > &new_snaps,
489521 const set<snapid_t > *old_snaps_check,
490522 MapCacher::Transaction<std::string, ceph::buffer::list> *t)
491523{
492- dout (20 ) << __func__ << " " << oid << " " << new_snaps
524+ dout (20 ) << * this << __func__ << " " << oid << " " << new_snaps
493525 << " was " << (old_snaps_check ? *old_snaps_check : set<snapid_t >())
494526 << dendl;
495527 ceph_assert (check (oid));
@@ -536,7 +568,7 @@ void SnapMapper::add_oid(
536568 object_snaps out;
537569 int r = get_snaps (oid, &out);
538570 if (r != -ENOENT) {
539- derr << __func__ << " found existing snaps mapped on " << oid
571+ derr << * this << __func__ << " found existing snaps mapped on " << oid
540572 << " , removing" << dendl;
541573 ceph_assert (!cct->_conf ->osd_debug_verify_snaps );
542574 remove_oid (oid, t);
@@ -554,7 +586,7 @@ void SnapMapper::add_oid(
554586 }
555587 if (g_conf ()->subsys .should_gather <ceph_subsys_osd, 20 >()) {
556588 for (auto & i : to_add) {
557- dout (20 ) << __func__ << " set " << i.first << dendl;
589+ dout (20 ) << * this << __func__ << " set " << i.first << dendl;
558590 }
559591 }
560592 backend.set_keys (to_add, t);
@@ -564,17 +596,17 @@ void SnapMapper::add_oid(
564596void SnapMapper::reset_prefix_itr (snapid_t snap, const char *s)
565597{
566598 if (prefix_itr_snap == CEPH_NOSNAP) {
567- dout (10 ) << __func__ << " ::from <CEPH_NOSNAP> to <" << snap << " > ::" << s << dendl;
599+ dout (10 ) << * this << __func__ << " ::from <CEPH_NOSNAP> to <" << snap << " > ::" << s << dendl;
568600 }
569601 else if (snap == CEPH_NOSNAP) {
570- dout (10 ) << __func__ << " ::from <" << prefix_itr_snap << " > to <CEPH_NOSNAP> ::" << s << dendl;
602+ dout (10 ) << * this << __func__ << " ::from <" << prefix_itr_snap << " > to <CEPH_NOSNAP> ::" << s << dendl;
571603 }
572604 else if (prefix_itr_snap == snap) {
573- dout (10 ) << __func__ << " ::with the same snapid <" << snap << " > ::" << s << dendl;
605+ dout (10 ) << * this << __func__ << " ::with the same snapid <" << snap << " > ::" << s << dendl;
574606 }
575607 else {
576608 // This is unexpected!!
577- dout (10 ) << __func__ << " ::from <" << prefix_itr_snap << " > to <" << snap << " > ::" << s << dendl;
609+ dout (10 ) << * this << __func__ << " ::from <" << prefix_itr_snap << " > to <" << snap << " > ::" << s << dendl;
578610 }
579611 prefix_itr_snap = snap;
580612 prefix_itr = prefixes.begin ();
@@ -594,7 +626,7 @@ vector<hobject_t> SnapMapper::get_objects_by_prefixes(
594626 pair<string, ceph::buffer::list> next;
595627 // access RocksDB (an expensive operation!)
596628 int r = backend.get_next (pos, &next);
597- dout (20 ) << __func__ << " get_next(" << pos << " ) returns " << r
629+ dout (20 ) << * this << __func__ << " get_next(" << pos << " ) returns " << r
598630 << " " << next.first << dendl;
599631 if (r != 0 ) {
600632 return out; // Done
@@ -611,18 +643,18 @@ vector<hobject_t> SnapMapper::get_objects_by_prefixes(
611643 break ; // Done with this prefix
612644 }
613645
614- dout (20 ) << __func__ << " " << next.first << dendl;
646+ dout (20 ) << * this << __func__ << " found " << next.first << dendl;
615647 pair<snapid_t , hobject_t > next_decoded (from_raw (next));
616648 ceph_assert (next_decoded.first == snap);
617649 ceph_assert (check (next_decoded.second ));
618-
619650 out.push_back (next_decoded.second );
651+
620652 pos = next.first ;
621653 }
622654
623655 if (out.size () >= max) {
624- dout (20 ) << fmt::format (" {}: reached max of: {} returning" ,
625- __func__, out.size ())
656+ dout (20 ) << * this << fmt::format (" {}: reached max of: {} returning" ,
657+ __func__, out.size ())
626658 << dendl;
627659 return out;
628660 }
@@ -634,7 +666,7 @@ std::optional<vector<hobject_t>> SnapMapper::get_next_objects_to_trim(
634666 snapid_t snap,
635667 unsigned max)
636668{
637- dout (20 ) << __func__ << " :: snapid=" << snap << dendl;
669+ dout (20 ) << * this << __func__ << " snapid=" << snap << dendl;
638670
639671 // if max would be 0, we return ENOENT and the caller would mistakenly
640672 // trim the snaptrim queue
@@ -664,7 +696,7 @@ std::optional<vector<hobject_t>> SnapMapper::get_next_objects_to_trim(
664696 objs = get_objects_by_prefixes (snap, max);
665697
666698 if (unlikely (objs.size () > 0 )) {
667- derr << __func__ << " :: New Clone-Objects were added to Snap " << snap
699+ derr << * this << __func__ << " New Clone-Objects were added to Snap " << snap
668700 << " after trimming was started" << dendl;
669701 }
670702 reset_prefix_itr (CEPH_NOSNAP, " Trim was completed successfully" );
@@ -682,7 +714,7 @@ int SnapMapper::remove_oid(
682714 const hobject_t &oid,
683715 MapCacher::Transaction<std::string, ceph::buffer::list> *t)
684716{
685- dout (20 ) << __func__ << " " << oid << dendl;
717+ dout (20 ) << * this << __func__ << " " << oid << dendl;
686718 ceph_assert (check (oid));
687719 return _remove_oid (oid, t);
688720}
@@ -691,7 +723,7 @@ int SnapMapper::_remove_oid(
691723 const hobject_t &oid,
692724 MapCacher::Transaction<std::string, ceph::buffer::list> *t)
693725{
694- dout (20 ) << __func__ << " " << oid << dendl;
726+ dout (20 ) << * this << __func__ << " " << oid << dendl;
695727 object_snaps out;
696728 int r = get_snaps (oid, &out);
697729 if (r < 0 )
@@ -707,7 +739,7 @@ int SnapMapper::_remove_oid(
707739 }
708740 if (g_conf ()->subsys .should_gather <ceph_subsys_osd, 20 >()) {
709741 for (auto & i : to_remove) {
710- dout (20 ) << __func__ << " ::rm " << i << dendl;
742+ dout (20 ) << * this << __func__ << " ::rm " << i << dendl;
711743 }
712744 }
713745 backend.remove_keys (to_remove, t);
@@ -739,7 +771,7 @@ void SnapMapper::update_snap_map(
739771 i.soid ,
740772 _t);
741773 if (r)
742- dout (20 ) << __func__ << " remove_oid " << i.soid << " failed with " << r << dendl;
774+ dout (20 ) << * this << __func__ << " remove_oid " << i.soid << " failed with " << r << dendl;
743775 // On removal tolerate missing key corruption
744776 ceph_assert (r == 0 || r == -ENOENT);
745777 } else if (i.is_update ()) {
@@ -750,7 +782,7 @@ void SnapMapper::update_snap_map(
750782 try {
751783 decode (snaps, p);
752784 } catch (...) {
753- dout (20 ) << __func__ << " decode snaps failure on " << i << dendl;
785+ dout (20 ) << * this << __func__ << " decode snaps failure on " << i << dendl;
754786 snaps.clear ();
755787 }
756788 std::set<snapid_t > _snaps (snaps.begin (), snaps.end ());
0 commit comments