]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: use pool level config overrides 24348/head
authorMykola Golub <mgolub@suse.com>
Sun, 30 Sep 2018 17:14:54 +0000 (20:14 +0300)
committerMykola Golub <mgolub@suse.com>
Sun, 30 Sep 2018 17:16:00 +0000 (20:16 +0300)
Signed-off-by: Mykola Golub <mgolub@suse.com>
15 files changed:
src/test/rbd_mirror/image_replayer/test_mock_PrepareRemoteImageRequest.cc
src/test/rbd_mirror/test_ImageReplayer.cc
src/test/rbd_mirror/test_mock_ImageReplayer.cc
src/test/rbd_mirror/test_mock_ImageSyncThrottler.cc
src/test/rbd_mirror/test_mock_InstanceWatcher.cc
src/test/rbd_mirror/test_mock_PoolReplayer.cc
src/tools/rbd_mirror/ImageDeleter.cc
src/tools/rbd_mirror/ImageReplayer.cc
src/tools/rbd_mirror/ImageSyncThrottler.cc
src/tools/rbd_mirror/ImageSyncThrottler.h
src/tools/rbd_mirror/InstanceReplayer.cc
src/tools/rbd_mirror/InstanceWatcher.cc
src/tools/rbd_mirror/PoolReplayer.cc
src/tools/rbd_mirror/image_replayer/PrepareRemoteImageRequest.cc
src/tools/rbd_mirror/image_replayer/PrepareRemoteImageRequest.h

