carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package registry
2
3import "context"
4
5// SetClaimHold runs inside the caller's captured hostguard transaction.
6// The caller supplies phase authority; this transaction binds the exact row
7// and observed operation, and does not change the failed-host projection.
8func (r *Registry) SetClaimHold(ctx context.Context, host string, owner ClaimOwnership, expected, next string) error {
9 if r.remote != nil {
10 _, err := r.remote.call(ctx, remoteRequest{Method: "SetClaimHold", Host: host, Owner: owner, Expected: expected, Next: next}, nil)
11 return err
12 }
13
14 if !owner.Valid() || host == "" {
15 return ErrClaimOwnership
16 }
17 tx, err := r.beginClaimTransaction(ctx, true)
18 if err != nil {
19 return err
20 }
21 defer tx.Rollback()
22 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)
23 if err != nil {
24 return err
25 }
26 n, err := result.RowsAffected()
27 if err != nil {
28 return err
29 }
30 if n != 1 {
31 return ErrClaimOwnership
32 }
33 return tx.Commit()
34}
35