]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: switch image sync to use abstract sync point handler
authorJason Dillaman <dillaman@redhat.com>
Wed, 8 Jan 2020 04:44:25 +0000 (23:44 -0500)
committerJason Dillaman <dillaman@redhat.com>
Thu, 9 Jan 2020 15:48:52 +0000 (10:48 -0500)
This removes all journal-specific code from the image sync path.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
14 files changed:
src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc
src/test/rbd_mirror/image_sync/test_mock_SyncPointCreateRequest.cc
src/test/rbd_mirror/image_sync/test_mock_SyncPointPruneRequest.cc
src/test/rbd_mirror/mock/image_sync/MockSyncPointHandler.h [new file with mode: 0644]
src/test/rbd_mirror/test_ImageSync.cc
src/test/rbd_mirror/test_mock_ImageSync.cc
src/tools/rbd_mirror/ImageSync.cc
src/tools/rbd_mirror/ImageSync.h
src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc
src/tools/rbd_mirror/image_replayer/BootstrapRequest.h
src/tools/rbd_mirror/image_sync/SyncPointCreateRequest.cc
src/tools/rbd_mirror/image_sync/SyncPointCreateRequest.h
src/tools/rbd_mirror/image_sync/SyncPointPruneRequest.cc
src/tools/rbd_mirror/image_sync/SyncPointPruneRequest.h

index 5b3bbb4f9011d1bae52837343565bf767fc09475..ee83b6a5121767c29eaeac474cbbc6d360e972fb 100644 (file)
 #include "tools/rbd_mirror/image_replayer/OpenLocalImageRequest.h"
 #include "tools/rbd_mirror/image_replayer/PrepareLocalImageRequest.h"
 #include "tools/rbd_mirror/image_replayer/PrepareRemoteImageRequest.h"
+#include "tools/rbd_mirror/image_replayer/StateBuilder.h"
 #include "tools/rbd_mirror/image_replayer/journal/CreateLocalImageRequest.h"
 #include "tools/rbd_mirror/image_replayer/journal/PrepareReplayRequest.h"
+#include "tools/rbd_mirror/image_replayer/journal/StateBuilder.h"
 #include "test/journal/mock/MockJournaler.h"
 #include "test/librados_test_stub/MockTestMemIoCtxImpl.h"
 #include "test/librbd/mock/MockImageCtx.h"
 #include "test/librbd/mock/MockJournal.h"
+#include "test/rbd_mirror/mock/image_sync/MockSyncPointHandler.h"
 
 namespace librbd {
 
@@ -99,13 +102,13 @@ struct ImageSync<librbd::MockTestImageCtx> {
   Context *on_finish = nullptr;
 
   static ImageSync* create(
+      Threads<librbd::MockTestImageCtx>* threads,
       librbd::MockTestImageCtx *local_image_ctx,
       librbd::MockTestImageCtx *remote_image_ctx,
-      SafeTimer *timer, ceph::mutex *timer_lock,
-      const std::string &mirror_uuid, ::journal::MockJournaler *journaler,
-      librbd::journal::MirrorPeerClientMeta *client_meta, ContextWQ *work_queue,
+      const std::string &local_mirror_uuid,
+      image_sync::SyncPointHandler* sync_point_handler,
       InstanceWatcher<librbd::MockTestImageCtx> *instance_watcher,
-      Context *on_finish, ProgressContext *progress_ctx) {
+      ProgressContext *progress_ctx, Context *on_finish) {
     ceph_assert(s_instance != nullptr);
     s_instance->on_finish = on_finish;
     return s_instance;
@@ -292,6 +295,16 @@ struct PrepareRemoteImageRequest<librbd::MockTestImageCtx> {
   MOCK_METHOD0(send, void());
 };
 
+template<>
+struct StateBuilder<librbd::MockTestImageCtx> {
+  virtual ~StateBuilder() {}
+
+  void destroy_sync_point_handler() {
+  }
+  void destroy() {
+  }
+};
+
 CloseImageRequest<librbd::MockTestImageCtx>*
   CloseImageRequest<librbd::MockTestImageCtx>::s_instance = nullptr;
 OpenImageRequest<librbd::MockTestImageCtx>*
@@ -376,10 +389,36 @@ struct PrepareReplayRequest<librbd::MockTestImageCtx> {
   MOCK_METHOD0(send, void());
 };
 
+template<>
+struct StateBuilder<librbd::MockTestImageCtx>
+  : image_replayer::StateBuilder<librbd::MockTestImageCtx>{
+  static StateBuilder* s_instance;
+
+  ::journal::MockJournaler* remote_journaler = nullptr;
+  librbd::journal::MirrorPeerClientMeta remote_client_meta;
+
+  image_sync::MockSyncPointHandler mock_sync_point_handler;
+
+  static StateBuilder* create(const std::string&) {
+    ceph_assert(s_instance != nullptr);
+    return s_instance;
+  }
+
+  image_sync::MockSyncPointHandler* create_sync_point_handler() {
+    return &mock_sync_point_handler;
+  }
+
+  StateBuilder() {
+    s_instance = this;
+  }
+};
+
 CreateLocalImageRequest<librbd::MockTestImageCtx>*
   CreateLocalImageRequest<librbd::MockTestImageCtx>::s_instance = nullptr;
 PrepareReplayRequest<librbd::MockTestImageCtx>*
   PrepareReplayRequest<librbd::MockTestImageCtx>::s_instance = nullptr;
+StateBuilder<librbd::MockTestImageCtx>*
+  StateBuilder<librbd::MockTestImageCtx>::s_instance = nullptr;
 
 } // namespace journal
 } // namespace image_replayer
@@ -419,6 +458,7 @@ public:
   typedef PrepareRemoteImageRequest<librbd::MockTestImageCtx> MockPrepareRemoteImageRequest;
   typedef journal::CreateLocalImageRequest<librbd::MockTestImageCtx> MockCreateLocalImageRequest;
   typedef journal::PrepareReplayRequest<librbd::MockTestImageCtx> MockPrepareReplayRequest;
+  typedef journal::StateBuilder<librbd::MockTestImageCtx> MockStateBuilder;
   typedef librbd::mirror::GetInfoRequest<librbd::MockTestImageCtx> MockGetMirrorInfoRequest;
   typedef std::list<cls::journal::Tag> Tags;
 
@@ -1047,6 +1087,7 @@ TEST_F(TestMockImageReplayerBootstrapRequest, PrepareReplaySyncing) {
   expect_prepare_replay(mock_prepare_replay_request, false, true, 0);
 
   // image sync
+  MockStateBuilder mock_state_builder;
   MockImageSync mock_image_sync;
   expect_image_sync(mock_image_sync, 0);
 
@@ -1167,6 +1208,7 @@ TEST_F(TestMockImageReplayerBootstrapRequest, ImageSyncError) {
   expect_prepare_replay(mock_prepare_replay_request, false, true, 0);
 
   // image sync
+  MockStateBuilder mock_state_builder;
   MockImageSync mock_image_sync;
   expect_image_sync(mock_image_sync, -EINVAL);
 
index 37556257a3fa0a68beb958757fba33512b13f94b..69c2f3883842dbef6d9314ff95c38285fc6001a4 100644 (file)
@@ -3,11 +3,9 @@
 
 #include "test/rbd_mirror/test_mock_fixture.h"
 #include "include/rbd/librbd.hpp"
-#include "librbd/journal/Types.h"
-#include "librbd/journal/TypeTraits.h"
-#include "test/journal/mock/MockJournaler.h"
 #include "test/librados_test_stub/MockTestMemIoCtxImpl.h"
 #include "test/librbd/mock/MockImageCtx.h"
+#include "test/rbd_mirror/mock/image_sync/MockSyncPointHandler.h"
 #include "tools/rbd_mirror/image_sync/SyncPointCreateRequest.h"
 
 namespace librbd {
@@ -22,26 +20,20 @@ struct MockTestImageCtx : public librbd::MockImageCtx {
 
 } // anonymous namespace
 
-namespace journal {
-
-template <>
-struct TypeTraits<librbd::MockTestImageCtx> {
-  typedef ::journal::MockJournaler Journaler;
-};
-
-} // namespace journal
 } // namespace librbd
 
 // template definitions
 #include "tools/rbd_mirror/image_sync/SyncPointCreateRequest.cc"
-template class rbd::mirror::image_sync::SyncPointCreateRequest<librbd::MockTestImageCtx>;
 
 namespace rbd {
 namespace mirror {
 namespace image_sync {
 
 using ::testing::_;
+using ::testing::DoAll;
 using ::testing::InSequence;
+using ::testing::Invoke;
+using ::testing::Return;
 using ::testing::WithArg;
 
 class TestMockImageSyncSyncPointCreateRequest : public TestMockFixture {
@@ -56,9 +48,27 @@ public:
     ASSERT_EQ(0, open_image(m_remote_io_ctx, m_image_name, &m_remote_image_ctx));
   }
 
-  void expect_update_client(journal::MockJournaler &mock_journaler, int r) {
-    EXPECT_CALL(mock_journaler, update_client(_, _))
-      .WillOnce(WithArg<1>(CompleteContext(r)));
+  void expect_get_snap_seqs(MockSyncPointHandler& mock_sync_point_handler) {
+    EXPECT_CALL(mock_sync_point_handler, get_snap_seqs())
+      .WillRepeatedly(Return(librbd::SnapSeqs{}));
+  }
+
+  void expect_get_sync_points(MockSyncPointHandler& mock_sync_point_handler) {
+    EXPECT_CALL(mock_sync_point_handler, get_sync_points())
+      .WillRepeatedly(Invoke([this]() {
+                        return m_sync_points;
+                      }));
+  }
+
+  void expect_update_sync_points(MockSyncPointHandler& mock_sync_point_handler,
+                                 int r) {
+    EXPECT_CALL(mock_sync_point_handler, update_sync_points(_, _, false, _))
+      .WillOnce(DoAll(WithArg<1>(Invoke([this, r](const SyncPoints& sync_points) {
+                                   if (r >= 0) {
+                                     m_sync_points = sync_points;
+                                   }
+                                 })),
+                      WithArg<3>(CompleteContext(r))));
   }
 
   void expect_image_refresh(librbd::MockTestImageCtx &mock_remote_image_ctx, int r) {
@@ -72,98 +82,112 @@ public:
   }
 
   MockSyncPointCreateRequest *create_request(librbd::MockTestImageCtx &mock_remote_image_ctx,
-                                             journal::MockJournaler &mock_journaler,
+                                             MockSyncPointHandler& mock_sync_point_handler,
                                              Context *ctx) {
     return new MockSyncPointCreateRequest(&mock_remote_image_ctx, "uuid",
-                                          &mock_journaler, &m_client_meta, ctx);
+                                          &mock_sync_point_handler, ctx);
   }
 
   librbd::ImageCtx *m_remote_image_ctx;
-  librbd::journal::MirrorPeerClientMeta m_client_meta;
+  SyncPoints m_sync_points;
 };
 
 TEST_F(TestMockImageSyncSyncPointCreateRequest, Success) {
   librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
-  journal::MockJournaler mock_journaler;
+  MockSyncPointHandler mock_sync_point_handler;
+
+  expect_get_snap_seqs(mock_sync_point_handler);
+  expect_get_sync_points(mock_sync_point_handler);
 
   InSequence seq;
-  expect_update_client(mock_journaler, 0);
+  expect_update_sync_points(mock_sync_point_handler, 0);
   expect_image_refresh(mock_remote_image_ctx, 0);
   expect_snap_create(mock_remote_image_ctx, 0);
   expect_image_refresh(mock_remote_image_ctx, 0);
 
   C_SaferCond ctx;
   MockSyncPointCreateRequest *req = create_request(mock_remote_image_ctx,
-                                                   mock_journaler, &ctx);
+                                                   mock_sync_point_handler,
+                                                   &ctx);
   req->send();
   ASSERT_EQ(0, ctx.wait());
 
-  ASSERT_EQ(1U, m_client_meta.sync_points.size());
+  ASSERT_EQ(1U, m_sync_points.size());
 }
 
 TEST_F(TestMockImageSyncSyncPointCreateRequest, ResyncSuccess) {
-  m_client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
-                                         "start snap",
-                                         "",
-                                         boost::none);
-  auto sync_point = m_client_meta.sync_points.front();
+  m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "start snap",
+                              "", boost::none);
+  auto sync_point = m_sync_points.front();
 
   librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
-  journal::MockJournaler mock_journaler;
+  MockSyncPointHandler mock_sync_point_handler;
+
+  expect_get_snap_seqs(mock_sync_point_handler);
+  expect_get_sync_points(mock_sync_point_handler);
 
   InSequence seq;
-  expect_update_client(mock_journaler, 0);
+  expect_update_sync_points(mock_sync_point_handler, 0);
   expect_image_refresh(mock_remote_image_ctx, 0);
   expect_snap_create(mock_remote_image_ctx, 0);
   expect_image_refresh(mock_remote_image_ctx, 0);
 
   C_SaferCond ctx;
   MockSyncPointCreateRequest *req = create_request(mock_remote_image_ctx,
-                                                   mock_journaler, &ctx);
+                                                   mock_sync_point_handler,
+                                                   &ctx);
   req->send();
   ASSERT_EQ(0, ctx.wait());
 
-  ASSERT_EQ(2U, m_client_meta.sync_points.size());
-  ASSERT_EQ(sync_point, m_client_meta.sync_points.front());
-  ASSERT_EQ("start snap", m_client_meta.sync_points.back().from_snap_name);
+  ASSERT_EQ(2U, m_sync_points.size());
+  ASSERT_EQ(sync_point, m_sync_points.front());
+  ASSERT_EQ("start snap", m_sync_points.back().from_snap_name);
 }
 
 TEST_F(TestMockImageSyncSyncPointCreateRequest, SnapshotExists) {
   librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
-  journal::MockJournaler mock_journaler;
+  MockSyncPointHandler mock_sync_point_handler;
+
+  expect_get_snap_seqs(mock_sync_point_handler);
+  expect_get_sync_points(mock_sync_point_handler);
 
   InSequence seq;
-  expect_update_client(mock_journaler, 0);
+  expect_update_sync_points(mock_sync_point_handler, 0);
   expect_image_refresh(mock_remote_image_ctx, 0);
   expect_snap_create(mock_remote_image_ctx, -EEXIST);
-  expect_update_client(mock_journaler, 0);
+  expect_update_sync_points(mock_sync_point_handler, 0);
   expect_image_refresh(mock_remote_image_ctx, 0);
   expect_snap_create(mock_remote_image_ctx, 0);
   expect_image_refresh(mock_remote_image_ctx, 0);
 
   C_SaferCond ctx;
   MockSyncPointCreateRequest *req = create_request(mock_remote_image_ctx,
-                                                   mock_journaler, &ctx);
+                                                   mock_sync_point_handler,
+                                                   &ctx);
   req->send();
   ASSERT_EQ(0, ctx.wait());
 
-  ASSERT_EQ(1U, m_client_meta.sync_points.size());
+  ASSERT_EQ(1U, m_sync_points.size());
 }
 
 TEST_F(TestMockImageSyncSyncPointCreateRequest, ClientUpdateError) {
   librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
-  journal::MockJournaler mock_journaler;
+  MockSyncPointHandler mock_sync_point_handler;
+
+  expect_get_snap_seqs(mock_sync_point_handler);
+  expect_get_sync_points(mock_sync_point_handler);
 
   InSequence seq;
-  expect_update_client(mock_journaler, -EINVAL);
+  expect_update_sync_points(mock_sync_point_handler, -EINVAL);
 
   C_SaferCond ctx;
   MockSyncPointCreateRequest *req = create_request(mock_remote_image_ctx,
-                                                   mock_journaler, &ctx);
+                                                   mock_sync_point_handler,
+                                                   &ctx);
   req->send();
   ASSERT_EQ(-EINVAL, ctx.wait());
 
