Distribution: each wait of a publish logged with its time; the window's learning no longer holds the answer

Builds: design 47 G (publish path of oci-artifact-registry; no design line covers the log lines)
This commit is contained in:
2026-11-15 01:20:04 +01:00
parent e8204a9c27
commit 99f3e23492
3 changed files with 58 additions and 6 deletions
@@ -249,10 +249,21 @@ func tools(v *holder.Verbs, windows kept[holder.Window]) []stdio.Tool {
if err != nil {
return nil, err
}
a, err := v.Publish(seat, stdio.CallerOf(args), publishOf(in))
caller := stdio.CallerOf(args)
start := time.Now()
logf("%s.publish received from %s: %s %s (%s, %d parts)", seat, caller, in.Name, in.Version, in.Kind, len(in.Parts))
a, err := v.Publish(seat, caller, publishOf(in))
if err == nil {
learnPublishing(windows, stdio.CallerOf(args))
// The window's learning asks the delivery view (up to 60 s, past the runner's 30 s call bound),
// so it never holds the answer.
go func() {
t := time.Now()
logf("learning the publishing build of %s starts (mesh-delivery-view.node_haves)", caller)
learnPublishing(windows, caller)
logf("learning the publishing build of %s ended after %s", caller, time.Since(t).Round(time.Millisecond))
}()
}
logf("%s.publish from %s answered after %s (error: %v)", seat, caller, time.Since(start).Round(time.Millisecond), err)
return publishAnswer(a), err
}},
stdio.Tool{Name: seat + "." + holder.VerbPublishPart, Description: "Send one chunk (at most 1 MiB) of one part of an open transfer, from the caller that opened it.",
@@ -468,7 +479,7 @@ func main() {
}()
base, _ := url.Parse("http://127.0.0.1:5001")
store := &holder.OCI{Base: base, Upstream: &holder.Upstream{}}
h := &holder.Holder{Objects: parts.BusObjects(holder.IncomingObjects), Builder: holder.Reserved{Ask: stdio.Ask}, Store: store, Say: say, Finding: findings.Say,
h := &holder.Holder{Logf: logf, Objects: parts.BusObjects(holder.IncomingObjects), Builder: holder.Reserved{Ask: stdio.Ask}, Store: store, Say: say, Finding: findings.Say,
Transfers: parts.BusTransfers[holder.Opening](holder.TransfersState), Cap: parts.BusCap(holder.IncomingObjects), Record: recordAct, Idle: parts.BusArm(holder.IdleState)}
files := &holder.Files{Container: or(os.Getenv("MESH_REGISTRY_CONTAINER"), "mesh-registry"), Run: holder.ExecRunner, UID: os.Getuid()}
v := &holder.Verbs{Holder: h, Catalog: store, Holds: kept[holder.Hold]{state: "holds", key: holder.Hold.Key}, Mirrors: mirrors{},
@@ -231,6 +231,21 @@ func TestTheHolderOfTheTwoImageSeats(t *testing.T) {
return PublishRequest{Transfer: id, Name: "m/program", Version: "0.1.4", Kind: KindBundle, Digest: part.Digest, Parts: []Part{part}}
}
t.Run("a publish says each of its waits with its time", func(t *testing.T) {
b := newBed(true)
var lines []string
b.h.Logf = func(f string, a ...any) { lines = append(lines, fmt.Sprintf(f, a...)) }
if _, err := b.h.Publish(ArtifactSeat, builder, req("tl")); err != nil {
t.Fatal(err)
}
all := strings.Join(lines, "\n")
for _, want := range []string{"the store's read of what it holds (the program's registry) starts", "(the program's registry) ended after", "the opening of the transfer on the bus"} {
if !strings.Contains(all, want) {
t.Errorf("no log line %q in:\n%s", want, all)
}
}
})
t.Run("a transfer in parts, cut and resumed, hashed, numbered by the builder, published", func(t *testing.T) {
b := newBed(true)
a, err := b.h.Publish(ArtifactSeat, builder, req("t1"))
@@ -173,6 +173,20 @@ type Holder struct {
// Idle writes a transfer's idle key with its own time to live, once (parts.BusArm over IdleState); the receiver
// arms it on each open that leaves a transfer open. Nil arms nothing.
Idle func(id string, ttl time.Duration) error
// Logf says each wait of a publish with its time (stderr in the bundle); nil says nothing.
Logf func(string, ...any)
}
// timed runs f and logs its name and time when the holder logs.
func (h *Holder) timed(what string, f func() error) error {
if h.Logf == nil {
return f()
}
start := time.Now()
h.Logf("publish: %s starts", what)
err := f()
h.Logf("publish: %s ended after %s (%v)", what, time.Since(start).Round(time.Millisecond), err)
return err
}
func (h *Holder) now() time.Time {
@@ -249,17 +263,29 @@ func (h *Holder) Publish(seat, caller string, r PublishRequest) (PublishAnswer,
}
// A rebuild of a held fingerprint answers the held version and stores nothing.
if r.Version != "" {
if ref, ok, err := h.Store.Held(r.Name, r.Version, r.Digest); err != nil {
var ref string
var ok bool
err := h.timed("the store's read of what it holds (the program's registry)", func() (err error) {
ref, ok, err = h.Store.Held(r.Name, r.Version, r.Digest)
return err
})
if err != nil {
return PublishAnswer{}, fmt.Errorf("publish: the store cannot say whether it holds %s@%s: %w", r.Name, r.Version, err)
} else if ok {
return PublishAnswer{Transfer: r.Transfer, Ended: true}, h.Say(seat, EventPublished, h.eventOf(seat, r, SeatReference(seat, ref), ""))
return PublishAnswer{Transfer: r.Transfer, Ended: true}, h.timed("the published event on the seat", func() error {
return h.Say(seat, EventPublished, h.eventOf(seat, r, SeatReference(seat, ref), ""))
})
}
}
wants := make([]parts.Want, 0, len(r.Parts))
for _, p := range r.Parts {
wants = append(wants, parts.Want{Digest: p.Digest, Size: p.Size})
}
got, err := h.receiver().Open(r.Transfer, caller, wants, Opening{PublishRequest: r, Seat: seat})
var got parts.Received
err := h.timed("the opening of the transfer on the bus (objects, transfer state, idle key)", func() (err error) {
got, err = h.receiver().Open(r.Transfer, caller, wants, Opening{PublishRequest: r, Seat: seat})
return err
})
if err != nil {
return answerOf(got), fmt.Errorf("publish: %w", err)
}