]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: stop querying remote mirror uuid during image bootstrap
authorJason Dillaman <dillaman@redhat.com>
Mon, 27 Jan 2020 16:51:20 +0000 (11:51 -0500)
committerJason Dillaman <dillaman@redhat.com>
Thu, 30 Jan 2020 15:26:36 +0000 (10:26 -0500)
The remote mirror uuid is now polled automatically by a higher layer.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc
src/test/rbd_mirror/image_replayer/test_mock_PrepareRemoteImageRequest.cc
src/test/rbd_mirror/test_ImageReplayer.cc
src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc
src/tools/rbd_mirror/image_replayer/PrepareRemoteImageRequest.cc
src/tools/rbd_mirror/image_replayer/PrepareRemoteImageRequest.h
src/tools/rbd_mirror/image_replayer/StateBuilder.cc

index e0dbb1c47df0113e1e1aec81fb01dff6a43ccc0f..cb25b351cfc9fdbe84a9f7d369f1dab58ff01aea 100644 (file)
@@ -252,6 +252,7 @@ struct PrepareRemoteImageRequest<librbd::MockTestImageCtx> {
                                            librados::IoCtx &,
                                            const std::string &global_image_id,
                                            const std::string &local_mirror_uuid,
+                                           const RemotePoolMeta& remote_pool_meta,
                                            ::journal::CacheManagerHandler *cache_manager_handler,
                                            StateBuilder<librbd::MockTestImageCtx>** state_builder,
                                            Context *on_finish) {
index dd48bef31350f9f7d61e23a0103dccc1442785de..49b22dac70fe1307ece57ec30c9279d405fc373f 100644 (file)
@@ -78,8 +78,8 @@ struct GetMirrorImageIdRequest<librbd::MockTestImageCtx> {
 template<>
 struct StateBuilder<librbd::MockTestImageCtx> {
   std::string local_image_id;
-  std::string remote_mirror_uuid;
   std::string remote_image_id;
+  std::string remote_mirror_uuid;
 
   virtual ~StateBuilder() {}
 
@@ -154,19 +154,6 @@ public:
                 }));
   }
 
-  void expect_mirror_uuid_get(librados::IoCtx &io_ctx,
-                              const std::string &mirror_uuid, int r) {
-    bufferlist bl;
-    encode(mirror_uuid, bl);
-
-    EXPECT_CALL(get_mock_io_ctx(io_ctx),
-                exec(RBD_MIRRORING, _, StrEq("rbd"), StrEq("mirror_uuid_get"), _, _, _))
-      .WillOnce(DoAll(WithArg<5>(Invoke([bl](bufferlist *out_bl) {
-                                          *out_bl = bl;
-                                        })),
-                      Return(r)));
-  }
-
   void expect_get_mirror_image(librados::IoCtx &io_ctx,
                                cls::rbd::MirrorImageMode mode, int r) {
     cls::rbd::MirrorImage mirror_image;
@@ -214,7 +201,6 @@ TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, Success) {
   MockThreads mock_threads(m_threads);
 
   InSequence seq;
-  expect_mirror_uuid_get(m_remote_io_ctx, "remote mirror uuid", 0);
   MockGetMirrorImageIdRequest mock_get_mirror_image_id_request;
   expect_get_mirror_image_id(mock_get_mirror_image_id_request,
                              "remote image id", 0);
@@ -242,6 +228,7 @@ TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, Success) {
                                                    m_remote_io_ctx,
                                                    "global image id",
                                                    "local mirror uuid",
+                                                   {"remote mirror uuid", ""},
                                                    nullptr,
                                                    &mock_state_builder,
                                                    &ctx);
@@ -249,8 +236,6 @@ TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, Success) {
 
   ASSERT_EQ(0, ctx.wait());
   ASSERT_TRUE(mock_state_builder != nullptr);
-  ASSERT_EQ(std::string("remote mirror uuid"),
-            mock_journal_state_builder.remote_mirror_uuid);
   ASSERT_EQ(std::string("remote image id"),
             mock_journal_state_builder.remote_image_id);
   ASSERT_TRUE(mock_journal_state_builder.remote_journaler != nullptr);
@@ -263,7 +248,6 @@ TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, SuccessNotRegistered) {
   MockThreads mock_threads(m_threads);
 
   InSequence seq;
-  expect_mirror_uuid_get(m_remote_io_ctx, "remote mirror uuid", 0);
   MockGetMirrorImageIdRequest mock_get_mirror_image_id_request;
   expect_get_mirror_image_id(mock_get_mirror_image_id_request,
                              "remote image id", 0);
@@ -294,6 +278,7 @@ TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, SuccessNotRegistered) {
                                                    m_remote_io_ctx,
                                                    "global image id",
                                                    "local mirror uuid",
+                                                   {"remote mirror uuid", ""},
                                                    nullptr,
                                                    &mock_state_builder,
                                                    &ctx);
