activator: a failed size lookup marks the entry for the next sweep; the captured tier is pinned to the read-back
A backstop pass starts clean and moves the backstop clock before its registry read, so a failed read left the entry unmarked for five minutes. The lookup error now always marks it. New tests: a failed backstop lookup is retried on the next sweep with the clock unmoved, and a settled read-back that differs from the request is what Current.Tier records.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+64
−1
internal/activator/size.go+6 −1internal/activator/size_live_test.go+58 −0
CI failed — run details
diff --git a/internal/activator/size.go b/internal/activator/size.go| index ff89a01b3..84efdc927 100644 |
| --- a/internal/activator/size.go |
| +++ b/internal/activator/size.go |
| @@ -226,9 +226,14 @@ func (a *Service) sizePass(e *actEntry, s sizeSnap) { |
| if a.Routes != nil { |
| r, err := a.Routes.Get(host) |
| if err != nil { |
| + // The compare did not happen. A backstop pass started clean and |
| + // has already moved the backstop clock, so the entry is marked |
| + // for the next sweep whatever started this pass. |
| log.Printf("activator: %s: size check: route lookup: %v (retried next sweep)", host, err) |
| + a.endSizeCheck(e, true) |
| + return |
| } |
| - if err != nil || r == nil { |
| + if r == nil { |
| a.endSizeCheck(e, s.dirty) |
| return |
| } |
diff --git a/internal/activator/size_live_test.go b/internal/activator/size_live_test.go| index a1c899852..f92e265e5 100644 |
| --- a/internal/activator/size_live_test.go |
| +++ b/internal/activator/size_live_test.go |
| @@ -31,6 +31,8 @@ type liveRoutes struct { |
| gets int |
| gate chan struct{} |
| entered chan struct{} |
| + // fails is how many more Gets answer an error. |
| + fails int |
| } |
| func (r *liveRoutes) Get(host string) (*registry.Route, error) { |
| @@ -38,6 +40,11 @@ func (r *liveRoutes) Get(host string) (*registry.Route, error) { |
| r.gets++ |
| gate, entered := r.gate, r.entered |
| r.gate = nil |
| + if r.fails > 0 { |
| + r.fails-- |
| + r.mu.Unlock() |
| + return nil, errors.New("registry: database is locked") |
| + } |
| r.mu.Unlock() |
| if gate != nil { |
| select { |
| @@ -203,6 +210,30 @@ func TestLiveGrowthWritesSliceAndUnitAndCapturesTheReadBack(t *testing.T) { |
| } |
| } |
| +// The captured tier is root's read-back, never the request: a read-back |
| +// that settles (slice and unit at one value) at a figure other than the one |
| +// asked for is what the entry records. |
| +func TestLiveGrowthCapturesTheReadBackNotTheRequest(t *testing.T) { |
| + t.Parallel() |
| + const held = int64(1610612736) // 1.5 GiB: what the slice and unit hold after the write |
| + f := newSizeFixture(t, "", half) |
| + n := f.incumbent.N |
| + f.b.setSizeHooks(nil, func(_ uint64, _ cgroup.Size, _ int64) (instancectl.SizeReadBack, error) { |
| + return instancectl.SizeReadBack{SliceMemoryMax: held, UnitMemoryMax: held}, nil |
| + }) |
| + f.operatorSets("large") |
| + f.sweep(t) |
| + if got, want := f.sizeEvents(), []string{readSizeEv(n), sizeEv("large", gib, n)}; !slices.Equal(got, want) { |
| + t.Fatalf("size calls %v, want %v", got, want) |
| + } |
| + if g, ok := f.a.Current(f.host); !ok || g.Tier.MemoryMax != held { |
| + t.Fatalf("Current = %+v, %v; want Tier %d from the read-back, not the requested %d", g, ok, held, gib) |
| + } |
| + if st := f.state(t); st.Unsettled { |
| + t.Fatalf("SizeState = %+v, want settled", st) |
| + } |
| +} |
| + |
| // Astra plan R1-8: with generations off the handle is numbered but no unit |
| // has that number, so the pass sizes the run template's slice (gen 0). |
| func TestLiveGrowthWithGenerationsOffUsesTheRunTemplate(t *testing.T) { |
| @@ -541,6 +572,33 @@ func TestTheBackstopCatchesAMissedNoteSize(t *testing.T) { |
| } |
| } |
| +// A backstop compare whose registry read fails is retried on the very next |
| +// sweep, not five minutes later: the failed read moved the backstop clock, |
| +// so the entry is marked. |
| +func TestAFailedBackstopLookupRetriesNextSweep(t *testing.T) { |
| + t.Parallel() |
| + f := newSizeFixture(t, "", half) |
| + n := f.incumbent.N |
| + f.sweep(t) |
| + f.routes.setSize(f.host, "large") // no NoteSize |
| + f.clk.advance(sizeBackstop) |
| + f.routes.mu.Lock() |
| + f.routes.fails = 1 |
| + f.routes.mu.Unlock() |
| + before := f.routes.count() |
| + f.sweep(t) |
| + if got := f.routes.count(); got != before+1 { |
| + t.Fatalf("%d registry reads, want the one failed backstop read", got-before) |
| + } |
| + if ev := f.sizeEvents(); len(ev) != 0 { |
| + t.Fatalf("size calls %v after a failed lookup", ev) |
| + } |
| + f.sweep(t) // the clock has not moved |
| + if got, want := f.sizeEvents(), []string{readSizeEv(n), sizeEv("large", gib, n)}; !slices.Equal(got, want) { |
| + t.Fatalf("size calls %v, want %v on the next sweep", got, want) |
| + } |
| +} |
| + |
| // Nothing is sized live for a host that is asleep or a worker, and a host |
| // with no live size (flat) is asked once per change, with no unsettled |
| // mark and no retries. |