From 528790781b503ad4dfce4dad85d7dcbf761014eb Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Thu, 20 Apr 2017 21:23:43 -0400 Subject: [PATCH] rbd-mirror: remove image name retrieval from pool watcher Signed-off-by: Jason Dillaman --- .../test_mock_RefreshImagesRequest.cc | 39 +--- src/test/rbd_mirror/test_PoolWatcher.cc | 4 +- src/test/rbd_mirror/test_mock_PoolWatcher.cc | 166 ++---------------- src/tools/rbd_mirror/PoolWatcher.cc | 134 +------------- src/tools/rbd_mirror/PoolWatcher.h | 34 ---- .../pool_watcher/RefreshImagesRequest.cc | 65 +------ .../pool_watcher/RefreshImagesRequest.h | 12 -- src/tools/rbd_mirror/types.cc | 3 +- src/tools/rbd_mirror/types.h | 8 +- 9 files changed, 38 insertions(+), 427 deletions(-) diff --git a/src/test/rbd_mirror/pool_watcher/test_mock_RefreshImagesRequest.cc b/src/test/rbd_mirror/pool_watcher/test_mock_RefreshImagesRequest.cc index 1e92670d8a5..0795fcdd445 100644 --- a/src/test/rbd_mirror/pool_watcher/test_mock_RefreshImagesRequest.cc +++ b/src/test/rbd_mirror/pool_watcher/test_mock_RefreshImagesRequest.cc @@ -54,24 +54,11 @@ public: Return(r))); } - void expect_dir_list(librados::IoCtx &io_ctx, - const std::map &ids, int r) { - bufferlist bl; - ::encode(ids, bl); - - EXPECT_CALL(get_mock_io_ctx(io_ctx), - exec(RBD_DIRECTORY, _, StrEq("rbd"), StrEq("dir_list"), _, _, _)) - .WillOnce(DoAll(WithArg<5>(Invoke([bl](bufferlist *out_bl) { - *out_bl = bl; - })), - Return(r))); - } }; TEST_F(TestMockPoolWatcherRefreshImagesRequest, Success) { InSequence seq; expect_mirror_image_list(m_remote_io_ctx, {{"local id", "global id"}}, 0); - expect_dir_list(m_remote_io_ctx, {{"image name", "local id"}}, 0); C_SaferCond ctx; ImageIds image_ids; @@ -81,29 +68,23 @@ TEST_F(TestMockPoolWatcherRefreshImagesRequest, Success) { req->send(); ASSERT_EQ(0, ctx.wait()); - ImageIds expected_image_ids = {{"global id", "local id", "image name"}}; + ImageIds expected_image_ids = {{"global id", "local id"}}; ASSERT_EQ(expected_image_ids, image_ids); } TEST_F(TestMockPoolWatcherRefreshImagesRequest, LargeDirectory) { InSequence seq; std::map mirror_list; - std::map dir_list; ImageIds expected_image_ids; for (uint32_t idx = 1; idx <= 1024; ++idx) { mirror_list.insert(std::make_pair("local id " + stringify(idx), "global id " + stringify(idx))); - dir_list.insert(std::make_pair("image " + stringify(idx), - "local id " + stringify(idx))); expected_image_ids.insert({{"global id " + stringify(idx), - "local id " + stringify(idx), - "image " + stringify(idx)}}); + "local id " + stringify(idx)}}); } expect_mirror_image_list(m_remote_io_ctx, mirror_list, 0); expect_mirror_image_list(m_remote_io_ctx, {{"local id", "global id"}}, 0); - expect_dir_list(m_remote_io_ctx, dir_list, 0); - expect_dir_list(m_remote_io_ctx, {{"image name", "local id"}}, 0); C_SaferCond ctx; ImageIds image_ids; @@ -113,7 +94,7 @@ TEST_F(TestMockPoolWatcherRefreshImagesRequest, LargeDirectory) { req->send(); ASSERT_EQ(0, ctx.wait()); - expected_image_ids.insert({"global id", "local id", "image name"}); + expected_image_ids.insert({"global id", "local id"}); ASSERT_EQ(expected_image_ids, image_ids); } @@ -130,20 +111,6 @@ TEST_F(TestMockPoolWatcherRefreshImagesRequest, MirrorImageListError) { ASSERT_EQ(-EINVAL, ctx.wait()); } -TEST_F(TestMockPoolWatcherRefreshImagesRequest, DirListError) { - InSequence seq; - expect_mirror_image_list(m_remote_io_ctx, {{"local id", "global id"}}, 0); - expect_dir_list(m_remote_io_ctx, {{"image name", "local id"}}, -EINVAL); - - C_SaferCond ctx; - ImageIds image_ids; - MockRefreshImagesRequest *req = new MockRefreshImagesRequest( - m_remote_io_ctx, &image_ids, &ctx); - - req->send(); - ASSERT_EQ(-EINVAL, ctx.wait()); -} - } // namespace pool_watcher } // namespace mirror } // namespace rbd diff --git a/src/test/rbd_mirror/test_PoolWatcher.cc b/src/test/rbd_mirror/test_PoolWatcher.cc index dd857423ee0..9d11c715638 100644 --- a/src/test/rbd_mirror/test_PoolWatcher.cc +++ b/src/test/rbd_mirror/test_PoolWatcher.cc @@ -148,7 +148,7 @@ public: image.close(); m_mirrored_images.insert(ImageId( - mirror_image_info.global_id, get_image_id(&ioctx, name), name)); + mirror_image_info.global_id, get_image_id(&ioctx, name))); } if (image_name != nullptr) *image_name = name; @@ -195,7 +195,7 @@ public: image.close(); m_mirrored_images.insert(ImageId( - mirror_image_info.global_id, get_image_id(&cioctx, name), name)); + mirror_image_info.global_id, get_image_id(&cioctx, name))); } if (image_name != nullptr) *image_name = name; diff --git a/src/test/rbd_mirror/test_mock_PoolWatcher.cc b/src/test/rbd_mirror/test_mock_PoolWatcher.cc index ebb26b9f223..b6e61516dce 100644 --- a/src/test/rbd_mirror/test_mock_PoolWatcher.cc +++ b/src/test/rbd_mirror/test_mock_PoolWatcher.cc @@ -231,26 +231,6 @@ public: Return(r))); } - void expect_dir_list(librados::IoCtx &io_ctx, - const std::string &id, const std::string &name, int r) { - bufferlist in_bl; - ::encode(id, in_bl); - - bufferlist out_bl; - ::encode(name, out_bl); - - EXPECT_CALL(get_mock_io_ctx(io_ctx), - exec(RBD_DIRECTORY, _, StrEq("rbd"), StrEq("dir_get_name"), - ContentsEqual(in_bl), _, _)) - .WillOnce(DoAll(WithArg<5>(Invoke([this, out_bl](bufferlist *bl) { - *bl = out_bl; - Mutex::Locker locker(m_lock); - ++m_get_name_count; - m_cond.Signal(); - })), - Return(r))); - } - void expect_timer_add_event(MockThreads &mock_threads) { EXPECT_CALL(*mock_threads.timer, add_event_after(_, _)) .WillOnce(WithArg<1>(Invoke([this](Context *ctx) { @@ -283,25 +263,9 @@ public: return true; } - bool wait_for_get_name(uint32_t count) { - Mutex::Locker locker(m_lock); - while (m_get_name_count < count) { - if (m_cond.WaitInterval(m_lock, utime_t(10, 0)) != 0) { - break; - } - } - if (m_get_name_count < count) { - return false; - } - - m_get_name_count -= count; - return true; - } - Mutex m_lock; Cond m_cond; uint32_t m_update_count = 0; - uint32_t m_get_name_count = 0; }; TEST_F(TestMockPoolWatcher, EmptyPool) { @@ -341,8 +305,8 @@ TEST_F(TestMockPoolWatcher, NonEmptyPool) { expect_mirroring_watcher_register(mock_mirroring_watcher, 0); ImageIds image_ids{ - {"global id 1", "remote id 1", "image name 1"}, - {"global id 2", "remote id 2", "image name 2"}}; + {"global id 1", "remote id 1"}, + {"global id 2", "remote id 2"}}; MockRefreshImagesRequest mock_refresh_images_request; expect_refresh_images(mock_refresh_images_request, image_ids, 0); expect_mirror_uuid_get(m_remote_io_ctx, "remote uuid", 0); @@ -371,8 +335,8 @@ TEST_F(TestMockPoolWatcher, NotifyDuringRefresh) { expect_mirroring_watcher_register(mock_mirroring_watcher, 0); ImageIds image_ids{ - {"global id 1", "remote id 1", "image name 1"}, - {"global id 2", "remote id 2", "image name 2"}}; + {"global id 1", "remote id 1"}, + {"global id 2", "remote id 2"}}; MockRefreshImagesRequest mock_refresh_images_request; bool refresh_sent = false; EXPECT_CALL(mock_refresh_images_request, send()) @@ -385,16 +349,12 @@ TEST_F(TestMockPoolWatcher, NotifyDuringRefresh) { m_cond.Signal(); })); - expect_dir_list(m_remote_io_ctx, "remote id 1a", "image name 1a", 0); - expect_dir_list(m_remote_io_ctx, "remote id 3", "image name 3", 0); - expect_dir_list(m_remote_io_ctx, "dummy", "", -ENOENT); - expect_mirror_uuid_get(m_remote_io_ctx, "remote uuid", 0); MockListener mock_listener(this); image_ids = { - {"global id 1", "remote id 1a", "image name 1a"}, - {"global id 3", "remote id 3", "image name 3"}}; + {"global id 1", "remote id 1a"}, + {"global id 3", "remote id 3"}}; expect_listener_handle_update(mock_listener, "remote uuid", image_ids, {}); MockPoolWatcher mock_pool_watcher(&mock_threads, m_remote_io_ctx, @@ -414,9 +374,6 @@ TEST_F(TestMockPoolWatcher, NotifyDuringRefresh) { cls::rbd::MIRROR_IMAGE_STATE_ENABLED, "remote id 1a", "global id 1"); MirroringWatcher::get_instance().handle_image_updated( cls::rbd::MIRROR_IMAGE_STATE_ENABLED, "remote id 3", "global id 3"); - MirroringWatcher::get_instance().handle_image_updated( - cls::rbd::MIRROR_IMAGE_STATE_ENABLED, "dummy", "dummy"); - wait_for_get_name(3); mock_refresh_images_request.on_finish->complete(0); ASSERT_TRUE(wait_for_update(1)); @@ -434,8 +391,8 @@ TEST_F(TestMockPoolWatcher, Notify) { expect_mirroring_watcher_register(mock_mirroring_watcher, 0); ImageIds image_ids{ - {"global id 1", "remote id 1", "image name 1"}, - {"global id 2", "remote id 2", "image name 2"}}; + {"global id 1", "remote id 1"}, + {"global id 2", "remote id 2"}}; MockRefreshImagesRequest mock_refresh_images_request; expect_refresh_images(mock_refresh_images_request, image_ids, 0); expect_mirror_uuid_get(m_remote_io_ctx, "remote uuid", 0); @@ -456,15 +413,10 @@ TEST_F(TestMockPoolWatcher, Notify) { notify_ctx = ctx; m_cond.Signal(); })); - expect_dir_list(m_remote_io_ctx, "remote id 1a", "image name 1a", 0); - expect_dir_list(m_remote_io_ctx, "remote id 3", "image name 3", 0); - expect_dir_list(m_remote_io_ctx, "dummy", "", -ENOENT); expect_listener_handle_update( mock_listener, "remote uuid", - {{"global id 1", "remote id 1a", "image name 1a"}, - {"global id 3", "remote id 3", "image name 3"}}, - {{"global id 1", "remote id 1", "image name 1"}, - {"global id 2", "remote id 2", "image name 2"}}); + {{"global id 1", "remote id 1a"}, {"global id 3", "remote id 3"}}, + {{"global id 1", "remote id 1"}, {"global id 2", "remote id 2"}}); MockPoolWatcher mock_pool_watcher(&mock_threads, m_remote_io_ctx, mock_listener); @@ -485,9 +437,6 @@ TEST_F(TestMockPoolWatcher, Notify) { cls::rbd::MIRROR_IMAGE_STATE_ENABLED, "remote id 1a", "global id 1"); MirroringWatcher::get_instance().handle_image_updated( cls::rbd::MIRROR_IMAGE_STATE_ENABLED, "remote id 3", "global id 3"); - MirroringWatcher::get_instance().handle_image_updated( - cls::rbd::MIRROR_IMAGE_STATE_ENABLED, "dummy", "dummy"); - ASSERT_TRUE(wait_for_get_name(3)); notify_ctx->complete(0); ASSERT_TRUE(wait_for_update(1)); @@ -768,10 +717,10 @@ TEST_F(TestMockPoolWatcher, Rewatch) { expect_timer_add_event(mock_threads); expect_mirroring_watcher_is_unregistered(mock_mirroring_watcher, false); - expect_refresh_images(mock_refresh_images_request, {{"global id", "image id", "name"}}, 0); + expect_refresh_images(mock_refresh_images_request, {{"global id", "image id"}}, 0); expect_mirror_uuid_get(m_remote_io_ctx, "remote uuid", 0); expect_listener_handle_update(mock_listener, "remote uuid", - {{"global id", "image id", "name"}}, {}); + {{"global id", "image id"}}, {}); MockPoolWatcher mock_pool_watcher(&mock_threads, m_remote_io_ctx, mock_listener); @@ -835,10 +784,10 @@ TEST_F(TestMockPoolWatcher, RewatchError) { expect_timer_add_event(mock_threads); expect_mirroring_watcher_is_unregistered(mock_mirroring_watcher, false); - expect_refresh_images(mock_refresh_images_request, {{"global id", "image id", "name"}}, 0); + expect_refresh_images(mock_refresh_images_request, {{"global id", "image id"}}, 0); expect_mirror_uuid_get(m_remote_io_ctx, "remote uuid", 0); expect_listener_handle_update(mock_listener, "remote uuid", - {{"global id", "image id", "name"}}, {}); + {{"global id", "image id"}}, {}); MockPoolWatcher mock_pool_watcher(&mock_threads, m_remote_io_ctx, mock_listener); @@ -854,86 +803,6 @@ TEST_F(TestMockPoolWatcher, RewatchError) { ASSERT_EQ(0, when_shut_down(mock_pool_watcher)); } -TEST_F(TestMockPoolWatcher, GetImageNameBlacklist) { - MockThreads mock_threads(m_threads); - expect_work_queue(mock_threads); - - InSequence seq; - MockMirroringWatcher mock_mirroring_watcher; - expect_mirroring_watcher_is_unregistered(mock_mirroring_watcher, true); - expect_mirroring_watcher_register(mock_mirroring_watcher, 0); - - MockRefreshImagesRequest mock_refresh_images_request; - expect_refresh_images(mock_refresh_images_request, {}, 0); - expect_mirror_uuid_get(m_remote_io_ctx, "remote uuid", 0); - - MockListener mock_listener(this); - expect_listener_handle_update(mock_listener, "remote uuid", {}, {}); - - expect_dir_list(m_remote_io_ctx, "remote id", "image name", -EBLACKLISTED); - - MockPoolWatcher mock_pool_watcher(&mock_threads, m_remote_io_ctx, - mock_listener); - C_SaferCond ctx; - mock_pool_watcher.init(&ctx); - ASSERT_EQ(0, ctx.wait()); - ASSERT_TRUE(wait_for_update(1)); - - MirroringWatcher::get_instance().handle_image_updated( - cls::rbd::MIRROR_IMAGE_STATE_ENABLED, "remote id", "global id"); - ASSERT_TRUE(wait_for_get_name(1)); - while (true) { - if (mock_pool_watcher.is_blacklisted()) { - break; - } - usleep(1000); - } - - expect_mirroring_watcher_unregister(mock_mirroring_watcher, 0); - ASSERT_EQ(0, when_shut_down(mock_pool_watcher)); -} - -TEST_F(TestMockPoolWatcher, GetImageNameError) { - MockThreads mock_threads(m_threads); - expect_work_queue(mock_threads); - - InSequence seq; - MockMirroringWatcher mock_mirroring_watcher; - expect_mirroring_watcher_is_unregistered(mock_mirroring_watcher, true); - expect_mirroring_watcher_register(mock_mirroring_watcher, 0); - - MockRefreshImagesRequest mock_refresh_images_request; - expect_refresh_images(mock_refresh_images_request, {}, 0); - expect_mirror_uuid_get(m_remote_io_ctx, "remote uuid", 0); - - MockListener mock_listener(this); - expect_listener_handle_update(mock_listener, "remote uuid", {}, {}); - - expect_dir_list(m_remote_io_ctx, "remote id", "image name", -EINVAL); - expect_timer_add_event(mock_threads); - - expect_mirroring_watcher_is_unregistered(mock_mirroring_watcher, false); - expect_refresh_images(mock_refresh_images_request, {{"global id", "remote id", "name"}}, 0); - expect_mirror_uuid_get(m_remote_io_ctx, "remote uuid", 0); - expect_listener_handle_update(mock_listener, "remote uuid", - {{"global id", "remote id", "name"}}, {}); - - MockPoolWatcher mock_pool_watcher(&mock_threads, m_remote_io_ctx, - mock_listener); - C_SaferCond ctx; - mock_pool_watcher.init(&ctx); - ASSERT_EQ(0, ctx.wait()); - ASSERT_TRUE(wait_for_update(1)); - - MirroringWatcher::get_instance().handle_image_updated( - cls::rbd::MIRROR_IMAGE_STATE_ENABLED, "remote id", "global id"); - ASSERT_TRUE(wait_for_get_name(1)); - ASSERT_TRUE(wait_for_update(1)); - - expect_mirroring_watcher_unregister(mock_mirroring_watcher, 0); - ASSERT_EQ(0, when_shut_down(mock_pool_watcher)); -} - TEST_F(TestMockPoolWatcher, DeferredRefresh) { MockThreads mock_threads(m_threads); expect_work_queue(mock_threads); @@ -982,8 +851,8 @@ TEST_F(TestMockPoolWatcher, MirrorUuidUpdated) { expect_mirroring_watcher_register(mock_mirroring_watcher, 0); ImageIds image_ids{ - {"global id 1", "remote id 1", "image name 1"}, - {"global id 2", "remote id 2", "image name 2"}}; + {"global id 1", "remote id 1"}, + {"global id 2", "remote id 2"}}; MockRefreshImagesRequest mock_refresh_images_request; expect_refresh_images(mock_refresh_images_request, image_ids, 0); expect_mirror_uuid_get(m_remote_io_ctx, "remote uuid", 0); @@ -1001,7 +870,7 @@ TEST_F(TestMockPoolWatcher, MirrorUuidUpdated) { expect_timer_add_event(mock_threads); ImageIds new_image_ids{ - {"global id 1", "remote id 1", "image name 1"}}; + {"global id 1", "remote id 1"}}; expect_mirroring_watcher_is_unregistered(mock_mirroring_watcher, false); expect_refresh_images(mock_refresh_images_request, new_image_ids, 0); expect_mirror_uuid_get(m_remote_io_ctx, "updated uuid", 0); @@ -1015,5 +884,6 @@ TEST_F(TestMockPoolWatcher, MirrorUuidUpdated) { expect_mirroring_watcher_unregister(mock_mirroring_watcher, 0); ASSERT_EQ(0, when_shut_down(mock_pool_watcher)); } + } // namespace mirror } // namespace rbd diff --git a/src/tools/rbd_mirror/PoolWatcher.cc b/src/tools/rbd_mirror/PoolWatcher.cc index 7bdd8cdb09e..6a855ff2185 100644 --- a/src/tools/rbd_mirror/PoolWatcher.cc +++ b/src/tools/rbd_mirror/PoolWatcher.cc @@ -217,18 +217,6 @@ void PoolWatcher::refresh_images() { // a full image list refresh m_pending_added_image_ids.clear(); m_pending_removed_image_ids.clear(); - if (!m_updated_images.empty()) { - auto it = m_updated_images.begin(); - it->invalid = true; - - // only have a single in-flight request -- remove the rest - ++it; - while (it != m_updated_images.end()) { - m_id_to_updated_images.erase({it->global_image_id, - it->remote_image_id}); - it = m_updated_images.erase(it); - } - } } m_async_op_tracker.start_op(); @@ -413,110 +401,15 @@ void PoolWatcher::handle_image_updated(const std::string &remote_image_id, m_pending_added_image_ids.erase(image_id); m_pending_removed_image_ids.erase(image_id); - auto id = std::make_pair(global_image_id, remote_image_id); - auto id_it = m_id_to_updated_images.find(id); - if (id_it != m_id_to_updated_images.end()) { - id_it->second->enabled = enabled; - id_it->second->invalid = false; - } else if (enabled) { - // need to resolve the image name before notifying listener - auto it = m_updated_images.emplace(m_updated_images.end(), - global_image_id, remote_image_id); - m_id_to_updated_images[id] = it; - schedule_get_image_name(); + if (enabled) { + m_pending_added_image_ids.insert(image_id); + schedule_listener(); } else { - // delete image w/ if no resolve name in-flight m_pending_removed_image_ids.insert(image_id); schedule_listener(); } } -template -void PoolWatcher::schedule_get_image_name() { - assert(m_lock.is_locked()); - if (m_shutting_down || m_blacklisted || m_updated_images.empty() || - m_get_name_in_progress) { - return; - } - m_get_name_in_progress = true; - - auto &updated_image = m_updated_images.front(); - dout(10) << "global_image_id=" << updated_image.global_image_id << ", " - << "remote_image_id=" << updated_image.remote_image_id << dendl; - - librados::ObjectReadOperation op; - librbd::cls_client::dir_get_name_start(&op, updated_image.remote_image_id); - - m_async_op_tracker.start_op(); - - m_out_bl.clear(); - librados::AioCompletion *aio_comp = create_rados_callback< - PoolWatcher, &PoolWatcher::handle_get_image_name>(this); - int r = m_remote_io_ctx.aio_operate(RBD_DIRECTORY, aio_comp, &op, &m_out_bl); - assert(r == 0); - aio_comp->release(); -} - -template -void PoolWatcher::handle_get_image_name(int r) { - dout(10) << "r=" << r << dendl; - - std::string name; - if (r == 0) { - bufferlist::iterator it = m_out_bl.begin(); - r = librbd::cls_client::dir_get_name_finish(&it, &name); - } - - bool image_ids_invalid = false; - { - Mutex::Locker locker(m_lock); - assert(!m_updated_images.empty()); - m_get_name_in_progress = false; - - auto updated_image = m_updated_images.front(); - m_updated_images.pop_front(); - m_id_to_updated_images.erase(std::make_pair(updated_image.global_image_id, - updated_image.remote_image_id)); - - if (r == 0) { - // since names are resolved in event order -- the current update is - // the latest state - ImageId image_id(updated_image.global_image_id, - updated_image.remote_image_id, name); - m_pending_added_image_ids.erase(image_id); - m_pending_removed_image_ids.erase(image_id); - if (!updated_image.invalid) { - if (updated_image.enabled) { - m_pending_added_image_ids.insert(image_id); - } else { - m_pending_removed_image_ids.insert(image_id); - } - schedule_listener(); - } - } else if (r == -EBLACKLISTED) { - dout(0) << "detected client is blacklisted" << dendl; - - m_blacklisted = true; - } else if (r == -ENOENT) { - dout(10) << "image removed after add notification" << dendl; - } else { - derr << "error resolving image name " << updated_image.remote_image_id - << " (" << updated_image.global_image_id << "): " << cpp_strerror(r) - << dendl; - image_ids_invalid = true; - } - - if (!image_ids_invalid) { - schedule_get_image_name(); - } - } - - if (image_ids_invalid) { - schedule_refresh_images(5); - } - m_async_op_tracker.finish_op(); -} - template void PoolWatcher::process_refresh_images() { assert(m_threads->timer_lock.is_locked()); @@ -603,24 +496,9 @@ void PoolWatcher::notify_listener() { // merge add/remove notifications into pending set (a given image // can only be in one set or another) - for (auto it = m_pending_removed_image_ids.begin(); - it != m_pending_removed_image_ids.end(); ) { - if (std::find_if(m_updated_images.begin(), m_updated_images.end(), - [&it](const UpdatedImage &updated_image) { - return (it->id == updated_image.remote_image_id); - }) != m_updated_images.end()) { - // still resolving the name -- so keep it in the pending set - auto image_id_it = m_image_ids.find(*it); - if (image_id_it != m_image_ids.end()) { - m_pending_image_ids.insert(*image_id_it); - } - ++it; - continue; - } - - // merge the remove event into the pending set - m_pending_image_ids.erase(*it); - it = m_pending_removed_image_ids.erase(it); + for (auto &image_id : m_pending_removed_image_ids) { + dout(20) << "image_id=" << image_id << dendl; + m_pending_image_ids.erase(image_id); } for (auto &image_id : m_pending_added_image_ids) { diff --git a/src/tools/rbd_mirror/PoolWatcher.h b/src/tools/rbd_mirror/PoolWatcher.h index 747a0ee5dc8..aebd981b864 100644 --- a/src/tools/rbd_mirror/PoolWatcher.h +++ b/src/tools/rbd_mirror/PoolWatcher.h @@ -14,8 +14,6 @@ #include "common/Mutex.h" #include "include/rados/librados.hpp" #include "types.h" -#include -#include #include #include #include "include/assert.h" @@ -101,31 +99,6 @@ private: */ class MirroringWatcher; - struct UpdatedImage { - std::string global_image_id; - std::string remote_image_id; - bool enabled = true; - bool invalid = false; - - UpdatedImage(const std::string &global_image_id, - const std::string &remote_image_id) - : global_image_id(global_image_id), remote_image_id(remote_image_id) { - } - }; - - typedef std::pair GlobalRemoteIds; - typedef std::list UpdatedImages; - typedef std::unordered_map > IdToUpdatedImages; - - struct StrictImageIdCompare { - bool operator()(const ImageId &lhs, const ImageId &rhs) const { - if (lhs.global_id != rhs.global_id) { - return lhs.global_id < rhs.global_id; - } - return lhs.id < rhs.id; - } - }; Threads *m_threads; librados::IoCtx m_remote_io_ctx; Listener &m_listener; @@ -159,10 +132,6 @@ private: bool m_refresh_in_progress = false; bool m_deferred_refresh = false; - UpdatedImages m_updated_images; - IdToUpdatedImages m_id_to_updated_images; - bool m_get_name_in_progress = false; - void register_watcher(); void handle_register_watcher(int r); void unregister_watcher(); @@ -181,9 +150,6 @@ private: const std::string &global_image_id, bool enabled); - void schedule_get_image_name(); - void handle_get_image_name(int r); - void schedule_listener(); void notify_listener(); diff --git a/src/tools/rbd_mirror/pool_watcher/RefreshImagesRequest.cc b/src/tools/rbd_mirror/pool_watcher/RefreshImagesRequest.cc index c387ecea789..1a6ed8c0541 100644 --- a/src/tools/rbd_mirror/pool_watcher/RefreshImagesRequest.cc +++ b/src/tools/rbd_mirror/pool_watcher/RefreshImagesRequest.cc @@ -24,6 +24,7 @@ using librbd::util::create_rados_callback; template void RefreshImagesRequest::send() { + m_image_ids->clear(); mirror_image_list(); } @@ -58,69 +59,17 @@ void RefreshImagesRequest::handle_mirror_image_list(int r) { return; } - if (!ids.empty()) { - m_local_to_global_ids.insert(ids.begin(), ids.end()); - if (ids.size() == MAX_RETURN) { - m_start_after = ids.rbegin()->first; - mirror_image_list(); - return; - } + // store as global -> local image ids + for (auto &id : ids) { + m_image_ids->emplace(id.second, id.first); } - dir_list(); -} - -template -void RefreshImagesRequest::dir_list() { - dout(10) << dendl; - - m_out_bl.clear(); - m_start_after = ""; - - librados::ObjectReadOperation op; - librbd::cls_client::dir_list_start(&op, m_start_after, MAX_RETURN); - - librados::AioCompletion *aio_comp = create_rados_callback< - RefreshImagesRequest, - &RefreshImagesRequest::handle_dir_list>(this); - int r = m_remote_io_ctx.aio_operate(RBD_DIRECTORY, aio_comp, &op, &m_out_bl); - assert(r == 0); - aio_comp->release(); -} - -template -void RefreshImagesRequest::handle_dir_list(int r) { - dout(10) << "r=" << r << dendl; - - std::map name_to_ids; - if (r == 0) { - bufferlist::iterator it = m_out_bl.begin(); - r = librbd::cls_client::dir_list_finish(&it, &name_to_ids); - } - - if (r < 0 && r != -ENOENT) { - derr << "failed to list images: " << cpp_strerror(r) << dendl; - finish(r); + if (ids.size() == MAX_RETURN) { + m_start_after = ids.rbegin()->first; + mirror_image_list(); return; } - if (!name_to_ids.empty()) { - for (auto &pair : name_to_ids) { - auto it = m_local_to_global_ids.find(pair.second); - if (it != m_local_to_global_ids.end()) { - // mirrored image must exist within directory to be treated as - // a valid image - m_image_ids->insert(ImageId(it->second, it->first, pair.first)); - } - } - - if (name_to_ids.size() == MAX_RETURN) { - m_start_after = name_to_ids.rbegin()->first; - dir_list(); - return; - } - } - finish(0); } diff --git a/src/tools/rbd_mirror/pool_watcher/RefreshImagesRequest.h b/src/tools/rbd_mirror/pool_watcher/RefreshImagesRequest.h index 79a327cd6c7..35ed6b33014 100644 --- a/src/tools/rbd_mirror/pool_watcher/RefreshImagesRequest.h +++ b/src/tools/rbd_mirror/pool_watcher/RefreshImagesRequest.h @@ -8,7 +8,6 @@ #include "include/rados/librados.hpp" #include "tools/rbd_mirror/types.h" #include -#include struct Context; @@ -45,33 +44,22 @@ private: * v v | (more images) * MIRROR_IMAGE_LIST ---/ * | - * | /-------------\ - * | | | - * v v | (more images) - * DIR_LIST ------------/ - * | * v * * * @endverbatim */ - typedef std::unordered_map LocalToGlobalIds; - librados::IoCtx &m_remote_io_ctx; ImageIds *m_image_ids; Context *m_on_finish; bufferlist m_out_bl; std::string m_start_after; - LocalToGlobalIds m_local_to_global_ids; void mirror_image_list(); void handle_mirror_image_list(int r); - void dir_list(); - void handle_dir_list(int r); - void finish(int r); }; diff --git a/src/tools/rbd_mirror/types.cc b/src/tools/rbd_mirror/types.cc index 52bf9de20fc..4cd1e490f3d 100644 --- a/src/tools/rbd_mirror/types.cc +++ b/src/tools/rbd_mirror/types.cc @@ -8,8 +8,7 @@ namespace mirror { std::ostream &operator<<(std::ostream &os, const ImageId &image_id) { return os << "global id=" << image_id.global_id << ", " - << "id=" << image_id.id << ", " - << "name=" << image_id.name; + << "id=" << image_id.id; } std::ostream& operator<<(std::ostream& lhs, const peer_t &peer) { diff --git a/src/tools/rbd_mirror/types.h b/src/tools/rbd_mirror/types.h index 617effd21cf..829998d74e9 100644 --- a/src/tools/rbd_mirror/types.h +++ b/src/tools/rbd_mirror/types.h @@ -9,7 +9,6 @@ #include #include #include -#include #include "include/rbd/librbd.hpp" #include "ImageSyncThrottler.h" @@ -27,20 +26,15 @@ using ImageSyncThrottlerRef = std::shared_ptr>; struct ImageId { std::string global_id; std::string id; - boost::optional name; explicit ImageId(const std::string &global_id) : global_id(global_id) { } ImageId(const std::string &global_id, const std::string &id) : global_id(global_id), id(id) { } - ImageId(const std::string &global_id, const std::string &id, - const std::string &name) - : global_id(global_id), id(id), name(name) { - } inline bool operator==(const ImageId &rhs) const { - return (global_id == rhs.global_id && id == rhs.id && name == rhs.name); + return (global_id == rhs.global_id && id == rhs.id); } inline bool operator<(const ImageId &rhs) const { return global_id < rhs.global_id; -- 2.39.5