From 4e1b834d2dc6f7af4d6f9a1e657619a319a24870 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Wed, 19 Jul 2017 16:18:23 -0400 Subject: [PATCH] rbd-mirror: simplify resync handling within image replayer Signed-off-by: Jason Dillaman --- qa/workunits/rbd/rbd_mirror.sh | 9 +++- src/test/rbd_mirror/test_ImageReplayer.cc | 2 +- src/tools/rbd_mirror/ImageReplayer.cc | 50 ++++++++--------------- src/tools/rbd_mirror/ImageReplayer.h | 3 +- 4 files changed, 27 insertions(+), 37 deletions(-) diff --git a/qa/workunits/rbd/rbd_mirror.sh b/qa/workunits/rbd/rbd_mirror.sh index 7d59200c171..021cbaf03f7 100755 --- a/qa/workunits/rbd/rbd_mirror.sh +++ b/qa/workunits/rbd/rbd_mirror.sh @@ -286,6 +286,7 @@ wait_for_image_replay_started ${CLUSTER1} ${POOL} ${image} testlog "TEST: simple image resync" request_resync_image ${CLUSTER1} ${POOL} ${image} image_id wait_for_image_present ${CLUSTER1} ${POOL} ${image} 'deleted' ${image_id} +wait_for_image_present ${CLUSTER1} ${POOL} ${image} 'present' wait_for_image_replay_started ${CLUSTER1} ${POOL} ${image} wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+replaying' 'master_position' compare_images ${POOL} ${image} @@ -297,6 +298,7 @@ request_resync_image ${CLUSTER1} ${POOL} ${image} image_id admin_daemon ${CLUSTER1} rbd mirror start ${POOL}/${image} wait_for_image_present ${CLUSTER1} ${POOL} ${image} 'deleted' ${image_id} admin_daemon ${CLUSTER1} rbd mirror start ${POOL}/${image} +wait_for_image_present ${CLUSTER1} ${POOL} ${image} 'present' wait_for_image_replay_started ${CLUSTER1} ${POOL} ${image} wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+replaying' 'master_position' compare_images ${POOL} ${image} @@ -306,6 +308,7 @@ stop_mirror ${CLUSTER1} request_resync_image ${CLUSTER1} ${POOL} ${image} image_id start_mirror ${CLUSTER1} wait_for_image_present ${CLUSTER1} ${POOL} ${image} 'deleted' ${image_id} +wait_for_image_present ${CLUSTER1} ${POOL} ${image} 'present' wait_for_image_replay_started ${CLUSTER1} ${POOL} ${image} wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+replaying' 'master_position' compare_images ${POOL} ${image} @@ -327,6 +330,7 @@ wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+error' 'disconnecte testlog " - replay started after resync requested" request_resync_image ${CLUSTER1} ${POOL} ${image} image_id wait_for_image_present ${CLUSTER1} ${POOL} ${image} 'deleted' ${image_id} +wait_for_image_present ${CLUSTER1} ${POOL} ${image} 'present' wait_for_image_replay_started ${CLUSTER1} ${POOL} ${image} wait_for_replay_complete ${CLUSTER1} ${CLUSTER2} ${POOL} ${image} test -n "$(get_mirror_position ${CLUSTER2} ${POOL} ${image})" @@ -352,6 +356,7 @@ wait_for_status_in_pool_dir ${CLUSTER1} ${POOL} ${image} 'up+error' 'disconnecte testlog " - replay started after resync requested" request_resync_image ${CLUSTER1} ${POOL} ${image} image_id wait_for_image_present ${CLUSTER1} ${POOL} ${image} 'deleted' ${image_id} +wait_for_image_present ${CLUSTER1} ${POOL} ${image} 'present' wait_for_image_replay_started ${CLUSTER1} ${POOL} ${image} wait_for_replay_complete ${CLUSTER1} ${CLUSTER2} ${POOL} ${image} test -n "$(get_mirror_position ${CLUSTER2} ${POOL} ${image})" @@ -361,8 +366,10 @@ testlog " - rbd_mirroring_resync_after_disconnect config option" set_image_meta ${CLUSTER2} ${POOL} ${image} \ conf_rbd_mirroring_resync_after_disconnect true wait_for_replay_complete ${CLUSTER1} ${CLUSTER2} ${POOL} ${image} +image_id=$(get_image_id ${CLUSTER1} ${pool} ${image}) disconnect_image ${CLUSTER2} ${POOL} ${image} -wait_for_image_present ${CLUSTER1} ${POOL} ${image} 'deleted' +wait_for_image_present ${CLUSTER1} ${POOL} ${image} 'deleted' ${image_id} +wait_for_image_present ${CLUSTER1} ${POOL} ${image} 'present' wait_for_image_replay_started ${CLUSTER1} ${POOL} ${image} wait_for_replay_complete ${CLUSTER1} ${CLUSTER2} ${POOL} ${image} test -n "$(get_mirror_position ${CLUSTER2} ${POOL} ${image})" diff --git a/src/test/rbd_mirror/test_ImageReplayer.cc b/src/test/rbd_mirror/test_ImageReplayer.cc index 4c9103eb930..57ceeff4740 100644 --- a/src/test/rbd_mirror/test_ImageReplayer.cc +++ b/src/test/rbd_mirror/test_ImageReplayer.cc @@ -947,7 +947,7 @@ TEST_F(TestImageReplayer, Disconnect) close_image(ictx); C_SaferCond cond2; m_replayer->start(&cond2); - ASSERT_EQ(-ENOTCONN, cond2.wait()); + ASSERT_EQ(0, cond2.wait()); C_SaferCond delete_cond; m_image_deleter->wait_for_scheduled_deletion( m_local_ioctx.get_id(), m_replayer->get_global_image_id(), &delete_cond); diff --git a/src/tools/rbd_mirror/ImageReplayer.cc b/src/tools/rbd_mirror/ImageReplayer.cc index e43cfb93956..5842dd4fb4f 100644 --- a/src/tools/rbd_mirror/ImageReplayer.cc +++ b/src/tools/rbd_mirror/ImageReplayer.cc @@ -525,7 +525,8 @@ void ImageReplayer::bootstrap() { &m_local_image_ctx, m_local_image_id, m_remote_image.image_id, m_global_image_id, m_threads->work_queue, m_threads->timer, &m_threads->timer_lock, m_local_mirror_uuid, m_remote_image.mirror_uuid, - m_remote_journaler, &m_client_meta, ctx, &m_do_resync, &m_progress_cxt); + m_remote_journaler, &m_client_meta, ctx, &m_resync_requested, + &m_progress_cxt); { Mutex::Locker locker(m_lock); @@ -565,6 +566,9 @@ void ImageReplayer::handle_bootstrap(int r) { return; } else if (on_start_interrupted()) { return; + } else if (m_resync_requested) { + on_start_fail(0, "resync requested"); + return; } assert(m_local_journal == nullptr); @@ -583,22 +587,6 @@ void ImageReplayer::handle_bootstrap(int r) { { Mutex::Locker locker(m_lock); - - if (m_do_resync) { - Context *on_finish = m_on_start_finish; - m_stopping_for_resync = true; - FunctionContext *ctx = new FunctionContext([this, on_finish](int r) { - if (r < 0) { - if (on_finish) { - on_finish->complete(r); - } - return; - } - resync_image(on_finish); - }); - m_on_start_finish = ctx; - } - std::string name = m_local_ioctx.get_pool_name() + "/" + m_local_image_ctx->name; if (m_name != name) { @@ -652,13 +640,18 @@ void ImageReplayer::handle_init_remote_journaler(int r) { return; } - if (client.state != cls::journal::CLIENT_STATE_CONNECTED) { + derr << "image_id=" << m_local_image_id << ", " + << "m_client_meta.image_id=" << m_client_meta.image_id << ", " + << "client.state=" << client.state << dendl; + if (m_client_meta.image_id == m_local_image_id && + client.state != cls::journal::CLIENT_STATE_CONNECTED) { dout(5) << "client flagged disconnected, stopping image replay" << dendl; if (m_local_image_ctx->mirroring_resync_after_disconnect) { - Mutex::Locker locker(m_lock); - m_stopping_for_resync = true; + m_resync_requested = true; + on_start_fail(-ENOTCONN, "disconnected: automatic resync"); + } else { + on_start_fail(-ENOTCONN, "disconnected"); } - on_start_fail(-ENOTCONN, "disconnected"); return; } @@ -1582,11 +1575,6 @@ void ImageReplayer::shut_down(int r) { m_remote_journaler->remove_listener(&m_remote_listener); m_remote_journaler->shut_down(ctx); }); - if (m_stopping_for_resync) { - ctx = new FunctionContext([this, ctx](int r) { - m_remote_journaler->unregister_client(ctx); - }); - } } // stop the replay of remote journal events @@ -1674,12 +1662,12 @@ void ImageReplayer::handle_shut_down(int r) { return; } - if (m_stopping_for_resync) { + if (m_resync_requested) { m_image_deleter->schedule_image_delete(m_local, m_local_pool_id, m_global_image_id, true); - m_stopping_for_resync = false; + m_resync_requested = false; } } @@ -1759,11 +1747,7 @@ template void ImageReplayer::resync_image(Context *on_finish) { dout(20) << dendl; - { - Mutex::Locker l(m_lock); - m_stopping_for_resync = true; - } - + m_resync_requested = true; stop(on_finish); } diff --git a/src/tools/rbd_mirror/ImageReplayer.h b/src/tools/rbd_mirror/ImageReplayer.h index 11ff0b35794..fe0be00b563 100644 --- a/src/tools/rbd_mirror/ImageReplayer.h +++ b/src/tools/rbd_mirror/ImageReplayer.h @@ -309,7 +309,7 @@ private: int m_last_r = 0; BootstrapProgressContext m_progress_cxt; - bool m_do_resync{false}; + bool m_resync_requested = false; image_replayer::EventPreprocessor *m_event_preprocessor = nullptr; image_replayer::ReplayStatusFormatter *m_replay_status_formatter = nullptr; @@ -322,7 +322,6 @@ private: Journaler* m_remote_journaler = nullptr; ::journal::ReplayHandler *m_replay_handler = nullptr; librbd::journal::Listener *m_journal_listener; - bool m_stopping_for_resync = false; Context *m_on_start_finish = nullptr; Context *m_on_stop_finish = nullptr; -- 2.39.5