@@ -301,8 +286,6 @@ TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, SuccessNotRegistered) {
 
   ASSERT_EQ(0, ctx.wait());
   ASSERT_TRUE(mock_state_builder != nullptr);
-  ASSERT_EQ(std::string("remote mirror uuid"),
-            mock_journal_state_builder.remote_mirror_uuid);
   ASSERT_EQ(std::string("remote image id"),
             mock_journal_state_builder.remote_image_id);
   ASSERT_TRUE(mock_journal_state_builder.remote_journaler != nullptr);
@@ -310,37 +293,11 @@ TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, SuccessNotRegistered) {
             mock_journal_state_builder.remote_client_state);
 }
 
-TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, MirrorUuidError) {
-  ::journal::MockJournaler mock_remote_journaler;
-  MockThreads mock_threads(m_threads);
-
-  InSequence seq;
-  expect_mirror_uuid_get(m_remote_io_ctx, "", -EINVAL);
-
-  MockJournalStateBuilder mock_journal_state_builder;
-  MockStateBuilder* mock_state_builder = nullptr;
-  C_SaferCond ctx;
-  auto req = MockPrepareRemoteImageRequest::create(&mock_threads,
-                                                   m_local_io_ctx,
-                                                   m_remote_io_ctx,
-                                                   "global image id",
-                                                   "local mirror uuid",
-                                                   nullptr,
-                                                   &mock_state_builder,
-                                                   &ctx);
-  req->send();
-
-  ASSERT_EQ(-EINVAL, ctx.wait());
-  ASSERT_EQ(std::string(""), mock_journal_state_builder.remote_mirror_uuid);
-  ASSERT_TRUE(mock_journal_state_builder.remote_journaler == nullptr);
-}
-
 TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, MirrorImageIdError) {
   ::journal::MockJournaler mock_remote_journaler;
   MockThreads mock_threads(m_threads);
 
   InSequence seq;
-  expect_mirror_uuid_get(m_remote_io_ctx, "remote mirror uuid", 0);
   MockGetMirrorImageIdRequest mock_get_mirror_image_id_request;
   expect_get_mirror_image_id(mock_get_mirror_image_id_request, "", -EINVAL);
 
@@ -352,14 +309,13 @@ TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, MirrorImageIdError) {
                                                    m_remote_io_ctx,
                                                    "global image id",
                                                    "local mirror uuid",
+                                                   {"remote mirror uuid", ""},
                                                    nullptr,
                                                    &mock_state_builder,
                                                    &ctx);
   req->send();
 
   ASSERT_EQ(-EINVAL, ctx.wait());
-  ASSERT_EQ(std::string("remote mirror uuid"),
-            mock_journal_state_builder.remote_mirror_uuid);
   ASSERT_TRUE(mock_journal_state_builder.remote_journaler == nullptr);
 }
 
@@ -368,7 +324,6 @@ TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, MirrorModeError) {
   MockThreads mock_threads(m_threads);
 
   InSequence seq;
-  expect_mirror_uuid_get(m_remote_io_ctx, "remote mirror uuid", 0);
   MockGetMirrorImageIdRequest mock_get_mirror_image_id_request;
   expect_get_mirror_image_id(mock_get_mirror_image_id_request,
                              "remote image id", 0);
@@ -384,6 +339,7 @@ TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, MirrorModeError) {
                                                    m_remote_io_ctx,
                                                    "global image id",
                                                    "local mirror uuid",
+                                                   {"remote mirror uuid", ""},
                                                    nullptr,
                                                    &mock_state_builder,
                                                    &ctx);
@@ -398,7 +354,6 @@ TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, GetClientError) {
   MockThreads mock_threads(m_threads);
 
   InSequence seq;
-  expect_mirror_uuid_get(m_remote_io_ctx, "remote mirror uuid", 0);
   MockGetMirrorImageIdRequest mock_get_mirror_image_id_request;
   expect_get_mirror_image_id(mock_get_mirror_image_id_request,
                              "remote image id", 0);
@@ -420,6 +375,7 @@ TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, GetClientError) {
                                                    m_remote_io_ctx,
                                                    "global image id",
                                                    "local mirror uuid",
+                                                   {"remote mirror uuid", ""},
                                                    nullptr,
                                                    &mock_state_builder,
                                                    &ctx);
