From 5792e83bc62c05687c584f9ba76479a5a0262941 Mon Sep 17 00:00:00 2001 From: jochen Date: Sun, 22 Nov 2026 23:01:56 +0100 Subject: [PATCH] Runner: the Ager deletes an aged test run's ask keys with the run The ask key ask. is created with the run and deleted with it, but the Ager deleted an aged run and left its ask keys in test-runs for good; only a run whose last reader left lost them. The Ager now holds the run clock and unmarks the aged run's ask keys as the Hearer does. Builds: design 47 H2 H-A-500 addenda (1) --- .../cmd/mesh-delivery-pipeline/testruns.go | 2 +- .../internal/pipeline/aged.go | 5 ++++- .../internal/pipeline/runends.go | 18 +++++++++++------- .../internal/pipeline/testruns_read.go | 2 +- .../internal/pipeline/testruns_test.go | 9 ++++++++- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns.go index 775a1e897..afe5b284d 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns.go @@ -449,7 +449,7 @@ func openTestRuns(ctx context.Context, js jetstream.JetStream, cred process.Acco hearer.TestRuns, hearer.Clock, hearer.Runs, hearer.DropRun = runs, runs, settings, drop hearer.RunOutputs = objects if hearer.Ager != nil { - hearer.Ager.Runs, hearer.Ager.RunOutputs, hearer.Ager.RunsKept = runs, objects.Delete, settings.Kept + hearer.Ager.Runs, hearer.Ager.RunOutputs, hearer.Ager.RunsKept, hearer.Ager.Clock = runs, objects.Delete, settings.Kept, runs } logf("test runs: cap %d bytes, kept %s, step bound %s, untaken bound %s", settings.CapBytes, settings.Kept, settings.StepBound, settings.Untaken) return kv, objects, nil diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/aged.go b/modules/mesh-delivery-pipeline/internal/pipeline/aged.go index 6c7705e3a..6699631f7 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/aged.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/aged.go @@ -57,7 +57,9 @@ type Ager struct { Runs TestRuns RunOutputs func(name string) error RunsKept time.Duration - Now func() time.Time + // Clock is test-runs' bound and ask keys: a run's ask keys are deleted with the run (H-A-500 addendum (1)); nil keeps them. + Clock RunClock + Now func() time.Time // Logf is the runner's journal: each delete writes a line naming the key or object and its retention. Logf func(string, ...any) } @@ -159,6 +161,7 @@ func (a *Ager) ageRun(r Retention, e seat.LogEntry) { return } a.logf("aged: deleted the test run %s and its output (%s after its end)", run, r.Age) + unmarkAsks(a.Clock, run, a.logf) return } } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/runends.go b/modules/mesh-delivery-pipeline/internal/pipeline/runends.go index e2645135a..99e2267d7 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/runends.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/runends.go @@ -83,22 +83,26 @@ func markAsk(clock RunClock, ask, run string, logf func(string, ...any)) { } // unmarkAsks deletes, with the run under run, every ask key holding it (H-A-500 addendum (1)): the ask it names now and each -// it was given before (a rerun, a declined step asked again). A key not read or not deleted is said. -func (h *Hearer) unmarkAsks(run string) { - all, err := h.Clock.Keys() +// it was given before (a rerun, a declined step asked again). A key not read or not deleted is said. The Hearer calls it +// when a run's last reader leaves, the Ager when a run is aged, so no ask key outlives its run. +func unmarkAsks(clock RunClock, run string, logf func(string, ...any)) { + if clock == nil { + return + } + all, err := clock.Keys() if err != nil { - h.logf("the ask keys of the deleted test run %s are not listed, so they are kept: %v", run, err) + logf("the ask keys of the deleted test run %s are not listed, so they are kept: %v", run, err) return } for _, k := range all { if !IsRunAsk(k) { continue } - if held, ok, err := h.Clock.RunOfAsk(strings.TrimPrefix(k, AskPrefix)); err != nil || !ok || held != run { + if held, ok, err := clock.RunOfAsk(strings.TrimPrefix(k, AskPrefix)); err != nil || !ok || held != run { continue } - if err := h.Clock.Unbound(k); err != nil { - h.logf("the ask key %s of the deleted test run %s is not deleted: %v", k, run, err) + if err := clock.Unbound(k); err != nil { + logf("the ask key %s of the deleted test run %s is not deleted: %v", k, run, err) } } } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/testruns_read.go b/modules/mesh-delivery-pipeline/internal/pipeline/testruns_read.go index 5595d64ac..1bbc0c462 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/testruns_read.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/testruns_read.go @@ -165,7 +165,7 @@ func (v Verbs) TestRunsDrop(caller string, in seat.TestRunsDropInput) (seat.Test for _, k := range []string{BoundPrefix + in.Key, UntakenPrefix + in.Key} { _ = h.Clock.Unbound(k) } - h.unmarkAsks(in.Key) + unmarkAsks(h.Clock, in.Key, h.logf) } gone := r.Answer() gone.Key = in.Key diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go index 8e79a9529..385e3624d 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go @@ -268,7 +268,7 @@ func TestATestRunHasOneClockACapAndAnAge(t *testing.T) { f.objects["out-1"] = []byte("ok") now := agedNow a := &Ager{Runs: f.runs, RunOutputs: f.objects.Delete, RunsKept: 7 * 24 * time.Hour, Pipelines: agedDeleter{f.store}, - Aged: agedState{}, Now: func() time.Time { return now }, + Clock: f.clock, Aged: agedState{}, Now: func() time.Time { return now }, Log: func(from uint64, limit int) ([]LoggedEntry, error) { if from > 1 { return nil, nil @@ -280,11 +280,18 @@ func TestATestRunHasOneClockACapAndAnAge(t *testing.T) { if _, _, err := f.runs.Get(run); err != nil { t.Fatal("a run is aged before test-runs-kept passed") } + if held, ok, _ := f.clock.RunOfAsk(unit.Ask); !ok || held != run { + t.Fatalf("the ask key of %s holds %q before the run is aged, want %s", unit.Ask, held, run) + } now = now.Add(2 * 24 * time.Hour) a.Age() if _, _, err := f.runs.Get(run); err != ErrNoRun || len(f.objects) != 0 { t.Errorf("the run past test-runs-kept is %v, objects %v; want both deleted", err, f.objects) } + // The ask key is deleted with the aged run (H-A-500 addendum (1)), as it is when the run's last reader leaves. + if _, ok, _ := f.clock.RunOfAsk(unit.Ask); ok { + t.Errorf("the ask key of %s outlives its aged run", unit.Ask) + } }) }