r = prepare_group_images(group_ioctx, group_id, &image_ctxs,
&group_snap, quiesce_requests,
- cls::rbd::MIRROR_SNAPSHOT_STATE_PRIMARY,
+ cls::rbd::MIRROR_SNAPSHOT_STATE_PRIMARY_DEMOTED,
flags);
if (r != 0) {
return r;
auto ns = std::get_if<cls::rbd::MirrorGroupSnapshotNamespace>(
&it->snapshot_namespace);
if (ns != nullptr) {
- if (ns->state != cls::rbd::MIRROR_SNAPSHOT_STATE_PRIMARY) {
+ // FIXME: after relocate, on new primary the previous primary demoted
+ // snap is not getting deleted, until the next demotion.
+ if (ns->state != cls::rbd::MIRROR_SNAPSHOT_STATE_PRIMARY &&
+ ns->state != cls::rbd::MIRROR_SNAPSHOT_STATE_NON_PRIMARY) {
continue;
}
count++;
#include "Replayer.h"
#include "common/Clock.h" // for ceph_clock_now()
+#include "common/Cond.h"
#include "common/debug.h"
#include "common/errno.h"
#include "common/perf_counters.h"
dout(10) << "shut down pending on completion of snapshot replay" << dendl;
return;
}
+
+ if (!m_prune_snap_ids.empty()) {
+ locker.unlock();
+
+ auto prune_snap_id = *m_prune_snap_ids.begin();
+ dout(5) << "pruning unused non-primary snapshot " << prune_snap_id << dendl;
+ C_SaferCond ctx;
+ prune_non_primary_snapshot(&ctx, prune_snap_id);
+ ctx.wait();
+ m_on_init_shutdown = nullptr;
+ shut_down(on_finish);
+ return;
+ }
locker.unlock();
unregister_remote_update_watcher();
auto prune_snap_id = *m_prune_snap_ids.begin();
dout(5) << "pruning unused non-primary snapshot " << prune_snap_id << dendl;
- prune_non_primary_snapshot(prune_snap_id);
+ prune_non_primary_snapshot(nullptr, prune_snap_id);
return;
}
}
template <typename I>
-void Replayer<I>::prune_non_primary_snapshot(uint64_t snap_id) {
+void Replayer<I>::prune_non_primary_snapshot(
+ Context* on_finish, uint64_t snap_id) {
dout(10) << "snap_id=" << snap_id << dendl;
auto local_image_ctx = m_state_builder->local_image_ctx;
auto ctx = create_context_callback<
Replayer<I>, &Replayer<I>::handle_prune_non_primary_snapshot>(this);
+ if (on_finish) {
+ ctx = on_finish;
+ }
local_image_ctx->operations->snap_remove(snap_namespace, snap_name, ctx);
}
void scan_local_mirror_snapshots(std::unique_lock<ceph::mutex>* locker);
void scan_remote_mirror_snapshots(std::unique_lock<ceph::mutex>* locker);
- void prune_non_primary_snapshot(uint64_t snap_id);
+ void prune_non_primary_snapshot(Context* on_finish, uint64_t snap_id);
void handle_prune_non_primary_snapshot(int r);
void copy_snapshots();