From 43ef7a498bc8606ba6e59643497b0dabef478416 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Mon, 27 Jan 2020 12:43:51 -0500 Subject: [PATCH] rbd-mirror: store remote promotion state within state builder This simplifies the factory method for the prepare state since it no longer needs to be an parameter. It will also permit the removal of the extra get mirror info call in bootstrap. Signed-off-by: Jason Dillaman --- .../image_replayer/test_mock_BootstrapRequest.cc | 7 +++---- .../image_replayer/test_mock_PrepareRemoteImageRequest.cc | 5 +++++ src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc | 3 +-- .../rbd_mirror/image_replayer/PrepareRemoteImageRequest.cc | 1 + src/tools/rbd_mirror/image_replayer/StateBuilder.h | 3 ++- .../rbd_mirror/image_replayer/journal/StateBuilder.cc | 3 +-- src/tools/rbd_mirror/image_replayer/journal/StateBuilder.h | 1 - .../rbd_mirror/image_replayer/snapshot/StateBuilder.cc | 1 - .../rbd_mirror/image_replayer/snapshot/StateBuilder.h | 1 - 9 files changed, 13 insertions(+), 12 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 cb25b351cfc9f..c9805f6d6220b 100644 --- a/src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc +++ b/src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc @@ -305,9 +305,8 @@ struct StateBuilder { const std::string&, ProgressContext*, Context*)); - MOCK_METHOD6(create_prepare_replay_request, + MOCK_METHOD5(create_prepare_replay_request, BaseRequest*(const std::string&, - librbd::mirror::PromotionState, ProgressContext*, bool*, bool*, Context*)); @@ -500,8 +499,8 @@ public: void expect_prepare_replay(MockStateBuilder& mock_state_builder, bool resync_requested, bool syncing, int r) { EXPECT_CALL(mock_state_builder, - create_prepare_replay_request(_, _, _, _, _, _)) - .WillOnce(WithArgs<3, 4, 5>( + create_prepare_replay_request(_, _, _, _, _)) + .WillOnce(WithArgs<2, 3, 4>( Invoke([this, &mock_state_builder, resync_requested, syncing, r] (bool* resync, bool* sync, Context* ctx) { if (r >= 0) { diff --git a/src/test/rbd_mirror/image_replayer/test_mock_PrepareRemoteImageRequest.cc b/src/test/rbd_mirror/image_replayer/test_mock_PrepareRemoteImageRequest.cc index ff65fef4c26b7..180a6f823c7c9 100644 --- a/src/test/rbd_mirror/image_replayer/test_mock_PrepareRemoteImageRequest.cc +++ b/src/test/rbd_mirror/image_replayer/test_mock_PrepareRemoteImageRequest.cc @@ -121,6 +121,7 @@ struct StateBuilder { std::string local_image_id; std::string remote_image_id; std::string remote_mirror_uuid; + librbd::mirror::PromotionState remote_promotion_state; virtual ~StateBuilder() {} @@ -285,6 +286,8 @@ TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, Success) { ASSERT_TRUE(mock_state_builder != nullptr); ASSERT_EQ(std::string("remote image id"), mock_journal_state_builder.remote_image_id); + ASSERT_EQ(librbd::mirror::PROMOTION_STATE_PRIMARY, + mock_journal_state_builder.remote_promotion_state); ASSERT_TRUE(mock_journal_state_builder.remote_journaler != nullptr); ASSERT_EQ(cls::journal::CLIENT_STATE_DISCONNECTED, mock_journal_state_builder.remote_client_state); @@ -341,6 +344,8 @@ TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, SuccessNotRegistered) { ASSERT_TRUE(mock_state_builder != nullptr); ASSERT_EQ(std::string("remote image id"), mock_journal_state_builder.remote_image_id); + ASSERT_EQ(librbd::mirror::PROMOTION_STATE_PRIMARY, + mock_journal_state_builder.remote_promotion_state); ASSERT_TRUE(mock_journal_state_builder.remote_journaler != nullptr); ASSERT_EQ(cls::journal::CLIENT_STATE_CONNECTED, mock_journal_state_builder.remote_client_state); diff --git a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc index e783989a28b29..80d40b60242b5 100644 --- a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc +++ b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc @@ -355,8 +355,7 @@ void BootstrapRequest::prepare_replay() { auto ctx = create_context_callback< BootstrapRequest, &BootstrapRequest::handle_prepare_replay>(this); auto request = (*m_state_builder)->create_prepare_replay_request( - m_local_mirror_uuid, m_promotion_state, m_progress_ctx, m_do_resync, - &m_syncing, ctx); + m_local_mirror_uuid, m_progress_ctx, m_do_resync, &m_syncing, ctx); request->send(); } diff --git a/src/tools/rbd_mirror/image_replayer/PrepareRemoteImageRequest.cc b/src/tools/rbd_mirror/image_replayer/PrepareRemoteImageRequest.cc index dfeb849c5b904..ccb578848ff53 100644 --- a/src/tools/rbd_mirror/image_replayer/PrepareRemoteImageRequest.cc +++ b/src/tools/rbd_mirror/image_replayer/PrepareRemoteImageRequest.cc @@ -218,6 +218,7 @@ void PrepareRemoteImageRequest::finalize_journal_state_builder( state_builder->remote_mirror_uuid = m_remote_pool_meta.mirror_uuid; state_builder->remote_image_id = m_remote_image_id; + state_builder->remote_promotion_state = m_promotion_state; state_builder->remote_journaler = m_remote_journaler; state_builder->remote_client_state = client_state; state_builder->remote_client_meta = client_meta; diff --git a/src/tools/rbd_mirror/image_replayer/StateBuilder.h b/src/tools/rbd_mirror/image_replayer/StateBuilder.h index ff291617ad840..192ffca44e889 100644 --- a/src/tools/rbd_mirror/image_replayer/StateBuilder.h +++ b/src/tools/rbd_mirror/image_replayer/StateBuilder.h @@ -59,7 +59,6 @@ public: virtual BaseRequest* create_prepare_replay_request( const std::string& local_mirror_uuid, - librbd::mirror::PromotionState remote_promotion_state, ProgressContext* progress_ctx, bool* resync_requested, bool* syncing, @@ -80,6 +79,8 @@ public: std::string remote_mirror_uuid; std::string remote_image_id; + librbd::mirror::PromotionState remote_promotion_state = + librbd::mirror::PROMOTION_STATE_NON_PRIMARY; protected: image_sync::SyncPointHandler* m_sync_point_handler = nullptr; diff --git a/src/tools/rbd_mirror/image_replayer/journal/StateBuilder.cc b/src/tools/rbd_mirror/image_replayer/journal/StateBuilder.cc index 2b7a463671af0..7372475d87078 100644 --- a/src/tools/rbd_mirror/image_replayer/journal/StateBuilder.cc +++ b/src/tools/rbd_mirror/image_replayer/journal/StateBuilder.cc @@ -83,13 +83,12 @@ BaseRequest* StateBuilder::create_local_image_request( template BaseRequest* StateBuilder::create_prepare_replay_request( const std::string& local_mirror_uuid, - librbd::mirror::PromotionState remote_promotion_state, ProgressContext* progress_ctx, bool* resync_requested, bool* syncing, Context* on_finish) { return PrepareReplayRequest::create( - local_mirror_uuid, remote_promotion_state, progress_ctx, this, + local_mirror_uuid, this->remote_promotion_state, progress_ctx, this, resync_requested, syncing, on_finish); } diff --git a/src/tools/rbd_mirror/image_replayer/journal/StateBuilder.h b/src/tools/rbd_mirror/image_replayer/journal/StateBuilder.h index c09f2a7f4fdf1..868260699f201 100644 --- a/src/tools/rbd_mirror/image_replayer/journal/StateBuilder.h +++ b/src/tools/rbd_mirror/image_replayer/journal/StateBuilder.h @@ -52,7 +52,6 @@ public: BaseRequest* create_prepare_replay_request( const std::string& local_mirror_uuid, - librbd::mirror::PromotionState remote_promotion_state, ProgressContext* progress_ctx, bool* resync_requested, bool* syncing, diff --git a/src/tools/rbd_mirror/image_replayer/snapshot/StateBuilder.cc b/src/tools/rbd_mirror/image_replayer/snapshot/StateBuilder.cc index 82b631a83788a..018574dec72b2 100644 --- a/src/tools/rbd_mirror/image_replayer/snapshot/StateBuilder.cc +++ b/src/tools/rbd_mirror/image_replayer/snapshot/StateBuilder.cc @@ -71,7 +71,6 @@ BaseRequest* StateBuilder::create_local_image_request( template BaseRequest* StateBuilder::create_prepare_replay_request( const std::string& local_mirror_uuid, - librbd::mirror::PromotionState remote_promotion_state, ProgressContext* progress_ctx, bool* resync_requested, bool* syncing, diff --git a/src/tools/rbd_mirror/image_replayer/snapshot/StateBuilder.h b/src/tools/rbd_mirror/image_replayer/snapshot/StateBuilder.h index ff4b12096761b..105e3a0134893 100644 --- a/src/tools/rbd_mirror/image_replayer/snapshot/StateBuilder.h +++ b/src/tools/rbd_mirror/image_replayer/snapshot/StateBuilder.h @@ -46,7 +46,6 @@ public: BaseRequest* create_prepare_replay_request( const std::string& local_mirror_uuid, - librbd::mirror::PromotionState remote_promotion_state, ProgressContext* progress_ctx, bool* resync_requested, bool* syncing, -- 2.39.5