Merge pull request 'Release a published build whose release was lost, say it as a finding, and wait out a bus refusal (H-A-773)' (#371) from fix/47-H2-773-release-again into main

This commit was merged in pull request #371.
This commit is contained in:
2026-11-26 19:31:20 +00:00
18 changed files with 488 additions and 108 deletions
@@ -274,7 +274,9 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
}
reserved.r.MovedFrom = reserved.movedFrom
republish.Unstored = reserved.unstoredAgain
republish.AsHeld = reserved.sayPublished // an artifact held for this very build is published as held (H-A-738 (1))
// An artifact held for this very build is published as held (H-A-738 (1)); a published version the catalog holds no release of is
// said again by builder_publish_again (H-A-773 (1)).
republish.SayPublished = reserved.sayPublished
reserved.judge = func(ctx context.Context, v versions.ReservedVersion) (versions.Judged, error) {
return republish.Held(ctx, v, registryVersionsVia(calls.Call))
}
@@ -325,7 +327,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
reserved: func(ctx context.Context, module, version string) (versions.ReservedVersion, bool, error) {
return reserved.r.Of(ctx, module, version)
},
republish: republish.Republish,
republish: republish.Queue, // the build's end's ask queues only; builder_publish_again says a published version again (H-A-773 (1))
// A publish is asked again while the registry's record lacks it (H-A-269 (2), H-A-272; H-A-514 addendum: no backlog count).
judge: func(ctx context.Context, v versions.ReservedVersion) (versions.Judged, error) {
return republish.Held(ctx, v, registryVersionsVia(calls.Call))
@@ -543,14 +543,14 @@ func TestThePublishQueueLosesNoItemAndNeverSendsADroppedItem(t *testing.T) {
}
rv.r.MovedFrom = rv.movedFrom
republish.Unstored = rv.unstoredAgain
republish.AsHeld = rv.sayPublished
republish.SayPublished = rv.sayPublished
rv.judge = func(ctx context.Context, v versions.ReservedVersion) (versions.Judged, error) {
return republish.Held(ctx, v, registryVersionsVia(conn.Call))
}
rv.r.HeldElsewhere = func(ctx context.Context, module string, skipped []string) {
rv.heldElsewhere(ctx, module, "the registries hold "+strings.Join(skipped, ", ")+", so the reserve skipped them")
}
items := &publishItems{now: time.Now, logf: t.Logf, unreleased: republish.Unreleased, republish: republish.Republish,
items := &publishItems{now: time.Now, logf: t.Logf, unreleased: republish.Unreleased, republish: republish.Queue,
dropMark: func(context.Context, string, string, string, string) error { return nil },
reserved: func(ctx context.Context, module, version string) (versions.ReservedVersion, bool, error) {
return rv.r.Of(ctx, module, version)
@@ -196,9 +196,14 @@ func versionActed(ctx context.Context, acts versions.Acts, kv jetstream.KeyValue
if acts.Republish == nil {
err = errors.New("this builder publishes nothing again")
} else {
r.Queued, err = acts.Republish(ctx, r.Module, r.Version)
var said []string
r.Queued, said, err = acts.Republish(ctx, r.Module, r.Version)
if err == nil {
r.Answer = "queued " + fmt.Sprint(len(r.Queued)) + " versions to publish again: " + strings.Join(r.Queued, ", ") + "; builder_publish_queue shows them"
if len(said) > 0 {
// A published version the catalog holds no release of has its package-published said again (H-A-773 (1)).
r.Answer += "; said the package-published again of " + fmt.Sprint(len(said)) + " published versions the catalog holds no release of: " + strings.Join(said, ", ")
}
}
}
} else if r.Mode == build.ModePublishDrop {
@@ -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))
@@ -501,17 +523,19 @@ func (rv *reservations) published(ctx context.Context, o versions.Outcome, inPro
}
}
// sayPublished says the seat mesh-builds' package-published of an artifact a published marked.
func (rv *reservations) sayPublished(ctx context.Context, m versions.Marked, digest string) {
// sayPublished says the seat mesh-builds' package-published of an artifact a published marked, and answers why it could not; the
// log says both.
func (rv *reservations) sayPublished(ctx context.Context, m versions.Marked, digest string) error {
if rv.say == nil {
rv.logf("package-published of %s at %s not said: no seat to say it on", m.Artifact, m.Reserved.Version)
return
return errors.New("no seat to say it on")
}
if err := rv.say(ctx, m.PackagePublished(digest, time.Now())); err != nil {
rv.logf("the package-published of %s at %s is not said: %v", m.Artifact, m.Reserved.Version, err)
} else {
rv.logf("package-published said: %s at %s, digest %s", m.Artifact, m.Reserved.Version, digest)
return err
}
rv.logf("package-published said: %s at %s, digest %s", m.Artifact, m.Reserved.Version, digest)
return nil
}
// dropped is builder_reserved_drop (design 47 H2 H-A-592): it names its version, and the reservation of the series is deleted whole
@@ -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)
@@ -681,6 +714,31 @@ func (e ansEntry) Revision() uint64 { return 1 }
func (e ansEntry) Value() []byte { return e.value }
func (e ansEntry) Operation() jetstream.KeyValueOp { return jetstream.KeyValuePut }
// TestPublishAgainAnswersTheVersionsItSaidAgain: design 47 H2 H-A-773 (1) — builder_publish_again's answer names, beside the
// versions it queued, the published versions the catalog holds no release of whose package-published it said again.
func TestPublishAgainAnswersTheVersionsItSaidAgain(t *testing.T) {
kv := &ansKV{wrote: make(chan []byte, 1)}
r := build.ReAsk{V: 1, Why: "its release was lost", By: "op@node", At: time.Now(), Mode: build.ModeRepublish, Module: "watchman"}
raw, _ := json.Marshal(r)
acts := versions.Acts{Republish: func(context.Context, string, string) ([]string, []string, error) {
return nil, []string{"watchman 0.1.170"}, nil
}}
versionActed(context.Background(), acts, kv, ansEntry{key: "republish.1", value: raw}, r, t.Logf)
var got build.ReAsk
select {
case v := <-kv.wrote:
if err := json.Unmarshal(v, &got); err != nil {
t.Fatal(err)
}
default:
t.Fatal("the publish again was not answered")
}
if got.Refused || len(got.Queued) != 0 || !strings.Contains(got.Answer, "queued 0 versions") ||
!strings.Contains(got.Answer, "said the package-published again of 1 published versions the catalog holds no release of: watchman 0.1.170") {
t.Errorf("answered %q (queued %v, refused %v); want the version said again named", got.Answer, got.Queued, got.Refused)
}
}
// noAskKnown is a builder none of whose lanes waits: it records the keys asked again and builds, announces and releases nothing.
type noAskKnown struct{ asked []string }
@@ -7,8 +7,9 @@ import (
// Acts are the builder's hand acts on its versions, answered by its program (the tools bundle writes them to reasks).
type Acts struct {
// Republish queues the reserved versions builder_publish_again names (design 47 G §588): the versions it queued.
Republish func(ctx context.Context, module, version string) ([]string, error)
// Republish queues the reserved versions builder_publish_again names (design 47 G §588): the versions it queued, and those whose
// package-published it said again, published and not released (design 47 H2 H-A-773 (1)).
Republish func(ctx context.Context, module, version string) (queued, said []string, err error)
// DropOldForm drops a retired node from the old form's count by hand (builder_old_form): its answer, or why not.
DropOldForm func(ctx context.Context, node, by, why string, at time.Time) (string, error)
// DropReserved drops a module's reservation of one MAJOR.MINOR by hand (builder_reserved_drop): its answer, or why not.
@@ -194,9 +194,11 @@ type Republisher struct {
// Unstored is told the first artifact of a reservation a holder refused as not stored, with the reservation as it stood: the
// builder builds the key again itself (design 47 H2 H-A-662); nil is told none.
Unstored func(ctx context.Context, v ReservedVersion, ref, words string)
// AsHeld is told each artifact a holder answered `other-bytes` for the publish's own fingerprint, newly marked published with the held
// digest (design 47 H2 H-A-738 (1)): the builder says package-published of it; nil says none.
AsHeld func(ctx context.Context, m Marked, digest string)
// SayPublished says the package-published of an artifact marked published, with its digest, answering why it could not: each
// artifact a holder answered `other-bytes` for the publish's own fingerprint, newly marked published with the held digest (design 47
// H2 H-A-738 (1)), and each artifact of a published version whose release the catalog does not hold, said again by
// builder_publish_again (H-A-773 (1)); nil says none.
SayPublished func(ctx context.Context, m Marked, digest string) error
// Ended ends the publish item of a version that never publishes, its reservation withdrawn or taken over (H-A-290 (2));
// nil ends none.
Ended func(ctx context.Context, module, version string)
@@ -480,44 +482,134 @@ func (r *Republisher) enqueue(ctx context.Context, v ReservedVersion, holder str
// Republish is builder_publish_again: with module and version, that reserved version's missing artifacts; with module
// alone, each reserved version of it whose artifacts are not all published; with neither, every version the finding
// version-unreleased names. It queues as the events do (no limit but the cap), at the holders Holders answers (design 47 G
// A-416), and answers the versions it queued.
func (r *Republisher) Republish(ctx context.Context, module, version string) ([]string, error) {
var vs []ReservedVersion
// A-416), and answers the versions it queued. A reservation it names whose artifacts are all published but whose version the
// catalog does not hold, asked through the catalog's verb versions (Reserver.ReleasedOf), has the package-published of each
// artifact said again, so the indexer releases it as at a first delivery (design 47 H2 H-A-773 (1)): those it answers as said.
func (r *Republisher) Republish(ctx context.Context, module, version string) (queued, said []string, err error) {
vs, again, err := r.named(ctx, module, version, true)
if err != nil {
return nil, nil, err
}
queued, qerr := r.queue(ctx, vs, r.holdersFn, 0, 0)
said, serr := r.sayAgain(ctx, again)
return queued, said, errors.Join(qerr, serr)
}
// Queue is the publish of a version whose build is done, its first try at the build's end (A-473): the versions Republish names
// with an artifact unpublished, queued as Republish queues them; it says no package-published again.
func (r *Republisher) Queue(ctx context.Context, module, version string) ([]string, error) {
vs, _, err := r.named(ctx, module, version, false)
if err != nil {
return nil, err
}
return r.queue(ctx, vs, r.holdersFn, 0, 0)
}
// named are the reserved versions Republish names: those with an artifact unpublished (vs) and, with published, those whose
// artifacts are all published and whose version the catalog does not hold (again; H-A-773 (1)). With a module, a dropped publish
// is asked anew and none named is refused.
func (r *Republisher) named(ctx context.Context, module, version string, published bool) (vs, again []ReservedVersion, err error) {
if module == "" {
over, err := r.Reserved.Overdue(ctx, nil)
if err != nil {
return nil, err
return nil, nil, err
}
for _, o := range over {
if v, ok, err := r.Reserved.Of(ctx, o.Module, o.Version); err == nil && ok {
vs = append(vs, v)
if len(v.Missing()) > 0 {
vs = append(vs, v)
} else if published {
again = append(again, v)
}
}
}
} else {
all, err := r.Reserved.All(ctx)
if err != nil {
return nil, err
return vs, again, nil
}
all, err := r.Reserved.All(ctx)
if err != nil {
return nil, nil, err
}
var released []string
read := false
for _, v := range all {
if v.Module != module || (version != "" && v.Version != version) {
continue
}
for _, v := range all {
if v.Module == module && (version == "" || v.Version == version) && len(v.Missing()) > 0 {
vs = append(vs, v)
}
if len(v.Missing()) > 0 {
vs = append(vs, v)
continue
}
// builder_publish_again asks a dropped publish anew: the drop is cleared in the write before its put (H-A-746).
for i := range vs {
if vs[i].Dropped == nil {
continue
}
if _, err := r.Reserved.ClearDropped(ctx, vs[i].Module, vs[i].Version); err != nil {
return nil, err
}
vs[i].Dropped = nil
if !published || !publishedWhole(v) {
continue
}
if len(vs) == 0 {
return nil, fmt.Errorf("%s holds no reserved version%s with an artifact unpublished", module, map[bool]string{true: " " + version, false: ""}[version != ""])
if !read {
if released, err = r.Reserved.releasedOf(ctx, module); err != nil {
return nil, nil, fmt.Errorf("the catalog's versions of %s cannot be read, so its published versions are not said again: %w", module, err)
}
read = true
}
if !slices.Contains(released, v.Version) {
again = append(again, v)
}
}
return r.queue(ctx, vs, r.holdersFn, 0, 0)
// builder_publish_again asks a dropped publish anew: the drop is cleared in the write before its put (H-A-746).
for _, list := range [][]ReservedVersion{vs, again} {
for i := range list {
if list[i].Dropped == nil {
continue
}
if _, err := r.Reserved.ClearDropped(ctx, list[i].Module, list[i].Version); err != nil {
return nil, nil, err
}
list[i].Dropped = nil
}
}
if len(vs)+len(again) == 0 {
what := "with an artifact unpublished"
if published {
what += " or a published one the catalog holds no release of"
}
return nil, nil, fmt.Errorf("%s holds no reserved version%s %s", module, map[bool]string{true: " " + version, false: ""}[version != ""], what)
}
return vs, again, nil
}
// sayAgain says again the package-published of each published artifact of each of vs, versions whose artifacts are all published
// and whose release the catalog does not hold (design 47 H2 H-A-773 (1)), and answers the versions said, `<module> <version>`. A
// version whose reservation stands no more at it is said in the log and not said again; a package-published that cannot be said is
// the answer's fault.
func (r *Republisher) sayAgain(ctx context.Context, vs []ReservedVersion) ([]string, error) {
var said []string
var errs []error
for _, v := range vs {
if why := NotStanding(v, true); why != "" {
r.logf("publish again: the package-published of %s %s is not said again: %s", v.Module, v.Version, why)
continue
}
if r.SayPublished == nil {
errs = append(errs, fmt.Errorf("the package-published of %s %s cannot be said again: this builder says none", v.Module, v.Version))
continue
}
var refs []string
for ref, ok := range v.Published {
if ok {
refs = append(refs, ref)
}
}
sort.Strings(refs)
whole := true
for _, ref := range refs {
if err := r.SayPublished(ctx, Marked{Reserved: v, Artifact: ref}, v.Artifacts[ref]); err != nil {
errs = append(errs, fmt.Errorf("the package-published of %s at %s is not said again: %w", ref, v.Version, err))
whole = false
}
}
if whole {
r.logf("publish again: %s %s is published and the catalog holds no release of it: the package-published of %s said again", v.Module, v.Version, strings.Join(refs, ", "))
said = append(said, v.Module+" "+v.Version)
}
}
return said, errors.Join(errs...)
}
// Queued is builder_publish_queue's answer, small at any size of the queue (design 47 H H-A-290 (5)): the queued versions'
@@ -666,8 +758,9 @@ const PublishDropDescription = "Drop one version's publish (design 47 H2 section
const PublishAgainDescription = "Publish reserved versions again (design 47 G section 588), which builds nothing: with module and version, that reserved " +
"version's missing artifacts; with module alone, each reserved version of that module whose artifacts are not all published; with neither, every " +
"version the finding version-unreleased names, newest first. It queues them as the builder's publish items do, and answers at once " +
"with the versions it queued; each outcome is said as package-published, or left in version-unreleased with the holder's words. A hand act, " +
"recorded in the hand-act log."
"with the versions it queued; each outcome is said as package-published, or left in version-unreleased with the holder's words. A version " +
"it names whose artifacts are all published but which the catalog's versions do not hold released has each artifact's package-published " +
"said again, so the catalog releases it as at a first delivery (design 47 H2 H-A-773). A hand act, recorded in the hand-act log."
// MoveQueued puts the values of the old state publish-queue on the work queue, once (§793): each under its message id, so a
// move run twice puts each once within the duplicates window; its class as of this run (a build ended before it is of the
@@ -809,8 +902,8 @@ func (r *Republisher) SendQueued(ctx context.Context, q QueuedPublish) SendFate
}
r.say(ctx, v, fmt.Sprintf("%s %s: %s holds it for this build with the digest %s, built %s: published as held, nothing stored", ref, q.Version, other.Seat, other.Digest, q.Artifacts[ref]))
for _, m := range marked {
if r.AsHeld != nil {
r.AsHeld(ctx, m, other.Digest)
if r.SayPublished != nil {
_ = r.SayPublished(ctx, m, other.Digest) // a fault is said by the holder of the hook
}
}
held++
@@ -128,7 +128,7 @@ func TestRepublish(t *testing.T) {
if v.Fingerprint != "src2:m" {
t.Fatalf("the reservation keeps the entry's fingerprint: %q", v.Fingerprint)
}
if q, err := b.Republish(ctx, "", ""); err != nil || len(b.sent) != 1 || fmt.Sprint(q) != "[m "+v.Version+"]" {
if q, _, err := b.Republish(ctx, "", ""); err != nil || len(b.sent) != 1 || fmt.Sprint(q) != "[m "+v.Version+"]" {
t.Fatalf("queued %v sent %d (%v), want 1", q, len(b.sent), err)
}
p := b.sent[0]
@@ -140,6 +140,57 @@ func TestRepublish(t *testing.T) {
t.Errorf("the work queue took %+v, want one live item at oci", b.puts)
}
})
t.Run("a published version the catalog holds no release of is said again, a released one refused", func(t *testing.T) {
// design 47 H2 H-A-773 (1): its release was lost, so builder_publish_again says each artifact's package-published again,
// asking the catalog's verb versions; the build's end's ask says nothing again; a released one is refused as today
b := newRepublishBed(t)
v := b.reserve(t, "m")
if _, _, err := b.Reserved.MarkHeld(ctx, "m", v.Version, []HeldArtifact{{Ref: "m:prog", Digest: "sha256:aa"}, {Ref: "m:lib", Digest: "sha256:bb"}}); err != nil {
t.Fatal(err)
}
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
var said []string
b.SayPublished = func(_ context.Context, m Marked, digest string) error {
said = append(said, m.Reserved.Version+" "+m.Artifact+" "+digest)
return nil
}
var released []string
var versionsErr error
b.Reserved.ReleasedOf = func(context.Context, string) ([]string, error) { return released, versionsErr }
if q, s, err := b.Republish(ctx, "m", ""); err != nil || len(q) != 0 || fmt.Sprint(s) != "[m "+v.Version+"]" || len(b.puts) != 0 ||
fmt.Sprint(said) != "["+v.Version+" m:lib sha256:bb "+v.Version+" m:prog sha256:aa]" {
t.Fatalf("module alone: queued %v, said %v (%v), puts %d, package-published %v; want both artifacts said again, nothing queued", q, s, err, len(b.puts), said)
}
if _, s, err := b.Republish(ctx, "m", v.Version); err != nil || len(s) != 1 || len(said) != 4 {
t.Errorf("module and version: said %v (%v), package-published %v; want it said again", s, err, said)
}
if _, err := b.Queue(ctx, "m", v.Version); err == nil || len(said) != 4 {
t.Errorf("the build's end's ask: %v, package-published %v; want refused as nothing is left to queue, nothing said again", err, said)
}
versionsErr = errors.New("no holder of mesh-catalog answered")
if _, _, err := b.Republish(ctx, "m", v.Version); err == nil || !strings.Contains(err.Error(), "cannot be read") || len(said) != 4 {
t.Errorf("the catalog's versions unread: %v, package-published %v; want refused, nothing said", err, said)
}
versionsErr = nil
say := b.SayPublished
b.SayPublished = func(context.Context, Marked, string) error { return errors.New("nats: jetstream not enabled") }
if _, s, err := b.Republish(ctx, "m", v.Version); err == nil || !strings.Contains(err.Error(), "jetstream not enabled") || len(s) != 0 {
t.Errorf("a package-published the bus refuses: said %v (%v); want the refusal answered, nothing said", s, err)
}
b.SayPublished, released = say, []string{v.Version}
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)
b.reserve(t, "m1")
@@ -152,7 +203,7 @@ func TestRepublish(t *testing.T) {
return entry(ctx, fp)
}
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
if _, err := b.Republish(ctx, "", ""); err == nil || !strings.Contains(err.Error(), "src2:m1") {
if _, _, err := b.Republish(ctx, "", ""); err == nil || !strings.Contains(err.Error(), "src2:m1") {
t.Errorf("the unreadable entry is not said: %v", err)
}
if len(b.sent) != 1 || !strings.HasPrefix(b.sent[0].Name, "m2/") {
@@ -164,8 +215,8 @@ func TestRepublish(t *testing.T) {
b.reserve(t, "m")
b.refuse = "oci-artifact-registry's publish of m/prog: not stored: no blob sha256:aa"
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
_, _ = b.Republish(ctx, "", "")
_, _ = b.Republish(ctx, "", "")
_, _, _ = b.Republish(ctx, "", "")
_, _, _ = b.Republish(ctx, "", "")
if len(b.sent) != 1 || len(b.said) != 1 || !strings.Contains(b.said[0], "not stored: ") {
t.Errorf("sent %d, said %v: want one try and one saying of not stored", len(b.sent), b.said)
}
@@ -206,7 +257,10 @@ func TestRepublish(t *testing.T) {
b := newRepublishBed(t)
v := b.reserve(t, "m")
var said []string
b.AsHeld = func(_ context.Context, m Marked, digest string) { said = append(said, m.Artifact+" "+digest) }
b.SayPublished = func(_ context.Context, m Marked, digest string) error {
said = append(said, m.Artifact+" "+digest)
return nil
}
b.other = &OtherBytes{Seat: SeatArtifacts, Name: "m/prog", Version: v.Version, Digest: "sha256:zz", Fingerprint: v.Fingerprint}
f := b.SendQueued(ctx, b.queueAt(v, PublishClassLive, b.now))
cur, _, _ := b.Reserved.At(ctx, ReservedKey("m", "0.1"))
@@ -235,8 +289,8 @@ func TestRepublish(t *testing.T) {
b.reserve(t, "m")
b.refuse = "the holder is full"
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
_, _ = b.Republish(ctx, "", "")
_, _ = b.Republish(ctx, "", "")
_, _, _ = b.Republish(ctx, "", "")
_, _, _ = b.Republish(ctx, "", "")
if len(b.sent) != 2 || len(b.said) != 2 {
t.Errorf("sent %d, said %v: want both events tried and said", len(b.sent), b.said)
}
@@ -246,7 +300,7 @@ func TestRepublish(t *testing.T) {
b.reserve(t, "m")
b.full = true
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
_, _ = b.Republish(ctx, "", "")
_, _, _ = b.Republish(ctx, "", "")
if len(b.sent) != 0 || len(b.said) != 1 || !strings.HasSuffix(b.said[0], QueueFull) {
t.Errorf("sent %d, said %v, want nothing sent and queue full said", len(b.sent), b.said)
}
@@ -256,8 +310,8 @@ func TestRepublish(t *testing.T) {
v := b.reserve(t, "m")
b.window, b.held = true, true
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
q1, _ := b.Republish(ctx, "m", v.Version)
q2, _ := b.Republish(ctx, "m", v.Version)
q1, _, _ := b.Republish(ctx, "m", v.Version)
q2, _, _ := b.Republish(ctx, "m", v.Version)
if len(b.puts) != 1 || len(q1) != 1 || len(q2) != 1 {
t.Errorf("puts %d, queued %v then %v: want one item, queued both times", len(b.puts), q1, q2)
}
@@ -288,19 +342,19 @@ func TestRepublish(t *testing.T) {
b := newRepublishBed(t)
b.reserve(t, "m1")
b.reserve(t, "m2")
if q, err := b.Republish(ctx, "", ""); err != nil || len(q) != 0 {
if q, _, err := b.Republish(ctx, "", ""); err != nil || len(q) != 0 {
t.Errorf("no holder named: queued %v (%v), want none", q, err)
}
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
q, err := b.Republish(ctx, "", "")
q, _, err := b.Republish(ctx, "", "")
if err != nil || fmt.Sprint(q) != "[m2 0.1.0 m1 0.1.0]" || len(b.sent) != 2 || b.sent[0].Seat != SeatArtifacts {
t.Errorf("the tool with neither queued %v (%v), sent %+v: want both versions at oci, with no limit", q, err, b.sent)
}
if _, err := b.Republish(ctx, "m1", "0.1.9"); err == nil {
if _, _, err := b.Republish(ctx, "m1", "0.1.9"); err == nil {
t.Error("a version no reservation holds is not refused")
}
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
_, _ = b.Republish(ctx, "", "")
_, _, _ = b.Republish(ctx, "", "")
})
}
@@ -380,8 +434,8 @@ func TestAQueuedItemIsSentWhileItsBuildStands(t *testing.T) {
live := b.reserve(t, "l")
b.held = true
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
_, _ = b.Republish(ctx, "o", old.Version)
_, _ = b.Republish(ctx, "l", live.Version)
_, _, _ = b.Republish(ctx, "o", old.Version)
_, _, _ = b.Republish(ctx, "l", live.Version)
if len(b.puts) != 2 || b.puts[0].Class != PublishClassStart || b.puts[1].Class != PublishClassLive ||
PublishEvent("oci", PublishClassLive, "l", live.Version) != "publish.oci.live.l.0=2E1=2E0" {
t.Errorf("puts %+v, want o again and l live, on publish.<holder>.<class>.<module>.<version>", b.puts)
@@ -396,7 +450,7 @@ func TestAQueuedItemIsSentWhileItsBuildStands(t *testing.T) {
t.Fatalf("withdrawn %v (%v)", ok, err)
}
if at == "put" {
if q, _ := b.Republish(ctx, "m", v.Version); len(q) != 0 {
if q, _, _ := b.Republish(ctx, "m", v.Version); len(q) != 0 {
t.Errorf("queued %v", q)
}
} else if f := b.SendQueued(ctx, b.queueAt(v, PublishClassLive, b.now)); f.Ended == "" {
@@ -504,13 +558,13 @@ func TestAQueuedItemIsSentWhileItsBuildStands(t *testing.T) {
if found, err := b.Reserved.MarkDropped(ctx, "d", v.Version, "op@node", "a test drops it", b.now); err != nil || !found {
t.Fatalf("drop: %v %v", found, err)
}
if _, err := b.Republish(ctx, "", ""); err != nil || len(b.puts) != 0 {
if _, _, err := b.Republish(ctx, "", ""); err != nil || len(b.puts) != 0 {
t.Errorf("an event put %d items (%v), want the dropped version passed over", len(b.puts), err)
}
if f := b.SendQueued(ctx, b.queueAt(v, PublishClassLive, b.now)); f.Ended == "" || !strings.Contains(f.Ended, "op@node") || len(b.sent) != 0 {
t.Errorf("a send of the dropped version answered %+v, sent %d: want it ended unsent, naming who dropped it", f, len(b.sent))
}
if _, err := b.Republish(ctx, "d", v.Version); err != nil || len(b.puts) != 1 {
if _, _, err := b.Republish(ctx, "d", v.Version); err != nil || len(b.puts) != 1 {
t.Errorf("builder_publish_again put %d items (%v), want the one", len(b.puts), err)
}
if cur, ok, err := b.Reserved.Of(ctx, "d", v.Version); err != nil || !ok || cur.Dropped != nil {
@@ -720,13 +720,42 @@ 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
}
// Overdue answers the reservations past the bound with an artifact not published.
// publishedWhole says whether v's build ended with every artifact a registry publishes published: a version the catalog then does
// not hold released is one whose release was lost (design 47 H2 H-A-773).
func publishedWhole(v ReservedVersion) bool {
return !v.BuiltAt.IsZero() && len(v.Published) > 0 && len(v.Missing()) == 0
}
// releasedOf are the versions the catalog holds released for module, asked through its verb versions (ReleasedOf).
func (r *Reserver) releasedOf(ctx context.Context, module string) ([]string, error) {
if r.ReleasedOf == nil {
return nil, errors.New("this builder asks no catalog's versions")
}
return r.ReleasedOf(ctx, module)
}
// 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 {
@@ -734,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 {
@@ -750,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
@@ -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)
}
}
}
@@ -589,12 +589,15 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
_ = m.Ack() // nothing else the indexer consumes rides the shared stream
}
}
if err := hub.Handle(meshbuilds.SubjectPackagePublished, func(m jetstream.Msg) { heardPackagePublished(ctx, ix, m, logger.Printf) }); err != nil {
// A message the indexer could not take is given again after a wait that doubles with each delivery, from the setting
// redeliver-pace-first (design 47 H2 H-A-773 (3), (4)).
pace := durationSetting(index.RedeliverPaceSetting, index.DefaultRedeliverPace, logger.Printf)
if err := hub.Handle(meshbuilds.SubjectPackagePublished, func(m jetstream.Msg) { heardPackagePublished(ctx, ix, m, pace, logger.Printf) }); err != nil {
return err
}
// A release re-pins once, at its reservation (design 47 H2 §805): the builder's version-reserved, and the step-ended of
// a pipeline whose reservations settle then.
if err := hub.Handle(meshbuilds.SubjectVersionReserved, func(m jetstream.Msg) { heardVersionReserved(ctx, ix, m, logger.Printf) }); err != nil {
if err := hub.Handle(meshbuilds.SubjectVersionReserved, func(m jetstream.Msg) { heardVersionReserved(ctx, ix, m, pace, logger.Printf) }); err != nil {
return err
}
if err := hub.Handle(meshbuilds.SubjectStepEndedAll, func(m jetstream.Msg) { heardBuildStepEnded(ctx, ix, m, logger.Printf) }); err != nil {
@@ -622,16 +625,16 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
}
}()
})
if err := hub.Handle(nodebuildgo.SubjectStepEndedAll, func(m jetstream.Msg) { heardStepEnded(ctx, ix, m, logger.Printf) }); err != nil {
if err := hub.Handle(nodebuildgo.SubjectStepEndedAll, func(m jetstream.Msg) { heardStepEnded(ctx, ix, m, pace, logger.Printf) }); err != nil {
return err
}
// A build's import set, said by its build module at its end (design 47 H2 H-A-517, H-A-532 DQ-2).
for _, subject := range []string{nodebuildgo.SubjectImportsReportedAll, nodebuildnode.SubjectImportsReportedAll} {
if err := hub.Handle(subject, func(m jetstream.Msg) { heardImportsReported(ctx, ix, m, logger.Printf) }); err != nil {
if err := hub.Handle(subject, func(m jetstream.Msg) { heardImportsReported(ctx, ix, m, pace, logger.Printf) }); err != nil {
return err
}
}
if err := hub.Handle(decidedSubject(cred.Module), func(m jetstream.Msg) { heardDecided(ctx, registry, m, logger.Printf) }); err != nil {
if err := hub.Handle(decidedSubject(cred.Module), func(m jetstream.Msg) { heardDecided(ctx, registry, m, pace, logger.Printf) }); err != nil {
return err
}
for _, subject := range droppedSubjects {
@@ -83,11 +83,16 @@ type deliveredMsg struct {
data []byte
n uint64
naked bool
delay time.Duration // the delay it was naked with
}
func (d *deliveredMsg) Subject() string { return d.subject }
func (d *deliveredMsg) Data() []byte { return d.data }
func (d *deliveredMsg) Nak() error { d.naked = true; return nil }
func (d *deliveredMsg) NakWithDelay(delay time.Duration) error {
d.naked, d.delay = true, delay
return nil
}
func (d *deliveredMsg) Metadata() (*jetstream.MsgMetadata, error) {
return &jetstream.MsgMetadata{NumDelivered: d.n}, nil
}
@@ -165,7 +165,7 @@ func routerRecordOf(module string, call toolCaller, record func(bucket, id strin
// heardDecided is the handler of the decided events for this module: a warrant is applied by the registry; one it could not
// apply is left for the bus to give again, and said. On the last delivery its consumer allows the warrant is given up: its ask
// is answered as not applied and the registration said unwritten (design 47 H2 H-A-470 (2)).
func heardDecided(ctx context.Context, reg *index.Registry, m jetstream.Msg, logf func(string, ...any)) {
func heardDecided(ctx context.Context, reg *index.Registry, m jetstream.Msg, pace time.Duration, logf func(string, ...any)) {
var w oc.Warrant
if err := json.Unmarshal(m.Data(), &w); err != nil {
logf("%s holds what is no warrant, dropped: %v", m.Subject(), err)
@@ -175,7 +175,7 @@ func heardDecided(ctx context.Context, reg *index.Registry, m jetstream.Msg, log
if err := reg.Heard(ctx, w); err != nil {
reason := strings.TrimSpace(err.Error())
logf("the warrant of the ask %s is left unapplied and given again: %s", w.Ask, reason)
leftForBus(m, "the warrant of the ask "+w.Ask, err, logf)
leftForBus(m, pace, "the warrant of the ask "+w.Ask, err, logf)
if md, merr := m.Metadata(); merr == nil && md != nil && md.NumDelivered >= EventDeliveries {
if gerr := reg.GiveUp(ctx, w, reason); gerr != nil {
logf("the warrant of the ask %s is given up, but its ask is not answered: %v", w.Ask, gerr)
@@ -5,8 +5,10 @@ import (
"encoding/json"
"errors"
"fmt"
"slices"
"strings"
"testing"
"time"
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
stdio "git.novox.be/novox/mesh-sdk/go"
@@ -65,15 +67,16 @@ func TestAWarrantIsGivenUpOnItsLastDelivery(t *testing.T) {
_ = json.Unmarshal(v, &p)
return p
}
for n := uint64(1); n < EventDeliveries; n++ {
// Design 47 H2 H-A-773 (3), (4): each is given again after the setting redeliver-pace-first's wait, doubled with each delivery.
for n, delay := range map[uint64]time.Duration{1: 2 * time.Second, 2: 4 * time.Second, 3: 8 * time.Second, 4: 16 * time.Second} {
m := &deliveredMsg{subject: "decided", data: body, n: n}
heardDecided(ctx, reg, m, func(string, ...any) {})
if !m.naked || state().State != index.ProposalOpen || len(said) != 0 {
t.Fatalf("delivery %d: naked %t, key %+v, said %v; want it left for the bus, the key open, nothing said", n, m.naked, state(), said)
heardDecided(ctx, reg, m, index.DefaultRedeliverPace, func(string, ...any) {})
if !m.naked || m.delay != delay || state().State != index.ProposalOpen || len(said) != 0 {
t.Fatalf("delivery %d: naked %t after %v, key %+v, said %v; want it left for the bus after %v, the key open, nothing said", n, m.naked, m.delay, state(), said, delay)
}
}
m := &deliveredMsg{subject: "decided", data: body, n: EventDeliveries}
heardDecided(ctx, reg, m, func(string, ...any) {})
heardDecided(ctx, reg, m, index.DefaultRedeliverPace, func(string, ...any) {})
if p := state(); !m.naked || p.State != index.ProposalRefused || !strings.HasPrefix(p.Outcome, "not applied: ") || !strings.Contains(p.Outcome, "no response from stream") {
t.Fatalf("the last delivery: naked %t, key %+v; want it ended refused, not applied, naming the reason", m.naked, p)
}
@@ -81,3 +84,31 @@ func TestAWarrantIsGivenUpOnItsLastDelivery(t *testing.T) {
t.Fatalf("said %v; want registration-unwritten of source.novox.hq naming the ask and the reason", said)
}
}
// Design 47 H2 H-A-773 (3), (4): a package-published the indexer cannot keep (the bus refused JetStream for a few seconds) is left
// for the bus after a wait that doubles with each delivery from the setting redeliver-pace-first, so its five deliveries span
// about 30 s and are not spent at once; the last says it gives the message up.
func TestARefusedPackagePublishedIsGivenAgainAfterAGrowingWait(t *testing.T) {
ctx := context.Background()
body, _ := json.Marshal(map[string]any{"v": 1, "module": "mesh-delivery-watchman", "artifact": "mesh-delivery-watchman:program", "version": "0.1.170"})
ix := &index.Indexer{} // keeps no state versions, so each delivery is refused
for _, c := range []struct {
pace time.Duration
n uint64
delay time.Duration
}{{index.DefaultRedeliverPace, 1, 2 * time.Second}, {index.DefaultRedeliverPace, 2, 4 * time.Second}, {index.DefaultRedeliverPace, 3, 8 * time.Second},
{index.DefaultRedeliverPace, 4, 16 * time.Second}, {5 * time.Second, 2, 10 * time.Second}} {
var said []string
m := &deliveredMsg{subject: "mesh.seat.mesh-builds.event.package-published", data: body, n: c.n}
heardPackagePublished(ctx, ix, m, c.pace, func(f string, a ...any) { said = append(said, fmt.Sprintf(f, a...)) })
if !m.naked || m.delay != c.delay || slices.ContainsFunc(said, func(l string) bool { return strings.HasPrefix(l, "gives up") }) {
t.Errorf("delivery %d at a pace of %v: naked %t after %v, said %q; want it given again after %v, not given up", c.n, c.pace, m.naked, m.delay, said, c.delay)
}
}
var said []string
m := &deliveredMsg{subject: "mesh.seat.mesh-builds.event.package-published", data: body, n: EventDeliveries}
heardPackagePublished(ctx, ix, m, index.DefaultRedeliverPace, func(f string, a ...any) { said = append(said, fmt.Sprintf(f, a...)) })
if !slices.ContainsFunc(said, func(l string) bool { return strings.HasPrefix(l, "gives up") && strings.Contains(l, "0.1.170") }) {
t.Errorf("the last delivery said %q; want it given up, naming the version", said)
}
}
@@ -65,19 +65,35 @@ func startHearing(ctx context.Context, hub hubStarter, js jetstream.JetStream, c
// composes a module's durable with (mesh-grants buscompose).
const EventDeliveries = 5
// leftForBus leaves a message the indexer could not take for the bus to give again, and on the last delivery its consumer allows
// says that it gives the message up, naming its subject, what it carries and the last refusal (design 47 G A-420): past it the bus
// drops the message without a word.
func leftForBus(m jetstream.Msg, what string, err error, logf func(string, ...any)) {
_ = m.Nak()
if md, merr := m.Metadata(); merr == nil && md != nil && md.NumDelivered >= EventDeliveries {
// leftForBus leaves a message the indexer could not take for the bus to give again after the delay of its delivery (redeliverDelay
// of pace, the setting redeliver-pace-first; design 47 H2 H-A-773 (3), (4)), and on the last delivery its consumer allows says that
// it gives the message up, naming its subject, what it carries and the last refusal (design 47 G A-420): past it the bus drops the
// message without a word.
func leftForBus(m jetstream.Msg, pace time.Duration, what string, err error, logf func(string, ...any)) {
md, merr := m.Metadata()
n := uint64(1)
if merr == nil && md != nil && md.NumDelivered > 0 {
n = md.NumDelivered
}
_ = m.NakWithDelay(redeliverDelay(pace, n))
if merr == nil && md != nil && md.NumDelivered >= EventDeliveries {
logf("gives up %s: %s, delivered %d times, the most its consumer allows; the last refusal: %v", m.Subject(), what, md.NumDelivered, err)
}
}
// redeliverDelay is the wait before the bus gives a message again after its delivery n (1 the first): pace, doubled with each
// delivery after the first (H-A-773 (4)).
func redeliverDelay(pace time.Duration, n uint64) time.Duration {
d := pace
for i := uint64(1); i < n && i < EventDeliveries; i++ {
d *= 2
}
return d
}
// heardPackagePublished takes one package-published of the seat mesh-builds into the catalog's versions (design 47 G §349):
// one that does not decode is said and acknowledged; one that cannot be kept is left, so the bus gives it again.
func heardPackagePublished(ctx context.Context, ix *index.Indexer, m jetstream.Msg, logf func(string, ...any)) {
func heardPackagePublished(ctx context.Context, ix *index.Indexer, m jetstream.Msg, pace time.Duration, logf func(string, ...any)) {
var p meshbuilds.PackagePublished
if err := json.Unmarshal(m.Data(), &p); err != nil {
logf("%s holds what is no package-published, left: %v", m.Subject(), err)
@@ -86,7 +102,7 @@ func heardPackagePublished(ctx context.Context, ix *index.Indexer, m jetstream.M
}
if err := ix.HearPackagePublished(ctx, p); err != nil {
logf("versions: the package-published of %s %s could not be kept, so the bus gives it again: %v", p.Artifact, p.Version, err)
leftForBus(m, fmt.Sprintf("the package-published of %s %s", p.Artifact, p.Version), err, logf)
leftForBus(m, pace, fmt.Sprintf("the package-published of %s %s", p.Artifact, p.Version), err, logf)
return
}
_ = m.Ack()
@@ -94,7 +110,7 @@ func heardPackagePublished(ctx context.Context, ix *index.Indexer, m jetstream.M
// heardVersionReserved takes one version-reserved of the seat mesh-builds in (design 47 H2 §805): one that does not decode
// is said and acknowledged; one that cannot be kept is left, so the bus gives it again.
func heardVersionReserved(ctx context.Context, ix *index.Indexer, m jetstream.Msg, logf func(string, ...any)) {
func heardVersionReserved(ctx context.Context, ix *index.Indexer, m jetstream.Msg, pace time.Duration, logf func(string, ...any)) {
var e meshbuilds.VersionReservedEvent
if err := json.Unmarshal(m.Data(), &e); err != nil {
logf("%s holds what is no version-reserved, left: %v", m.Subject(), err)
@@ -103,7 +119,7 @@ func heardVersionReserved(ctx context.Context, ix *index.Indexer, m jetstream.Ms
}
if err := ix.HearVersionReserved(ctx, e); err != nil {
logf("versions: the version-reserved of %s %s could not be kept, so the bus gives it again: %v", e.Artifact, e.Version, err)
leftForBus(m, fmt.Sprintf("the version-reserved of %s %s", e.Artifact, e.Version), err, logf)
leftForBus(m, pace, fmt.Sprintf("the version-reserved of %s %s", e.Artifact, e.Version), err, logf)
return
}
_ = m.Ack()
@@ -125,7 +141,7 @@ func heardBuildStepEnded(ctx context.Context, ix *index.Indexer, m jetstream.Msg
}
// heardStepEnded deletes the input kept for the run ask a build seat's step-ended names (design 47 G §354, A-78 d).
func heardStepEnded(ctx context.Context, ix *index.Indexer, m jetstream.Msg, logf func(string, ...any)) {
func heardStepEnded(ctx context.Context, ix *index.Indexer, m jetstream.Msg, pace time.Duration, logf func(string, ...any)) {
var e nodebuildgo.StepEnded
if err := json.Unmarshal(m.Data(), &e); err != nil {
logf("%s holds what is no step-ended, left: %v", m.Subject(), err)
@@ -134,7 +150,7 @@ func heardStepEnded(ctx context.Context, ix *index.Indexer, m jetstream.Msg, log
}
if err := ix.HearInputEnded(ctx, e); err != nil {
logf("inputs: the input of the ask %s could not be deleted, so the bus gives it again: %v", e.Ask, err)
leftForBus(m, "the step-ended of the ask "+e.Ask, err, logf)
leftForBus(m, pace, "the step-ended of the ask "+e.Ask, err, logf)
return
}
_ = m.Ack()
@@ -142,7 +158,7 @@ func heardStepEnded(ctx context.Context, ix *index.Indexer, m jetstream.Msg, log
// heardImportsReported keeps a build's import set (design 47 H2 H-A-517, H-A-527): one that does not decode, or names no
// module or fingerprint, is said and acknowledged; one that cannot be kept is left, so the bus gives it again.
func heardImportsReported(ctx context.Context, ix *index.Indexer, m jetstream.Msg, logf func(string, ...any)) {
func heardImportsReported(ctx context.Context, ix *index.Indexer, m jetstream.Msg, pace time.Duration, logf func(string, ...any)) {
var e nodebuildgo.ImportsReported
if err := json.Unmarshal(m.Data(), &e); err != nil {
logf("%s holds what is no imports-reported, left: %v", m.Subject(), err)
@@ -155,7 +171,7 @@ func heardImportsReported(ctx context.Context, ix *index.Indexer, m jetstream.Ms
logf("%s: %v, left", m.Subject(), err)
case err != nil:
logf("imports: the import set of %s at %s could not be kept, so the bus gives it again: %v", e.Module, e.Fingerprint, err)
leftForBus(m, fmt.Sprintf("the imports-reported of %s at %s", e.Module, e.Fingerprint), err, logf)
leftForBus(m, pace, fmt.Sprintf("the imports-reported of %s at %s", e.Module, e.Fingerprint), err, logf)
return
}
_ = m.Ack()
@@ -10,6 +10,7 @@ import (
"slices"
"strconv"
"strings"
"time"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
@@ -38,6 +39,14 @@ const (
PendingPrefix = "pending."
)
// The setting redeliver-pace-first and its default (design 47 H2 H-A-773 (3), (4)): the first wait before the bus gives again a
// message of the indexer's events consumer that it could not take, doubled with each delivery (2, 4, 8 and 16 s between the
// consumer's five deliveries), so a bus refusal of a few seconds spends none of them.
const (
RedeliverPaceSetting = "redeliver-pace-first"
DefaultRedeliverPace = 2 * time.Second
)
// published is what a not yet released version holds: each artifact published at it, by reference.
type published struct {
Artifacts map[string]meshcatalog.VersionArtifact `json:"artifacts"`
@@ -246,7 +246,8 @@ func TestManifestDeclarations(t *testing.T) { // 1238/AC1, 1444 (reads the build
if m.Class != "core" {
t.Errorf("class = %q, want core", m.Class)
}
for key, def := range map[string]string{busretry.PaceFirstSetting: "1s", busretry.PaceMaxSetting: "30s", index.WaitingLineSetting: "1m", index.WaitingBoundSetting: "5m", index.RereadPaceFirstSetting: "5s", index.RereadPaceMaxSetting: "1m"} {
for key, def := range map[string]string{busretry.PaceFirstSetting: "1s", busretry.PaceMaxSetting: "30s", index.WaitingLineSetting: "1m", index.WaitingBoundSetting: "5m", index.RereadPaceFirstSetting: "5s", index.RereadPaceMaxSetting: "1m",
index.RedeliverPaceSetting: "2s"} { // H-A-773 (4): the wait before the bus gives a refused message again, 2 s doubling
if c, _ := m.Config[key].(map[string]any); c["default"] != def || c["runtime"] != true || c["type"] != "string" {
t.Errorf("config %s = %v, want a runtime string setting defaulting to %s", key, m.Config[key], def)
}
@@ -110,6 +110,13 @@
"default": "1s",
"runtime": true
},
"redeliver-pace-first": {
"type": "string",
"description": "the first wait before the bus gives again a message of the indexer's events consumer that it could not take, doubled with each delivery (2, 4, 8 and 16 s between the five), a Go duration (design 47 H2 H-A-773 (3), (4)).",
"trusted": false,
"default": "2s",
"runtime": true
},
"kept-call-pace-max": {
"type": "string",
"description": "the longest wait between two tries of a kept call after a transport fault, a Go duration (design 47 H2 §775).",