From 47f81051be43117b99e54d64a25cbf23aed863a1 Mon Sep 17 00:00:00 2001 From: jochen Date: Sat, 21 Nov 2026 17:47:54 +0100 Subject: [PATCH] Keep a same-source re-pin's mover in its pipeline and build it again there (H-A-283) A module importing packages its own pipeline releases was re-pinned at each publish; each re-pin revision of the same source took it out of the running pipeline, and each newer build withdrew the older reservation, so nothing ever published. A revision of the same source now moves no mover out of the open pipeline of that source: the pipeline keeps it at its new fingerprint, ends every step of it superseded (said at the old fingerprint, its asks dropped, its runs left) and places them again from the re-pin revision's entry under new asks, the build first, still naming the pipeline's revision. The revision the mover is kept at rides in the record's kept-revisions, beside the movers, where the pin check reads its entry. A revision whose every mover is kept starts no pipeline; one of a new source moves movers as before. Builds: design 47 H H-A-283, H-A-284, H-A-285 (with H-A-223, H-A-244, ADR 0682) --- .../cmd/mesh-delivery-pipeline/main.go | 1 + .../internal/pipeline/moverkeys.go | 73 ++++++ .../internal/pipeline/place.go | 45 ++-- .../internal/pipeline/repin.go | 214 ++++++++++++++++++ .../internal/pipeline/repin_test.go | 125 ++++++++++ .../internal/pipeline/start.go | 9 + .../internal/pipeline/start_test.go | 3 + .../internal/pipeline/supersede.go | 64 ++++-- 8 files changed, 499 insertions(+), 35 deletions(-) create mode 100644 modules/mesh-delivery-pipeline/internal/pipeline/repin.go create mode 100644 modules/mesh-delivery-pipeline/internal/pipeline/repin_test.go 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 f0e750ee..86cdfc35 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go @@ -177,6 +177,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro clock := askClock(ctx, bounds, askBound, silentBound, rv.Findings, cred.Module, time.Now) starter.Asks, hearer.Asks = clock, clock starter.Supersede = func(newer seat.Pipeline) { hearer.SupersedeRunning(newer) } + starter.Left = hearer.LeftInPlace // a same-source re-pin's superseded steps leave their runs (H-A-284) hearer.Unplaced = func(p seat.Pipeline, module string) string { return starter.Unplaced(p, module, rv.Catalog.View) } hearer.AskPinHeld = func(key, module string, pins map[string]string) { if _, err := starter.AskPinHeld(hearer.Store, key, module, pins, widener.Revision); err != nil { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/moverkeys.go b/modules/mesh-delivery-pipeline/internal/pipeline/moverkeys.go index bc21891e..ca162ce9 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/moverkeys.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/moverkeys.go @@ -288,6 +288,65 @@ func (s *MoverStore) Get(key string) (seat.Pipeline, uint64, error) { // when the record or a mover key was written since the read revision gave. A record carrying its steps inline has its // mover keys written before the record, so its steps are never lost between the two. func (s *MoverStore) Update(key string, p seat.Pipeline, revision uint64) (uint64, error) { + return s.update(key, p, revision, nil) +} + +// UpdateKept is Update with kept laid over the record's kept-revisions (H-A-285): the catalog revision each kept mover's +// fingerprint is from (H-A-283, H-A-284 (2)). +func (s *MoverStore) UpdateKept(key string, p seat.Pipeline, revision uint64, kept map[string]int64) (uint64, error) { + return s.update(key, p, revision, kept) +} + +// KeptRevisions are pipeline key's kept-revisions, the catalog revision each mover a same-source re-pin kept in it is from +// (H-A-283, H-A-284 (2), H-A-285); none for a pipeline that kept none. +func (s *MoverStore) KeptRevisions(key string) (map[string]int64, error) { + defer s.lock(key)() + raw, _, err := s.Raw.Get(key) + if err != nil { + return nil, err + } + if raw == nil { + return nil, fmt.Errorf("%w: %s", ErrNoPipeline, key) + } + return keptOf(raw) +} + +// keptRevisionsField is the pipeline record's property kept-revisions, beside its movers (H-A-285): written and read by the +// runner alone, never part of the seat's Go form of a pipeline, which drops it on every decode. +const keptRevisionsField = "kept-revisions" + +// keptOf is the kept-revisions a record carries; none when it carries none. +func keptOf(raw []byte) (map[string]int64, error) { + var fields map[string]json.RawMessage + if err := json.Unmarshal(raw, &fields); err != nil { + return nil, fmt.Errorf("the record is no object: %w", err) + } + f, ok := fields[keptRevisionsField] + if !ok { + return nil, nil + } + var kept map[string]int64 + if err := json.Unmarshal(f, &kept); err != nil { + return nil, fmt.Errorf("the record's %s is no map of module to revision: %w", keptRevisionsField, err) + } + return kept, nil +} + +// withKept is record with kept as its kept-revisions. +func withKept(record []byte, kept map[string]int64) ([]byte, error) { + var fields map[string]json.RawMessage + if err := json.Unmarshal(record, &fields); err != nil { + return nil, err + } + raw, err := json.Marshal(kept) + if err != nil { + return nil, err + } + fields[keptRevisionsField] = raw + return json.Marshal(fields) +} + +func (s *MoverStore) update(key string, p seat.Pipeline, revision uint64, kept map[string]int64) (uint64, error) { defer s.lock(key)() record, want, err := split(key, p) if err != nil { @@ -303,6 +362,20 @@ func (s *MoverStore) Update(key string, p seat.Pipeline, revision uint64) (uint6 if cur != revision { return 0, ErrChanged } + // The record's kept-revisions ride on through every write, kept laid over them (H-A-285). + merged, err := keptOf(raw) + if err != nil { + return 0, fmt.Errorf("the pipeline %s: %w", key, err) + } + if len(kept) > 0 && merged == nil { + merged = map[string]int64{} + } + maps.Copy(merged, kept) + if len(merged) > 0 { + if record, err = withKept(record, merged); err != nil { + return 0, err + } + } vals, revs, err := s.moverKeys(key) if err != nil { return 0, err diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/place.go b/modules/mesh-delivery-pipeline/internal/pipeline/place.go index ef891deb..c86938bd 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/place.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/place.go @@ -101,14 +101,7 @@ func place(p seat.Pipeline, m seat.Mover, reg catalog.Registration, entries map[ build := seat.StepResult{Step: seat.StepResultStepBuild, Module: m.Module, Status: seat.StepResultStatusRequired, Fingerprint: m.Fingerprint, Seat: builds.Seat, Outcome: seat.StepResultOutcomeRunning, Started: &now, Ask: AskID(startOf(p, now), p.Pipeline, m.Module, "", seat.StepResultStepBuild)} steps = append(steps, build) - // A run on request's build step ask names no source (the seat mesh-builds' contract; H-A-162): its candidate's - // fingerprints are never in the builder's picture of the branch, so it waits for no revision there. - source := p.Source - if p.Run != "" { - source = 0 - } - asks = append(asks, Asked{Seat: builds.Seat, ID: build.Ask, Commit: m.Commit, Ask: builds.StepRun{Pipeline: p.Pipeline, Step: builds.StepRunStepBuild, Branch: p.Branch, - Revision: p.Revision, Source: source, Entries: []builds.BuildEntry{{Module: m.Module, Commit: m.Commit, Fingerprint: m.Fingerprint}}}}) + asks = append(asks, buildAsk(p, m, build.Ask)) for _, a := range arts { name := a.Ref if _, after, ok := strings.Cut(a.Ref, ":"); ok { @@ -309,12 +302,13 @@ func (s *Starter) AskPinHeld(store Updater, key, module string, pins map[string] return 0, nil } var entry catalog.CatalogEntry - unread := "" - switch half, err := readRevision(revision, p.Branch, p.Revision); { + at, whose, unread := moverRevision(store, p, module) + switch half, err := readRevision(revision, p.Branch, at); { + case unread != "": case err != nil: - unread = fmt.Sprintf("revision %d of %s, the pipeline's, cannot be read for its entry: %v", p.Revision, p.Branch, err) + unread = fmt.Sprintf("revision %d of %s, %s, cannot be read for its entry: %v", at, p.Branch, whose, err) case half.Entries[module].Fp != m.Fingerprint: - unread = fmt.Sprintf("revision %d of %s holds %s at %q, not the mover's %s", p.Revision, p.Branch, module, half.Entries[module].Fp, m.Fingerprint) + unread = fmt.Sprintf("revision %d of %s holds %s at %q, not the mover's %s", at, p.Branch, module, half.Entries[module].Fp, m.Fingerprint) default: entry = half.Entries[module] } @@ -332,7 +326,7 @@ func (s *Starter) AskPinHeld(store Updater, key, module string, pins map[string] if unread != "" || j < 0 || err != nil { why := unread if why == "" { - why = fmt.Sprintf("revision %d of %s names no artifact %s of %s to ask it of", p.Revision, p.Branch, st.Artifact, module) + why = fmt.Sprintf("revision %d of %s names no artifact %s of %s to ask it of", at, p.Branch, st.Artifact, module) } st.Outcome, st.Ended = seat.StepResultOutcomeCouldNotRun, &now st.Why = "its build passed with its pins, but " + why + " (H-A-207, H-A-205)" @@ -363,6 +357,31 @@ func (s *Starter) AskPinHeld(store Updater, key, module string, pins map[string] } } +// keptRevisions is the state pipelines' kept-revisions (MoverStore, H-A-285): the catalog revision each mover a same-source +// re-pin kept in a pipeline is from (H-A-283, H-A-284 (2)). +type keptRevisions interface { + KeptRevisions(key string) (map[string]int64, error) + UpdateKept(key string, p seat.Pipeline, revision uint64, kept map[string]int64) (uint64, error) +} + +// moverRevision is the catalog revision mover module's entry of p is read at (H-A-284 (2)): the one its pipeline kept it at +// when a same-source re-pin kept it, else the pipeline's; whose says which, and unread why it is not read when its record +// cannot be. +func moverRevision(store Updater, p seat.Pipeline, module string) (int64, string, string) { + ks, ok := store.(keptRevisions) + if !ok { + return p.Revision, "the pipeline's", "" + } + kept, err := ks.KeptRevisions(p.Pipeline) + if err != nil { + return p.Revision, "the pipeline's", fmt.Sprintf("the revision %s was kept at in %s cannot be read: %v", module, p.Pipeline, err) + } + if r := kept[module]; r > 0 { + return r, "the one the pipeline kept " + module + " at (H-A-284)", "" + } + return p.Revision, "the pipeline's", "" +} + func stepAsk(p seat.Pipeline, m seat.Mover, e catalog.CatalogEntry, a catalog.Artifact, language, step, id, asker string, now time.Time) nodebuildgo.StepAsk { // A step is for its module alone (principle 10, A-447): the fetch always names the module's directory, and the // artifact's named paths in it when the entry has them. diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/repin.go b/modules/mesh-delivery-pipeline/internal/pipeline/repin.go new file mode 100644 index 00000000..1f79239e --- /dev/null +++ b/modules/mesh-delivery-pipeline/internal/pipeline/repin.go @@ -0,0 +1,214 @@ +package pipeline + +import ( + "errors" + "fmt" + "slices" + "strings" + "time" + + builds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds" + seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner" +) + +// keepSameSource keeps, in the open pipeline of the same source revision that holds it, each mover of the revision half a +// re-pin made (design 47 H H-A-283): a revision of the same source moves no mover out of a running or waiting pipeline (as +// H-A-223 and H-A-244 (1) move one for a revision of a new source); the pipeline keeps the mover and takes its new +// fingerprint, and the revision's own pipeline starts without it. It answers the movers no open pipeline of the source +// holds, which the revision's pipeline carries. +func (s *Starter) keepSameSource(branch string, half Half, movers []seat.Mover) []seat.Mover { + if s.Store == nil || len(movers) == 0 { + return movers + } + pkeys, err := branchKeys(s.Store, branch) + if err != nil { + s.logf("the pipelines of %s are not listed, so no open pipeline of source %d keeps the movers of revision %d: %v", branch, half.Source, half.Revision, err) + return movers + } + left := movers + for _, key := range pkeys { + if len(left) == 0 { + break + } + left = s.keepIn(key, half, left) + } + return left +} + +// holdsOpen says whether the pipeline p, not ended and of no run on request, is of revision half's source, older than it, and +// still holds mover module as its own. +func holdsOpen(p seat.Pipeline, half Half, module string) bool { + return (p.Outcome == seat.PipelineOutcomeRunning || p.Outcome == seat.PipelineOutcomeWaiting) && p.Run == "" && + p.Source == half.Source && p.Revision < half.Revision && Moves(p, module) && !slices.Contains(p.Superseded, module) +} + +// keepIn keeps in pipeline key each of movers it holds (H-A-283), answering the movers it does not hold. A kept mover whose +// fingerprint the re-pin moved takes its new fingerprint and commit, and the pipeline keeps the revision it is from in its +// kept-revisions (H-A-285); when its steps were placed, every one of them, open or ended, ends superseded and its steps are +// placed again from the revision's entry, the build first (H-A-284 (1)), each under an ask of its own (placed at this +// time), so no ask of the old fingerprint is kept for the new. One not placed yet is placed when it is due, as any mover. +func (s *Starter) keepIn(key string, half Half, movers []seat.Mover) []seat.Mover { + for { + p, rev, err := s.Store.Get(key) + if err != nil { + return movers + } + var kept, left []seat.Mover + for _, m := range movers { + if holdsOpen(p, half, m.Module) { + kept = append(kept, m) + } else { + left = append(left, m) + } + } + if len(kept) == 0 { + return movers + } + now := s.now() + why := fmt.Sprintf("superseded: the re-pin revision %d of the pipeline's own source %d moved its mover's fingerprint; its steps are placed again (H-A-283, H-A-284)", half.Revision, half.Source) + revisions := map[string]int64{} + olds := slices.Clone(p.Movers) // the superseded steps are said at the fingerprint they ran for + var moved, unregistered []string + var ended []seat.StepResult + var leave, drop []seat.StepResult + var asks []Asked + var notAsked []int + for _, m := range kept { + i := slices.IndexFunc(p.Movers, func(o seat.Mover) bool { return o.Module == m.Module }) + old := p.Movers[i] + if old.Fingerprint == m.Fingerprint && old.Commit == m.Commit { + continue + } + p.Movers[i].Fingerprint, p.Movers[i].Commit = m.Fingerprint, m.Commit + revisions[m.Module] = half.Revision + moved = append(moved, fmt.Sprintf("%s %s to %s", m.Module, old.Fingerprint, m.Fingerprint)) + if p.Outcome != seat.PipelineOutcomeRunning || !placed(p, m.Module) { + continue + } + rest := make([]seat.StepResult, 0, len(p.Steps)) + for _, st := range p.Steps { + if st.Module != m.Module { + rest = append(rest, st) + continue + } + live := open(st) || st.Outcome == seat.StepResultOutcomeWaiting + l, d := supersedeStep(&p, &st, why, now) + if live { + leave, drop = append(leave, l...), append(drop, d...) + } + ended = append(ended, st) + } + p.Steps = rest + a, n, unreg := s.placeAgain(&p, p.Movers[i], half, now) + asks, notAsked = append(asks, a...), append(notAsked, n...) + if unreg { + unregistered = append(unregistered, m.Module) + } + } + if len(moved) == 0 { + s.logf("%s keeps %d movers of revision %d, of its own source %d, at the fingerprints it holds (H-A-283)", key, len(kept), half.Revision, half.Source) + return left + } + var holderEnded []int + if len(asks) > 0 { + asks, holderEnded = s.holderless(&p, asks, now) + } + ks, keeps := s.Store.(keptRevisions) + if keeps { + _, err = ks.UpdateKept(key, p, rev, revisions) + } else { + _, err = s.Store.Update(key, p, rev) + } + if errors.Is(err, ErrChanged) { + continue + } else if err != nil { + s.logf("%s is not written, so the movers revision %d re-pinned stay its own at their old fingerprints: %v", key, half.Revision, err) + return left + } + if !keeps { + s.logf("%s keeps no kept-revisions, so the pin check of its re-pinned movers reads the pipeline's revision (H-A-285)", key) + } + s.logf("%s keeps the movers revision %d of its own source %d re-pinned, %s: %d steps ended superseded, %d asked again (H-A-283, H-A-284)", + key, half.Revision, half.Source, strings.Join(moved, ", "), len(ended), len(asks)) + for _, st := range ended { + if s.Say == nil { + break + } + was := p + was.Movers = olds + if err := s.Say(stepEvent(seat.EventStepEnded, was, st, now)); err != nil { + s.logf("step-ended of %s's %s %s, superseded, is not said: %v", key, st.Module, st.Step, err) + } + } + if s.Left != nil { + s.Left(key, leave, drop, why) + } + 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) + } + s.sayNotAsked(p, notAsked) + if len(holderEnded) > 0 { + if err := s.endedAtPlacing(p, holderEnded); err != nil { + s.logf("%v", err) + } + return left + } + if s.Steps != nil && len(asks) > 0 { + if err := s.askSteps(key, asks); err != nil { + s.logf("%s: the steps placed again are not all put, they are asked at the next start: %v", key, err) + } + } + return left + } +} + +// placeAgain places the steps of kept mover m of p from the re-pin revision half's entry (H-A-284 (1)), as a mover is placed +// (placeMovers), under asks of this placing's time: it answers the asks to put, the steps placed not asked because a +// dependency did not build, and whether m has no registration. A mover not due yet (it waits on a publish) is left +// unplaced, placed when the publish is heard. +func (s *Starter) placeAgain(p *seat.Pipeline, m seat.Mover, half Half, now time.Time) ([]Asked, []int, bool) { + if s.Registration == nil { + return nil, nil, false + } + r, ok := s.Registration(m.Module) + if !ok { + return nil, nil, true + } + due, waiting, failed := ready(*p, m.Module, half.Entries) + if !due && failed == "" { + s.logf("%s: %s waits for %s before its build", p.Pipeline, m.Module, strings.Join(waiting, ", ")) + return nil, nil, false + } + at := *p + at.Started = &now + steps, asks := Place(at, m, r, half.Entries, now, s.Name) + supersededWhy(*p, m.Module, half.Entries, steps) + var notAsked []int + if failed != "" { + why := "its dependency " + failed + " did not build" + for k := range steps { + st := &steps[k] + if st.Outcome == seat.StepResultOutcomeBypassed { + continue + } + st.Outcome, st.Why, st.Ask, st.Shared, st.Ended = seat.StepResultOutcomeNotAsked, why, "", nil, &now + p.Unlogged = append(p.Unlogged, endEntry(p.Pipeline, *st, now)) + notAsked = append(notAsked, len(p.Steps)+k) + } + asks = nil + } + p.Steps = append(p.Steps, steps...) + return asks, notAsked, false +} + +// buildAsk is mover m's build step ask under id, of the seat mesh-builds for the mover's own entry only (A-99, A-97): a run on +// request's names no source (H-A-162). +func buildAsk(p seat.Pipeline, m seat.Mover, id string) Asked { + source := p.Source + if p.Run != "" { + source = 0 + } + return Asked{Seat: builds.Seat, ID: id, Commit: m.Commit, Ask: builds.StepRun{Pipeline: p.Pipeline, Step: builds.StepRunStepBuild, Branch: p.Branch, + Revision: p.Revision, Source: source, Entries: []builds.BuildEntry{{Module: m.Module, Commit: m.Commit, Fingerprint: m.Fingerprint}}}} +} diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/repin_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/repin_test.go new file mode 100644 index 00000000..f3f3946e --- /dev/null +++ b/modules/mesh-delivery-pipeline/internal/pipeline/repin_test.go @@ -0,0 +1,125 @@ +package pipeline + +import ( + "fmt" + "slices" + "testing" + + builds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds" + catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" + seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner" + nodebuildgo "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo" + "git.novox.be/novox/mesh-sdk/go/keys" +) + +// H-A-283, H-A-284, H-A-285: a re-pin revision of the same source moves no mover out of the running pipeline of that source: +// the pipeline keeps it at its new fingerprint, every step of it ends superseded (said at the old fingerprint, its asks +// dropped) and is placed again from the re-pin revision's entry under new asks, the build first, still naming the +// pipeline's revision; the revision the mover is kept at rides in the record's kept-revisions, where the pin check reads +// its entry; the re-pin starts no pipeline. A revision of a new source still starts its own and moves the mover out. +func TestASameSourceRepinKeepsTheMoverInItsPipeline(t *testing.T) { + reg, entries := placeFixture() + repinned := map[string]catalog.CatalogEntry{} + for k, e := range entries { + repinned[k] = e + } + app := entries["app"] + app.Fp = "src2:aa" + entries["app"] = app + re := app + re.Fp, re.Packages = "src2:ab", map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.26", "git.novox.be/novox/x/go": ""} + repinned["app"] = re + store := &MoverStore{Raw: newMemRaw()} + asks := &stepAsks{} + var said []seat.StepEvent + var left [][]seat.StepResult + s := &Starter{Pipelines: store, Store: store, Steps: asks, Name: "the-runner", + Registration: func(m string) (catalog.Registration, bool) { return reg, m == "app" }, + Say: func(_ string, body any) error { + if ev, ok := body.(seat.StepEvent); ok && ev.Result.Outcome == seat.StepResultOutcomeSuperseded { + said = append(said, ev) + } + return nil + }, + Left: func(_ string, leave, drop []seat.StepResult, _ string) { left = append(left, append(leave, drop...)) }} + h := &Hearer{Store: store, Say: func(string, any) error { return nil }} + s.Supersede = func(newer seat.Pipeline) { h.SupersedeRunning(newer) } + key := Key("main", 10) + if ok, err := s.Start(Begin{Branch: "main", Source: 41, Revision: 10, Entries: entries, + Movers: []seat.Mover{{Module: "app", Commit: "c1", Fingerprint: "src2:aa", Repository: "o/app"}}}); !ok || err != nil { + t.Fatalf("start = %v, %v", ok, err) + } + before, _, _ := store.Get(key) + oldAsks := map[string]bool{} + for _, st := range before.Steps { + if st.Ask != "" { + oldAsks[st.Ask] = true + } + } + asks.at, asks.ids, asks.asks = nil, nil, nil + read := func(branch string, revision int64) (Half, error) { + switch revision { + case 10: + return Half{Revision: 10, Source: 41, Entries: entries}, nil + case 11: + return Half{Revision: 11, Source: 41, Entries: repinned, Call: "release of mesh-sdk 0.1.26", + Movers: []catalog.TakeInEntry{{Module: "app", Commit: "c1", Fingerprint: "src2:ab", Repository: "o/app"}}}, nil + case 12: + return Half{Revision: 12, Source: 42, Entries: repinned, Call: "take-in of 42", + Movers: []catalog.TakeInEntry{{Module: "app", Commit: "c2", Fingerprint: "src2:ac", Repository: "o/app"}}}, nil + } + return Half{}, fmt.Errorf("no revision %d", revision) + } + ev := func(n int64) catalog.CatalogRevisionEvent { + return catalog.CatalogRevisionEvent{Kind: "trunk", Branch: keys.EscapeName("main"), Revision: n, CallKind: "release"} + } + if n, err := s.Revised(ev(11), read); n != 0 || err != nil { + t.Fatalf("the same-source re-pin started %d pipelines (%v), want none", n, err) + } + if _, _, err := store.Get(Key("main", 11)); err == nil { + t.Fatal("the same-source re-pin wrote a pipeline of its own") + } + p, _, err := store.Get(key) + if err != nil { + t.Fatal(err) + } + if m, _ := MoverOf(p, "app"); m.Fingerprint != "src2:ab" || slices.Contains(p.Superseded, "app") || p.Outcome != seat.PipelineOutcomeRunning { + t.Fatalf("the kept mover = %+v, superseded %v, outcome %s: want it kept at src2:ab, the pipeline running", m, p.Superseded, p.Outcome) + } + if len(p.Steps) != len(before.Steps) || p.Steps[0].Step != seat.StepResultStepBuild || p.Steps[0].Outcome != seat.StepResultOutcomeRunning || + p.Steps[0].Fingerprint != "src2:ab" || oldAsks[p.Steps[0].Ask] { + t.Fatalf("the steps placed again = %+v, want the build first, running at src2:ab under a new ask", p.Steps) + } + for _, st := range p.Steps { + if st.Outcome == seat.StepResultOutcomeSuperseded || (st.Ask != "" && oldAsks[st.Ask]) { + t.Errorf("the step %s %s stands for the old fingerprint: %+v", st.Artifact, st.Step, st) + } + } + // Every old step ended superseded, said at the fingerprint it ran for; the ones open on a build node are dropped. + if len(said) != len(before.Steps) || said[0].Fingerprint != "src2:aa" || len(left) != 1 || len(left[0]) == 0 { + t.Errorf("said %d superseded steps (of %d), the first at %+v; left %v", len(said), len(before.Steps), said, left) + } + b, ok := asks.asks[0].(builds.StepRun) + if !ok || asks.ids[0] != p.Steps[0].Ask || b.Revision != 10 || b.Source != 41 || len(b.Entries) != 1 || b.Entries[0].Fingerprint != "src2:ab" { + t.Fatalf("the build asked again = %+v (%s), want the new fingerprint at the pipeline's revision", asks.asks[0], asks.ids[0]) + } + if kept, err := store.KeptRevisions(key); err != nil || kept["app"] != 11 { + t.Errorf("kept-revisions = %v (%v), want app at 11", kept, err) + } + // The pin check reads the kept mover's entry at the revision it was kept at, never the pipeline's. + if n, err := s.AskPinHeld(store, key, "app", map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.26", "git.novox.be/novox/x/go": "v0.1.1"}, read); n == 0 || err != nil { + after, _, _ := store.Get(key) + t.Fatalf("the held steps asked %d (%v): %+v", n, err, after.Steps) + } + last := asks.asks[len(asks.asks)-1].(nodebuildgo.StepAsk) + if last.Step.Fingerprint != "src2:ab" || last.Step.Fetch.Packages["git.novox.be/novox/x/go"] != "v0.1.1" { + t.Errorf("a held step asked = %+v", last.Step) + } + // A revision of a new source starts its own pipeline and moves the mover out (H-A-223). + if n, err := s.Revised(ev(12), read); n != 1 || err != nil { + t.Fatalf("a new source's revision started %d (%v)", n, err) + } + if p, _, _ := store.Get(key); !slices.Contains(p.Superseded, "app") { + t.Errorf("the new source's revision left app in %s: %v", key, p.Superseded) + } +} diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/start.go b/modules/mesh-delivery-pipeline/internal/pipeline/start.go index 057ee319..ef84a808 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/start.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/start.go @@ -165,6 +165,9 @@ type Starter struct { // Supersede takes out of every older running pipeline of newer's branch each mover whose fingerprint newer moved // (H-A-223; Hearer.SupersedeRunning); nil leaves running pipelines as they are. Supersede func(newer seat.Pipeline) + // Left takes the steps a same-source re-pin superseded in a pipeline that kept their mover out of the test runs they + // read and drops their own asks (H-A-283, H-A-284 (1); Hearer.LeftInPlace); nil leaves them. + Left func(key string, leave, drop []seat.StepResult, why string) // Fills refuses a start while a store of the runner is full (§366); nil refuses none. Fills *Fills // Recovered says whether a commit is named a recovery (§81, §86): its steps are asked on the build seats' stream delivery. @@ -1023,6 +1026,12 @@ func (s *Starter) Revised(ev catalog.CatalogRevisionEvent, read func(branch stri for _, e := range half.Movers { movers = append(movers, seat.Mover{Module: e.Module, Commit: e.Commit, Fingerprint: e.Fingerprint, Repository: e.Repository}) } + // A revision of the same source moves no mover out of the open pipeline of that source holding it: that pipeline keeps + // it, and this revision starts no pipeline of its own for it (H-A-283); only a revision of a new source moves movers. + if movers = s.keepSameSource(branch, half, movers); len(movers) == 0 { + s.logf("the revision %d of %s (%s) moves only movers the open pipelines of its source %d keep: it starts no pipeline (H-A-283)", ev.Revision, branch, ev.Call, half.Source) + return 0, nil + } movers = Tiers(movers, half.Entries, s.logf) call := half.Call if call == "" { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/start_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/start_test.go index 61255668..ac547827 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/start_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/start_test.go @@ -88,6 +88,9 @@ func TestARevisionOfAReleaseStartsOnePipeline(t *testing.T) { return Half{}, fmt.Errorf("branch %q", branch) } r := Half{Revision: revision, Source: 41, Entries: entries, Call: "release of mesh-sdk 0.1.17"} + if revision > 10 { + r.Source = 41 + revision // a later source's revision: one of the same source keeps its movers in 10's (H-A-283) + } if revision != 12 { r.Movers = movers } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/supersede.go b/modules/mesh-delivery-pipeline/internal/pipeline/supersede.go index 0f2340ad..40402f69 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/supersede.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/supersede.go @@ -118,14 +118,8 @@ func (h *Hearer) supersedeRunningOne(key string, newer seat.Pipeline) bool { if !slices.Contains(moved, st.Module) || (!open(*st) && st.Outcome != seat.StepResultOutcomeWaiting) { continue } - switch { - case sharedRun(*st) != "" && st.Seat != wants.Seat: - leave = append(leave, *st) - case st.Ask != "" && BoundSeat(st.Seat): - drop = append(drop, *st) // its own ask on a build node: the seat's drop cancels it - } - st.Outcome, st.Why, st.Ended = seat.StepResultOutcomeSuperseded, why, &now - p.Unlogged = append(p.Unlogged, endEntry(key, *st, now)) + l, d := supersedeStep(&p, st, why, now) + leave, drop = append(leave, l...), append(drop, d...) ended = append(ended, i) } p.Superseded = append(p.Superseded, moved...) @@ -142,20 +136,7 @@ func (h *Hearer) supersedeRunningOne(key string, newer seat.Pipeline) bool { h.logf("step-ended of %s's %s %s, superseded, is not said: %v", key, p.Steps[i].Module, p.Steps[i].Step, err) } } - for _, st := range leave { - h.leaveRun(key, st, "the mover "+st.Module+" left "+key+" for the newer "+newer.Pipeline) - } - // Its running asks on the build nodes are cancelled through the seat's drop (H-A-223). The seat mesh-builds serves no - // drop, so a build ask there runs to its end, which the runner ignores: the step is no longer open. - for _, st := range drop { - if h.DropRun == nil { - h.logf("%s: the ask %s of %s's %s is not dropped: the runner has no drop", key, st.Ask, st.Module, st.Step) - continue - } - if err := h.DropRun(st.Seat, st.Node, st.Ask, why); err != nil { - h.logf("%s: the drop of the ask %s of %s's %s is not asked of %s: %v", key, st.Ask, st.Module, st.Step, st.Seat, err) - } - } + h.leaveSteps(key, leave, drop, "the mover %s left "+key+" for the newer "+newer.Pipeline, why) if err := h.said(p, nil, done); err != nil { h.logf("%v", err) } @@ -164,6 +145,45 @@ func (h *Hearer) supersedeRunningOne(key string, newer seat.Pipeline) bool { } } +// supersedeStep ends the open or waiting step st of p superseded, naming why, with its step log entry: a step reading a test +// run is answered to leave it, and one with its own ask on a build node to drop it (H-A-223). +func supersedeStep(p *seat.Pipeline, st *seat.StepResult, why string, now time.Time) (leave, drop []seat.StepResult) { + switch { + case sharedRun(*st) != "" && st.Seat != wants.Seat: + leave = append(leave, *st) + case st.Ask != "" && BoundSeat(st.Seat): + drop = append(drop, *st) // its own ask on a build node: the seat's drop cancels it + } + st.Outcome, st.Why, st.Ended = seat.StepResultOutcomeSuperseded, why, &now + p.Unlogged = append(p.Unlogged, endEntry(p.Pipeline, *st, now)) + return leave, drop +} + +// leaveSteps takes the superseded steps of pipeline key out of the test runs they read (leaving, its %s the step's mover) +// and drops their own asks on the build nodes, naming why (H-A-223). The seat mesh-builds serves no drop, so a build ask +// there runs to its end, which the runner ignores: the step is no longer open. +func (h *Hearer) leaveSteps(key string, leave, drop []seat.StepResult, leaving, why string) { + for _, st := range leave { + h.leaveRun(key, st, fmt.Sprintf(leaving, st.Module)) + } + for _, st := range drop { + if h.DropRun == nil { + h.logf("%s: the ask %s of %s's %s is not dropped: the runner has no drop", key, st.Ask, st.Module, st.Step) + continue + } + if err := h.DropRun(st.Seat, st.Node, st.Ask, why); err != nil { + h.logf("%s: the drop of the ask %s of %s's %s is not asked of %s: %v", key, st.Ask, st.Module, st.Step, st.Seat, err) + } + } +} + +// LeftInPlace takes the steps a same-source re-pin superseded in pipeline key, whose mover it kept (H-A-283, H-A-284 (1)), +// out of the test runs they read and drops their own asks, naming why, and appends their step log entries. +func (h *Hearer) LeftInPlace(key string, leave, drop []seat.StepResult, why string) { + h.leaveSteps(key, leave, drop, "the mover %s of "+key+" was re-pinned and its steps placed again (H-A-284)", why) + h.appendUnlogged(key) +} + // supersedeWaiting takes, in each older waiting pipeline of newer's branch, the movers newer also moves out of it (design 47 H // §748, ADR 0682 §7): a waiting pipeline left with no mover ends superseded, its waiting key deleted, saying wait-ended and its // pipeline-ended. newer is a pipeline just written, waiting or placed: a mover a newer revision moves leaves every pipeline not