B1a: the builder's version floor and its wait go
The numbering from before G goes with its floor wait (design 47 H §756): the builder asks no floor (seat git.tags, the registry seats' versions, the entries' requirements), keeps no state floor-waits, serves neither builder_floor_again nor builder_floor_waits, raises no floor-silent finding and hears no take-in.taken or condition-cleared to wake one. The claim numbering that asked the floor (Numberer.Number, build.Numbers) goes with it; the reservation is the one place a version is numbered. Builds: design 47 H §756, G §372, spec 29, 41, 47, 48
This commit is contained in:
@@ -44,7 +44,7 @@ type queueAsker func(key string, value []byte) (json.RawMessage, error)
|
||||
// builder_versions, asked by a name, answers also what the verb reserved answers for it (reserve; design 47 G §572): the
|
||||
// bundle calls the seat mesh-builds through its invokes, as any caller does. Nil answers none.
|
||||
func Tools(r build.StuckReader, askAgain func(key string, value []byte) error, queue, buildAgain queueAsker, since build.LogSince, now func() time.Time, vs versions.Reader,
|
||||
fw, of versions.Reader, reserve func(name, version string) (meshbuilds.ReservedAnswer, error)) []stdio.Tool {
|
||||
of versions.Reader, reserve func(name, version string) (meshbuilds.ReservedAnswer, error)) []stdio.Tool {
|
||||
str := func(args map[string]any, k string) string { s, _ := args[k].(string); return strings.TrimSpace(s) }
|
||||
// handAct writes a reasks value of a versions hand act and answers the builder's answer, or its refusal as an error.
|
||||
handAct := func(key string, value []byte, err error) (any, error) {
|
||||
@@ -65,13 +65,6 @@ func Tools(r build.StuckReader, askAgain func(key string, value []byte) error, q
|
||||
return map[string]any{"key": key, "name": a.Name, "answer": a.Answer}, nil
|
||||
}
|
||||
return []stdio.Tool{
|
||||
{Name: versions.FloorAgainTool, Description: versions.FloorAgainDescription,
|
||||
Input: map[string]any{"type": "object", "required": []string{"name", "why"}, "properties": map[string]any{
|
||||
"name": map[string]any{"type": "string", "description": "the numbered name, <module>/<artifact>"},
|
||||
"why": map[string]any{"type": "string", "description": "why, in plain words"}}},
|
||||
Run: func(args map[string]any) (any, error) {
|
||||
return handAct(build.NewFloorAgain(str(args, "name"), str(args, "why"), stdio.CallerOf(args), now()))
|
||||
}},
|
||||
{Name: versions.OldFormTool, Description: versions.OldFormDescription,
|
||||
Input: map[string]any{"type": "object", "properties": map[string]any{
|
||||
"drop": map[string]any{"type": "string", "description": "a retired node to drop from the count by hand"},
|
||||
@@ -82,9 +75,6 @@ func Tools(r build.StuckReader, askAgain func(key string, value []byte) error, q
|
||||
}
|
||||
return versions.AnswerOldForm(of)
|
||||
}},
|
||||
{Name: versions.FloorWaitsTool, Description: versions.FloorWaitsDescription,
|
||||
Input: map[string]any{"type": "object", "properties": map[string]any{}},
|
||||
Run: func(map[string]any) (any, error) { return versions.AnswerFloorWaits(fw) }},
|
||||
{Name: versions.VersionsTool, Description: versions.VersionsDescription,
|
||||
Input: map[string]any{"type": "object", "required": []string{"name"}, "properties": map[string]any{
|
||||
"name": map[string]any{"type": "string", "description": "the package, image, bundle or archive name"},
|
||||
@@ -366,14 +356,6 @@ func main() {
|
||||
}
|
||||
return e.Value, true, nil
|
||||
}}
|
||||
fs := stdio.State(versions.FloorWaitsState)
|
||||
fr := versions.Reader{Keys: fs.Keys, Get: func(key string) (json.RawMessage, bool, error) {
|
||||
e, err := fs.Get(key)
|
||||
if err != nil || e == nil {
|
||||
return nil, false, err
|
||||
}
|
||||
return e.Value, true, nil
|
||||
}}
|
||||
ofs := stdio.State(versions.OldFormState)
|
||||
ofr := versions.Reader{Keys: ofs.Keys, Get: func(key string) (json.RawMessage, bool, error) {
|
||||
e, err := ofs.Get(key)
|
||||
@@ -429,7 +411,7 @@ func main() {
|
||||
var a meshbuilds.ReservedAnswer
|
||||
return a, json.Unmarshal(raw, &a)
|
||||
}
|
||||
tools := Tools(r, put, askQueue(stdio.State(build.QueuesState), 25*time.Second), buildAgain, stdio.Log(builds.BuilderLog).Since, time.Now, vr, fr, ofr, reserve)
|
||||
tools := Tools(r, put, askQueue(stdio.State(build.QueuesState), 25*time.Second), buildAgain, stdio.Log(builds.BuilderLog).Since, time.Now, vr, ofr, reserve)
|
||||
tools = append(tools, buildTool(&build.BuildReader{Builds: read(stdio.State("builds")), Entry: entryOf(stdio.State("builds").Get), Asked: read(stdio.State("asked")),
|
||||
Newest: newestVia(stdio.Ask), Steps: r}))
|
||||
tools = append(tools, reservedTools(rr, buildAgain, time.Now, meshhandactsclient.Recorder{Ask: stdio.Ask})...)
|
||||
|
||||
@@ -28,7 +28,7 @@ func TestBuilderVersionsByNameCallsReserved(t *testing.T) {
|
||||
called = append(called, name+"@"+version)
|
||||
return want, nil
|
||||
}
|
||||
tools := Tools(build.StuckReader{}, nil, nil, nil, nil, time.Now, none, none, none, reserve)
|
||||
tools := Tools(build.StuckReader{}, nil, nil, nil, nil, time.Now, none, none, reserve)
|
||||
for _, tl := range tools {
|
||||
if tl.Name == versions.VersionsTool {
|
||||
out, err := tl.Run(map[string]any{"name": "@novox/mesh-sdk", "version": "0.1.2"})
|
||||
|
||||
@@ -75,8 +75,6 @@ type catalogHalf struct {
|
||||
halves map[string]*views.Follower
|
||||
once sync.Once
|
||||
ctx context.Context
|
||||
// floor is told each entry change: a floor whose tags or requirements were silent is asked again (design 47 G A-119).
|
||||
floor func(context.Context)
|
||||
// holders is told each entry change: a claim of a build seat may have moved (design 47 G A-82).
|
||||
holders func()
|
||||
}
|
||||
@@ -112,9 +110,6 @@ func (c *catalogHalf) Changed(ctx context.Context) func(branch, module string, e
|
||||
c.logf("%v", err)
|
||||
}
|
||||
c.b.Entry(ctx, origin, e)
|
||||
if c.floor != nil {
|
||||
defer c.floor(ctx)
|
||||
}
|
||||
c.mu.Lock()
|
||||
was := c.named[module]
|
||||
now := namesOf(e)
|
||||
|
||||
@@ -13,8 +13,6 @@ import (
|
||||
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
|
||||
"mesh-delivery-builder/internal/versions"
|
||||
)
|
||||
|
||||
// heldWriter is the builder's finding writer: its findings are raised as they happen, so the writer holds them (design 47 G
|
||||
@@ -151,19 +149,3 @@ func (f *findings) notHeard(ctx context.Context) heard.Writer {
|
||||
return f.w.Clear(ctx, scope, rest[:i], rest[i+1:], "the builder hears it")
|
||||
}}
|
||||
}
|
||||
|
||||
// floorSaid is the floor finding (design 51 *Health and conditions*: a floor source silent): raised for a name waiting on
|
||||
// its floor, about that name, cleared once all three sources answered.
|
||||
func (f *findings) floorSaid(ctx context.Context) func(versions.FloorWait, bool) {
|
||||
return func(w versions.FloorWait, raised bool) {
|
||||
if !raised {
|
||||
f.clear(ctx, versions.FloorSilent, mcc.ScopeModule, w.Name)
|
||||
return
|
||||
}
|
||||
f.raise(ctx, finding{kind: versions.FloorSilent, scope: mcc.ScopeModule, id: w.Name, summary: w.Finding(),
|
||||
headline: "A version's floor is not known",
|
||||
explanation: "The builder numbers a name only once its registry seat, the forge bridge's tags and the indexer's requirements all answered; one of them did not.",
|
||||
resolved: "All three answered.",
|
||||
needs: "builder_floor_waits names the silent source; builder_floor_again asks again by hand."})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
@@ -323,7 +322,7 @@ func startBedWith(t *testing.T, closed bool) *bed {
|
||||
// each have their durable consumer.
|
||||
b.catalog = newCatalogHolder(t, ctx, js, ctl)
|
||||
b.catalog.buildSeats(t, ctl, map[string]string{"node-build-go": testGo, "node-build-node": testNode, "node-build-image": testImage,
|
||||
"git": "mesh-delivery-forge-bridge", "mesh-catalog": "mesh-delivery-indexer", // the floor's sources are the holders of git and mesh-catalog
|
||||
"git": "mesh-delivery-forge-bridge", "mesh-catalog": "mesh-delivery-indexer",
|
||||
"mesh-builds": builds.BuilderModule}) // the builder's own seat, whose verb reserved it answers once its definition is read (A-115, A-278)
|
||||
readers := []string{"n1_" + builds.BuilderModule, "n2_" + builds.BuilderModule}
|
||||
// Design 47 G §717, A-298: the catalog half names testAssigner the claimant of mesh-module-assigner, and its seat-holders view
|
||||
@@ -571,7 +570,7 @@ func isState(state string) func(builds.BuilderBuild) bool {
|
||||
// the digests of both bundles, both build modules' toolchains, after a fetch and a build on one node (ADR 0478 clause 4).
|
||||
func TestBuilderMakesADoneKeyWithTheDigests(t *testing.T) { // 1607/AC7
|
||||
b := startBed(t)
|
||||
// The builder's versions, findings and the floor's three sources are on the bus, the seat answering 0.1.4; two merges close
|
||||
// The builder's versions and findings are on the bus, the seat answering 0.1.4; two merges close
|
||||
// together, the first replaced before its claim. The builder numbers neither in its state versions (design 47 H H-A-159,
|
||||
// G §348, §369): the reservation is the one place a version is numbered.
|
||||
reg := b.registry(t, "n1", "0.1.4")
|
||||
@@ -622,7 +621,7 @@ func TestBuilderMakesADoneKeyWithTheDigests(t *testing.T) { // 1607/AC7
|
||||
for _, e := range b.logged(t, "netcheck") {
|
||||
if e.Event != builds.BuildSaidEvent {
|
||||
ended = append(ended, e)
|
||||
} else if e.Why == versions.SaidNumbered || e.Why == versions.SaidKept {
|
||||
} else if e.Why == "numbered" || e.Why == "kept" { // the narrations of the numbering from before G (design 47 H §756)
|
||||
t.Errorf("said = %+v, want no version of the builder's own numbered (H-A-159)", e)
|
||||
}
|
||||
}
|
||||
@@ -669,29 +668,6 @@ func TestBuilderMakesADoneKeyWithTheDigests(t *testing.T) { // 1607/AC7
|
||||
if _, err := reg.versions.Put(b.ctx, versions.Key("netcheck/tools-go", "0.1.6"), refusable); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Running-testing note (review round 1): two claims never get one number on the bus's own compare-and-set, as
|
||||
// the builder's state versions keeps them: eight claims of one name at once, eight versions.
|
||||
store := versions.Versions{Store: awaitedVersions{b: process.AwaitBucket(b.ctx, b.js, nil, builds.StateBucket(builds.BuilderModule, versions.State), "", t.Logf)}}
|
||||
numbers := make(chan string, 8)
|
||||
var claims sync.WaitGroup
|
||||
for i := range 8 {
|
||||
claims.Go(func() {
|
||||
d, _, err := store.Number(b.ctx, versions.Claim{Name: "netcheck/race", Kind: versions.KindBundle, Fingerprint: fmt.Sprintf("f%d", i)})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
numbers <- d.Version
|
||||
})
|
||||
}
|
||||
claims.Wait()
|
||||
close(numbers)
|
||||
got := map[string]bool{}
|
||||
for v := range numbers {
|
||||
got[v] = true
|
||||
}
|
||||
if len(got) != 8 {
|
||||
t.Errorf("eight claims of one name at once were numbered %v, want eight versions", slices.Sorted(maps.Keys(got)))
|
||||
}
|
||||
if got := reg.numberedOf("netcheck/tools-go"); len(got) != 0 {
|
||||
t.Errorf("version.numbered of netcheck/tools-go said %v, want none", got)
|
||||
}
|
||||
@@ -1154,10 +1130,9 @@ func TestARestartedBuilderPutsNoSecondAsk(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// registry is the part of the bed design 51's builder cases need: the builder's states versions, findings, floor-waits and
|
||||
// reasks, EVENTS with the seat oci-artifact-registry's outcomes and the builder's durable consumer of it, the builder's
|
||||
// own events kept, and the floor's three sources served on the bus as their holders answer through the tool runner
|
||||
// ({result}): the seat's versions, the seat git's tags and the indexer's indexer_requirements.
|
||||
// registry is the part of the bed design 51's builder cases need: the builder's states versions, findings and reasks, EVENTS
|
||||
// with the seat oci-artifact-registry's outcomes and the builder's durable consumer of it, the builder's own events kept, and
|
||||
// the seat's versions served on the bus as its holder answers through the tool runner ({result}).
|
||||
type registry struct {
|
||||
b *bed
|
||||
versions, findings, reasks jetstream.KeyValue
|
||||
@@ -1176,7 +1151,6 @@ func (b *bed) registry(t *testing.T, node string, seatVersions ...string) *regis
|
||||
return kv
|
||||
}
|
||||
r.versions, r.findings, r.reasks = mk(builds.StateBucket(builds.BuilderModule, versions.State)), mk(builds.StateBucket(builds.BuilderModule, mcseat.StateFindings)), mk(builds.StateBucket(builds.BuilderModule, build.ReAsksState))
|
||||
mk(builds.StateBucket(builds.BuilderModule, versions.FloorWaitsState))
|
||||
// EVENTS with two seats' outcomes, and the forge bridge's stream (a branch's end): each with the builder's durable consumer.
|
||||
for stream, subjects := range map[string][]string{
|
||||
eventsStream: {"mesh.mod.*.event.>", "mesh.seat.*.event.>"},
|
||||
@@ -1206,7 +1180,6 @@ func (b *bed) registry(t *testing.T, node string, seatVersions ...string) *regis
|
||||
}
|
||||
for subject, answer := range map[string]any{
|
||||
"mesh.seat." + ociartifactregistry.Seat + ".call.versions.>": map[string]any{"versions": listed},
|
||||
"mesh.seat.git.call.tags.>": map[string]any{"tags": []string{}},
|
||||
} {
|
||||
reply, _ := json.Marshal(map[string]any{"result": answer, "node": "ctl"})
|
||||
s, err := nc.Subscribe(subject, func(m *nats.Msg) { _ = m.Respond(reply) })
|
||||
|
||||
@@ -163,22 +163,13 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
// it, bound once the bus holds it; the builder numbers nothing in it (design 47 H H-A-159).
|
||||
versionsKV := process.AwaitBucket(ctx, js, conn, own.versions, "builder_versions answers nothing of the versions numbered before G", logger.Printf)
|
||||
found := &findings{module: cred.Module, w: fw, logf: logger.Printf, now: time.Now}
|
||||
floorWaits := &versions.FloorWaits{Holder: versions.HolderOf(branches), Logf: logger.Printf, Said: found.floorSaid(context.WithoutCancel(ctx))}
|
||||
// The names waiting on their floor are kept in the state floor-waits (DLV-B4): a restarted builder takes them in, so
|
||||
// their silent sources' events still wake them; until the state is bound they are kept here only.
|
||||
process.AwaitBucket(ctx, js, conn, builds.StateBucket(cred.Module, versions.FloorWaitsState), "the names waiting on their floor are kept in memory only, and builder_floor_waits shows none", logger.Printf).
|
||||
Ready(func(kv jetstream.KeyValue) {
|
||||
floorWaits.Keep(kvKeeper{ctx: ctx, kv: kv}, heldFloorWaits(ctx, kv, logger.Printf))
|
||||
})
|
||||
// A package is numbered under its name in its ecosystem, read from the catalog half's entries (design 32, design 47 G §348).
|
||||
numberer := &versions.Numberer{Versions: versions.Versions{Store: awaitedVersions{b: versionsKV}}, Floor: floorVia(calls.Call, versions.RequirementsFrom(versions.EntriesOf(branches))), Waits: floorWaits,
|
||||
Names: versions.NamesFrom(versions.EntriesOf(branches))}
|
||||
// The state versions kept from before G: the registry seats' words still mark its entries (design 47 H §756 removes it).
|
||||
numberer := &versions.Numberer{Versions: versions.Versions{Store: awaitedVersions{b: versionsKV}}}
|
||||
// A publish that ends badly is a finding (design 51 *Health and conditions*): a holder's refused, a version no holder
|
||||
// answered within its bound (a key of the state bounds with its own time to live), a seat's outcome that does not read.
|
||||
pubBoundsKV := process.AwaitBucket(ctx, js, conn, own.bounds, "a publish no holder answers, and a node holding the old form seven days, are not raised", logger.Printf)
|
||||
stepReads.bounds, stepReads.findings = func() jetstream.KeyValue { return pubBoundsKV.KV() }, found
|
||||
pubs := &publishes{bounds: pubBoundsKV.KV, versions: numberer.Versions, findings: found, bound: versions.PublishBound, logf: logger.Printf}
|
||||
numberer.Publishing = pubs.arm
|
||||
stepExpiry := &buildrun.Expiry{}
|
||||
var b *build.Builder
|
||||
seatsChanged := func(ctx context.Context) {
|
||||
@@ -211,9 +202,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
unput := &unputs{bounds: pubBoundsKV.KV, store: b.Claimer.Store, looking: b.Looking, findings: found,
|
||||
bound: meshconditionsclient.CallUnansweredAfter, now: time.Now, logf: logger.Printf}
|
||||
b.Left, b.Ended = unput.left, unput.ended
|
||||
// The builder numbers nothing of its own (design 47 H H-A-159, G §348, §349, §369): b.Numbers stays nil, so no trunk build
|
||||
// is numbered in the state versions, waits on a floor or arms a publish-unanswered bound of it; the reservation is the one
|
||||
// place a version is numbered. The state, kept from before G, is still read (builder_versions) until G §372 removes it.
|
||||
// The builder numbers nothing of its own and asks no floor (design 47 H §756, H H-A-159, G §348, §349, §369): the
|
||||
// reservation is the one place a version is numbered.
|
||||
// The builder's toolchain waits (design 47 G §672): its state waits, and wait-held and wait-ended on its stream waits; its
|
||||
// bound is its setting toolchain-wait-minutes.
|
||||
waitBound, err := toolchainWaitOf(getenv("MESH_BUILDER_TOOLCHAIN_WAIT_FILE"))
|
||||
@@ -269,8 +259,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
reserved.readFilled(ctx, lastKeptOf(js, cred, logger.Printf), sleeps)
|
||||
// A state bound later numbers the builds looked at without it.
|
||||
versionsKV.Ready(func(jetstream.KeyValue) { b.Reconsider(ctx) })
|
||||
// The versions' hand acts (builder_publish_again, builder_floor_again) come through reasks, as builder_build_again.
|
||||
acts := versions.Acts{Numberer: numberer, DropReserved: reserved.dropped, Reconsider: b.Reconsider}
|
||||
// The versions' hand acts (builder_publish_again, builder_reserved_drop) come through reasks, as builder_build_again.
|
||||
acts := versions.Acts{Numberer: numberer, DropReserved: reserved.dropped}
|
||||
// A reserved version left unpublished is published again, by the builder on an event or by a person's tool (design 47 G
|
||||
// §588): its items on the work queue publishes, the module's own stream of its old streams section (design 47 H2 §793, H-A-454).
|
||||
actedKV := process.AwaitBucket(ctx, js, conn, own.acted, "no version is published again on an event or by builder_publish_again", logger.Printf)
|
||||
@@ -479,9 +469,6 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
// The seat mesh-artifact-sweep says artifacts-gone when it found a key's blob gone (issue 1937, ADR 0571 §2): the
|
||||
// builder's durable consumer on EVENTS, made by the grants part from the manifest's consumes. Where it is not there yet the builder says
|
||||
// so; it still asks held at its start and at every module value.
|
||||
// The same consumer carries what wakes a floor (design 51 *The floor*): the indexer's take-in.taken (design 47 H H-A-116) and the
|
||||
// condition keeper's condition-cleared.
|
||||
floor := floorWake{b: b, waits: floorWaits, logf: logger.Printf}
|
||||
// And the four registry seats' published, refused and removed (DLV-B4), which move a numbered version.
|
||||
seatHeard := seatHearer{n: numberer, b: b, logf: logger.Printf, pub: pubs, res: reserved}
|
||||
// Each part takes the events it hears in turn; a handling over the setting slow-event is said with the part that took it
|
||||
@@ -496,7 +483,6 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
{"what a node's engine reads", func(m jetstream.Msg) bool { return reads.heard(m, logger.Printf) }}, // manifest-reads-changed (ADR 0618 §4)
|
||||
{"the toolchains reported", func(m jetstream.Msg) bool { return heardTools.Reported(ctx, m) }},
|
||||
{"the toolchains running", func(m jetstream.Msg) bool { return heardTools.Running(ctx, m) }},
|
||||
{"the floor", func(m jetstream.Msg) bool { return floor.heard(ctx, m) }},
|
||||
{"the reservations", func(m jetstream.Msg) bool { return reserved.heard(ctx, m) }},
|
||||
{"the registry seats' outcomes", func(m jetstream.Msg) bool { return seatHeard.heard(ctx, m) }},
|
||||
}
|
||||
@@ -573,15 +559,11 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
b.SayUnbuildable(ctx) // at the start, once the first views are in: the plans no seat builds in one line (§795)
|
||||
}
|
||||
branches.Changed = half.Changed(ctx)
|
||||
// A catalog revision the builder hears wakes a floor whose tags or requirements were silent (design 47 G A-119).
|
||||
half.floor = func(ctx context.Context) {
|
||||
(&floorWake{b: b, waits: floorWaits, logf: logger.Printf}).wake(ctx, versions.WakeRevision, "", "")
|
||||
}
|
||||
// All of the catalog half's wiring is set before the reader starts: its views are heard on the reader's goroutines from then.
|
||||
reader.Start(ctx, js, cred, process.AwaitBucket(ctx, js, conn, builds.StateBucket(cred.Module, views.StatusState), "builder_first_views reads nothing and builder_first_view_again is not heard", logger.Printf))
|
||||
// Every part has registered: the hub pulls the module's durable. Where the consumer is not there yet the builder says so
|
||||
// and binds it at a later change (heard.Writer; ADR 0615 §5).
|
||||
_ = notHeard.Bind(eventsStream, sweep.EventArtifactsGone+", what wakes a floor, the registry seats' words, the views and manifest-reads-changed are not heard until the builder starts again", func() error {
|
||||
_ = notHeard.Bind(eventsStream, sweep.EventArtifactsGone+", the registry seats' words, the views and manifest-reads-changed are not heard until the builder starts again", func() error {
|
||||
if err := hub.Start(ctx, js, cred); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
const namedTreePrefix = "named:"
|
||||
|
||||
// seatEventPatterns are the seats' events the builder's own handler takes off its durable consumer (its manifest's `consumes` of
|
||||
// them): the registry seats' words, artifacts-gone, the build seats' toolchain-reported, condition-cleared, the node-engine
|
||||
// seat's events, of the seat mesh-catalog, version-released and versions-filled, and the indexer's take-in.taken. The seat mesh-catalog's
|
||||
// them): the registry seats' words, artifacts-gone, the build seats' toolchain-reported, the node-engine
|
||||
// seat's events, of the seat mesh-catalog, version-released and versions-filled. The seat mesh-catalog's
|
||||
// catalog-revision and registration-changed and the seat mesh-delivery's source-moved are the views reader's (the branch
|
||||
// follower's), so no pattern here covers them: a message has one taker.
|
||||
var seatEventPatterns = func() []string {
|
||||
@@ -21,6 +21,5 @@ var seatEventPatterns = func() []string {
|
||||
for _, event := range []string{meshcatalog.EventVersionReleased, meshcatalog.EventVersionsFilled} {
|
||||
out = append(out, "mesh.seat."+meshcatalog.Seat+".event."+event, "mesh.seat."+meshcatalog.Seat+".event."+event+".>")
|
||||
}
|
||||
// And the indexer's take-in.taken, which wakes the floor (design 47 H H-A-116).
|
||||
return append(out, takenInSubject)
|
||||
return out
|
||||
}()
|
||||
|
||||
@@ -32,14 +32,11 @@ func TestTheNamesAreTheManifests(t *testing.T) {
|
||||
t.Errorf("the builder reads %s, its manifest's reads are %v", read, m.Reads)
|
||||
}
|
||||
}
|
||||
// The catalog half (design 47 G §348, §614) is followed through the seat, and no state of the indexer is; the indexer's
|
||||
// event take-in.taken wakes the floor (design 47 H H-A-116).
|
||||
if !slices.Contains(m.Consumes, "mesh-delivery-indexer.take-in.taken") {
|
||||
t.Errorf("the builder's floor wakes on no take-in.taken: its manifest consumes %v", m.Consumes)
|
||||
}
|
||||
// The catalog half (design 47 G §348, §614) is followed through the seat, and nothing of the indexer is: with the floor gone
|
||||
// (design 47 H §756) not its take-in.taken either (H-A-116).
|
||||
for _, c := range m.Consumes {
|
||||
if strings.HasPrefix(c, "mesh-delivery-indexer.") && c != "mesh-delivery-indexer.take-in.taken" {
|
||||
t.Errorf("the builder follows %s, an indexer state, its manifest consumes it", c)
|
||||
if strings.HasPrefix(c, "mesh-delivery-indexer.") {
|
||||
t.Errorf("the builder follows %s of the indexer, its manifest consumes it", c)
|
||||
}
|
||||
}
|
||||
for _, view := range []string{"mesh-catalog.catalog-revision", "mesh-catalog.registration-changed", "mesh-delivery.source-moved", "seat:mesh-module-assigner.views.assignments"} {
|
||||
|
||||
@@ -65,7 +65,7 @@ func reAsked(ctx context.Context, b askAgainer, acts versions.Acts, items *publi
|
||||
released(ctx, b, kv, e, r, logf)
|
||||
return
|
||||
}
|
||||
if r.Mode == build.ModeRepublish || r.Mode == build.ModePublishDrop || r.Mode == build.ModeFloorAgain || r.Mode == build.ModeOldFormDrop || r.Mode == build.ModeReservedDrop || r.Mode == build.ModeReserveDone {
|
||||
if r.Mode == build.ModeRepublish || r.Mode == build.ModePublishDrop || r.Mode == build.ModeOldFormDrop || r.Mode == build.ModeReservedDrop || r.Mode == build.ModeReserveDone {
|
||||
// A version's hand act (design 51 *Tools of the builder*) may build again, so it is answered beside the watch.
|
||||
go versionActed(ctx, acts, kv, e, r, logf)
|
||||
return
|
||||
@@ -196,7 +196,7 @@ func emitBuildEnded(ctx context.Context, js jetstream.JetStream, cred process.Ac
|
||||
return nil
|
||||
}
|
||||
|
||||
// versionActed answers a reasks value of builder_publish_again, builder_floor_again or builder_old_form's drop, a hand act said in the log.
|
||||
// versionActed answers a reasks value of builder_publish_again, builder_publish_drop, builder_reserve_done, builder_reserved_drop or builder_old_form's drop, a hand act said in the log.
|
||||
func versionActed(ctx context.Context, acts versions.Acts, kv jetstream.KeyValue, e jetstream.KeyValueEntry, r build.ReAsk, logf func(string, ...any)) {
|
||||
var err error
|
||||
if r.Mode == build.ModeRepublish {
|
||||
@@ -227,14 +227,10 @@ func versionActed(ctx context.Context, acts versions.Acts, kv jetstream.KeyValue
|
||||
} else {
|
||||
r.Answer, err = acts.DropReserved(ctx, r.Name, r.FP, r.By, r.Why, r.At)
|
||||
}
|
||||
} else if r.Mode == build.ModeOldFormDrop {
|
||||
if acts.DropOldForm == nil {
|
||||
err = errors.New("this builder keeps no old-form window")
|
||||
} else {
|
||||
r.Answer, err = acts.DropOldForm(ctx, r.Name, r.By, r.Why, r.At)
|
||||
}
|
||||
} else if acts.DropOldForm == nil {
|
||||
err = errors.New("this builder keeps no old-form window")
|
||||
} else {
|
||||
r.Answer, err = acts.FloorAgain(ctx, r.Name)
|
||||
r.Answer, err = acts.DropOldForm(ctx, r.Name, r.By, r.Why, r.At)
|
||||
}
|
||||
if err != nil {
|
||||
r.Answer, r.Refused = err.Error(), true
|
||||
|
||||
@@ -42,7 +42,7 @@ import (
|
||||
// its grant. The gate over the seat's assignments, and its refusal, are mesh-sdk's (buildrun.PlacedNodes,
|
||||
// issue 774).
|
||||
func TestARefusedBucketIsSaidAndThePartGoesOn(t *testing.T) {
|
||||
t.Run("a floor's wake is heard on the events consumer (design 51 The floor)", aFloorsWakeIsHeard)
|
||||
t.Run("a registry seat's outcome is heard on the events consumer (DLV-B4)", aSeatsOutcomeIsHeard)
|
||||
t.Run("a failed trunk build is a finding until a later done one (DLV-B7)", aFailedTrunkBuildIsAFinding)
|
||||
refused := refusingBus{err: errors.New("nats: permissions violation for publish to $JS.API.CONSUMER.CREATE.KV_mesh-delivery-indexer_modules")}
|
||||
if _, err := process.EssentialBucket(context.Background(), refusingBus{refuseOpen: true, err: refused.err}, "builder", "mesh-delivery-indexer_modules", "work"); err == nil ||
|
||||
@@ -250,33 +250,16 @@ func (m *wakeMsg) Headers() nats.Header {
|
||||
return nil
|
||||
}
|
||||
|
||||
func aFloorsWakeIsHeard(t *testing.T) {
|
||||
func aSeatsOutcomeIsHeard(t *testing.T) {
|
||||
var logs bytes.Buffer
|
||||
holders := map[string]string{"git": "mesh-delivery-forge-bridge", "mesh-catalog": "mesh-delivery-indexer"}
|
||||
waits := &versions.FloorWaits{Holder: func(seat string) (string, bool) { h, ok := holders[seat]; return h, ok }}
|
||||
waits.Wait("m/lib", versions.SeatGoPackages, "", versions.Floor{Silent: []string{versions.SourceRequirements}}, nil, time.Unix(0, 0))
|
||||
waits.Wait("m/img", versions.SeatImages, "", versions.Floor{Silent: []string{versions.SourceTags}}, nil, time.Unix(0, 0))
|
||||
f := &floorWake{b: &build.Builder{}, waits: waits, logf: log.New(&logs, "", 0).Printf}
|
||||
accepted := &wakeMsg{subject: takenInSubject}
|
||||
if !f.heard(context.Background(), accepted) || !accepted.acked || !strings.Contains(logs.String(), "the floor of m/lib is asked again: take-in.taken") {
|
||||
t.Fatalf("take-in.taken: acked %v, log %q", accepted.acked, logs.String())
|
||||
}
|
||||
logs.Reset()
|
||||
cleared := &wakeMsg{subject: conditionClearedSubject, data: []byte(`{"subject":{"scope":"probe","id":"ace/mesh-delivery-forge-bridge"}}`)}
|
||||
if !f.heard(context.Background(), cleared) || !strings.Contains(logs.String(), "the floor of m/img is asked again: condition-cleared") {
|
||||
t.Fatalf("condition-cleared: log %q", logs.String())
|
||||
}
|
||||
if f.heard(context.Background(), &wakeMsg{subject: sweep.SubjectArtifactsGone}) {
|
||||
t.Fatal("artifacts-gone was taken as a floor's wake")
|
||||
}
|
||||
// DLV-B4: a registry seat's outcome on the same consumer moves a version; a published wakes a name whose seat was
|
||||
// silent; one the state cannot take is left for the bus to give again.
|
||||
logs.Reset()
|
||||
waits.Wait("m/pkg", versions.SeatGoPackages, "", versions.Floor{Silent: []string{versions.SourceSeat}}, nil, time.Unix(0, 0))
|
||||
h := &seatHearer{n: &versions.Numberer{Versions: versions.Versions{Store: noVersions{}}, Waits: waits}, b: &build.Builder{}, logf: log.New(&logs, "", 0).Printf}
|
||||
// DLV-B4: a registry seat's outcome on the events consumer moves a version; a by-digest publish marks none and is taken.
|
||||
h := &seatHearer{n: &versions.Numberer{Versions: versions.Versions{Store: noVersions{}}}, b: &build.Builder{}, logf: log.New(&logs, "", 0).Printf}
|
||||
byDigest := &wakeMsg{subject: "mesh.seat.go-package-registry.event.published", data: []byte(`{"name":"m/other","digest":"sha256:aa","kind":"package","holder":"gitea"}`)}
|
||||
if !h.heard(context.Background(), byDigest) || !byDigest.acked || !strings.Contains(logs.String(), "the floor of m/pkg is asked again: go-package-registry said published") {
|
||||
t.Fatalf("published: acked %v, log %q", byDigest.acked, logs.String())
|
||||
if !h.heard(context.Background(), byDigest) || !byDigest.acked || byDigest.naked {
|
||||
t.Fatalf("published: acked %v, naked %v, log %q", byDigest.acked, byDigest.naked, logs.String())
|
||||
}
|
||||
if h.heard(context.Background(), &wakeMsg{subject: sweep.SubjectArtifactsGone}) {
|
||||
t.Fatal("artifacts-gone was taken as a seat's outcome")
|
||||
}
|
||||
// Design 47 G §369, A-415: a published of a version the reservation numbered, which the state versions does not hold, is
|
||||
// taken: its artifact is marked and package-published said, never left for the bus to give again.
|
||||
@@ -299,9 +282,6 @@ func aFloorsWakeIsHeard(t *testing.T) {
|
||||
if !h.heard(context.Background(), published) || !published.acked || published.naked || len(saidPub) != 1 || saidPub[0].Artifact != "m:program" {
|
||||
t.Fatalf("a published of a reserved version: acked %v, naked %v, said %+v, log %q", published.acked, published.naked, saidPub, logs.String())
|
||||
}
|
||||
if h.heard(context.Background(), &wakeMsg{subject: takenInSubject}) {
|
||||
t.Fatal("take-in.taken was taken as a seat's outcome")
|
||||
}
|
||||
// Design 47 G A-420: a message left for the bus is said given up on the last delivery its consumer allows, never before.
|
||||
for _, n := range []uint64{4, EventDeliveries} {
|
||||
logs.Reset()
|
||||
@@ -354,17 +334,6 @@ func aFailedTrunkBuildIsAFinding(t *testing.T) {
|
||||
if _, ok := st.vals[key]; ok {
|
||||
t.Error("a later done trunk build leaves build-failed")
|
||||
}
|
||||
// The floor finding: raised while a name waits on its floor, cleared once it is known.
|
||||
fw := &versions.FloorWaits{Said: f.floorSaid(context.Background())}
|
||||
fw.Wait("m/lib", versions.SeatGoPackages, "", versions.Floor{Silent: []string{versions.SourceTags}}, nil, time.Unix(0, 0))
|
||||
floorKey := meshconditionsclient.Key(meshconditionsclient.ScopeModule, "m/lib", versions.FloorSilent)
|
||||
if got, err := decodeFinding(st.vals[floorKey]); err != nil || !strings.Contains(got.Summary, "git.tags did not answer") {
|
||||
t.Fatalf("the floor finding = %+v, %v", got, err)
|
||||
}
|
||||
fw.Answered("m/lib")
|
||||
if _, ok := st.vals[floorKey]; ok {
|
||||
t.Error("a known floor leaves floor-silent")
|
||||
}
|
||||
// Design 51 *Health and conditions* (review round 1): a holder's refused is publish-refused with its reason, a version
|
||||
// no holder answered within its bound publish-unanswered, a seat's outcome that does not read seat-outcome-unread;
|
||||
// a later published of the name clears the first two, the seat's next outcome that reads the third.
|
||||
|
||||
@@ -689,8 +689,8 @@ func TestEventsAreHandledByAWorkerPerName(t *testing.T) {
|
||||
if got := eventKey(&wakeMsg{subject: meshcatalog.SubjectVersionReleased, data: []byte(`{"module":"m","version":"0.1.0"}`)}); got != "module m" {
|
||||
t.Errorf("a version-released's key is %q, want its module", got)
|
||||
}
|
||||
if got := eventKey(&wakeMsg{subject: takenInSubject, data: []byte(`{}`)}); got != "" {
|
||||
t.Errorf("a take-in's key is %q, want the shared worker's", got)
|
||||
if got := eventKey(&wakeMsg{subject: "mesh.seat.mesh-artifact-sweep.event.artifacts-gone", data: []byte(`{}`)}); got != "" {
|
||||
t.Errorf("an event naming no name has the key %q, want the shared worker's", got)
|
||||
}
|
||||
release := make(chan struct{})
|
||||
handled := make(chan string, 4)
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
@@ -44,8 +43,7 @@ var seatEvents = map[string]seatEvent{
|
||||
npmpackageregistry.SubjectKept: {npmpackageregistry.Seat, npmpackageregistry.EventKept},
|
||||
}
|
||||
|
||||
// seatHearer takes the registry seats' outcomes in: each moves a numbered version (versions.Numberer.Heard), and a
|
||||
// `published` that wakes a name waiting on its floor looks at every module again.
|
||||
// seatHearer takes the registry seats' outcomes in: each moves a numbered version (versions.Numberer.Heard).
|
||||
type seatHearer struct {
|
||||
n *versions.Numberer
|
||||
b *build.Builder
|
||||
@@ -83,7 +81,7 @@ func (h *seatHearer) heard(ctx context.Context, m jetstream.Msg) bool {
|
||||
if m.Headers() != nil {
|
||||
id = m.Headers().Get("x-event-id")
|
||||
}
|
||||
wake, err := h.n.Heard(ctx, se.seat, se.event, id, o)
|
||||
err := h.n.Heard(ctx, se.seat, se.event, id, o)
|
||||
if errors.Is(err, versions.ErrNotNumbered) {
|
||||
// The version is no entry of the state versions, design 51's numbering by name, which G keeps only until it is removed
|
||||
// (§372); the reservation numbers a version (§369, §52) and takes the outcome in (A-415). Heard again it would stay
|
||||
@@ -115,10 +113,6 @@ func (h *seatHearer) heard(ctx context.Context, m jetstream.Msg) bool {
|
||||
h.b.PackagePublished(o.Name, o.Version)
|
||||
}
|
||||
h.ack(m)
|
||||
if len(wake) > 0 {
|
||||
h.logf("the floor of %s is asked again: %s said %s", strings.Join(wake, ", "), se.seat, se.event)
|
||||
h.b.Reconsider(ctx)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -150,7 +144,7 @@ func (h *seatHearer) ack(m jetstream.Msg) {
|
||||
}
|
||||
}
|
||||
|
||||
// kvKeeper is the state floor-waits as versions.FloorKeeper.
|
||||
// kvKeeper is a state of the builder as a keeper of keys: Put a key's value, Delete its key.
|
||||
type kvKeeper struct {
|
||||
ctx context.Context
|
||||
kv jetstream.KeyValue
|
||||
@@ -168,27 +162,3 @@ func (k kvKeeper) Delete(key string) error {
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// heldFloorWaits are the waits floor-waits holds at the builder's start; a value that is no wait is said and left.
|
||||
func heldFloorWaits(ctx context.Context, kv jetstream.KeyValue, logf func(string, ...any)) []versions.FloorWait {
|
||||
l, err := kv.ListKeys(ctx)
|
||||
if err != nil {
|
||||
logf("%s cannot be listed, so a restart's waits are asked at their next claim: %v", versions.FloorWaitsState, err)
|
||||
return nil
|
||||
}
|
||||
defer func() { _ = l.Stop() }()
|
||||
var out []versions.FloorWait
|
||||
for k := range l.Keys() {
|
||||
e, err := kv.Get(ctx, k)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
w, err := versions.DecodeFloorWait(e.Value())
|
||||
if err != nil {
|
||||
logf("%s.%s holds what is no floor wait, left: %v", versions.FloorWaitsState, k, err)
|
||||
continue
|
||||
}
|
||||
out = append(out, w)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -5,23 +5,19 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||
gitseat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/git"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/gopackageregistry"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
|
||||
"mesh-delivery-builder/internal/build"
|
||||
"mesh-delivery-builder/internal/versions"
|
||||
)
|
||||
|
||||
// awaitedVersions is the state versions as versions.Store: bound once the bus holds it (the grants part makes it, issue
|
||||
// 1790); until then every use is an error, so a trunk build is built unnumbered and said (build.Builder.number).
|
||||
// 1790); until then every use is an error.
|
||||
type awaitedVersions struct {
|
||||
b *process.AwaitedBucket
|
||||
// bucket names the state in the error of one not on the bus yet; empty is the versions'.
|
||||
@@ -119,70 +115,6 @@ func publishedVersionsVia(call toolCaller) func(context.Context, string) ([]stri
|
||||
}
|
||||
}
|
||||
|
||||
// floorVia is the floor's three sources as calls of the builder's own account (design 51 *The floor*): the seat's verb
|
||||
// versions, the seat git's tags and the requirements the catalog half's entries name (A-119). A call that fails is that source
|
||||
// silent.
|
||||
func floorVia(call toolCaller, requirements func(context.Context, string) ([]string, error)) versions.FloorSources {
|
||||
return versions.FloorSources{
|
||||
Seat: func(_ context.Context, seat, name string) ([]string, error) {
|
||||
raw, err := call("seat:"+seat+".versions", map[string]any{"name": name})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var a struct {
|
||||
Versions []struct {
|
||||
Version string `json:"version"`
|
||||
} `json:"versions"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &a); err != nil {
|
||||
return nil, fmt.Errorf("%s's versions answered what is no list of versions: %w", seat, err)
|
||||
}
|
||||
var out []string
|
||||
for _, v := range a.Versions {
|
||||
if v.Version != "" {
|
||||
out = append(out, v.Version)
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
},
|
||||
Tags: func(ctx context.Context, repository, prefix string) ([]string, error) {
|
||||
tags, _, err := tagsVia(call)(ctx, repository, prefix)
|
||||
out := make([]string, 0, len(tags))
|
||||
for _, t := range tags {
|
||||
out = append(out, t.Tag)
|
||||
}
|
||||
return out, err
|
||||
},
|
||||
Requirements: requirements,
|
||||
}
|
||||
}
|
||||
|
||||
// tagsVia reads a repository's tags starting with prefix, each with the commit it names, through the seat git's verb tags,
|
||||
// whichever module holds the seat (design 47 G §7, A-82), page by page; its answer is read tolerantly, form 2 naming each tag's
|
||||
// commit (design 47 H2 §796, §780). away says the read met a transport fault or the error kind away (§776).
|
||||
func tagsVia(call toolCaller) func(ctx context.Context, repository, prefix string) ([]gitseat.Tag, bool, error) {
|
||||
return func(_ context.Context, repository, prefix string) ([]gitseat.Tag, bool, error) {
|
||||
var out []gitseat.Tag
|
||||
for page := int64(1); ; page++ {
|
||||
raw, err := call("seat:"+gitseat.Seat+"."+gitseat.VerbTags, gitseat.TagsInput{Repository: repository, Prefix: prefix, Page: page})
|
||||
if err != nil {
|
||||
return nil, true, err
|
||||
}
|
||||
a, _, err := gitseat.DecodeTagsAnswer(raw)
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("the seat git's tags answered what is no list of tags: %w", err)
|
||||
}
|
||||
if a.Error != "" {
|
||||
return nil, a.ErrorKind == gitseat.ErrorKindAway, fmt.Errorf("the seat git's tags: %s (%s)", a.Error, a.ErrorKind)
|
||||
}
|
||||
out = append(out, a.Tags...)
|
||||
if !a.More {
|
||||
return out, false, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// emitEvent says one of the builder's events, mesh.mod.<module>.event.<event>, with the SDK's envelope headers and id as
|
||||
// the bus's dedup id.
|
||||
func emitEvent(ctx context.Context, js jetstream.JetStream, cred process.Account, event, id string, body any) error {
|
||||
@@ -221,65 +153,3 @@ func emitSeatEvent(ctx context.Context, js jetstream.JetStream, cred process.Acc
|
||||
_, err = js.PublishMsg(pub, msg, jetstream.WithMsgID(id))
|
||||
return err
|
||||
}
|
||||
|
||||
// The events on the builder's consumer of EVENTS that wake a floor (design 51 *The floor*, DLV-B3b).
|
||||
var (
|
||||
// The indexer's take-in.taken, which the builder consumes in place of the retired manifest-accepted (design 47 H H-A-116).
|
||||
takenInSubject = "mesh.mod.mesh-delivery-indexer.event.take-in.taken"
|
||||
conditionClearedSubject = meshconditions.SubjectConditionCleared
|
||||
)
|
||||
|
||||
// floorWake asks the floor of the names an event wakes again, by looking at every module again: a trunk build is
|
||||
// numbered before its claim (build.Builder.number).
|
||||
type floorWake struct {
|
||||
b *build.Builder
|
||||
waits *versions.FloorWaits
|
||||
logf func(string, ...any)
|
||||
}
|
||||
|
||||
// heard takes a message of the consumer in when it is one that wakes a floor, acknowledged, and answers whether it was.
|
||||
func (f *floorWake) heard(ctx context.Context, m jetstream.Msg) bool {
|
||||
switch m.Subject() {
|
||||
case takenInSubject:
|
||||
f.ack(m)
|
||||
f.wake(ctx, versions.WakeTakenIn, "", "")
|
||||
case conditionClearedSubject:
|
||||
f.ack(m)
|
||||
var e meshconditions.ConditionEvent
|
||||
if err := json.Unmarshal(m.Data(), &e); err != nil {
|
||||
f.logf("%s holds what is no condition, left: %v", m.Subject(), err)
|
||||
return true
|
||||
}
|
||||
if e.Subject == nil {
|
||||
return true
|
||||
}
|
||||
for _, module := range conditionModules(e.Subject.ID) {
|
||||
f.wake(ctx, versions.WakeCleared, "", module)
|
||||
}
|
||||
default:
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (f *floorWake) ack(m jetstream.Msg) {
|
||||
if err := m.Ack(); err != nil {
|
||||
f.logf("acknowledging %s: %v", m.Subject(), err)
|
||||
}
|
||||
}
|
||||
|
||||
// wake looks at every module again when the event wakes a name, and says which.
|
||||
func (f *floorWake) wake(ctx context.Context, kind, seat, module string) {
|
||||
names := f.waits.Wake(kind, seat, module, "")
|
||||
if len(names) == 0 {
|
||||
return
|
||||
}
|
||||
f.logf("the floor of %s is asked again: %s", strings.Join(names, ", "), kind)
|
||||
f.b.Reconsider(ctx)
|
||||
}
|
||||
|
||||
// conditionModules are the tokens of a condition's subject id (`<node>/<module>`, `<module>.<check>`): a module named
|
||||
// among them is the one whose condition cleared.
|
||||
func conditionModules(id string) []string {
|
||||
return strings.FieldsFunc(id, func(r rune) bool { return r == '/' || r == '.' || r == ':' })
|
||||
}
|
||||
|
||||
@@ -23,11 +23,6 @@ func TestAnEntryOfTheCatalogHalfIsTheFormTheBuilderBuildsBy(t *testing.T) {
|
||||
!reflect.DeepEqual(got.Inputs2.Paths, map[string]string{"a/b": "lib", "c": "lib"}) {
|
||||
t.Errorf("ModuleOf = %+v", got)
|
||||
}
|
||||
// A module value carries no source stamp (design 47 H H-A-48): its claim is numbered per fingerprint, naming no source
|
||||
// revision and no merge.
|
||||
if c := ClaimOf("netcheck", got, Plan{}); c.Revision != "" || c.Merge != 0 || c.Fingerprint != "src2:f" {
|
||||
t.Errorf("ClaimOf = %+v", c)
|
||||
}
|
||||
if bare := ModuleOf(meshcatalog.CatalogEntry{Module: "m"}); bare.Inputs2 != nil || bare.Fp2 != "" {
|
||||
t.Errorf("ModuleOf of an entry with none = %+v, want nothing set", bare)
|
||||
}
|
||||
|
||||
@@ -11,93 +11,10 @@ import (
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/trunk"
|
||||
|
||||
"mesh-delivery-builder/internal/versions"
|
||||
)
|
||||
|
||||
// Numbers numbers a trunk build at its claim (novox/hq design 51 *The versions*, ADR 0606, ADR 0617 §1) and records the
|
||||
// digests it was built with. Nil numbers nothing.
|
||||
type Numbers interface {
|
||||
// done is the digests of the build's key when it is done already (versions.BuildClaim.Done), nil otherwise.
|
||||
Number(ctx context.Context, module string, m meshcatalog.ModulesByModuleValue, plan Plan, done map[string]string) (versions.Numbering, error)
|
||||
Built(ctx context.Context, module string, m meshcatalog.ModulesByModuleValue, plan Plan, got versions.Numbering, made []builds.BuiltArtifact) error
|
||||
}
|
||||
|
||||
// VersionNumbers is Numbers over the builder's state versions.
|
||||
type VersionNumbers struct {
|
||||
N *versions.Numberer
|
||||
}
|
||||
|
||||
// ClaimOf is the claim a module value's trunk build is numbered by, per fingerprint: a module value carries no source stamp
|
||||
// (design 47 H H-A-48), so the claim names no source revision and no merge.
|
||||
func ClaimOf(module string, m meshcatalog.ModulesByModuleValue, plan Plan) versions.BuildClaim {
|
||||
c := versions.BuildClaim{Module: module, Path: m.Path, Repository: trunk.RepositoryName(m.Repository), Fingerprint: m.Fp2,
|
||||
Commit: m.Commit}
|
||||
for _, t := range plan.Tasks {
|
||||
c.Artifacts = append(c.Artifacts, versions.ClaimArtifact{Artifact: t.Artifact, Kind: t.Kind, Language: t.Language})
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func (v VersionNumbers) Number(ctx context.Context, module string, m meshcatalog.ModulesByModuleValue, plan Plan, done map[string]string) (versions.Numbering, error) {
|
||||
c := ClaimOf(module, m, plan)
|
||||
c.Done = done
|
||||
return v.N.Number(ctx, c)
|
||||
}
|
||||
|
||||
func (v VersionNumbers) Built(ctx context.Context, module string, m meshcatalog.ModulesByModuleValue, plan Plan, got versions.Numbering, made []builds.BuiltArtifact) error {
|
||||
digests := map[string]string{}
|
||||
for _, a := range made {
|
||||
digests[a.Name] = a.Digest
|
||||
}
|
||||
return v.N.Built(ctx, ClaimOf(module, m, plan), got, digests)
|
||||
}
|
||||
|
||||
// number numbers a trunk build's artifacts before its claim: false
|
||||
// when it waits for its floor (a package, design 51 *The floor*), and then nothing is claimed; the floor's wake looks at
|
||||
// the module again.
|
||||
func (b *Builder) number(ctx context.Context, module string, m meshcatalog.ModulesByModuleValue, plan Plan) (versions.Numbering, bool) {
|
||||
if b.Numbers == nil {
|
||||
return versions.Numbering{}, true
|
||||
}
|
||||
done := b.doneDigests(ctx, module, m.Fp2)
|
||||
got, err := b.Numbers.Number(ctx, module, m, plan, done)
|
||||
for _, s := range got.Said {
|
||||
b.logf("%s at %s: %s", module, m.Fp2, s.Line)
|
||||
// And in the build log (design 51 *The versions*: it says a version was kept, and why), between the build's start and end.
|
||||
// A look at a key already done builds nothing and has no start or end: a version kept there says nothing new, and is
|
||||
// not logged (each later look, a first view answered or a name heard, would add one).
|
||||
if b.Log != nil && !(done != nil && s.Why == versions.SaidKept) {
|
||||
b.Log(builds.BuildLogEntry{Event: builds.BuildSaidEvent, Module: module, FP: m.Fp2, Commit: m.Commit, Node: b.Node,
|
||||
At: time.Now().UTC(), Line: s.Line, Why: s.Why})
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
// Said, and built as before: an unnumbered build is published by its digest (ADR 0617 §1), numbered at its next look.
|
||||
b.logf("%s at %s: %v", module, m.Fp2, fmt.Errorf("not numbered, the versions cannot be used: %w", err))
|
||||
return versions.Numbering{}, true
|
||||
}
|
||||
if done != nil && len(got.Versions) > 0 && b.Reserved != nil {
|
||||
// A late look numbered a done build: G §349 retires numbering at a look, so one with no reservation and no release is
|
||||
// said aloud with the recovery that reserves it (A-455), never taken in silently.
|
||||
_, reserved, rerr := b.Reserved.ReservedFor(ctx, module, m.Fp2)
|
||||
released, derr := b.Reserved.ReleasedFor(ctx, module, m.Fp2)
|
||||
if rerr == nil && derr == nil && !reserved && !released {
|
||||
b.logf("%s at %s: a late look numbered this done build (%v) and no version is reserved for it: builder_reserve_done reserves one and queues its publish", module, m.Fp2, got.Versions)
|
||||
}
|
||||
}
|
||||
if got.Refused != "" {
|
||||
b.logf("%s at %s: %s", module, m.Fp2, got.Refused)
|
||||
return got, true
|
||||
}
|
||||
if got.Wait != "" {
|
||||
b.logf("%s at %s is not built yet: %s", module, m.Fp2, got.Wait)
|
||||
return got, false
|
||||
}
|
||||
return got, true
|
||||
}
|
||||
|
||||
// doneDigests are the digests of a trunk build's key by artifact when the key is done, nil otherwise or when it cannot be
|
||||
// read: a look at a done build numbers what it left unnumbered with them (versions.BuildClaim.Done).
|
||||
func (b *Builder) doneDigests(ctx context.Context, module, fp string) map[string]string {
|
||||
|
||||
@@ -104,9 +104,6 @@ type Builder struct {
|
||||
// time.Now. Node is the node the builder runs on, which asked the build.
|
||||
Now func() time.Time
|
||||
Node string
|
||||
// Numbers numbers each trunk build at its claim and records what it was built with (design 51 *The versions*); nil
|
||||
// numbers nothing, as the builder's program leaves it (design 47 H H-A-159: the reservation numbers, G §369).
|
||||
Numbers Numbers
|
||||
// Reserved reserves the version of a trunk build at its start (design 47 G §369); nil reserves nothing.
|
||||
Reserved Reservations
|
||||
// Picture answers the source revision the builder's picture of a watched branch holds, false while it holds none (design 47
|
||||
@@ -719,14 +716,6 @@ func (b *Builder) try(ctx context.Context, module string, m meshcatalog.ModulesB
|
||||
byEvent := b.events[key]
|
||||
delete(b.events, key)
|
||||
b.mu.Unlock()
|
||||
var numbering versions.Numbering
|
||||
if trunk && planErr == nil && !nothing {
|
||||
var goOn bool
|
||||
if numbering, goOn = b.number(ctx, module, m, plan); !goOn {
|
||||
end("is not built yet: it waits for its package's floor, nothing is claimed")
|
||||
return
|
||||
}
|
||||
}
|
||||
// Only a build of the registration's first watched branch reserves and releases a version (design 47 G §371).
|
||||
reserving := trunk && b.originOf(key).First && planErr == nil && !nothing && b.reserves(ctx, module, m, plan)
|
||||
if trunk && b.originOf(key).First && planErr == nil && !nothing && !reserving {
|
||||
@@ -805,10 +794,6 @@ func (b *Builder) try(ctx context.Context, module string, m meshcatalog.ModulesB
|
||||
// A trunk build that reserves is never built without its version: it would end done and publish nothing, and its key would
|
||||
// stay done, never built again (A-490). The key fails with why and is taken again at the next look or by builder_build_again.
|
||||
result = failed("no version is reserved for this build: the builder's journal says why, and it is built again once one can be")
|
||||
} else if numbering.Refused != "" && cl.Build.State != builds.BuildDone {
|
||||
// Refused, naming the state it could not read, and built against no guess (ADR 0666 §15; design 47, test 70): the key
|
||||
// fails with why, and is taken again at the next look.
|
||||
result = failed("%s", numbering.Refused)
|
||||
} else if nothing {
|
||||
// A manifest with no artifact is built by building nothing: its key is done with no artifact, claimed and written as
|
||||
// any other, so the controller has a done key to register it from (issue 1613, ADR 0478 clause 1, ADR 0501 clause 1).
|
||||
@@ -858,11 +843,6 @@ func (b *Builder) try(ctx context.Context, module string, m meshcatalog.ModulesB
|
||||
ended := LogEnded(module, m, "", b.Node, b.now(), result)
|
||||
ended.OutOfStep = b.takeOutOfStep(key) // the generated files the build module's compare found out of step (design 26)
|
||||
b.logBuild(ended)
|
||||
if result.State == builds.BuildDone && b.Numbers != nil && len(numbering.Versions) > 0 {
|
||||
if err := b.Numbers.Built(ctx, module, m, plan, numbering, result.Artifacts); err != nil {
|
||||
b.logf("%s: %v", cl.Key, err)
|
||||
}
|
||||
}
|
||||
if result.State == builds.BuildDone && hasReserved {
|
||||
digests := map[string]string{}
|
||||
for _, a := range result.Artifacts {
|
||||
|
||||
@@ -23,8 +23,6 @@ import (
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
|
||||
"mesh-delivery-builder/internal/versions"
|
||||
)
|
||||
|
||||
// buildModules simulates the two build modules on the nodes: a long tool answers a step and key at once and writes the
|
||||
@@ -552,88 +550,21 @@ func TestABundleAndAnImageOfOneModuleBuildOnOneNodeEach(t *testing.T) { // 1705a
|
||||
}
|
||||
}
|
||||
|
||||
func TestATrunkImageCallCarriesPublish(t *testing.T) { // 1705b; design 51 *The versions*: numbered at the claim
|
||||
func TestATrunkImageCallCarriesPublish(t *testing.T) { // 1705b; design 47 H §756: a trunk build is claimed and built, asking no floor
|
||||
r := newRig(t, imageArt)
|
||||
r.puller = "ace"
|
||||
nums := &fakeNumbers{wait: "m/img: the package waits for its floor"}
|
||||
r.b.Numbers = nums
|
||||
r.b.Module(context.Background(), "m", moduleValue(t, "modules/m"))
|
||||
r.b.Wait()
|
||||
if _, ok := r.st.vals[r.key]; ok || nums.numbered != 1 {
|
||||
t.Fatalf("a build waiting for its floor was claimed (numbered %d times)", nums.numbered)
|
||||
}
|
||||
nums.wait, nums.versions = "", map[string]string{"img": "0.1.4"}
|
||||
r.consider(t, "modules/m")
|
||||
calls := r.bm.callsOf("build_image_build")
|
||||
if len(calls) != 1 || calls[0].body.(map[string]any)["publish"] != true {
|
||||
t.Errorf("calls = %+v, want publish true", calls)
|
||||
}
|
||||
if nums.built["img"] != digest {
|
||||
t.Errorf("the built digest recorded = %v, want %s for img", nums.built, digest)
|
||||
}
|
||||
if nums.done != nil {
|
||||
t.Errorf("a build still to make was numbered with done digests %v", nums.done)
|
||||
}
|
||||
// The indexer's packages state names a package of the module (PackageNamed): the done build is looked at again and
|
||||
// numbered with its key's digests, so version.numbered carries them for the late publish; nothing is built again.
|
||||
looks := nums.numbered
|
||||
// nothing is built again.
|
||||
r.b.PackageNamed(context.Background(), "m")
|
||||
r.b.Wait()
|
||||
if nums.numbered != looks+1 || nums.done["img"] != digest || len(r.bm.callsOf("build_image_build")) != 1 {
|
||||
t.Errorf("a named package's done build: numbered %d more times with %v, %d image builds; want once with img %s and no build",
|
||||
nums.numbered-looks, nums.done, len(r.bm.callsOf("build_image_build")), digest)
|
||||
if n := len(r.bm.callsOf("build_image_build")); n != 1 {
|
||||
t.Errorf("a named package's done build was built again: %d image builds, want 1", n)
|
||||
}
|
||||
// A late look that numbers a done build with no reservation is said aloud, naming builder_reserve_done (G §349, A-455).
|
||||
late := &logged{}
|
||||
r.b.Logf, r.b.Reserved = late.logf, &fakeReservations{filled: true}
|
||||
r.b.PackageNamed(context.Background(), "m")
|
||||
r.b.Wait()
|
||||
if !late.has("late look numbered", "builder_reserve_done") {
|
||||
t.Errorf("a late look numbered a done build with no reservation and said %v", late.lines)
|
||||
}
|
||||
r.b.Reserved = nil
|
||||
looks = nums.numbered
|
||||
r.b.PackageNamed(context.Background(), "other")
|
||||
r.b.Wait()
|
||||
if nums.numbered != looks {
|
||||
t.Errorf("a module the builder does not know was looked at")
|
||||
}
|
||||
// D-B5 (ADR 0666 §15; design 47, test 70): a build whose published packages cannot be read is refused, naming the
|
||||
// state: its key fails with why, and nothing is built.
|
||||
unread := newRig(t, imageArt)
|
||||
unread.puller = "ace"
|
||||
unread.b.Numbers = &fakeNumbers{refused: "m/img: refused: the builder's state versions (bucket mesh-delivery-builder_versions) cannot be read"}
|
||||
unread.b.Module(context.Background(), "m", moduleValue(t, "modules/m"))
|
||||
unread.b.Wait()
|
||||
if v := valueOf(t, unread.st, unread.key); v.State != builds.BuildFailed || !strings.Contains(v.Error, "state versions") || len(unread.bm.callsOf("build_image_build")) != 0 {
|
||||
t.Errorf("a build with its versions unread: key %+v, %d builds; want failed naming the state, none built", v, len(unread.bm.callsOf("build_image_build")))
|
||||
}
|
||||
}
|
||||
|
||||
// fakeNumbers is Numbers that answers what it is set to and keeps the digests a done build recorded.
|
||||
type fakeNumbers struct {
|
||||
wait string
|
||||
versions map[string]string
|
||||
numbered int
|
||||
built map[string]string
|
||||
done map[string]string // the done key's digests the last look numbered with
|
||||
refused string // answered as Numbering.Refused
|
||||
}
|
||||
|
||||
func (f *fakeNumbers) Number(_ context.Context, _ string, _ meshcatalog.ModulesByModuleValue, _ Plan, done map[string]string) (versions.Numbering, error) {
|
||||
f.done = done
|
||||
f.numbered++
|
||||
return versions.Numbering{Wait: f.wait, Versions: f.versions, Refused: f.refused}, nil
|
||||
}
|
||||
|
||||
func (f *fakeNumbers) Built(_ context.Context, _ string, _ meshcatalog.ModulesByModuleValue, _ Plan, got versions.Numbering, made []builds.BuiltArtifact) error {
|
||||
f.built = map[string]string{}
|
||||
for _, a := range made {
|
||||
if got.Versions[a.Name] != "" {
|
||||
f.built[a.Name] = a.Digest
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestAnUnpinnedUpstreamFailsNotPinnedAndIsNeverBuiltAgain(t *testing.T) { // B3, ADR 0498 clause 4
|
||||
|
||||
@@ -56,7 +56,7 @@ type ReAsk struct {
|
||||
Failed string `json:"failed,omitempty"`
|
||||
Revision uint64 `json:"revision,omitempty"`
|
||||
Asks map[string]string `json:"asks,omitempty"`
|
||||
// Name is the numbered name (`<module>/<artifact>`) of a ModeFloorAgain value; Version is a ModeRepublish value's
|
||||
// Name is the module or node a hand act names; Version is a ModeRepublish value's
|
||||
// request and Queued the builder's answer to it: the versions it queued, `<module> <version>`.
|
||||
Name string `json:"name,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
@@ -92,9 +92,6 @@ func NewPublishAct(mode, module, version, why, by string, at time.Time) (string,
|
||||
return mode + "." + strconv.FormatInt(at.UnixNano(), 10), data, err
|
||||
}
|
||||
|
||||
// ModeFloorAgain is the Mode of a reasks value of builder_floor_again (design 51 *The floor*).
|
||||
const ModeFloorAgain = "floor-again"
|
||||
|
||||
// NewRepublish is the value builder_publish_again writes (design 47 G §588): its key, `republish.<unix nanoseconds>`
|
||||
// (a call is one value, never a build key), and the value. Module and version are each optional.
|
||||
func NewRepublish(module, version, why, by string, at time.Time) (string, []byte, error) {
|
||||
@@ -109,20 +106,6 @@ func NewRepublish(module, version, why, by string, at time.Time) (string, []byte
|
||||
return "republish." + strconv.FormatInt(at.UnixNano(), 10), data, err
|
||||
}
|
||||
|
||||
// NewFloorAgain is the value builder_floor_again writes for a name: the key `floor.<name escaped>`, never a build key,
|
||||
// and the value.
|
||||
func NewFloorAgain(name, why, by string, at time.Time) (string, []byte, error) {
|
||||
name = strings.TrimSpace(name)
|
||||
if module, artifact, ok := strings.Cut(name, "/"); !ok || module == "" || artifact == "" {
|
||||
return "", nil, fmt.Errorf("name %q is not a numbered name, <module>/<artifact>, as builder_versions lists it", name)
|
||||
}
|
||||
if strings.TrimSpace(why) == "" {
|
||||
return "", nil, errors.New("say why the floor is asked again (why)")
|
||||
}
|
||||
data, err := json.Marshal(ReAsk{V: 1, Why: strings.TrimSpace(why), By: by, At: at.UTC(), Mode: ModeFloorAgain, Name: name})
|
||||
return "floor." + versions.EscapeToken(name), data, err
|
||||
}
|
||||
|
||||
// ModeOldFormDrop is the Mode of a reasks value of builder_old_form's drop (design 51 *Every build keeps the old
|
||||
// reference form*): a retired node dropped from the count by hand; Name is the node.
|
||||
const ModeOldFormDrop = "old-form-drop"
|
||||
|
||||
@@ -2,22 +2,12 @@ package versions
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// The tools' descriptions.
|
||||
const (
|
||||
FloorAgainDescription = "Refused for every name: the builder numbers nothing of its own and asks no floor (design 47 H H-A-159); " +
|
||||
"a version is numbered by the reservation (design 47 G §369, builder_reserved). Kept until design 47 G §372 removes it with " +
|
||||
"the state versions."
|
||||
)
|
||||
|
||||
// Acts are the builder's hand acts on its versions, answered by its program (the tools bundle writes them to reasks).
|
||||
type Acts struct {
|
||||
Numberer *Numberer
|
||||
// Reconsider looks at every module again, so a claim asks a name's floor.
|
||||
Reconsider func(ctx context.Context)
|
||||
// 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)
|
||||
// DropOldForm drops a retired node from the old form's count by hand (builder_old_form): its answer, or why not.
|
||||
@@ -30,10 +20,3 @@ type Acts struct {
|
||||
// PublishDrop terminates one publish item (builder_publish_drop, design 47 H2 §793): the answer, or why not.
|
||||
PublishDrop func(ctx context.Context, module, version, by, why string) (string, error)
|
||||
}
|
||||
|
||||
// FloorAgain is builder_floor_again of name: refused, since the builder numbers nothing of its own and no claim asks a floor
|
||||
// (design 47 H H-A-159; the reservation numbers, G §369). The tool stays until G §372 removes it with the state versions.
|
||||
func (a Acts) FloorAgain(_ context.Context, name string) (string, error) {
|
||||
return "", fmt.Errorf("the floor of %s is not asked: the builder numbers nothing of its own and asks no floor (design 47 H H-A-159); "+
|
||||
"a version is numbered by the reservation (G §369, builder_reserved)", name)
|
||||
}
|
||||
|
||||
@@ -2,10 +2,7 @@ package versions
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// The registry seats a version is published to (design 51 *The seats*), by what is published.
|
||||
@@ -55,206 +52,8 @@ func TagPrefix(path string) string {
|
||||
return path + "/v"
|
||||
}
|
||||
|
||||
// ClaimArtifact is one artifact of a trunk build to number.
|
||||
type ClaimArtifact struct {
|
||||
Artifact, Kind, Language string
|
||||
}
|
||||
|
||||
// BuildClaim is a trunk build at its claim: what Numberer.Number numbers.
|
||||
type BuildClaim struct {
|
||||
Module, Path, Repository, Fingerprint, Commit, Series string
|
||||
// Revision is the source revision of the merge (a package is numbered per revision); Merge its sequence, for order.
|
||||
Revision string
|
||||
Merge uint64
|
||||
Artifacts []ClaimArtifact
|
||||
// Done are the digests of the build's done key, by artifact, when the claim is a look at a build already done: what it
|
||||
// left unnumbered (a package whose name was not known yet, a floor that was silent) is numbered with them, so
|
||||
// version.numbered carries the digest its build module publishes late. Nil for a build still to make.
|
||||
Done map[string]string
|
||||
}
|
||||
|
||||
// Numbering is what the claim got.
|
||||
type Numbering struct {
|
||||
// Versions are each artifact's version, by artifact; an artifact built unnumbered (its floor not known) has none.
|
||||
Versions map[string]string
|
||||
// Unnumbered are the artifacts built and published by digest, numbered once their floor answers (ADR 0617 §1).
|
||||
Unnumbered []string
|
||||
// Wait is why the build waits: a package whose floor is not known (design 51 *The floor*). Nothing is claimed.
|
||||
Wait string
|
||||
// Said are the builder's narrations of each decision, for its process log and its build log (build.said).
|
||||
Said []Narration
|
||||
// Names are the names each numbered artifact was numbered under, by artifact (NameOf, or a package's name in its
|
||||
// ecosystem).
|
||||
Names map[string]string
|
||||
// Refused is why the build is refused: a package's published versions could not be read (ADR 0666 §15). Nothing else
|
||||
// is numbered.
|
||||
Refused string
|
||||
}
|
||||
|
||||
// NameOf is the name artifact of module was numbered under in this numbering.
|
||||
func (g Numbering) NameOf(module, artifact string) string {
|
||||
if name := g.Names[artifact]; name != "" {
|
||||
return name
|
||||
}
|
||||
return NameOf(module, artifact)
|
||||
}
|
||||
|
||||
// Narration is one line the builder says in its build log (design 51: the build log says a version was kept, and
|
||||
// why), and what it narrates.
|
||||
type Narration struct{ Line, Why string }
|
||||
|
||||
// What a narration of the build log narrates (the build.said entry's why).
|
||||
const (
|
||||
SaidNumbered = "numbered"
|
||||
SaidKept = "kept"
|
||||
SaidWaiting = "waiting"
|
||||
SaidUnnumbered = "unnumbered"
|
||||
SaidOldFormClosed = "old-form-closed"
|
||||
)
|
||||
|
||||
// narrationOf is a decision's narration.
|
||||
func narrationOf(name string, d Decision) Narration {
|
||||
why := SaidNumbered
|
||||
switch {
|
||||
case d.Keep:
|
||||
why = SaidKept
|
||||
case d.Wait:
|
||||
why = SaidWaiting
|
||||
case d.Unnumbered:
|
||||
why = SaidUnnumbered
|
||||
}
|
||||
return Narration{Line: name + ": " + d.Why, Why: why}
|
||||
}
|
||||
|
||||
// Numberer numbers trunk builds at their claim (design 51 *The versions*, DLV-B2, B3): it asks a name's floor only
|
||||
// when versions holds nothing for it, and records a silent floor as a wait (FloorWaits, woken by its source's event).
|
||||
// Numberer holds the state versions kept from before G (design 51 *The versions*): the builder numbers nothing in it at a
|
||||
// claim and asks no floor (design 47 H §756, H H-A-159); the registry seats' words still mark its entries (Heard).
|
||||
type Numberer struct {
|
||||
Versions Versions
|
||||
Floor FloorSources
|
||||
Waits *FloorWaits
|
||||
// Holder is the module holding a seat, whose health condition's clear wakes a silent seat source; nil names none.
|
||||
Holder func(seat string) string
|
||||
// Names answers a package's name in its ecosystem; nil numbers a package as NameOf names it.
|
||||
Names PackageNames
|
||||
// Publishing is told each version Built recorded that is still numbered, its holder's word not heard yet: the
|
||||
// builder arms its publish bound (publish.go); nil arms none.
|
||||
Publishing func(ctx context.Context, e Entry)
|
||||
Now func() time.Time
|
||||
}
|
||||
|
||||
// Number numbers every numbered artifact of c. An error is a store that cannot be read or written: the claim is then
|
||||
// built as before, unnumbered, and said.
|
||||
func (n *Numberer) Number(ctx context.Context, c BuildClaim) (Numbering, error) {
|
||||
out := Numbering{Versions: map[string]string{}, Names: map[string]string{}}
|
||||
arts := append([]ClaimArtifact(nil), c.Artifacts...)
|
||||
sort.Slice(arts, func(i, j int) bool { return arts[i].Artifact < arts[j].Artifact })
|
||||
for _, a := range arts {
|
||||
seat, kind, ok := SeatOf(a.Kind, a.Language)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
name := NameOf(c.Module, a.Artifact)
|
||||
if kind == KindPackage && n.Names != nil {
|
||||
// A package is numbered, asked for its floor and published under its name in its ecosystem (design 32), the
|
||||
// name the holder's builder_versions question and the seat's versions name it by.
|
||||
named, known, err := n.Names(ctx, c.Module, a.Artifact)
|
||||
if err != nil || !known {
|
||||
why := "the indexer's packages state names no name of it in its ecosystem yet (it writes one at the module's next trunk merge)"
|
||||
if err != nil {
|
||||
why = "the indexer's packages state cannot be read: " + err.Error()
|
||||
}
|
||||
out.Unnumbered = append(out.Unnumbered, a.Artifact)
|
||||
out.Said = append(out.Said, Narration{Line: name + ": built unnumbered: " + why, Why: SaidUnnumbered})
|
||||
continue
|
||||
}
|
||||
name = named
|
||||
}
|
||||
out.Names[a.Artifact] = name
|
||||
entries, err := n.Versions.Of(ctx, name)
|
||||
if err != nil && kind == KindPackage {
|
||||
// A build that cannot read the published packages refuses, naming the unread state, never building against a
|
||||
// guess (ADR 0666 §15; design 51 *The versions*, line 287).
|
||||
out.Refused = fmt.Sprintf("%s: refused: the builder's state %s cannot be read, so its published versions are not known: %v", name, State, err)
|
||||
return out, nil
|
||||
}
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
var floor Floor
|
||||
var why map[string]string
|
||||
if len(entries) == 0 {
|
||||
floor, why = n.askFloor(ctx, seat, name, c)
|
||||
}
|
||||
d, _, err := n.Versions.Number(ctx, Claim{Name: name, Kind: kind, Series: c.Series, Module: c.Module, Fingerprint: c.Fingerprint,
|
||||
Commit: c.Commit, Revision: c.Revision, Digest: c.Done[a.Artifact], Seat: seat, Merge: c.Merge, Floor: floor})
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
out.Said = append(out.Said, narrationOf(name, d))
|
||||
switch {
|
||||
case d.Wait:
|
||||
n.wait(name, seat, floor, why)
|
||||
out.Wait = name + ": " + d.Why
|
||||
return out, nil
|
||||
case d.Unnumbered:
|
||||
n.wait(name, seat, floor, why)
|
||||
out.Unnumbered = append(out.Unnumbered, a.Artifact)
|
||||
continue
|
||||
}
|
||||
if n.Waits != nil {
|
||||
n.Waits.Answered(name)
|
||||
}
|
||||
out.Versions[a.Artifact] = d.Version
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (n *Numberer) askFloor(ctx context.Context, seat, name string, c BuildClaim) (Floor, map[string]string) {
|
||||
return n.Floor.Ask(ctx, FloorOf{Seat: seat, Name: name, Repository: c.Repository, Prefix: TagPrefix(c.Path)})
|
||||
}
|
||||
|
||||
func (n *Numberer) wait(name, seat string, f Floor, why map[string]string) {
|
||||
if n.Waits == nil {
|
||||
return
|
||||
}
|
||||
holder := ""
|
||||
if n.Holder != nil {
|
||||
holder = n.Holder(seat)
|
||||
}
|
||||
now := time.Now()
|
||||
if n.Now != nil {
|
||||
now = n.Now()
|
||||
}
|
||||
n.Waits.Wait(name, seat, holder, f, why, now)
|
||||
}
|
||||
|
||||
// Built records the digest each numbered artifact was built with, on an entry that holds none yet or was never published: what the holder's
|
||||
// builder_versions question compares (ADR 0605 §4).
|
||||
func (n *Numberer) Built(ctx context.Context, c BuildClaim, got Numbering, digests map[string]string) error {
|
||||
var errs []string
|
||||
for artifact, version := range got.Versions {
|
||||
d := digests[artifact]
|
||||
if d == "" {
|
||||
continue
|
||||
}
|
||||
e, err := n.Versions.Mark(ctx, got.NameOf(c.Module, artifact), version, func(e *Entry) {
|
||||
// The new digest replaces the recorded one only while no published was said for the number (design 51
|
||||
// *Tools of the builder*): a rebuild of a gone file under the same number.
|
||||
if e.Digest == "" || e.State == Numbered || e.State == Refused {
|
||||
e.Digest = d
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
errs = append(errs, err.Error())
|
||||
continue
|
||||
}
|
||||
if e.State == Numbered && n.Publishing != nil {
|
||||
n.Publishing(ctx, e)
|
||||
}
|
||||
}
|
||||
if len(errs) > 0 {
|
||||
sort.Strings(errs)
|
||||
return fmt.Errorf("the built digests could not be recorded: %s", strings.Join(errs, "; "))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -122,20 +122,3 @@ func EntriesOf(branches *meshcatalogclient.Branches) Entries {
|
||||
func HolderOf(branches *meshcatalogclient.Branches) func(seat string) (string, bool) {
|
||||
return branches.Claimant
|
||||
}
|
||||
|
||||
// RequirementsFrom answers the versions of a package the entries of every followed half require, each once, in order: what a
|
||||
// consumer's entry names for it in its packages (design 47 G A-119), the floor's third source.
|
||||
func RequirementsFrom(all Entries) func(ctx context.Context, name string) ([]string, error) {
|
||||
return func(_ context.Context, name string) ([]string, error) {
|
||||
seen := map[string]bool{}
|
||||
var out []string
|
||||
for _, e := range all() {
|
||||
if v := e.Packages[name]; v != "" && !seen[v] {
|
||||
seen[v] = true
|
||||
out = append(out, v)
|
||||
}
|
||||
}
|
||||
sort.Strings(out)
|
||||
return out, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,22 +66,3 @@ func TestPackageNamesAreReadFromTheCatalogHalfsEntries(t *testing.T) {
|
||||
t.Errorf("CarriersFrom(twin) = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 G A-119: the floor's requirements are what the catalog half's entries name for the package, each version once.
|
||||
func TestRequirementsFromAreTheVersionsEntriesNameForAPackage(t *testing.T) {
|
||||
entries := func() []meshcatalog.CatalogEntry {
|
||||
return []meshcatalog.CatalogEntry{
|
||||
{Module: "a", Packages: map[string]string{"x/sdk": "v0.0.0-2026-aaa", "y": "v1.0.0"}},
|
||||
{Module: "b", Packages: map[string]string{"x/sdk": "v0.0.0-2026-bbb"}},
|
||||
{Module: "c", Packages: map[string]string{"x/sdk": "v0.0.0-2026-aaa"}},
|
||||
{Module: "d"},
|
||||
}
|
||||
}
|
||||
got, err := RequirementsFrom(entries)(context.Background(), "x/sdk")
|
||||
if err != nil || !reflect.DeepEqual(got, []string{"v0.0.0-2026-aaa", "v0.0.0-2026-bbb"}) {
|
||||
t.Errorf("requirements = %v, %v", got, err)
|
||||
}
|
||||
if got, _ := RequirementsFrom(entries)(context.Background(), "none"); len(got) != 0 {
|
||||
t.Errorf("a package no entry names has requirements %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,332 +0,0 @@
|
||||
package versions
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// FloorSources are the three sources of a name's floor (design 51 *The floor*): each a tool call that answers the
|
||||
// versions it knows of a name, or an error when it does not answer.
|
||||
type FloorSources struct {
|
||||
// Seat is `seat:<registry>.versions` of the registry seat the name is published to.
|
||||
Seat func(ctx context.Context, seat, name string) ([]string, error)
|
||||
// Tags is the seat git's tags: the git tags of the repository the name is built from, under prefix.
|
||||
Tags func(ctx context.Context, repository, prefix string) ([]string, error)
|
||||
// Requirements are the versions of a package the catalog half's entries require (design 47 G A-119).
|
||||
Requirements func(ctx context.Context, name string) ([]string, error)
|
||||
}
|
||||
|
||||
// FloorOf names what a floor is asked for: the name on its seat, and the repository and tag prefix of its git tags.
|
||||
type FloorOf struct{ Seat, Name, Repository, Prefix string }
|
||||
|
||||
// Ask asks the three sources of a name; a source that errs, or is not wired, is named in Silent with its error in why.
|
||||
func (s FloorSources) Ask(ctx context.Context, of FloorOf) (Floor, map[string]string) {
|
||||
seat, name := of.Seat, of.Name
|
||||
var f Floor
|
||||
why := map[string]string{}
|
||||
ask := func(source string, call func() ([]string, error), into *[]string) {
|
||||
if call == nil {
|
||||
f.Silent, why[source] = append(f.Silent, source), "not asked: the builder has no path to it"
|
||||
return
|
||||
}
|
||||
got, err := call()
|
||||
if err != nil {
|
||||
f.Silent, why[source] = append(f.Silent, source), err.Error()
|
||||
return
|
||||
}
|
||||
*into = got
|
||||
}
|
||||
var seatCall, tagsCall, reqCall func() ([]string, error)
|
||||
if s.Seat != nil {
|
||||
seatCall = func() ([]string, error) { return s.Seat(ctx, seat, name) }
|
||||
}
|
||||
if s.Tags != nil {
|
||||
tagsCall = func() ([]string, error) { return s.Tags(ctx, of.Repository, of.Prefix) }
|
||||
}
|
||||
if s.Requirements != nil {
|
||||
reqCall = func() ([]string, error) { return s.Requirements(ctx, name) }
|
||||
}
|
||||
ask(SourceSeat, seatCall, &f.Seat)
|
||||
ask(SourceTags, tagsCall, &f.Tags)
|
||||
ask(SourceRequirements, reqCall, &f.Requirements)
|
||||
return f, why
|
||||
}
|
||||
|
||||
// What wakes a name waiting on its floor, never a timer (design 51, DLV-B3b): the source that was silent saying
|
||||
// something, or its module's health condition clearing.
|
||||
const (
|
||||
// WakePublished is the holder's `published` on the builder's durable consumer of `<seat>.events`.
|
||||
WakePublished = "published"
|
||||
// WakeRevision is a catalog revision the builder hears (the catalog half's entry changed): tags and requirements are asked again.
|
||||
WakeRevision = "catalog-revision"
|
||||
// WakeTakenIn is the indexer's next `take-in.taken`, in place of the retired manifest-accepted: the floor looks at every
|
||||
// module again (design 47 H H-A-116).
|
||||
WakeTakenIn = "take-in.taken"
|
||||
// WakeCleared is the condition keeper's clear of a silent module's health condition on `mesh-conditions`.
|
||||
WakeCleared = "condition-cleared"
|
||||
// WakeByHand is builder_floor_again, a hand act.
|
||||
WakeByHand = "by hand"
|
||||
)
|
||||
|
||||
// sourceOfWake is the floor source each event says something of; a clear names the source by its module.
|
||||
var sourceOfWake = map[string]string{WakePublished: SourceSeat, WakeTakenIn: SourceRequirements}
|
||||
|
||||
// SourceSeats are the seats whose holders are the floor's tag and requirement sources (design 47 G A-82): the seat git (tags)
|
||||
// and the seat mesh-catalog (requirements), the holders read from the seat list and the catalog half.
|
||||
var SourceSeats = map[string]string{SourceTags: "git", SourceRequirements: "mesh-catalog"}
|
||||
|
||||
// FloorWait is one name waiting on its floor: the sources still silent and why, since when; the finding the builder
|
||||
// writes names them, cleared once all three answer.
|
||||
type FloorWait struct {
|
||||
Name string `json:"name"`
|
||||
Seat string `json:"seat"`
|
||||
Silent []string `json:"silent"`
|
||||
Why map[string]string `json:"why,omitempty"`
|
||||
Since time.Time `json:"since"`
|
||||
// Holder is the module holding the name's seat: its condition's clear wakes the seat source.
|
||||
Holder string `json:"holder,omitempty"`
|
||||
}
|
||||
|
||||
// Finding is the floor finding's words.
|
||||
func (w FloorWait) Finding() string {
|
||||
var parts []string
|
||||
for _, s := range w.Silent {
|
||||
p := s
|
||||
if why := w.Why[s]; why != "" {
|
||||
p += " (" + why + ")"
|
||||
}
|
||||
parts = append(parts, p)
|
||||
}
|
||||
return fmt.Sprintf("the floor of %s is not known since %s: %s did not answer; nothing of it is numbered until all three answer",
|
||||
w.Name, w.Since.UTC().Format(time.RFC3339), strings.Join(parts, ", "))
|
||||
}
|
||||
|
||||
// The builder's state floor-waits (DLV-B4): each name waiting on its floor, keyed by its escaped name, so a restarted
|
||||
// builder still knows which names its silent sources' events wake; builder_floor_waits reads it.
|
||||
const (
|
||||
FloorWaitsState = "floor-waits"
|
||||
FloorWaitsTool = "builder_floor_waits"
|
||||
)
|
||||
|
||||
// FloorWaitKey is a wait's key in floor-waits.
|
||||
func FloorWaitKey(name string) string { return EscapeToken(name) }
|
||||
|
||||
// FloorKeeper keeps the waits on the bus: Put a wait's value, Delete its key.
|
||||
type FloorKeeper interface {
|
||||
Put(key string, value []byte) error
|
||||
Delete(key string) error
|
||||
}
|
||||
|
||||
// FloorWaits are the names waiting on their floor. Wake answers which names to ask again for an event, Answered drops
|
||||
// a name once all three answered; the builder's finding for each is the wait's Finding. Once Kept, every change is
|
||||
// written to the state floor-waits as well.
|
||||
type FloorWaits struct {
|
||||
mu sync.Mutex
|
||||
waits map[string]FloorWait
|
||||
keeper FloorKeeper
|
||||
// Logf says a wait that could not be kept; nil says nothing.
|
||||
Logf func(string, ...any)
|
||||
// Holder finds the module holding a seat (the catalog half's claim); a source's module is the holder of its SourceSeats seat.
|
||||
Holder func(seat string) (string, bool)
|
||||
// Said is told each wait recorded (raised) and each answered (not raised): the builder's finding floor-silent.
|
||||
Said func(w FloorWait, raised bool)
|
||||
}
|
||||
|
||||
// FloorSilent is the kind of the floor finding.
|
||||
const FloorSilent = "floor-silent"
|
||||
|
||||
// Keep binds the state: the waits it holds that are not known here are taken in (a restarted builder's), every wait
|
||||
// known here is written to it, and every change from now on is.
|
||||
func (fw *FloorWaits) Keep(k FloorKeeper, held []FloorWait) {
|
||||
fw.mu.Lock()
|
||||
if fw.waits == nil {
|
||||
fw.waits = map[string]FloorWait{}
|
||||
}
|
||||
for _, w := range held {
|
||||
if _, had := fw.waits[w.Name]; !had && w.Name != "" {
|
||||
fw.waits[w.Name] = w
|
||||
}
|
||||
}
|
||||
fw.keeper = k
|
||||
all := make([]FloorWait, 0, len(fw.waits))
|
||||
for _, w := range fw.waits {
|
||||
all = append(all, w)
|
||||
}
|
||||
fw.mu.Unlock()
|
||||
for _, w := range all {
|
||||
fw.put(k, w)
|
||||
}
|
||||
}
|
||||
|
||||
func (fw *FloorWaits) put(k FloorKeeper, w FloorWait) {
|
||||
if k == nil {
|
||||
return
|
||||
}
|
||||
data, err := json.Marshal(w)
|
||||
if err == nil {
|
||||
err = k.Put(FloorWaitKey(w.Name), data)
|
||||
}
|
||||
if err != nil && fw.Logf != nil {
|
||||
fw.Logf("the floor wait of %s is not kept in %s (a restart forgets it until its next claim): %v", w.Name, FloorWaitsState, err)
|
||||
}
|
||||
}
|
||||
|
||||
// DecodeFloorWait reads one value of floor-waits.
|
||||
func DecodeFloorWait(raw []byte) (FloorWait, error) {
|
||||
var w FloorWait
|
||||
if err := json.Unmarshal(raw, &w); err != nil {
|
||||
return FloorWait{}, err
|
||||
}
|
||||
if w.Name == "" {
|
||||
return FloorWait{}, errors.New("a floor wait names no name")
|
||||
}
|
||||
return w, nil
|
||||
}
|
||||
|
||||
// Wait records that name's floor is not known.
|
||||
func (fw *FloorWaits) Wait(name, seat, holder string, f Floor, why map[string]string, now time.Time) FloorWait {
|
||||
fw.mu.Lock()
|
||||
if fw.waits == nil {
|
||||
fw.waits = map[string]FloorWait{}
|
||||
}
|
||||
w, had := fw.waits[name]
|
||||
if !had {
|
||||
w.Since = now
|
||||
}
|
||||
w.Name, w.Seat, w.Holder, w.Silent, w.Why = name, seat, holder, slices.Clone(f.Silent), why
|
||||
fw.waits[name] = w
|
||||
k := fw.keeper
|
||||
fw.mu.Unlock()
|
||||
fw.put(k, w)
|
||||
if fw.Said != nil {
|
||||
fw.Said(w, true)
|
||||
}
|
||||
return w
|
||||
}
|
||||
|
||||
// Answered drops name: its floor is known. It says whether the name waited, so its finding is cleared.
|
||||
func (fw *FloorWaits) Answered(name string) bool {
|
||||
fw.mu.Lock()
|
||||
w, had := fw.waits[name]
|
||||
delete(fw.waits, name)
|
||||
k := fw.keeper
|
||||
fw.mu.Unlock()
|
||||
if had && fw.Said != nil {
|
||||
fw.Said(w, false)
|
||||
}
|
||||
if had && k != nil {
|
||||
if err := k.Delete(FloorWaitKey(name)); err != nil && fw.Logf != nil {
|
||||
fw.Logf("the floor wait of %s is not cleared from %s: %v", name, FloorWaitsState, err)
|
||||
}
|
||||
}
|
||||
return had
|
||||
}
|
||||
|
||||
// FloorWaitsAnswer is what builder_floor_waits answers: every name waiting on its floor, oldest first, with its finding.
|
||||
type FloorWaitsAnswer struct {
|
||||
Waits []FloorWaitRead `json:"waits"`
|
||||
}
|
||||
|
||||
// FloorWaitRead is one wait as builder_floor_waits shows it.
|
||||
type FloorWaitRead struct {
|
||||
FloorWait
|
||||
Finding string `json:"finding"`
|
||||
}
|
||||
|
||||
// AnswerFloorWaits is builder_floor_waits, read from the state floor-waits.
|
||||
func AnswerFloorWaits(r Reader) (FloorWaitsAnswer, error) {
|
||||
keys, err := r.Keys()
|
||||
if err != nil {
|
||||
return FloorWaitsAnswer{}, err
|
||||
}
|
||||
out := FloorWaitsAnswer{Waits: []FloorWaitRead{}}
|
||||
for _, k := range keys {
|
||||
raw, ok, err := r.Get(k)
|
||||
if err != nil {
|
||||
return FloorWaitsAnswer{}, err
|
||||
}
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
w, err := DecodeFloorWait(raw)
|
||||
if err != nil {
|
||||
return FloorWaitsAnswer{}, fmt.Errorf("%s.%s: %w", FloorWaitsState, k, err)
|
||||
}
|
||||
out.Waits = append(out.Waits, FloorWaitRead{FloorWait: w, Finding: w.Finding()})
|
||||
}
|
||||
sort.Slice(out.Waits, func(i, j int) bool {
|
||||
if !out.Waits[i].Since.Equal(out.Waits[j].Since) {
|
||||
return out.Waits[i].Since.Before(out.Waits[j].Since)
|
||||
}
|
||||
return out.Waits[i].Name < out.Waits[j].Name
|
||||
})
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// FloorWaitsDescription is builder_floor_waits' description.
|
||||
const FloorWaitsDescription = "The names waiting on their floor (the builder's state floor-waits, design 51 *The floor*), oldest first: " +
|
||||
"each name, its registry seat, the sources still silent and why, since when, and the finding the builder says for it. " +
|
||||
"Nothing of a waiting name is numbered until all three sources answer; builder_floor_again asks one again by hand. Read-only."
|
||||
|
||||
// Wake answers the names to ask their floor again on an event: kind one of the Wake constants; seat the seat a
|
||||
// `published` came on; module the module whose condition cleared. A name is woken only when the event says something
|
||||
// of a source it waits on; WakeByHand with a name wakes that name alone.
|
||||
func (fw *FloorWaits) Wake(kind, seat, module, name string) []string {
|
||||
fw.mu.Lock()
|
||||
defer fw.mu.Unlock()
|
||||
var out []string
|
||||
for n, w := range fw.waits {
|
||||
switch kind {
|
||||
case WakeByHand:
|
||||
if n == name {
|
||||
out = append(out, n)
|
||||
}
|
||||
case WakeCleared:
|
||||
for _, s := range w.Silent {
|
||||
if fw.holds(SourceSeats[s], module) || (s == SourceSeat && w.Holder != "" && w.Holder == module) {
|
||||
out = append(out, n)
|
||||
break
|
||||
}
|
||||
}
|
||||
default:
|
||||
src := sourceOfWake[kind]
|
||||
if kind == WakeRevision {
|
||||
if slices.Contains(w.Silent, SourceTags) || slices.Contains(w.Silent, SourceRequirements) {
|
||||
out = append(out, n)
|
||||
}
|
||||
} else if slices.Contains(w.Silent, src) && (kind != WakePublished || seat == "" || seat == w.Seat) {
|
||||
out = append(out, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
sort.Strings(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// Waiting is every wait, by name.
|
||||
func (fw *FloorWaits) Waiting() []FloorWait {
|
||||
fw.mu.Lock()
|
||||
defer fw.mu.Unlock()
|
||||
out := make([]FloorWait, 0, len(fw.waits))
|
||||
for _, w := range fw.waits {
|
||||
out = append(out, w)
|
||||
}
|
||||
sort.Slice(out, func(i, j int) bool { return out[i].Name < out[j].Name })
|
||||
return out
|
||||
}
|
||||
|
||||
// holds is whether module holds seat on the catalog half.
|
||||
func (fw *FloorWaits) holds(seat, module string) bool {
|
||||
if seat == "" || module == "" || fw.Holder == nil {
|
||||
return false
|
||||
}
|
||||
holder, ok := fw.Holder(seat)
|
||||
return ok && holder == module
|
||||
}
|
||||
@@ -30,15 +30,10 @@ type Outcome struct {
|
||||
// Heard takes one seat event in: a numbered version's entry turns published (with its digest when it held none),
|
||||
// refused with the holder's reason, removed with its reason and the event's id, or kept (another tag names its digest)
|
||||
// with the other tags; a by-digest publish (no version)
|
||||
// marks nothing. It answers the names waiting on their floor that the event wakes: a `published` says the seat
|
||||
// answers (design 51 *The floor*).
|
||||
func (n *Numberer) Heard(ctx context.Context, seat, event, id string, o Outcome) ([]string, error) {
|
||||
var wake []string
|
||||
if event == HeardPublished && n.Waits != nil {
|
||||
wake = n.Waits.Wake(WakePublished, seat, "", "")
|
||||
}
|
||||
// marks nothing.
|
||||
func (n *Numberer) Heard(ctx context.Context, seat, event, id string, o Outcome) error {
|
||||
if o.Version == "" {
|
||||
return wake, nil
|
||||
return nil
|
||||
}
|
||||
var change func(*Entry)
|
||||
switch event {
|
||||
@@ -46,7 +41,7 @@ func (n *Numberer) Heard(ctx context.Context, seat, event, id string, o Outcome)
|
||||
// A published of other bytes than an entry records under its number is no publish of that entry: the reservation
|
||||
// numbered it and takes it in (design 47 H H-A-159, G §369, A-415; ADR 0605 §4), and the entry stays as it is.
|
||||
if e, ok, _, err := n.Versions.Recorded(ctx, o.Name, o.Version, o.Digest); err == nil && !ok && e.Digest != "" && o.Digest != "" && e.Digest != o.Digest {
|
||||
return wake, fmt.Errorf("%s@%s is recorded with digest %s, so %s's published of %s is %w", o.Name, o.Version, e.Digest, seat, o.Digest, ErrNotNumbered)
|
||||
return fmt.Errorf("%s@%s is recorded with digest %s, so %s's published of %s is %w", o.Name, o.Version, e.Digest, seat, o.Digest, ErrNotNumbered)
|
||||
}
|
||||
change = func(e *Entry) {
|
||||
e.State, e.Reason = Published, ""
|
||||
@@ -72,10 +67,10 @@ func (n *Numberer) Heard(ctx context.Context, seat, event, id string, o Outcome)
|
||||
}
|
||||
}
|
||||
default:
|
||||
return wake, fmt.Errorf("%s says %q, which the builder does not hear", seat, event)
|
||||
return fmt.Errorf("%s says %q, which the builder does not hear", seat, event)
|
||||
}
|
||||
if _, err := n.Versions.Mark(ctx, o.Name, o.Version, change); err != nil {
|
||||
return wake, fmt.Errorf("%s's %s of %s@%s: %w", seat, event, o.Name, o.Version, err)
|
||||
return fmt.Errorf("%s's %s of %s@%s: %w", seat, event, o.Name, o.Version, err)
|
||||
}
|
||||
return wake, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ import (
|
||||
const (
|
||||
OldFormState = "old-form"
|
||||
OldFormKey = "window"
|
||||
// SaidOldFormClosed is the why of the build log's line saying the window closed (build.said).
|
||||
SaidOldFormClosed = "old-form-closed"
|
||||
)
|
||||
|
||||
// OldFormHeld is the finding of a node holding the window open for FindingAfter, about that node, cleared when the
|
||||
|
||||
@@ -68,58 +68,6 @@ func (v Versions) Of(ctx context.Context, name string) ([]Entry, error) {
|
||||
return InOrder(out), nil
|
||||
}
|
||||
|
||||
// Claim is one numbering asked of the builder.
|
||||
type Claim struct {
|
||||
Name, Kind, Series, Module, Fingerprint, Commit, Revision, Digest, Seat string
|
||||
Merge uint64
|
||||
Floor Floor
|
||||
// Fresh numbers anew a fingerprint or revision already numbered: builder_publish_again after a published (design 51
|
||||
// *Tools of the builder*).
|
||||
Fresh bool
|
||||
}
|
||||
|
||||
// Number numbers a claim under compare-and-set: two claims of one name never get one number, the second reading the
|
||||
// first's key and taking the next (ADR 0606 §2). It answers the decision and, when it numbered or kept a version, its
|
||||
// entry. Attempts are bounded by the claims the name can meet at once; a store that keeps conflicting is an error.
|
||||
func (v Versions) Number(ctx context.Context, c Claim) (Decision, Entry, error) {
|
||||
if c.Series == "" {
|
||||
c.Series = DefaultSeries
|
||||
}
|
||||
for attempt := 0; attempt < 16; attempt++ {
|
||||
entries, err := v.Of(ctx, c.Name)
|
||||
if err != nil {
|
||||
return Decision{}, Entry{}, err
|
||||
}
|
||||
d := Decide(fresh(entries, c), c.Kind, c.Series, c.Fingerprint, c.Revision, c.Floor)
|
||||
if d.Version == "" {
|
||||
return d, Entry{}, nil
|
||||
}
|
||||
if d.Keep {
|
||||
for _, e := range entries {
|
||||
if e.Version == d.Version {
|
||||
return d, e, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
e := Entry{Name: c.Name, Kind: c.Kind, Series: c.Series, Version: d.Version, Module: c.Module,
|
||||
Fingerprint: c.Fingerprint, Commit: c.Commit, Revision: c.Revision, Digest: c.Digest, Seat: c.Seat,
|
||||
State: Numbered, At: v.now(), Merge: c.Merge}
|
||||
raw, err := Encode(e)
|
||||
if err != nil {
|
||||
return Decision{}, Entry{}, err
|
||||
}
|
||||
_, err = v.Store.Create(ctx, Key(c.Name, d.Version), raw)
|
||||
if errors.Is(err, ErrConflict) {
|
||||
continue // another claim took this number: read again and take the next
|
||||
}
|
||||
if err != nil {
|
||||
return Decision{}, Entry{}, fmt.Errorf("%s@%s: %w", c.Name, d.Version, err)
|
||||
}
|
||||
return d, e, nil
|
||||
}
|
||||
return Decision{}, Entry{}, fmt.Errorf("%s: the versions kept changing under 16 claims", c.Name)
|
||||
}
|
||||
|
||||
// ErrNotNumbered is a version the state versions does not hold (design 51's numbering by name): a version the reservation
|
||||
// numbered (§369) is never held there.
|
||||
var ErrNotNumbered = errors.New("not numbered by the builder")
|
||||
@@ -186,22 +134,6 @@ func (v Versions) now() time.Time {
|
||||
return time.Now().UTC()
|
||||
}
|
||||
|
||||
// fresh is entries as Decide reads them for c: with Fresh, the entries of c's fingerprint and revision still count for the
|
||||
// next number but keep none.
|
||||
func fresh(entries []Entry, c Claim) []Entry {
|
||||
if !c.Fresh {
|
||||
return entries
|
||||
}
|
||||
out := make([]Entry, len(entries))
|
||||
for i, e := range entries {
|
||||
if e.Tag == "" && (e.Fingerprint == c.Fingerprint || (c.Revision != "" && e.Revision == c.Revision)) {
|
||||
e.Fingerprint, e.Revision = "", ""
|
||||
}
|
||||
out[i] = e
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// All is every entry of every name, by name in order: what the versions' readers read.
|
||||
func (v Versions) All(ctx context.Context) ([]Entry, error) {
|
||||
keys, err := v.Store.KeysOf(ctx, AllFilter)
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
const (
|
||||
VersionsTool = "builder_versions"
|
||||
PublishAgainTool = "builder_publish_again"
|
||||
FloorAgainTool = "builder_floor_again"
|
||||
OldFormTool = "builder_old_form"
|
||||
// OldFormClosedEvent is the builder's own family `version`, kept seven days,
|
||||
// apart from its builds' ends, so a waiter on a build's end does not wake on them.
|
||||
|
||||
@@ -182,125 +182,6 @@ func Patch(series, version string) (int, bool) {
|
||||
return n, true
|
||||
}
|
||||
|
||||
// Floor is what the three sources answered for a name (design 51 *The floor*, ADR 0606 §3): the seat's versions, the
|
||||
// package's git tags (the seat git's tags) and the pseudo-versions consumers require (the catalog half's
|
||||
// indexer_requirements). A source not answered is listed in Silent.
|
||||
type Floor struct {
|
||||
Seat []string `json:"seat,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
Requirements []string `json:"requirements,omitempty"`
|
||||
// Silent names the sources that did not answer: "seat", "git.tags", "catalog.requirements".
|
||||
Silent []string `json:"silent,omitempty"`
|
||||
}
|
||||
|
||||
// The floor's sources, as Floor.Silent names them.
|
||||
const (
|
||||
SourceSeat = "seat"
|
||||
SourceTags = "git.tags"
|
||||
SourceRequirements = "catalog.requirements"
|
||||
)
|
||||
|
||||
// Known is whether every source answered.
|
||||
func (f Floor) Known() bool { return len(f.Silent) == 0 }
|
||||
|
||||
// Highest is the highest count of series the floor's three sources name, -1 when none names one. A pseudo-version
|
||||
// (`v0.1.14-0.2026…-abc`) counts as the version below it was cut from, so its base (`0.1.13`) counts: Go orders it
|
||||
// before `0.1.14`.
|
||||
func (f Floor) Highest(series string) int {
|
||||
high := -1
|
||||
for _, list := range [][]string{f.Seat, f.Tags, f.Requirements} {
|
||||
for _, v := range list {
|
||||
n, ok := Patch(series, v)
|
||||
if !ok {
|
||||
n, ok = pseudoBase(series, v)
|
||||
}
|
||||
if ok && n > high {
|
||||
high = n
|
||||
}
|
||||
}
|
||||
}
|
||||
return high
|
||||
}
|
||||
|
||||
// pseudoBase is the count a Go pseudo-version stands on: `v0.1.14-0.<time>-<hash>` is cut after `v0.1.13`.
|
||||
func pseudoBase(series, version string) (int, bool) {
|
||||
version = strings.TrimPrefix(version, "v")
|
||||
base, rest, ok := strings.Cut(version, "-")
|
||||
if !ok || !strings.HasPrefix(rest, "0.") || strings.Count(rest, "-") != 1 {
|
||||
return 0, false
|
||||
}
|
||||
n, ok := Patch(series, base)
|
||||
if !ok || n == 0 {
|
||||
return 0, false
|
||||
}
|
||||
return n - 1, true
|
||||
}
|
||||
|
||||
// Next is the next trunk version of name in series: one above the highest of the trunk versions entries hold and the
|
||||
// floor (design 51: a name with none starts at `<series>.0`).
|
||||
func Next(entries []Entry, series string, floor Floor) string {
|
||||
high := floor.Highest(series)
|
||||
for _, e := range entries {
|
||||
if e.Tag != "" || e.Series != series {
|
||||
continue
|
||||
}
|
||||
if n, ok := Patch(series, e.Version); ok && n > high {
|
||||
high = n
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("%s.%d", series, high+1)
|
||||
}
|
||||
|
||||
// Decision is what the builder does with a trunk build at its claim.
|
||||
type Decision struct {
|
||||
// Version is the version the build is published under; empty when it is built unnumbered (Unnumbered) or waits (Wait).
|
||||
Version string
|
||||
// Keep is true when the version is one entries already hold for this fingerprint or source revision.
|
||||
Keep bool
|
||||
// Publish is false only for a package's revision held published: it publishes nothing (design 51).
|
||||
Publish bool
|
||||
// Unnumbered: an image, bundle or archive whose floor is not known is built and published by its digest, numbered
|
||||
// once the floor answers (ADR 0617 §1).
|
||||
Unnumbered bool
|
||||
// Wait: a package whose floor is not known waits for it (a package is published only under its version).
|
||||
Wait bool
|
||||
// Why is said in the build log.
|
||||
Why string
|
||||
}
|
||||
|
||||
// Decide numbers a trunk build of kind for name in series at fingerprint and source revision, from what entries hold of
|
||||
// the name and what the floor answered (design 51 *The versions*, ADR 0606, ADR 0617 §1):
|
||||
// - a package is numbered per source revision: a revision held published keeps its version and publishes nothing; a
|
||||
// revision numbered or refused but never stored is published again under the same version;
|
||||
// - an image, bundle or archive is numbered per fingerprint: a fingerprint already numbered keeps its number;
|
||||
// - otherwise the next version, when the floor is known; else an image, bundle or archive is built unnumbered and a
|
||||
// package waits.
|
||||
func Decide(entries []Entry, kind, series, fingerprint, revision string, floor Floor) Decision {
|
||||
for _, e := range latestFirst(entries) {
|
||||
if e.Tag != "" || e.State == Removed {
|
||||
continue
|
||||
}
|
||||
switch {
|
||||
case kind == KindPackage && revision != "" && e.Revision == revision:
|
||||
if e.State == Published {
|
||||
return Decision{Version: e.Version, Keep: true, Why: fmt.Sprintf("version %s kept: source revision %s is published under it, and a package's content is its source", e.Version, revision)}
|
||||
}
|
||||
return Decision{Version: e.Version, Keep: true, Publish: true, Why: fmt.Sprintf("version %s kept: source revision %s was numbered %s but never stored, so it is published under it", e.Version, revision, e.State)}
|
||||
case kind != KindPackage && e.Fingerprint == fingerprint:
|
||||
return Decision{Version: e.Version, Keep: true, Publish: e.State != Published, Why: fmt.Sprintf("version %s kept: fingerprint %s is numbered under it", e.Version, fingerprint)}
|
||||
}
|
||||
}
|
||||
if !floor.Known() {
|
||||
silent := strings.Join(floor.Silent, ", ")
|
||||
if kind == KindPackage {
|
||||
return Decision{Wait: true, Why: "the package waits for its floor: " + silent + " did not answer"}
|
||||
}
|
||||
return Decision{Unnumbered: true, Publish: true, Why: "built unnumbered and published by its digest: the floor is not known (" + silent + " did not answer); numbered once it answers"}
|
||||
}
|
||||
v := Next(entries, series, floor)
|
||||
return Decision{Version: v, Publish: true, Why: "numbered " + v}
|
||||
}
|
||||
|
||||
// Fill is whether a bucket holding bytes of cap is past its finding's mark.
|
||||
func Fill(bytes, capacity uint64) (share float64, full bool) {
|
||||
if capacity == 0 {
|
||||
|
||||
@@ -75,20 +75,6 @@ func (m *mem) KeysOf(_ context.Context, filter string) ([]string, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// keeperMem is the state floor-waits in memory.
|
||||
type keeperMem map[string][]byte
|
||||
|
||||
func (k keeperMem) Put(key string, v []byte) error { k[key] = v; return nil }
|
||||
func (k keeperMem) Delete(key string) error { delete(k, key); return nil }
|
||||
func (k keeperMem) keys() ([]string, error) {
|
||||
var out []string
|
||||
for key := range k {
|
||||
out = append(out, key)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func (k keeperMem) get(key string) (json.RawMessage, bool, error) { v, ok := k[key]; return v, ok, nil }
|
||||
|
||||
// packagesMem is the indexer's packages state as the builder reads it, in memory.
|
||||
type packagesMem map[string][]byte
|
||||
|
||||
@@ -106,7 +92,17 @@ func (p packagesMem) Get(_ context.Context, key string) ([]byte, bool, error) {
|
||||
|
||||
func (p packagesMem) failing() packagesMem { return nil }
|
||||
|
||||
func known(seat, tags, reqs []string) Floor { return Floor{Seat: seat, Tags: tags, Requirements: reqs} }
|
||||
// seed writes an entry of the state versions kept from before G: the builder numbers none of its own (design 47 H §756).
|
||||
func seed(t *testing.T, st *mem, e Entry) {
|
||||
t.Helper()
|
||||
raw, err := Encode(e)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := st.Create(context.Background(), Key(e.Name, e.Version), raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestTheBuildersVersions holds design 51 *The versions*, *The floor* and *Tagged versions* (DLV-B1, DLV-B2, DLV-B3):
|
||||
// one table per rule, the unit cases of the builder's numbering.
|
||||
@@ -128,86 +124,11 @@ func TestTheBuildersVersions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
})
|
||||
t.Run("floor", func(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
floor Floor
|
||||
want string
|
||||
}{
|
||||
{"none starts at 0", known(nil, nil, nil), "0.1.0"},
|
||||
{"the Go tag of today gives v0.1.14", known(nil, []string{"go/v0.1.13"}, []string{"v0.1.14-0.20261103221822-85ba0a9a70d8"}), "0.1.14"},
|
||||
{"npm's 0.1.17 on the seat gives 0.1.18", known([]string{"0.1.17", "0.1.3"}, nil, nil), "0.1.18"},
|
||||
{"another series and a tagged version count nothing", known([]string{"0.2.40", "0.1.9-feat-x.1"}, nil, nil), "0.1.0"},
|
||||
{"the highest of the three", known([]string{"0.1.4"}, []string{"v0.1.9"}, []string{"v0.1.7"}), "0.1.10"},
|
||||
} {
|
||||
if got := Next(nil, "0.1", c.floor); got != c.want {
|
||||
t.Errorf("%s: Next = %s, want %s", c.name, got, c.want)
|
||||
}
|
||||
}
|
||||
if got := Next([]Entry{{Version: "0.1.20", Series: "0.1"}, {Version: "0.1.21-x.1", Series: "0.1", Tag: "x"}}, "0.1", known([]string{"0.1.3"}, nil, nil)); got != "0.1.21" {
|
||||
t.Errorf("Next above the state's own = %s, want 0.1.21", got)
|
||||
}
|
||||
})
|
||||
t.Run("decide", func(t *testing.T) {
|
||||
pub := Entry{Name: "n", Kind: KindPackage, Series: "0.1", Version: "0.1.5", Revision: "r1", Fingerprint: "fA", State: Published}
|
||||
ref := pub
|
||||
ref.State, ref.Version, ref.Revision = Refused, "0.1.6", "r2"
|
||||
img := Entry{Name: "i", Kind: KindBundle, Series: "0.1", Version: "0.1.2", Fingerprint: "fB", State: Published}
|
||||
silent := Floor{Silent: []string{SourceSeat}}
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
entries []Entry
|
||||
kind, fp, rev string
|
||||
floor Floor
|
||||
version string
|
||||
keep, publish, unnum bool
|
||||
wait bool
|
||||
}{
|
||||
{"a package's revision held published keeps its version and publishes nothing", []Entry{pub}, KindPackage, "fX", "r1", silent, "0.1.5", true, false, false, false},
|
||||
{"a revision numbered but refused is published by its second build under the same version", []Entry{pub, ref}, KindPackage, "fY", "r2", known(nil, nil, nil), "0.1.6", true, true, false, false},
|
||||
{"a new revision takes the next", []Entry{pub, ref}, KindPackage, "fZ", "r3", known(nil, nil, nil), "0.1.7", false, true, false, false},
|
||||
{"a bundle's fingerprint keeps its number", []Entry{img}, KindBundle, "fB", "", silent, "0.1.2", true, false, false, false},
|
||||
{"an unknown floor builds a bundle unnumbered", nil, KindBundle, "fC", "", silent, "", false, true, true, false},
|
||||
{"an unknown floor builds an image unnumbered", nil, KindImage, "fC", "", silent, "", false, true, true, false},
|
||||
{"an unknown floor makes a package wait", nil, KindPackage, "fC", "r9", silent, "", false, false, false, true},
|
||||
} {
|
||||
d := Decide(c.entries, c.kind, "0.1", c.fp, c.rev, c.floor)
|
||||
if d.Version != c.version || d.Keep != c.keep || d.Publish != c.publish || d.Unnumbered != c.unnum || d.Wait != c.wait || d.Why == "" {
|
||||
t.Errorf("%s: Decide = %+v", c.name, d)
|
||||
}
|
||||
}
|
||||
})
|
||||
t.Run("two claims never one number", func(t *testing.T) {
|
||||
st := newMem()
|
||||
v := Versions{Store: st, Now: func() time.Time { return time.Unix(0, 0) }}
|
||||
ctx := context.Background()
|
||||
st.before = func() { // a second claim takes 0.1.0 between the first's read and its create
|
||||
if _, _, err := (Versions{Store: st}).Number(ctx, Claim{Name: "n", Kind: KindBundle, Fingerprint: "f2"}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
d, e, err := v.Number(ctx, Claim{Name: "n", Kind: KindBundle, Fingerprint: "f1"})
|
||||
if err != nil || d.Version != "0.1.1" || e.State != Numbered || e.Series != DefaultSeries {
|
||||
t.Fatalf("Number = %+v, %+v, %v, want 0.1.1 after the other claim's 0.1.0", d, e, err)
|
||||
}
|
||||
if d, _, _ := v.Number(ctx, Claim{Name: "n", Kind: KindBundle, Fingerprint: "f1"}); !d.Keep || d.Version != "0.1.1" {
|
||||
t.Errorf("a numbered fingerprint claimed again = %+v, want it kept", d)
|
||||
}
|
||||
got, err := v.Mark(ctx, "n", "0.1.1", func(e *Entry) { e.State = Published })
|
||||
if err != nil || got.State != Published {
|
||||
t.Errorf("Mark = %+v, %v", got, err)
|
||||
}
|
||||
if _, err := v.Mark(ctx, "n", "0.9.9", func(*Entry) {}); err == nil {
|
||||
t.Error("marking a version never numbered is no error")
|
||||
}
|
||||
})
|
||||
t.Run("recorded", func(t *testing.T) {
|
||||
st := newMem()
|
||||
v := Versions{Store: st}
|
||||
ctx := context.Background()
|
||||
if _, _, err := v.Number(ctx, Claim{Name: "n", Kind: KindImage, Fingerprint: "f", Digest: "sha256:aa", Floor: known(nil, nil, nil)}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
seed(t, st, Entry{Name: "n", Kind: KindImage, Series: "0.1", Version: "0.1.0", Fingerprint: "f", Digest: "sha256:aa", State: Numbered, At: time.Unix(1, 0)})
|
||||
for _, c := range []struct {
|
||||
version, digest string
|
||||
ok bool
|
||||
@@ -235,77 +156,6 @@ func TestTheBuildersVersions(t *testing.T) {
|
||||
t.Error("builder_versions with no name answered")
|
||||
}
|
||||
})
|
||||
t.Run("the floor wakes on its silent source, never a timer", func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
src := FloorSources{
|
||||
Seat: func(context.Context, string, string) ([]string, error) { return []string{"0.1.3"}, nil },
|
||||
Tags: func(context.Context, string, string) ([]string, error) { return nil, errors.New("no answer") },
|
||||
Requirements: func(context.Context, string) ([]string, error) { return nil, nil },
|
||||
}
|
||||
f, why := src.Ask(ctx, FloorOf{Seat: "oci-artifact-registry", Name: "m/program"})
|
||||
if f.Known() || !reflect.DeepEqual(f.Silent, []string{SourceTags}) || why[SourceTags] != "no answer" {
|
||||
t.Fatalf("Ask = %+v, %v; want git.tags silent", f, why)
|
||||
}
|
||||
holders := map[string]string{SourceSeats[SourceTags]: "mesh-delivery-forge-bridge", SourceSeats[SourceRequirements]: "mesh-delivery-indexer"}
|
||||
fw := FloorWaits{Holder: func(seat string) (string, bool) { h, ok := holders[seat]; return h, ok }}
|
||||
w := fw.Wait("m/program", "oci-artifact-registry", "distribution", f, why, time.Unix(0, 0))
|
||||
if !strings.Contains(w.Finding(), "git.tags (no answer)") {
|
||||
t.Errorf("finding = %q", w.Finding())
|
||||
}
|
||||
for _, c := range []struct {
|
||||
kind, seat, module, name string
|
||||
want []string
|
||||
}{
|
||||
{WakePublished, "oci-artifact-registry", "", "", nil}, // the seat answered already: a publish wakes nothing
|
||||
{WakeTakenIn, "", "", "", nil},
|
||||
{WakeRevision, "", "", "", []string{"m/program"}},
|
||||
{WakeCleared, "", "mesh-delivery-forge-bridge", "", []string{"m/program"}}, // recovered with nothing to say
|
||||
{WakeCleared, "", "mesh-delivery-indexer", "", nil},
|
||||
{WakeByHand, "", "", "m/program", []string{"m/program"}},
|
||||
{WakeByHand, "", "", "other", nil},
|
||||
} {
|
||||
if got := fw.Wake(c.kind, c.seat, c.module, c.name); !reflect.DeepEqual(got, c.want) {
|
||||
t.Errorf("Wake(%s %s %s %s) = %v, want %v", c.kind, c.seat, c.module, c.name, got, c.want)
|
||||
}
|
||||
}
|
||||
seatDown := Floor{Silent: []string{SourceSeat}}
|
||||
fw.Wait("distribution/program", "container-image-registry", "distribution", seatDown, nil, time.Unix(0, 0))
|
||||
if got := fw.Wake(WakePublished, "container-image-registry", "", ""); !reflect.DeepEqual(got, []string{"distribution/program"}) {
|
||||
t.Errorf("the holder's published woke %v, want its own image's name", got)
|
||||
}
|
||||
if got := fw.Wake(WakeCleared, "", "distribution", ""); !reflect.DeepEqual(got, []string{"distribution/program"}) {
|
||||
t.Errorf("the holder's clear woke %v", got)
|
||||
}
|
||||
if !fw.Answered("m/program") || fw.Answered("m/program") || len(fw.Waiting()) != 1 {
|
||||
t.Error("Answered drops the wait once")
|
||||
}
|
||||
// DLV-B4: the waits are kept in floor-waits; a restarted builder takes them in, and its sources' events still wake them.
|
||||
kept := keeperMem{}
|
||||
restarted := &FloorWaits{}
|
||||
restarted.Keep(kept, []FloorWait{{Name: "m/held", Seat: SeatImages, Silent: []string{SourceTags}, Since: time.Unix(5, 0)}})
|
||||
if got := restarted.Wake(WakeRevision, "", "", ""); !reflect.DeepEqual(got, []string{"m/held"}) {
|
||||
t.Errorf("a wait held in floor-waits woke %v after a restart, want m/held", got)
|
||||
}
|
||||
restarted.Wait("m/new", SeatNPM, "", Floor{Silent: []string{SourceSeat}}, nil, time.Unix(9, 0))
|
||||
ans, err := AnswerFloorWaits(Reader{Keys: kept.keys, Get: kept.get})
|
||||
if err != nil || len(ans.Waits) != 2 || ans.Waits[0].Name != "m/held" || ans.Waits[1].Name != "m/new" || !strings.Contains(ans.Waits[1].Finding, "seat did not answer") {
|
||||
t.Fatalf("builder_floor_waits = %+v, %v", ans, err)
|
||||
}
|
||||
restarted.Answered("m/held")
|
||||
if _, ok := kept[FloorWaitKey("m/held")]; ok {
|
||||
t.Error("an answered floor stays in floor-waits")
|
||||
}
|
||||
// The lead's ruling (review round 1): builder_bounds lists each key of the state bounds with what it bounds and
|
||||
// when it ends.
|
||||
at := time.Date(2026, 11, 4, 17, 0, 0, 0, time.UTC)
|
||||
bounds := keeperMem{PublishBoundKey("m/program", "0.1.4"): EncodeBound("the publish of m/program@0.1.4 to oci-artifact-registry", at.Add(PublishBound)),
|
||||
OldFormBoundKey("g14"): EncodeBound("the seven days g14 holds the old form's window", at.Add(FindingAfter))}
|
||||
rows, err := AnswerBounds(Reader{Keys: bounds.keys, Get: bounds.get}, at)
|
||||
if err != nil || len(rows) != 2 || rows[0].Key != OldFormBoundKey("g14") || rows[1].Left != "10m0s" ||
|
||||
!strings.Contains(rows[1].Bounds, "m/program@0.1.4") || !rows[0].Ends.Equal(at.Add(FindingAfter)) {
|
||||
t.Fatalf("builder_bounds = %+v, %v", rows, err)
|
||||
}
|
||||
})
|
||||
t.Run("old form", func(t *testing.T) {
|
||||
// One kind, a first form and a newer one.
|
||||
fs := forms.ArtifactForms{{Name: "registry", First: true, Kinds: []string{"image"}}, {Name: "oci", Kinds: []string{"image"}}}
|
||||
@@ -368,75 +218,23 @@ func TestTheBuildersVersions(t *testing.T) {
|
||||
t.Error("a closed window closes again: old-form-closed would be said twice")
|
||||
}
|
||||
})
|
||||
t.Run("at the claim", func(t *testing.T) {
|
||||
t.Run("the registry seats' words mark an entry", func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tagsUp := false
|
||||
var asked []string
|
||||
src := FloorSources{
|
||||
Seat: func(context.Context, string, string) ([]string, error) { return []string{"0.1.3"}, nil },
|
||||
Tags: func(_ context.Context, repo, prefix string) ([]string, error) {
|
||||
asked = append(asked, repo+" "+prefix)
|
||||
if !tagsUp {
|
||||
return nil, errors.New("no answer")
|
||||
}
|
||||
return []string{"go/v0.1.13"}, nil
|
||||
},
|
||||
Requirements: func(context.Context, string) ([]string, error) { return nil, nil },
|
||||
}
|
||||
fw := &FloorWaits{}
|
||||
n := &Numberer{Versions: Versions{Store: newMem()}, Floor: src, Waits: fw}
|
||||
c := BuildClaim{Module: "m", Path: "go", Repository: "novox/m", Fingerprint: "fp1", Commit: "c1", Revision: "7", Merge: 7,
|
||||
Artifacts: []ClaimArtifact{{Artifact: "program", Kind: KindBundle, Language: "go"}, {Artifact: "base", Kind: "upstream"}}}
|
||||
got, err := n.Number(ctx, c)
|
||||
if err != nil || len(got.Versions) != 0 || !reflect.DeepEqual(got.Unnumbered, []string{"program"}) || got.Wait != "" {
|
||||
t.Fatalf("silent floor: %+v, %v; want program unnumbered, the upstream copy left out", got, err)
|
||||
}
|
||||
if !reflect.DeepEqual(asked, []string{"novox/m go/v"}) || len(fw.Waiting()) != 1 {
|
||||
t.Fatalf("asked %v, waits %+v", asked, fw.Waiting())
|
||||
}
|
||||
pkg := c
|
||||
pkg.Artifacts = []ClaimArtifact{{Artifact: "lib", Kind: KindPackage, Language: "go"}}
|
||||
if got, _ := n.Number(ctx, pkg); got.Wait == "" || len(got.Versions) != 0 {
|
||||
t.Fatalf("a package with no floor = %+v; want it to wait", got)
|
||||
}
|
||||
tagsUp = true
|
||||
got, err = n.Number(ctx, c)
|
||||
if err != nil || got.Versions["program"] != "0.1.14" || len(fw.Waiting()) != 1 {
|
||||
t.Fatalf("floor answered: %+v, %v, waits %+v; want 0.1.14, lib still waiting", got, err, fw.Waiting())
|
||||
}
|
||||
got, _ = n.Number(ctx, c)
|
||||
var publishing []string // review round 1: a version built and still numbered arms its publish bound
|
||||
n.Publishing = func(_ context.Context, e Entry) { publishing = append(publishing, e.Name+"@"+e.Version) }
|
||||
if err := n.Built(ctx, c, got, map[string]string{"program": "sha256:aa"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n.Publishing = nil; !reflect.DeepEqual(publishing, []string{"m/program@0.1.14"}) {
|
||||
t.Fatalf("the publish bounds armed: %v, want m/program@0.1.14", publishing)
|
||||
}
|
||||
again, _ := n.Number(ctx, c)
|
||||
if again.Versions["program"] != "0.1.14" || len(asked) != 3 {
|
||||
t.Fatalf("again: %+v, asked %v; want the number kept, the floor not asked", again, asked)
|
||||
}
|
||||
if _, ok, why, _ := n.Versions.Recorded(ctx, "m/program", "0.1.14", "sha256:bb"); ok {
|
||||
t.Fatalf("another digest recorded: %s", why)
|
||||
}
|
||||
// DLV-B4: the seat's events move the entry; a published wakes the names waiting on that seat.
|
||||
if wake, err := n.Heard(ctx, SeatArtifacts, HeardPublished, "e1", Outcome{Name: "m/other", Digest: "sha256:cc"}); err != nil || len(wake) != 0 {
|
||||
t.Fatalf("a by-digest publish of another seat's wait: %v, %v", wake, err)
|
||||
}
|
||||
n.Waits.Wait("m/lib", SeatGoPackages, "", Floor{Silent: []string{SourceSeat}}, nil, time.Unix(0, 0))
|
||||
if wake, _ := n.Heard(ctx, SeatGoPackages, HeardPublished, "e2", Outcome{Name: "m/x", Digest: "sha256:dd"}); !reflect.DeepEqual(wake, []string{"m/lib"}) {
|
||||
t.Fatalf("a published on the Go seat woke %v, want m/lib, whose seat was silent", wake)
|
||||
st := newMem()
|
||||
n := &Numberer{Versions: Versions{Store: st}}
|
||||
seed(t, st, Entry{Name: "m/program", Kind: KindBundle, Series: "0.1", Version: "0.1.14", Fingerprint: "fp1", Digest: "sha256:aa", State: Numbered, At: time.Unix(1, 0)})
|
||||
if err := n.Heard(ctx, SeatArtifacts, HeardPublished, "e1", Outcome{Name: "m/other", Digest: "sha256:cc"}); err != nil {
|
||||
t.Fatalf("a by-digest publish: %v", err)
|
||||
}
|
||||
// Design 47 G §369, A-415; ADR 0605 §4: a published of other bytes under the number is the reservation's, never this entry's.
|
||||
if _, err := n.Heard(ctx, SeatArtifacts, HeardPublished, "e5", Outcome{Name: "m/program", Version: "0.1.14", Digest: "sha256:new"}); !errors.Is(err, ErrNotNumbered) {
|
||||
if err := n.Heard(ctx, SeatArtifacts, HeardPublished, "e5", Outcome{Name: "m/program", Version: "0.1.14", Digest: "sha256:new"}); !errors.Is(err, ErrNotNumbered) {
|
||||
t.Fatalf("a published of other bytes under 0.1.14: %v, want ErrNotNumbered", err)
|
||||
}
|
||||
if all, _ := n.Versions.Of(ctx, "m/program"); all[0].State != Numbered || all[0].Digest != "sha256:aa" {
|
||||
t.Fatalf("after a published of other bytes: %+v, want it numbered with sha256:aa", all[0])
|
||||
}
|
||||
for _, h := range []struct{ event, state, reason string }{{HeardRefused, Refused, "bytes differ"}, {HeardPublished, Published, ""}, {HeardRefused, Published, ""}, {HeardRemoved, Removed, "retention"}} {
|
||||
if _, err := n.Heard(ctx, SeatArtifacts, h.event, "e3", Outcome{Name: "m/program", Version: "0.1.14", Digest: "sha256:aa", Reason: h.reason}); err != nil {
|
||||
if err := n.Heard(ctx, SeatArtifacts, h.event, "e3", Outcome{Name: "m/program", Version: "0.1.14", Digest: "sha256:aa", Reason: h.reason}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
all, _ := n.Versions.Of(ctx, "m/program")
|
||||
@@ -444,96 +242,25 @@ func TestTheBuildersVersions(t *testing.T) {
|
||||
t.Fatalf("after %s: %+v, want %s", h.event, all[0], h.state)
|
||||
}
|
||||
}
|
||||
if _, err := n.Heard(ctx, SeatArtifacts, HeardPublished, "e4", Outcome{Name: "m/none", Version: "0.1.0"}); err == nil {
|
||||
if err := n.Heard(ctx, SeatArtifacts, HeardPublished, "e4", Outcome{Name: "m/none", Version: "0.1.0"}); err == nil {
|
||||
t.Fatal("a published of a version the builder never numbered is not said")
|
||||
}
|
||||
// D-B5 (ADR 0666 §15, design 51 *The versions* line 287): a package's build whose published versions cannot be read
|
||||
// is refused, naming the state; a bundle's is built as before (ADR 0617 §1), the error said.
|
||||
st := n.Versions.Store.(*mem)
|
||||
st.down = errors.New("nats: no responders available for request")
|
||||
if got, err := n.Number(ctx, pkg); err != nil || !strings.Contains(got.Refused, "state versions cannot be read") || len(got.Versions) != 0 {
|
||||
t.Errorf("a package with its versions unread = %+v, %v; want refused naming the state", got, err)
|
||||
}
|
||||
if got, err := n.Number(ctx, c); err == nil || got.Refused != "" {
|
||||
t.Errorf("a bundle with its versions unread = %+v, %v; want the error, no refusal", got, err)
|
||||
}
|
||||
st.down = nil
|
||||
})
|
||||
t.Run("a package is numbered under its name in its ecosystem", func(t *testing.T) {
|
||||
// design 32: the indexer's packages state names, in each series key, the package's name and the <module>/<artifact>
|
||||
// it is built from; the builder numbers, asks the floor of and records the package under that name.
|
||||
t.Run("the packages state's names", func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
state := packagesMem{
|
||||
"git=2enovox=2ebe/novox/mesh-sdk/go.0.1": []byte(`{"v":1,"name":"git.novox.be/novox/mesh-sdk/go","package":"mesh-sdk/go","series":"0.1"}`),
|
||||
"@novox/mesh-sdk.0.1": []byte(`{"v":1,"name":"@novox/mesh-sdk","package":"mesh-sdk/ts","series":"0.1"}`),
|
||||
"git=2enovox=2ebe/novox/mesh-sdk/go": []byte(`{"v":1,"module":"git.novox.be/novox/mesh-sdk/go"}`),
|
||||
"broken.0.1": []byte(`not json`),
|
||||
"git=2enovox=2ebe/novox/mesh-sdk/go": []byte(`{"v":1,"module":"git.novox.be/novox/mesh-sdk/go"}`),
|
||||
"broken.0.1": []byte(`not json`),
|
||||
"new.0.1": []byte(`{"v":1,"name":"new","package":"mesh-sdk/new","series":"0.1"}`),
|
||||
}
|
||||
var floorOf []string
|
||||
src := FloorSources{
|
||||
Seat: func(_ context.Context, _, name string) ([]string, error) {
|
||||
floorOf = append(floorOf, name)
|
||||
return []string{"0.1.3"}, nil
|
||||
},
|
||||
Tags: func(context.Context, string, string) ([]string, error) { return nil, nil },
|
||||
Requirements: func(_ context.Context, name string) ([]string, error) {
|
||||
floorOf = append(floorOf, name)
|
||||
return nil, nil
|
||||
},
|
||||
}
|
||||
n := &Numberer{Versions: Versions{Store: newMem()}, Floor: src, Names: NamesIn(state)}
|
||||
c := BuildClaim{Module: "mesh-sdk", Path: "go", Repository: "novox/mesh-sdk", Fingerprint: "fp1", Commit: "c1", Revision: "3", Merge: 3,
|
||||
Artifacts: []ClaimArtifact{{Artifact: "go", Kind: KindPackage, Language: "go"}, {Artifact: "ts", Kind: KindPackage, Language: "typescript"},
|
||||
{Artifact: "new", Kind: KindPackage, Language: "go"}, {Artifact: "program", Kind: KindBundle, Language: "go"}}}
|
||||
got, err := n.Number(ctx, c)
|
||||
if err != nil || got.Versions["go"] != "0.1.4" || got.Versions["ts"] != "0.1.4" || !reflect.DeepEqual(got.Unnumbered, []string{"new"}) {
|
||||
t.Fatalf("Number = %+v, %v; want go and ts numbered, new unnumbered (no name yet)", got, err)
|
||||
}
|
||||
if got.Names["go"] != "git.novox.be/novox/mesh-sdk/go" || got.Names["ts"] != "@novox/mesh-sdk" || got.Names["program"] != "mesh-sdk/program" {
|
||||
t.Errorf("names = %v", got.Names)
|
||||
}
|
||||
if !slices.Contains(floorOf, "git.novox.be/novox/mesh-sdk/go") || slices.Contains(floorOf, "mesh-sdk/go") {
|
||||
t.Errorf("the floor was asked of %v, want the Go module path", floorOf)
|
||||
}
|
||||
if es, _ := n.Versions.Of(ctx, "git.novox.be/novox/mesh-sdk/go"); len(es) != 1 || es[0].Version != "0.1.4" {
|
||||
t.Errorf("versions of the Go module path = %+v", es)
|
||||
}
|
||||
if es, _ := n.Versions.Of(ctx, "mesh-sdk/go"); len(es) != 0 {
|
||||
t.Errorf("numbered under the builder's name too: %+v", es)
|
||||
}
|
||||
if err := n.Built(ctx, c, got, map[string]string{"go": "sha256:aa"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if es, _ := n.Versions.Of(ctx, "git.novox.be/novox/mesh-sdk/go"); len(es) != 1 || es[0].Digest != "sha256:aa" {
|
||||
t.Errorf("the built digest is not recorded under the name: %+v", es)
|
||||
}
|
||||
// The indexer writes the name of `new` later: its series key names the module, and the look at the done build
|
||||
// numbers it with the done key's digest; the rest are kept.
|
||||
state["new.0.1"] = []byte(`{"v":1,"name":"new","package":"mesh-sdk/new","series":"0.1"}`)
|
||||
for key, want := range map[string]string{"new.0.1": "mesh-sdk", "git=2enovox=2ebe/novox/mesh-sdk/go": "", "broken.0.1": ""} {
|
||||
if module, name, ok := NamedModule(key, state[key]); module != want || ok != (want != "") || (ok && name != "new") {
|
||||
t.Errorf("NamedModule(%s) = %q, %q, %v, want %q", key, module, name, ok, want)
|
||||
}
|
||||
}
|
||||
done := c
|
||||
done.Done = map[string]string{"go": "sha256:aa", "new": "sha256:bb"}
|
||||
late, err := n.Number(ctx, done)
|
||||
if err != nil || late.Versions["new"] != "0.1.4" || late.Versions["go"] != "0.1.4" || len(late.Unnumbered) != 0 {
|
||||
t.Fatalf("a look at the done build = %+v, %v; want new numbered and go kept", late, err)
|
||||
}
|
||||
if es, _ := n.Versions.Of(ctx, "new"); len(es) != 1 || es[0].Digest != "sha256:bb" {
|
||||
t.Errorf("versions of new = %+v, want its done digest recorded", es)
|
||||
}
|
||||
if _, _, err := NamesIn(packagesMem(nil).failing())(ctx, "m", "a"); err == nil {
|
||||
t.Error("a packages state that cannot be read is no error")
|
||||
}
|
||||
// A packages state not on the bus yet leaves the package unnumbered, said, and numbers the rest of the claim.
|
||||
n.Names = NamesIn(packagesMem(nil).failing())
|
||||
bare, err := n.Number(ctx, c)
|
||||
if err != nil || !reflect.DeepEqual(bare.Unnumbered, []string{"go", "new", "ts"}) || bare.Versions["program"] == "" ||
|
||||
!strings.Contains(bare.Said[0].Line, "cannot be read") {
|
||||
t.Errorf("an unreadable packages state: %+v, %v", bare, err)
|
||||
}
|
||||
})
|
||||
t.Run("fill", func(t *testing.T) {
|
||||
if _, full := Fill(Cap*79/100, Cap); full {
|
||||
@@ -543,46 +270,19 @@ func TestTheBuildersVersions(t *testing.T) {
|
||||
t.Error("80 % is not full")
|
||||
}
|
||||
})
|
||||
t.Run("fresh claims and the floor", func(t *testing.T) {
|
||||
t.Run("a refusal records its digest", func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
// A fresh claim of a published fingerprint takes the next number; the old one stays.
|
||||
st := newMem()
|
||||
v := Versions{Store: st}
|
||||
raw, _ := Encode(Entry{Name: "m/p", Kind: KindBundle, Series: "0.1", Version: "0.1.3", Fingerprint: "f1", State: Published, At: time.Unix(1, 0)})
|
||||
_, _ = st.Create(ctx, Key("m/p", "0.1.3"), raw)
|
||||
if d, _, err := v.Number(ctx, Claim{Name: "m/p", Kind: KindBundle, Fingerprint: "f1"}); err != nil || d.Version != "0.1.3" || !d.Keep {
|
||||
t.Fatalf("a published fingerprint keeps its number: %+v %v", d, err)
|
||||
}
|
||||
if d, e, err := v.Number(ctx, Claim{Name: "m/p", Kind: KindBundle, Fingerprint: "f1", Fresh: true}); err != nil || d.Version != "0.1.4" || d.Keep || e.Fingerprint != "f1" {
|
||||
t.Fatalf("a fresh claim takes the next number: %+v %+v %v", d, e, err)
|
||||
}
|
||||
// A refusal records the digest refused; Built replaces a digest no published was said for, never a published one.
|
||||
seed(t, st, Entry{Name: "m/p", Kind: KindBundle, Series: "0.1", Version: "0.1.4", Fingerprint: "f1", State: Numbered, At: time.Unix(1, 0)})
|
||||
n := &Numberer{Versions: v}
|
||||
_, _ = n.Heard(ctx, SeatArtifacts, HeardRefused, "r1", Outcome{Name: "m/p", Version: "0.1.4", Digest: "sha256:old", Reason: "x"})
|
||||
if es, _ := v.Of(ctx, "m/p"); es[1].RefusedDigest != "sha256:old" {
|
||||
t.Errorf("refused records no digest: %+v", es[1])
|
||||
_ = n.Heard(ctx, SeatArtifacts, HeardRefused, "r1", Outcome{Name: "m/p", Version: "0.1.4", Digest: "sha256:old", Reason: "x"})
|
||||
if es, _ := v.Of(ctx, "m/p"); es[0].RefusedDigest != "sha256:old" {
|
||||
t.Errorf("refused records no digest: %+v", es[0])
|
||||
}
|
||||
_, _ = v.Mark(ctx, "m/p", "0.1.4", func(e *Entry) { e.Digest = "sha256:old" })
|
||||
bc := BuildClaim{Module: "m"}
|
||||
_ = n.Built(ctx, bc, Numbering{Versions: map[string]string{"p": "0.1.4"}}, map[string]string{"p": "sha256:new"})
|
||||
_, _ = v.Mark(ctx, "m/p", "0.1.3", func(e *Entry) { e.Digest = "sha256:held" })
|
||||
_ = n.Built(ctx, bc, Numbering{Versions: map[string]string{"p": "0.1.3"}}, map[string]string{"p": "sha256:other"})
|
||||
es, _ := v.Of(ctx, "m/p")
|
||||
if es[0].Digest != "sha256:held" || es[1].Digest != "sha256:new" {
|
||||
t.Errorf("Built: published %s (want sha256:held), refused %s (want sha256:new)", es[0].Digest, es[1].Digest)
|
||||
}
|
||||
if all, err := v.All(ctx); err != nil || len(all) != 2 {
|
||||
if all, err := v.All(ctx); err != nil || len(all) != 1 {
|
||||
t.Errorf("All = %d entries, %v", len(all), err)
|
||||
}
|
||||
_, _ = v.Mark(ctx, "m/p", "0.1.4", func(e *Entry) { e.State = Published })
|
||||
acts := Acts{Numberer: &Numberer{Versions: v, Waits: &FloorWaits{}}, Reconsider: func(context.Context) {}}
|
||||
reconsidered := false
|
||||
acts.Reconsider = func(context.Context) { reconsidered = true }
|
||||
// H-A-159: the builder numbers nothing of its own, so no claim asks a floor: the tool refuses, saying so, and does nothing.
|
||||
for _, name := range []string{"m/p", "m/new"} {
|
||||
if ans, err := acts.FloorAgain(ctx, name); err == nil || !strings.Contains(err.Error(), "numbers nothing of its own") || reconsidered {
|
||||
t.Errorf("floor again of %s: %q %v, looked again %v; want refused naming H-A-159, nothing looked at", name, ans, err, reconsidered)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ func TestManifestDeclarations(t *testing.T) { // 1607/AC1
|
||||
if m.Module != "mesh-delivery-builder" {
|
||||
t.Errorf("module = %q", m.Module)
|
||||
}
|
||||
if want := []state{{Name: "builds", History: 5, MaxMiB: 128}, {Name: "engine-reads", History: 1, MaxMiB: 8}, {Name: "findings", History: 5, MaxMiB: 32}, {Name: "floor-waits", History: 1, MaxMiB: 8}, {Name: "hearing", History: 1, MaxMiB: 8}, {Name: "instances", History: 1, MaxMiB: 8}, {Name: "old-form", History: 1, MaxMiB: 8}, {Name: "bounds", History: 1, KeyTTL: true, MaxMiB: 16}, {Name: "taken", History: 1, KeyTTL: true, MaxMiB: 8}, {Name: "queues", History: 1, MaxMiB: 8}, {Name: "toolchains-heard", History: 1, MaxMiB: 8}, {Name: "waits", History: 1, MaxMiB: 4}, {Name: "reserved", History: 1, MaxMiB: 8}, {Name: "acted", History: 1, MaxMiB: 1}, {Name: "asked", History: 1, MaxMiB: 8}, {Name: "reasks", History: 1, MaxMiB: 8}, {Name: "versions", History: 1, MaxMiB: 32}, {Name: "first-views", History: 1, MaxMiB: 8}, {Name: "unbuildable", History: 1, MaxMiB: 8}, {Name: "consumers", History: 1, MaxMiB: 8}}; !reflect.DeepEqual(m.State, want) { // builds.BuilderBuildsHistory // caps per H-A-437 over the fills read on novox 2026-11-22 (design 47 H2 §812, §814)
|
||||
if want := []state{{Name: "builds", History: 5, MaxMiB: 128}, {Name: "engine-reads", History: 1, MaxMiB: 8}, {Name: "findings", History: 5, MaxMiB: 32}, {Name: "hearing", History: 1, MaxMiB: 8}, {Name: "instances", History: 1, MaxMiB: 8}, {Name: "old-form", History: 1, MaxMiB: 8}, {Name: "bounds", History: 1, KeyTTL: true, MaxMiB: 16}, {Name: "taken", History: 1, KeyTTL: true, MaxMiB: 8}, {Name: "queues", History: 1, MaxMiB: 8}, {Name: "toolchains-heard", History: 1, MaxMiB: 8}, {Name: "waits", History: 1, MaxMiB: 4}, {Name: "reserved", History: 1, MaxMiB: 8}, {Name: "acted", History: 1, MaxMiB: 1}, {Name: "asked", History: 1, MaxMiB: 8}, {Name: "reasks", History: 1, MaxMiB: 8}, {Name: "versions", History: 1, MaxMiB: 32}, {Name: "first-views", History: 1, MaxMiB: 8}, {Name: "unbuildable", History: 1, MaxMiB: 8}, {Name: "consumers", History: 1, MaxMiB: 8}}; !reflect.DeepEqual(m.State, want) { // builds.BuilderBuildsHistory // caps per H-A-437 over the fills read on novox 2026-11-22 (design 47 H2 §812, §814)
|
||||
t.Errorf("state = %+v, want %+v", m.State, want)
|
||||
}
|
||||
// 1887/A4c: the builder chooses no node, so it reads neither presence nor have, invokes no build module's tool and
|
||||
@@ -149,10 +149,10 @@ func TestManifestDeclarations(t *testing.T) { // 1607/AC1
|
||||
t.Errorf("reads %s: the indexer's and the assigner's state is read by their tools and views families alone", r)
|
||||
}
|
||||
}
|
||||
// Design 51 *The floor*: the floor's three sources, the registry seats' versions, git.tags and indexer_requirements.
|
||||
// Design 47 H §756: the floor goes, and with it its source git.tags; the registry seats' versions are asked of a number a
|
||||
// registry holds (H-A-275) and of a package's published versions (H-A-194).
|
||||
// The watchdogs seat's presence says a node's machine is heard (issue 1966, ADR 0596 §2, ADR 0668 §3).
|
||||
if want := []string{"seat:mesh-catalog.entry", "seat:mesh-catalog.registrations", "seat:mesh-catalog.seat-definitions", "seat:mesh-catalog.revision", "seat:mesh-delivery.source", "seat:container-image-registry.publish", "seat:container-image-registry.remove", "seat:container-image-registry.versions",
|
||||
"seat:git.tags", // the floor's source alone: no tag is written at a release (design 47 H2 H-A-494)
|
||||
"seat:go-package-registry.publish", "seat:go-package-registry.remove", "seat:go-package-registry.versions", "seat:mesh-artifact-sweep.held", "seat:mesh-builds.reserved", "seat:mesh-builds.drop", "seat:mesh-builds.publish-queue", "seat:mesh-catalog.versions", "seat:mesh-hand-acts.hand-act", "seat:mesh-module-assigner.assignments", "seat:mesh-watchdogs.presence", "seat:node-build-go.drop", "seat:node-build-image.drop", "seat:node-build-node.drop", "seat:node-build-go.answer", "seat:node-build-image.answer", "seat:node-build-node.answer", "seat:node-engine.manifest-reads", "seat:npm-package-registry.publish", "seat:npm-package-registry.remove",
|
||||
"seat:npm-package-registry.versions", "seat:oci-artifact-registry.publish", "seat:oci-artifact-registry.remove", "seat:oci-artifact-registry.versions",
|
||||
// A-231: the build asks on each build seat's queue delivery (accept.delivery.<asker>).
|
||||
@@ -162,14 +162,13 @@ func TestManifestDeclarations(t *testing.T) { // 1607/AC1
|
||||
// The builder hears the build seats' toolchain-reported and the node-engine seat's running (design 47 G §492, §546) and reads no
|
||||
// build module's toolchains; and by the seat mesh-artifact-sweep's artifacts-gone, a blob the sweep found gone (1937/AC4, 1955/L7), the
|
||||
// controller's no longer (1126/B9, ADR 0590).
|
||||
// Design 51 *The floor*: the indexer's take-in.taken (design 47 H H-A-116) and the condition keeper's condition-cleared wake
|
||||
// a silent floor.
|
||||
// Design 47 H §756: the floor and its wait go, so neither the indexer's take-in.taken (H-A-116) nor condition-cleared is heard.
|
||||
// DLV-B4: the four registry seats' outcomes, each a seat event `<seat>.<event>` on the shared events stream.
|
||||
// DLV-M1: the indexer's and the assigner's views families of the states it follows.
|
||||
if want := []string{"container-image-registry.kept", "container-image-registry.published", "container-image-registry.refused", "container-image-registry.removed",
|
||||
"go-package-registry.kept", "go-package-registry.published", "go-package-registry.refused", "go-package-registry.removed",
|
||||
"mesh-artifact-sweep.artifacts-gone", "mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed", "mesh-catalog.version-released", "mesh-catalog.versions-filled",
|
||||
"mesh-conditions.condition-cleared", "mesh-conditions.findings-asked", "mesh-delivery-indexer.take-in.taken", "seat:mesh-module-assigner.views.assignments",
|
||||
"mesh-conditions.findings-asked", "seat:mesh-module-assigner.views.assignments",
|
||||
"seat:mesh-module-assigner.views.seat-holders", // A-298: the claimant's seat-holders view resolves the callers' seat entries
|
||||
"mesh-catalog.catalog-revision", "mesh-catalog.registration-changed", "mesh-delivery.source-moved", "node-build-go.toolchain-reported", "node-build-node.toolchain-reported", "node-engine.manifest-reads-changed", "node-engine.running",
|
||||
"npm-package-registry.kept", "npm-package-registry.published", "npm-package-registry.refused", "npm-package-registry.removed",
|
||||
@@ -185,7 +184,7 @@ func TestManifestDeclarations(t *testing.T) { // 1607/AC1
|
||||
}
|
||||
// 1945: the builder's tools (builder_seat_queue: note 62), served by its tools bundle, and the event it says when it asks an ask again.
|
||||
if want := []string{"build_current", "builder_announce_again", "builder_ask_again", "builder_ask_drop", "builder_asks", "builder_bounds", "builder_build", "builder_build_again", "builder_builds_since", "builder_engine_reads", "builder_first_view_again", "builder_first_views",
|
||||
"builder_floor_again", "builder_floor_waits", "builder_health", "builder_old_form", "builder_publish_again", "builder_publish_queue", "builder_release", "builder_reserve_done", "builder_reserved", "builder_reserved_drop", "builder_seat_list", "builder_seat_list_again", "builder_seat_queue", "builder_stuck", "builder_toolchains", "builder_toolchains_drop", "builder_unbuildable", "builder_versions", "builder_waits"}; !reflect.DeepEqual(sorted(m.Tools), want) {
|
||||
"builder_health", "builder_old_form", "builder_publish_again", "builder_publish_queue", "builder_release", "builder_reserve_done", "builder_reserved", "builder_reserved_drop", "builder_seat_list", "builder_seat_list_again", "builder_seat_queue", "builder_stuck", "builder_toolchains", "builder_toolchains_drop", "builder_unbuildable", "builder_versions", "builder_waits"}; !reflect.DeepEqual(sorted(m.Tools), want) {
|
||||
t.Errorf("tools = %v, want %v", m.Tools, want)
|
||||
}
|
||||
// Design 47 G §672: the toolchain waits' stream, kept 7 days within 16 MiB, and the bound's setting, 60 minutes.
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
"builder_build_again",
|
||||
"builder_builds_since",
|
||||
"builder_engine_reads",
|
||||
"builder_floor_again",
|
||||
"builder_floor_waits",
|
||||
"builder_old_form",
|
||||
"builder_publish_again",
|
||||
"builder_publish_queue",
|
||||
@@ -67,8 +65,6 @@
|
||||
"mesh-catalog.seat-definition-removed",
|
||||
"mesh-catalog.version-released",
|
||||
"mesh-catalog.versions-filled",
|
||||
"mesh-conditions.condition-cleared",
|
||||
"mesh-delivery-indexer.take-in.taken",
|
||||
"node-build-go.toolchain-reported",
|
||||
"node-build-node.toolchain-reported",
|
||||
"node-engine.manifest-reads-changed",
|
||||
@@ -91,7 +87,6 @@
|
||||
"invokes": [
|
||||
"seat:container-image-registry.remove",
|
||||
"seat:container-image-registry.versions",
|
||||
"seat:git.tags",
|
||||
"seat:go-package-registry.remove",
|
||||
"seat:go-package-registry.versions",
|
||||
"seat:mesh-artifact-sweep.held",
|
||||
@@ -133,7 +128,6 @@
|
||||
{ "name": "builds", "history": 5, "max-mib": 128 },
|
||||
{ "name": "engine-reads", "history": 1, "max-mib": 8 },
|
||||
{ "name": "findings", "history": 5, "max-mib": 32 },
|
||||
{ "name": "floor-waits", "history": 1, "max-mib": 8 },
|
||||
{ "name": "hearing", "history": 1, "max-mib": 8 },
|
||||
{ "name": "instances", "history": 1, "max-mib": 8 },
|
||||
{ "name": "old-form", "history": 1, "max-mib": 8 },
|
||||
|
||||
Reference in New Issue
Block a user