feat: remove cephmig snapshots during sync and add cleanup command

Users of a subvolume should not see traces of the migration. Each sync
round now deletes the older cephmig-* round snapshots at source and
target and keeps only the newest one as base for the next round. The new
command `cephmig cleanup` deletes the remaining one after the cutover.
Application snapshots are never touched.

The journal marks a snapshot as removed before deleting it, so an
interrupted run finishes the deletion instead of reporting a vanished
snapshot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-12-03 19:52:13 +01:00
1 parent cc2dff46a0
commit 907d400765
9 files changed
+322 -19

No files matched your search

+24
View File
@@ -29,6 +29,10 @@ def snapshot(cluster, *args):
return volume(cluster, "snapshot", *args)
def snapshot_names(cluster):
return {x["name"] for x in json.loads(snapshot(cluster, "ls", "cephfs", name))}
def acl():
entries = [(1, 6, 0xffffffff), (2, 4, 12345), (4, 0, 0xffffffff),
(16, 4, 0xffffffff), (32, 0, 0xffffffff)]
@@ -247,8 +251,16 @@ elif action in ("verify", "final"):
compare(roots["source"], roots["target"])
compare_times(roots["source"], roots["target"], atime=False)
s = json.load(open(state))
listed = {c: snapshot_names(c) for c in ("source", "target")}
# Only the newest round snapshot remains as base; older ones are removed.
kept = [x["name"] for x in s["snapshots"] if x["owned"] and not x.get("removed")]
assert kept == [s["live_snapshot"]], (kept, s["live_snapshot"])
for c in ("source", "target"):
assert {n for n in listed[c] if n.startswith("cephmig-")} == set(kept), (c, listed[c])
for snap in s["snapshots"]:
assert snap["done"], snap
if snap.get("removed"):
continue
a, b = [f"/mnt/{c}-fs" + ceph(c, "fs", "subvolume", "snapshot", "getpath",
"cephfs", name, snap["name"], "migration") for c in ("source", "target")]
compare(a, b)
@@ -264,6 +276,18 @@ elif action in ("verify", "final"):
assert s["phase"] == "ready-for-cutover" and len(s["snapshots"]) == 5, s
assert s["snapshots"][-1]["transfer"]["bytes_copied"] == 0, s["snapshots"][-1]
print(json.dumps({"phase": s["phase"], "rounds": len(s["snapshots"]), "history_2": h2}))
elif action == "cleaned":
roots = json.load(open(fixture))
compare(roots["source"], roots["target"])
compare_times(roots["source"], roots["target"], atime=False)
s = json.load(open(state))
assert s["phase"] == "ready-for-cutover" and not s.get("live_snapshot"), s
assert all(x.get("removed") for x in s["snapshots"] if x["owned"]), s
application = {x["name"] for x in s["snapshots"] if not x["owned"]}
assert application == {"history-1", "history-2"}, application
for c in ("source", "target"):
assert snapshot_names(c) == application, (c, snapshot_names(c))
print(json.dumps({"remaining_snapshots": sorted(application)}))
elif action == "busy":
# An unrelated source subvolume remains writable throughout migration/finalization.
p = "/mnt/source/" + name