From 810fdbf317df7978339df30f4bbb7f4ffca545d8 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Sun, 16 Jul 2017 16:13:41 -0400 Subject: [PATCH] rbd-mirror: service daemon attributes for instance replayer Signed-off-by: Jason Dillaman --- .../rbd_mirror/test_mock_InstanceReplayer.cc | 6 ++ src/tools/rbd_mirror/InstanceReplayer.cc | 60 ++++++++++++++----- src/tools/rbd_mirror/InstanceReplayer.h | 3 +- 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/src/test/rbd_mirror/test_mock_InstanceReplayer.cc b/src/test/rbd_mirror/test_mock_InstanceReplayer.cc index 9e786fc757042..cda56eb4c165d 100644 --- a/src/test/rbd_mirror/test_mock_InstanceReplayer.cc +++ b/src/test/rbd_mirror/test_mock_InstanceReplayer.cc @@ -9,6 +9,7 @@ #include "tools/rbd_mirror/InstanceReplayer.h" #include "tools/rbd_mirror/ServiceDaemon.h" #include "tools/rbd_mirror/Threads.h" +#include "tools/rbd_mirror/image_replayer/Types.h" namespace librbd { @@ -49,6 +50,9 @@ struct ImageDeleter { template<> struct ServiceDaemon { + MOCK_METHOD3(add_or_update_attribute, + void(int64_t, const std::string&, + const service_daemon::AttributeValue&)); }; template<> @@ -99,6 +103,8 @@ struct ImageReplayer { MOCK_METHOD0(is_running, bool()); MOCK_METHOD0(is_stopped, bool()); MOCK_METHOD0(is_blacklisted, bool()); + + MOCK_CONST_METHOD0(get_health_state, image_replayer::HealthState()); }; ImageReplayer* ImageReplayer::s_instance = nullptr; diff --git a/src/tools/rbd_mirror/InstanceReplayer.cc b/src/tools/rbd_mirror/InstanceReplayer.cc index 5dbddc16f6c60..a100a8f31ac4c 100644 --- a/src/tools/rbd_mirror/InstanceReplayer.cc +++ b/src/tools/rbd_mirror/InstanceReplayer.cc @@ -8,6 +8,7 @@ #include "librbd/Utils.h" #include "ImageReplayer.h" #include "InstanceReplayer.h" +#include "ServiceDaemon.h" #include "Threads.h" #define dout_context g_ceph_context @@ -19,6 +20,14 @@ namespace rbd { namespace mirror { +namespace { + +const std::string SERVICE_DAEMON_ASSIGNED_COUNT_KEY("image_assigned_count"); +const std::string SERVICE_DAEMON_WARNING_COUNT_KEY("image_warning_count"); +const std::string SERVICE_DAEMON_ERROR_COUNT_KEY("image_error_count"); + +} // anonymous namespace + using librbd::util::create_async_context_callback; using librbd::util::create_context_callback; @@ -345,25 +354,48 @@ void InstanceReplayer::start_image_replayer( } template -void InstanceReplayer::start_image_replayers() { +void InstanceReplayer::queue_start_image_replayers() { dout(20) << dendl; - Context *ctx = new FunctionContext( - [this] (int r) { - Mutex::Locker locker(m_lock); - m_async_op_tracker.finish_op(); - if (m_on_shut_down != nullptr) { - return; - } - for (auto &it : m_image_replayers) { - start_image_replayer(it.second); - } - }); - + Context *ctx = create_context_callback< + InstanceReplayer, &InstanceReplayer::start_image_replayers>(this); m_async_op_tracker.start_op(); m_threads->work_queue->queue(ctx, 0); } +template +void InstanceReplayer::start_image_replayers(int r) { + dout(20) << dendl; + + Mutex::Locker locker(m_lock); + if (m_on_shut_down != nullptr) { + return; + } + + size_t image_count = 0; + size_t warning_count = 0; + size_t error_count = 0; + for (auto &it : m_image_replayers) { + ++image_count; + auto health_state = it.second->get_health_state(); + if (health_state == image_replayer::HEALTH_STATE_WARNING) { + ++warning_count; + } else if (health_state == image_replayer::HEALTH_STATE_ERROR) { + ++error_count; + } + + start_image_replayer(it.second); + } + + m_service_daemon->add_or_update_attribute( + m_local_pool_id, SERVICE_DAEMON_ASSIGNED_COUNT_KEY, image_count); + m_service_daemon->add_or_update_attribute( + m_local_pool_id, SERVICE_DAEMON_WARNING_COUNT_KEY, warning_count); + m_service_daemon->add_or_update_attribute( + m_local_pool_id, SERVICE_DAEMON_ERROR_COUNT_KEY, error_count); + + m_async_op_tracker.finish_op(); +} template void InstanceReplayer::stop_image_replayer(ImageReplayer *image_replayer, @@ -483,7 +515,7 @@ void InstanceReplayer::schedule_image_state_check_task() { assert(m_threads->timer_lock.is_locked()); m_image_state_check_task = nullptr; schedule_image_state_check_task(); - start_image_replayers(); + queue_start_image_replayers(); }); int after = diff --git a/src/tools/rbd_mirror/InstanceReplayer.h b/src/tools/rbd_mirror/InstanceReplayer.h index ecd7d11f4a7cf..16618b84123da 100644 --- a/src/tools/rbd_mirror/InstanceReplayer.h +++ b/src/tools/rbd_mirror/InstanceReplayer.h @@ -130,7 +130,8 @@ private: void handle_wait_for_ops(int r); void start_image_replayer(ImageReplayer *image_replayer); - void start_image_replayers(); + void queue_start_image_replayers(); + void start_image_replayers(int r); void stop_image_replayer(ImageReplayer *image_replayer, Context *on_finish); -- 2.39.5