-  ASSERT_TRUE(m_client_meta.sync_points.empty());
+  ASSERT_TRUE(m_sync_points.empty());
 }
 
 } // namespace image_sync
index d230944e1b2234d518b80ab561b1409e75bc1e9f..bd13f3cd00b1b3394652c92e3c380a182b92c8a0 100644 (file)
@@ -3,11 +3,9 @@
 
 #include "test/rbd_mirror/test_mock_fixture.h"
 #include "include/rbd/librbd.hpp"
-#include "librbd/journal/Types.h"
-#include "librbd/journal/TypeTraits.h"
-#include "test/journal/mock/MockJournaler.h"
 #include "test/librados_test_stub/MockTestMemIoCtxImpl.h"
 #include "test/librbd/mock/MockImageCtx.h"
+#include "test/rbd_mirror/mock/image_sync/MockSyncPointHandler.h"
 #include "tools/rbd_mirror/image_sync/SyncPointPruneRequest.h"
 
 namespace librbd {
@@ -22,14 +20,6 @@ struct MockTestImageCtx : public librbd::MockImageCtx {
 
 } // anonymous namespace
 
-namespace journal {
-
-template <>
-struct TypeTraits<librbd::MockTestImageCtx> {
-  typedef ::journal::MockJournaler Journaler;
-};
-
-} // namespace journal
 } // namespace librbd
 
 // template definitions
@@ -41,7 +31,9 @@ namespace mirror {
 namespace image_sync {
 
 using ::testing::_;
+using ::testing::DoAll;
 using ::testing::InSequence;
+using ::testing::Invoke;
 using ::testing::Return;
 using ::testing::StrEq;
 using ::testing::WithArg;
@@ -58,9 +50,27 @@ public:
     ASSERT_EQ(0, open_image(m_remote_io_ctx, m_image_name, &m_remote_image_ctx));
   }
 
-  void expect_update_client(journal::MockJournaler &mock_journaler, int r) {
-    EXPECT_CALL(mock_journaler, update_client(_, _))
-      .WillOnce(WithArg<1>(CompleteContext(r)));
+  void expect_get_snap_seqs(MockSyncPointHandler& mock_sync_point_handler) {
+    EXPECT_CALL(mock_sync_point_handler, get_snap_seqs())
+      .WillRepeatedly(Return(librbd::SnapSeqs{}));
+  }
+
+  void expect_get_sync_points(MockSyncPointHandler& mock_sync_point_handler) {
+    EXPECT_CALL(mock_sync_point_handler, get_sync_points())
+      .WillRepeatedly(Invoke([this]() {
+                        return m_sync_points;
+                      }));
+  }
+
+  void expect_update_sync_points(MockSyncPointHandler& mock_sync_point_handler,
+                                 bool complete, int r) {
+    EXPECT_CALL(mock_sync_point_handler, update_sync_points(_, _, complete, _))
+      .WillOnce(DoAll(WithArg<1>(Invoke([this, r](const SyncPoints& sync_points) {
+                                   if (r >= 0) {
+                                     m_sync_points = sync_points;
+                                   }
+                                 })),
+                      WithArg<3>(CompleteContext(r))));
   }
 
   void expect_get_snap_id(librbd::MockTestImageCtx &mock_remote_image_ctx,
@@ -81,256 +91,255 @@ public:
   }
 
   MockSyncPointPruneRequest *create_request(librbd::MockTestImageCtx &mock_remote_image_ctx,
-                                            journal::MockJournaler &mock_journaler,
+                                            MockSyncPointHandler& mock_sync_point_handler,
                                             bool sync_complete, Context *ctx) {
     return new MockSyncPointPruneRequest(&mock_remote_image_ctx, sync_complete,
-                                         &mock_journaler, &m_client_meta, ctx);
+                                         &mock_sync_point_handler, ctx);
   }
 
   librbd::ImageCtx *m_remote_image_ctx;
-  librbd::journal::MirrorPeerClientMeta m_client_meta;
+  SyncPoints m_sync_points;
 };
 
 TEST_F(TestMockImageSyncSyncPointPruneRequest, SyncInProgressSuccess) {
-  librbd::journal::MirrorPeerClientMeta client_meta;
-  client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
-                                       "snap1",
-                                       boost::none);
-  m_client_meta = client_meta;
+  m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap1",
+                             "", boost::none);
+  auto sync_points = m_sync_points;
 
   librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
-  journal::MockJournaler mock_journaler;
+  MockSyncPointHandler mock_sync_point_handler;
+
+  expect_get_snap_seqs(mock_sync_point_handler);
+  expect_get_sync_points(mock_sync_point_handler);
 
   InSequence seq;
   expect_get_snap_id(mock_remote_image_ctx, "snap1", 123);
   expect_image_refresh(mock_remote_image_ctx, 0);
-  expect_update_client(mock_journaler, 0);
+  expect_update_sync_points(mock_sync_point_handler, false, 0);
 
   C_SaferCond ctx;
   MockSyncPointPruneRequest *req = create_request(mock_remote_image_ctx,
-                                                  mock_journaler, false, &ctx);
+                                                  mock_sync_point_handler,
+                                                  false, &ctx);
   req->send();
   ASSERT_EQ(0, ctx.wait());
-  ASSERT_EQ(client_meta, m_client_meta);
+  ASSERT_EQ(sync_points, m_sync_points);
 }
 
 TEST_F(TestMockImageSyncSyncPointPruneRequest, RestartedSyncInProgressSuccess) {
-  librbd::journal::MirrorPeerClientMeta client_meta;
-  client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
-                                       "snap2",
-                                       "snap1", boost::none);
-  client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
-                                       "snap1",
-                                       boost::none);
-  m_client_meta = client_meta;
+  m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap2",
+                              "snap1", boost::none);
+  m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap1", "",
+                              boost::none);
+  auto sync_points = m_sync_points;
 
   librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
-  journal::MockJournaler mock_journaler;
+  MockSyncPointHandler mock_sync_point_handler;
+
+  expect_get_snap_seqs(mock_sync_point_handler);
+  expect_get_sync_points(mock_sync_point_handler);
 
   InSequence seq;
   expect_get_snap_id(mock_remote_image_ctx, "snap1", 123);
   expect_snap_remove(mock_remote_image_ctx, "snap2", 0);
   expect_image_refresh(mock_remote_image_ctx, 0);
-  expect_update_client(mock_journaler, 0);
+  expect_update_sync_points(mock_sync_point_handler, false, 0);
 
   C_SaferCond ctx;
   MockSyncPointPruneRequest *req = create_request(mock_remote_image_ctx,
-                                                  mock_journaler, false, &ctx);
+                                                  mock_sync_point_handler,
+                                                  false, &ctx);
   req->send();
   ASSERT_EQ(0, ctx.wait());
 
-  client_meta.sync_points.pop_back();
-  ASSERT_EQ(client_meta, m_client_meta);
+  sync_points.pop_back();
+  ASSERT_EQ(sync_points, m_sync_points);
 }
 
 TEST_F(TestMockImageSyncSyncPointPruneRequest, SyncInProgressMissingSnapSuccess) {
-  librbd::journal::MirrorPeerClientMeta client_meta;
-  client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
-                                       "snap2",
-                                       "snap1",
-                                       boost::none);
-  client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
-                                       "snap1",
-                                       boost::none);
-  m_client_meta = client_meta;
+  m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap2",
+                              "snap1", boost::none);
+  m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap1", "",
+                              boost::none);
 
   librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
