From 2dc707782f06f30e0964db4eeb28deaa34c75e35 Mon Sep 17 00:00:00 2001 From: jochen Date: Thu, 26 Nov 2026 20:11:05 +0100 Subject: [PATCH] mesh-delivery-builder: a published version the catalog holds no release of is version-unreleased past its bound (H-A-773 (2); issues 1984, 1423) A build whose every artifact was published but whose release the indexer lost raised nothing, so the lost release was never said. Past the same bound as an unpublished one, the reservations' arm (at a look or the start) and the bound's end now ask the catalog's verb versions, and raise version-unreleased, its words saying every artifact is published and its release was lost; one whose versions cannot be read is raised too, saying so. Its version-released clears it, as before. Reserver.Overdue lists such a version, so builder_publish_again with neither module nor version says it again. Issue 1984 note 8's two rows (1984/AC5) now expect the finding and its clearing. Builds: design 47 H2 H-A-773 (2), (5), (6), (7) --- .../cmd/mesh-delivery-builder/reserve.go | 36 ++++++++++--- .../cmd/mesh-delivery-builder/reserve_test.go | 51 +++++++++++++++---- .../internal/versions/republish_test.go | 9 ++++ .../internal/versions/reserve.go | 34 ++++++++++++- .../internal/versions/reserve_test.go | 27 ++++++++++ 5 files changed, 139 insertions(+), 18 deletions(-) diff --git a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/reserve.go b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/reserve.go index 4bdacfacb..fe0d7d505 100644 --- a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/reserve.go +++ b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/reserve.go @@ -271,13 +271,17 @@ func (rv *reservations) now() time.Time { // arm arms a built reservation's publish's bound, a key of the state bounds with its own time to live, counted from its build's // end (BuiltAt): its end with the reservation standing is version-unreleased. One armed already stands; at a look or the start // after the bound passed, a reservation left with an artifact unpublished is version-unreleased at once (lapsed), and its bound -// is not armed again (issue 1984 note 8, 1984/AC5); one with every artifact published waits for its version-released. +// is not armed again (issue 1984 note 8, 1984/AC5); one with every artifact published is version-unreleased at once too when the +// catalog's versions hold no release of it or cannot be read, even when its package-published were said a moment before, and its +// version-released clears it (design 47 H2 H-A-773 (2), (5), (7)). func (rv *reservations) arm(ctx context.Context, v versions.ReservedVersion) { ends := v.BuiltAt.Add(rv.bound) left := ends.Sub(rv.now()) if left <= 0 { if len(v.Missing()) > 0 { rv.lapsed(ctx, v, fmt.Sprintf("nothing within %s of its build", rv.bound)) + } else { + rv.lostRelease(ctx, v, fmt.Sprintf("within %s of its build", rv.bound)) } return } @@ -306,10 +310,24 @@ func (rv *reservations) lapsed(ctx context.Context, v versions.ReservedVersion, rv.unreleased(ctx, v, why) } -// unreleased raises version-unreleased about the module, naming the version and the artifacts missing. +// lostRelease raises version-unreleased for a built reservation past its bound with every artifact published whose version the +// catalog's verb versions does not hold, its release lost, and for one whose versions cannot be read, saying so (design 47 H2 +// H-A-773 (2), (5), (6)); a standing one keeps its words (lapsed). within says the bound. +func (rv *reservations) lostRelease(ctx context.Context, v versions.ReservedVersion, within string) { + lost, err := rv.r.ReleaseLost(ctx, v) + switch { + case err != nil: + rv.lapsed(ctx, v, fmt.Sprintf("the catalog's versions could not be read %s to say whether it is released: %v", within, err)) + case lost: + rv.lapsed(ctx, v, "the catalog holds no release of it "+within+": its release was lost") + } +} + +// unreleased raises version-unreleased about the module, naming the version and the artifacts missing, or that every artifact is +// published (H-A-773 (2)). func (rv *reservations) unreleased(ctx context.Context, v versions.ReservedVersion, why string) { missing := v.Missing() - what := "an artifact is unpublished" + what := "every artifact is published" if len(missing) > 0 { what = strings.Join(missing, ", ") + " unpublished" } @@ -318,7 +336,7 @@ func (rv *reservations) unreleased(ctx context.Context, v versions.ReservedVersi headline: "A built version is not released", explanation: "The builder reserved " + v.Module + " " + v.Version + " and its build ended, and the catalog has not said version-released: " + what + ".", resolved: "The catalog says version-released for " + v.Module + " " + v.Version + ".", - needs: "builder_reserved shows the reservation; builder_publish_again publishes the missing artifacts under it; builder_reserved_drop drops it."}) + needs: "builder_reserved shows the reservation; builder_publish_again publishes the missing artifacts under it, or says a published one's package-published again; builder_reserved_drop drops it."}) } // unreleasedWords raises version-unreleased about a version with the words of a publish again that ended badly. @@ -328,8 +346,8 @@ func (rv *reservations) unreleasedWords(ctx context.Context, v versions.Reserved // ended is told each change of the state bounds: a reservation's bound whose time ended raises version-unreleased while // the reservation stands built with an artifact unpublished (lapsed: a standing one keeps its words); one with every artifact -// published is not left unmarked (issue 1984 note 8, 1984/AC5) and waits for its version-released, as arm leaves it past the -// bound. +// published is not left unmarked (issue 1984 note 8, 1984/AC5), and raises it when the catalog's versions hold no release of it, +// its release lost, or cannot be read (design 47 H2 H-A-773 (2), (5), (6)). func (rv *reservations) ended(ctx context.Context, e jetstream.KeyValueEntry) bool { key, ok := versions.ReservedBoundOf(e.Key()) if !ok { @@ -339,7 +357,11 @@ func (rv *reservations) ended(ctx context.Context, e jetstream.KeyValueEntry) bo return true } v, found, err := rv.r.At(ctx, key) - if err != nil || !found || v.BuiltAt.IsZero() || len(v.Missing()) == 0 { + if err != nil || !found || v.BuiltAt.IsZero() { + return true + } + if len(v.Missing()) == 0 { + rv.lostRelease(ctx, v, fmt.Sprintf("within %s of its build", rv.bound)) return true } rv.lapsed(ctx, v, fmt.Sprintf("nothing within %s of its build", rv.bound)) diff --git a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/reserve_test.go b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/reserve_test.go index 3c765dbed..70c604f82 100644 --- a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/reserve_test.go +++ b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/reserve_test.go @@ -3,6 +3,7 @@ package main import ( "context" "encoding/json" + "errors" "fmt" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds" "slices" @@ -441,10 +442,22 @@ func TestABuildsDigestsAreRecordedInOneWrite(t *testing.T) { func TestABuiltReservationIsTakenInFromItsState(t *testing.T) { ctx := context.Background() store := &memReserve{vals: map[string][]byte{}, revs: map[string]uint64{}} - none := func(string, any) (json.RawMessage, error) { return json.Marshal(meshcatalog.VersionsAnswer{}) } + // The catalog's verb versions holds held released, or fails with versionsErr (design 47 H2 H-A-773 (2), (5)). + var held []string + var versionsErr error + catalog := func(string, any) (json.RawMessage, error) { + if versionsErr != nil { + return nil, versionsErr + } + a := meshcatalog.VersionsAnswer{} + for _, v := range held { + a.Versions = append(a.Versions, meshcatalog.VersionEntry{Version: v}) + } + return json.Marshal(a) + } fs := &memFindings{vals: map[string][]byte{}} bounds := &boundsKV{keys: map[string]bool{}, vals: map[string][]byte{}} - rv := newReservations(store, none, func() jetstream.KeyValue { return bounds }, + rv := newReservations(store, catalog, func() jetstream.KeyValue { return bounds }, &findings{module: builds.BuilderModule, w: fs, logf: t.Logf, now: time.Now}, t.Logf) var said []string rv.say = func(_ context.Context, p meshbuilds.PackagePublished) error { @@ -555,13 +568,14 @@ func TestABuiltReservationIsTakenInFromItsState(t *testing.T) { } // Note 8's own case: every artifact's published kept on it is taken in before its bound is judged, so nothing is - // unpublished and nothing is raised; each is said as package-published. + // unpublished; each is said as package-published. The catalog holds no release of it past its bound, so it is + // version-unreleased, its release lost, and its version-released clears it (design 47 H2 H-A-773 (2), (7)). module = map[string]string{"a look": "keptlook", "the start": "keptstart"}[when] v = recordedLost(module, now.Add(-defaultPublishAckMinutes*time.Minute-time.Minute), "a", "b") said = nil takeIn() - if got := unreleased(module); got != "" { - t.Errorf("at %s, a reservation past its bound whose kept published mark every artifact raised %q, want no version-unreleased", when, got) + if got := unreleased(module); !strings.Contains(got, "every artifact is published") || !strings.Contains(got, "its release was lost") || strings.Contains(got, "unpublished") { + t.Errorf("at %s, a reservation past its bound whose kept published mark every artifact raised %q, want version-unreleased saying its release was lost", when, got) } if !slices.Contains(said, module+":a@"+v.Version+" sha256:"+module+"a") || !slices.Contains(said, module+":b@"+v.Version+" sha256:"+module+"b") { t.Errorf("at %s, said %v, want package-published of %s:a and %s:b", when, said, module, module) @@ -569,6 +583,9 @@ func TestABuiltReservationIsTakenInFromItsState(t *testing.T) { if bounds.keys[versions.ReservedBoundKey(module, "0.1")] { t.Errorf("at %s, the bound of a reservation past it was armed", when) } + if err := rv.release(ctx, meshcatalog.VersionReleasedEvent{Module: module, Version: v.Version}); err != nil || unreleased(module) != "" { + t.Errorf("at %s, its version-released (%v) left %q, want version-unreleased cleared", when, err, unreleased(module)) + } } }) t.Run("its bound ending", func(t *testing.T) { @@ -591,8 +608,9 @@ func TestABuiltReservationIsTakenInFromItsState(t *testing.T) { if got := unreleased("ends"); !strings.Contains(got, "ends:b unpublished") || !strings.Contains(got, "nothing within") { t.Errorf("at the bound's end with none standing, version-unreleased reads %q, want nothing within naming ends:b", got) } - // One whose every artifact is published is not left unmarked (1984/AC5): its bound's end raises nothing, and it waits for - // its version-released. + // One whose every artifact is published is not left unmarked (1984/AC5). Its bound's end asks the catalog's verb versions + // (design 47 H2 H-A-773 (2), (5), (6)): one the catalog holds released raises nothing; one it holds no release of is + // version-unreleased, its release lost; one whose versions cannot be read is raised too, saying so. all := recordedLost("endsall", now.Add(-time.Minute), "a", "b") if err := rv.Built(ctx, "endsall", all.Version, all.Artifacts, nil); err != nil { t.Fatal(err) @@ -600,9 +618,24 @@ func TestABuiltReservationIsTakenInFromItsState(t *testing.T) { if cur, _, _ := rv.r.Of(ctx, "endsall", all.Version); len(cur.Missing()) != 0 { t.Fatalf("endsall: %v unpublished after the take-in, want every artifact published", cur.Missing()) } - rv.ended(ctx, purged{key: versions.ReservedBoundKey("endsall", "0.1")}) + allKey := versions.ReservedBoundKey("endsall", "0.1") + held = []string{all.Version} + rv.ended(ctx, purged{key: allKey}) if got := unreleased("endsall"); got != "" { - t.Errorf("at the bound's end, a reservation whose every artifact is published raised %q, want no version-unreleased", got) + t.Errorf("at the bound's end, a published reservation the catalog holds released raised %q, want no version-unreleased", got) + } + held = nil + rv.ended(ctx, purged{key: allKey}) + if got := unreleased("endsall"); !strings.Contains(got, "every artifact is published") || !strings.Contains(got, "its release was lost") || + !strings.Contains(got, all.Version) || !strings.Contains(got, "says a published one's package-published again") { + t.Errorf("at the bound's end, a published reservation the catalog holds no release of raised %q, want version-unreleased saying its release was lost", got) + } + _ = fs.Clear(ctx, meshconditionsclient.ScopeModule, "endsall", versions.VersionUnreleased, "") + versionsErr = errors.New("no holder of mesh-catalog answered") + rv.ended(ctx, purged{key: allKey}) + versionsErr = nil + if got := unreleased("endsall"); !strings.Contains(got, "the catalog's versions could not be read") || !strings.Contains(got, "no holder of mesh-catalog answered") { + t.Errorf("at the bound's end with the catalog's versions unread, version-unreleased reads %q, want it raised saying they could not be read", got) } if cur, found, _ := rv.r.Of(ctx, "endsall", all.Version); !found || cur.BuiltAt.IsZero() { t.Errorf("at the bound's end, the reservation of endsall %s stands no more, want it waiting for its version-released", all.Version) diff --git a/modules/mesh-delivery-builder/internal/versions/republish_test.go b/modules/mesh-delivery-builder/internal/versions/republish_test.go index 8331fc300..8c31dda4a 100644 --- a/modules/mesh-delivery-builder/internal/versions/republish_test.go +++ b/modules/mesh-delivery-builder/internal/versions/republish_test.go @@ -181,6 +181,15 @@ func TestRepublish(t *testing.T) { if _, s, err := b.Republish(ctx, "m", v.Version); err == nil || len(s) != 0 || len(said) != 4 { t.Errorf("a released version: said %v (%v); want it refused as today", s, err) } + // With neither, every version version-unreleased names: Overdue lists a published one the catalog holds no release of + // past its bound (H-A-773 (2), (6)), and it is said again; a released one is not listed. + if q, s, err := b.Republish(ctx, "", ""); err != nil || len(q)+len(s) != 0 || len(said) != 4 { + t.Errorf("neither, the version released: queued %v, said %v (%v); want nothing", q, s, err) + } + released = nil + if q, s, err := b.Republish(ctx, "", ""); err != nil || len(q) != 0 || fmt.Sprint(s) != "[m "+v.Version+"]" || len(said) != 6 { + t.Errorf("neither: queued %v, said %v (%v), package-published %v; want it said again", q, s, err, said) + } }) t.Run("an entry that cannot be read stops neither the other versions nor the drain", func(t *testing.T) { b := newRepublishBed(t) diff --git a/modules/mesh-delivery-builder/internal/versions/reserve.go b/modules/mesh-delivery-builder/internal/versions/reserve.go index b7fba2d80..6cf594c4a 100644 --- a/modules/mesh-delivery-builder/internal/versions/reserve.go +++ b/modules/mesh-delivery-builder/internal/versions/reserve.go @@ -720,7 +720,8 @@ func (r *Reserver) Released(ctx context.Context, module, version string) ([]stri // Unreleased are the reservations whose build ended more than Reserver.Bound before now with an artifact unpublished: // the finding version-unreleased, naming the module, the version and the artifacts missing (published says whether an -// artifact is). A reservation whose build has not ended is not one. +// artifact is), and those with every artifact published whose version the catalog does not hold, their release lost (Missing +// empty; design 47 H2 H-A-773 (2)). A reservation whose build has not ended is not one. type Unreleased struct { Module, Version string Missing []string @@ -740,7 +741,21 @@ func (r *Reserver) releasedOf(ctx context.Context, module string) ([]string, err return r.ReleasedOf(ctx, module) } -// Overdue answers the reservations past the bound with an artifact not published. +// ReleaseLost says whether v's build ended with every artifact published while the catalog, asked through its verb versions +// (ReleasedOf), holds no release of its version: its release was lost (design 47 H2 H-A-773 (2)). An ask that fails is its error. +func (r *Reserver) ReleaseLost(ctx context.Context, v ReservedVersion) (bool, error) { + if !publishedWhole(v) { + return false, nil + } + released, err := r.releasedOf(ctx, v.Module) + if err != nil { + return false, err + } + return !slices.Contains(released, v.Version), nil +} + +// Overdue answers the reservations past the bound with an artifact not published, and those past it with every artifact published +// whose version the catalog does not hold (H-A-773 (2), (6)), the catalog's versions asked once per module. func (r *Reserver) Overdue(ctx context.Context, published func(module, version, artifact string) bool) ([]Unreleased, error) { keys, err := r.Store.KeysOf(ctx, AllFilter) if err != nil { @@ -748,6 +763,7 @@ func (r *Reserver) Overdue(ctx context.Context, published func(module, version, } sort.Strings(keys) var out []Unreleased + read := map[string][]string{} for _, k := range keys { cur, _, found, err := r.get(ctx, k) if err != nil { @@ -764,6 +780,20 @@ func (r *Reserver) Overdue(ctx context.Context, published func(module, version, } if len(missing) > 0 { out = append(out, Unreleased{Module: cur.Module, Version: cur.Version, Missing: missing}) + continue + } + if !publishedWhole(cur) { + continue + } + released, ok := read[cur.Module] + if !ok { + if released, err = r.releasedOf(ctx, cur.Module); err != nil { + return nil, fmt.Errorf("the catalog's versions of %s cannot be read, so whether its published %s is released is not known: %w", cur.Module, cur.Version, err) + } + read[cur.Module] = released + } + if !slices.Contains(released, cur.Version) { + out = append(out, Unreleased{Module: cur.Module, Version: cur.Version}) } } return out, nil diff --git a/modules/mesh-delivery-builder/internal/versions/reserve_test.go b/modules/mesh-delivery-builder/internal/versions/reserve_test.go index 656d9efe9..df369753f 100644 --- a/modules/mesh-delivery-builder/internal/versions/reserve_test.go +++ b/modules/mesh-delivery-builder/internal/versions/reserve_test.go @@ -559,4 +559,31 @@ func TestOverdueTakesTheSettingsBound(t *testing.T) { t.Errorf("%v after the build with the bound at 30 minutes: %v (%v), want %d findings", c.after, got, err, c.want) } } + // design 47 H2 H-A-773 (2), (5), (6): a reservation with every artifact published whose version the catalog's versions does not + // hold is listed past the same bound, its release lost, with nothing missing; one the catalog holds is not; an unread one fails. + if _, _, err := r.MarkHeld(ctx, "m", v.Version, []HeldArtifact{{Ref: "m:a", Digest: "sha256:a"}}); err != nil { + t.Fatal(err) + } + var released []string + var versionsErr error + r.ReleasedOf = func(context.Context, string) ([]string, error) { return released, versionsErr } + for _, c := range []struct { + name string + after time.Duration + released []string + err error + want []Unreleased + fails bool + }{ + {name: "within the bound", after: 29 * time.Minute}, + {name: "past the bound, not released", after: 30 * time.Minute, want: []Unreleased{{Module: "m", Version: v.Version}}}, + {name: "past the bound, released", after: 30 * time.Minute, released: []string{v.Version}}, + {name: "past the bound, the catalog's versions unread", after: 30 * time.Minute, err: errors.New("no holder answered"), fails: true}, + } { + now, released, versionsErr = time.Date(2026, 11, 25, 12, 0, 0, 0, time.UTC).Add(c.after), c.released, c.err + got, err := r.Overdue(ctx, nil) + if (err != nil) != c.fails || !reflect.DeepEqual(got, c.want) { + t.Errorf("%s: %v (%v), want %v (fails %v)", c.name, got, err, c.want, c.fails) + } + } }