Download this file
| 1 | package host |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "github.com/carlosframework/platform/internal/hostbox" |
| 6 | ) |
| 7 | |
| 8 | // reapLocked needs only namespace/slot/record authority; it never takes a host |
| 9 | // guard. Pressure selection and authenticated replacement are separate callers. |
| 10 | func (l *servingParkLedger) reapLocked(ctx context.Context, id string) error { |
| 11 | r, err := l.read(id) |
| 12 | if err != nil { |
| 13 | return err |
| 14 | } |
| 15 | unlock, err := l.state.Lock(ctx, "slot-"+servingParkKey(r.Authorization.Successor.Box, r.Authorization.Successor.Host)+".lock") |
| 16 | if err != nil { |
| 17 | return err |
| 18 | } |
| 19 | defer unlock() |
| 20 | unlockRecord, err := l.state.Lock(ctx, "retirement-"+id+".lock") |
| 21 | if err != nil { |
| 22 | return err |
| 23 | } |
| 24 | defer unlockRecord() |
| 25 | if r.Closed { |
| 26 | return nil |
| 27 | } |
| 28 | if !r.Complete || r.Disposition != servingParkRetain || l.now().Before(r.ReapAfter) { |
| 29 | return hostbox.ErrChanged |
| 30 | } |
| 31 | return l.deleteLocked(ctx, &r, "expiry") |
| 32 | } |
| 33 | |