From 379309b552db51dcab9b08ba5437c1dae5cd45a7 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Wed, 3 May 2017 21:36:21 -0400 Subject: [PATCH] rbd-mirror: ensure missing images are re-synced when detected Fixes: http://tracker.ceph.com/issues/19811 Signed-off-by: Jason Dillaman (cherry picked from commit 74bd4f230a0cb7b709f2cb5c6db3dc79f0d8dede) Conflicts: src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc: trivial resolution src/tools/rbd_mirror/image_replayer/BootstrapRequest.h: trivial resolution --- .../test_mock_BootstrapRequest.cc | 49 +++---------------- .../image_replayer/BootstrapRequest.cc | 12 ++--- .../image_replayer/BootstrapRequest.h | 1 - 3 files changed, 12 insertions(+), 50 deletions(-) diff --git a/src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc b/src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc index 542b78c54289c..7da2de953b99f 100644 --- a/src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc +++ b/src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc @@ -3,7 +3,6 @@ #include "test/rbd_mirror/test_mock_fixture.h" #include "librbd/journal/TypeTraits.h" -#include "tools/rbd_mirror/ImageSync.h" #include "tools/rbd_mirror/ImageSyncThrottler.h" #include "tools/rbd_mirror/Threads.h" #include "tools/rbd_mirror/image_replayer/BootstrapRequest.h" @@ -44,40 +43,6 @@ namespace mirror { class ProgressContext; -template<> -struct ImageSync { - static ImageSync* s_instance; - Context *on_finish = nullptr; - - static ImageSync* create(librbd::MockTestImageCtx *local_image_ctx, - librbd::MockTestImageCtx *remote_image_ctx, - SafeTimer *timer, Mutex *timer_lock, - const std::string &mirror_uuid, - ::journal::MockJournaler *journaler, - librbd::journal::MirrorPeerClientMeta *client_meta, - ContextWQ *work_queue, Context *on_finish, - ProgressContext *progress_ctx = nullptr) { - assert(s_instance != nullptr); - return s_instance; - } - - ImageSync() { - assert(s_instance == nullptr); - s_instance = this; - } - - void put() { - } - - void get() { - } - - MOCK_METHOD0(send, void()); - MOCK_METHOD0(cancel, void()); -}; - -ImageSync* ImageSync::s_instance = nullptr; - template<> struct ImageSyncThrottler { MOCK_METHOD10(start_sync, void(librbd::MockTestImageCtx *local_image_ctx, @@ -366,12 +331,12 @@ public: void expect_open_local_image(MockOpenLocalImageRequest &mock_open_local_image_request, librados::IoCtx &io_ctx, const std::string &image_id, - librbd::MockTestImageCtx &mock_image_ctx, int r) { + librbd::MockTestImageCtx *mock_image_ctx, int r) { EXPECT_CALL(mock_open_local_image_request, construct(IsSameIoCtx(&io_ctx), image_id)); EXPECT_CALL(mock_open_local_image_request, send()) - .WillOnce(Invoke([this, &mock_open_local_image_request, &mock_image_ctx, r]() { - *mock_open_local_image_request.image_ctx = &mock_image_ctx; + .WillOnce(Invoke([this, &mock_open_local_image_request, mock_image_ctx, r]() { + *mock_open_local_image_request.image_ctx = mock_image_ctx; m_threads->work_queue->queue(mock_open_local_image_request.on_finish, r); })); @@ -551,7 +516,7 @@ TEST_F(TestMockImageReplayerBootstrapRequest, RemoteDemotePromote) { mock_local_image_ctx.journal = &mock_journal; MockOpenLocalImageRequest mock_open_local_image_request; expect_open_local_image(mock_open_local_image_request, m_local_io_ctx, - mock_local_image_ctx.id, mock_local_image_ctx, 0); + mock_local_image_ctx.id, &mock_local_image_ctx, 0); expect_is_resync_requested(mock_journal, false, 0); // remote demotion / promotion event @@ -630,7 +595,7 @@ TEST_F(TestMockImageReplayerBootstrapRequest, MultipleRemoteDemotePromotes) { mock_local_image_ctx.journal = &mock_journal; MockOpenLocalImageRequest mock_open_local_image_request; expect_open_local_image(mock_open_local_image_request, m_local_io_ctx, - mock_local_image_ctx.id, mock_local_image_ctx, 0); + mock_local_image_ctx.id, &mock_local_image_ctx, 0); expect_is_resync_requested(mock_journal, false, 0); // remote demotion / promotion event @@ -719,7 +684,7 @@ TEST_F(TestMockImageReplayerBootstrapRequest, LocalDemoteRemotePromote) { mock_local_image_ctx.journal = &mock_journal; MockOpenLocalImageRequest mock_open_local_image_request; expect_open_local_image(mock_open_local_image_request, m_local_io_ctx, - mock_local_image_ctx.id, mock_local_image_ctx, 0); + mock_local_image_ctx.id, &mock_local_image_ctx, 0); expect_is_resync_requested(mock_journal, false, 0); // remote demotion / promotion event @@ -796,7 +761,7 @@ TEST_F(TestMockImageReplayerBootstrapRequest, SplitBrainForcePromote) { mock_local_image_ctx.journal = &mock_journal; MockOpenLocalImageRequest mock_open_local_image_request; expect_open_local_image(mock_open_local_image_request, m_local_io_ctx, - mock_local_image_ctx.id, mock_local_image_ctx, 0); + mock_local_image_ctx.id, &mock_local_image_ctx, 0); expect_is_resync_requested(mock_journal, false, 0); // remote demotion / promotion event diff --git a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc index 54c3818e93aad..cb9f00280dbd9 100644 --- a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc +++ b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc @@ -20,7 +20,6 @@ #include "librbd/Journal.h" #include "librbd/Utils.h" #include "librbd/journal/Types.h" -#include "tools/rbd_mirror/ImageSync.h" #include "tools/rbd_mirror/ProgressContext.h" #include "tools/rbd_mirror/ImageSyncThrottler.h" @@ -454,7 +453,6 @@ void BootstrapRequest::handle_create_local_image(int r) { return; } - m_created_local_image = true; open_local_image(); } @@ -473,8 +471,8 @@ void BootstrapRequest::update_client_image() { dout(20) << dendl; - librbd::journal::MirrorPeerClientMeta client_meta; - client_meta.image_id = m_local_image_id; + librbd::journal::MirrorPeerClientMeta client_meta{m_local_image_id}; + client_meta.state = librbd::journal::MIRROR_PEER_STATE_SYNCING; librbd::journal::ClientData client_data(client_meta); bufferlist data_bl; @@ -504,7 +502,8 @@ void BootstrapRequest::handle_update_client_image(int r) { return; } - m_client_meta->image_id = m_local_image_id; + *m_client_meta = {m_local_image_id}; + m_client_meta->state = librbd::journal::MIRROR_PEER_STATE_SYNCING; get_remote_tags(); } @@ -514,8 +513,7 @@ void BootstrapRequest::get_remote_tags() { update_progress("GET_REMOTE_TAGS"); - if (m_created_local_image || - m_client_meta->state == librbd::journal::MIRROR_PEER_STATE_SYNCING) { + if (m_client_meta->state == librbd::journal::MIRROR_PEER_STATE_SYNCING) { // optimization -- no need to compare remote tags if we just created // the image locally or sync was interrupted image_sync(); diff --git a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h index 6b4ed215a0f26..be49544c4a155 100644 --- a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h +++ b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h @@ -171,7 +171,6 @@ private: uint64_t m_remote_tag_class = 0; ImageCtxT *m_remote_image_ctx = nullptr; bool m_primary = false; - bool m_created_local_image = false; int m_ret_val = 0; bufferlist m_out_bl; -- 2.39.5