@@ -434,7 +390,6 @@ TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, RegisterClientError) {
   MockThreads mock_threads(m_threads);
 
   InSequence seq;
-  expect_mirror_uuid_get(m_remote_io_ctx, "remote mirror uuid", 0);
   MockGetMirrorImageIdRequest mock_get_mirror_image_id_request;
   expect_get_mirror_image_id(mock_get_mirror_image_id_request,
                              "remote image id", 0);
@@ -465,6 +420,7 @@ TEST_F(TestMockImageReplayerPrepareRemoteImageRequest, RegisterClientError) {
                                                    m_remote_io_ctx,
                                                    "global image id",
                                                    "local mirror uuid",
+                                                   {"remote mirror uuid", ""},
                                                    nullptr,
                                                    &mock_state_builder,
                                                    &ctx);
index fc7a3f86e6e0110791d3ee4b3c5c0970683743f9..63bdc8410599d949ea2dd3bb136bdedfd8e0e677 100644 (file)
@@ -163,7 +163,9 @@ public:
                                     m_global_image_id, m_threads.get(),
                                     m_instance_watcher, m_local_status_updater,
                                     nullptr, &m_pool_meta_cache);
-    m_replayer->add_peer({"peer uuid", m_remote_ioctx, {}, nullptr});
+    m_replayer->add_peer({"peer uuid", m_remote_ioctx,
+                         {m_remote_mirror_uuid, "remote mirror peer uuid"},
+                         nullptr});
   }
 
   void start()
index 2265f706892599fc469fa1a522783c194548650a..e783989a28b29b38ac370213bb39cdcbf2df1dac 100644 (file)
@@ -163,7 +163,8 @@ void BootstrapRequest<I>::prepare_remote_image() {
     BootstrapRequest, &BootstrapRequest<I>::handle_prepare_remote_image>(this);
   auto req = image_replayer::PrepareRemoteImageRequest<I>::create(
     m_threads, m_local_io_ctx, m_remote_io_ctx, m_global_image_id,
-    m_local_mirror_uuid, m_cache_manager_handler, m_state_builder, ctx);
+    m_local_mirror_uuid, m_remote_pool_meta, m_cache_manager_handler,
+    m_state_builder, ctx);
   req->send();
 }
 