-  journal::MockJournaler mock_journaler;
+  MockSyncPointHandler mock_sync_point_handler;
+
+  expect_get_snap_seqs(mock_sync_point_handler);
+  expect_get_sync_points(mock_sync_point_handler);
 
   InSequence seq;
   expect_get_snap_id(mock_remote_image_ctx, "snap1", CEPH_NOSNAP);
   expect_snap_remove(mock_remote_image_ctx, "snap2", 0);
   expect_snap_remove(mock_remote_image_ctx, "snap1", 0);
   expect_image_refresh(mock_remote_image_ctx, 0);
-  expect_update_client(mock_journaler, 0);
+  expect_update_sync_points(mock_sync_point_handler, false, 0);
 
   C_SaferCond ctx;
   MockSyncPointPruneRequest *req = create_request(mock_remote_image_ctx,
-                                                  mock_journaler, false, &ctx);
+                                                  mock_sync_point_handler,
+                                                  false, &ctx);
   req->send();
   ASSERT_EQ(0, ctx.wait());
 
-  client_meta.sync_points.clear();
-  ASSERT_EQ(client_meta, m_client_meta);
+  ASSERT_EQ(SyncPoints{}, m_sync_points);
 }
 
 TEST_F(TestMockImageSyncSyncPointPruneRequest, SyncInProgressUnexpectedFromSnapSuccess) {
-  librbd::journal::MirrorPeerClientMeta client_meta;
-  client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
-                                       "snap2",
-                                       "snap1",
-                                       boost::none);
-  m_client_meta = client_meta;
+  m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap2",
+                              "snap1", boost::none);
 
   librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
-  journal::MockJournaler mock_journaler;
+  MockSyncPointHandler mock_sync_point_handler;
+
+  expect_get_snap_seqs(mock_sync_point_handler);
+  expect_get_sync_points(mock_sync_point_handler);
 
   InSequence seq;
   expect_get_snap_id(mock_remote_image_ctx, "snap2", 124);
   expect_snap_remove(mock_remote_image_ctx, "snap2", 0);
   expect_snap_remove(mock_remote_image_ctx, "snap1", 0);
   expect_image_refresh(mock_remote_image_ctx, 0);
-  expect_update_client(mock_journaler, 0);
+  expect_update_sync_points(mock_sync_point_handler, false, 0);
 
   C_SaferCond ctx;
   MockSyncPointPruneRequest *req = create_request(mock_remote_image_ctx,
-                                                  mock_journaler, false, &ctx);
+                                                  mock_sync_point_handler,
+                                                  false, &ctx);
   req->send();
   ASSERT_EQ(0, ctx.wait());
 
-  client_meta.sync_points.clear();
-  ASSERT_EQ(client_meta, m_client_meta);
+  ASSERT_EQ(SyncPoints(), m_sync_points);
 }
 
 TEST_F(TestMockImageSyncSyncPointPruneRequest, SyncCompleteSuccess) {
-  librbd::journal::MirrorPeerClientMeta client_meta;
-  client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
-                                       "snap1",
-                                       boost::none);
-  m_client_meta = client_meta;
-  ASSERT_EQ(librbd::journal::MIRROR_PEER_STATE_SYNCING, m_client_meta.state);
+  m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap1",
+                              "", boost::none);
 
   librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
-  journal::MockJournaler mock_journaler;
+  MockSyncPointHandler mock_sync_point_handler;
+
+  expect_get_snap_seqs(mock_sync_point_handler);
+  expect_get_sync_points(mock_sync_point_handler);
 
   InSequence seq;
   expect_snap_remove(mock_remote_image_ctx, "snap1", 0);
   expect_image_refresh(mock_remote_image_ctx, 0);
-  expect_update_client(mock_journaler, 0);
+  expect_update_sync_points(mock_sync_point_handler, true, 0);
 
   C_SaferCond ctx;
   MockSyncPointPruneRequest *req = create_request(mock_remote_image_ctx,
-                                                  mock_journaler, true, &ctx);
+                                                  mock_sync_point_handler,
+                                                  true, &ctx);
   req->send();
   ASSERT_EQ(0, ctx.wait());
-  ASSERT_TRUE(m_client_meta.sync_points.empty());
-  ASSERT_EQ(librbd::journal::MIRROR_PEER_STATE_REPLAYING, m_client_meta.state);
+  ASSERT_TRUE(m_sync_points.empty());
 }
 
 TEST_F(TestMockImageSyncSyncPointPruneRequest, RestartedSyncCompleteSuccess) {
-  librbd::journal::MirrorPeerClientMeta client_meta;
-  client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
-                                       "snap2",
-                                       "snap1",
-                                       boost::none);
-  client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
-                                       "snap1",
-                                       boost::none);
-  m_client_meta = client_meta;
+  m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap2",
+                              "snap1", boost::none);
+  m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap1",
+                              "", boost::none);
+  auto sync_points = m_sync_points;
 
   librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
-  journal::MockJournaler mock_journaler;
+  MockSyncPointHandler mock_sync_point_handler;
+
+  expect_get_snap_seqs(mock_sync_point_handler);
+  expect_get_sync_points(mock_sync_point_handler);
 
   InSequence seq;
   expect_image_refresh(mock_remote_image_ctx, 0);
-  expect_update_client(mock_journaler, 0);
+  expect_update_sync_points(mock_sync_point_handler, true, 0);
 
   C_SaferCond ctx;
   MockSyncPointPruneRequest *req = create_request(mock_remote_image_ctx,
-                                                  mock_journaler, true, &ctx);
+                                                  mock_sync_point_handler,
+                                                  true, &ctx);
   req->send();
   ASSERT_EQ(0, ctx.wait());
-  client_meta.sync_points.pop_front();
-  ASSERT_EQ(client_meta, m_client_meta);
+  sync_points.pop_front();
+  ASSERT_EQ(sync_points, m_sync_points);
 }
 
 TEST_F(TestMockImageSyncSyncPointPruneRequest, RestartedCatchUpSyncCompleteSuccess) {
-  librbd::journal::MirrorPeerClientMeta client_meta;
-  client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
-                                       "snap3",
-                                       "snap2",
-                                       boost::none);
-  client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
-                                       "snap2",
-                                       "snap1",
-                                       boost::none);
-  m_client_meta = client_meta;
+  m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap3",
+                              "snap2", boost::none);
+  m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap2",
+                              "snap1", boost::none);
+  auto sync_points = m_sync_points;
 
   librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
-  journal::MockJournaler mock_journaler;
+  MockSyncPointHandler mock_sync_point_handler;
+
+  expect_get_snap_seqs(mock_sync_point_handler);
+  expect_get_sync_points(mock_sync_point_handler);
 
   InSequence seq;
   expect_snap_remove(mock_remote_image_ctx, "snap1", 0);
   expect_image_refresh(mock_remote_image_ctx, 0);
-  expect_update_client(mock_journaler, 0);
+  expect_update_sync_points(mock_sync_point_handler, true, 0);
 
   C_SaferCond ctx;
   MockSyncPointPruneRequest *req = create_request(mock_remote_image_ctx,
-                                                  mock_journaler, true, &ctx);
+                                                  mock_sync_point_handler,
+                                                  true, &ctx);
   req->send();
   ASSERT_EQ(0, ctx.wait());
-  client_meta.sync_points.pop_front();
-  ASSERT_EQ(client_meta, m_client_meta);
+  sync_points.pop_front();
+  ASSERT_EQ(sync_points, m_sync_points);
 }
 
 TEST_F(TestMockImageSyncSyncPointPruneRequest, SnapshotDNE) {
-  librbd::journal::MirrorPeerClientMeta client_meta;
-  client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
-                                       "snap1",
-                                       boost::none);
-  m_client_meta = client_meta;
+  m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap1",
+                              "", boost::none);
 
   librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
-  journal::MockJournaler mock_journaler;
+  MockSyncPointHandler mock_sync_point_handler;
+
+  expect_get_snap_seqs(mock_sync_point_handler);
+  expect_get_sync_points(mock_sync_point_handler);
 
   InSequence seq;
   expect_snap_remove(mock_remote_image_ctx, "snap1", -ENOENT);
   expect_image_refresh(mock_remote_image_ctx, 0);
-  expect_update_client(mock_journaler, 0);
+  expect_update_sync_points(mock_sync_point_handler, true, 0);
 
   C_SaferCond ctx;
   MockSyncPointPruneRequest *req = create_request(mock_remote_image_ctx,
-                                                  mock_journaler, true, &ctx);
+                                                  mock_sync_point_handler,
+                                                  true, &ctx);
   req->send();
   ASSERT_EQ(0, ctx.wait());
-  ASSERT_TRUE(m_client_meta.sync_points.empty());
+  ASSERT_TRUE(m_sync_points.empty());
 }
 
 TEST_F(TestMockImageSyncSyncPointPruneRequest, ClientUpdateError) {
-  librbd::journal::MirrorPeerClientMeta client_meta;
-  client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
-                                       "snap2",
-                                       "snap1",
-                                       boost::none);
-  client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
-                                       "snap1",
-                                       boost::none);
-  m_client_meta = client_meta;
+  m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap2",
+                              "snap1", boost::none);
+  m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap1",
+                              "", boost::none);
+  auto sync_points = m_sync_points;
 
   librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
-  journal::MockJournaler mock_journaler;
+  MockSyncPointHandler mock_sync_point_handler;
+
+  expect_get_snap_seqs(mock_sync_point_handler);
+  expect_get_sync_points(mock_sync_point_handler);
 
   InSequence seq;
   expect_image_refresh(mock_remote_image_ctx, 0);
-  expect_update_client(mock_journaler, -EINVAL);
+  expect_update_sync_points(mock_sync_point_handler, true, -EINVAL);
 
   C_SaferCond ctx;
   MockSyncPointPruneRequest *req = create_request(mock_remote_image_ctx,
-                                                  mock_journaler, true, &ctx);
+                                                  mock_sync_point_handler,
+                                                  true, &ctx);
   req->send();
   ASSERT_EQ(-EINVAL, ctx.wait());
 
-  ASSERT_EQ(client_meta, m_client_meta);
+  ASSERT_EQ(sync_points, m_sync_points);
 }
 
 } // namespace image_sync
diff --git a/src/test/rbd_mirror/mock/image_sync/MockSyncPointHandler.h b/src/test/rbd_mirror/mock/image_sync/MockSyncPointHandler.h
new file mode 100644 (file)
index 0000000..b6263cb
--- /dev/null
@@ -0,0 +1,29 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#ifndef CEPH_MOCK_IMAGE_SYNC_SYNC_POINT_HANDLER_H
+#define CEPH_MOCK_IMAGE_SYNC_SYNC_POINT_HANDLER_H
+
+#include "tools/rbd_mirror/image_sync/Types.h"
+#include <gmock/gmock.h>
+
+struct Context;
+
+namespace rbd {
+namespace mirror {
+namespace image_sync {
+
+struct MockSyncPointHandler : public SyncPointHandler{
+  MOCK_CONST_METHOD0(get_sync_points, SyncPoints());
+  MOCK_CONST_METHOD0(get_snap_seqs, librbd::SnapSeqs());
+
+  MOCK_METHOD4(update_sync_points, void(const librbd::SnapSeqs&,
+                                        const SyncPoints&,
+                                        bool, Context*));
+};
+
+} // namespace image_sync
+} // namespace mirror
+} // namespace rbd
+
+#endif // CEPH_MOCK_IMAGE_SYNC_SYNC_POINT_HANDLER_H
index b585ea571fbcf575c4619959464d5d510c808665..c8aab54b0b5af1d72a418f895a6320c61a53daf7 100644 (file)
@@ -21,6 +21,7 @@
 #include "tools/rbd_mirror/InstanceWatcher.h"
 #include "tools/rbd_mirror/Threads.h"
 #include "tools/rbd_mirror/Throttler.h"
