Runner: the Ager deletes an aged test run's ask keys with the run

The ask key ask.<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)
This commit is contained in:
2026-11-22 23:02:05 +01:00
parent 678d8fa5b3
commit 5792e83bc6
5 changed files with 25 additions and 11 deletions
@@ -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
@@ -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
}
}
@@ -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)
}
}
}
@@ -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
@@ -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)
}
})
}