Skip to content

librbd: remove previous incomplete primary snapshot after successfully creating a new one - #50324

Merged
anthonyeleven merged 2 commits into
ceph:mainfrom
pkalever:scrub_incomplete
Apr 22, 2023
Merged

anthonyeleven merged 2 commits into
ceph:mainfrom
pkalever:scrub_incomplete

Conversation

@pkalever

@pkalever pkalever commented Mar 1, 2023 •

Copy link
Copy Markdown

Problem:

At a high level, creating a primary snapshot consists of three steps:

  1. actually creating a snapshot in the mirror namespace
  2. generating a set of image state objects with additional metadata for the snapshot
  3. marking the snapshot as complete after the image state objects are written out

Depending on the circumstances, a request to a create a primary snapshot can be forwarded to rbd-mirror daemon. If that happens and rbd-mirror daemon gets axed for some practical reason after completing steps (1) and/or (2) but before completing step (3), we are left with a permanently incomplete primary snapshot because upon retrying that primary snapshot creation request, librbd notices that such snapshot already exists. It does not check whether this "pre-existing" snapshot is complete.

Solution:

As part of the next mirror snapshot create (say triggered by the scheduler) the unlink_peer() is called, it checks if there exists any incomplete snapshot and delete them accordingly.

Fixes: https://tracker.ceph.com/issues/58887
Signed-off-by: Prasanna Kumar Kalever <[email protected]>

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands
  • jenkins retest this please
  • jenkins test classic perf
  • jenkins test crimson perf
  • jenkins test signed
  • jenkins test make check
  • jenkins test make check arm64
  • jenkins test submodules
  • jenkins test dashboard
  • jenkins test dashboard cephadm
  • jenkins test api
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox
  • jenkins test windows

@pkalever
pkalever requested a review from a team as a code owner March 1, 2023 11:37
@pkalever
pkalever requested a review from idryomov March 1, 2023 11:38
@github-actions github-actions Bot added the rbd label Mar 1, 2023

@idryomov idryomov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have pointed out some implementation issues mostly for educational purposes -- I think this is better approached differently. If you look at CreatePrimaryRequest::unlink_peer, it already has logic for removing snapshots when rbd_mirroring_max_mirroring_snapshots limit is reached. It also removes snapshots that aren't linked to any peer unconditionally (i.e. even if rbd_mirroring_max_mirroring_snapshots limit isn't reached). It seems like we could piggy-back on that just by adding an extra provision for incomplete snapshots.

It may not be apparent that CreatePrimaryRequest::unlink_peer can remove snapshots because it invokes a fairly nondescript UnlinkPeerRequest to do the work, but UnlinkPeerRequest actually ends up calling snap_remove if certain conditions are met. I suspect that an incomplete snapshot would meet those conditions.

@idryomov idryomov changed the title rbd: scrub the incomplete primary snapshots librbd: remove previous incomplete primary snapshot after successuffly creating a new one Mar 2, 2023
@idryomov idryomov changed the title librbd: remove previous incomplete primary snapshot after successuffly creating a new one librbd: remove previous incomplete primary snapshot after successfully creating a new one Mar 2, 2023
@pkalever
pkalever requested a review from idryomov March 6, 2023 10:17

@idryomov idryomov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you verify that UnlinkPeerRequest would actually remove the snapshot in this case?

@idryomov

idryomov commented Mar 6, 2023

Copy link
Copy Markdown
Contributor

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2120624

Please drop this from the PR description and the commit message.

@pkalever

pkalever commented Mar 6, 2023

Copy link
Copy Markdown
Author

Did you verify that UnlinkPeerRequest would actually remove the snapshot in this case?

I had added some additional debug logs like:

