Skip to content

Commit 64e349a

Browse files
Merge pull request ceph#61365 from Matan-B/wip-matanb-snapmapper-logs
osd/SnapMapper: Improve logging
2 parents cfadbfe + 4d18b13 commit 64e349a

File tree

3 files changed

+68
-38
lines changed

3 files changed

+68
-38
lines changed

src/osd/PG.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,8 @@ void PG::finish_recovery_op(const hobject_t& soid, bool dequeue)
514514

515515
void PG::split_into(pg_t child_pgid, PG *child, unsigned split_bits)
516516
{
517+
dout(10) << __func__ << " split_bits " << split_bits << dendl;
518+
517519
recovery_state.split_into(child_pgid, &child->recovery_state, split_bits);
518520

519521
child->update_snap_mapper_bits(split_bits);

src/osd/SnapMapper.cc

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
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

2929
using std::make_pair;
3030
using 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+
208222
string 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+
486518
int 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(
564596
void 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());

src/osd/SnapMapper.h

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ class OSDriver : public MapCacher::StoreDriver<std::string, ceph::buffer::list>
122122
class SnapMapper : public Scrub::SnapMapReaderI {
123123
friend class MapperVerifier; // unit-test support
124124
friend class DirectMapper; // unit-test support
125+
friend std::ostream& operator<<(std::ostream &lhs, const SnapMapper &sm);
126+
125127
public:
126128
CephContext* cct;
127129
struct object_snaps {
@@ -329,28 +331,12 @@ class SnapMapper : public Scrub::SnapMapReaderI {
329331
uint32_t bits, ///< [in] current split bits
330332
int64_t pool, ///< [in] pool
331333
shard_id_t shard ///< [in] shard
332-
)
333-
: cct(cct), backend(driver), mask_bits(bits), match(match), pool(pool),
334-
shard(shard), shard_prefix(make_shard_prefix(shard)) {
335-
update_bits(mask_bits);
336-
}
334+
);
337335

338336
/// Update bits in case of pg split or merge
339337
void update_bits(
340338
uint32_t new_bits ///< [in] new split bits
341-
) {
342-
mask_bits = new_bits;
343-
std::set<std::string> _prefixes = hobject_t::get_prefixes(
344-
mask_bits,
345-
match,
346-
pool);
347-
prefixes.clear();
348-
for (auto i = _prefixes.begin(); i != _prefixes.end(); ++i) {
349-
prefixes.insert(shard_prefix + *i);
350-
}
351-
352-
reset_prefix_itr(CEPH_NOSNAP, "update_bits");
353-
}
339+
);
354340

355341
const std::set<std::string>::iterator get_prefix_itr() {
356342
return prefix_itr;
@@ -414,4 +400,14 @@ class SnapMapper : public Scrub::SnapMapReaderI {
414400
WRITE_CLASS_ENCODER(SnapMapper::object_snaps)
415401
WRITE_CLASS_ENCODER(SnapMapper::Mapping)
416402

403+
inline std::ostream& operator<<(std::ostream& os, const SnapMapper& sm)
404+
{
405+
os << fmt::format(" [pg_id:{:x}, match:{}, mask_bits:{}, "
406+
"last_key_checked:{}, pool:{}, shard:{}, "
407+
"shard_prefix: {}, prefixes: {}] ",
408+
sm.match, sm.match, sm.mask_bits, sm.last_key_checked,
409+
sm.pool, sm.shard.id, sm.shard_prefix, sm.prefixes);
410+
return os;
411+
}
412+
417413
#endif

0 commit comments

Comments
 (0)