From a04aae75ebddfe6dc72a731a3669d5354a9d68ed Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Wed, 19 Feb 2020 12:03:10 -0500 Subject: [PATCH] rbd-mirror: do not attempt to replay incomplete primary snapshots In case we race with the creation of a primary mirror snapshot, do not attempt to replay incomplete snapshots. Once the image state has been successfully written, the snapshot will be flagged as complete and an update notification will be sent. Signed-off-by: Jason Dillaman --- .../snapshot/test_mock_Replayer.cc | 24 +++++++++---------- .../image_replayer/snapshot/Replayer.cc | 23 +++++++++++------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/test/rbd_mirror/image_replayer/snapshot/test_mock_Replayer.cc b/src/test/rbd_mirror/image_replayer/snapshot/test_mock_Replayer.cc index e1e83ca4543..fa6018087c4 100644 --- a/src/test/rbd_mirror/image_replayer/snapshot/test_mock_Replayer.cc +++ b/src/test/rbd_mirror/image_replayer/snapshot/test_mock_Replayer.cc @@ -597,17 +597,17 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, SyncSnapshot) { mock_remote_image_ctx.snap_info = { {1U, librbd::SnapInfo{"snap1", cls::rbd::MirrorSnapshotNamespace{ cls::rbd::MIRROR_SNAPSHOT_STATE_PRIMARY, {"remote mirror peer uuid"}, - "", 0U}, + "", 0U, true, 0, {}}, 0, {}, 0, 0, {}}}, {2U, librbd::SnapInfo{"snap2", cls::rbd::UserSnapshotNamespace{}, 0, {}, 0, 0, {}}}, {3U, librbd::SnapInfo{"snap3", cls::rbd::MirrorSnapshotNamespace{ cls::rbd::MIRROR_SNAPSHOT_STATE_PRIMARY, {""}, - "", 0U}, + "", 0U, true, 0, {}}, 0, {}, 0, 0, {}}}, {4U, librbd::SnapInfo{"snap4", cls::rbd::MirrorSnapshotNamespace{ cls::rbd::MIRROR_SNAPSHOT_STATE_PRIMARY, {"remote mirror peer uuid"}, - "", 0U}, + "", 0U, true, 0, {}}, 0, {}, 0, 0, {}}}}; MockThreads mock_threads(m_threads); @@ -737,7 +737,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, InterruptedSync) { mock_remote_image_ctx.snap_info = { {1U, librbd::SnapInfo{"snap1", cls::rbd::MirrorSnapshotNamespace{ cls::rbd::MIRROR_SNAPSHOT_STATE_PRIMARY, {"remote mirror peer uuid"}, - "", 0U}, + "", 0U, true, 0, {}}, 0, {}, 0, 0, {}}}}; mock_local_image_ctx.snap_info = { {11U, librbd::SnapInfo{"snap1", cls::rbd::MirrorSnapshotNamespace{ @@ -809,7 +809,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, RemoteImageDemoted) { mock_remote_image_ctx.snap_info = { {1U, librbd::SnapInfo{"snap1", cls::rbd::MirrorSnapshotNamespace{ cls::rbd::MIRROR_SNAPSHOT_STATE_PRIMARY_DEMOTED, - {"remote mirror peer uuid"}, "", 0U}, + {"remote mirror peer uuid"}, "", 0U, true, 0, {}}, 0, {}, 0, 0, {}}}}; // sync snap1 @@ -1091,7 +1091,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, CopySnapshotsError) { mock_remote_image_ctx.snap_info = { {1U, librbd::SnapInfo{"snap1", cls::rbd::MirrorSnapshotNamespace{ cls::rbd::MIRROR_SNAPSHOT_STATE_PRIMARY, {"remote mirror peer uuid"}, "", - 0U}, + 0U, true, 0, {}}, 0, {}, 0, 0, {}}}}; // sync snap1 @@ -1145,7 +1145,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, GetImageStateError) { mock_remote_image_ctx.snap_info = { {1U, librbd::SnapInfo{"snap1", cls::rbd::MirrorSnapshotNamespace{ cls::rbd::MIRROR_SNAPSHOT_STATE_PRIMARY, {"remote mirror peer uuid"}, "", - 0U}, + 0U, true, 0, {}}, 0, {}, 0, 0, {}}}}; // sync snap1 @@ -1201,7 +1201,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, CreateNonPrimarySnapshotError) { mock_remote_image_ctx.snap_info = { {1U, librbd::SnapInfo{"snap1", cls::rbd::MirrorSnapshotNamespace{ cls::rbd::MIRROR_SNAPSHOT_STATE_PRIMARY, {"remote mirror peer uuid"}, "", - 0U}, + 0U, true, 0, {}}, 0, {}, 0, 0, {}}}}; // sync snap1 @@ -1261,7 +1261,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, CopyImageError) { mock_remote_image_ctx.snap_info = { {1U, librbd::SnapInfo{"snap1", cls::rbd::MirrorSnapshotNamespace{ cls::rbd::MIRROR_SNAPSHOT_STATE_PRIMARY, {"remote mirror peer uuid"}, "", - 0U}, + 0U, true, 0, {}}, 0, {}, 0, 0, {}}}}; // sync snap1 @@ -1324,7 +1324,7 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, UpdateNonPrimarySnapshotError) { mock_remote_image_ctx.snap_info = { {1U, librbd::SnapInfo{"snap1", cls::rbd::MirrorSnapshotNamespace{ cls::rbd::MIRROR_SNAPSHOT_STATE_PRIMARY, {"remote mirror peer uuid"}, "", - 0U}, + 0U, true, 0, {}}, 0, {}, 0, 0, {}}}}; // sync snap1 @@ -1389,11 +1389,11 @@ TEST_F(TestMockImageReplayerSnapshotReplayer, UnlinkPeerError) { mock_remote_image_ctx.snap_info = { {1U, librbd::SnapInfo{"snap1", cls::rbd::MirrorSnapshotNamespace{ cls::rbd::MIRROR_SNAPSHOT_STATE_PRIMARY, {"remote mirror peer uuid"}, "", - 0U}, + 0U, true, 0, {}}, 0, {}, 0, 0, {}}}, {2U, librbd::SnapInfo{"snap2", cls::rbd::MirrorSnapshotNamespace{ cls::rbd::MIRROR_SNAPSHOT_STATE_PRIMARY, {"remote mirror peer uuid"}, - "", 0U}, + "", 0U, true, 0, {}}, 0, {}, 0, 0, {}}}}; mock_local_image_ctx.snap_info = { {11U, librbd::SnapInfo{"snap1", cls::rbd::MirrorSnapshotNamespace{ diff --git a/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc b/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc index 0a926429975..2af646ca1af 100644 --- a/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc +++ b/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc @@ -418,17 +418,22 @@ void Replayer::scan_remote_mirror_snapshots() { << "remote_snap_id_start=" << m_remote_snap_id_start << ", " << "remote_snap_id_end=" << m_remote_snap_id_end << ", " << "remote_snap_ns=" << m_remote_mirror_snap_ns << dendl; - - if (m_local_snap_id_end != CEPH_NOSNAP && - !m_local_mirror_snap_ns.complete) { - // attempt to resume image-sync - dout(10) << "local image contains in-progress mirror snapshot" - << dendl; - copy_image(); + if (m_remote_mirror_snap_ns.complete) { + if (m_local_snap_id_end != CEPH_NOSNAP && + !m_local_mirror_snap_ns.complete) { + // attempt to resume image-sync + dout(10) << "local image contains in-progress mirror snapshot" + << dendl; + copy_image(); + } else { + copy_snapshots(); + } + return; } else { - copy_snapshots(); + // might have raced with the creation of a remote mirror snapshot + // so we will need to refresh and rescan once it completes + dout(15) << "remote mirror snapshot not complete" << dendl; } - return; } std::unique_lock locker{m_lock}; -- 2.39.5