| index ea0b1b0df..d558292f1 100644 |
| --- a/internal/activator/activator.go |
| +++ b/internal/activator/activator.go |
| @@ -676,14 +676,19 @@ type actEntry struct { |
| // (finishPendingStop) the moment it's proven. |
| pendingStop bool |
| // The fleet checkpoint's state (fleet record labels R2), under a.mu. |
| - // checkpointCancel is non-nil while finishStop's CloseProven is in |
| - // flight, and cancels its context; checkpointUnproven marks a stop |
| - // kept pending over an unproven checkpoint; checkpointAbandoned marks |
| - // one Shutdown abandoned when its budget ended |
| - // (abandonCheckpointsAtExit), which no later finishStop tries again. |
| + // checkpointBusy is true from finishStop's CloseProven until its |
| + // outcome has been handled (closeFleetCheckpoint), and |
| + // checkpointCancel cancels that call's context meanwhile; |
| + // checkpointUnproven marks a stop kept pending over an unproven |
| + // checkpoint; checkpointAbandoned marks one Shutdown abandoned when |
| + // its budget ended (abandonCheckpointsAtExit), which no later |
| + // finishStop tries again. checkpointNotice is its C45, logged once by |
| + // whichever call learns of the abandonment first (not under a.mu). |
| + checkpointBusy bool |
| checkpointCancel context.CancelFunc |
| checkpointUnproven bool |
| checkpointAbandoned bool |
| + checkpointNotice abandonNotice |
| // stopRetrying is true while a retried proc.Stop call for a still-running |
| // pendingStop entry is in flight, so finishPendingStops does not launch a |
| // second one on top of it. stopRetriedAt is when the last retry was |
| @@ -1748,6 +1753,10 @@ type Service struct { |
| // at a chosen point. It is a test seam; nil in production |
| // (context.WithCancel). |
| checkpointContext func(context.Context) (context.Context, context.CancelFunc) |
| + // checkpointReturned, when set, is called (off a.mu) once a fleet |
| + // stop's CloseProven has returned, before its outcome is handled |
| + // (closeFleetCheckpoint). It is a test seam; nil in production. |
| + checkpointReturned func(host string, err error) |
| } |
| |
| // New wires the state machine to its side-effect backend and due-time store. |
| @@ -5531,6 +5540,9 @@ func (a *Service) finishStop(e *actEntry, outcome *stopObservation) { |
| type provenCloser interface { |
| CloseProven(ctx context.Context) error |
| TryAbandon(ctx context.Context) bool |
| + // Abandoned reports whether the teardown, by whichever call, was an |
| + // abandonment: the lease frees at its TTL (lease.Replicator). |
| + Abandoned() bool |
| } |
| |
| var _ provenCloser = (*lease.Replicator)(nil) |
| @@ -5586,25 +5598,37 @@ func (a *Service) closeFleetCheckpoint(ctx context.Context, e *actEntry, pc prov |
| mk = context.WithCancel |
| } |
| cctx, cancel := mk(ctx) |
| - e.checkpointCancel = cancel |
| + e.checkpointCancel, e.checkpointBusy = cancel, true |
| started := a.checkpointStarted |
| a.mu.Unlock() |
| defer cancel() |
| + // The checkpoint stays registered until its outcome has been handled |
| + // (M1 review Astra P2-2): Shutdown's exit (abandonCheckpointsAtExit) |
| + // then never misses it, between CloseProven's return and the pending |
| + // state or the abandonment below. |
| + defer func() { |
| + a.mu.Lock() |
| + e.checkpointCancel, e.checkpointBusy = nil, false |
| + a.mu.Unlock() |
| + }() |
| if started != nil { |
| started(e.host) |
| } |
| err = pc.CloseProven(cctx) |
| a.mu.Lock() |
| - e.checkpointCancel = nil |
| shutting := a.shuttingDown |
| + returned := a.checkpointReturned |
| a.mu.Unlock() |
| + if returned != nil { |
| + returned(e.host, err) |
| + } |
| prefix := "" |
| if shutting { |
| prefix = "shutdown: " |
| } |
| switch { |
| case errors.Is(err, lease.ErrCheckpointAbandoned): |
| - logCheckpointAbandoned(prefix, e.host) |
| + e.checkpointNotice.name(prefix, e.host) |
| case errors.Is(err, lease.ErrCheckpointUnproven): |
| a.mu.Lock() |
| shutting = a.shuttingDown |
| @@ -5616,33 +5640,55 @@ func (a *Service) closeFleetCheckpoint(ctx context.Context, e *actEntry, pc prov |
| a.mu.Unlock() |
| if !shutting { |
| log.Printf("activator: final checkpoint %s: %v", e.host, err) |
| - // draft for copy review (C44) |
| - log.Printf("activator: final checkpoint for %s failed. keeping its lease until the checkpoint succeeds", e.host) |
| + logCheckpointKept(e.host) |
| if hook != nil { |
| hook(e.host) |
| } |
| return true, err |
| } |
| - if abandonCheckpoint(pc) { |
| - logCheckpointAbandoned("shutdown: ", e.host) |
| + abandonCheckpoint(pc) |
| + if pc.Abandoned() { |
| + e.checkpointNotice.name("shutdown: ", e.host) |
| } |
| } |
| return false, err |
| } |
| |
| +// logCheckpointKept is the line a fleet stop or failed wake kept over an |
| +// unproven final checkpoint logs (C44). |
| +func logCheckpointKept(host string) { |
| + // draft for copy review (C44) |
| + log.Printf("activator: final checkpoint for %s failed. keeping its lease until the checkpoint succeeds", host) |
| +} |
| + |
| // abandonCheckpoint gives an unproven fleet checkpoint's lease up to its |
| // TTL: renewal and replication stop, nothing is released, and, under a |
| // context already done, nothing more is synced (the checkpoint just |
| // failed, as a crash would ship nothing more). It reports whether this |
| -// call tore the replicator down, and so must name it (C45). |
| +// call tore the replicator down. Whoever names the abandonment (C45) |
| +// asks pc.Abandoned instead, which answers for any call's teardown. |
| func abandonCheckpoint(pc provenCloser) bool { |
| done, cancel := context.WithCancel(context.Background()) |
| cancel() |
| return pc.TryAbandon(done) |
| } |
| |
| +// abandonNotice is the C45 of one abandoned fleet checkpoint (M1 review |
| +// Astra P2-2): every call that learns its replicator was abandoned names |
| +// it through the notice, which logs once. A call that comes second |
| +// returns only once the first has logged (sync.Once), so Shutdown, which |
| +// names each checkpoint it abandons or finds abandoned before it |
| +// returns, never returns before the line is out. |
| +type abandonNotice struct{ once sync.Once } |
| + |
| +// name logs C45 for host with prefix, the first time it is called. |
| +func (n *abandonNotice) name(prefix, host string) { |
| + n.once.Do(func() { logCheckpointAbandoned(prefix, host) }) |
| +} |
| + |
| // logCheckpointAbandoned is the ERROR an abandoned fleet checkpoint logs, |
| -// naming the host; prefix says where ("shutdown: " or ""). |
| +// naming the host; prefix says where ("shutdown: " or ""). It is logged |
| +// only through an abandonNotice. |
| func logCheckpointAbandoned(prefix, host string) { |
| // draft for copy review (C45) |
| log.Printf("activator: ERROR: %s%s: its final checkpoint failed, so its lease is not released and frees at its expiry", prefix, host) |
| @@ -5650,18 +5696,20 @@ func logCheckpointAbandoned(prefix, host string) { |
| |
| // abandonCheckpointsAtExit runs as Shutdown's budget ends: no unproven |
| // fleet checkpoint is left renewing or unnamed when Shutdown returns. |
| -// Every fleet stop with a checkpoint in flight (e.checkpointCancel), or |
| -// kept pending over an unproven one, is marked abandoned (so no later |
| -// finishStop tries it again), its checkpoint's context is cancelled, and |
| -// its replicator abandoned here, whatever the call in flight is waiting |
| -// on, and named when this is the teardown. Nothing waits for the calls |
| -// in flight: once abandoned they hold no lease, and each finishes its |
| -// entry when it returns. |
| +// Every fleet stop with a checkpoint in flight or not yet handled |
| +// (e.checkpointBusy), or kept pending over an unproven one, is marked |
| +// abandoned (so no later finishStop tries it again), its checkpoint's |
| +// context is cancelled, and its replicator abandoned here, whatever the |
| +// call in flight is waiting on. When its teardown was an abandonment, by |
| +// this call or any other, it is named (C45) before this returns, once in |
| +// all (abandonNotice). Nothing waits for the calls in flight: once |
| +// abandoned they hold no lease, and each finishes its entry when it |
| +// returns. |
| func (a *Service) abandonCheckpointsAtExit() { |
| a.mu.Lock() |
| var left []*actEntry |
| for _, e := range a.entries { |
| - if e.checkpointAbandoned || (e.checkpointCancel == nil && !e.checkpointUnproven) { |
| + if e.checkpointAbandoned || (!e.checkpointBusy && !e.checkpointUnproven) { |
| continue |
| } |
| e.checkpointAbandoned = true |
| @@ -5672,8 +5720,11 @@ func (a *Service) abandonCheckpointsAtExit() { |
| } |
| a.mu.Unlock() |
| for _, e := range left { |
| - if pc, ok := a.fleetProvenCloser(e); ok && abandonCheckpoint(pc) { |
| - logCheckpointAbandoned("shutdown: ", e.host) |
| + if pc, ok := a.fleetProvenCloser(e); ok { |
| + abandonCheckpoint(pc) |
| + if pc.Abandoned() { |
| + e.checkpointNotice.name("shutdown: ", e.host) |
| + } |
| } |
| } |
| } |