diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go index f5f8af67..a39f8180 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go @@ -159,7 +159,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro starter := &pipeline.Starter{Pipelines: store, Logf: logger.Printf, Say: say, Registration: rv.Registrations.Registration, Steps: busStepAsker{ctx: ctx, js: js, cred: cred}, Name: cred.Module, Kept: keptReader(ctx, kept), Toolchain: toolchainReader(ctx, toolchains), - Fills: fills, Recovered: kvRecoveries{ctx, recovered}.Has, Holders: rv.Holders.Holders, Ended: hearer.EndedAtPlacing} + Fills: fills, Recovered: kvRecoveries{ctx, recovered}.Has, Holders: rv.Holders.Holders, Ended: hearer.EndedAtPlacing, + Findings: rv.Findings, Observer: cred.Module} // a mover waiting on its registration is registration-missing (H-A-262) hearer.AskSteps = starter.AskSteps // Every ask but a test run's is bounded until its holder's first word (H-A-235, H-A-238), its bounds keys of the state // bounds. diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/registration_missing.go b/modules/mesh-delivery-pipeline/internal/pipeline/registration_missing.go new file mode 100644 index 00000000..c898fbdc --- /dev/null +++ b/modules/mesh-delivery-pipeline/internal/pipeline/registration_missing.go @@ -0,0 +1,75 @@ +package pipeline + +import ( + "context" + "fmt" + + mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient" + condseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions" + "git.novox.be/novox/mesh-sdk/go/keys" +) + +// RegistrationMissingKind is the runner's finding of a mover that waits on its module's registration (design 47 H H-A-262, +// G A-327): scope module, id the module, raised while a mover of a running pipeline has no registration to place its steps +// from, cleared when the registration arrives. +const RegistrationMissingKind = "registration-missing" + +// registrationMissingID is the finding's id: the module, escaped as a key's name is. +func registrationMissingID(module string) string { return keys.EscapeName(module) } + +// registrationMissing raises registration-missing of module, waited on by the pipeline key (H-A-262). +func (s *Starter) registrationMissing(module, key string) { + if s.Findings == nil { + return + } + id := registrationMissingID(module) + err := s.Findings.Write(context.Background(), condseat.Finding{Scope: mcc.ScopeModule, ID: id, Kind: RegistrationMissingKind, + Severity: condseat.FindingSeverityWarning, + Summary: fmt.Sprintf("%s has no registration: the pipeline %s waits on it for its steps", module, key), + Headline: "A pipeline waits on a module's registration", + Explanation: fmt.Sprintf("The pipeline %s moves %s, which has no registration, so none of its steps is placed (A-327). The indexer registers a module the take-in first lists (H-A-262); this is cleared when the registration of %s arrives.", + key, module, module), + Needs: "the registration of " + module, + Source: "pipeline-runner." + RegistrationMissingKind, Observer: s.Observer, At: s.now(), + Subject: condseat.Subject{Scope: mcc.ScopeModule, ID: id}}) + if err != nil { + s.logf("the finding %s of %s is not written: %v", RegistrationMissingKind, module, err) + } +} + +// registrationArrived clears registration-missing of module when the findings hold it (H-A-262). +func (s *Starter) registrationArrived(module string) { + if s.Findings == nil { + return + } + id := registrationMissingID(module) + for _, f := range s.Findings.Held() { + if f.Scope != mcc.ScopeModule || f.ID != id || f.Kind != RegistrationMissingKind { + continue + } + if err := s.Findings.Clear(context.Background(), mcc.ScopeModule, id, RegistrationMissingKind, "the registration of "+module+" arrived"); err != nil { + s.logf("the finding %s of %s is not cleared: %v", RegistrationMissingKind, module, err) + } + return + } +} + +// registrationsArrived clears registration-missing of every module the registrations held now name (Waiting: the +// registrations' first view, or a restart that heard the registration before). +func (s *Starter) registrationsArrived() { + if s.Findings == nil || s.Registration == nil { + return + } + for _, f := range s.Findings.Held() { + if f.Scope != mcc.ScopeModule || f.Kind != RegistrationMissingKind { + continue + } + module, err := keys.UnescapeName(f.ID) + if err != nil { + module = f.ID + } + if _, ok := s.Registration(module); ok { + s.registrationArrived(module) + } + } +} diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/start.go b/modules/mesh-delivery-pipeline/internal/pipeline/start.go index 17168081..872ce5ac 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/start.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/start.go @@ -188,6 +188,10 @@ type Starter struct { // RunTurn places a run on request whose turn in the queue came, from its candidate's newest revision (A-222); nil places // it at the runner's next start. RunTurn func(UnplacedRun) + // Findings is the runner's finding writer, through which a mover waiting on its registration raises + // registration-missing (H-A-262); Observer is the runner's own module name. nil raises none. + Findings Findings + Observer string } // holderless ends at once, as it is placed, a pipeline with a build step whose seat the seat mesh-module-assigner's view @@ -528,6 +532,7 @@ func (s *Starter) Start(b Begin) (bool, error) { asks, unregistered, ended, notAsked = s.placeMovers(&p, s.Registration, b.Entries, now) for _, m := range unregistered { s.logf("%s: %s has no registration yet: its steps wait on its registration, which places them (A-327)", key, m) + s.registrationMissing(m, key) } } if err := s.create(key, p); err != nil { @@ -667,6 +672,7 @@ func (s *Starter) Registered(store Updater, reg catalog.Registration, view func( if reg.Module == "" { return 0, nil } + defer s.registrationArrived(reg.Module) // the finding of a mover that waited on it goes (H-A-262) return s.placeWaiting(store, func(p seat.Pipeline) bool { return Moves(p, reg.Module) && !placed(p, reg.Module) }, func(module string) (catalog.Registration, bool) { return reg, module == reg.Module }, view, "the registration of "+reg.Module+", which arrived after the pipeline started") @@ -680,6 +686,7 @@ func (s *Starter) Waiting(store Updater, branch string, view func(branch string) if s.Registration == nil { return 0, nil } + defer s.registrationsArrived() // the finding of a mover whose registration is held now goes (H-A-262) return s.placeWaiting(store, func(p seat.Pipeline) bool { if branch != "" && p.Branch != branch { return false @@ -732,6 +739,7 @@ func (s *Starter) placeWaiting(store Updater, due func(seat.Pipeline) bool, reg // and it holds the pipeline's end only while every placed mover's required steps passed (H-A-163, H-A-171). for _, m := range unregistered { s.logf("%s: %s has no registration yet: its steps wait on its registration, which places them (A-327)", key, m) + s.registrationMissing(m, key) } if len(p.Steps) == before { continue diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/start_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/start_test.go index d3f5700b..52a3a4d8 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/start_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/start_test.go @@ -203,6 +203,8 @@ func TestAPipelineStartedBeforeItsRegistrationIsPlacedWhenItArrives(t *testing.T var said []string s := &Starter{Pipelines: store, Steps: asks, Name: "the-runner", Say: func(subject string, _ any) error { said = append(said, subject); return nil }, Registration: func(m string) (catalog.Registration, bool) { return reg, registered && m == "app" }} + findings := newHeld() + s.Findings, s.Observer = findings, "the-runner" view := func(string) (Half, bool) { return Half{Entries: entries}, true } taken := catalog.TakeInTaken{Branch: "main", Source: 4, Entries: []catalog.TakeInEntry{{Module: "app", Commit: "c1", Fingerprint: "src2:aa"}}} if n, err := s.TakenIn(taken, view); n != 1 || err != nil { @@ -211,8 +213,15 @@ func TestAPipelineStartedBeforeItsRegistrationIsPlacedWhenItArrives(t *testing.T if p, _, _ := store.Get("main.4"); len(p.Steps) != 0 || len(asks.asks) != 0 { t.Fatalf("before its registration the pipeline has %d steps and %d asks, want none", len(p.Steps), len(asks.asks)) } + // H-A-262: the mover waiting on its registration is the finding registration-missing, scope module, id the module. + if f, ok := findings.held["module.app."+RegistrationMissingKind]; !ok || f.Observer != "the-runner" || !strings.Contains(f.Summary, "main.4") { + t.Fatalf("the mover waiting on its registration raised %v, want registration-missing of app naming main.4", findings.held) + } registered = true n, err := s.Registered(store.memStore, reg, view) + if _, ok := findings.held["module.app."+RegistrationMissingKind]; ok { + t.Errorf("the registration of app arrived and its registration-missing is still held") + } p, _, _ := store.Get("main.4") if n != 1 || err != nil || len(p.Steps) == 0 || len(asks.asks) == 0 || p.Outcome != seat.PipelineOutcomeRunning { t.Fatalf("the registration placed %d (%v): %d steps, %d asks, want the pipeline's steps placed and asked", n, err, len(p.Steps), len(asks.asks)) @@ -303,6 +312,17 @@ func TestAPipelineStartedBeforeItsRegistrationIsPlacedWhenItArrives(t *testing.T if !slices.ContainsFunc(logged, func(l string) bool { return strings.Contains(l, "next.8: contracts has no registration yet") }) { t.Errorf("placing next.8 said %q, want that contracts waits on its registration (A-327)", logged) } + // H-A-262: the mover still waiting is raised from the placing too, and cleared once the registrations held name it. + if _, ok := findings.held["module.contracts."+RegistrationMissingKind]; !ok { + t.Errorf("placing next.8 raised %v, want registration-missing of contracts", findings.held) + } + s.Registration = func(string) (catalog.Registration, bool) { return reg, true } + if _, err := s.Waiting(store.memStore, "", late); err != nil { + t.Fatal(err) + } + if _, ok := findings.held["module.contracts."+RegistrationMissingKind]; ok { + t.Errorf("the registrations held name contracts and its registration-missing is still held") + } } // R1/AC1 (design 47 H ยง747): a start names an event, never a sweep. A take-in starts the pipelines of its own entries