]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: periodically flush prior to updating status 27937/head
authorJason Dillaman <dillaman@redhat.com>
Thu, 11 Apr 2019 21:01:22 +0000 (17:01 -0400)
committerPrashant D <pdhange@redhat.com>
Thu, 2 May 2019 23:18:22 +0000 (19:18 -0400)
This ensure the most up-to-date commit position is included in the
status report.

Fixes: http://tracker.ceph.com/issues/39257
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
(cherry picked from commit af22cd213c90c6a5a6ae9d7bcc44457ef5b01649)

src/test/rbd_mirror/test_mock_ImageReplayer.cc
src/tools/rbd_mirror/ImageReplayer.cc

index 4683b0d8fdb1463ce3425ac505d02eda654746c5..1bd330fd8a4529bf1dd28478089c86103dd5d642 100644 (file)
@@ -396,6 +396,18 @@ public:
         }));
   }
 
+  void expect_flush_repeatedly(MockReplay& mock_replay,
+                               journal::MockJournaler& mock_journal) {
+    EXPECT_CALL(mock_replay, flush(_))
+      .WillRepeatedly(Invoke([this](Context* ctx) {
+                        m_threads->work_queue->queue(ctx, 0);
+                      }));
+    EXPECT_CALL(mock_journal, flush_commit_position(_))
+      .WillRepeatedly(Invoke([this](Context* ctx) {
+                        m_threads->work_queue->queue(ctx, 0);
+                      }));
+  }
+
   void expect_trash_move(MockImageDeleter& mock_image_deleter,
                          const std::string& global_image_id,
                          bool ignore_orphan, int r) {
@@ -624,6 +636,7 @@ TEST_F(TestMockImageReplayer, StartStop) {
   MockEventPreprocessor mock_event_preprocessor;
   MockReplayStatusFormatter mock_replay_status_formatter;
 
+  expect_flush_repeatedly(mock_local_replay, mock_remote_journaler);
   expect_get_or_send_update(mock_replay_status_formatter);
 
   InSequence seq;
@@ -999,6 +1012,7 @@ TEST_F(TestMockImageReplayer, StopError) {
   MockEventPreprocessor mock_event_preprocessor;
   MockReplayStatusFormatter mock_replay_status_formatter;
 
+  expect_flush_repeatedly(mock_local_replay, mock_remote_journaler);
   expect_get_or_send_update(mock_replay_status_formatter);
 
   InSequence seq;
@@ -1067,6 +1081,7 @@ TEST_F(TestMockImageReplayer, Replay) {
   MockReplayStatusFormatter mock_replay_status_formatter;
   ::journal::MockReplayEntry mock_replay_entry;
 
+  expect_flush_repeatedly(mock_local_replay, mock_remote_journaler);
   expect_get_or_send_update(mock_replay_status_formatter);
   expect_get_commit_tid_in_debug(mock_replay_entry);
   expect_get_tag_tid_in_debug(mock_local_journal);
@@ -1176,6 +1191,7 @@ TEST_F(TestMockImageReplayer, DecodeError) {
   MockReplayStatusFormatter mock_replay_status_formatter;
   ::journal::MockReplayEntry mock_replay_entry;
 
+  expect_flush_repeatedly(mock_local_replay, mock_remote_journaler);
   expect_get_or_send_update(mock_replay_status_formatter);
   expect_get_commit_tid_in_debug(mock_replay_entry);
   expect_get_tag_tid_in_debug(mock_local_journal);
@@ -1277,6 +1293,7 @@ TEST_F(TestMockImageReplayer, DelayedReplay) {
   MockReplayStatusFormatter mock_replay_status_formatter;
   ::journal::MockReplayEntry mock_replay_entry;
 
+  expect_flush_repeatedly(mock_local_replay, mock_remote_journaler);
   expect_get_or_send_update(mock_replay_status_formatter);
   expect_get_commit_tid_in_debug(mock_replay_entry);
   expect_get_tag_tid_in_debug(mock_local_journal);
index 48b78be01aa662a739116ecf4fdccc7849a22d05..14d66df135ff3889d6effecae787b89e05831879 100644 (file)
@@ -1343,10 +1343,18 @@ void ImageReplayer<I>::finish_mirror_image_status_update() {
 template <typename I>
 void ImageReplayer<I>::queue_mirror_image_status_update(const OptionalState &state) {
   dout(15) << dendl;
-  FunctionContext *ctx = new FunctionContext(
+
+  auto ctx = new FunctionContext(
     [this, state](int r) {
       send_mirror_status_update(state);
     });
+
+  // ensure pending IO is flushed and the commit position is updated
+  // prior to updating the mirror status
+  ctx = new FunctionContext(
+    [this, ctx](int r) {
+      flush_local_replay(ctx);
+    });
   m_threads->work_queue->queue(ctx, 0);
 }