From 03dc984f07d87d9c50632fb9843411562dd0db72 Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Tue, 27 Aug 2019 20:42:46 +0100 Subject: [PATCH] rbd-mirror: generalize ImageSyncThrottler into Throttler Signed-off-by: Mykola Golub --- src/test/rbd_mirror/CMakeLists.txt | 2 +- src/test/rbd_mirror/test_ImageReplayer.cc | 7 +- src/test/rbd_mirror/test_ImageSync.cc | 7 +- .../rbd_mirror/test_mock_InstanceWatcher.cc | 16 ++-- .../rbd_mirror/test_mock_NamespaceReplayer.cc | 2 +- src/test/rbd_mirror/test_mock_PoolReplayer.cc | 20 +++-- ...yncThrottler.cc => test_mock_Throttler.cc} | 66 +++++++------- src/tools/rbd_mirror/CMakeLists.txt | 2 +- src/tools/rbd_mirror/InstanceWatcher.cc | 6 +- src/tools/rbd_mirror/InstanceWatcher.h | 8 +- src/tools/rbd_mirror/NamespaceReplayer.cc | 2 +- src/tools/rbd_mirror/NamespaceReplayer.h | 8 +- src/tools/rbd_mirror/PoolReplayer.cc | 3 +- src/tools/rbd_mirror/PoolReplayer.h | 4 +- .../{ImageSyncThrottler.cc => Throttler.cc} | 87 +++++++++---------- .../{ImageSyncThrottler.h => Throttler.h} | 30 ++++--- 16 files changed, 138 insertions(+), 132 deletions(-) rename src/test/rbd_mirror/{test_mock_ImageSyncThrottler.cc => test_mock_Throttler.cc} (74%) rename src/tools/rbd_mirror/{ImageSyncThrottler.cc => Throttler.cc} (66%) rename src/tools/rbd_mirror/{ImageSyncThrottler.h => Throttler.h} (68%) diff --git a/src/test/rbd_mirror/CMakeLists.txt b/src/test/rbd_mirror/CMakeLists.txt index 4ea85e4d249e3..e481139928606 100644 --- a/src/test/rbd_mirror/CMakeLists.txt +++ b/src/test/rbd_mirror/CMakeLists.txt @@ -21,13 +21,13 @@ add_executable(unittest_rbd_mirror test_mock_ImageMap.cc test_mock_ImageReplayer.cc test_mock_ImageSync.cc - test_mock_ImageSyncThrottler.cc test_mock_InstanceReplayer.cc test_mock_InstanceWatcher.cc test_mock_LeaderWatcher.cc test_mock_NamespaceReplayer.cc test_mock_PoolReplayer.cc test_mock_PoolWatcher.cc + test_mock_Throttler.cc image_deleter/test_mock_RemoveRequest.cc image_deleter/test_mock_SnapshotPurgeRequest.cc image_deleter/test_mock_TrashMoveRequest.cc diff --git a/src/test/rbd_mirror/test_ImageReplayer.cc b/src/test/rbd_mirror/test_ImageReplayer.cc index 7d85d3c568bb8..1491e8bcd774f 100644 --- a/src/test/rbd_mirror/test_ImageReplayer.cc +++ b/src/test/rbd_mirror/test_ImageReplayer.cc @@ -35,9 +35,9 @@ #include "librbd/io/ImageRequestWQ.h" #include "librbd/io/ReadResult.h" #include "tools/rbd_mirror/ImageReplayer.h" -#include "tools/rbd_mirror/ImageSyncThrottler.h" #include "tools/rbd_mirror/InstanceWatcher.h" #include "tools/rbd_mirror/Threads.h" +#include "tools/rbd_mirror/Throttler.h" #include "tools/rbd_mirror/Types.h" #include "test/librados/test_cxx.h" @@ -120,7 +120,8 @@ public: auto cct = reinterpret_cast(m_local_ioctx.cct()); m_threads.reset(new rbd::mirror::Threads<>(cct)); - m_image_sync_throttler.reset(new rbd::mirror::ImageSyncThrottler<>(cct)); + m_image_sync_throttler.reset(new rbd::mirror::Throttler<>( + cct, "rbd_mirror_concurrent_image_syncs")); m_instance_watcher = rbd::mirror::InstanceWatcher<>::create( m_local_ioctx, m_threads->work_queue, nullptr, @@ -377,7 +378,7 @@ public: std::shared_ptr m_local_cluster; std::unique_ptr> m_threads; - std::unique_ptr> m_image_sync_throttler; + std::unique_ptr> m_image_sync_throttler; librados::Rados m_remote_cluster; rbd::mirror::InstanceWatcher<> *m_instance_watcher; std::string m_local_mirror_uuid = "local mirror uuid"; diff --git a/src/test/rbd_mirror/test_ImageSync.cc b/src/test/rbd_mirror/test_ImageSync.cc index 39feffe89f5a0..b585ea571fbcf 100644 --- a/src/test/rbd_mirror/test_ImageSync.cc +++ b/src/test/rbd_mirror/test_ImageSync.cc @@ -18,9 +18,9 @@ #include "librbd/io/ReadResult.h" #include "librbd/journal/Types.h" #include "tools/rbd_mirror/ImageSync.h" -#include "tools/rbd_mirror/ImageSyncThrottler.h" #include "tools/rbd_mirror/InstanceWatcher.h" #include "tools/rbd_mirror/Threads.h" +#include "tools/rbd_mirror/Throttler.h" void register_test_image_sync() { } @@ -74,7 +74,8 @@ public: create_and_open(m_remote_io_ctx, &m_remote_image_ctx); auto cct = reinterpret_cast(m_local_io_ctx.cct()); - m_image_sync_throttler = rbd::mirror::ImageSyncThrottler<>::create(cct); + m_image_sync_throttler = rbd::mirror::Throttler<>::create( + cct, "rbd_mirror_concurrent_image_syncs"); m_instance_watcher = rbd::mirror::InstanceWatcher<>::create( m_local_io_ctx, m_threads->work_queue, nullptr, m_image_sync_throttler); @@ -126,7 +127,7 @@ public: librbd::ImageCtx *m_remote_image_ctx; librbd::ImageCtx *m_local_image_ctx; - rbd::mirror::ImageSyncThrottler<> *m_image_sync_throttler; + rbd::mirror::Throttler<> *m_image_sync_throttler; rbd::mirror::InstanceWatcher<> *m_instance_watcher; ::journal::Journaler *m_remote_journaler; librbd::journal::MirrorPeerClientMeta m_client_meta; diff --git a/src/test/rbd_mirror/test_mock_InstanceWatcher.cc b/src/test/rbd_mirror/test_mock_InstanceWatcher.cc index 039b97e8284c5..78bb972b55565 100644 --- a/src/test/rbd_mirror/test_mock_InstanceWatcher.cc +++ b/src/test/rbd_mirror/test_mock_InstanceWatcher.cc @@ -83,15 +83,15 @@ struct InstanceReplayer { }; template <> -struct ImageSyncThrottler { - static ImageSyncThrottler* s_instance; +struct Throttler { + static Throttler* s_instance; - ImageSyncThrottler() { + Throttler() { ceph_assert(s_instance == nullptr); s_instance = this; } - virtual ~ImageSyncThrottler() { + virtual ~Throttler() { ceph_assert(s_instance == this); s_instance = nullptr; } @@ -102,7 +102,7 @@ struct ImageSyncThrottler { MOCK_METHOD2(drain, void(const std::string &, int)); }; -ImageSyncThrottler* ImageSyncThrottler::s_instance = nullptr; +Throttler* Throttler::s_instance = nullptr; } // namespace mirror } // namespace rbd @@ -658,10 +658,10 @@ TEST_F(TestMockInstanceWatcher, PeerImageRemovedCancel) { class TestMockInstanceWatcher_NotifySync : public TestMockInstanceWatcher { public: - typedef ImageSyncThrottler MockImageSyncThrottler; + typedef Throttler MockThrottler; MockManagedLock mock_managed_lock; - MockImageSyncThrottler mock_image_sync_throttler; + MockThrottler mock_image_sync_throttler; std::string instance_id1; std::string instance_id2; @@ -765,7 +765,7 @@ public: void expect_throttler_drain() { EXPECT_CALL(mock_image_sync_throttler, drain("", -ESTALE)); - } + } }; TEST_F(TestMockInstanceWatcher_NotifySync, StartStopOnLeader) { diff --git a/src/test/rbd_mirror/test_mock_NamespaceReplayer.cc b/src/test/rbd_mirror/test_mock_NamespaceReplayer.cc index b787a388921b3..b52e932ed5c49 100644 --- a/src/test/rbd_mirror/test_mock_NamespaceReplayer.cc +++ b/src/test/rbd_mirror/test_mock_NamespaceReplayer.cc @@ -130,7 +130,7 @@ struct InstanceWatcher { static InstanceWatcher* create( librados::IoCtx &ioctx, ContextWQ* work_queue, InstanceReplayer* instance_replayer, - ImageSyncThrottler *image_sync_throttler) { + Throttler *image_sync_throttler) { ceph_assert(s_instance != nullptr); return s_instance; } diff --git a/src/test/rbd_mirror/test_mock_PoolReplayer.cc b/src/test/rbd_mirror/test_mock_PoolReplayer.cc index 369624c0d35e0..e1f050f8f5336 100644 --- a/src/test/rbd_mirror/test_mock_PoolReplayer.cc +++ b/src/test/rbd_mirror/test_mock_PoolReplayer.cc @@ -10,7 +10,7 @@ #include "test/rbd_mirror/test_mock_fixture.h" #include "test/rbd_mirror/mock/MockContextWQ.h" #include "test/rbd_mirror/mock/MockSafeTimer.h" -#include "tools/rbd_mirror/ImageSyncThrottler.h" +#include "tools/rbd_mirror/Throttler.h" #include "tools/rbd_mirror/LeaderWatcher.h" #include "tools/rbd_mirror/NamespaceReplayer.h" #include "tools/rbd_mirror/PoolReplayer.h" @@ -97,19 +97,21 @@ namespace rbd { namespace mirror { template <> -struct ImageSyncThrottler { - static ImageSyncThrottler* s_instance; +struct Throttler { + static Throttler* s_instance; - static ImageSyncThrottler *create(CephContext *cct) { + static Throttler *create( + CephContext *cct, + const std::string &max_concurrent_ops_config_param_name) { return s_instance; } - ImageSyncThrottler() { + Throttler() { ceph_assert(s_instance == nullptr); s_instance = this; } - virtual ~ImageSyncThrottler() { + virtual ~Throttler() { ceph_assert(s_instance == this); s_instance = nullptr; } @@ -117,7 +119,7 @@ struct ImageSyncThrottler { MOCK_METHOD2(print_status, void(Formatter*, std::stringstream*)); }; -ImageSyncThrottler* ImageSyncThrottler::s_instance = nullptr; +Throttler* Throttler::s_instance = nullptr; template <> struct NamespaceReplayer { @@ -130,7 +132,7 @@ struct NamespaceReplayer { const std::string &local_mirror_uuid, const std::string &remote_mirror_uuid, Threads *threads, - ImageSyncThrottler *image_sync_throttler, + Throttler *image_sync_throttler, ServiceDaemon *service_daemon, journal::CacheManagerHandler *cache_manager_handler) { ceph_assert(s_instances.count(name)); @@ -250,7 +252,7 @@ class TestMockPoolReplayer : public TestMockFixture { public: typedef librbd::api::Namespace MockNamespace; typedef PoolReplayer MockPoolReplayer; - typedef ImageSyncThrottler MockImageSyncThrottler; + typedef Throttler MockThrottler; typedef NamespaceReplayer MockNamespaceReplayer; typedef LeaderWatcher MockLeaderWatcher; typedef ServiceDaemon MockServiceDaemon; diff --git a/src/test/rbd_mirror/test_mock_ImageSyncThrottler.cc b/src/test/rbd_mirror/test_mock_Throttler.cc similarity index 74% rename from src/test/rbd_mirror/test_mock_ImageSyncThrottler.cc rename to src/test/rbd_mirror/test_mock_Throttler.cc index 1189e03b48f2e..ab562c18d7c98 100644 --- a/src/test/rbd_mirror/test_mock_ImageSyncThrottler.cc +++ b/src/test/rbd_mirror/test_mock_Throttler.cc @@ -30,28 +30,28 @@ struct MockTestImageCtx : public librbd::MockImageCtx { } // namespace librbd // template definitions -#include "tools/rbd_mirror/ImageSyncThrottler.cc" +#include "tools/rbd_mirror/Throttler.cc" namespace rbd { namespace mirror { -class TestMockImageSyncThrottler : public TestMockFixture { +class TestMockThrottler : public TestMockFixture { public: - typedef ImageSyncThrottler MockImageSyncThrottler; + typedef Throttler MockThrottler; }; -TEST_F(TestMockImageSyncThrottler, Single_Sync) { - MockImageSyncThrottler throttler(g_ceph_context); +TEST_F(TestMockThrottler, Single_Sync) { + MockThrottler throttler(g_ceph_context, "rbd_mirror_concurrent_image_syncs"); C_SaferCond on_start; throttler.start_op("ns", "id", &on_start); ASSERT_EQ(0, on_start.wait()); throttler.finish_op("ns", "id"); } -TEST_F(TestMockImageSyncThrottler, Multiple_Syncs) { - MockImageSyncThrottler throttler(g_ceph_context); - throttler.set_max_concurrent_syncs(2); +TEST_F(TestMockThrottler, Multiple_Syncs) { + MockThrottler throttler(g_ceph_context, "rbd_mirror_concurrent_image_syncs"); + throttler.set_max_concurrent_ops(2); C_SaferCond on_start1; throttler.start_op("ns", "id1", &on_start1); @@ -72,8 +72,8 @@ TEST_F(TestMockImageSyncThrottler, Multiple_Syncs) { throttler.finish_op("ns", "id4"); } -TEST_F(TestMockImageSyncThrottler, Cancel_Running_Sync) { - MockImageSyncThrottler throttler(g_ceph_context); +TEST_F(TestMockThrottler, Cancel_Running_Sync) { + MockThrottler throttler(g_ceph_context, "rbd_mirror_concurrent_image_syncs"); C_SaferCond on_start; throttler.start_op("ns", "id", &on_start); ASSERT_EQ(0, on_start.wait()); @@ -81,9 +81,9 @@ TEST_F(TestMockImageSyncThrottler, Cancel_Running_Sync) { throttler.finish_op("ns", "id"); } -TEST_F(TestMockImageSyncThrottler, Cancel_Waiting_Sync) { - MockImageSyncThrottler throttler(g_ceph_context); - throttler.set_max_concurrent_syncs(1); +TEST_F(TestMockThrottler, Cancel_Waiting_Sync) { + MockThrottler throttler(g_ceph_context, "rbd_mirror_concurrent_image_syncs"); + throttler.set_max_concurrent_ops(1); C_SaferCond on_start1; throttler.start_op("ns", "id1", &on_start1); @@ -96,9 +96,9 @@ TEST_F(TestMockImageSyncThrottler, Cancel_Waiting_Sync) { throttler.finish_op("ns", "id1"); } -TEST_F(TestMockImageSyncThrottler, Cancel_Running_Sync_Start_Waiting) { - MockImageSyncThrottler throttler(g_ceph_context); - throttler.set_max_concurrent_syncs(1); +TEST_F(TestMockThrottler, Cancel_Running_Sync_Start_Waiting) { + MockThrottler throttler(g_ceph_context, "rbd_mirror_concurrent_image_syncs"); + throttler.set_max_concurrent_ops(1); C_SaferCond on_start1; throttler.start_op("ns", "id1", &on_start1); @@ -112,9 +112,9 @@ TEST_F(TestMockImageSyncThrottler, Cancel_Running_Sync_Start_Waiting) { throttler.finish_op("ns", "id2"); } -TEST_F(TestMockImageSyncThrottler, Duplicate) { - MockImageSyncThrottler throttler(g_ceph_context); - throttler.set_max_concurrent_syncs(1); +TEST_F(TestMockThrottler, Duplicate) { + MockThrottler throttler(g_ceph_context, "rbd_mirror_concurrent_image_syncs"); + throttler.set_max_concurrent_ops(1); C_SaferCond on_start1; throttler.start_op("ns", "id1", &on_start1); @@ -135,9 +135,9 @@ TEST_F(TestMockImageSyncThrottler, Duplicate) { throttler.finish_op("ns", "id2"); } -TEST_F(TestMockImageSyncThrottler, Duplicate2) { - MockImageSyncThrottler throttler(g_ceph_context); - throttler.set_max_concurrent_syncs(2); +TEST_F(TestMockThrottler, Duplicate2) { + MockThrottler throttler(g_ceph_context, "rbd_mirror_concurrent_image_syncs"); + throttler.set_max_concurrent_ops(2); C_SaferCond on_start1; throttler.start_op("ns", "id1", &on_start1); @@ -171,9 +171,9 @@ TEST_F(TestMockImageSyncThrottler, Duplicate2) { throttler.finish_op("ns", "id5"); } -TEST_F(TestMockImageSyncThrottler, Increase_Max_Concurrent_Syncs) { - MockImageSyncThrottler throttler(g_ceph_context); - throttler.set_max_concurrent_syncs(2); +TEST_F(TestMockThrottler, Increase_Max_Concurrent_Syncs) { + MockThrottler throttler(g_ceph_context, "rbd_mirror_concurrent_image_syncs"); + throttler.set_max_concurrent_ops(2); C_SaferCond on_start1; throttler.start_op("ns", "id1", &on_start1); @@ -189,7 +189,7 @@ TEST_F(TestMockImageSyncThrottler, Increase_Max_Concurrent_Syncs) { ASSERT_EQ(0, on_start1.wait()); ASSERT_EQ(0, on_start2.wait()); - throttler.set_max_concurrent_syncs(4); + throttler.set_max_concurrent_ops(4); ASSERT_EQ(0, on_start3.wait()); ASSERT_EQ(0, on_start4.wait()); @@ -203,9 +203,9 @@ TEST_F(TestMockImageSyncThrottler, Increase_Max_Concurrent_Syncs) { throttler.finish_op("ns", "id5"); } -TEST_F(TestMockImageSyncThrottler, Decrease_Max_Concurrent_Syncs) { - MockImageSyncThrottler throttler(g_ceph_context); - throttler.set_max_concurrent_syncs(4); +TEST_F(TestMockThrottler, Decrease_Max_Concurrent_Syncs) { + MockThrottler throttler(g_ceph_context, "rbd_mirror_concurrent_image_syncs"); + throttler.set_max_concurrent_ops(4); C_SaferCond on_start1; throttler.start_op("ns", "id1", &on_start1); @@ -223,7 +223,7 @@ TEST_F(TestMockImageSyncThrottler, Decrease_Max_Concurrent_Syncs) { ASSERT_EQ(0, on_start3.wait()); ASSERT_EQ(0, on_start4.wait()); - throttler.set_max_concurrent_syncs(2); + throttler.set_max_concurrent_ops(2); throttler.finish_op("ns", "id1"); throttler.finish_op("ns", "id2"); @@ -235,9 +235,9 @@ TEST_F(TestMockImageSyncThrottler, Decrease_Max_Concurrent_Syncs) { throttler.finish_op("ns", "id5"); } -TEST_F(TestMockImageSyncThrottler, Drain) { - MockImageSyncThrottler throttler(g_ceph_context); - throttler.set_max_concurrent_syncs(1); +TEST_F(TestMockThrottler, Drain) { + MockThrottler throttler(g_ceph_context, "rbd_mirror_concurrent_image_syncs"); + throttler.set_max_concurrent_ops(1); C_SaferCond on_start1; throttler.start_op("ns", "id1", &on_start1); diff --git a/src/tools/rbd_mirror/CMakeLists.txt b/src/tools/rbd_mirror/CMakeLists.txt index 3c0088fdf103d..0bf91bd5ec864 100644 --- a/src/tools/rbd_mirror/CMakeLists.txt +++ b/src/tools/rbd_mirror/CMakeLists.txt @@ -9,7 +9,6 @@ set(rbd_mirror_internal ImageMap.cc ImageReplayer.cc ImageSync.cc - ImageSyncThrottler.cc InstanceReplayer.cc InstanceWatcher.cc Instances.cc @@ -21,6 +20,7 @@ set(rbd_mirror_internal PoolWatcher.cc ServiceDaemon.cc Threads.cc + Throttler.cc Types.cc image_deleter/RemoveRequest.cc image_deleter/SnapshotPurgeRequest.cc diff --git a/src/tools/rbd_mirror/InstanceWatcher.cc b/src/tools/rbd_mirror/InstanceWatcher.cc index f29a8d48abc1b..122e35326b60b 100644 --- a/src/tools/rbd_mirror/InstanceWatcher.cc +++ b/src/tools/rbd_mirror/InstanceWatcher.cc @@ -9,7 +9,7 @@ #include "librbd/ManagedLock.h" #include "librbd/Utils.h" #include "InstanceReplayer.h" -#include "ImageSyncThrottler.h" +#include "Throttler.h" #include "common/Cond.h" #define dout_context g_ceph_context @@ -313,7 +313,7 @@ template InstanceWatcher *InstanceWatcher::create( librados::IoCtx &io_ctx, ContextWQ *work_queue, InstanceReplayer *instance_replayer, - ImageSyncThrottler *image_sync_throttler) { + Throttler *image_sync_throttler) { return new InstanceWatcher(io_ctx, work_queue, instance_replayer, image_sync_throttler, stringify(io_ctx.get_instance_id())); @@ -323,7 +323,7 @@ template InstanceWatcher::InstanceWatcher(librados::IoCtx &io_ctx, ContextWQ *work_queue, InstanceReplayer *instance_replayer, - ImageSyncThrottler *image_sync_throttler, + Throttler *image_sync_throttler, const std::string &instance_id) : Watcher(io_ctx, work_queue, RBD_MIRROR_INSTANCE_PREFIX + instance_id), m_instance_replayer(instance_replayer), diff --git a/src/tools/rbd_mirror/InstanceWatcher.h b/src/tools/rbd_mirror/InstanceWatcher.h index 5e077921fa2bc..bc459f3e4c068 100644 --- a/src/tools/rbd_mirror/InstanceWatcher.h +++ b/src/tools/rbd_mirror/InstanceWatcher.h @@ -25,8 +25,8 @@ template class ManagedLock; namespace rbd { namespace mirror { -template class ImageSyncThrottler; template class InstanceReplayer; +template class Throttler; template struct Threads; template @@ -44,14 +44,14 @@ public: static InstanceWatcher *create( librados::IoCtx &io_ctx, ContextWQ *work_queue, InstanceReplayer *instance_replayer, - ImageSyncThrottler *image_sync_throttler); + Throttler *image_sync_throttler); void destroy() { delete this; } InstanceWatcher(librados::IoCtx &io_ctx, ContextWQ *work_queue, InstanceReplayer *instance_replayer, - ImageSyncThrottler *image_sync_throttler, + Throttler *image_sync_throttler, const std::string &instance_id); ~InstanceWatcher() override; @@ -157,7 +157,7 @@ private: Threads *m_threads; InstanceReplayer *m_instance_replayer; - ImageSyncThrottler *m_image_sync_throttler; + Throttler *m_image_sync_throttler; std::string m_instance_id; mutable ceph::mutex m_lock; diff --git a/src/tools/rbd_mirror/NamespaceReplayer.cc b/src/tools/rbd_mirror/NamespaceReplayer.cc index 6428bfe11e8f2..35703ab8bf4c1 100644 --- a/src/tools/rbd_mirror/NamespaceReplayer.cc +++ b/src/tools/rbd_mirror/NamespaceReplayer.cc @@ -40,7 +40,7 @@ NamespaceReplayer::NamespaceReplayer( const std::string &name, librados::IoCtx &local_io_ctx, librados::IoCtx &remote_io_ctx, const std::string &local_mirror_uuid, const std::string &remote_mirror_uuid, - Threads *threads, ImageSyncThrottler *image_sync_throttler, + Threads *threads, Throttler *image_sync_throttler, ServiceDaemon *service_daemon, journal::CacheManagerHandler *cache_manager_handler) : m_local_mirror_uuid(local_mirror_uuid), diff --git a/src/tools/rbd_mirror/NamespaceReplayer.h b/src/tools/rbd_mirror/NamespaceReplayer.h index 810f8b445070c..c6f519f5590ab 100644 --- a/src/tools/rbd_mirror/NamespaceReplayer.h +++ b/src/tools/rbd_mirror/NamespaceReplayer.h @@ -32,8 +32,8 @@ namespace librbd { class ImageCtx; } namespace rbd { namespace mirror { -template class ImageSyncThrottler; template class ServiceDaemon; +template class Throttler; template struct Threads; /** @@ -49,7 +49,7 @@ public: const std::string &local_mirror_uuid, const std::string &remote_mirror_uuid, Threads *threads, - ImageSyncThrottler *image_sync_throttler, + Throttler *image_sync_throttler, ServiceDaemon *service_daemon, journal::CacheManagerHandler *cache_manager_handler) { return new NamespaceReplayer(name, local_ioctx, remote_ioctx, @@ -64,7 +64,7 @@ public: const std::string &local_mirror_uuid, const std::string &remote_mirror_uuid, Threads *threads, - ImageSyncThrottler *image_sync_throttler, + Throttler *image_sync_throttler, ServiceDaemon *service_daemon, journal::CacheManagerHandler *cache_manager_handler); NamespaceReplayer(const NamespaceReplayer&) = delete; @@ -251,7 +251,7 @@ private: std::string m_local_mirror_uuid; std::string m_remote_mirror_uuid; Threads *m_threads; - ImageSyncThrottler *m_image_sync_throttler; + Throttler *m_image_sync_throttler; ServiceDaemon *m_service_daemon; journal::CacheManagerHandler *m_cache_manager_handler; diff --git a/src/tools/rbd_mirror/PoolReplayer.cc b/src/tools/rbd_mirror/PoolReplayer.cc index c61951b6ffc8a..588ea5e074939 100644 --- a/src/tools/rbd_mirror/PoolReplayer.cc +++ b/src/tools/rbd_mirror/PoolReplayer.cc @@ -312,7 +312,8 @@ void PoolReplayer::init() { dout(10) << "connected to " << m_peer << dendl; - m_image_sync_throttler.reset(ImageSyncThrottler::create(cct)); + m_image_sync_throttler.reset( + Throttler::create(cct, "rbd_mirror_concurrent_image_syncs")); m_default_namespace_replayer.reset(NamespaceReplayer::create( "", m_local_io_ctx, m_remote_io_ctx, m_local_mirror_uuid, m_peer.uuid, diff --git a/src/tools/rbd_mirror/PoolReplayer.h b/src/tools/rbd_mirror/PoolReplayer.h index 039a420c67501..33a8eebd3bf74 100644 --- a/src/tools/rbd_mirror/PoolReplayer.h +++ b/src/tools/rbd_mirror/PoolReplayer.h @@ -10,9 +10,9 @@ #include "include/rados/librados.hpp" #include "librbd/Utils.h" -#include "tools/rbd_mirror/ImageSyncThrottler.h" #include "tools/rbd_mirror/LeaderWatcher.h" #include "tools/rbd_mirror/NamespaceReplayer.h" +#include "tools/rbd_mirror/Throttler.h" #include "tools/rbd_mirror/Types.h" #include "tools/rbd_mirror/leader_watcher/Types.h" #include "tools/rbd_mirror/service_daemon/Types.h" @@ -259,7 +259,7 @@ private: } m_leader_listener; std::unique_ptr> m_leader_watcher; - std::unique_ptr> m_image_sync_throttler; + std::unique_ptr> m_image_sync_throttler; }; } // namespace mirror diff --git a/src/tools/rbd_mirror/ImageSyncThrottler.cc b/src/tools/rbd_mirror/Throttler.cc similarity index 66% rename from src/tools/rbd_mirror/ImageSyncThrottler.cc rename to src/tools/rbd_mirror/Throttler.cc index f2d0be97df0d1..ed377f1b061d3 100644 --- a/src/tools/rbd_mirror/ImageSyncThrottler.cc +++ b/src/tools/rbd_mirror/Throttler.cc @@ -12,7 +12,7 @@ * */ -#include "ImageSyncThrottler.h" +#include "Throttler.h" #include "common/Formatter.h" #include "common/debug.h" #include "common/errno.h" @@ -21,26 +21,25 @@ #define dout_context g_ceph_context #define dout_subsys ceph_subsys_rbd_mirror #undef dout_prefix -#define dout_prefix *_dout << "rbd::mirror::ImageSyncThrottler:: " << this \ +#define dout_prefix *_dout << "rbd::mirror::Throttler:: " << this \ << " " << __func__ << ": " namespace rbd { namespace mirror { template -ImageSyncThrottler::ImageSyncThrottler(CephContext *cct) - : m_cct(cct), +Throttler::Throttler(CephContext *cct, const std::string &config_key) + : m_cct(cct), m_config_key(config_key), + m_config_keys{m_config_key.c_str(), nullptr}, m_lock(ceph::make_mutex( - librbd::util::unique_lock_name("rbd::mirror::ImageSyncThrottler", - this))), - m_max_concurrent_syncs(cct->_conf.get_val( - "rbd_mirror_concurrent_image_syncs")) { - dout(20) << "max_concurrent_syncs=" << m_max_concurrent_syncs << dendl; + librbd::util::unique_lock_name("rbd::mirror::Throttler", this))), + m_max_concurrent_ops(cct->_conf.get_val(m_config_key)) { + dout(20) << m_config_key << "=" << m_max_concurrent_ops << dendl; m_cct->_conf.add_observer(this); } template -ImageSyncThrottler::~ImageSyncThrottler() { +Throttler::~Throttler() { m_cct->_conf.remove_observer(this); std::lock_guard locker{m_lock}; @@ -49,7 +48,7 @@ ImageSyncThrottler::~ImageSyncThrottler() { } template -void ImageSyncThrottler::start_op(const std::string &ns, +void Throttler::start_op(const std::string &ns, const std::string &id_, Context *on_start) { Id id{ns, id_}; @@ -66,17 +65,17 @@ void ImageSyncThrottler::start_op(const std::string &ns, dout(20) << "duplicate for already queued op " << id << dendl; std::swap(m_queued_ops[id], on_start); r = -ENOENT; - } else if (m_max_concurrent_syncs == 0 || - m_inflight_ops.size() < m_max_concurrent_syncs) { + } else if (m_max_concurrent_ops == 0 || + m_inflight_ops.size() < m_max_concurrent_ops) { ceph_assert(m_queue.empty()); m_inflight_ops.insert(id); - dout(20) << "ready to start sync for " << id << " [" - << m_inflight_ops.size() << "/" << m_max_concurrent_syncs << "]" + dout(20) << "ready to start op for " << id << " [" + << m_inflight_ops.size() << "/" << m_max_concurrent_ops << "]" << dendl; } else { m_queue.push_back(id); std::swap(m_queued_ops[id], on_start); - dout(20) << "image sync for " << id << " has been queued" << dendl; + dout(20) << "op for " << id << " has been queued" << dendl; } } @@ -86,7 +85,7 @@ void ImageSyncThrottler::start_op(const std::string &ns, } template -bool ImageSyncThrottler::cancel_op(const std::string &ns, +bool Throttler::cancel_op(const std::string &ns, const std::string &id_) { Id id{ns, id_}; @@ -97,7 +96,7 @@ bool ImageSyncThrottler::cancel_op(const std::string &ns, std::lock_guard locker{m_lock}; auto it = m_queued_ops.find(id); if (it != m_queued_ops.end()) { - dout(20) << "canceled queued sync for " << id << dendl; + dout(20) << "canceled queued op for " << id << dendl; m_queue.remove(id); on_start = it->second; m_queued_ops.erase(it); @@ -113,7 +112,7 @@ bool ImageSyncThrottler::cancel_op(const std::string &ns, } template -void ImageSyncThrottler::finish_op(const std::string &ns, +void Throttler::finish_op(const std::string &ns, const std::string &id_) { Id id{ns, id_}; @@ -129,13 +128,13 @@ void ImageSyncThrottler::finish_op(const std::string &ns, m_inflight_ops.erase(id); - if (m_inflight_ops.size() < m_max_concurrent_syncs && !m_queue.empty()) { + if (m_inflight_ops.size() < m_max_concurrent_ops && !m_queue.empty()) { auto id = m_queue.front(); auto it = m_queued_ops.find(id); ceph_assert(it != m_queued_ops.end()); m_inflight_ops.insert(id); - dout(20) << "ready to start sync for " << id << " [" - << m_inflight_ops.size() << "/" << m_max_concurrent_syncs << "]" + dout(20) << "ready to start op for " << id << " [" + << m_inflight_ops.size() << "/" << m_max_concurrent_ops << "]" << dendl; on_start = it->second; m_queued_ops.erase(it); @@ -149,7 +148,7 @@ void ImageSyncThrottler::finish_op(const std::string &ns, } template -void ImageSyncThrottler::drain(const std::string &ns, int r) { +void Throttler::drain(const std::string &ns, int r) { dout(20) << "ns=" << ns << dendl; std::map queued_ops; @@ -181,22 +180,22 @@ void ImageSyncThrottler::drain(const std::string &ns, int r) { } template -void ImageSyncThrottler::set_max_concurrent_syncs(uint32_t max) { +void Throttler::set_max_concurrent_ops(uint32_t max) { dout(20) << "max=" << max << dendl; std::list ops; { std::lock_guard locker{m_lock}; - m_max_concurrent_syncs = max; + m_max_concurrent_ops = max; // Start waiting ops in the case of available free slots - while ((m_max_concurrent_syncs == 0 || - m_inflight_ops.size() < m_max_concurrent_syncs) && + while ((m_max_concurrent_ops == 0 || + m_inflight_ops.size() < m_max_concurrent_ops) && !m_queue.empty()) { auto id = m_queue.front(); m_inflight_ops.insert(id); - dout(20) << "ready to start sync for " << id << " [" - << m_inflight_ops.size() << "/" << m_max_concurrent_syncs << "]" + dout(20) << "ready to start op for " << id << " [" + << m_inflight_ops.size() << "/" << m_max_concurrent_ops << "]" << dendl; auto it = m_queued_ops.find(id); ceph_assert(it != m_queued_ops.end()); @@ -212,42 +211,38 @@ void ImageSyncThrottler::set_max_concurrent_syncs(uint32_t max) { } template -void ImageSyncThrottler::print_status(ceph::Formatter *f, std::stringstream *ss) { +void Throttler::print_status(ceph::Formatter *f, std::stringstream *ss) { dout(20) << dendl; std::lock_guard locker{m_lock}; if (f) { - f->dump_int("max_parallel_syncs", m_max_concurrent_syncs); - f->dump_int("running_syncs", m_inflight_ops.size()); - f->dump_int("waiting_syncs", m_queue.size()); + f->dump_int("max_parallel_requests", m_max_concurrent_ops); + f->dump_int("running_requests", m_inflight_ops.size()); + f->dump_int("waiting_requests", m_queue.size()); f->flush(*ss); } else { *ss << "[ "; - *ss << "max_parallel_syncs=" << m_max_concurrent_syncs << ", "; - *ss << "running_syncs=" << m_inflight_ops.size() << ", "; - *ss << "waiting_syncs=" << m_queue.size() << " ]"; + *ss << "max_parallel_requests=" << m_max_concurrent_ops << ", "; + *ss << "running_requests=" << m_inflight_ops.size() << ", "; + *ss << "waiting_requests=" << m_queue.size() << " ]"; } } template -const char** ImageSyncThrottler::get_tracked_conf_keys() const { - static const char* KEYS[] = { - "rbd_mirror_concurrent_image_syncs", - NULL - }; - return KEYS; +const char** Throttler::get_tracked_conf_keys() const { + return m_config_keys; } template -void ImageSyncThrottler::handle_conf_change(const ConfigProxy& conf, +void Throttler::handle_conf_change(const ConfigProxy& conf, const set &changed) { - if (changed.count("rbd_mirror_concurrent_image_syncs")) { - set_max_concurrent_syncs(conf.get_val("rbd_mirror_concurrent_image_syncs")); + if (changed.count(m_config_key)) { + set_max_concurrent_ops(conf.get_val(m_config_key)); } } } // namespace mirror } // namespace rbd -template class rbd::mirror::ImageSyncThrottler; +template class rbd::mirror::Throttler; diff --git a/src/tools/rbd_mirror/ImageSyncThrottler.h b/src/tools/rbd_mirror/Throttler.h similarity index 68% rename from src/tools/rbd_mirror/ImageSyncThrottler.h rename to src/tools/rbd_mirror/Throttler.h index 278b7c3061f20..f92c032729bda 100644 --- a/src/tools/rbd_mirror/ImageSyncThrottler.h +++ b/src/tools/rbd_mirror/Throttler.h @@ -1,8 +1,8 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab -#ifndef RBD_MIRROR_IMAGE_SYNC_THROTTLER_H -#define RBD_MIRROR_IMAGE_SYNC_THROTTLER_H +#ifndef RBD_MIRROR_THROTTLER_H +#define RBD_MIRROR_THROTTLER_H #include #include @@ -24,19 +24,22 @@ namespace rbd { namespace mirror { template -class ImageSyncThrottler : public md_config_obs_t { +class Throttler : public md_config_obs_t { public: - static ImageSyncThrottler *create(CephContext *cct) { - return new ImageSyncThrottler(cct); + static Throttler *create( + CephContext *cct, + const std::string &config_key) { + return new Throttler(cct, config_key); } void destroy() { delete this; } - ImageSyncThrottler(CephContext *cct); - ~ImageSyncThrottler() override; + Throttler(CephContext *cct, + const std::string &config_key); + ~Throttler() override; - void set_max_concurrent_syncs(uint32_t max); + void set_max_concurrent_ops(uint32_t max); void start_op(const std::string &ns, const std::string &id, Context *on_start); bool cancel_op(const std::string &ns, const std::string &id); @@ -47,10 +50,13 @@ public: private: typedef std::pair Id; - + CephContext *m_cct; + const std::string m_config_key; + mutable const char* m_config_keys[2]; + ceph::mutex m_lock; - uint32_t m_max_concurrent_syncs; + uint32_t m_max_concurrent_ops; std::list m_queue; std::map m_queued_ops; std::set m_inflight_ops; @@ -63,6 +69,6 @@ private: } // namespace mirror } // namespace rbd -extern template class rbd::mirror::ImageSyncThrottler; +extern template class rbd::mirror::Throttler; -#endif // RBD_MIRROR_IMAGE_SYNC_THROTTLER_H +#endif // RBD_MIRROR_THROTTLER_H -- 2.39.5