From b423f14c4c9eca42ecd6714c6d252bc3b4615417 Mon Sep 17 00:00:00 2001 From: jochen Date: Thu, 26 Nov 2026 02:33:37 +0100 Subject: [PATCH] mesh-delivery-pipeline: a predecessor a newer revision moved ties nothing in the carries, start, place and rerun (fix-770, issue 1984) main.530's mesh-delivery-builder failed at src2:0da7a2b0 and main.531 built it at src2:f28847e6, yet start's reopen of main.530 asked its build again and was refused whole, and the carry of revision 537 kept 21 movers tied to it. A mover of an ended pipeline that did not pass and whose head entry holds another fingerprint now counts as carried by the newer revision in every path that reads a closed group's ties or reopens a failed pipeline's group: the carry at a take-in and at a pipeline's end (read at the head's revision, the view's newest), start's reopen, runner_unfinished_place and a rerun's reopen. It ties nothing, goes in no group, leaves a reopened pipeline's movers, and is said naming both fingerprints and the revisions read, its unfinished key dropped where it names another fingerprint than the head's; the group goes on. Builds: design 47 H2 H-A-594 (2), (3), (4), H-A-759, H-A-761 --- .../cmd/mesh-delivery-pipeline/main.go | 3 + .../internal/pipeline/handplace.go | 64 ++++++-- .../internal/pipeline/repin_test.go | 141 ++++++++++++++++++ .../internal/pipeline/unfinished.go | 130 +++++++++++++--- .../internal/pipeline/verbs.go | 18 ++- 5 files changed, 329 insertions(+), 27 deletions(-) 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 1688b9b47..19f4342d1 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go @@ -297,6 +297,9 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro return kept } unfinished.Registered = func(module string) bool { _, ok := rv.Registrations.Registration(module); return ok } + // The head's revision, the newest the view holds (H-A-759): a mover a newer revision moved ties nothing at a pipeline's end + // (design 47 H2 H-A-594 (2), H-A-761). + unfinished.Head = rv.Catalog.View unfinished.Add = func(from seat.Pipeline, group []seat.Mover) (string, bool) { half, ok := rv.Catalog.View(from.Branch) if !ok { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/handplace.go b/modules/mesh-delivery-pipeline/internal/pipeline/handplace.go index a4a45a733..85d2afe9f 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/handplace.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/handplace.go @@ -3,6 +3,7 @@ package pipeline import ( "errors" "fmt" + "maps" "slices" "strings" @@ -62,6 +63,7 @@ func (v Verbs) Start(caller string, in seat.StartInput) (seat.StartAnswer, error return seat.StartAnswer{}, err } for _, o := range older { + s.passMovedOn(o.from, half.Revision, o.passed) if err := v.reopenGroup(caller, o.from, o.group, nil, o.entries, in.Why); err != nil { return seat.StartAnswer{}, err } @@ -125,12 +127,15 @@ func (v Verbs) startAtHead(caller string, in seat.StartInput, half Half, key str entries := half.Entries var group []string var add []seat.Mover + passed := map[string]movedMover{} for _, m := range movers { switch { case !Moves(head, m.Module): add = append(add, m) case len(failedSteps(head, m.Module)) > 0 || !allPassed(head, m.Module): - group = appendNew(group, v.closedGroup(head, m.Module, entries)...) + g, by := v.closedGroup(head, m.Module, entries) + group = appendNew(group, g...) + maps.Copy(passed, by) } } if len(group) == 0 && len(add) == 0 { @@ -139,6 +144,7 @@ func (v Verbs) startAtHead(caller string, in seat.StartInput, half Half, key str if err := v.record(seat.VerbStart, what, in.Why); err != nil { return seat.StartAnswer{}, err } + s.passMovedOn(head, half.Revision, passed) if err := v.reopenGroup(caller, head, group, add, entries, in.Why); err != nil { return seat.StartAnswer{}, err } @@ -151,6 +157,8 @@ type ownPipeline struct { from seat.Pipeline group []string entries map[string]catalog.CatalogEntry + // passed are the movers of from a newer revision moved that the group passes (design 47 H2 H-A-594 (2), H-A-761). + passed map[string]movedMover } func olderModules(o []ownPipeline) []string { @@ -210,10 +218,12 @@ func (v Verbs) ownFailedPipelines(branch, key string, movers []seat.Mover, headE at := slices.IndexFunc(out, func(o ownPipeline) bool { return o.from.Pipeline == best.Pipeline }) if at < 0 { // Its movers are read at the head's revision, whose entries are the newest (design 47 H2 H-A-763 (3)). - out = append(out, ownPipeline{from: best, entries: headEntries}) + out = append(out, ownPipeline{from: best, entries: headEntries, passed: map[string]movedMover{}}) at = len(out) - 1 } - out[at].group = appendNew(out[at].group, v.closedGroup(best, m.Module, out[at].entries)...) + g, by := v.closedGroup(best, m.Module, out[at].entries) + out[at].group = appendNew(out[at].group, g...) + maps.Copy(out[at].passed, by) } return out, rest, nil } @@ -244,10 +254,24 @@ func appendNew(into []string, add ...string) []string { // closedGroup is the group of movers of p that go with module: closed under the tier edges and under every awaited edge from a // mover that left unfinished or failed, so a mover goes only with every mover it has an edge from (design 47 H2 H-A-594 (2), -// H-A-646). A passed mover is never in it. -func (v Verbs) closedGroup(p seat.Pipeline, module string, entries map[string]catalog.CatalogEntry) []string { - left := unfinishedOf(p) - universe := appendNew(slices.Clone(left), failedMovers(p)...) +// H-A-646). A passed mover is never in it. entries are the head's revision's: a mover of p a newer revision moved, the head's +// entry holding another fingerprint than p's, counts as carried by that revision's pipeline and is in no group (H-A-594 (2), +// H-A-761); passed are those the group would hold otherwise, to be said and their keys dropped. +func (v Verbs) closedGroup(p seat.Pipeline, module string, entries map[string]catalog.CatalogEntry) (group []string, passed map[string]movedMover) { + moved := movedOn(p, entries) + delete(moved, module) + universe := appendNew(slices.Clone(unfinishedOf(p)), failedMovers(p)...) + passed = map[string]movedMover{} + for _, m := range closeOver(p, module, universe, entries) { + if mv, ok := moved[m]; ok { + passed[m] = mv + } + } + return closeOver(p, module, without(universe, moved), entries), passed +} + +// closeOver is module's group among universe, movers of p: closed under the tier edges and the awaited edges (closedGroup). +func closeOver(p seat.Pipeline, module string, universe []string, entries map[string]catalog.CatalogEntry) []string { group := []string{module} for changed := true; changed; { changed = false @@ -272,6 +296,23 @@ func (v Verbs) closedGroup(p seat.Pipeline, module string, entries map[string]ca return group } +// passMovedOn says each of moved, movers of p a newer revision moved, as carried by that revision's pipeline, naming both +// fingerprints and the revisions read (head, the head's revision), and drops its unfinished key where that names another +// fingerprint than the head's entry (design 47 H2 H-A-594 (2), H-A-761). +func (s *Starter) passMovedOn(p seat.Pipeline, head int64, moved map[string]movedMover) { + for _, m := range slices.Sorted(maps.Keys(moved)) { + why := movedWords(p, m, moved[m], head) + if s.Unfinished != nil { + k := UnfinishedKey(p.Branch, m) + if e, held, _ := s.Unfinished.Entry(k); held && e.Fingerprint != moved[m].Head { + s.Unfinished.dropMoved(k, m, e.Fingerprint, why) + continue + } + } + s.logf("%s", why) + } +} + // markCarriedKeys names carrier as the carrier of the unfinished keys of group's modules of p's branch. func (s *Starter) markCarriedKeys(p seat.Pipeline, group []string, carrier string) { if s.Unfinished != nil { @@ -364,6 +405,10 @@ type handPlan struct { movers []seat.Mover // entries are the entries a carry tiers its movers from. entries map[string]catalog.CatalogEntry + // passed are the movers of from a newer revision moved that the group passes, read at the head's revision head (design 47 H2 + // H-A-594 (2), H-A-761). + passed map[string]movedMover + head int64 } // planUnfinished is the group key belongs to (design 47 H2 H-A-607 (3)): refused, naming why, a key the state does not hold, one a @@ -408,9 +453,9 @@ func (v Verbs) planUnfinished(key string) (handPlan, error) { return handPlan{}, fmt.Errorf("%s at fingerprint %s is read at the head's revision %d of %s, which has no source", module, e.Fingerprint, head.Revision, branch) } half := head - group := v.closedGroup(from, module, half.Entries) + group, passed := v.closedGroup(from, module, half.Entries) from.Movers = slices.Clone(from.Movers) - plan := handPlan{from: from, group: group, entries: half.Entries} + plan := handPlan{from: from, group: group, entries: half.Entries, passed: passed, head: half.Revision} for _, g := range group { adoptHead(&from, g, half.Entries) // a mover joins the head at the head's commit (design 47 H2 H-A-769 (1), H-A-768) mv, _ := MoverOf(from, g) @@ -517,6 +562,7 @@ func (v Verbs) PlaceUnfinished(caller string, in seat.PlaceUnfinishedInput) (sea // otherwise by reopening the pipeline it left. It answers the pipeline that carries the group now. func (v Verbs) placeGroup(caller string, plan handPlan, why string) (string, error) { s := v.Starter + s.passMovedOn(plan.from, plan.head, plan.passed) failed := false for _, m := range plan.group { failed = failed || len(failedSteps(plan.from, m)) > 0 diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/repin_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/repin_test.go index ab1528795..c0e707b47 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/repin_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/repin_test.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "maps" "slices" "strings" "testing" @@ -521,6 +522,7 @@ func TestAMoverReopenedIsAskedWithTheHeadsPins(t *testing.T) { // design 47 H2 H-A-763 (3): the group a hand place or start's reopen closes is read over the head's entries, whose edges are the newest: // an edge the head's entry of lib has and its kept revision's has not puts app, which lib waits for, in the group. func TestAReopenedGroupIsClosedOverTheHeadsEdges(t *testing.T) { + t.Run("a predecessor a newer revision moved ties nothing", testAPredecessorANewerRevisionMovedTiesNothing) reg, entries := placeFixture() mk := func(module, fp string, edges []catalog.Edge) catalog.CatalogEntry { return catalog.CatalogEntry{Module: module, Fp: fp, Commit: "c1", Repository: "o/" + module, Path: "modules/" + module, Edges: edges, @@ -642,3 +644,142 @@ func TestAPlacedGroupJoinsTheHeadAtTheHeadsCommit(t *testing.T) { t.Errorf("no build was asked of the joined mover (asks %d)", len(asks.asks)) } } + +// design 47 H2 H-A-594 (2), (3), (4), H-A-761 (issue 1984; main.530's mesh-delivery-builder, failed at src2:0da7a2b0 and built at +// src2:f28847e6 in main.531, refused start's reopen of main.530 whole and tied 21 movers at the carry of revision 537): a predecessor +// whose head entry holds another fingerprint than its pipeline's counts as carried by the newer revision. In every path that reads a +// closed group's ties or reopens a failed pipeline's group it ties nothing, leaves the group, its key dropped and said naming both +// fingerprints and the revisions read; the group goes on. One row per path. +// testAPredecessorANewerRevisionMovedTiesNothing is a row of TestAReopenedGroupIsClosedOverTheHeadsEdges (the module's tests are +// folded under its budget). +func testAPredecessorANewerRevisionMovedTiesNothing(t *testing.T) { + saidOf := func(said []string) string { return strings.Join(said, "\n") } + namesBoth := func(j, module, pipeline, at, head string, rev int64) bool { + return strings.Contains(j, module+" of "+pipeline+" counts as carried by a newer revision") && strings.Contains(j, at) && + strings.Contains(j, fmt.Sprintf("head's revision %d", rev)) && strings.Contains(j, `at "`+head+`"`) + } + // The carries (Unfinished): main.5 ended failed, engine failed at f1, gitea left unfinished awaiting engine's package; stale left + // unfinished at f4. The head's revision 7 holds engine at f1b and stale at f4b, both moved by a newer revision. + failed := seat.Pipeline{Pipeline: "main.5", Branch: "main", Revision: 5, Outcome: seat.PipelineOutcomeFailed, + Movers: []seat.Mover{{Module: "engine", Fingerprint: "f1"}, {Module: "gitea", Fingerprint: "f2"}, {Module: "stale", Fingerprint: "f4"}}, + Steps: []seat.StepResult{{Module: "engine", Step: seat.StepResultStepUnit, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeFailed}, + {Module: "gitea", Step: seat.StepResultStepUnit, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeNotAsked}, + {Module: "stale", Step: seat.StepResultStepUnit, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeNotAsked}}} + edges := map[string]catalog.CatalogEntry{} + edgeInto(edges, "gitea", "engine", 1) + moved := map[string]catalog.CatalogEntry{"engine": {Commit: "c7", Fp: "f1b"}, "gitea": {Commit: "c7", Fp: "f2"}, "stale": {Commit: "c7", Fp: "f4b"}} + t.Run("the carry at a take-in", func(t *testing.T) { + for _, engine := range []string{"f1", "f1b"} { + var said []string + u := &Unfinished{Store: memUnfinished{"main.gitea": `{"fingerprint":"f2","revision":5,"pipeline":"main.5","outcome":"failed"}`}, + Logf: func(f string, a ...any) { said = append(said, fmt.Sprintf(f, a...)) }, + Entries: func(string, int64) (map[string]catalog.CatalogEntry, bool) { return edges, true }, + Pipeline: func(string) (seat.Pipeline, bool) { return failed, true }} + head := maps.Clone(moved) + head["engine"] = catalog.CatalogEntry{Commit: "c7", Fp: engine} + got := u.Carry("main", 7, head, nil) + if engine == "f1" { // the head holds engine at its failed fingerprint: gitea stays tied + if len(got) != 0 || !strings.Contains(saidOf(said), "tied to [engine]") { + t.Errorf("with engine at f1 the carry = %+v (said %q), want gitea tied to engine", got, said) + } + continue + } + if len(got) != 1 || got[0].Module != "gitea" || got[0].Fingerprint != "f2" || !namesBoth(saidOf(said), "engine", "main.5", "f1", "f1b", 7) { + t.Errorf("with engine moved to f1b the carry = %+v (said %q), want gitea carried and engine said with both fingerprints", got, said) + } + } + }) + t.Run("the carry at a pipeline's end", func(t *testing.T) { + var said []string + var added []string + st := memUnfinished{} + u := &Unfinished{Store: st, Logf: func(f string, a ...any) { said = append(said, fmt.Sprintf(f, a...)) }, + Entries: func(string, int64) (map[string]catalog.CatalogEntry, bool) { return edges, true }, + Head: func(string) (Half, bool) { return Half{Revision: 7, Source: 9, Entries: moved}, true }, + Add: func(_ seat.Pipeline, group []seat.Mover) (string, bool) { + added = append(added, moduleNames(group)...) + return "main.7", true + }} + u.Ended(failed) + if !slices.Equal(added, []string{"gitea"}) || st["main.stale"] != "" || !namesBoth(saidOf(said), "engine", "main.5", "f1", "f1b", 7) || + !namesBoth(saidOf(said), "stale", "main.5", "f4", "f4b", 7) { + t.Errorf("at main.5's end added %v, state %v, said %q: want gitea carried, stale not kept, engine and stale said", added, st, said) + } + }) + // The reopens (Verbs): main.10 moves app and lib at revision 10; the head's revision 13 holds lib at src2:b2, which a newer + // revision moved, and app's entry there awaits lib's package. + reg, entries := placeFixture() + mk := func(module, fp string, edges []catalog.Edge) catalog.CatalogEntry { + return catalog.CatalogEntry{Module: module, Fp: fp, Commit: "c1", Repository: "o/" + module, Path: "modules/" + module, Edges: edges, + Artifacts: []catalog.Artifact{{Ref: catalog.ArtifactRef(module + ":program"), Language: "go"}}} + } + kept := Half{Revision: 10, Source: 41, Entries: map[string]catalog.CatalogEntry{"app": mk("app", "src2:aa", nil), "lib": mk("lib", "src2:bb", nil), "mesh-build-go": entries["mesh-build-go"]}} + head := Half{Revision: 13, Source: 42, Entries: map[string]catalog.CatalogEntry{"app": mk("app", "src2:aa", []catalog.Edge{{From: "lib:program", Kind: 1}}), + "lib": mk("lib", "src2:b2", nil), "mesh-build-go": entries["mesh-build-go"]}} + for _, how := range []string{"start", "place-unfinished", "rerun"} { + t.Run(how, func(t *testing.T) { + store := &MoverStore{Raw: newMemRaw()} + asks := &stepAsks{} + u := memUnfinished{} + var said []string + logf := func(f string, a ...any) { said = append(said, fmt.Sprintf(f, a...)) } + s := &Starter{Pipelines: store, Store: store, Steps: asks, Name: "the-runner", Now: ticking(), Say: func(string, any) error { return nil }, Logf: logf, + Revision: func(string, int64) (Half, error) { return kept, nil }, + Registration: func(string) (catalog.Registration, bool) { return reg, true }, Unfinished: &Unfinished{Store: u, Logf: logf}} + key := Key("main", 10) + if ok, err := s.Start(Begin{Branch: "main", Source: 41, Revision: 10, Entries: kept.Entries, Movers: []seat.Mover{ + {Module: "app", Commit: "c1", Fingerprint: "src2:aa", Repository: "o/app"}, {Module: "lib", Commit: "c1", Fingerprint: "src2:bb", Repository: "o/lib"}}}); !ok || err != nil { + t.Fatalf("start = %v, %v", ok, err) + } + p, rev, _ := store.Get(key) + end := time.Unix(50, 0) + for i := range p.Steps { // lib's lint failed; app's failed too, or for place-unfinished never ran + switch st := &p.Steps[i]; { + case how == "place-unfinished" && st.Module == "app": + st.Outcome, st.Ask = seat.StepResultOutcomeNotAsked, "" + case st.Step == seat.StepResultStepLint && st.Artifact != "": + st.Outcome, st.Ended = seat.StepResultOutcomeFailed, &end + } + } + p.Outcome, p.Ended, p.EndCount = seat.PipelineOutcomeFailed, &end, 1 + if _, err := store.Update(key, p, rev); err != nil { + t.Fatal(err) + } + u["main.lib"] = `{"fingerprint":"src2:bb","revision":10,"pipeline":"` + key + `","outcome":"failed"}` + v := Verbs{Starter: s, Hearer: &Hearer{Store: store, Unfinished: s.Unfinished, Say: func(string, any) error { return nil }}, View: func(string) (Half, bool) { return head, true }, Acts: &actLog{}} + before := len(asks.asks) + var err error + switch how { + case "start": + _, err = v.Start("op@shanks", seat.StartInput{Branch: "main", Module: "app", Why: "again"}) + case "place-unfinished": + u["main.app"] = `{"fingerprint":"src2:aa","revision":10,"pipeline":"` + key + `","outcome":"failed"}` + var a seat.PlaceUnfinishedAnswer + if a, err = v.PlaceUnfinished("op@shanks", seat.PlaceUnfinishedInput{Key: "main.app", Why: "again"}); err == nil && + (len(a.Placed) != 1 || a.Placed[0] != (seat.PlaceUnfinishedAnswerPlacedItem{Key: "main.app", Pipeline: key})) { + t.Errorf("placed %+v, want main.app placed in %s", a, key) + } + default: + _, err = v.Rerun("op@shanks", seat.RerunInput{Pipeline: key, Module: "app", Step: seat.StepResultStepLint, Artifact: "app:program", Why: "again"}) + } + if err != nil { + t.Fatalf("%s is refused (%v), want the group to go on without lib", how, err) + } + var modules []string + for _, a := range asks.asks[before:] { + if b, ok := a.(nodebuildgo.StepAsk); ok && b.Step != nil && !slices.Contains(modules, b.Step.Module) { + modules = append(modules, b.Step.Module) + } + } + if !slices.Equal(modules, []string{"app"}) { + t.Errorf("asked steps of %v, want app's alone", modules) + } + if cur, _, _ := store.Get(key); Moves(cur, "lib") || !Moves(cur, "app") { + t.Errorf("%s moves %+v, want app and lib gone", key, cur.Movers) + } + if j := saidOf(said); !namesBoth(j, "lib", key, "src2:bb", "src2:b2", 13) || u["main.lib"] != "" { + t.Errorf("said %q, lib's key %q: want lib said with both fingerprints and its key dropped", said, u["main.lib"]) + } + }) + } +} diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/unfinished.go b/modules/mesh-delivery-pipeline/internal/pipeline/unfinished.go index f005998cb..95879a3a8 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/unfinished.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/unfinished.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "maps" "slices" "strconv" "strings" @@ -113,6 +114,43 @@ type Unfinished struct { // Kept reads a pipeline's kept-revisions, the revision each re-pinned mover's entry comes from (H-A-285); nil, or a pipeline // that keeps none, says the revision the key names (H-A-608). Kept func(pipeline string) map[string]int64 + // Head reads the head's revision of a branch, the newest its catalog view holds (H-A-759), whose entries say which movers a + // newer revision moved at a pipeline's end (design 47 H2 H-A-594 (2), H-A-761); nil reads none and passes no mover. + Head func(branch string) (Half, bool) +} + +// movedMover is a mover a newer revision moved: its fingerprint in the pipeline read, and the one the head's entry holds ("" for +// none). +type movedMover struct{ At, Head string } + +// movedOn are the movers of p it did not deliver, left unfinished or failed, whose module's entry in head, the head's revision's +// entries, does not hold p's fingerprint of them: a predecessor a newer revision moved counts as carried by that revision's +// pipeline, so it ties nothing and goes in no group (design 47 H2 H-A-594 (2)), and it goes on only at the fingerprint the head's +// entry holds (H-A-761). None when head is nil. +func movedOn(p seat.Pipeline, head map[string]catalog.CatalogEntry) map[string]movedMover { + if head == nil { + return nil + } + out := map[string]movedMover{} + for _, name := range appendNew(slices.Clone(unfinishedOf(p)), failedMovers(p)...) { + m, _ := MoverOf(p, name) + if e := head[name]; !slices.Contains(p.Superseded, name) && e.Fp != m.Fingerprint { + out[name] = movedMover{At: m.Fingerprint, Head: e.Fp} + } + } + return out +} + +// without is modules less every one of moved. +func without(modules []string, moved map[string]movedMover) []string { + return slices.DeleteFunc(slices.Clone(modules), func(m string) bool { _, ok := moved[m]; return ok }) +} + +// movedWords says that module of p, which a newer revision moved, ties nothing, naming both fingerprints and the revisions read +// (design 47 H2 H-A-594 (2), H-A-761). +func movedWords(p seat.Pipeline, module string, mv movedMover, head int64) string { + return fmt.Sprintf("%s of %s counts as carried by a newer revision: %s holds it at %s (revision %d) and the head's revision %d of %s at %q, so it ties nothing and goes in no group (H-A-594 (2), H-A-761)", + module, p.Pipeline, p.Pipeline, mv.At, p.Revision, head, p.Branch, mv.Head) } func (u *Unfinished) logf(format string, args ...any) { @@ -244,11 +282,29 @@ func (u *Unfinished) Ended(p seat.Pipeline) { return } left := unfinishedOf(p) + // A mover a newer revision moved is not kept unfinished, and a failed one a newer revision moved ties nothing (design 47 H2 + // H-A-594 (2), H-A-761). + var moved map[string]movedMover + var head Half + if len(left) > 0 && u.Head != nil { + if h, ok := u.Head(p.Branch); ok { + head, moved = h, movedOn(p, h.Entries) + } + } for _, m := range p.Movers { if slices.Contains(p.Superseded, m.Module) { continue } key := UnfinishedKey(p.Branch, m.Module) + if mv, ok := moved[m.Module]; ok && slices.Contains(left, m.Module) { + why := movedWords(p, m.Module, mv, head.Revision) + if e, held, _ := u.read(key); held && e.Fingerprint != mv.Head { + u.dropMoved(key, m.Module, e.Fingerprint, why) + continue + } + u.logf("%s ended %s and does not keep %s unfinished: %s", p.Pipeline, p.Outcome, m.Module, why) + continue + } if slices.Contains(left, m.Module) { raw, _ := json.Marshal(UnfinishedEntry{Fingerprint: m.Fingerprint, Revision: p.Revision, Pipeline: p.Pipeline, Outcome: p.Outcome, Widens: m.Widens}) if err := u.Store.Put(key, raw); err != nil { @@ -280,12 +336,14 @@ func (u *Unfinished) Ended(p seat.Pipeline) { } u.logf("%s ended %s: %s is no longer unfinished", p.Pipeline, p.Outcome, m.Module) } - u.carryAtEnd(p, left) + u.carryAtEnd(p, left, moved, head.Revision) } // carryAtEnd adds each closed group of the movers left to the head's pipeline (H-A-594 (2), (3), H-A-607 (2)), and names that -// pipeline as the carrier of each of its movers' keys. -func (u *Unfinished) carryAtEnd(p seat.Pipeline, left []string) { +// pipeline as the carrier of each of its movers' keys. A mover of p a newer revision moved (moved, read at the head's revision +// head) goes in no group, and a failed one ties nothing, said (design 47 H2 H-A-594 (2), H-A-761). +func (u *Unfinished) carryAtEnd(p seat.Pipeline, left []string, moved map[string]movedMover, head int64) { + left = without(left, moved) if len(left) == 0 || u.Add == nil || u.Entries == nil { return } @@ -294,7 +352,20 @@ func (u *Unfinished) carryAtEnd(p seat.Pipeline, left []string) { u.logf("%s: revision %d of %s is not read, so the movers it left are carried at the next take-in", p.Pipeline, p.Revision, p.Branch) return } - tied := tiedTo(p, left, failedMovers(p), entries) + failed := failedMovers(p) + tied := tiedTo(p, left, without(failed, moved), entries) + var passed []string + for _, by := range tiedTo(p, left, failed, entries) { + for _, f := range by { + if _, ok := moved[f]; ok && !slices.Contains(passed, f) { + passed = append(passed, f) + } + } + } + slices.Sort(passed) + for _, f := range passed { + u.logf("%s ended %s: %s", p.Pipeline, p.Outcome, movedWords(p, f, moved[f], head)) + } var free []string for _, m := range left { if len(tied[m]) == 0 { @@ -333,32 +404,42 @@ func (u *Unfinished) markCarried(branch string, modules []string, carrier string // heldBack are the failed modules a mover's key is tied to: the failed movers of its pipeline that the mover awaits at that // pipeline's revision, directly or through others, and that are registered still (H-A-610, H-A-646). None when the hooks that -// read them are not set. -func (u *Unfinished) heldBack(branch, module string, e UnfinishedEntry) []string { +// read them are not set. With head, the head's revision's entries, a mover of that pipeline a newer revision moved ties nothing +// (design 47 H2 H-A-594 (2), H-A-761): the failed ones it passes for that are answered in passed, with the pipeline read. +func (u *Unfinished) heldBack(branch, module string, e UnfinishedEntry, head map[string]catalog.CatalogEntry) (by []string, passed map[string]movedMover, from seat.Pipeline) { if u.Pipeline == nil || u.Entries == nil { - return nil + return nil, nil, seat.Pipeline{} } p, ok := u.Pipeline(e.Pipeline) if !ok { - return nil + return nil, nil, seat.Pipeline{} } entries, ok := u.Entries(branch, p.Revision) if !ok { - return nil + return nil, nil, seat.Pipeline{} } + moved := movedOn(p, head) var left []string for _, m := range p.Movers { if _, held, _ := u.read(UnfinishedKey(branch, m.Module)); held && !slices.Contains(failedMovers(p), m.Module) { left = append(left, m.Module) } } - var out []string - for _, f := range tiedTo(p, left, failedMovers(p), entries)[module] { - if u.Registered == nil || u.Registered(f) { - out = append(out, f) + registered := func(f string) bool { return u.Registered == nil || u.Registered(f) } + for _, f := range tiedTo(p, without(left, moved), without(failedMovers(p), moved), entries)[module] { + if registered(f) { + by = append(by, f) } } - return out + for _, f := range tiedTo(p, left, failedMovers(p), entries)[module] { + if mv, ok := moved[f]; ok && registered(f) { + if passed == nil { + passed = map[string]movedMover{} + } + passed[f] = mv + } + } + return by, passed, p } // HeldBehind are the modules whose unfinished key of branch is tied to module (H-A-625 (2)): the movers a failed module holds @@ -379,7 +460,11 @@ func (u *Unfinished) HeldBehind(branch, module string) []string { if err != nil { continue } - if e, held, _ := u.read(key); held && slices.Contains(u.heldBack(branch, m, e), module) { + e, held, _ := u.read(key) + if !held { + continue + } + if by, _, _ := u.heldBack(branch, m, e, nil); slices.Contains(by, module) { out = append(out, m) } } @@ -391,7 +476,8 @@ func (u *Unfinished) HeldBehind(branch, module string) []string { // moves at a newer fingerprint, or whose entry holds another fingerprint or none, has its key deleted; one it moves at its // own fingerprint is carried by the revision already. A key whose carrier waits or runs is skipped (H-A-594 (4)); one tied to // a failed mover the revision does not move is kept, tied, until that mover passes or leaves the registrations (H-A-594 (2), -// H-A-610). It answers movers with the added ones after them. +// H-A-610); a failed mover whose entry in entries holds another fingerprint than its pipeline's, which a newer revision moved, +// ties nothing, said (design 47 H2 H-A-594 (2), H-A-761). It answers movers with the added ones after them. func (u *Unfinished) Carry(branch string, revision int64, entries map[string]catalog.CatalogEntry, movers []seat.Mover) []seat.Mover { if u == nil { return movers @@ -402,6 +488,7 @@ func (u *Unfinished) Carry(branch string, revision int64, entries map[string]cat return movers } slices.Sort(ukeys) + var said []string for _, key := range ukeys { _, name, _ := strings.Cut(key, ".") module, err := keys.UnescapeName(name) @@ -429,7 +516,16 @@ func (u *Unfinished) Carry(branch string, revision int64, entries map[string]cat u.dropMoved(key, module, e.Fingerprint, why) continue } - if by := u.heldBack(branch, module, e); len(by) > 0 && !slices.ContainsFunc(by, func(f string) bool { + // A failed predecessor a newer revision moved, the head's entry holding another fingerprint than its pipeline's, ties nothing, + // said once (design 47 H2 H-A-594 (2), H-A-761). + by, passed, from := u.heldBack(branch, module, e, entries) + for _, f := range slices.Sorted(maps.Keys(passed)) { + if w := movedWords(from, f, passed[f], revision); !slices.Contains(said, w) { + said = append(said, w) + u.logf("revision %d of %s: %s", revision, branch, w) + } + } + if len(by) > 0 && !slices.ContainsFunc(by, func(f string) bool { return slices.ContainsFunc(movers, func(m seat.Mover) bool { return m.Module == f }) }) { u.logf("revision %d of %s does not carry %s: it is tied to %v, which it does not move (H-A-594 (2))", revision, branch, module, by) diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go b/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go index 89b49c5d1..9c370ea63 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go @@ -380,10 +380,12 @@ func (v Verbs) rerun(caller string, in seat.RerunInput, reopens bool) (seat.Reru var ask *Asked var replaced string var held []seat.StepResult + var moved map[string]movedMover + var head int64 p, _, err := v.change(in.Pipeline, seat.EventStepStarted, func() error { return v.record(seat.VerbRerun, fmt.Sprintf("asked the %s step of %s again", in.Step, in.Pipeline), in.Why) }, func(p *seat.Pipeline, now time.Time) (int, error) { - ask, replaced, held = nil, "", heldOf(*p) + ask, replaced, held, moved = nil, "", heldOf(*p), nil switch p.Outcome { case seat.PipelineOutcomeCancelled, seat.PipelineOutcomeSuperseded: return -1, fmt.Errorf("the pipeline %s is %s: a step of it is not asked again", p.Pipeline, p.Outcome) @@ -406,6 +408,17 @@ func (v Verbs) rerun(caller string, in seat.RerunInput, reopens bool) (seat.Reru return -1, err } } + // A rerun that reopens an ended delivering pipeline takes out of its movers each other mover a newer revision moved, the + // head's entry holding another fingerprint: it counts as carried by that revision's pipeline, so it ties nothing and none of + // the pipeline's later ends names it (design 47 H2 H-A-594 (2), (4), H-A-761). + if p.Ended != nil && p.Run == "" && v.View != nil { + if h, ok := v.View(p.Branch); ok { + if moved, head = movedOn(*p, h.Entries), h.Revision; moved != nil { + delete(moved, in.Module) + } + p.Movers = slices.DeleteFunc(slices.Clone(p.Movers), func(m seat.Mover) bool { _, ok := moved[m.Module]; return ok }) + } + } oldAsk := s.Ask replaced = oldAsk *s = seat.StepResult{Step: s.Step, Module: s.Module, Artifact: s.Artifact, Status: s.Status, Fingerprint: s.Fingerprint, Seat: s.Seat, @@ -433,6 +446,9 @@ func (v Verbs) rerun(caller string, in seat.RerunInput, reopens bool) (seat.Reru if err != nil { return seat.RerunAnswer{}, err } + if v.Starter != nil { + v.Starter.passMovedOn(p, head, moved) + } v.sayReopened(p, reopens) v.Hearer.sayHeldEnded(p, held, allHow(waitHowReleased)) // the rerun of a held step releases its wait (H-A-599) if ask == nil || replaced != ask.ID {