From 62f79cae1be75105d2dd4ba7e71f0639a2366626 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 4 Jan 2018 12:09:56 -0600 Subject: [PATCH] osd/PG: request scrub via a state machine event Continuing effort to make PG interactions event based. Signed-off-by: Sage Weil --- src/osd/OSD.cc | 66 +++++++++++++++++++++++++------------------------- src/osd/OSD.h | 1 - src/osd/PG.cc | 15 ++++++++++++ src/osd/PG.h | 24 +++++++++++++++--- 4 files changed, 68 insertions(+), 38 deletions(-) diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index de193d26bdbd7..5b188e1aec8f7 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -6800,20 +6800,6 @@ void OSD::_dispatch(Message *m) } } -void OSD::handle_pg_scrub(MOSDScrub *m, PG *pg) -{ - pg->lock(); - if (pg->is_primary()) { - pg->unreg_next_scrub(); - pg->scrubber.must_scrub = true; - pg->scrubber.must_deep_scrub = m->deep || m->repair; - pg->scrubber.must_repair = m->repair; - pg->reg_next_scrub(); - dout(10) << "marking " << *pg << " for scrub" << dendl; - } - pg->unlock(); -} - void OSD::handle_scrub(MOSDScrub *m) { dout(10) << "handle_scrub " << *m << dendl; @@ -6822,35 +6808,49 @@ void OSD::handle_scrub(MOSDScrub *m) return; } if (m->fsid != monc->get_fsid()) { - dout(0) << "handle_scrub fsid " << m->fsid << " != " << monc->get_fsid() << dendl; + dout(0) << "handle_scrub fsid " << m->fsid << " != " << monc->get_fsid() + << dendl; m->put(); return; } - RWLock::RLocker l(pg_map_lock); - if (m->scrub_pgs.empty()) { - for (ceph::unordered_map::iterator p = pg_map.begin(); - p != pg_map.end(); - ++p) { - if (p->second->is_deleted()) { - continue; + vector spgs; + { + RWLock::RLocker l(pg_map_lock); + if (m->scrub_pgs.empty()) { + for (ceph::unordered_map::iterator p = pg_map.begin(); + p != pg_map.end(); + ++p) { + if (p->second->is_deleted()) { + continue; + } + spgs.push_back(p->second->get_pgid()); } - handle_pg_scrub(m, p->second); - } - } else { - for (vector::iterator p = m->scrub_pgs.begin(); - p != m->scrub_pgs.end(); - ++p) { - spg_t pcand; - if (osdmap->get_primary_shard(*p, &pcand)) { - auto pg_map_entry = pg_map.find(pcand); - if (pg_map_entry != pg_map.end()) { - handle_pg_scrub(m, pg_map_entry->second); + } else { + for (vector::iterator p = m->scrub_pgs.begin(); + p != m->scrub_pgs.end(); + ++p) { + spg_t pcand; + if (osdmap->get_primary_shard(*p, &pcand)) { + auto pg_map_entry = pg_map.find(pcand); + if (pg_map_entry != pg_map.end()) { + spgs.push_back(pcand); + } } } } } + for (auto pgid : spgs) { + enqueue_peering_evt( + pgid, + PGPeeringEventRef( + std::make_shared( + get_osdmap()->get_epoch(), + get_osdmap()->get_epoch(), + PG::RequestScrub(m->deep, m->repair)))); + } + m->put(); } diff --git a/src/osd/OSD.h b/src/osd/OSD.h index 6e8c5897ec6ee..ff02231e90078 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -2245,7 +2245,6 @@ private: ObjectStore *store, uuid_d& cluster_fsid, uuid_d& osd_fsid, int whoami); - void handle_pg_scrub(struct MOSDScrub *m, PG* pg); void handle_scrub(struct MOSDScrub *m); void handle_osd_ping(class MOSDPing *m); diff --git a/src/osd/PG.cc b/src/osd/PG.cc index e9b18d03dae56..0721d747d7586 100644 --- a/src/osd/PG.cc +++ b/src/osd/PG.cc @@ -6844,6 +6844,21 @@ boost::statechart::result PG::RecoveryState::Primary::react( return discard_event(); } +boost::statechart::result PG::RecoveryState::Primary::react( + const RequestScrub& evt) +{ + PG *pg = context< RecoveryMachine >().pg; + if (pg->is_primary()) { + pg->unreg_next_scrub(); + pg->scrubber.must_scrub = true; + pg->scrubber.must_deep_scrub = evt.deep || evt.repair; + pg->scrubber.must_repair = evt.repair; + pg->reg_next_scrub(); + ldout(pg->cct,10) << "marking for scrub" << dendl; + } + return discard_event(); +} + boost::statechart::result PG::RecoveryState::Primary::react( const SetForceBackfill&) { diff --git a/src/osd/PG.h b/src/osd/PG.h index aa5406527509b..5b5429a7fa4d5 100644 --- a/src/osd/PG.h +++ b/src/osd/PG.h @@ -1848,6 +1848,17 @@ public: *out << "UnfoundRecovery"; } }; + + struct RequestScrub : boost::statechart::event { + bool deep; + bool repair; + explicit RequestScrub(bool d, bool r) : deep(d), repair(r) {} + void print(std::ostream *out) const { + *out << "RequestScrub(" << (deep ? "deep" : "shallow") + << (repair ? " repair" : ""); + } + }; + protected: TrivialEvent(Initialize) TrivialEvent(GotInfo) @@ -2063,13 +2074,16 @@ protected: typedef boost::mpl::list < boost::statechart::custom_reaction< QueryState >, boost::statechart::custom_reaction< AdvMap >, - boost::statechart::custom_reaction< NullEvt >, boost::statechart::custom_reaction< IntervalFlush >, - boost::statechart::transition< boost::statechart::event_base, Crashed >, + // ignored + boost::statechart::custom_reaction< NullEvt >, boost::statechart::custom_reaction, boost::statechart::custom_reaction, boost::statechart::custom_reaction, - boost::statechart::custom_reaction + boost::statechart::custom_reaction, + boost::statechart::custom_reaction, + // crash + boost::statechart::transition< boost::statechart::event_base, Crashed > > reactions; boost::statechart::result react(const QueryState& q); boost::statechart::result react(const AdvMap&); @@ -2108,7 +2122,8 @@ protected: boost::statechart::custom_reaction, boost::statechart::custom_reaction, boost::statechart::custom_reaction, - boost::statechart::custom_reaction + boost::statechart::custom_reaction, + boost::statechart::custom_reaction > reactions; boost::statechart::result react(const ActMap&); boost::statechart::result react(const MNotifyRec&); @@ -2116,6 +2131,7 @@ protected: boost::statechart::result react(const UnsetForceRecovery&); boost::statechart::result react(const SetForceBackfill&); boost::statechart::result react(const UnsetForceBackfill&); + boost::statechart::result react(const RequestScrub&); }; struct WaitActingChange : boost::statechart::state< WaitActingChange, Primary>, -- 2.39.5