+#include "tools/rbd_mirror/image_replayer/journal/StateBuilder.h"
 
 void register_test_image_sync() {
 }
@@ -92,11 +93,21 @@ public:
     encode(client_data, client_data_bl);
 
     ASSERT_EQ(0, m_remote_journaler->register_client(client_data_bl));
+
+    m_state_builder = rbd::mirror::image_replayer::journal::StateBuilder<
+      librbd::ImageCtx>::create("global image id");
+    m_state_builder->remote_journaler = m_remote_journaler;
+    m_state_builder->remote_client_meta = m_client_meta;
+    m_sync_point_handler = m_state_builder->create_sync_point_handler();
   }
 
   void TearDown() override {
     m_instance_watcher->handle_release_leader();
 
+    m_state_builder->remote_journaler = nullptr;
+    m_state_builder->destroy_sync_point_handler();
+    m_state_builder->destroy();
+
     delete m_remote_journaler;
     delete m_instance_watcher;
     delete m_image_sync_throttler;
@@ -119,10 +130,9 @@ public:
   }
 
   ImageSync<> *create_request(Context *ctx) {
-    return new ImageSync<>(m_local_image_ctx, m_remote_image_ctx,
-                           m_threads->timer, &m_threads->timer_lock,
-                           "mirror-uuid", m_remote_journaler, &m_client_meta,
-                           m_threads->work_queue, m_instance_watcher, ctx);
+    return new ImageSync<>(m_threads, m_local_image_ctx, m_remote_image_ctx,
+                           "mirror-uuid", m_sync_point_handler,
+                           m_instance_watcher, nullptr, ctx);
   }
 
   librbd::ImageCtx *m_remote_image_ctx;
@@ -131,6 +141,8 @@ public:
   rbd::mirror::InstanceWatcher<> *m_instance_watcher;
   ::journal::Journaler *m_remote_journaler;
   librbd::journal::MirrorPeerClientMeta m_client_meta;
