package registry import "context" // SetClaimHold runs inside the caller's captured hostguard transaction. // The caller supplies phase authority; this transaction binds the exact row // and observed operation, and does not change the failed-host projection. func (r *Registry) SetClaimHold(ctx context.Context, host string, owner ClaimOwnership, expected, next string) error { if r.remote != nil { _, err := r.remote.call(ctx, remoteRequest{Method: "SetClaimHold", Host: host, Owner: owner, Expected: expected, Next: next}, nil) return err } if !owner.Valid() || host == "" { return ErrClaimOwnership } tx, err := r.beginClaimTransaction(ctx, true) if err != nil { return err } defer tx.Rollback() result, err := tx.ExecContext(ctx, `UPDATE routes SET hold_op=? WHERE host=? AND claim_incarnation=? AND claim_stamp=? AND claim_owner=? AND claim_row_id=? AND hold_op=?`, next, host, owner.ClaimIncarnation, owner.ClaimStamp, owner.ClaimOwner, owner.ClaimRowID, expected) if err != nil { return err } n, err := result.RowsAffected() if err != nil { return err } if n != 1 { return ErrClaimOwnership } return tx.Commit() }