feat: release the target claim in cleanup

cleanup now deletes the claim file under .cephmig/claims as its last
step, if it holds the job's own ID, and removes the claim directories
when they are empty. A cleaned-up job is finished: cleanup and finalize
do nothing and do not claim the target again, and sync is refused.

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 20:37:20 +01:00
1 parent 5f29328932
commit a6e7bbb17e
10 files changed
+218 -14

No files matched your search

+29 -5
View File
@@ -98,12 +98,16 @@ func (e Engine) Cleanup(ctx context.Context, c Config, statePath string) error {
return errors.New("config or cluster identity changed; refusing to use migration state")
}
claim, err := e.access().Claim(ctx, c, s.TargetFSID, s.ID)
if err != nil {
return err
// A completed cleanup has released the claim; do not create it again.
if !cleanedUp(s) {
claim, err := e.access().Claim(ctx, c, s.TargetFSID, s.ID)
if err != nil {
return err
}
defer claim.Close()
}
defer claim.Close()
native := c.Backend == "native"
src, dst := ceph{endpoint: c.Source, exec: e.Exec, native: native}, ceph{endpoint: c.Target, exec: e.Exec, native: native}
s.LiveSnapshot = ""
@@ -115,6 +119,26 @@ func (e Engine) Cleanup(ctx context.Context, c Config, statePath string) error {
return err
}
e.log("cleanup: removed cephmig snapshots at source and target; state=%s", abs)
// Last step: the job no longer protects the target.
if err = e.access().Release(ctx, c, s.TargetFSID, s.ID); err != nil {
return err
}
e.log("cleanup: removed cephmig snapshots and the target claim; state=%s", abs)
return nil
}
// cleanedUp reports whether Cleanup completed its snapshot removal for s.
func cleanedUp(s *State) bool {
if s.Phase != "ready-for-cutover" || s.LiveSnapshot != "" {
return false
}
for _, snap := range s.Snapshots {
if snap.Owned && !snap.Removed {
return false
}
}
return true
}