@@ -89,23 +89,18 @@ std::ostream& ScrubMachine::gen_prefix(std::ostream& out) const
8989
9090ceph::timespan ScrubMachine::get_time_scrubbing () const
9191{
92- // note: the state_cast does not work in the Session ctor
93- auto session = state_cast<const Session*>();
94- if (!session) {
95- dout (20 ) << fmt::format (" {}: not in session" , __func__) << dendl;
92+ if (!m_session_started_at) {
93+ dout (30 ) << fmt::format (" {}: no session_start time" , __func__) << dendl;
9694 return ceph::timespan{};
9795 }
9896
99- if (session && session-> m_session_started_at != ScrubTimePoint{}) {
100- dout (20 ) << fmt::format (
101- " {}: session_started_at: {} d :{}" , __func__,
102- session-> m_session_started_at ,
103- ScrubClock::now () - session-> m_session_started_at )
97+ const auto dur = ScrubClock::now () - *m_session_started_at;
98+ dout (20 ) << fmt::format (
99+ " {}: session_started_at: {} duration :{}ms " , __func__,
100+ * m_session_started_at,
101+ ceil<milliseconds>(dur). count () )
104102 << dendl;
105- return ScrubClock::now () - session->m_session_started_at ;
106- }
107- dout (30 ) << fmt::format (" {}: no session_start time" , __func__) << dendl;
108- return ceph::timespan{};
103+ return dur;
109104}
110105
111106std::optional<pg_scrubbing_status_t > ScrubMachine::get_reservation_status ()
@@ -196,6 +191,8 @@ Session::Session(my_context ctx)
196191 dout (10 ) << " -- state -->> PrimaryActive/Session" << dendl;
197192 DECLARE_LOCALS; // 'scrbr' & 'pg_id' aliases
198193
194+ machine.m_session_started_at = ScrubClock::now ();
195+
199196 m_perf_set = scrbr->get_labeled_counters ();
200197 m_osd_counters = scrbr->get_osd_perf_counters ();
201198 m_counters_idx = &scrbr->get_unlabeled_counters ();
@@ -206,6 +203,7 @@ Session::~Session()
206203{
207204 DECLARE_LOCALS; // 'scrbr' & 'pg_id' aliases
208205 m_reservations.reset ();
206+ machine.m_session_started_at .reset ();
209207
210208 // note the interaction between clearing the 'queued' flag and two
211209 // other states: the snap-mapper and the scrubber internal state.
@@ -337,12 +335,12 @@ ActiveScrubbing::~ActiveScrubbing()
337335
338336 // if the begin-time stamp was not set 'off' (as done if the scrubbing
339337 // completed successfully), we use it now to set the 'failed scrub' duration.
340- if (session .m_session_started_at != ScrubTimePoint{} ) {
338+ if (machine .m_session_started_at ) {
341339 // delay the next invocation of the scrubber on this target
342340 scrbr->on_mid_scrub_abort (
343341 session.m_abort_reason .value_or (Scrub::delay_cause_t ::aborted));
344342
345- auto logged_duration = ScrubClock::now () - session .m_session_started_at ;
343+ auto logged_duration = ScrubClock::now () - *machine .m_session_started_at ;
346344 session.m_osd_counters ->tinc (session.m_counters_idx ->failed_elapsed ,
347345 logged_duration);
348346 session.m_osd_counters ->inc (session.m_counters_idx ->failed_cnt );
@@ -723,8 +721,8 @@ sc::result WaitDigestUpdate::react(const ScrubFinished&)
723721
724722 // set the 'scrub duration'
725723 auto duration = machine.get_time_scrubbing ();
726- scrbr->set_scrub_duration (duration_cast <milliseconds>(duration));
727- session .m_session_started_at = ScrubTimePoint{} ;
724+ scrbr->set_scrub_duration (ceil <milliseconds>(duration));
725+ machine .m_session_started_at . reset () ;
728726 session.m_osd_counters ->tinc (
729727 session.m_counters_idx ->successful_elapsed , duration);
730728
0 commit comments