diff --git a/src/librbd/mirror/snapshot/CreatePrimaryRequest.cc b/src/librbd/mirror/snapshot/CreatePrimaryRequest.cc
index 36cd3bddfc7..5b474631f5b 100644
--- a/src/librbd/mirror/snapshot/CreatePrimaryRequest.cc
+++ b/src/librbd/mirror/snapshot/CreatePrimaryRequest.cc
@@ -189,6 +189,7 @@ void CreatePrimaryRequest<I>::unlink_peer() {
   std::string peer_uuid;
   uint64_t snap_id = CEPH_NOSNAP;
 
+  CephContext *cct = m_image_ctx->cct;
   for (auto &peer : m_mirror_peer_uuids) {
     std::shared_lock image_locker{m_image_ctx->image_lock};
     size_t count = 0;
@@ -209,9 +210,12 @@ void CreatePrimaryRequest<I>::unlink_peer() {
       // or if it's not linked with any peer (happens if mirroring is enabled
       // on a pool with no peers configured or if UnlinkPeerRequest gets
       // interrupted)
-      if (info->mirror_peer_uuids.size() == 0) {
+      if (info->mirror_peer_uuids.size() == 0 || !info->complete) {
         peer_uuid = peer;
         snap_id = snap_it.first;
+       if (!info->complete) {
+         ldout(cct, 20) << "previous snapshot is not marked complete" << dendl;
+       }
         break;
       }
       if (info->mirror_peer_uuids.count(peer) == 0) {
@@ -237,7 +241,6 @@ void CreatePrimaryRequest<I>::unlink_peer() {
     return;
   }
 
-  CephContext *cct = m_image_ctx->cct;
   ldout(cct, 15) << "peer=" << peer_uuid << ", snap_id=" << snap_id << dendl;
 
   auto ctx = create_context_callback<
[pkalever@localhost build]$ 

And it worked actually:

2023-03-06T12:43:49.600+0530 7fd6ce7fc640 10 librbd::image::RefreshRequest: 0x7fd694014210 handle_v2_get_snapshots: r=0                                                                                                                       
2023-03-06T12:43:49.600+0530 7fd6ce7fc640 10 librbd::image::RefreshRequest: 0x7fd694014210 send_v2_apply                                                                                                                                      
2023-03-06T12:43:49.600+0530 7fd6ce7fc640 10 librbd::image::RefreshRequest: 0x7fd694014210 handle_v2_apply                                                                                                                                    
2023-03-06T12:43:49.600+0530 7fd6ce7fc640 20 librbd::image::RefreshRequest: 0x7fd694014210 apply                                                                                                                                              
2023-03-06T12:43:49.600+0530 7fd6ce7fc640 10 librbd::ImageState: 0x55c32265ff90 0x55c32265ff90 handle_refresh: r=0                                                                                                                            
2023-03-06T12:43:49.600+0530 7fd6ce7fc640 15 librbd::mirror::snapshot::CreatePrimaryRequest: 0x7fd694015200 handle_refresh_image: r=0                                                                                                         
2023-03-06T12:43:49.600+0530 7fd6ce7fc640 15 librbd::mirror::snapshot::CreatePrimaryRequest: 0x7fd694015200 handle_refresh_image: snap_id=8                                                                                                   
2023-03-06T12:43:49.600+0530 7fd6ce7fc640 20 librbd::mirror::snapshot::CreatePrimaryRequest: 0x7fd694015200 unlink_peer: previous snapshot is not marked complete                                                                             
2023-03-06T12:43:49.600+0530 7fd6ce7fc640 15 librbd::mirror::snapshot::CreatePrimaryRequest: 0x7fd694015200 unlink_peer: peer=ede117b7-be2d-4cfa-9241-42bc67812b5e, snap_id=7                                                                 
2023-03-06T12:43:49.600+0530 7fd6ce7fc640 15 librbd::mirror::snapshot::UnlinkPeerRequest: 0x7fd69400c090 unlink_peer: located newer mirror snapshot                                                                                           
2023-03-06T12:43:49.600+0530 7fd6ce7fc640 15 librbd::mirror::snapshot::UnlinkPeerRequest: 0x7fd69400c090 remove_snapshot:                                                                                                                     
2023-03-06T12:43:49.600+0530 7fd6ce7fc640  5 librbd::Operations: 0x55c3224c8ac0 snap_remove: snap_name=.mirror.primary.aae8d3b9-334b-483e-bc41-e2b46f2baddc.70cc6d67-d37a-4324-a148-96e03c652a27                                              
2023-03-06T12:43:49.600+0530 7fd6ce7fc640 20 librbd::ManagedLock: 0x7fd69c003b98 is_lock_owner: =1                                                                                                                                            
2023-03-06T12:43:49.600+0530 7fd6ce7fc640 20 librbd::ExclusiveLock: 0x7fd69c003b80 accept_request=1 (request_type=0)
2023-03-06T12:43:49.600+0530 7fd6ce7fc640 20 librbd::Operations: start_op: snap remove 0x7fd6c8001260                                                                                                                                         
2023-03-06T12:43:49.600+0530 7fd6ce7fc640 20 librbd::Operations: start snap remove 0x7fd6c8001260                                                                                                                                             
2023-03-06T12:43:49.600+0530 7fd6ce7fc640 20 librbd::Operations: execute_local_request                                
2023-03-06T12:43:49.600+0530 7fd6ce7fc640 20 librbd::ManagedLock: 0x7fd69c003b98 is_lock_owner: =1                                                                                                                                            
2023-03-06T12:43:49.600+0530 7fd6ce7fc640  5 librbd::Operations: 0x55c3224c8ac0 execute_snap_remove: snap_name=.mirror.primary.aae8d3b9-334b-483e-bc41-e2b46f2baddc.70cc6d67-d37a-4324-a148-96e03c652a27
2023-03-06T12:43:49.600+0530 7fd6ce7fc640  5 librbd::SnapshotRemoveRequest: 0x7fd694012e40 trash_snap: 
2023-03-06T12:43:49.603+0530 7fd6ceffd640  5 librbd::SnapshotRemoveRequest: 0x7fd694012e40 handle_trash_snap: r=0
2023-03-06T12:43:49.603+0530 7fd6ceffd640  5 librbd::SnapshotRemoveRequest: 0x7fd694012e40 get_snap: 
2023-03-06T12:43:49.604+0530 7fd6ce7fc640  5 librbd::SnapshotRemoveRequest: 0x7fd694012e40 handle_get_snap: r=0
2023-03-06T12:43:49.604+0530 7fd6ce7fc640  5 librbd::SnapshotRemoveRequest: 0x7fd694012e40 remove_object_map: 
2023-03-06T12:43:49.604+0530 7fd6ce7fc640  5 librbd::object_map::SnapshotRemoveRequest: 0x7fd69c013270 load_map: snap_oid=rbd_object_map.102df4a80a2.0000000000000007
2023-03-06T12:43:49.605+0530 7fd6ceffd640  5 librbd::object_map::SnapshotRemoveRequest: 0x7fd69c013270 handle_load_map: r=-2
2023-03-06T12:43:49.605+0530 7fd6ceffd640  5 librbd::SnapshotRemoveRequest: 0x7fd694012e40 handle_remove_object_map: r=0
2023-03-06T12:43:49.605+0530 7fd6ceffd640  5 librbd::SnapshotRemoveRequest: 0x7fd694012e40 remove_image_state: 
2023-03-06T12:43:49.605+0530 7fd6ceffd640 15 librbd::mirror::snapshot::RemoveImageStateRequest: 0x7fd69c012e90 get_object_count: rbd_mirror_snapshot.102df4a80a2.7.0
2023-03-06T12:43:49.606+0530 7fd6ce7fc640 15 librbd::mirror::snapshot::RemoveImageStateRequest: 0x7fd69c012e90 handle_get_object_count: r=-2
2023-03-06T12:43:49.606+0530 7fd6ce7fc640 -1 librbd::mirror::snapshot::RemoveImageStateRequest: 0x7fd69c012e90 handle_get_object_count: failed to read image state object: (2) No such file or directory
2023-03-06T12:43:49.606+0530 7fd6ce7fc640 15 librbd::mirror::snapshot::RemoveImageStateRequest: 0x7fd69c012e90 finish: r=-2
2023-03-06T12:43:49.606+0530 7fd6ce7fc640  5 librbd::SnapshotRemoveRequest: 0x7fd694012e40 handle_remove_image_state: r=-2
2023-03-06T12:43:49.606+0530 7fd6ce7fc640 -1 librbd::SnapshotRemoveRequest: 0x7fd694012e40 handle_remove_image_state: failed to remove image state: (2) No such file or directory
2023-03-06T12:43:49.606+0530 7fd6ce7fc640  5 librbd::SnapshotRemoveRequest: 0x7fd694012e40 release_snap_id: snap_name=.mirror.primary.aae8d3b9-334b-483e-bc41-e2b46f2baddc.70cc6d67-d37a-4324-a148-96e03c652a27, snap_id=7
2023-03-06T12:43:50.559+0530 7fd6ceffd640  5 librbd::SnapshotRemoveRequest: 0x7fd694012e40 handle_release_snap_id: r=0
2023-03-06T12:43:50.559+0530 7fd6ceffd640  5 librbd::SnapshotRemoveRequest: 0x7fd694012e40 remove_snap: 
2023-03-06T12:43:50.572+0530 7fd6ce7fc640  5 librbd::SnapshotRemoveRequest: 0x7fd694012e40 handle_remove_snap: r=0
2023-03-06T12:43:50.572+0530 7fd6ce7fc640  5 librbd::SnapshotRemoveRequest: 0x7fd694012e40 remove_snap_context: 
2023-03-06T12:43:50.572+0530 7fd6ce7fc640  5 librbd::SnapshotRemoveRequest: 0x7fd694012e40 should_complete: r=0
2023-03-06T12:43:50.572+0530 7fd6ce7fc640 10 librbd::Request: 0x7fd694012e40 finish_and_destroy: r=0

@pkalever
pkalever requested a review from idryomov March 13, 2023 12:40
@github-actions github-actions Bot added the tests label Mar 13, 2023
Comment thread src/test/librbd/mock/MockOperations.h Resolved
@pkalever
pkalever requested a review from idryomov March 16, 2023 14:34

@idryomov idryomov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please squash the test commit and drop the BZ link.

@pkalever
pkalever requested a review from idryomov March 28, 2023 14:48
@pkalever
pkalever force-pushed the scrub_incomplete branch 2 times, most recently from a25e640 to ae5dcf7 Compare April 3, 2023 04:57
@pkalever

Copy link
Copy Markdown
Author

@idryomov Please help review this PR. Thanks!

@pkalever
pkalever requested a review from trociny April 13, 2023 11:26
@idryomov

Copy link
Copy Markdown
Contributor

Also please squash the test commit and drop the BZ link.

This is still pending for the original fix. While at it, change the commit title to match the title of the PR.

The follow-up fix clearly needs more investigation.

@pkalever
pkalever requested a review from idryomov April 17, 2023 11:05
@pkalever
pkalever requested a review from idryomov April 18, 2023 15:14
@idryomov

Copy link
Copy Markdown
Contributor

Also please squash the test commit and drop the BZ link.

This is still pending for the original fix. While at it, change the commit title to match the title of the PR.

This is still outstanding -- only the test commit got squashed.

…y creating a new one

Problem:
-------
At a high level, creating a primary snapshot consists of three steps:

1. actually creating a snapshot in the mirror namespace
2. generating a set of image state objects with additional metadata for
   the snapshot
3. marking the snapshot as complete after the image state objects are
   written out

Depending on the circumstances, a request to create a primary snapshot
can be forwarded to rbd-mirror daemon.  If that happens and rbd-mirror
daemon gets axed for some practical reason after completing steps (1)
and/or (2) but before completing step (3), we are left with a
permanently incomplete primary snapshot because upon retrying that
primary snapshot creation request, librbd notices that such snapshot
already exists.  It does not check whether this "pre-existing" snapshot
is complete.

Solution:
--------
As part of the next mirror snapshot create (say triggered by the
scheduler) the unlink_peer() is called, it checks if there exists any
incomplete snapshot and delete them accordingly.

Fixes: https://tracker.ceph.com/issues/58887
Signed-off-by: Prasanna Kumar Kalever <[email protected]>
@pkalever

Copy link
Copy Markdown
Author

@idryomov cleaned now. Thanks!

Up until now this was conditioned on whether the caller expressed
interest in the ID of the created snapshot and happened to work only
because CreatePrimaryRequest wasn't actually consulting any mirror
snapshot metadata.  This has just changed with unlink_peer() needing to
see an up-to-date complete flag which is set in SetImageStateRequest
following the write out of image state object(s).

Signed-off-by: Ilya Dryomov <[email protected]>
@idryomov

Copy link
Copy Markdown
Contributor

Pushed a fixup for TestMockMirrorSnapshotCreatePrimaryRequest tests.

@idryomov

Copy link
Copy Markdown
Contributor

jenkins test windows

@idryomov

Copy link
Copy Markdown
Contributor

jenkins test api

@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@anthonyeleven
anthonyeleven merged commit 92ba1c0 into ceph:main Apr 22, 2023
yuvalif pushed a commit to yuvalif/ceph that referenced this pull request Apr 30, 2023
librbd: remove previous incomplete primary snapshot after successfully creating a new one

Reviewed-by: Ilya Dryomov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants