From ce58c88158381e252ffa432ff855a01570cc98dd Mon Sep 17 00:00:00 2001 From: Ronen Friedman Date: Mon, 23 Sep 2024 05:15:57 -0500 Subject: [PATCH] osd/scrub: add dout() capability to the ScrubStore now that the ScrubSTore object is directly created by the scrubber, (and has a lifetime that does not extend beyond the scrubber object), we can add the same dout() mechanism used by the other scrubber sub-objects. Note: that mechanism will be changed shortly, so that the sub-objects would use one prefix() creator supplied by the Scrubber object. Signed-off-by: Ronen Friedman --- src/osd/scrubber/ScrubStore.cc | 50 +++++++++++++++++++++++++++++---- src/osd/scrubber/ScrubStore.h | 20 +++++++++---- src/osd/scrubber/pg_scrubber.cc | 2 +- 3 files changed, 61 insertions(+), 11 deletions(-) diff --git a/src/osd/scrubber/ScrubStore.cc b/src/osd/scrubber/ScrubStore.cc index 0c36be6b66b02..dd141d1c38ca4 100644 --- a/src/osd/scrubber/ScrubStore.cc +++ b/src/osd/scrubber/ScrubStore.cc @@ -1,11 +1,13 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab -#include "ScrubStore.h" +#include "./ScrubStore.h" #include "osd/osd_types.h" #include "common/scrub_types.h" #include "include/rados/rados_types.hpp" +#include "pg_scrubber.h" + using std::ostringstream; using std::string; using std::vector; @@ -95,16 +97,31 @@ string last_snap_key(int64_t pool) hoid.build_hash_cache(); return "SCRUB_SS_" + hoid.to_str(); } + +} // namespace + +#undef dout_context +#define dout_context (m_scrubber.get_pg_cct()) +#define dout_subsys ceph_subsys_osd +#undef dout_prefix +#define dout_prefix _prefix_fn(_dout, this, __func__) + +template +static std::ostream& _prefix_fn(std::ostream* _dout, T* t, std::string fn = "") +{ + return t->gen_prefix(*_dout, fn); } namespace Scrub { Store::Store( + PgScrubber& scrubber, ObjectStore& osd_store, ObjectStore::Transaction* t, const spg_t& pgid, const coll_t& coll) - : object_store{osd_store} + : m_scrubber{scrubber} + , object_store{osd_store} , coll{coll} { ceph_assert(t); @@ -120,6 +137,18 @@ Store::~Store() ceph_assert(!errors_db || errors_db->results.empty()); } + +std::ostream& Store::gen_prefix(std::ostream& out, std::string_view fn) const +{ + if (fn.starts_with("operator")) { + // it's a lambda, and __func__ is not available + return m_scrubber.gen_prefix(out) << "Store::"; + } else { + return m_scrubber.gen_prefix(out) << "Store::" << fn << ": "; + } +} + + void Store::add_error(int64_t pool, const inconsistent_obj_wrapper& e) { add_object_error(pool, e); @@ -163,8 +192,11 @@ void Store::flush(ObjectStore::Transaction* t) void Store::clear_level_db( ObjectStore::Transaction* t, - at_level_t& db) + at_level_t& db, + std::string_view db_name) { + dout(20) << fmt::format("removing (omap) entries for {} error DB", db_name) + << dendl; // easiest way to guarantee that the object representing the DB exists t->touch(coll, db.errors_hoid); @@ -176,19 +208,27 @@ void Store::clear_level_db( } -void Store::reinit(ObjectStore::Transaction* t, [[maybe_unused]] scrub_level_t level) +void Store::reinit( + ObjectStore::Transaction* t, + [[maybe_unused]] scrub_level_t level) { + dout(20) << fmt::format( + "re-initializing the Scrub::Store (for {} scrub)", + (level == scrub_level_t::deep ? "deep" : "shallow")) + << dendl; + // Note: only one caller, and it creates the transaction passed to reinit(). // No need to assert on 't' if (errors_db) { - clear_level_db(t, *errors_db); + clear_level_db(t, *errors_db, "scrub"); } } void Store::cleanup(ObjectStore::Transaction* t) { + dout(20) << "discarding error DBs" << dendl; ceph_assert(t); if (errors_db) t->remove(coll, errors_db->errors_hoid); diff --git a/src/osd/scrubber/ScrubStore.h b/src/osd/scrubber/ScrubStore.h index 600905e85e8a2..a83841e2cfbb2 100644 --- a/src/osd/scrubber/ScrubStore.h +++ b/src/osd/scrubber/ScrubStore.h @@ -14,6 +14,7 @@ struct object_id_t; struct inconsistent_obj_wrapper; struct inconsistent_snapset_wrapper; +class PgScrubber; namespace Scrub { @@ -21,10 +22,12 @@ class Store { public: ~Store(); - Store(ObjectStore& osd_store, - ObjectStore::Transaction* t, - const spg_t& pgid, - const coll_t& coll); + Store( + PgScrubber& scrubber, + ObjectStore& osd_store, + ObjectStore::Transaction* t, + const spg_t& pgid, + const coll_t& coll); /// mark down detected errors, either shallow or deep @@ -64,6 +67,8 @@ class Store { const librados::object_id_t& start, uint64_t max_return) const; + std::ostream& gen_prefix(std::ostream& out, std::string_view fn) const; + private: /** * at_level_t @@ -95,6 +100,10 @@ class Store { std::vector get_errors(const std::string& start, const std::string& end, uint64_t max_return) const; + + /// access to the owning Scrubber object, for logging mostly + PgScrubber& m_scrubber; + /// the OSD's storage backend ObjectStore& object_store; @@ -116,7 +125,8 @@ class Store { */ void clear_level_db( ObjectStore::Transaction* t, - at_level_t& db); + at_level_t& db, + std::string_view db_name); }; } // namespace Scrub diff --git a/src/osd/scrubber/pg_scrubber.cc b/src/osd/scrubber/pg_scrubber.cc index a085481f477ac..81093666f91c8 100644 --- a/src/osd/scrubber/pg_scrubber.cc +++ b/src/osd/scrubber/pg_scrubber.cc @@ -1223,7 +1223,7 @@ void PgScrubber::reinit_scrub_store() } else { dout(10) << __func__ << " creating new store" << dendl; m_store = std::make_unique( - *m_pg->osd->store, &t, m_pg->info.pgid, m_pg->coll); + *this, *m_pg->osd->store, &t, m_pg->info.pgid, m_pg->coll); } // regardless of whether the ScrubStore object was recreated or reused, we need to -- 2.39.5