Skip to content

Commit

Permalink
rbd-mirror: service daemon attributes for instance replayer
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
  • Loading branch information
Jason Dillaman committed Jul 18, 2017
1 parent 8ddd65b commit 810fdbf
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 15 deletions.
6 changes: 6 additions & 0 deletions src/test/rbd_mirror/test_mock_InstanceReplayer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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<>
Expand Down Expand Up @@ -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;
Expand Down
60 changes: 46 additions & 14 deletions src/tools/rbd_mirror/InstanceReplayer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 =
Expand Down
3 changes: 2 additions & 1 deletion src/tools/rbd_mirror/InstanceReplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ class InstanceReplayer {
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);
Expand Down

0 comments on commit 810fdbf

Please sign in to comment.