+  rbd::mirror::image_replayer::journal::StateBuilder<librbd::ImageCtx>* m_state_builder = nullptr;
+  rbd::mirror::image_sync::SyncPointHandler* m_sync_point_handler = nullptr;
 };
 
 TEST_F(TestImageSync, Empty) {
index f7c24a4370b987faf21dc6658205603f1914b457..b86d4bee88c957690af27a479d01ac225baff621 100644 (file)
@@ -4,11 +4,9 @@
 #include "test/rbd_mirror/test_mock_fixture.h"
 #include "include/rbd/librbd.hpp"
 #include "librbd/DeepCopyRequest.h"
-#include "librbd/journal/Types.h"
-#include "librbd/journal/TypeTraits.h"
-#include "test/journal/mock/MockJournaler.h"
 #include "test/librados_test_stub/MockTestMemIoCtxImpl.h"
 #include "test/librbd/mock/MockImageCtx.h"
+#include "test/rbd_mirror/mock/image_sync/MockSyncPointHandler.h"
 #include "tools/rbd_mirror/ImageSync.h"
 #include "tools/rbd_mirror/Threads.h"
 #include "tools/rbd_mirror/image_sync/SyncPointCreateRequest.h"
@@ -26,15 +24,6 @@ struct MockTestImageCtx : public librbd::MockImageCtx {
 
 } // anonymous namespace
 
-namespace journal {
-
-template <>
-struct TypeTraits<librbd::MockTestImageCtx> {
-  typedef ::journal::MockJournaler Journaler;
-};
-
-} // namespace journal
-
 template <>
 class DeepCopyRequest<librbd::MockTestImageCtx> {
 public:
@@ -78,6 +67,18 @@ template class rbd::mirror::ImageSync<librbd::MockTestImageCtx>;
 namespace rbd {
 namespace mirror {
 
+template <>
+struct Threads<librbd::MockTestImageCtx> {
+  ceph::mutex &timer_lock;
+  SafeTimer *timer;
+  ContextWQ *work_queue;
+
+  Threads(Threads<librbd::ImageCtx> *threads)
+    : timer_lock(threads->timer_lock), timer(threads->timer),
+      work_queue(threads->work_queue) {
+  }
+};
+
 template<>
 struct InstanceWatcher<librbd::MockTestImageCtx> {
   MOCK_METHOD2(notify_sync_request, void(const std::string, Context *));
@@ -95,8 +96,7 @@ public:
 
   static SyncPointCreateRequest* create(librbd::MockTestImageCtx *remote_image_ctx,
                                         const std::string &mirror_uuid,
-                                        journal::MockJournaler *journaler,
-                                        librbd::journal::MirrorPeerClientMeta *client_meta,
+                                        image_sync::SyncPointHandler* sync_point_handler,
                                         Context *on_finish) {
     ceph_assert(s_instance != nullptr);
     s_instance->on_finish = on_finish;
@@ -118,8 +118,7 @@ public:
 
   static SyncPointPruneRequest* create(librbd::MockTestImageCtx *remote_image_ctx,
                                        bool sync_complete,
-                                       journal::MockJournaler *journaler,
-                                       librbd::journal::MirrorPeerClientMeta *client_meta,
+                                       image_sync::SyncPointHandler* sync_point_handler,
                                        Context *on_finish) {
     ceph_assert(s_instance != nullptr);
     s_instance->on_finish = on_finish;
@@ -149,10 +148,12 @@ using ::testing::InvokeWithoutArgs;
 
 class TestMockImageSync : public TestMockFixture {
 public:
+  typedef Threads<librbd::MockTestImageCtx> MockThreads;
   typedef ImageSync<librbd::MockTestImageCtx> MockImageSync;
   typedef InstanceWatcher<librbd::MockTestImageCtx> MockInstanceWatcher;
   typedef image_sync::SyncPointCreateRequest<librbd::MockTestImageCtx> MockSyncPointCreateRequest;
   typedef image_sync::SyncPointPruneRequest<librbd::MockTestImageCtx> MockSyncPointPruneRequest;
+  typedef image_sync::MockSyncPointHandler MockSyncPointHandler;
   typedef librbd::DeepCopyRequest<librbd::MockTestImageCtx> MockImageCopyRequest;
 
   void SetUp() override {
@@ -198,9 +199,8 @@ public:
           if (r == 0) {
             mock_local_image_ctx.snap_ids[{cls::rbd::UserSnapshotNamespace(),
                                           "snap1"}] = 123;
-            m_client_meta.sync_points.emplace_back(cls::rbd::UserSnapshotNamespace(),
-                                                  "snap1",
-                                                  boost::none);
+            m_sync_points.emplace_back(cls::rbd::UserSnapshotNamespace(),
+                                       "snap1", "", boost::none);
           }
           m_threads->work_queue->queue(mock_sync_point_create_request.on_finish, r);
         }));
@@ -213,9 +213,10 @@ public:
         }));
   }
 
-  void expect_flush_sync_point(journal::MockJournaler &mock_journaler, int r) {
-    EXPECT_CALL(mock_journaler, update_client(_, _))
-      .WillOnce(WithArg<1>(CompleteContext(r)));
+  void expect_flush_sync_point(MockSyncPointHandler& mock_sync_point_handler,
+                               int r) {
+    EXPECT_CALL(mock_sync_point_handler, update_sync_points(_, _, false, _))
+      .WillOnce(WithArg<3>(CompleteContext(r)));
   }
 
   void expect_prune_sync_point(MockSyncPointPruneRequest &mock_sync_point_prune_request,
@@ -223,12 +224,12 @@ public:
     EXPECT_CALL(mock_sync_point_prune_request, send())
       .WillOnce(Invoke([this, &mock_sync_point_prune_request, sync_complete, r]() {
           ASSERT_EQ(sync_complete, mock_sync_point_prune_request.sync_complete);
-          if (r == 0 && !m_client_meta.sync_points.empty()) {
+          if (r == 0 && !m_sync_points.empty()) {
             if (sync_complete) {
-              m_client_meta.sync_points.pop_front();
+              m_sync_points.pop_front();
             } else {
-              while (m_client_meta.sync_points.size() > 1) {
-                m_client_meta.sync_points.pop_back();
+              while (m_sync_points.size() > 1) {
+                m_sync_points.pop_back();
               }
             }
           }
@@ -236,88 +237,114 @@ public:
         }));
   }
 
-  MockImageSync *create_request(librbd::MockTestImageCtx &mock_remote_image_ctx,
+  void expect_get_snap_seqs(MockSyncPointHandler& mock_sync_point_handler) {
+    EXPECT_CALL(mock_sync_point_handler, get_snap_seqs())
+      .WillRepeatedly(Return(librbd::SnapSeqs{}));
+  }
+
+  void expect_get_sync_points(MockSyncPointHandler& mock_sync_point_handler) {
+    EXPECT_CALL(mock_sync_point_handler, get_sync_points())
+      .WillRepeatedly(Invoke([this]() {
+                        return m_sync_points;
+                      }));
+  }
+
+  MockImageSync *create_request(MockThreads& mock_threads,
+                                librbd::MockTestImageCtx &mock_remote_image_ctx,
                                 librbd::MockTestImageCtx &mock_local_image_ctx,
-                                journal::MockJournaler &mock_journaler,
+                                MockSyncPointHandler& mock_sync_point_handler,
                                 MockInstanceWatcher &mock_instance_watcher,
                                 Context *ctx) {
-    return new MockImageSync(&mock_local_image_ctx, &mock_remote_image_ctx,
-                             m_threads->timer, &m_threads->timer_lock,
-                             "mirror-uuid", &mock_journaler, &m_client_meta,
-                             m_threads->work_queue, &mock_instance_watcher,
-                             ctx);
+    return new MockImageSync(&mock_threads, &mock_local_image_ctx,
+                             &mock_remote_image_ctx,
+                             "mirror-uuid", &mock_sync_point_handler,
+                             &mock_instance_watcher, nullptr, ctx);
   }
 
   librbd::ImageCtx *m_remote_image_ctx;
   librbd::ImageCtx *m_local_image_ctx;
-  librbd::journal::MirrorPeerClientMeta m_client_meta;
+
+  image_sync::SyncPoints m_sync_points;
 };
 
 TEST_F(TestMockImageSync, SimpleSync) {
+  MockThreads mock_threads(m_threads);
   librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
   librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
-  journal::MockJournaler mock_journaler;
+  MockSyncPointHandler mock_sync_point_handler;
   MockInstanceWatcher mock_instance_watcher;
   MockImageCopyRequest mock_image_copy_request;
   MockSyncPointCreateRequest mock_sync_point_create_request;
   MockSyncPointPruneRequest mock_sync_point_prune_request;
 
+  expect_get_snap_seqs(mock_sync_point_handler);
+  expect_get_sync_points(mock_sync_point_handler);
+
   InSequence seq;
   expect_notify_sync_request(mock_instance_watcher, mock_local_image_ctx.id, 0);
   expect_create_sync_point(mock_local_image_ctx, mock_sync_point_create_request, 0);
   expect_get_snap_id(mock_remote_image_ctx);
   expect_copy_image(mock_image_copy_request, 0);
-  expect_flush_sync_point(mock_journaler, 0);
+  expect_flush_sync_point(mock_sync_point_handler, 0);
   expect_prune_sync_point(mock_sync_point_prune_request, true, 0);
   expect_notify_sync_complete(mock_instance_watcher, mock_local_image_ctx.id);
 
   C_SaferCond ctx;
-  MockImageSync *request = create_request(mock_remote_image_ctx,
-                                          mock_local_image_ctx, mock_journaler,
+  MockImageSync *request = create_request(mock_threads, mock_remote_image_ctx,
+                                          mock_local_image_ctx,
+                                          mock_sync_point_handler,
                                           mock_instance_watcher, &ctx);
   request->send();
   ASSERT_EQ(0, ctx.wait());
 }
 
 TEST_F(TestMockImageSync, RestartSync) {
+  MockThreads mock_threads(m_threads);
   librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
   librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
-  journal::MockJournaler mock_journaler;
+  MockSyncPointHandler mock_sync_point_handler;
   MockInstanceWatcher mock_instance_watcher;
   MockImageCopyRequest mock_image_copy_request;
   MockSyncPointCreateRequest mock_sync_point_create_request;
   MockSyncPointPruneRequest mock_sync_point_prune_request;
 
-  m_client_meta.sync_points = {{cls::rbd::UserSnapshotNamespace(), "snap1", boost::none},
-                               {cls::rbd::UserSnapshotNamespace(), "snap2", "snap1", boost::none}};
+  m_sync_points = {{cls::rbd::UserSnapshotNamespace(), "snap1", "", boost::none},
+                   {cls::rbd::UserSnapshotNamespace(), "snap2", "snap1", boost::none}};
   mock_local_image_ctx.snap_ids[{cls::rbd::UserSnapshotNamespace(), "snap1"}] = 123;
   mock_local_image_ctx.snap_ids[{cls::rbd::UserSnapshotNamespace(), "snap2"}] = 234;
 
   expect_test_features(mock_local_image_ctx);
+  expect_get_snap_seqs(mock_sync_point_handler);
+  expect_get_sync_points(mock_sync_point_handler);
 
   InSequence seq;
   expect_notify_sync_request(mock_instance_watcher, mock_local_image_ctx.id, 0);
   expect_prune_sync_point(mock_sync_point_prune_request, false, 0);
   expect_get_snap_id(mock_remote_image_ctx);
   expect_copy_image(mock_image_copy_request, 0);
-  expect_flush_sync_point(mock_journaler, 0);
+  expect_flush_sync_point(mock_sync_point_handler, 0);
   expect_prune_sync_point(mock_sync_point_prune_request, true, 0);
   expect_notify_sync_complete(mock_instance_watcher, mock_local_image_ctx.id);
 
   C_SaferCond ctx;
-  MockImageSync *request = create_request(mock_remote_image_ctx,
-                                          mock_local_image_ctx, mock_journaler,
+  MockImageSync *request = create_request(mock_threads, mock_remote_image_ctx,
+                                          mock_local_image_ctx,
+                                          mock_sync_point_handler,
                                           mock_instance_watcher, &ctx);
   request->send();
   ASSERT_EQ(0, ctx.wait());
 }
 
 TEST_F(TestMockImageSync, CancelNotifySyncRequest) {
+  MockThreads mock_threads(m_threads);
   librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
   librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
-  journal::MockJournaler mock_journaler;
+  MockSyncPointHandler mock_sync_point_handler;
   MockInstanceWatcher mock_instance_watcher;
 
+  expect_get_snap_seqs(mock_sync_point_handler);
+  expect_get_sync_points(mock_sync_point_handler);
+
   InSequence seq;
   Context *on_sync_start = nullptr;
   C_SaferCond notify_sync_ctx;
@@ -337,8 +364,9 @@ TEST_F(TestMockImageSync, CancelNotifySyncRequest) {
         }));
 
   C_SaferCond ctx;
-  MockImageSync *request = create_request(mock_remote_image_ctx,
-                                          mock_local_image_ctx, mock_journaler,
+  MockImageSync *request = create_request(mock_threads, mock_remote_image_ctx,
+                                          mock_local_image_ctx,
+                                          mock_sync_point_handler,
                                           mock_instance_watcher, &ctx);
   request->get();
   request->send();
@@ -352,15 +380,18 @@ TEST_F(TestMockImageSync, CancelNotifySyncRequest) {
 }
 
 TEST_F(TestMockImageSync, CancelImageCopy) {
+  MockThreads mock_threads(m_threads);
   librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
   librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
-  journal::MockJournaler mock_journaler;
+  MockSyncPointHandler mock_sync_point_handler;
   MockInstanceWatcher mock_instance_watcher;
   MockImageCopyRequest mock_image_copy_request;
   MockSyncPointCreateRequest mock_sync_point_create_request;
   MockSyncPointPruneRequest mock_sync_point_prune_request;
 
-  m_client_meta.sync_points = {{cls::rbd::UserSnapshotNamespace(), "snap1", boost::none}};
+  m_sync_points = {{cls::rbd::UserSnapshotNamespace(), "snap1", "", boost::none}};
+  expect_get_snap_seqs(mock_sync_point_handler);
+  expect_get_sync_points(mock_sync_point_handler);
 
   InSequence seq;
   expect_notify_sync_request(mock_instance_watcher, mock_local_image_ctx.id, 0);
@@ -378,8 +409,9 @@ TEST_F(TestMockImageSync, CancelImageCopy) {
   expect_notify_sync_complete(mock_instance_watcher, mock_local_image_ctx.id);
 
   C_SaferCond ctx;
-  MockImageSync *request = create_request(mock_remote_image_ctx,
-                                          mock_local_image_ctx, mock_journaler,
+  MockImageSync *request = create_request(mock_threads, mock_remote_image_ctx,
+                                          mock_local_image_ctx,
+                                          mock_sync_point_handler,
                                           mock_instance_watcher, &ctx);
   request->get();
   request->send();
@@ -394,18 +426,24 @@ TEST_F(TestMockImageSync, CancelImageCopy) {
 }
 
 TEST_F(TestMockImageSync, CancelAfterCopyImage) {
+  MockThreads mock_threads(m_threads);
   librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
   librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
-  journal::MockJournaler mock_journaler;
+  MockSyncPointHandler mock_sync_point_handler;
   MockInstanceWatcher mock_instance_watcher;
   MockImageCopyRequest mock_image_copy_request;
   MockSyncPointCreateRequest mock_sync_point_create_request;
   MockSyncPointPruneRequest mock_sync_point_prune_request;
 
   C_SaferCond ctx;
-  MockImageSync *request = create_request(mock_remote_image_ctx,
-                                          mock_local_image_ctx, mock_journaler,
+  MockImageSync *request = create_request(mock_threads, mock_remote_image_ctx,
+                                          mock_local_image_ctx,
+                                          mock_sync_point_handler,
                                           mock_instance_watcher, &ctx);
+
+  expect_get_snap_seqs(mock_sync_point_handler);
+  expect_get_sync_points(mock_sync_point_handler);
+
   InSequence seq;
   expect_notify_sync_request(mock_instance_watcher, mock_local_image_ctx.id, 0);
   expect_create_sync_point(mock_local_image_ctx, mock_sync_point_create_request, 0);
index ae1c475f62379105881cd0ea3a8c1920de9cf155..f9d8f357e42e49e51c361b5ce5b084616f0e7c1f 100644 (file)
@@ -7,15 +7,15 @@
 #include "common/debug.h"
 #include "common/Timer.h"
 #include "common/errno.h"
-#include "journal/Journaler.h"
 #include "librbd/DeepCopyRequest.h"
 #include "librbd/ImageCtx.h"
 #include "librbd/ImageState.h"
 #include "librbd/Utils.h"
 #include "librbd/internal.h"
-#include "librbd/journal/Types.h"
+#include "tools/rbd_mirror/Threads.h"
 #include "tools/rbd_mirror/image_sync/SyncPointCreateRequest.h"
 #include "tools/rbd_mirror/image_sync/SyncPointPruneRequest.h"
+#include "tools/rbd_mirror/image_sync/Types.h"
 
 #define dout_context g_ceph_context
 #define dout_subsys ceph_subsys_rbd_mirror
@@ -46,22 +46,27 @@ public:
 };
 
 template <typename I>
-ImageSync<I>::ImageSync(I *local_image_ctx, I *remote_image_ctx,
-                        SafeTimer *timer, ceph::mutex *timer_lock,
-                        const std::string &mirror_uuid, Journaler *journaler,
-                        MirrorPeerClientMeta *client_meta,
-                        ContextWQ *work_queue,
-                        InstanceWatcher<I> *instance_watcher,
-                        Context *on_finish, ProgressContext *progress_ctx)
+ImageSync<I>::ImageSync(
+    Threads<I>* threads,
+    I *local_image_ctx,
+    I *remote_image_ctx,
+    const std::string &local_mirror_uuid,
+    image_sync::SyncPointHandler* sync_point_handler,
+    InstanceWatcher<I> *instance_watcher,
+    ProgressContext *progress_ctx,
+    Context *on_finish)
   : BaseRequest("rbd::mirror::ImageSync", local_image_ctx->cct, on_finish),
-    m_local_image_ctx(local_image_ctx), m_remote_image_ctx(remote_image_ctx),
-    m_timer(timer), m_timer_lock(timer_lock), m_mirror_uuid(mirror_uuid),
-    m_journaler(journaler), m_client_meta(client_meta),
-    m_work_queue(work_queue), m_instance_watcher(instance_watcher),
+    m_threads(threads),
+    m_local_image_ctx(local_image_ctx),
+    m_remote_image_ctx(remote_image_ctx),
+    m_local_mirror_uuid(local_mirror_uuid),
+    m_sync_point_handler(sync_point_handler),
+    m_instance_watcher(instance_watcher),
     m_progress_ctx(progress_ctx),
     m_lock(ceph::make_mutex(unique_lock_name("ImageSync::m_lock", this))),
-    m_update_sync_point_interval(m_local_image_ctx->cct->_conf.template get_val<double>(
-        "rbd_mirror_sync_point_update_age")), m_client_meta_copy(*client_meta) {
+    m_update_sync_point_interval(
+      m_local_image_ctx->cct->_conf.template get_val<double>(
+        "rbd_mirror_sync_point_update_age")) {
 }
 
 template <typename I>
@@ -107,7 +112,7 @@ void ImageSync<I>::send_notify_sync_request() {
   }
 
   Context *ctx = create_async_context_callback(
-    m_work_queue, create_context_callback<
+    m_threads->work_queue, create_context_callback<
       ImageSync<I>, &ImageSync<I>::handle_notify_sync_request>(this));
   m_instance_watcher->notify_sync_request(m_local_image_ctx->id, ctx);
   m_lock.unlock();
@@ -135,7 +140,7 @@ template <typename I>
 void ImageSync<I>::send_prune_catch_up_sync_point() {
   update_progress("PRUNE_CATCH_UP_SYNC_POINT");
 
-  if (m_client_meta->sync_points.empty()) {
+  if (m_sync_point_handler->get_sync_points().empty()) {
     send_create_sync_point();
     return;
   }
@@ -148,7 +153,7 @@ void ImageSync<I>::send_prune_catch_up_sync_point() {
   Context *ctx = create_context_callback<
     ImageSync<I>, &ImageSync<I>::handle_prune_catch_up_sync_point>(this);
   SyncPointPruneRequest<I> *request = SyncPointPruneRequest<I>::create(
-    m_remote_image_ctx, false, m_journaler, m_client_meta, ctx);
+    m_remote_image_ctx, false, m_sync_point_handler, ctx);
   request->send();
 }
 
@@ -172,7 +177,7 @@ void ImageSync<I>::send_create_sync_point() {
 
   // TODO: when support for disconnecting laggy clients is added,
   //       re-connect and create catch-up sync point
-  if (m_client_meta->sync_points.size() > 0) {
+  if (!m_sync_point_handler->get_sync_points().empty()) {
     send_copy_image();
     return;
   }
@@ -182,7 +187,7 @@ void ImageSync<I>::send_create_sync_point() {
   Context *ctx = create_context_callback<
     ImageSync<I>, &ImageSync<I>::handle_create_sync_point>(this);
   SyncPointCreateRequest<I> *request = SyncPointCreateRequest<I>::create(
-    m_remote_image_ctx, m_mirror_uuid, m_journaler, m_client_meta, ctx);
+    m_remote_image_ctx, m_local_mirror_uuid, m_sync_point_handler, ctx);
   request->send();
 }
 
@@ -206,10 +211,14 @@ void ImageSync<I>::send_copy_image() {
   librados::snap_t snap_id_end;
   librbd::deep_copy::ObjectNumber object_number;
   int r = 0;
+
+  m_snap_seqs_copy = m_sync_point_handler->get_snap_seqs();
+  m_sync_points_copy = m_sync_point_handler->get_sync_points();
+  ceph_assert(!m_sync_points_copy.empty());
+  auto &sync_point = m_sync_points_copy.front();
+
   {
     std::shared_lock image_locker{m_remote_image_ctx->image_lock};
-    ceph_assert(!m_client_meta->sync_points.empty());
-    auto &sync_point = m_client_meta->sync_points.front();
     snap_id_end = m_remote_image_ctx->get_snap_id(
        cls::rbd::UserSnapshotNamespace(), sync_point.snap_name);
     if (snap_id_end == CEPH_NOSNAP) {
@@ -245,7 +254,7 @@ void ImageSync<I>::send_copy_image() {
   m_image_copy_prog_ctx = new ImageCopyProgressContext(this);
   m_image_copy_request = librbd::DeepCopyRequest<I>::create(
       m_remote_image_ctx, m_local_image_ctx, snap_id_start, snap_id_end,
-      false, object_number, m_work_queue, &m_client_meta->snap_seqs,
+      false, object_number, m_threads->work_queue, &m_snap_seqs_copy,
       m_image_copy_prog_ctx, ctx);
   m_image_copy_request->get();
   m_lock.unlock();
@@ -260,7 +269,7 @@ void ImageSync<I>::handle_copy_image(int r) {
   dout(10) << ": r=" << r << dendl;
 
   {
-    std::scoped_lock locker{*m_timer_lock, m_lock};
+    std::scoped_lock locker{m_threads->timer_lock, m_lock};
     m_image_copy_request->put();
     m_image_copy_request = nullptr;
     delete m_image_copy_prog_ctx;
@@ -270,7 +279,7 @@ void ImageSync<I>::handle_copy_image(int r) {
     }
 
     if (m_update_sync_ctx != nullptr) {
-      m_timer->cancel_event(m_update_sync_ctx);
+      m_threads->timer->cancel_event(m_update_sync_ctx);
       m_update_sync_ctx = nullptr;
     }
 
@@ -318,10 +327,10 @@ void ImageSync<I>::send_update_sync_point() {
     return;
   }
 
-  auto sync_point = &m_client_meta->sync_points.front();
+  ceph_assert(!m_sync_points_copy.empty());
+  auto sync_point = &m_sync_points_copy.front();
 
-  if (m_client_meta->sync_object_count == m_image_copy_object_count &&
-      sync_point->object_number &&
+  if (sync_point->object_number &&
       (m_image_copy_object_no - 1) == sync_point->object_number.get()) {
     // update sync point did not progress since last sync
     return;
@@ -329,23 +338,14 @@ void ImageSync<I>::send_update_sync_point() {
 
   m_updating_sync_point = true;
 
-  m_client_meta_copy = *m_client_meta;
-  m_client_meta->sync_object_count = m_image_copy_object_count;
   if (m_image_copy_object_no > 0) {
     sync_point->object_number = m_image_copy_object_no - 1;
   }
 
-  CephContext *cct = m_local_image_ctx->cct;
-  ldout(cct, 20) << ": sync_point=" << *sync_point << dendl;
-
-  bufferlist client_data_bl;
-  librbd::journal::ClientData client_data(*m_client_meta);
-  encode(client_data, client_data_bl);
-
-  Context *ctx = create_context_callback<
-    ImageSync<I>, &ImageSync<I>::handle_update_sync_point>(
-      this);
-  m_journaler->update_client(client_data_bl, ctx);
+  auto ctx = create_context_callback<
+    ImageSync<I>, &ImageSync<I>::handle_update_sync_point>(this);
+  m_sync_point_handler->update_sync_points(m_snap_seqs_copy,
+                                           m_sync_points_copy, false, ctx);
 }
 
 template <typename I>
@@ -353,14 +353,8 @@ void ImageSync<I>::handle_update_sync_point(int r) {
   CephContext *cct = m_local_image_ctx->cct;
   ldout(cct, 20) << ": r=" << r << dendl;
 
-  if (r < 0) {
-    *m_client_meta = m_client_meta_copy;
-    lderr(cct) << ": failed to update client data: " << cpp_strerror(r)
-               << dendl;
-  }
-
   {
-    std::scoped_lock locker{*m_timer_lock, m_lock};
+    std::scoped_lock locker{m_threads->timer_lock, m_lock};
     m_updating_sync_point = false;
 
     if (m_image_copy_request != nullptr) {
@@ -369,8 +363,8 @@ void ImageSync<I>::handle_update_sync_point(int r) {
          std::lock_guard locker{m_lock};
           this->send_update_sync_point();
         });
-      m_timer->add_event_after(m_update_sync_point_interval,
-                               m_update_sync_ctx);
+      m_threads->timer->add_event_after(
+        m_update_sync_point_interval, m_update_sync_ctx);
       return;
     }
   }
@@ -387,25 +381,19 @@ void ImageSync<I>::send_flush_sync_point() {
 
   update_progress("FLUSH_SYNC_POINT");
 
-  m_client_meta_copy = *m_client_meta;
-  m_client_meta->sync_object_count = m_image_copy_object_count;
-  auto sync_point = &m_client_meta->sync_points.front();
+  ceph_assert(!m_sync_points_copy.empty());
+  auto sync_point = &m_sync_points_copy.front();
+
   if (m_image_copy_object_no > 0) {
     sync_point->object_number = m_image_copy_object_no - 1;
   } else {
     sync_point->object_number = boost::none;
   }
 
-  dout(10) << ": sync_point=" << *sync_point << dendl;
-
-  bufferlist client_data_bl;
-  librbd::journal::ClientData client_data(*m_client_meta);
-  encode(client_data, client_data_bl);
-
-  Context *ctx = create_context_callback<
-    ImageSync<I>, &ImageSync<I>::handle_flush_sync_point>(
-      this);
-  m_journaler->update_client(client_data_bl, ctx);
+  auto ctx = create_context_callback<
+    ImageSync<I>, &ImageSync<I>::handle_flush_sync_point>(this);
+  m_sync_point_handler->update_sync_points(m_snap_seqs_copy,
+                                           m_sync_points_copy, false, ctx);
 }
 
 template <typename I>
@@ -413,8 +401,6 @@ void ImageSync<I>::handle_flush_sync_point(int r) {
   dout(10) << ": r=" << r << dendl;
 
   if (r < 0) {
-    *m_client_meta = m_client_meta_copy;
-
     derr << ": failed to update client data: " << cpp_strerror(r)
          << dendl;
     finish(r);
@@ -433,7 +419,7 @@ void ImageSync<I>::send_prune_sync_points() {
   Context *ctx = create_context_callback<
     ImageSync<I>, &ImageSync<I>::handle_prune_sync_points>(this);
   SyncPointPruneRequest<I> *request = SyncPointPruneRequest<I>::create(
-    m_remote_image_ctx, true, m_journaler, m_client_meta, ctx);
+    m_remote_image_ctx, true, m_sync_point_handler, ctx);
   request->send();
 }
 
@@ -448,7 +434,7 @@ void ImageSync<I>::handle_prune_sync_points(int r) {
     return;
   }
 
-  if (!m_client_meta->sync_points.empty()) {
+  if (!m_sync_point_handler->get_sync_points().empty()) {
     send_copy_image();
     return;
   }
index 1fcc14c7eafc3216eaffaed973a3a89b6323aa0d..eebb1273d3db67110c25468c8df902403ae1b621 100644 (file)
@@ -6,54 +6,52 @@
 
 #include "include/int_types.h"
 #include "librbd/ImageCtx.h"
-#include "librbd/journal/TypeTraits.h"
-#include "librbd/journal/Types.h"
+#include "librbd/Types.h"
 #include "common/ceph_mutex.h"
 #include "tools/rbd_mirror/BaseRequest.h"
-#include <map>
-#include <vector>
+#include "tools/rbd_mirror/image_sync/Types.h"
 
 class Context;
 class ContextWQ;
 namespace journal { class Journaler; }
 namespace librbd { class ProgressContext; }
 namespace librbd { template <typename> class DeepCopyRequest; }
-namespace librbd { namespace journal { struct MirrorPeerClientMeta; } }
 
 namespace rbd {
 namespace mirror {
 
 class ProgressContext;
-
 template <typename> class InstanceWatcher;
+template <typename> class Threads;
+
+namespace image_sync { struct SyncPointHandler; }
 
 template <typename ImageCtxT = librbd::ImageCtx>
 class ImageSync : public BaseRequest {
 public:
-  typedef librbd::journal::TypeTraits<ImageCtxT> TypeTraits;
-  typedef typename TypeTraits::Journaler Journaler;
-  typedef librbd::journal::MirrorPeerClientMeta MirrorPeerClientMeta;
-
-  static ImageSync* create(ImageCtxT *local_image_ctx,
-                           ImageCtxT *remote_image_ctx,
-                           SafeTimer *timer, ceph::mutex *timer_lock,
-                           const std::string &mirror_uuid,
-                           Journaler *journaler,
-                           MirrorPeerClientMeta *client_meta,
-                           ContextWQ *work_queue,
-                           InstanceWatcher<ImageCtxT> *instance_watcher,
-                           Context *on_finish,
-                           ProgressContext *progress_ctx = nullptr) {
-    return new ImageSync(local_image_ctx, remote_image_ctx, timer, timer_lock,
-                         mirror_uuid, journaler, client_meta, work_queue,
-                         instance_watcher, on_finish, progress_ctx);
+  static ImageSync* create(
+      Threads<ImageCtxT>* threads,
+      ImageCtxT *local_image_ctx,
+      ImageCtxT *remote_image_ctx,
+      const std::string &local_mirror_uuid,
+      image_sync::SyncPointHandler* sync_point_handler,
+      InstanceWatcher<ImageCtxT> *instance_watcher,
+      ProgressContext *progress_ctx,
+      Context *on_finish) {
+    return new ImageSync(threads, local_image_ctx, remote_image_ctx,
+                         local_mirror_uuid, sync_point_handler,
+                         instance_watcher, progress_ctx, on_finish);
   }
 
-  ImageSync(ImageCtxT *local_image_ctx, ImageCtxT *remote_image_ctx,
-            SafeTimer *timer, ceph::mutex *timer_lock, const std::string &mirror_uuid,
-            Journaler *journaler, MirrorPeerClientMeta *client_meta,
-            ContextWQ *work_queue, InstanceWatcher<ImageCtxT> *instance_watcher,
-            Context *on_finish, ProgressContext *progress_ctx = nullptr);
+  ImageSync(
+      Threads<ImageCtxT>* threads,
+      ImageCtxT *local_image_ctx,
+      ImageCtxT *remote_image_ctx,
+      const std::string &local_mirror_uuid,
+      image_sync::SyncPointHandler* sync_point_handler,
+      InstanceWatcher<ImageCtxT> *instance_watcher,
+      ProgressContext *progress_ctx,
+      Context *on_finish);
   ~ImageSync() override;
 
   void send() override;
@@ -92,23 +90,16 @@ private:
    * @endverbatim
    */
 
-  typedef std::vector<librados::snap_t> SnapIds;
-  typedef std::map<librados::snap_t, SnapIds> SnapMap;
   class ImageCopyProgressContext;
 
+  Threads<ImageCtxT>* m_threads;
   ImageCtxT *m_local_image_ctx;
   ImageCtxT *m_remote_image_ctx;
-  SafeTimer *m_timer;
-  ceph::mutex *m_timer_lock;
-  std::string m_mirror_uuid;
-  Journaler *m_journaler;
-  MirrorPeerClientMeta *m_client_meta;
-  ContextWQ *m_work_queue;
+  std::string m_local_mirror_uuid;
+  image_sync::SyncPointHandler* m_sync_point_handler;
   InstanceWatcher<ImageCtxT> *m_instance_watcher;
   ProgressContext *m_progress_ctx;
 
-  SnapMap m_snap_map;
-
   ceph::mutex m_lock;
   bool m_canceled = false;
 
@@ -120,7 +111,9 @@ private:
   double m_update_sync_point_interval;
   uint64_t m_image_copy_object_no = 0;
   uint64_t m_image_copy_object_count = 0;
-  MirrorPeerClientMeta m_client_meta_copy;
+
+  librbd::SnapSeqs m_snap_seqs_copy;
+  image_sync::SyncPoints m_sync_points_copy;
 
   int m_ret_val = 0;
 
index 9b93da5c88edcfb68b89021ff82c5f318397c5a4..06920de953382c8d1641b49a51f1bc6fd3f9a5e7 100644 (file)
@@ -28,6 +28,8 @@
 #include "tools/rbd_mirror/image_replayer/PrepareRemoteImageRequest.h"
 #include "tools/rbd_mirror/image_replayer/journal/CreateLocalImageRequest.h"
 #include "tools/rbd_mirror/image_replayer/journal/PrepareReplayRequest.h"
+#include "tools/rbd_mirror/image_replayer/journal/StateBuilder.h"
+#include "tools/rbd_mirror/image_replayer/journal/SyncPointHandler.h"
 
 #define dout_context g_ceph_context
 #define dout_subsys ceph_subsys_rbd_mirror
@@ -449,13 +451,17 @@ void BootstrapRequest<I>::image_sync() {
   dout(15) << dendl;
   ceph_assert(m_image_sync == nullptr);
 
+  // TODO temporary
+  m_state_builder = journal::StateBuilder<I>::create(m_global_image_id);
+  m_state_builder->remote_journaler = *m_remote_journaler;
+  m_state_builder->remote_client_meta = m_client_meta;
+  auto sync_point_handler = m_state_builder->create_sync_point_handler();
+
   Context *ctx = create_context_callback<
     BootstrapRequest<I>, &BootstrapRequest<I>::handle_image_sync>(this);
   m_image_sync = ImageSync<I>::create(
-    *m_local_image_ctx, m_remote_image_ctx, m_threads->timer,
-    &m_threads->timer_lock, m_local_mirror_uuid, *m_remote_journaler,
-    &m_client_meta, m_threads->work_queue, m_instance_watcher, ctx,
-    m_progress_ctx);
+    m_threads, *m_local_image_ctx, m_remote_image_ctx, m_local_mirror_uuid,
+    sync_point_handler, m_instance_watcher, m_progress_ctx, ctx);
   m_image_sync->get();
   locker.unlock();
 
@@ -471,6 +477,13 @@ void BootstrapRequest<I>::handle_image_sync(int r) {
     std::lock_guard locker{m_lock};
     m_image_sync->put();
     m_image_sync = nullptr;
+
+    m_state_builder->destroy_sync_point_handler();
+
+    // TODO
+    m_state_builder->remote_journaler = nullptr;
+    m_state_builder->destroy();
+    m_state_builder = nullptr;
   }
 
   if (r < 0) {
index 012bbbe2141b8842c882d5f5324bd7f0523232ad..8e9f868a1f6bcd22e063a155e1365060c3f7e71d 100644 (file)
@@ -35,6 +35,9 @@ template <typename> struct Threads;
 
 namespace image_replayer {
 
+// TODO
+namespace journal { template <typename> class StateBuilder; }
+
 template <typename ImageCtxT = librbd::ImageCtx>
 class BootstrapRequest : public BaseRequest {
 public:
@@ -175,6 +178,9 @@ private:
   bool m_syncing = false;
   ImageSync<ImageCtxT> *m_image_sync = nullptr;
 
+  // TODO temporary
+  journal::StateBuilder<ImageCtxT>* m_state_builder = nullptr;
+
   void prepare_local_image();
   void handle_prepare_local_image(int r);
 
index ffe2eca9f37f4a3de8c3eb145b02c4fa91f62e6d..53153b0c678653a6b7226637236110e554eb04d0 100644 (file)
@@ -5,11 +5,11 @@
 #include "include/uuid.h"
 #include "common/debug.h"
 #include "common/errno.h"
-#include "journal/Journaler.h"
 #include "librbd/ImageCtx.h"
 #include "librbd/ImageState.h"
 #include "librbd/Operations.h"
 #include "librbd/Utils.h"
+#include "tools/rbd_mirror/image_sync/Types.h"
 
 #define dout_context g_ceph_context
 #define dout_subsys ceph_subsys_rbd_mirror
@@ -30,52 +30,49 @@ static const std::string SNAP_NAME_PREFIX(".rbd-mirror");
 using librbd::util::create_context_callback;
 
 template <typename I>
-SyncPointCreateRequest<I>::SyncPointCreateRequest(I *remote_image_ctx,
-                                                  const std::string &mirror_uuid,
-                                                  Journaler *journaler,
-                                                  MirrorPeerClientMeta *client_meta,
-                                                  Context *on_finish)
-  : m_remote_image_ctx(remote_image_ctx), m_mirror_uuid(mirror_uuid),
-    m_journaler(journaler), m_client_meta(client_meta), m_on_finish(on_finish),
-    m_client_meta_copy(*client_meta) {
-  ceph_assert(m_client_meta->sync_points.size() < 2);
+SyncPointCreateRequest<I>::SyncPointCreateRequest(
+    I *remote_image_ctx,
+    const std::string &local_mirror_uuid,
+    SyncPointHandler* sync_point_handler,
+    Context *on_finish)
+  : m_remote_image_ctx(remote_image_ctx),
+    m_local_mirror_uuid(local_mirror_uuid),
+    m_sync_point_handler(sync_point_handler),
+    m_on_finish(on_finish) {
+  m_sync_points_copy = m_sync_point_handler->get_sync_points();
+  ceph_assert(m_sync_points_copy.size() < 2);
 
   // initialize the updated client meta with the new sync point
-  m_client_meta_copy.sync_points.emplace_back();
-  if (m_client_meta_copy.sync_points.size() > 1) {
-    m_client_meta_copy.sync_points.back().from_snap_name =
-      m_client_meta_copy.sync_points.front().snap_name;
+  m_sync_points_copy.emplace_back();
+  if (m_sync_points_copy.size() > 1) {
+    m_sync_points_copy.back().from_snap_name =
+      m_sync_points_copy.front().snap_name;
   }
 }
 
 template <typename I>
 void SyncPointCreateRequest<I>::send() {
-  send_update_client();
+  send_update_sync_points();
 }
 
 template <typename I>
-void SyncPointCreateRequest<I>::send_update_client() {
+void SyncPointCreateRequest<I>::send_update_sync_points() {
   uuid_d uuid_gen;
   uuid_gen.generate_random();
 
-  MirrorPeerSyncPoint &sync_point = m_client_meta_copy.sync_points.back();
-  sync_point.snap_name = SNAP_NAME_PREFIX + "." + m_mirror_uuid + "." +
+  auto& sync_point = m_sync_points_copy.back();
+  sync_point.snap_name = SNAP_NAME_PREFIX + "." + m_local_mirror_uuid + "." +
                          uuid_gen.to_string();
 
-  dout(20) << ": sync_point=" << sync_point << dendl;
-
-  bufferlist client_data_bl;
-  librbd::journal::ClientData client_data(m_client_meta_copy);
-  encode(client_data, client_data_bl);
-
-  Context *ctx = create_context_callback<
-    SyncPointCreateRequest<I>, &SyncPointCreateRequest<I>::handle_update_client>(
-      this);
-  m_journaler->update_client(client_data_bl, ctx);
+  auto ctx = create_context_callback<
+    SyncPointCreateRequest<I>,
+    &SyncPointCreateRequest<I>::handle_update_sync_points>(this);
+  m_sync_point_handler->update_sync_points(
+    m_sync_point_handler->get_snap_seqs(), m_sync_points_copy, false, ctx);
 }
 
 template <typename I>
-void SyncPointCreateRequest<I>::handle_update_client(int r) {
+void SyncPointCreateRequest<I>::handle_update_sync_points(int r) {
   dout(20) << ": r=" << r << dendl;
 
   if (r < 0) {
@@ -85,9 +82,6 @@ void SyncPointCreateRequest<I>::handle_update_client(int r) {
     return;
   }
 
-  // update provided meta structure to reflect reality
-  *m_client_meta = m_client_meta_copy;
-
   send_refresh_image();
 }
 
@@ -118,7 +112,7 @@ template <typename I>
 void SyncPointCreateRequest<I>::send_create_snap() {
   dout(20) << dendl;
 
-  MirrorPeerSyncPoint &sync_point = m_client_meta_copy.sync_points.back();
+  auto& sync_point = m_sync_points_copy.back();
 
   Context *ctx = create_context_callback<
     SyncPointCreateRequest<I>, &SyncPointCreateRequest<I>::handle_create_snap>(
@@ -132,7 +126,7 @@ void SyncPointCreateRequest<I>::handle_create_snap(int r) {
   dout(20) << ": r=" << r << dendl;
 
   if (r == -EEXIST) {
-    send_update_client();
+    send_update_sync_points();
     return;
   } else if (r < 0) {
     derr << ": failed to create snapshot: " << cpp_strerror(r) << dendl;
index 45275ec4e2fb59795040bc3b0a7aa289ee12f3c0..278795af967e11827f09d550655dfae7948c6231 100644 (file)
@@ -4,8 +4,7 @@
 #ifndef RBD_MIRROR_IMAGE_SYNC_SYNC_POINT_CREATE_REQUEST_H
 #define RBD_MIRROR_IMAGE_SYNC_SYNC_POINT_CREATE_REQUEST_H
 
-#include "librbd/journal/Types.h"
-#include "librbd/journal/TypeTraits.h"
+#include "Types.h"
 #include <string>
 
 class Context;
@@ -20,23 +19,20 @@ namespace image_sync {
 template <typename ImageCtxT = librbd::ImageCtx>
 class SyncPointCreateRequest {
 public:
-  typedef librbd::journal::TypeTraits<ImageCtxT> TypeTraits;
-  typedef typename TypeTraits::Journaler Journaler;
-  typedef librbd::journal::MirrorPeerClientMeta MirrorPeerClientMeta;
-  typedef librbd::journal::MirrorPeerSyncPoint MirrorPeerSyncPoint;
-
-  static SyncPointCreateRequest* create(ImageCtxT *remote_image_ctx,
-                                        const std::string &mirror_uuid,
-                                        Journaler *journaler,
-                                        MirrorPeerClientMeta *client_meta,
-                                        Context *on_finish) {
-    return new SyncPointCreateRequest(remote_image_ctx, mirror_uuid, journaler,
-                                      client_meta, on_finish);
+  static SyncPointCreateRequest* create(
+      ImageCtxT *remote_image_ctx,
+      const std::string &local_mirror_uuid,
+      SyncPointHandler* sync_point_handler,
+      Context *on_finish) {
+    return new SyncPointCreateRequest(remote_image_ctx, local_mirror_uuid,
+                                      sync_point_handler, on_finish);
   }
 
-  SyncPointCreateRequest(ImageCtxT *remote_image_ctx,
-                         const std::string &mirror_uuid, Journaler *journaler,
-                         MirrorPeerClientMeta *client_meta, Context *on_finish);
+  SyncPointCreateRequest(
+      ImageCtxT *remote_image_ctx,
+      const std::string &local_mirror_uuid,
+      SyncPointHandler* sync_point_handler,
+      Context *on_finish);
 
   void send();
 
@@ -47,13 +43,13 @@ private:
    * <start>
    *    |
    *    v
-   * UPDATE_CLIENT < . .
-   *    |              .
-   *    v              .
-   * REFRESH_IMAGE     .
-   *    |              . (repeat on EEXIST)
-   *    v              .
-   * CREATE_SNAP . . . .
+   * UPDATE_SYNC_POINTS < . .
+   *    |                   .
+   *    v                   .
+   * REFRESH_IMAGE          .
+   *    |                   . (repeat on EEXIST)
+   *    v                   .
+   * CREATE_SNAP  . . . . . .
    *    |
    *    v
    * REFRESH_IMAGE
@@ -65,15 +61,14 @@ private:
    */
 
   ImageCtxT *m_remote_image_ctx;
-  std::string m_mirror_uuid;
-  Journaler *m_journaler;
-  MirrorPeerClientMeta *m_client_meta;
+  std::string m_local_mirror_uuid;
+  SyncPointHandler* m_sync_point_handler;
   Context *m_on_finish;
 
-  MirrorPeerClientMeta m_client_meta_copy;
+  SyncPoints m_sync_points_copy;
 
-  void send_update_client();
-  void handle_update_client(int r);
+  void send_update_sync_points();
+  void handle_update_sync_points(int r);
 
   void send_refresh_image();
   void handle_refresh_image(int r);
index 73e17abb79faca127dc22c9cd3d5a02cb55c3b92..d1cd32b39f35911ad8f23d00b2d25de1e697cbec 100644 (file)
@@ -4,7 +4,6 @@
 #include "SyncPointPruneRequest.h"
 #include "common/debug.h"
 #include "common/errno.h"
-#include "journal/Journaler.h"
 #include "librbd/ImageCtx.h"
 #include "librbd/ImageState.h"
 #include "librbd/Operations.h"
@@ -23,30 +22,32 @@ namespace image_sync {
 using librbd::util::create_context_callback;
 
 template <typename I>
-SyncPointPruneRequest<I>::SyncPointPruneRequest(I *remote_image_ctx,
-                                                bool sync_complete,
-                                                Journaler *journaler,
-                                                MirrorPeerClientMeta *client_meta,
-                                                Context *on_finish)
-  : m_remote_image_ctx(remote_image_ctx), m_sync_complete(sync_complete),
-    m_journaler(journaler), m_client_meta(client_meta), m_on_finish(on_finish),
-    m_client_meta_copy(*client_meta) {
+SyncPointPruneRequest<I>::SyncPointPruneRequest(
+    I *remote_image_ctx,
+    bool sync_complete,
+    SyncPointHandler* sync_point_handler,
+    Context *on_finish)
+  : m_remote_image_ctx(remote_image_ctx),
+    m_sync_complete(sync_complete),
+    m_sync_point_handler(sync_point_handler),
+    m_on_finish(on_finish) {
+  m_sync_points_copy = m_sync_point_handler->get_sync_points();
 }
 
 template <typename I>
 void SyncPointPruneRequest<I>::send() {
-  if (m_client_meta->sync_points.empty()) {
+  if (m_sync_points_copy.empty()) {
     send_remove_snap();
     return;
   }
 
   if (m_sync_complete) {
     // if sync is complete, we can remove the master sync point
-    auto it = m_client_meta_copy.sync_points.begin();
-    MirrorPeerSyncPoint &sync_point = *it;
+    auto it = m_sync_points_copy.begin();
+    auto& sync_point = *it;
 
     ++it;
-    if (it == m_client_meta_copy.sync_points.end() ||
+    if (it == m_sync_points_copy.end() ||
         it->from_snap_name != sync_point.snap_name) {
       m_snap_names.push_back(sync_point.snap_name);
     }
@@ -59,10 +60,10 @@ void SyncPointPruneRequest<I>::send() {
     // trim them off
     std::shared_lock image_locker{m_remote_image_ctx->image_lock};
     std::set<std::string> snap_names;
-    for (auto it = m_client_meta_copy.sync_points.rbegin();
-         it != m_client_meta_copy.sync_points.rend(); ++it) {
-      MirrorPeerSyncPoint &sync_point = *it;
-      if (&sync_point == &m_client_meta_copy.sync_points.front()) {
+    for (auto it = m_sync_points_copy.rbegin();
+         it != m_sync_points_copy.rend(); ++it) {
+      auto& sync_point = *it;
+      if (&sync_point == &m_sync_points_copy.front()) {
         if (m_remote_image_ctx->get_snap_id(
              cls::rbd::UserSnapshotNamespace(), sync_point.snap_name) ==
               CEPH_NOSNAP) {
@@ -83,8 +84,7 @@ void SyncPointPruneRequest<I>::send() {
         m_snap_names.push_back(sync_point.snap_name);
       }
 
-      MirrorPeerSyncPoint &front_sync_point =
-        m_client_meta_copy.sync_points.front();
+      auto& front_sync_point = m_sync_points_copy.front();
       if (!sync_point.from_snap_name.empty() &&
           snap_names.count(sync_point.from_snap_name) == 0 &&
           sync_point.from_snap_name != front_sync_point.snap_name) {
@@ -157,40 +157,35 @@ void SyncPointPruneRequest<I>::handle_refresh_image(int r) {
     return;
   }
 
-  send_update_client();
+  send_update_sync_points();
 }
 
 template <typename I>
-void SyncPointPruneRequest<I>::send_update_client() {
+void SyncPointPruneRequest<I>::send_update_sync_points() {
   dout(20) << dendl;
 
   if (m_sync_complete) {
-    m_client_meta_copy.sync_points.pop_front();
-    if (m_client_meta_copy.sync_points.empty()) {
-      m_client_meta_copy.state = librbd::journal::MIRROR_PEER_STATE_REPLAYING;
-    }
+    m_sync_points_copy.pop_front();
   } else {
-    while (m_client_meta_copy.sync_points.size() > 1) {
-      m_client_meta_copy.sync_points.pop_back();
+    while (m_sync_points_copy.size() > 1) {
+      m_sync_points_copy.pop_back();
     }
     if (m_invalid_master_sync_point) {
       // all subsequent sync points would have been pruned
-      m_client_meta_copy.sync_points.clear();
+      m_sync_points_copy.clear();
     }
   }
 
-  bufferlist client_data_bl;
-  librbd::journal::ClientData client_data(m_client_meta_copy);
-  encode(client_data, client_data_bl);
-
-  Context *ctx = create_context_callback<
-    SyncPointPruneRequest<I>, &SyncPointPruneRequest<I>::handle_update_client>(
-      this);
-  m_journaler->update_client(client_data_bl, ctx);
+  auto ctx = create_context_callback<
+    SyncPointPruneRequest<I>,
+    &SyncPointPruneRequest<I>::handle_update_sync_points>(this);
+  m_sync_point_handler->update_sync_points(
+    m_sync_point_handler->get_snap_seqs(), m_sync_points_copy,
+    m_sync_complete, ctx);
 }
 
 template <typename I>
-void SyncPointPruneRequest<I>::handle_update_client(int r) {
+void SyncPointPruneRequest<I>::handle_update_sync_points(int r) {
   dout(20) << ": r=" << r << dendl;
 
   if (r < 0) {
@@ -200,8 +195,6 @@ void SyncPointPruneRequest<I>::handle_update_client(int r) {
     return;
   }
 
-  // update provided meta structure to reflect reality
-  *m_client_meta = m_client_meta_copy;
   finish(0);
 }
 
index 65e13ef5d496210e96bbd5614bb13fc2adcebf54..08bf840b186c991de70489f2e7e29691d23e7690 100644 (file)
@@ -4,8 +4,7 @@
 #ifndef RBD_MIRROR_IMAGE_SYNC_SYNC_POINT_PRUNE_REQUEST_H
 #define RBD_MIRROR_IMAGE_SYNC_SYNC_POINT_PRUNE_REQUEST_H
 
-#include "librbd/journal/Types.h"
-#include "librbd/journal/TypeTraits.h"
+#include "tools/rbd_mirror/image_sync/Types.h"
 #include <list>
 #include <string>
 
@@ -21,23 +20,20 @@ namespace image_sync {
 template <typename ImageCtxT = librbd::ImageCtx>
 class SyncPointPruneRequest {
 public:
-  typedef librbd::journal::TypeTraits<ImageCtxT> TypeTraits;
-  typedef typename TypeTraits::Journaler Journaler;
-  typedef librbd::journal::MirrorPeerClientMeta MirrorPeerClientMeta;
-  typedef librbd::journal::MirrorPeerSyncPoint MirrorPeerSyncPoint;
-
-  static SyncPointPruneRequest* create(ImageCtxT *remote_image_ctx,
-                                       bool sync_complete,
-                                       Journaler *journaler,
-                                       MirrorPeerClientMeta *client_meta,
-                                       Context *on_finish) {
-    return new SyncPointPruneRequest(remote_image_ctx, sync_complete, journaler,
-                                      client_meta, on_finish);
+  static SyncPointPruneRequest* create(
+      ImageCtxT *remote_image_ctx,
+      bool sync_complete,
+      SyncPointHandler* sync_point_handler,
+      Context *on_finish) {
+    return new SyncPointPruneRequest(remote_image_ctx, sync_complete,
+                                     sync_point_handler, on_finish);
   }
 
-  SyncPointPruneRequest(ImageCtxT *remote_image_ctx, bool sync_complete,
-                        Journaler *journaler, MirrorPeerClientMeta *client_meta,
-                        Context *on_finish);
+  SyncPointPruneRequest(
+      ImageCtxT *remote_image_ctx,
+      bool sync_complete,
+      SyncPointHandler* sync_point_handler,
+      Context *on_finish);
 
   void send();
 
@@ -66,11 +62,10 @@ private:
 
   ImageCtxT *m_remote_image_ctx;
   bool m_sync_complete;
-  Journaler *m_journaler;
-  MirrorPeerClientMeta *m_client_meta;
+  SyncPointHandler* m_sync_point_handler;
   Context *m_on_finish;
 
-  MirrorPeerClientMeta m_client_meta_copy;
+  SyncPoints m_sync_points_copy;
   std::list<std::string> m_snap_names;
 
   bool m_invalid_master_sync_point = false;
@@ -81,8 +76,8 @@ private:
   void send_refresh_image();
   void handle_refresh_image(int r);
 
-  void send_update_client();
-  void handle_update_client(int r);
+  void send_update_sync_points();
+  void handle_update_sync_points(int r);
 
   void finish(int r);
 };