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:
1 parent
5f29328932
commit
a6e7bbb17e
10 files changed
+218
-14
No files matched your search
@@ -190,10 +190,16 @@ func emptyDirectory(path string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// claimName is the file name of the claim for the target subvolume ep in
|
||||
// the cluster fsid, below .cephmig/claims at the file system root.
|
||||
func claimName(fsid string, ep Endpoint) string {
|
||||
key := sha256.Sum256([]byte(fsid + "\x00" + ep.Filesystem + "\x00" + ep.Group + "\x00" + ep.Subvolume))
|
||||
return hex.EncodeToString(key[:])
|
||||
}
|
||||
|
||||
// claimTarget locks the target subvolume for the job id. The claim is outside
|
||||
// the migrated tree and survives deletion of the local journal. O_EXCL prevents two different jobs from adopting the same target.
|
||||
func claimTarget(root, fsid string, ep Endpoint, id string) (*os.File, error) {
|
||||
key := sha256.Sum256([]byte(fsid + "\x00" + ep.Filesystem + "\x00" + ep.Group + "\x00" + ep.Subvolume))
|
||||
dir := filepath.Join(root, ".cephmig", "claims")
|
||||
if err := privateDirectories(dir); err != nil {
|
||||
return nil, err
|
||||
@@ -204,7 +210,7 @@ func claimTarget(root, fsid string, ep Endpoint, id string) (*os.File, error) {
|
||||
return nil, errors.New("claim directory contains symlinks")
|
||||
}
|
||||
|
||||
path := filepath.Join(dir, hex.EncodeToString(key[:]))
|
||||
path := filepath.Join(dir, claimName(fsid, ep))
|
||||
f, err := os.OpenFile(path, os.O_CREATE|os.O_EXCL|os.O_RDWR, 0600)
|
||||
if err == nil {
|
||||
if _, err = f.WriteString(id + "\n"); err == nil {
|
||||
@@ -369,6 +375,15 @@ func (e Engine) Sync(ctx context.Context, c Config, statePath string, final bool
|
||||
return errors.New("config or cluster identity changed; refusing to reuse migration state")
|
||||
}
|
||||
|
||||
if cleanedUp(s) {
|
||||
if final {
|
||||
e.log("job is cleaned up; nothing to do")
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.New("job is cleaned up; sync is no longer allowed")
|
||||
}
|
||||
|
||||
claim, err := e.access().Claim(ctx, c, s.TargetFSID, s.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in new issue
Block a user