@@ -172,6 +173,9 @@ void BootstrapRequest<I>::handle_prepare_remote_image(int r) {
   dout(10) << "r=" << r << dendl;
 
   auto state_builder = *m_state_builder;
+  ceph_assert(state_builder == nullptr ||
+              !state_builder->remote_mirror_uuid.empty());
+
   if (state_builder != nullptr && state_builder->is_local_primary()) {
     dout(5) << "local image is primary" << dendl;
     finish(-ENOMSG);
index 462f8b6974025b549f542a99657e946e48f7eba3..65ff88002c1086a724ec80308620d1be1d5813e2 100644 (file)
@@ -33,51 +33,8 @@ using librbd::util::create_rados_callback;
 
 template <typename I>
 void PrepareRemoteImageRequest<I>::send() {
-  get_remote_mirror_uuid();
-}
-
-template <typename I>
-void PrepareRemoteImageRequest<I>::get_remote_mirror_uuid() {
-  dout(10) << dendl;
-
-  librados::ObjectReadOperation op;
-  librbd::cls_client::mirror_uuid_get_start(&op);
-
-  librados::AioCompletion *aio_comp = create_rados_callback<
-    PrepareRemoteImageRequest<I>,
-    &PrepareRemoteImageRequest<I>::handle_get_remote_mirror_uuid>(this);
-  int r = m_remote_io_ctx.aio_operate(RBD_MIRRORING, aio_comp, &op, &m_out_bl);
-  ceph_assert(r == 0);
-  aio_comp->release();
-}
-
-template <typename I>
-void PrepareRemoteImageRequest<I>::handle_get_remote_mirror_uuid(int r) {
-  if (r >= 0) {
-    auto it = m_out_bl.cbegin();
-    r = librbd::cls_client::mirror_uuid_get_finish(&it, &m_remote_mirror_uuid);
-    if (r >= 0 && m_remote_mirror_uuid.empty()) {
-      r = -ENOENT;
-    }
-  }
-
-  dout(10) << "r=" << r << dendl;
-  if (r < 0) {
-    if (r == -ENOENT) {
-      dout(5) << "remote mirror uuid missing" << dendl;
-    } else {
-      derr << "failed to retrieve remote mirror uuid: " << cpp_strerror(r)
-           << dendl;
-    }
-    finish(r);
-    return;
-  }
-
-  auto state_builder = *m_state_builder;
-  if (state_builder != nullptr) {
-    // if the local image exists but the remote image doesn't, we still
-    // want to populate the remote mirror uuid that we've looked up
-    state_builder->remote_mirror_uuid = m_remote_mirror_uuid;
+  if (*m_state_builder != nullptr) {
+    (*m_state_builder)->remote_mirror_uuid = m_remote_pool_meta.mirror_uuid;
   }
 
   get_remote_image_id();
@@ -265,7 +222,7 @@ void PrepareRemoteImageRequest<I>::finalize_journal_state_builder(
     *m_state_builder = state_builder;
   }
 
-  state_builder->remote_mirror_uuid = m_remote_mirror_uuid;
+  state_builder->remote_mirror_uuid = m_remote_pool_meta.mirror_uuid;
   state_builder->remote_image_id = m_remote_image_id;
   state_builder->remote_journaler = m_remote_journaler;
   state_builder->remote_client_state = client_state;
index 616c18e13beef145a7299436782e45d148a18270..59a28feddf759c4f112a26c8aa83fa77b96162b4 100644 (file)
@@ -10,6 +10,7 @@
 #include "journal/Settings.h"
 #include "librbd/journal/Types.h"
 #include "librbd/journal/TypeTraits.h"
+#include "tools/rbd_mirror/Types.h"
 #include <string>
 
 namespace journal { class Journaler; }
@@ -42,11 +43,13 @@ public:
       librados::IoCtx &remote_io_ctx,
       const std::string &global_image_id,
       const std::string &local_mirror_uuid,
+      const RemotePoolMeta& remote_pool_meta,
       ::journal::CacheManagerHandler *cache_manager_handler,
       StateBuilder<ImageCtxT>** state_builder,
       Context *on_finish) {
     return new PrepareRemoteImageRequest(threads, local_io_ctx, remote_io_ctx,
                                          global_image_id, local_mirror_uuid,
+                                         remote_pool_meta,
                                          cache_manager_handler, state_builder,
                                          on_finish);
   }
@@ -57,6 +60,7 @@ public:
       librados::IoCtx &remote_io_ctx,
       const std::string &global_image_id,
       const std::string &local_mirror_uuid,
+      const RemotePoolMeta& remote_pool_meta,
       ::journal::CacheManagerHandler *cache_manager_handler,
       StateBuilder<ImageCtxT>** state_builder,
       Context *on_finish)
@@ -65,6 +69,7 @@ public:
       m_remote_io_ctx(remote_io_ctx),
       m_global_image_id(global_image_id),
       m_local_mirror_uuid(local_mirror_uuid),
+      m_remote_pool_meta(remote_pool_meta),
       m_cache_manager_handler(cache_manager_handler),
       m_state_builder(state_builder),
       m_on_finish(on_finish) {
@@ -79,9 +84,6 @@ private:
    * <start>
    *    |
    *    v
-   * GET_REMOTE_MIRROR_UUID
-   *    |
-   *    v
    * GET_REMOTE_IMAGE_ID
    *    |
    *    v
@@ -104,21 +106,18 @@ private:
   librados::IoCtx &m_remote_io_ctx;
   std::string m_global_image_id;
   std::string m_local_mirror_uuid;
+  RemotePoolMeta m_remote_pool_meta;
   ::journal::CacheManagerHandler *m_cache_manager_handler;
   StateBuilder<ImageCtxT>** m_state_builder;
   Context *m_on_finish;
 
   bufferlist m_out_bl;
-  std::string m_remote_mirror_uuid;
   std::string m_remote_image_id;
 
   // journal-based mirroring
   Journaler *m_remote_journaler = nullptr;
   cls::journal::Client m_client;
 
-  void get_remote_mirror_uuid();
-  void handle_get_remote_mirror_uuid(int r);
-
   void get_remote_image_id();
   void handle_get_remote_image_id(int r);
 
index dda6204ed6ade14b2e6463cfdb0f3a29fefea5e7..4c543b7880aee650ef42acf4eaf2f6620648be5e 100644 (file)
@@ -42,6 +42,7 @@ bool StateBuilder<I>::is_local_primary() const  {
 
 template <typename I>
 bool StateBuilder<I>::is_linked() const {
+  ceph_assert(!remote_mirror_uuid.empty());
   return (local_promotion_state ==
             librbd::mirror::PROMOTION_STATE_NON_PRIMARY &&
           local_primary_mirror_uuid == remote_mirror_uuid);