]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: service daemon attributes for instance replayer
authorJason Dillaman <dillaman@redhat.com>
Sun, 16 Jul 2017 20:13:41 +0000 (16:13 -0400)
committerJason Dillaman <dillaman@redhat.com>
Tue, 18 Jul 2017 14:28:14 +0000 (10:28 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/test/rbd_mirror/test_mock_InstanceReplayer.cc
src/tools/rbd_mirror/InstanceReplayer.cc
src/tools/rbd_mirror/InstanceReplayer.h

index 9e786fc7570425b86aca0cba37c422ea0ac9fe19..cda56eb4c165da6f3a96c1124726e17a84433bfe 100644 (file)
@@ -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<librbd::MockTestImageCtx> {
 
 template<>
 struct ServiceDaemon<librbd::MockTestImageCtx> {
+  MOCK_METHOD3(add_or_update_attribute,
+               void(int64_t, const std::string&,
+                    const service_daemon::AttributeValue&));
 };
 
 template<>
@@ -99,6 +103,8 @@ struct ImageReplayer<librbd::MockTestImageCtx> {
   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<librbd::MockTestImageCtx>* ImageReplayer<librbd::MockTestImageCtx>::s_instance = nullptr;
index 5dbddc16f6c606cb3ee860f5e4888889f48572d0..a100a8f31ac4c964abfb73234ffc23f1d9d4c7de 100644 (file)
@@ -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
 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<I>::start_image_replayer(
 }
 
 template <typename I>
-void InstanceReplayer<I>::start_image_replayers() {
+void InstanceReplayer<I>::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<I>::start_image_replayers>(this);
   m_async_op_tracker.start_op();
   m_threads->work_queue->queue(ctx, 0);
 }
 
+template <typename I>
+void InstanceReplayer<I>::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 <typename I>
 void InstanceReplayer<I>::stop_image_replayer(ImageReplayer<I> *image_replayer,
@@ -483,7 +515,7 @@ void InstanceReplayer<I>::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 =
index ecd7d11f4a7cf15249a1d5cde4b686d001abb08d..16618b84123daced34494a214f0ad46e8a039328 100644 (file)
@@ -130,7 +130,8 @@ private:
   void handle_wait_for_ops(int r);
 
   void start_image_replayer(ImageReplayer<ImageCtxT> *image_replayer);
-  void start_image_replayers();
+  void queue_start_image_replayers();
+  void start_image_replayers(int r);
 
   void stop_image_replayer(ImageReplayer<ImageCtxT> *image_replayer,
                            Context *on_finish);