]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd/mirror: tweak which snapshot is unlinked when at capacity
authorJason Dillaman <dillaman@redhat.com>
Thu, 10 Dec 2020 22:32:16 +0000 (17:32 -0500)
committerJason Dillaman <dillaman@redhat.com>
Tue, 9 Mar 2021 21:13:58 +0000 (16:13 -0500)
The rbd-mirror daemon will attempt to sync from the last synced
snapshot to the next mirror snapshot. When the limit is at 3, this
currently can result in a situation where an in-use sync snapshot is
deleted. Instead of unlinking the second oldest snapshot, always
unlink the third oldest.

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

src/librbd/mirror/snapshot/CreatePrimaryRequest.cc
src/test/librbd/mirror/snapshot/test_mock_CreatePrimaryRequest.cc
src/test/librbd/test_mirroring.cc

index a6ce53ff16150c6c4969d878f45d786e8760be1a..9fc865d1747d31eb0a981b36c6879687102e3fb8 100644 (file)
@@ -190,7 +190,7 @@ void CreatePrimaryRequest<I>::unlink_peer() {
   for (auto &peer : m_mirror_peer_uuids) {
     std::shared_lock image_locker{m_image_ctx->image_lock};
     size_t count = 0;
-    uint64_t prev_snap_id = 0;
+    uint64_t unlink_snap_id = 0;
     for (auto &snap_it : m_image_ctx->snap_info) {
       auto info = boost::get<cls::rbd::MirrorSnapshotNamespace>(
         &snap_it.second.snap_namespace);
@@ -200,15 +200,16 @@ void CreatePrimaryRequest<I>::unlink_peer() {
       if (info->state != cls::rbd::MIRROR_SNAPSHOT_STATE_PRIMARY) {
         // reset counters -- we count primary snapshots after the last promotion
         count = 0;
-        prev_snap_id = 0;
+        unlink_snap_id = 0;
         continue;
       }
       count++;
-      if (count == max_snapshots - 1) {
-        prev_snap_id = snap_it.first;
-      } else if (count > max_snapshots) {
+      if (count == 3) {
+        unlink_snap_id = snap_it.first;
+      }
+      if (count > max_snapshots) {
         peer_uuid = peer;
-        snap_id = prev_snap_id;
+        snap_id = unlink_snap_id;
         break;
       }
     }
index a79bd0cc45ff67bf5e4af96f1ca4d15c5c97b4c2..f07f425500424cfbfb8bc635c3c43804a25eb413 100644 (file)
@@ -311,7 +311,7 @@ TEST_F(TestMockMirrorSnapshotCreatePrimaryRequest, SuccessUnlinkPeer) {
   expect_create_snapshot(mock_image_ctx, 0);
   MockUnlinkPeerRequest mock_unlink_peer_request;
   auto it = mock_image_ctx.snap_info.rbegin();
-  auto snap_id = (++it)->first;
+  auto snap_id = it->first;
   expect_unlink_peer(mock_image_ctx, mock_unlink_peer_request, snap_id, "uuid",
                      0);
   C_SaferCond ctx;
index c72c34c32d4b2644aa1db6633801d50b64869182..d449be78d9fd02a0449f7d17bca212b3a379583b 100644 (file)
@@ -1154,7 +1154,7 @@ TEST_F(TestMirroring, Snapshot)
   ASSERT_EQ(0, image.snap_list(snaps1));
   ASSERT_EQ(3U, snaps1.size());
   ASSERT_EQ(snaps1[0].id, snaps[0].id);
-  ASSERT_EQ(snaps1[1].id, snaps[2].id);
+  ASSERT_EQ(snaps1[1].id, snaps[1].id);
   ASSERT_EQ(snaps1[2].id, snap_id);
 
   librbd::snap_namespace_type_t snap_ns_type;