From 49520156414cb0667e8edd6ea4b31462e7cb7752 Mon Sep 17 00:00:00 2001 From: Venky Shankar Date: Thu, 25 Jul 2019 09:16:18 -0400 Subject: [PATCH] mds: send scrub state changes to cluster log. ... also log new and completed scrubs. Signed-off-by: Venky Shankar --- src/mds/MDSRank.cc | 2 +- src/mds/ScrubStack.cc | 28 ++++++++++++++++++++++------ src/mds/ScrubStack.h | 26 +++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/mds/MDSRank.cc b/src/mds/MDSRank.cc index 975f9d095e0..46112b9771f 100644 --- a/src/mds/MDSRank.cc +++ b/src/mds/MDSRank.cc @@ -529,7 +529,7 @@ MDSRank::MDSRank( mdlog = new MDLog(this); balancer = new MDBalancer(this, messenger, monc); - scrubstack = new ScrubStack(mdcache, finisher); + scrubstack = new ScrubStack(mdcache, clog, finisher); inotable = new InoTable(this); snapserver = new SnapServer(this, monc); diff --git a/src/mds/ScrubStack.cc b/src/mds/ScrubStack.cc index 846960088cc..e73d441e3a7 100644 --- a/src/mds/ScrubStack.cc +++ b/src/mds/ScrubStack.cc @@ -480,6 +480,7 @@ void ScrubStack::_validate_inode_done(CInode *in, int r, if (in == header->get_origin()) { scrub_origins.erase(in); + clog_scrub_summary(in); if (!header->get_recursive()) { if (r >= 0) { // we got into the scrubbing dump it result.dump(&(header->get_formatter())); @@ -512,6 +513,7 @@ void ScrubStack::set_state(State next_state) { dout(20) << __func__ << ", from state=" << state << ", to state=" << next_state << dendl; state = next_state; + clog_scrub_summary(); } } @@ -568,9 +570,7 @@ std::string_view ScrubStack::scrub_summary() { *cs << ","; } - std::string path; - (*inode)->make_path_string(path, true); - *cs << (path.empty() ? "/" : path.c_str()); + *cs << scrub_inode_path(*inode); } *cs << "]"; } @@ -619,9 +619,7 @@ void ScrubStack::scrub_status(Formatter *f) { std::string tag(header->get_tag()); f->open_object_section(tag.c_str()); // scrub id - std::string path; - inode->make_path_string(path, true); - f->dump_string("path", path.empty() ? "/" : path.c_str()); + f->dump_string("path", scrub_inode_path(inode)); std::stringstream optss; if (header->get_recursive()) { @@ -657,6 +655,7 @@ void ScrubStack::abort_pending_scrubs() { CInode *in = *inode; if (in == in->scrub_info()->header->get_origin()) { scrub_origins.erase(in); + clog_scrub_summary(in); } MDSContext *ctx = nullptr; @@ -735,3 +734,20 @@ bool ScrubStack::scrub_resume() { return r; } + +// send current scrub summary to cluster log +void ScrubStack::clog_scrub_summary(CInode *in) { + if (in) { + std::string what; + if (clear_inode_stack) { + what = "aborted"; + } else if (scrub_origins.count(in)) { + what = "queued"; + } else { + what = "completed"; + } + clog->info() << "scrub " << what << " for path: " << scrub_inode_path(in); + } + + clog->info() << "scrub summary: " << scrub_summary(); +} diff --git a/src/mds/ScrubStack.h b/src/mds/ScrubStack.h index ad2393af23c..691dd8a1c7e 100644 --- a/src/mds/ScrubStack.h +++ b/src/mds/ScrubStack.h @@ -21,6 +21,7 @@ #include "MDSContext.h" #include "ScrubHeader.h" +#include "common/LogClient.h" #include "include/elist.h" class MDCache; @@ -28,6 +29,9 @@ class Finisher; class ScrubStack { protected: + // reference to global cluster log client + LogChannelRef &clog; + /// A finisher needed so that we don't re-enter kick_off_scrubs Finisher *finisher; @@ -57,7 +61,8 @@ protected: public: MDCache *mdcache; - ScrubStack(MDCache *mdc, Finisher *finisher_) : + ScrubStack(MDCache *mdc, LogChannelRef &clog, Finisher *finisher_) : + clog(clog), finisher(finisher_), inode_stack(member_offset(CInode, item_scrub)), scrubs_in_progress(0), @@ -81,6 +86,7 @@ public: MDSContext *on_finish) { enqueue_inode(in, header, on_finish, true); scrub_origins.emplace(in); + clog_scrub_summary(in); } /** Like enqueue_inode_top, but we wait for all pending scrubs before * starting this one. @@ -89,6 +95,7 @@ public: MDSContext *on_finish) { enqueue_inode(in, header, on_finish, false); scrub_origins.emplace(in); + clog_scrub_summary(in); } /** @@ -275,6 +282,23 @@ private: * Completion context is complete with -ECANCELED. */ void abort_pending_scrubs(); + + /** + * Return path for a given inode. + * @param in inode to make path entry. + */ + std::string scrub_inode_path(CInode *in) { + std::string path; + in->make_path_string(path, true); + return (path.empty() ? "/" : path.c_str()); + } + + /** + * Send scrub information (queued/finished scrub path and summary) + * to cluster log. + * @param in inode for which scrub has been queued or finished. + */ + void clog_scrub_summary(CInode *in=nullptr); }; #endif /* SCRUBSTACK_H_ */ -- 2.47.3