B5 read-before-the-ask: the registries' record at V is written on the reservation before a build module is asked again; a first not stored starts the build again once

Builds: design 47 H2 H-A-588 (3) (4), H-A-662, H-A-664, H-A-666, H-A-703
This commit is contained in:
2026-11-25 17:14:05 +01:00
parent 13c9fb430e
commit b7dc1dc3e1
9 changed files with 138 additions and 6 deletions
@@ -264,6 +264,10 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
return republish.HeldRecords(ctx, module, fp, refs, registryVersionsVia(calls.Call))
}
reserved.r.MovedFrom = reserved.movedFrom
republish.Unstored = reserved.unstoredAgain
reserved.judge = func(ctx context.Context, v versions.ReservedVersion) (versions.Judged, error) {
return republish.Held(ctx, v, registryVersionsVia(calls.Call))
}
// A done build whose number a registry holds elsewhere is built again at the next free number (H-A-279), on the builder's context.
reserved.rebuild = func(_ context.Context, module, fp, why string) error {
res := b.BuildAgain(ctx, module, fp, why, "the builder", buildAgainBound)
@@ -58,6 +58,8 @@ type reservations struct {
recordAgain func(ctx context.Context, module, fp, when string) (string, error)
// rebuild builds a done key of module at fp again (the build-again path, A-490; H-A-279); nil builds none.
rebuild func(ctx context.Context, module, fp, why string) error
// judge reads the registries' record of a reservation's artifacts at its version (the republisher's Held); nil reads none.
judge func(ctx context.Context, v versions.ReservedVersion) (versions.Judged, error)
// say says package-published on the seat mesh-builds; nil says none.
say func(context.Context, meshbuilds.PackagePublished) error
// names is each package's name as its series key names it (for Go, its module path), and sayReserved says version-reserved on
@@ -568,6 +570,36 @@ func (rv *reservations) ReleasedFor(ctx context.Context, module, fingerprint str
return rv.r.ReleasedFor(ctx, module, fingerprint)
}
// MarkRegistryHeld reads the registries' record of v's artifacts and writes the held digest of each artifact a registry holds at v's version
// for the build's fingerprint on the reservation, marked published, and says package-published of each once (design 47 H2 H-A-588
// (4)); what the registries do not hold loses its recorded digest (H-A-664). A read that does not answer is said and nothing is
// written, so the build goes on.
func (rv *reservations) MarkRegistryHeld(ctx context.Context, v versions.ReservedVersion) {
if rv.judge == nil {
return
}
j, err := rv.judge(ctx, v)
if err != nil {
rv.logf("%s %s: the registries' record of its artifacts is not read before the build module is asked again, so none is marked held: %v", v.Module, v.Version, err)
return
}
marked, _, err := rv.r.MarkHeld(ctx, v.Module, v.Version, j.Held)
if err != nil {
rv.logf("%s %s: what the registries hold is not written on the reservation: %v", v.Module, v.Version, err)
return
}
for _, m := range marked {
var held versions.HeldArtifact
for _, h := range j.Held {
if h.Ref == m.Artifact {
held = h
}
}
rv.logf("%s %s: %s holds %s %s at %s for this build: marked published from its record before the build is asked again", v.Module, v.Version, held.Seat, held.Name, held.Version, held.Digest)
rv.sayPublished(ctx, m, held.Digest)
}
}
// markHeld marks the artifacts the registries' record holds at their version with the built digest published, as their published
// heard would, and says package-published of each (design 47 H H-A-274): a published heard and lost never leaves the publish
// asked for ever. The version's release follows from the catalog as for any published.
@@ -627,6 +659,19 @@ func elsewhereWords(v versions.ReservedVersion, elsewhere []versions.HeldArtifac
return fmt.Sprintf("%s is withdrawn and the build of %s is built again at the next free number: %s", v.Version, v.Fingerprint, strings.Join(at, "; "))
}
// unstoredAgain builds a key again whose reservation's first artifact a holder refused as not stored (design 47 H2 H-A-662): the
// build under its standing version completes what the registries lack, as the person's builder_build_again would. A key the
// build again refuses (not a first branch's trunk build, or released) is said and left to the person's tool.
func (rv *reservations) unstoredAgain(ctx context.Context, v versions.ReservedVersion, ref, words string) {
if rv.rebuild == nil {
return
}
why := fmt.Sprintf("%s refused by its holder as not stored (%s): the build of %s is built again under %s", ref, words, v.Fingerprint, v.Version)
if err := rv.rebuild(ctx, v.Module, v.Fingerprint, why); err != nil {
rv.logf("%s %s: the build again is not started: %v; builder_build_again builds it", v.Module, v.Version, err)
}
}
// movedFrom is told by the reserver a standing number it withdrew at a build again (design 47 H2 H-A-590 (1)): the finding is raised;
// the reserve itself takes the next number no registry holds.
func (rv *reservations) movedFrom(ctx context.Context, v versions.ReservedVersion, elsewhere []versions.HeldArtifact) {
@@ -133,6 +133,10 @@ type Reservations interface {
// TakenOver is the reservation of module's series that took the series over from the build of fingerprint, whose number
// it keeps withdrawn (design 47 H H-A-226), and whether one does (H-A-244).
TakenOver(ctx context.Context, module, fingerprint string) (versions.ReservedVersion, bool, error)
// MarkRegistryHeld reads the registries' record of v's artifacts at its version and writes on the reservation the held digest of each
// artifact a registry holds there for the build's fingerprint, marking it published, before a build module is asked for the
// fingerprint again (design 47 H2 H-A-588 (4)). A read that does not answer is said and the build goes on.
MarkRegistryHeld(ctx context.Context, v versions.ReservedVersion)
// VersionAt is the version module's artifact is published at from the source revision of branch: its reservation of that
// origin with the artifact published, else its release recorded at that source revision (design 47 H2 H-A-547 (3), H-A-551).
VersionAt(ctx context.Context, module, artifact, branch string, source int64) (string, bool, error)
@@ -34,6 +34,8 @@ type fakeReservations struct {
tookBy map[string]versions.ReservedVersion // by fingerprint, the reservation that took its series over (H-A-244)
held map[string]versions.ReservedVersion // by fingerprint, the reservation ReservedFor answers as it stands (H-A-492)
lost error // the record of the digests fails, as a store refusing it would
marks []string // the versions MarkRegistryHeld was told, with the asks the build module had by then (H-A-588 (4))
asked func() int
atMu sync.Mutex
at map[string]string // by "<module>:<artifact>@<branch>.<source>", the version VersionAt answers (H-A-547 (3))
}
@@ -55,6 +57,14 @@ func (f *fakeReservations) publishAt(module, artifact, branch string, source int
f.at[fmt.Sprintf("%s:%s@%s.%d", module, artifact, branch, source)] = version
}
func (f *fakeReservations) MarkRegistryHeld(_ context.Context, v versions.ReservedVersion) {
n := 0
if f.asked != nil {
n = f.asked()
}
f.marks = append(f.marks, fmt.Sprintf("%s@%d asks", v.Version, n))
}
func (f *fakeReservations) TakenOver(_ context.Context, _, fp string) (versions.ReservedVersion, bool, error) {
v, ok := f.tookBy[fp]
return v, ok, nil
@@ -429,6 +439,7 @@ func TestAReservingTrunkBuildNeverEndsDoneWithoutItsVersion(t *testing.T) {
}
r.b.Reserved = res
asked := len(r.asks.Asks())
res.asked = func() int { return len(r.asks.Asks()) - asked }
got := r.b.BuildAgain(context.Background(), "m", fp1, "its publish was refused", "shanks.lead", 2*time.Second)
r.b.Wait()
if c.refuse != "" {
@@ -447,6 +458,10 @@ func TestAReservingTrunkBuildNeverEndsDoneWithoutItsVersion(t *testing.T) {
if _, ok := res.built[want]; !ok || len(res.reserved) != 1 {
t.Fatalf("built %v after %d reservations; want the digests recorded under the freshly reserved %s so the build's end asks its publish", res.built, len(res.reserved), want)
}
// H2 H-A-588 (4): what the registries hold is marked once the version is reserved and before the build module is asked
if len(res.marks) != 1 || res.marks[0] != want+"@0 asks" {
t.Errorf("MarkRegistryHeld was told %v; want %s once, before any ask of the build module", res.marks, want)
}
})
}
}
@@ -457,6 +472,7 @@ type realReserve struct {
reservations map[string][]byte
}
func (r *realReserve) MarkRegistryHeld(context.Context, versions.ReservedVersion) {}
func (r *realReserve) ReleasedFor(context.Context, string, string) (bool, error) {
return false, nil
}
@@ -815,6 +815,12 @@ func (b *Builder) try(ctx context.Context, module string, m meshcatalog.ModulesB
reserved, hasReserved = b.reserve(ctx, module, m, plan, b.originOf(key), false)
}
}
if hasReserved && supersededNow == "" && cl.Build.State != builds.BuildDone {
// Before a build module is asked for the fingerprint again, what a registry holds of it at its version is on the reservation
// and marked published, so a version a failed build left partly published is completed, never built whole again over a
// refusal (design 47 H2 H-A-588 (4), H-A-666: between the reserve and the build).
b.Reserved.MarkRegistryHeld(ctx, reserved)
}
var result builds.BuilderBuild
if supersededNow != "" {
// Ended as the newer entry's take-in withdraws a build in flight: final for this fingerprint.
@@ -162,6 +162,9 @@ type Republisher struct {
// Started is when this run of the builder started: a version whose build ended at or after it is of the live class, one
// that ended before it of the start's (H-A-290 (1)). Zero makes every version live.
Started time.Time
// 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)
// 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)
@@ -748,7 +751,7 @@ func (r *Republisher) SendQueued(ctx context.Context, q QueuedPublish) SendFate
return SendFate{Ended: "none of its artifacts is left to send: each is published or refused as not stored"}
}
var failed []string
sent := 0
sent, again := 0, false
for _, ref := range refs {
seat, name, kind, ok := publishTarget(e, q.Module, ref)
if !ok {
@@ -769,6 +772,12 @@ func (r *Republisher) SendQueued(ctx context.Context, q QueuedPublish) SendFate
r.logf("%s %s: the unstored %s is not kept: %v", q.Module, q.Version, ref, merr)
} else if ok {
r.say(ctx, v, ref+" "+NotStoredWords+words)
// The first of the reservation's artifacts refused as not stored starts the build again, once per reservation: one
// the kept `unstored` already holds starts none (design 47 H2 H-A-662, H-A-703).
if len(v.Unstored) == 0 && !again && r.Unstored != nil {
again = true
r.Unstored(ctx, v, ref, words)
}
}
continue
}
@@ -163,6 +163,22 @@ func TestRepublish(t *testing.T) {
t.Errorf("sent %d, said %v: want one try and one saying of not stored", len(b.sent), b.said)
}
})
t.Run("the first artifact refused as not stored starts the build again once", func(t *testing.T) {
// design 47 H2 H-A-662, H-A-703: one start per reservation, whatever number of its artifacts are refused
b := newRepublishBed(t)
v := b.reserve(t, "m")
var started []string
b.Unstored = func(_ context.Context, v ReservedVersion, ref, _ string) {
started = append(started, v.Version+" "+ref)
}
b.refuse = "oci-artifact-registry's publish of m/prog: not stored: no blob sha256:aa"
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
b.SendQueued(ctx, b.queueAt(v, PublishClassLive, b.now))
b.SendQueued(ctx, b.queueAt(v, PublishClassLive, b.now))
if len(started) != 1 || started[0] != v.Version+" m:prog" {
t.Errorf("the build again was started %v, want once for %s", started, v.Version)
}
})
t.Run("a refusal in other words is said each time", func(t *testing.T) {
b := newRepublishBed(t)
b.reserve(t, "m")
@@ -447,9 +447,11 @@ func allSet(m map[string]string) bool {
}
// MarkHeld writes on module's reservation of version each artifact a registry holds at the version for the reservation's
// fingerprint, with the held digest, and marks it published when it was not (design 47 H2 H-A-588 (4)), in one compare-and-set.
// It answers the artifacts it newly marked, and false when the reservation stands at another version.
func (r *Reserver) MarkHeld(ctx context.Context, module, version string, held []HeldArtifact) ([]HeldArtifact, bool, error) {
// fingerprint, with the held digest, and marks it published when it was not, in one compare-and-set; in the same write each
// artifact that is neither held nor marked published loses its recorded digest and the reservation its built-at, since what
// the registries do not hold is built again (design 47 H2 H-A-588 (4), H-A-664; unstored is kept). It answers the artifacts it
// newly marked, and false when the reservation stands at another version.
func (r *Reserver) MarkHeld(ctx context.Context, module, version string, held []HeldArtifact) ([]Marked, bool, error) {
series, _, err := SplitVersion(version)
if err != nil {
return nil, false, err
@@ -462,20 +464,30 @@ func (r *Reserver) MarkHeld(ctx context.Context, module, version string, held []
}
was := cur
was.Artifacts, was.Published, was.PublishedAt = maps.Clone(cur.Artifacts), maps.Clone(cur.Published), maps.Clone(cur.PublishedAt)
var marked []HeldArtifact
var marked []Marked
changed := false
if cur.Artifacts == nil {
cur.Artifacts = map[string]string{}
}
isHeld := map[string]bool{}
for _, h := range held {
isHeld[h.Ref] = true
if cur.Artifacts[h.Ref] != h.Digest {
cur.Artifacts[h.Ref], changed = h.Digest, true
}
if !cur.Published[h.Ref] {
cur.markPublished(h.Ref, r.now())
marked, changed = append(marked, h), true
marked, changed = append(marked, Marked{Artifact: h.Ref}), true
}
}
for ref, d := range cur.Artifacts {
if d != "" && !isHeld[ref] && !cur.Published[ref] && !slices.Contains(cur.Upstream, ref) {
cur.Artifacts[ref], changed = "", true
}
}
if !cur.BuiltAt.IsZero() && !allSet(cur.Artifacts) {
cur.BuiltAt, changed = time.Time{}, true
}
if !changed {
return nil, true, nil
}
@@ -486,6 +498,9 @@ func (r *Reserver) MarkHeld(ctx context.Context, module, version string, held []
return nil, false, fmt.Errorf("%s cannot be written: %w", key, err)
}
r.said(r.reindex(ctx, key, was, cur))
for i := range marked {
marked[i].Reserved = cur
}
return marked, true, nil
}
}
@@ -187,6 +187,23 @@ func TestReservationIsReadAndMarkedPublished(t *testing.T) {
if _, ok, _ := r.MarkHeld(ctx, "m", "1.4.99", held); ok {
t.Error("a reservation at another version was marked")
}
// H-A-664: in the same write what no registry holds loses its recorded digest and the reservation its built-at; unstored is kept
nv, err := r.Reserve(ctx, "n", "0.1", []string{"n:a", "n:b"}, Source{Fingerprint: "fpn"})
if err != nil {
t.Fatal(err)
}
if _, _, err := r.Built(ctx, "n", nv.Version, map[string]string{"n:a": "sha256:a", "n:b": "sha256:b"}, nil); err != nil {
t.Fatal(err)
}
if _, err := r.MarkUnstored(ctx, "n", nv.Version, "n:b", "not stored: no blob"); err != nil {
t.Fatal(err)
}
if _, _, err := r.MarkHeld(ctx, "n", nv.Version, []HeldArtifact{{Ref: "n:a", Digest: "sha256:a"}}); err != nil {
t.Fatal(err)
}
if cur, _, _ = r.At(ctx, ReservedKey("n", "0.1")); cur.Artifacts["n:b"] != "" || cur.Artifacts["n:a"] != "sha256:a" || !cur.BuiltAt.IsZero() || cur.Unstored["n:b"] == "" || !cur.Published["n:a"] {
t.Errorf("after the marking %+v: want n:b's digest and the built-at cleared, n:a held, unstored kept", cur)
}
}
// TestAReleaseIsRecordedByFingerprintBeforeItsReservationGoes: design 47 G A-456a — the version-released of a version records