From: Jason Dillaman Date: Thu, 2 Apr 2020 18:50:37 +0000 (-0400) Subject: rbd-mirror: periodically poll image replayer status X-Git-Tag: wip-pdonnell-testing-20200918.022351~1584^2~5 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=133cce8af50653d147d7147fc4bc7269ad10b5e1;p=ceph-ci.git rbd-mirror: periodically poll image replayer status When metrics are incorporated, there might not be a forced status update if no new data is available to replicate. However, we will want the metrics to decrease over time. Signed-off-by: Jason Dillaman --- diff --git a/src/tools/rbd_mirror/ImageReplayer.cc b/src/tools/rbd_mirror/ImageReplayer.cc index dd74512dfd1..3123c973076 100644 --- a/src/tools/rbd_mirror/ImageReplayer.cc +++ b/src/tools/rbd_mirror/ImageReplayer.cc @@ -248,6 +248,7 @@ ImageReplayer::~ImageReplayer() ceph_assert(m_on_start_finish == nullptr); ceph_assert(m_on_stop_finish == nullptr); ceph_assert(m_bootstrap_request == nullptr); + ceph_assert(m_update_status_task == nullptr); delete m_replayer_listener; } @@ -446,6 +447,9 @@ void ImageReplayer::handle_start_replay(int r) { ceph_assert(m_state == STATE_STARTING); m_state = STATE_REPLAYING; std::swap(m_on_start_finish, on_finish); + + std::unique_lock timer_locker{m_threads->timer_lock}; + schedule_update_mirror_image_replay_status(); } update_mirror_image_status(true, boost::none); @@ -578,6 +582,7 @@ void ImageReplayer::on_stop_journal_replay(int r, const std::string &desc) m_state = STATE_STOPPING; } + cancel_update_mirror_image_replay_status(); set_state_description(r, desc); update_mirror_image_status(true, boost::none); shut_down(0); @@ -646,6 +651,60 @@ void ImageReplayer::print_status(Formatter *f) f->close_section(); } +template +void ImageReplayer::schedule_update_mirror_image_replay_status() { + ceph_assert(ceph_mutex_is_locked_by_me(m_lock)); + ceph_assert(ceph_mutex_is_locked_by_me(m_threads->timer_lock)); + if (m_state != STATE_REPLAYING) { + return; + } + + dout(10) << dendl; + + // periodically update the replaying status even if nothing changes + // so that we can adjust our performance stats + ceph_assert(m_update_status_task == nullptr); + m_update_status_task = create_context_callback< + ImageReplayer, + &ImageReplayer::handle_update_mirror_image_replay_status>(this); + m_threads->timer->add_event_after(10, m_update_status_task); +} + +template +void ImageReplayer::handle_update_mirror_image_replay_status(int r) { + dout(10) << dendl; + + auto ctx = new LambdaContext([this](int) { + update_mirror_image_status(false, boost::none); + + { + std::unique_lock locker{m_lock}; + std::unique_lock timer_locker{m_threads->timer_lock}; + ceph_assert(m_update_status_task != nullptr); + m_update_status_task = nullptr; + + schedule_update_mirror_image_replay_status(); + } + + m_in_flight_op_tracker.finish_op(); + }); + + m_in_flight_op_tracker.start_op(); + m_threads->work_queue->queue(ctx, 0); +} + +template +void ImageReplayer::cancel_update_mirror_image_replay_status() { + std::unique_lock timer_locker{m_threads->timer_lock}; + if (m_update_status_task != nullptr) { + dout(10) << dendl; + + if (m_threads->timer->cancel_event(m_update_status_task)) { + m_update_status_task = nullptr; + } + } +} + template void ImageReplayer::update_mirror_image_status( bool force, const OptionalState &opt_state) { diff --git a/src/tools/rbd_mirror/ImageReplayer.h b/src/tools/rbd_mirror/ImageReplayer.h index c9718e06b9c..493d38d9d28 100644 --- a/src/tools/rbd_mirror/ImageReplayer.h +++ b/src/tools/rbd_mirror/ImageReplayer.h @@ -221,6 +221,8 @@ private: AsyncOpTracker m_in_flight_op_tracker; + Context* m_update_status_task = nullptr; + static std::string to_string(const State state); bool is_stopped_() const { @@ -233,6 +235,10 @@ private: return (m_state == STATE_REPLAYING); } + void schedule_update_mirror_image_replay_status(); + void handle_update_mirror_image_replay_status(int r); + void cancel_update_mirror_image_replay_status(); + void update_mirror_image_status(bool force, const OptionalState &state); void set_mirror_image_status_update(bool force, const OptionalState &state); @@ -250,6 +256,7 @@ private: void register_admin_socket_hook(); void unregister_admin_socket_hook(); void reregister_admin_socket_hook(); + }; } // namespace mirror