Skip to content

Commit

Permalink
Merge pull request ceph#38536 from dillaman/wip-48553
Browse files Browse the repository at this point in the history
librbd/mirror: unlink the third snapshot when the limit is reached

Reviewed-by: Mykola Golub <[email protected]>
  • Loading branch information
trociny committed Dec 16, 2020
2 parents f649030 + fb69efc commit 0e9ffeb
Show file tree
Hide file tree
Showing 13 changed files with 215 additions and 117 deletions.
22 changes: 11 additions & 11 deletions src/librbd/mirror/snapshot/CreateNonPrimaryRequest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void CreateNonPrimaryRequest<I>::refresh_image() {
}

CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << dendl;
ldout(cct, 15) << dendl;

auto ctx = create_context_callback<
CreateNonPrimaryRequest<I>,
Expand All @@ -62,7 +62,7 @@ void CreateNonPrimaryRequest<I>::refresh_image() {
template <typename I>
void CreateNonPrimaryRequest<I>::handle_refresh_image(int r) {
CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << "r=" << r << dendl;
ldout(cct, 15) << "r=" << r << dendl;

if (r < 0) {
lderr(cct) << "failed to refresh image: " << cpp_strerror(r) << dendl;
Expand All @@ -76,7 +76,7 @@ void CreateNonPrimaryRequest<I>::handle_refresh_image(int r) {
template <typename I>
void CreateNonPrimaryRequest<I>::get_mirror_image() {
CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << dendl;
ldout(cct, 15) << dendl;

librados::ObjectReadOperation op;
cls_client::mirror_image_get_start(&op, m_image_ctx->id);
Expand All @@ -92,7 +92,7 @@ void CreateNonPrimaryRequest<I>::get_mirror_image() {
template <typename I>
void CreateNonPrimaryRequest<I>::handle_get_mirror_image(int r) {
CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << "r=" << r << dendl;
ldout(cct, 15) << "r=" << r << dendl;

cls::rbd::MirrorImage mirror_image;
if (r == 0) {
Expand Down Expand Up @@ -134,7 +134,7 @@ void CreateNonPrimaryRequest<I>::get_mirror_peers() {
}

CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << dendl;
ldout(cct, 15) << dendl;

librados::ObjectReadOperation op;
cls_client::mirror_peer_list_start(&op);
Expand All @@ -151,7 +151,7 @@ void CreateNonPrimaryRequest<I>::get_mirror_peers() {
template <typename I>
void CreateNonPrimaryRequest<I>::handle_get_mirror_peers(int r) {
CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << "r=" << r << dendl;
ldout(cct, 15) << "r=" << r << dendl;

std::vector<cls::rbd::MirrorPeer> peers;
if (r == 0) {
Expand Down Expand Up @@ -189,7 +189,7 @@ void CreateNonPrimaryRequest<I>::create_snapshot() {
}
ns.snap_seqs = m_snap_seqs;
ns.complete = is_orphan();
ldout(cct, 20) << "ns=" << ns << dendl;
ldout(cct, 15) << "ns=" << ns << dendl;

auto ctx = create_context_callback<
CreateNonPrimaryRequest<I>,
Expand All @@ -200,7 +200,7 @@ void CreateNonPrimaryRequest<I>::create_snapshot() {
template <typename I>
void CreateNonPrimaryRequest<I>::handle_create_snapshot(int r) {
CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << "r=" << r << dendl;
ldout(cct, 15) << "r=" << r << dendl;

if (r < 0) {
lderr(cct) << "failed to create mirror snapshot: " << cpp_strerror(r)
Expand Down Expand Up @@ -231,7 +231,7 @@ void CreateNonPrimaryRequest<I>::write_image_state() {
}

CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << dendl;
ldout(cct, 15) << dendl;

auto ctx = create_context_callback<
CreateNonPrimaryRequest<I>,
Expand All @@ -245,7 +245,7 @@ void CreateNonPrimaryRequest<I>::write_image_state() {
template <typename I>
void CreateNonPrimaryRequest<I>::handle_write_image_state(int r) {
CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << "r=" << r << dendl;
ldout(cct, 15) << "r=" << r << dendl;

if (r < 0) {
lderr(cct) << "failed to write image state: " << cpp_strerror(r)
Expand All @@ -260,7 +260,7 @@ void CreateNonPrimaryRequest<I>::handle_write_image_state(int r) {
template <typename I>
void CreateNonPrimaryRequest<I>::finish(int r) {
CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << "r=" << r << dendl;
ldout(cct, 15) << "r=" << r << dendl;

m_on_finish->complete(r);
delete this;
Expand Down
33 changes: 17 additions & 16 deletions src/librbd/mirror/snapshot/CreatePrimaryRequest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void CreatePrimaryRequest<I>::send() {
template <typename I>
void CreatePrimaryRequest<I>::get_mirror_peers() {
CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << dendl;
ldout(cct, 15) << dendl;

librados::ObjectReadOperation op;
cls_client::mirror_peer_list_start(&op);
Expand All @@ -76,7 +76,7 @@ void CreatePrimaryRequest<I>::get_mirror_peers() {
template <typename I>
void CreatePrimaryRequest<I>::handle_get_mirror_peers(int r) {
CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << "r=" << r << dendl;
ldout(cct, 15) << "r=" << r << dendl;

std::vector<cls::rbd::MirrorPeer> peers;
if (r == 0) {
Expand Down Expand Up @@ -117,7 +117,7 @@ void CreatePrimaryRequest<I>::create_snapshot() {
m_mirror_peer_uuids, "", m_clean_since_snap_id};

CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << "name=" << m_snap_name << ", "
ldout(cct, 15) << "name=" << m_snap_name << ", "
<< "ns=" << ns << dendl;
auto ctx = create_context_callback<
CreatePrimaryRequest<I>,
Expand All @@ -129,7 +129,7 @@ void CreatePrimaryRequest<I>::create_snapshot() {
template <typename I>
void CreatePrimaryRequest<I>::handle_create_snapshot(int r) {
CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << "r=" << r << dendl;
ldout(cct, 15) << "r=" << r << dendl;

if (r < 0) {
lderr(cct) << "failed to create mirror snapshot: " << cpp_strerror(r)
Expand All @@ -151,7 +151,7 @@ void CreatePrimaryRequest<I>::refresh_image() {
}

CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << dendl;
ldout(cct, 15) << dendl;

auto ctx = create_context_callback<
CreatePrimaryRequest<I>,
Expand All @@ -162,7 +162,7 @@ void CreatePrimaryRequest<I>::refresh_image() {
template <typename I>
void CreatePrimaryRequest<I>::handle_refresh_image(int r) {
CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << "r=" << r << dendl;
ldout(cct, 15) << "r=" << r << dendl;

if (r < 0) {
lderr(cct) << "failed to refresh image: " << cpp_strerror(r) << dendl;
Expand All @@ -174,7 +174,7 @@ void CreatePrimaryRequest<I>::handle_refresh_image(int r) {
std::shared_lock image_locker{m_image_ctx->image_lock};
*m_snap_id = m_image_ctx->get_snap_id(
cls::rbd::MirrorSnapshotNamespace{}, m_snap_name);
ldout(cct, 20) << "snap_id=" << *m_snap_id << dendl;
ldout(cct, 15) << "snap_id=" << *m_snap_id << dendl;
}

unlink_peer();
Expand All @@ -192,7 +192,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);
Expand All @@ -202,15 +202,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;
}
}
Expand All @@ -225,7 +226,7 @@ void CreatePrimaryRequest<I>::unlink_peer() {
}

CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << "peer=" << peer_uuid << ", snap_id=" << snap_id << dendl;
ldout(cct, 15) << "peer=" << peer_uuid << ", snap_id=" << snap_id << dendl;

auto ctx = create_context_callback<
CreatePrimaryRequest<I>,
Expand All @@ -237,7 +238,7 @@ void CreatePrimaryRequest<I>::unlink_peer() {
template <typename I>
void CreatePrimaryRequest<I>::handle_unlink_peer(int r) {
CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << "r=" << r << dendl;
ldout(cct, 15) << "r=" << r << dendl;

if (r < 0) {
lderr(cct) << "failed to unlink peer: " << cpp_strerror(r) << dendl;
Expand All @@ -251,7 +252,7 @@ void CreatePrimaryRequest<I>::handle_unlink_peer(int r) {
template <typename I>
void CreatePrimaryRequest<I>::finish(int r) {
CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << "r=" << r << dendl;
ldout(cct, 15) << "r=" << r << dendl;

m_on_finish->complete(r);
delete this;
Expand Down
6 changes: 3 additions & 3 deletions src/librbd/mirror/snapshot/DemoteRequest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void DemoteRequest<I>::handle_enable_non_primary_feature(int r) {
template <typename I>
void DemoteRequest<I>::create_snapshot() {
CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << dendl;
ldout(cct, 15) << dendl;

auto ctx = create_context_callback<
DemoteRequest<I>, &DemoteRequest<I>::handle_create_snapshot>(this);
Expand All @@ -82,7 +82,7 @@ void DemoteRequest<I>::create_snapshot() {
template <typename I>
void DemoteRequest<I>::handle_create_snapshot(int r) {
CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << "r=" << r << dendl;
ldout(cct, 15) << "r=" << r << dendl;

if (r < 0) {
lderr(cct) << "failed to create mirror snapshot: " << cpp_strerror(r)
Expand All @@ -97,7 +97,7 @@ void DemoteRequest<I>::handle_create_snapshot(int r) {
template <typename I>
void DemoteRequest<I>::finish(int r) {
CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << "r=" << r << dendl;
ldout(cct, 15) << "r=" << r << dendl;

m_on_finish->complete(r);
delete this;
Expand Down
6 changes: 3 additions & 3 deletions src/librbd/mirror/snapshot/GetImageStateRequest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void GetImageStateRequest<I>::read_object() {

auto oid = util::image_state_object_name(m_image_ctx, m_snap_id,
m_object_index);
ldout(cct, 20) << oid << dendl;
ldout(cct, 15) << oid << dendl;

librados::ObjectReadOperation op;
m_bl.clear();
Expand All @@ -50,7 +50,7 @@ void GetImageStateRequest<I>::read_object() {
template <typename I>
void GetImageStateRequest<I>::handle_read_object(int r) {
CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << "r=" << r << dendl;
ldout(cct, 15) << "r=" << r << dendl;

if (r < 0) {
lderr(cct) << "failed to read image state object: " << cpp_strerror(r)
Expand Down Expand Up @@ -91,7 +91,7 @@ void GetImageStateRequest<I>::handle_read_object(int r) {
template <typename I>
void GetImageStateRequest<I>::finish(int r) {
CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << "r=" << r << dendl;
ldout(cct, 15) << "r=" << r << dendl;

if (r == 0) {
try {
Expand Down
Loading

0 comments on commit 0e9ffeb

Please sign in to comment.