index 782702f04836c5af75347f262e25a341b1158a23..1b957ed177f1b4058814a4cc2c8fe29f57147ee1 100644 (file)
@@ -179,7 +179,7 @@ TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, Success) {
                                                    m_remote_io_ctx,
                                                    "global image id",
                                                    "local mirror uuid",
-                                                   "local image id",
+                                                   "local image id", {},
                                                    &remote_mirror_uuid,
                                                    &remote_image_id,
                                                    &remote_journaler,
@@ -227,7 +227,7 @@ TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, SuccessNotRegistered) {
                                                    m_remote_io_ctx,
                                                    "global image id",
                                                    "local mirror uuid",
-                                                   "local image id",
+                                                   "local image id", {},
                                                    &remote_mirror_uuid,
                                                    &remote_image_id,
                                                    &remote_journaler,
@@ -260,7 +260,7 @@ TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, MirrorUuidError) {
                                                    m_remote_io_ctx,
                                                    "global image id",
                                                    "local mirror uuid",
-                                                   "",
+                                                   "", {},
                                                    &remote_mirror_uuid,
                                                    &remote_image_id,
                                                    &remote_journaler,
@@ -292,7 +292,7 @@ TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, MirrorImageIdError) {
                                                    m_remote_io_ctx,
                                                    "global image id",
                                                    "local mirror uuid",
-                                                   "",
+                                                   "", {},
                                                    &remote_mirror_uuid,
                                                    &remote_image_id,
                                                    &remote_journaler,
@@ -331,7 +331,7 @@ TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, GetClientError) {
                                                    m_remote_io_ctx,
                                                    "global image id",
                                                    "local mirror uuid",
-                                                   "local image id",
+                                                   "local image id", {},
                                                    &remote_mirror_uuid,
                                                    &remote_image_id,
                                                    &remote_journaler,
@@ -377,7 +377,7 @@ TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, RegisterClientError) {
                                                    m_remote_io_ctx,
                                                    "global image id",
                                                    "local mirror uuid",
-                                                   "local image id",
+                                                   "local image id", {},
                                                    &remote_mirror_uuid,
                                                    &remote_image_id,
                                                    &remote_journaler,
index 122182d7e42c37d90a79e46f8a19adde429e5374..51eb8b560c66b3bd8a5650b4b6e3907a6c431c4b 100644 (file)
@@ -82,15 +82,11 @@ public:
   TestImageReplayer()
     : m_local_cluster(new librados::Rados()), m_watch_handle(0)
   {
-    EXPECT_EQ(0, g_ceph_context->_conf.get_val("rbd_mirror_journal_commit_age",
-                                                &m_journal_commit_age));
-    EXPECT_EQ(0, g_ceph_context->_conf.set_val("rbd_mirror_journal_commit_age",
-                                                "0.1"));
-
     EXPECT_EQ("", connect_cluster_pp(*m_local_cluster.get()));
     EXPECT_EQ(0, m_local_cluster->conf_set("rbd_cache", "false"));
     EXPECT_EQ(0, m_local_cluster->conf_set("rbd_mirror_journal_poll_age", "1"));
-
+    EXPECT_EQ(0, m_local_cluster->conf_set("rbd_mirror_journal_commit_age",
+                                           "0.1"));
     m_local_pool_name = get_temp_pool_name();
     EXPECT_EQ(0, m_local_cluster->pool_create(m_local_pool_name.c_str()));
     EXPECT_EQ(0, m_local_cluster->ioctx_create(m_local_pool_name.c_str(),
@@ -144,8 +140,6 @@ public:
 
     EXPECT_EQ(0, m_remote_cluster.pool_delete(m_remote_pool_name.c_str()));
     EXPECT_EQ(0, m_local_cluster->pool_delete(m_local_pool_name.c_str()));
-    EXPECT_EQ(0, g_ceph_context->_conf.set_val("rbd_mirror_journal_commit_age",
-                                                m_journal_commit_age));
   }
 
   template <typename ImageReplayerT = rbd::mirror::ImageReplayer<> >
index 85d22ec70a9f1f25f7ab0c940b5edfe9f227d166..d9ed376a78873db92f2a4f6b68288d6ad40993df 100644 (file)
@@ -165,6 +165,7 @@ struct PrepareRemoteImageRequest<librbd::MockTestImageCtx> {
                                            const std::string &global_image_id,
                                            const std::string &local_mirror_uuid,
                                            const std::string &local_image_id,
+                                           const journal::Settings &settings,
                                            std::string *remote_mirror_uuid,
                                            std::string *remote_image_id,
                                            ::journal::MockJournalerProxy **remote_journaler,
index 24815aeb799aa2bf41d818a708b2e78dd3f7a137..f30a299f1505ba2800a4acd2f31688f5b5b19589 100644 (file)
@@ -42,7 +42,7 @@ public:
 };
 
 TEST_F(TestMockImageSyncThrottler, Single_Sync) {
-  MockImageSyncThrottler throttler;
+  MockImageSyncThrottler throttler(g_ceph_context);
   C_SaferCond on_start;
   throttler.start_op("id", &on_start);
   ASSERT_EQ(0, on_start.wait());
@@ -50,7 +50,7 @@ TEST_F(TestMockImageSyncThrottler, Single_Sync) {
 }
 
 TEST_F(TestMockImageSyncThrottler, Multiple_Syncs) {
-  MockImageSyncThrottler throttler;
+  MockImageSyncThrottler throttler(g_ceph_context);
   throttler.set_max_concurrent_syncs(2);
 
   C_SaferCond on_start1;
@@ -73,7 +73,7 @@ TEST_F(TestMockImageSyncThrottler, Multiple_Syncs) {
 }
 
 TEST_F(TestMockImageSyncThrottler, Cancel_Running_Sync) {
-  MockImageSyncThrottler throttler;
+  MockImageSyncThrottler throttler(g_ceph_context);
   C_SaferCond on_start;
   throttler.start_op("id", &on_start);
   ASSERT_EQ(0, on_start.wait());
@@ -82,7 +82,7 @@ TEST_F(TestMockImageSyncThrottler, Cancel_Running_Sync) {
 }
 
 TEST_F(TestMockImageSyncThrottler, Cancel_Waiting_Sync) {
-  MockImageSyncThrottler throttler;
+  MockImageSyncThrottler throttler(g_ceph_context);
   throttler.set_max_concurrent_syncs(1);
 
   C_SaferCond on_start1;
@@ -98,7 +98,7 @@ TEST_F(TestMockImageSyncThrottler, Cancel_Waiting_Sync) {
 
 
 TEST_F(TestMockImageSyncThrottler, Cancel_Running_Sync_Start_Waiting) {
-  MockImageSyncThrottler throttler;
+  MockImageSyncThrottler throttler(g_ceph_context);
   throttler.set_max_concurrent_syncs(1);
 
   C_SaferCond on_start1;
@@ -114,7 +114,7 @@ TEST_F(TestMockImageSyncThrottler, Cancel_Running_Sync_Start_Waiting) {
 }
 
 TEST_F(TestMockImageSyncThrottler, Increase_Max_Concurrent_Syncs) {
-  MockImageSyncThrottler throttler;
+  MockImageSyncThrottler throttler(g_ceph_context);
   throttler.set_max_concurrent_syncs(2);
 
   C_SaferCond on_start1;
@@ -146,7 +146,7 @@ TEST_F(TestMockImageSyncThrottler, Increase_Max_Concurrent_Syncs) {
 }
 
 TEST_F(TestMockImageSyncThrottler, Decrease_Max_Concurrent_Syncs) {
-  MockImageSyncThrottler throttler;
+  MockImageSyncThrottler throttler(g_ceph_context);
   throttler.set_max_concurrent_syncs(4);
 
   C_SaferCond on_start1;
index ede548dc043063456e97c3680bc688a5eff8a317..ec2b7057df7d776b5e68d65427c2c18a71e6bc82 100644 (file)
@@ -87,7 +87,7 @@ template <>
 struct ImageSyncThrottler<librbd::MockTestImageCtx> {
   static ImageSyncThrottler* s_instance;
 
-  static ImageSyncThrottler *create() {
+  static ImageSyncThrottler *create(CephContext *cct) {
     ceph_assert(s_instance != nullptr);
     return s_instance;
   }
index 0709201f310d8fb3ee58f0e89e4103716865a3c1..c7f0909cd518715e992b6a2a2ee4a13fb7e8f63a 100644 (file)
@@ -1,6 +1,7 @@
 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
 // vim: ts=8 sw=2 smarttab
 
+#include "librbd/api/Config.h"
 #include "test/librbd/mock/MockImageCtx.h"
 #include "test/librados_test_stub/MockTestMemCluster.h"
 #include "test/librados_test_stub/MockTestMemIoCtxImpl.h"
@@ -30,6 +31,19 @@ struct MockTestImageCtx : public MockImageCtx {
 
 } // anonymous namespace
 
+namespace api {
+
+template <>
+class Config<MockTestImageCtx> {
+public:
+  static int list(librados::IoCtx& io_ctx,
+                  std::vector<config_option_t> *options) {
+    return 0;
+  }
+};
+
+}
+
 } // namespace librbd
 
 namespace rbd {
index e8439f273ca40075cfdf30ba097c8f5db6563fa8..93ddf5cea1b257cd052ba1d4c1c84d790a547b54 100644 (file)
@@ -356,7 +356,8 @@ template <typename I>
 void ImageDeleter<I>::remove_images() {
   dout(10) << dendl;
 
-  uint64_t max_concurrent_deletions = g_ceph_context->_conf.get_val<uint64_t>(
+  auto cct = reinterpret_cast<CephContext *>(m_local_io_ctx.cct());
+  uint64_t max_concurrent_deletions = cct->_conf.get_val<uint64_t>(
     "rbd_mirror_concurrent_image_deletions");
 
   Mutex::Locker locker(m_lock);
@@ -414,7 +415,8 @@ void ImageDeleter<I>::handle_remove_image(DeleteInfoRef delete_info,
                  image_deleter::ERROR_RESULT_RETRY_IMMEDIATELY) {
       enqueue_failed_delete(&delete_info, r, m_busy_interval);
     } else {
-      double failed_interval = g_ceph_context->_conf.get_val<double>(
+      auto cct = reinterpret_cast<CephContext *>(m_local_io_ctx.cct());
+      double failed_interval = cct->_conf.get_val<double>(
         "rbd_mirror_delete_retry_interval");
       enqueue_failed_delete(&delete_info, r, failed_interval);
     }
index 35650e5d3e485b5ceebfc0eabc333bd01265da1d..2a9a26f40fa1312a3063a1a6d21632c2befe3f71 100644 (file)
@@ -433,12 +433,20 @@ void ImageReplayer<I>::prepare_remote_image() {
   ceph_assert(!m_peers.empty());
   m_remote_image = {*m_peers.begin()};
 
+  auto cct = static_cast<CephContext *>(m_local->cct());
+  journal::Settings journal_settings;
+  journal_settings.commit_interval = cct->_conf.get_val<double>(
+    "rbd_mirror_journal_commit_age");
+  journal_settings.max_fetch_bytes = cct->_conf.get_val<Option::size_t>(
+    "rbd_mirror_journal_max_fetch_bytes");
+
   Context *ctx = create_context_callback<
     ImageReplayer, &ImageReplayer<I>::handle_prepare_remote_image>(this);
   auto req = PrepareRemoteImageRequest<I>::create(
     m_threads, m_remote_image.io_ctx, m_global_image_id, m_local_mirror_uuid,
-    m_local_image_id, &m_remote_image.mirror_uuid, &m_remote_image.image_id,
-    &m_remote_journaler, &m_client_state, &m_client_meta, ctx);
+    m_local_image_id, journal_settings, &m_remote_image.mirror_uuid,
+    &m_remote_image.image_id, &m_remote_journaler, &m_client_state,
+    &m_client_meta, ctx);
   req->send();
 }
 
index a3fc8330fdcecce24e2d4c86610056b6777161c9..c2e618bf48fc1110354ba26bb191144f693d83d5 100644 (file)
@@ -28,18 +28,19 @@ namespace rbd {
 namespace mirror {
 
 template <typename I>
-ImageSyncThrottler<I>::ImageSyncThrottler()
-  : m_lock(librbd::util::unique_lock_name("rbd::mirror::ImageSyncThrottler",
+ImageSyncThrottler<I>::ImageSyncThrottler(CephContext *cct)
+  : m_cct(cct),
+    m_lock(librbd::util::unique_lock_name("rbd::mirror::ImageSyncThrottler",
                                           this)),
-    m_max_concurrent_syncs(g_ceph_context->_conf.get_val<uint64_t>(
+    m_max_concurrent_syncs(cct->_conf.get_val<uint64_t>(
       "rbd_mirror_concurrent_image_syncs")) {
   dout(20) << "max_concurrent_syncs=" << m_max_concurrent_syncs << dendl;
-  g_ceph_context->_conf.add_observer(this);
+  m_cct->_conf.add_observer(this);
 }
 
 template <typename I>
 ImageSyncThrottler<I>::~ImageSyncThrottler() {
-  g_ceph_context->_conf.remove_observer(this);
+  m_cct->_conf.remove_observer(this);
 
   Mutex::Locker locker(m_lock);
   ceph_assert(m_inflight_ops.empty());
index 8f965bf7b7ec82613259686be1086c604e0a4e2c..8c8f754626a3f28b9fbd23a7e76df92f2a15a6bf 100644 (file)
@@ -13,6 +13,7 @@
 #include "common/Mutex.h"
 #include "common/config_obs.h"
 
+class CephContext;
 class Context;
 
 namespace ceph { class Formatter; }
@@ -24,14 +25,14 @@ namespace mirror {
 template <typename ImageCtxT = librbd::ImageCtx>
 class ImageSyncThrottler : public md_config_obs_t {
 public:
-  static ImageSyncThrottler *create() {
-    return new ImageSyncThrottler();
+  static ImageSyncThrottler *create(CephContext *cct) {
+    return new ImageSyncThrottler(cct);
   }
   void destroy() {
     delete this;
   }
 
-  ImageSyncThrottler();
+  ImageSyncThrottler(CephContext *cct);
   ~ImageSyncThrottler() override;
 
   void set_max_concurrent_syncs(uint32_t max);
@@ -43,6 +44,7 @@ public:
   void print_status(Formatter *f, std::stringstream *ss);
 
 private:
+  CephContext *m_cct;
   Mutex m_lock;
   uint32_t m_max_concurrent_syncs;
   std::list<std::pair<std::string, Context *>> m_queue;
index a2165965f5d23c625f6767d4d7512cdb2eb76d04..d3dfc557d702f75a2ad30e432df921ee6f433c3c 100644 (file)
@@ -488,7 +488,8 @@ void InstanceReplayer<I>::schedule_image_state_check_task() {
       queue_start_image_replayers();
     });
 
-  int after = g_ceph_context->_conf.get_val<int64_t>(
+  auto cct = static_cast<CephContext *>(m_local_rados->cct());
+  int after = cct->_conf.get_val<int64_t>(
     "rbd_mirror_image_state_check_interval");
 
   dout(10) << "scheduling image state check after " << after << " sec (task "
index 9ba9d01056a9be6671af77c1ca4e1b19edfed828..afecd4042f5ec01e23df0ede99baaf1d704e89ac 100644 (file)
@@ -595,7 +595,7 @@ void InstanceWatcher<I>::handle_acquire_leader() {
   Mutex::Locker locker(m_lock);
 
   ceph_assert(m_image_sync_throttler == nullptr);
-  m_image_sync_throttler = ImageSyncThrottler<I>::create();
+  m_image_sync_throttler = ImageSyncThrottler<I>::create(m_cct);
 
   m_leader_instance_id = m_instance_id;
   unsuspend_notify_requests();
index 2dbaf93f8f6038e893778ede398eb8bad908ce34..8d0ec509df181ffb4f83baf27671e0a704f2b5e5 100644 (file)
@@ -16,6 +16,7 @@
 #include "librbd/internal.h"
 #include "librbd/Utils.h"
 #include "librbd/Watcher.h"
+#include "librbd/api/Config.h"
 #include "librbd/api/Mirror.h"
 #include "ImageMap.h"
 #include "InstanceReplayer.h"
@@ -305,6 +306,21 @@ void PoolReplayer<I>::init()
     return;
   }
 
+  std::vector<librbd::config_option_t> options;
+  r = librbd::api::Config<I>::list(m_local_io_ctx, &options);
+  if (r < 0) {
+    derr << "error listing local pool config overrides: " << cpp_strerror(r)
+         << dendl;
+    return;
+  }
+  auto cct = reinterpret_cast<CephContext *>(m_local_io_ctx.cct());
+  for (auto &option : options) {
+    if (option.source == RBD_CONFIG_SOURCE_POOL) {
+      r = cct->_conf.set_val(option.name.c_str(), option.value);
+      assert(r == 0);
+    }
+  }
+
   std::string local_mirror_uuid;
   r = librbd::cls_client::mirror_uuid_get(&m_local_io_ctx,
                                           &local_mirror_uuid);
index 3ebd5992d436bf3077c4c64fb76e82ae8d08b5c7..00c141e0bc1cb5f2641e25e6155b4ccc68e4b12c 100644 (file)
@@ -8,7 +8,6 @@
 #include "common/errno.h"
 #include "common/WorkQueue.h"
 #include "journal/Journaler.h"
-#include "journal/Settings.h"
 #include "librbd/ImageCtx.h"
 #include "librbd/Utils.h"
 #include "librbd/journal/Types.h"
@@ -106,17 +105,11 @@ template <typename I>
 void PrepareRemoteImageRequest<I>::get_client() {
   dout(20) << dendl;
 
-  journal::Settings settings;
-  settings.commit_interval = g_ceph_context->_conf.get_val<double>(
-    "rbd_mirror_journal_commit_age");
-  settings.max_fetch_bytes = g_ceph_context->_conf.get_val<Option::size_t>(
-    "rbd_mirror_journal_max_fetch_bytes");
-
   ceph_assert(*m_remote_journaler == nullptr);
   *m_remote_journaler = new Journaler(m_threads->work_queue, m_threads->timer,
                                       &m_threads->timer_lock, m_remote_io_ctx,
                                       *m_remote_image_id, m_local_mirror_uuid,
-                                      settings);
+                                      m_journal_settings);
 
   Context *ctx = create_async_context_callback(
     m_threads->work_queue, create_context_callback<
index 5f278a8c65cf153f2a4213cf4b25615c263c9a09..e0b4898cac3f5b50df3bbf500855429af5e94ed6 100644 (file)
@@ -6,10 +6,12 @@
 
 #include "include/buffer.h"
 #include "cls/journal/cls_journal_types.h"
+#include "journal/Settings.h"
 #include "librbd/journal/TypeTraits.h"
 #include <string>
 
 namespace journal { class Journaler; }
+namespace journal { class Settings; }
 namespace librados { struct IoCtx; }
 namespace librbd { struct ImageCtx; }
 namespace librbd { namespace journal { struct MirrorPeerClientMeta; } }
@@ -36,6 +38,7 @@ public:
                                            const std::string &global_image_id,
                                            const std::string &local_mirror_uuid,
                                            const std::string &local_image_id,
+                                           const journal::Settings &settings,
                                            std::string *remote_mirror_uuid,
                                            std::string *remote_image_id,
                                            Journaler **remote_journaler,
@@ -44,9 +47,10 @@ public:
                                            Context *on_finish) {
     return new PrepareRemoteImageRequest(threads, remote_io_ctx,
                                          global_image_id, local_mirror_uuid,
-                                         local_image_id, remote_mirror_uuid,
-                                         remote_image_id, remote_journaler,
-                                         client_state, client_meta, on_finish);
+                                         local_image_id, settings,
+                                         remote_mirror_uuid, remote_image_id,
+                                         remote_journaler, client_state,
+                                         client_meta, on_finish);
   }
 
   PrepareRemoteImageRequest(Threads<ImageCtxT> *threads,
@@ -54,6 +58,7 @@ public:
                            const std::string &global_image_id,
                            const std::string &local_mirror_uuid,
                            const std::string &local_image_id,
+                           const journal::Settings &journal_settings,
                            std::string *remote_mirror_uuid,
                            std::string *remote_image_id,
                            Journaler **remote_journaler,
@@ -100,6 +105,7 @@ private:
   std::string m_global_image_id;
   std::string m_local_mirror_uuid;
   std::string m_local_image_id;
+  journal::Settings m_journal_settings;
   std::string *m_remote_mirror_uuid;
   std::string *m_remote_image_id;
   Journaler **m_remote_journaler;