B1b: the builder's numberer and its state versions go; builder_versions answers from the reservations
The numbering from before G goes (design 47 H §756, G §372): the builder keeps no state versions, marks no numbered entry on a registry seat's word and arms no numbered version's publish bound; the publishes' findings and the reservations still hear the same events (DQ-11), and a reserved version's bound is the reservation's (DQ-10). builder_versions keeps answering, from the reservations alone (DMC-5): what the seat mesh-builds' reserved answers for a name and, with a version and a digest, whether that version is reserved or released with that digest. Builds: design 47 H §756, G §372, G §381, H2 H-A-532 (DMC-5, DQ-10, DQ-11), spec 29, 41, 48
This commit is contained in:
@@ -41,9 +41,9 @@ type queueAsker func(key string, value []byte) (json.RawMessage, error)
|
||||
// Tools are the builder's tools: stuck reads, askAgain writes the reasks value, queue writes a queues value and waits for
|
||||
// the builder's read, buildAgain writes a reasks value of mode build and waits for the builder's answer.
|
||||
//
|
||||
// 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,
|
||||
// builder_versions answers from the reservations alone, what the verb reserved answers for a name (reserve; design 47 G §572,
|
||||
// H §756): the bundle calls the seat mesh-builds through its invokes, as any caller does.
|
||||
func Tools(r build.StuckReader, askAgain func(key string, value []byte) error, queue, buildAgain queueAsker, since build.LogSince, now func() time.Time,
|
||||
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.
|
||||
@@ -81,16 +81,7 @@ func Tools(r build.StuckReader, askAgain func(key string, value []byte) error, q
|
||||
"version": map[string]any{"type": "string", "description": "one version, to ask whether it is recorded"},
|
||||
"digest": map[string]any{"type": "string", "description": "with version: the digest the holder received"}}},
|
||||
Run: func(args map[string]any) (any, error) {
|
||||
out, err := versions.AnswerVersions(context.Background(), vs, str(args, "name"), str(args, "version"), str(args, "digest"))
|
||||
if err != nil || reserve == nil {
|
||||
return out, err
|
||||
}
|
||||
ra, err := reserve(out.Name, str(args, "version"))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the seat mesh-builds' reserved did not answer for %s: %w", out.Name, err)
|
||||
}
|
||||
out.Reserved = &ra
|
||||
return out, nil
|
||||
return versions.AnswerVersions(str(args, "name"), str(args, "version"), str(args, "digest"), reserve)
|
||||
}},
|
||||
{Name: build.StuckTool,
|
||||
Description: "Every build key that waits (building or queued), oldest first: its module, fingerprint, step words and since when, and each ask it " +
|
||||
@@ -348,14 +339,6 @@ func main() {
|
||||
a, err := build.DecodeReAsk(v)
|
||||
return err == nil && !a.Answered.IsZero()
|
||||
})
|
||||
vs := stdio.State(versions.State)
|
||||
vr := versions.Reader{Keys: vs.Keys, Get: func(key string) (json.RawMessage, bool, error) {
|
||||
e, err := vs.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)
|
||||
@@ -411,7 +394,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, ofr, reserve)
|
||||
tools := Tools(r, put, askQueue(stdio.State(build.QueuesState), 25*time.Second), buildAgain, stdio.Log(builds.BuilderLog).Since, time.Now, 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, reserve)
|
||||
tools := Tools(build.StuckReader{}, nil, nil, nil, nil, time.Now, 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"})
|
||||
|
||||
@@ -9,12 +9,12 @@ import (
|
||||
// ownBuckets are the buckets of the builder's own states, each `<module>_<state>` of the module its credential names, never
|
||||
// a constant (design 47 G A-296, §428).
|
||||
type ownBuckets struct {
|
||||
versions, bounds, reserved, queue, acted, toolchainsHeard, instances string
|
||||
bounds, reserved, queue, acted, toolchainsHeard, instances string
|
||||
}
|
||||
|
||||
func ownBucketsOf(module string) ownBuckets {
|
||||
return ownBuckets{
|
||||
versions: builds.StateBucket(module, versions.State), bounds: builds.StateBucket(module, versions.BoundsState),
|
||||
bounds: builds.StateBucket(module, versions.BoundsState),
|
||||
reserved: builds.StateBucket(module, versions.ReservedState), queue: builds.StateBucket(module, versions.PublishQueueState),
|
||||
acted: builds.StateBucket(module, versions.ActedState), toolchainsHeard: builds.StateBucket(module, buildrun.ToolchainsHeardState),
|
||||
instances: builds.StateBucket(module, instancesState),
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
@@ -570,7 +569,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 and findings are on the bus, the seat answering 0.1.4; two merges close
|
||||
// The builder's 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")
|
||||
@@ -583,12 +582,6 @@ func TestBuilderMakesADoneKeyWithTheDigests(t *testing.T) { // 1607/AC7
|
||||
doneBound := map[string]string{"MESH_BUILDER_STEP_BOUND": testbus.SetupBound(t).String()}
|
||||
b.start(t, "n1", doneBound)
|
||||
v := b.await(t, "netcheck", isState(builds.BuildDone))
|
||||
for _, a := range []string{"tools-go", "tools-typescript"} {
|
||||
es := reg.of(t, "netcheck/"+a)
|
||||
if len(es) != 0 {
|
||||
t.Errorf("versions of netcheck/%s = %+v, want none: the builder numbers nothing of its own (H-A-159)", a, es)
|
||||
}
|
||||
}
|
||||
if v.By != "n1.mesh-delivery-builder" || v.Manifest != digest || len(v.Artifacts) != 2 {
|
||||
t.Fatalf("build = %+v", v)
|
||||
}
|
||||
@@ -657,17 +650,6 @@ func TestBuilderMakesADoneKeyWithTheDigests(t *testing.T) { // 1607/AC7
|
||||
if got := reg.numberedOf("netcheck/tools-go"); len(got) != 0 {
|
||||
t.Errorf("version.numbered of netcheck/tools-go said %v, want none", got)
|
||||
}
|
||||
// Versions numbered before G, which the state keeps until G §372 removes it: one a holder removes below, one it refuses.
|
||||
kept, _ := json.Marshal(versions.Entry{Name: "netcheck/tools-typescript", Kind: versions.KindBundle, Series: "0.1", Version: "0.1.5", Module: "netcheck",
|
||||
Fingerprint: fp, Digest: digestOf("tools-typescript"), Seat: ociartifactregistry.Seat, State: versions.Published, At: time.Now().UTC()})
|
||||
if _, err := reg.versions.Put(b.ctx, versions.Key("netcheck/tools-typescript", "0.1.5"), kept); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
refusable, _ := json.Marshal(versions.Entry{Name: "netcheck/tools-go", Kind: versions.KindBundle, Series: "0.1", Version: "0.1.6", Module: "netcheck",
|
||||
Fingerprint: "src2:" + strings.Repeat("6", 64), Seat: ociartifactregistry.Seat, State: versions.Numbered, At: time.Now().UTC()})
|
||||
if _, err := reg.versions.Put(b.ctx, versions.Key("netcheck/tools-go", "0.1.6"), refusable); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := reg.numberedOf("netcheck/tools-go"); len(got) != 0 {
|
||||
t.Errorf("version.numbered of netcheck/tools-go said %v, want none", got)
|
||||
}
|
||||
@@ -700,20 +682,10 @@ func TestBuilderMakesADoneKeyWithTheDigests(t *testing.T) { // 1607/AC7
|
||||
b.moduleFP(t, "netcheck", netcheck, "modules/netcheck", bothToolchains, "89abcdef0123456789abcdef0123456789abcdef", third, 3) // the entry moves to a later commit, same fingerprint
|
||||
b.awaitFP(t, "netcheck", third, isState(builds.BuildDone))
|
||||
reg.awaitFinding(t, failed, false)
|
||||
// DLV-B4: the seats' refused and removed, heard on the builder's durable consumer, move a numbered version: a retention
|
||||
// removal turns the entry removed with its reason, a refusal refused with the holder's reason and the bytes it refused.
|
||||
reg.outcome(t, ociartifactregistry.SubjectRemoved, versions.Outcome{Name: "netcheck/tools-typescript", Version: "0.1.5", Kind: "bundle", Holder: "distribution", Reason: "retention"})
|
||||
// DLV-B4: a seat's refused, heard on the builder's durable consumer, is the finding publish-refused about the name with the
|
||||
// holder's reason; the numbering from before G, which marked its state versions, is gone (design 47 H §756).
|
||||
reg.outcome(t, ociartifactregistry.SubjectRefused, versions.Outcome{Name: "netcheck/tools-go", Version: "0.1.6", Digest: digestOf("other"), Kind: "bundle", Holder: "distribution", Reason: "the cap"})
|
||||
reg.awaitOf(t, "netcheck/tools-typescript", func(es []versions.Entry) bool {
|
||||
return slices.ContainsFunc(es, func(e versions.Entry) bool {
|
||||
return e.Version == "0.1.5" && e.State == versions.Removed && e.Reason == "retention"
|
||||
})
|
||||
})
|
||||
reg.awaitOf(t, "netcheck/tools-go", func(es []versions.Entry) bool {
|
||||
return slices.ContainsFunc(es, func(e versions.Entry) bool {
|
||||
return e.Version == "0.1.6" && e.State == versions.Refused && e.Reason == "the cap" && e.RefusedDigest == digestOf("other")
|
||||
})
|
||||
})
|
||||
reg.awaitFinding(t, meshconditionsclient.Key(meshconditionsclient.ScopeModule, "netcheck/tools-go", versions.PublishRefused), true)
|
||||
}
|
||||
|
||||
// TestAnArchiveOnlyModuleAndARootModuleAreBuilt: the indexer gives an archive no language, so modules.ca-trust has no
|
||||
@@ -1130,14 +1102,14 @@ func TestARestartedBuilderPutsNoSecondAsk(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// registry is the part of the bed design 51's builder cases need: the builder's states versions, findings and reasks, EVENTS
|
||||
// registry is the part of the bed design 51's builder cases need: the builder's states 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
|
||||
mu sync.Mutex
|
||||
numbered []string // the bodies said on the subject version.numbered was said on before design 47 G §349
|
||||
b *bed
|
||||
findings, reasks jetstream.KeyValue
|
||||
mu sync.Mutex
|
||||
numbered []string // the bodies said on the subject version.numbered was said on before design 47 G §349
|
||||
}
|
||||
|
||||
func (b *bed) registry(t *testing.T, node string, seatVersions ...string) *registry {
|
||||
@@ -1150,7 +1122,7 @@ 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))
|
||||
r.findings, r.reasks = mk(builds.StateBucket(builds.BuilderModule, mcseat.StateFindings)), mk(builds.StateBucket(builds.BuilderModule, build.ReAsksState))
|
||||
// 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.>"},
|
||||
@@ -1191,42 +1163,6 @@ func (b *bed) registry(t *testing.T, node string, seatVersions ...string) *regis
|
||||
return r
|
||||
}
|
||||
|
||||
// of is every entry versions holds of name.
|
||||
func (r *registry) of(t *testing.T, name string) []versions.Entry {
|
||||
t.Helper()
|
||||
l, err := r.versions.ListKeysFiltered(r.b.ctx, versions.NameFilter(name))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() { _ = l.Stop() }()
|
||||
var out []versions.Entry
|
||||
for k := range l.Keys() {
|
||||
e, err := r.versions.Get(r.b.ctx, k)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var v versions.Entry
|
||||
if err := json.Unmarshal(e.Value(), &v); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
out = append(out, v)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// awaitOf reads name's entries until pred holds of them, within 20 s.
|
||||
func (r *registry) awaitOf(t *testing.T, name string, pred func([]versions.Entry) bool) []versions.Entry {
|
||||
t.Helper()
|
||||
var es []versions.Entry
|
||||
for deadline := time.Now().Add(20 * time.Second); time.Now().Before(deadline); time.Sleep(50 * time.Millisecond) {
|
||||
if es = r.of(t, name); pred(es) {
|
||||
return es
|
||||
}
|
||||
}
|
||||
t.Fatalf("versions of %s = %+v within 20 s", name, es)
|
||||
return es
|
||||
}
|
||||
|
||||
// published says the artifact seat's published for name@version, as its holder does.
|
||||
func (r *registry) published(t *testing.T, name, version, digest string) {
|
||||
t.Helper()
|
||||
|
||||
@@ -159,17 +159,12 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
conn.SetReconnectHandler(func(*nats.Conn) { hearing.Again(); heard.Nudge("") })
|
||||
// The builder asks the controller, as its own account, whether the artifact store still holds a done key's blobs
|
||||
// (the seat verb held, novox/hq issue 1937) before it leaves the key done, on its calls connection.
|
||||
// The state versions, kept from before G (design 51 *The versions*) and read through builder_versions until G §372 removes
|
||||
// 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}
|
||||
// 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}
|
||||
pubs := &publishes{findings: found}
|
||||
stepExpiry := &buildrun.Expiry{}
|
||||
var b *build.Builder
|
||||
seatsChanged := func(ctx context.Context) {
|
||||
@@ -241,7 +236,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
// The versions a build reserves at its start (design 47 G §369): its state reserved, and the catalog's versions-filled
|
||||
// and version-released heard; nothing is reserved before the fill.
|
||||
reservedKV := process.AwaitBucket(ctx, js, conn, own.reserved, "no version is reserved: builds are made unreserved", logger.Printf)
|
||||
reserved := newReservations(awaitedReserved{awaitedVersions{b: reservedKV, bucket: own.reserved}}, calls.Call, pubBoundsKV.KV, found, b.Reconsider, logger.Printf)
|
||||
reserved := newReservations(awaitedReserved{awaitedState{b: reservedKV, bucket: own.reserved}}, calls.Call, pubBoundsKV.KV, found, b.Reconsider, logger.Printf)
|
||||
// The index by digest and by version beside the reservations is written again once the state is bound (H-A-269 (1), H-A-271).
|
||||
reservedKV.Ready(func(jetstream.KeyValue) { reserved.reindex(ctx) })
|
||||
// Each artifact the holder says published at a reserved version is said as the seat mesh-builds' package-published (design 47 G §52).
|
||||
@@ -257,10 +252,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
reserved.recordAgain = b.RecordAgain // a done build's digests its end did not record are recorded at the start (H-A-492)
|
||||
// The last versions-filled the stream keeps is read at the start (design 47 G §369, §372): a restart does not lose it.
|
||||
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_reserved_drop) come through reasks, as builder_build_again.
|
||||
acts := versions.Acts{Numberer: numberer, DropReserved: reserved.dropped}
|
||||
acts := versions.Acts{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)
|
||||
@@ -323,7 +316,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
reserved.releasedAtStart(ctx)
|
||||
items.AskAllDone(ctx)
|
||||
})
|
||||
wirePublishItems(reserved, items, awaitedReserved{awaitedVersions{b: actedKV, bucket: own.acted}}, releasedKept)
|
||||
wirePublishItems(reserved, items, awaitedReserved{awaitedState{b: actedKV, bucket: own.acted}}, releasedKept)
|
||||
acts.Republish = republish.Republish
|
||||
acts.PublishDrop = func(ctx context.Context, module, version, by, why string) (string, error) {
|
||||
return pq.drop(ctx, items, module, version, by, why)
|
||||
@@ -332,7 +325,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
acts.ReserveDone = reserveDoneAct(b.ReserveDone, republish.Republish, logger.Printf)
|
||||
// The operator is asked once a key's event builds are spent (design 47 G §568): the builder's asker on the seat operator-channel.
|
||||
decided := &decisions{subject: oc.SubjectDecided(cred.Module)}
|
||||
retakeActed := awaitedReserved{awaitedVersions{b: actedKV, bucket: own.acted}}
|
||||
retakeActed := awaitedReserved{awaitedState{b: actedKV, bucket: own.acted}}
|
||||
asker := &operatorask.Asker[oc.Warrant]{Module: cred.Module, Call: calls.Call, Record: calls.Ask, Publish: publishVia(ctx, js), Subscribe: decided.hear(logger.Printf),
|
||||
Contract: operatorask.Contract{Seat: oc.Seat, StateAsks: oc.StateAsks},
|
||||
AskSubject: oc.AcceptSubjectAsk, DecidedSubject: oc.SubjectDecided}
|
||||
@@ -470,7 +463,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
// 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.
|
||||
// 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}
|
||||
seatHeard := seatHearer{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
|
||||
// (design 47 H2 §794; H-A-461 (2)).
|
||||
slow, err := slowEvent()
|
||||
@@ -615,7 +608,6 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
}
|
||||
return
|
||||
}
|
||||
pubs.ended(ctx, e)
|
||||
}
|
||||
watchBounds(ctx, kv, each, found.notHeard(ctx), errs, logger.Printf)
|
||||
})
|
||||
|
||||
@@ -48,7 +48,6 @@ func TestTheNamesAreTheManifests(t *testing.T) {
|
||||
"mesh-build-go_steps": buildrun.StepsBucket("mesh-build-go"),
|
||||
ownBucketsOf("acme-builder").toolchainsHeard: "acme-builder_toolchains-heard",
|
||||
ownBucketsOf("acme-builder").bounds: "acme-builder_bounds",
|
||||
ownBucketsOf("acme-builder").versions: "acme-builder_versions",
|
||||
ownBucketsOf("acme-builder").instances: "acme-builder_instances",
|
||||
} {
|
||||
if want != got {
|
||||
|
||||
@@ -2,9 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
@@ -17,53 +15,15 @@ import (
|
||||
)
|
||||
|
||||
// publishes raises and clears the builder's findings of a publish that ended badly (versions/publish.go): a holder's
|
||||
// refused, a version unanswered past its bound, kept as a key of the state bounds with its own time to live, and a seat's
|
||||
// outcome that does not read.
|
||||
// refused and a seat's outcome that does not read. A reserved version left unpublished is the reservation's bound (design 47
|
||||
// G §369, design 47 H §756: the numbered version's bound goes with the numbering from before G).
|
||||
type publishes struct {
|
||||
bounds func() jetstream.KeyValue
|
||||
versions versions.Versions
|
||||
findings *findings
|
||||
bound time.Duration
|
||||
logf func(string, ...any)
|
||||
}
|
||||
|
||||
// arm writes the version's bound when none stands, so a standing bound keeps its time. A bound that cannot be written
|
||||
// would never end, so the version is publish-unanswered at once (review round 2): the finding says why.
|
||||
func (p *publishes) arm(ctx context.Context, e versions.Entry) {
|
||||
kv := p.bounds()
|
||||
var err error
|
||||
if kv == nil {
|
||||
err = fmt.Errorf("%s is not on the bus yet", versions.BoundsState)
|
||||
} else if _, err = kv.Create(ctx, versions.PublishBoundKey(e.Name, e.Version), versions.EncodeBound("the publish of "+e.Name+"@"+e.Version+" to "+e.Seat, time.Now().Add(p.bound)), jetstream.KeyTTL(p.bound)); errors.Is(err, jetstream.ErrKeyExists) {
|
||||
err = nil
|
||||
}
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
p.logf("the publish bound of %s@%s is not written, so it is raised unanswered now: %v", e.Name, e.Version, err)
|
||||
p.unanswered(ctx, e, fmt.Sprintf("its bound could not be written (%v), so the builder cannot wait on the holder's word", err))
|
||||
}
|
||||
|
||||
// unanswered raises publish-unanswered about e's name, saying why.
|
||||
func (p *publishes) unanswered(ctx context.Context, v versions.Entry, why string) {
|
||||
p.findings.raise(ctx, finding{kind: versions.PublishUnanswered, scope: meshconditionsclient.ScopeModule, id: v.Name,
|
||||
summary: fmt.Sprintf("%s said neither published nor refused of %s@%s: %s", v.Seat, v.Name, v.Version, why),
|
||||
headline: "A registry seat did not answer a publish",
|
||||
explanation: "The builder built and numbered " + v.Name + " " + v.Version + " and asked " + v.Seat + " to publish it; no word of its holder is known, so the build says done while the version may not be in the registry.",
|
||||
resolved: "That version is published, or a later version of " + v.Name + " is.",
|
||||
needs: "a look at the holder of " + v.Seat + " (its health and log); builder_publish_again asks the publish again."})
|
||||
}
|
||||
|
||||
// heard is told each holder's word the numberer took in: published clears the name's findings, refused raises
|
||||
// publish-refused with the holder's reason, and either ends the version's bound.
|
||||
// heard is told each holder's word: published clears the name's findings (publish-unanswered too, raised by a builder of
|
||||
// before the change), refused raises publish-refused with the holder's reason.
|
||||
func (p *publishes) heard(ctx context.Context, seat, event string, o versions.Outcome) {
|
||||
if o.Version != "" {
|
||||
if kv := p.bounds(); kv != nil {
|
||||
if err := kv.Delete(ctx, versions.PublishBoundKey(o.Name, o.Version)); err != nil && !errors.Is(err, jetstream.ErrKeyNotFound) {
|
||||
p.logf("the publish bound of %s@%s is not ended: %v", o.Name, o.Version, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
switch event {
|
||||
case versions.HeardPublished:
|
||||
p.findings.clear(ctx, versions.PublishRefused, meshconditionsclient.ScopeModule, o.Name)
|
||||
@@ -78,7 +38,7 @@ func (p *publishes) heard(ctx context.Context, seat, event string, o versions.Ou
|
||||
headline: "A registry seat refused a publish",
|
||||
explanation: "The builder built and numbered " + o.Name + " " + o.Version + ", and the holder of " + seat + " refused to store it, so that version is not in the registry.",
|
||||
resolved: "That version is published, or a later version of " + o.Name + " is.",
|
||||
needs: "builder_versions shows the version and why; builder_publish_again publishes it again once the cause is mended."})
|
||||
needs: "builder_reserved shows the version and why; builder_publish_again publishes it again once the cause is mended."})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,24 +56,6 @@ func (p *publishes) read(ctx context.Context, seat string) {
|
||||
p.findings.clear(ctx, versions.SeatOutcomeUnread, meshconditionsclient.ScopeModule, seat)
|
||||
}
|
||||
|
||||
// ended is told each change of the state bounds: a bound whose time ended (the bus's marker) on a version still numbered
|
||||
// raises publish-unanswered.
|
||||
func (p *publishes) ended(ctx context.Context, e jetstream.KeyValueEntry) {
|
||||
key, ok := versions.PublishBoundOf(e.Key())
|
||||
if e.Operation() != jetstream.KeyValuePurge || !ok {
|
||||
return
|
||||
}
|
||||
raw, _, found, err := p.versions.Store.Get(ctx, key)
|
||||
if err != nil || !found {
|
||||
return
|
||||
}
|
||||
v, err := versions.Decode(raw)
|
||||
if err != nil || v.State != versions.Numbered {
|
||||
return
|
||||
}
|
||||
p.unanswered(ctx, v, fmt.Sprintf("nothing within %s of its build", p.bound))
|
||||
}
|
||||
|
||||
// watchBounds watches the state bounds, handing each change to each: a watch that cannot start loses every bound's end,
|
||||
// so it is the finding family-not-heard naming the state until a later start watches it (review round 2).
|
||||
func watchBounds(ctx context.Context, kv jetstream.KeyValue, each func(jetstream.KeyValueEntry), w heard.Writer, errs chan<- error, logf func(string, ...any)) {
|
||||
|
||||
@@ -253,7 +253,7 @@ func (m *wakeMsg) Headers() nats.Header {
|
||||
func aSeatsOutcomeIsHeard(t *testing.T) {
|
||||
var logs bytes.Buffer
|
||||
// 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}
|
||||
h := &seatHearer{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 || byDigest.naked {
|
||||
t.Fatalf("published: acked %v, naked %v, log %q", byDigest.acked, byDigest.naked, logs.String())
|
||||
@@ -293,27 +293,6 @@ func aSeatsOutcomeIsHeard(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// noVersions is a state versions that holds nothing.
|
||||
type noVersions struct{}
|
||||
|
||||
func (noVersions) Get(context.Context, string) ([]byte, uint64, bool, error) {
|
||||
return nil, 0, false, nil
|
||||
}
|
||||
func (noVersions) Create(context.Context, string, []byte) (uint64, error) {
|
||||
return 0, errors.New("read only")
|
||||
}
|
||||
func (noVersions) Update(context.Context, string, []byte, uint64) (uint64, error) {
|
||||
return 0, errors.New("read only")
|
||||
}
|
||||
func (noVersions) KeysOf(context.Context, string) ([]string, error) { return nil, nil }
|
||||
|
||||
// failingVersions is a state versions that cannot be read.
|
||||
type failingVersions struct{ noVersions }
|
||||
|
||||
func (failingVersions) KeysOf(context.Context, string) ([]string, error) {
|
||||
return nil, errors.New("down")
|
||||
}
|
||||
|
||||
func aFailedTrunkBuildIsAFinding(t *testing.T) {
|
||||
st := &memFindings{vals: map[string][]byte{}}
|
||||
f := &findings{module: builds.BuilderModule, w: st, logf: t.Logf, now: func() time.Time { return time.Unix(0, 0) }}
|
||||
@@ -334,19 +313,11 @@ func aFailedTrunkBuildIsAFinding(t *testing.T) {
|
||||
if _, ok := st.vals[key]; ok {
|
||||
t.Error("a later done trunk build leaves build-failed")
|
||||
}
|
||||
// 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.
|
||||
vs := versions.Versions{Store: memVersions{}}
|
||||
for _, v := range []string{"0.1.3", "0.1.4"} {
|
||||
raw, err := versions.Encode(versions.Entry{Name: "m/program", Kind: versions.KindBundle, Series: "0.1", Version: v, Seat: "oci-artifact-registry", State: versions.Numbered})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
vs.Store.(memVersions)[versions.Key("m/program", v)] = raw
|
||||
}
|
||||
pubs := &publishes{bounds: func() jetstream.KeyValue { return nil }, versions: vs, findings: f, bound: versions.PublishBound, logf: t.Logf}
|
||||
h := &seatHearer{n: &versions.Numberer{Versions: vs}, b: &build.Builder{}, logf: t.Logf, pub: pubs}
|
||||
// Design 51 *Health and conditions* (review round 1): a holder's refused is publish-refused with its reason, a seat's outcome
|
||||
// that does not read seat-outcome-unread; a later published of the name clears the first, the seat's next outcome that
|
||||
// reads the second. The numbered version's bound goes with the numbering from before G (design 47 H §756).
|
||||
pubs := &publishes{findings: f}
|
||||
h := &seatHearer{b: &build.Builder{}, logf: t.Logf, pub: pubs}
|
||||
refusedKey := meshconditionsclient.Key(meshconditionsclient.ScopeModule, "m/program", versions.PublishRefused)
|
||||
refused := &wakeMsg{subject: "mesh.seat.oci-artifact-registry.event.refused", data: []byte(`{"name":"m/program","version":"0.1.3","digest":"sha256:bb","reason":"bytes differ"}`)}
|
||||
if !h.heard(context.Background(), refused) || !refused.acked {
|
||||
@@ -355,18 +326,10 @@ func aFailedTrunkBuildIsAFinding(t *testing.T) {
|
||||
if got, err := decodeFinding(st.vals[refusedKey]); err != nil || !strings.Contains(got.Summary, "refused to publish m/program@0.1.3") || !strings.Contains(got.Summary, "bytes differ") {
|
||||
t.Fatalf("a holder's refused: the finding = %+v, %v", got, err)
|
||||
}
|
||||
pubs.ended(context.Background(), purged{key: versions.PublishBoundKey("m/program", "0.1.4")})
|
||||
// A publish-unanswered a builder of before the change raised is cleared by the name's next published.
|
||||
unansweredKey := meshconditionsclient.Key(meshconditionsclient.ScopeModule, "m/program", versions.PublishUnanswered)
|
||||
if got, err := decodeFinding(st.vals[unansweredKey]); err != nil || !strings.Contains(got.Summary, "neither published nor refused of m/program@0.1.4") {
|
||||
t.Fatalf("a bound ended unanswered: the finding = %+v, %v", got, err)
|
||||
}
|
||||
// Review round 2: a bound that cannot be written is publish-unanswered at once; a watch of bounds that cannot start
|
||||
// is family-not-heard naming the state.
|
||||
delete(st.vals, unansweredKey)
|
||||
pubs.arm(context.Background(), versions.Entry{Name: "m/program", Version: "0.1.4", Seat: "oci-artifact-registry"})
|
||||
if got, err := decodeFinding(st.vals[unansweredKey]); err != nil || !strings.Contains(got.Summary, "its bound could not be written") {
|
||||
t.Fatalf("a bound not written: the finding = %+v, %v", got, err)
|
||||
}
|
||||
st.vals[unansweredKey] = st.vals[refusedKey]
|
||||
// A watch of bounds that cannot start is family-not-heard naming the state (review round 2).
|
||||
watchBounds(context.Background(), refusedWatch{err: errors.New("permissions violation")}, func(jetstream.KeyValueEntry) {}, f.notHeard(context.Background()), nil, t.Logf)
|
||||
if got, err := decodeFinding(st.vals[heard.Key(builds.BuilderModule, versions.BoundsState)]); err != nil || !strings.Contains(got.Summary, "permissions violation") {
|
||||
t.Fatalf("bounds not watched: the finding = %+v, %v", got, err)
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
// catalog's version-released and versions-filled it hears.
|
||||
|
||||
// awaitedReserved is the state reserved as versions.ReserveStore: bound once the bus holds it.
|
||||
type awaitedReserved struct{ awaitedVersions }
|
||||
type awaitedReserved struct{ awaitedState }
|
||||
|
||||
func (s awaitedReserved) Delete(ctx context.Context, key string) error {
|
||||
kv, err := s.kv()
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
@@ -43,9 +42,9 @@ 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).
|
||||
// seatHearer takes the registry seats' outcomes in: the publishes' findings and the reservations hear them (design 47 G §369,
|
||||
// A-415); the numbering from before G, which marked its state versions with them, is gone (design 47 H §756).
|
||||
type seatHearer struct {
|
||||
n *versions.Numberer
|
||||
b *build.Builder
|
||||
logf func(string, ...any)
|
||||
// pub raises and clears the findings of a publish that ended badly; nil raises none.
|
||||
@@ -77,26 +76,6 @@ func (h *seatHearer) heard(ctx context.Context, m jetstream.Msg) bool {
|
||||
if h.pub != nil {
|
||||
h.pub.read(ctx, se.seat)
|
||||
}
|
||||
id := ""
|
||||
if m.Headers() != nil {
|
||||
id = m.Headers().Get("x-event-id")
|
||||
}
|
||||
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
|
||||
// unnumbered there, so it is taken, not left for the bus.
|
||||
h.logf("%v in the state versions; the reservations take it (design 47 G §369, A-415)", err)
|
||||
err = nil
|
||||
}
|
||||
if err != nil {
|
||||
h.logf("%v; heard again (delivery %s)", err, deliveryOf(m))
|
||||
if nakErr := m.Nak(); nakErr != nil {
|
||||
h.logf("leaving %s for the bus to give again: %v", m.Subject(), nakErr)
|
||||
}
|
||||
givenUp(m, fmt.Sprintf("%s's %s of %s@%s", se.seat, se.event, o.Name, o.Version), err, h.logf)
|
||||
return true
|
||||
}
|
||||
if h.pub != nil {
|
||||
h.pub.heard(ctx, se.seat, se.event, o)
|
||||
}
|
||||
|
||||
@@ -16,27 +16,21 @@ import (
|
||||
"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.
|
||||
type awaitedVersions struct {
|
||||
b *process.AwaitedBucket
|
||||
// bucket names the state in the error of one not on the bus yet; empty is the versions'.
|
||||
// awaitedState is one of the builder's states as versions.Store: bound once the bus holds it (the grants part makes it,
|
||||
// issue 1790); until then every use is an error naming the state's bucket.
|
||||
type awaitedState struct {
|
||||
b *process.AwaitedBucket
|
||||
bucket string
|
||||
}
|
||||
|
||||
var errVersionsMissing = errors.New("the state " + versions.State + " is not on the bus yet")
|
||||
|
||||
func (s awaitedVersions) kv() (jetstream.KeyValue, error) {
|
||||
func (s awaitedState) kv() (jetstream.KeyValue, error) {
|
||||
if kv := s.b.KV(); kv != nil {
|
||||
return kv, nil
|
||||
}
|
||||
if s.bucket != "" {
|
||||
return nil, errors.New("the state " + s.bucket + " is not on the bus yet")
|
||||
}
|
||||
return nil, errVersionsMissing
|
||||
return nil, errors.New("the state " + s.bucket + " is not on the bus yet")
|
||||
}
|
||||
|
||||
func (s awaitedVersions) Get(ctx context.Context, key string) ([]byte, uint64, bool, error) {
|
||||
func (s awaitedState) Get(ctx context.Context, key string) ([]byte, uint64, bool, error) {
|
||||
kv, err := s.kv()
|
||||
if err != nil {
|
||||
return nil, 0, false, err
|
||||
@@ -58,7 +52,7 @@ func versionsConflict(err error) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (s awaitedVersions) Create(ctx context.Context, key string, value []byte) (uint64, error) {
|
||||
func (s awaitedState) Create(ctx context.Context, key string, value []byte) (uint64, error) {
|
||||
kv, err := s.kv()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -67,7 +61,7 @@ func (s awaitedVersions) Create(ctx context.Context, key string, value []byte) (
|
||||
return rev, versionsConflict(err)
|
||||
}
|
||||
|
||||
func (s awaitedVersions) Update(ctx context.Context, key string, value []byte, revision uint64) (uint64, error) {
|
||||
func (s awaitedState) Update(ctx context.Context, key string, value []byte, revision uint64) (uint64, error) {
|
||||
kv, err := s.kv()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -76,7 +70,7 @@ func (s awaitedVersions) Update(ctx context.Context, key string, value []byte, r
|
||||
return rev, versionsConflict(err)
|
||||
}
|
||||
|
||||
func (s awaitedVersions) KeysOf(ctx context.Context, filter string) ([]string, error) {
|
||||
func (s awaitedState) KeysOf(ctx context.Context, filter string) ([]string, error) {
|
||||
kv, err := s.kv()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
// Acts are the builder's hand acts on its versions, answered by its program (the tools bundle writes them to reasks).
|
||||
type Acts struct {
|
||||
Numberer *Numberer
|
||||
// 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.
|
||||
|
||||
@@ -51,9 +51,3 @@ func TagPrefix(path string) string {
|
||||
}
|
||||
return path + "/v"
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
package versions
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// The registry seats' events the builder hears on its durable consumer of each `<seat>.events` (design 51 *How a
|
||||
// publish ends*, DLV-B4).
|
||||
const (
|
||||
@@ -26,51 +21,3 @@ type Outcome struct {
|
||||
// Tags are, on kept, the other tags still naming its digest.
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (n *Numberer) Heard(ctx context.Context, seat, event, id string, o Outcome) error {
|
||||
if o.Version == "" {
|
||||
return nil
|
||||
}
|
||||
var change func(*Entry)
|
||||
switch event {
|
||||
case HeardPublished:
|
||||
// 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 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, ""
|
||||
if e.Digest == "" {
|
||||
e.Digest = o.Digest
|
||||
}
|
||||
}
|
||||
case HeardRefused:
|
||||
change = func(e *Entry) {
|
||||
if e.State != Published {
|
||||
e.State, e.Reason, e.RefusedDigest = Refused, o.Reason, o.Digest
|
||||
}
|
||||
}
|
||||
case HeardRemoved:
|
||||
change = func(e *Entry) { e.State, e.Reason, e.RemovedBy = Removed, o.Reason, id }
|
||||
case HeardKept:
|
||||
change = func(e *Entry) {
|
||||
if e.State != Removed {
|
||||
e.State, e.Reason, e.KeptWith = Kept, o.Reason, append([]string(nil), o.Tags...)
|
||||
if e.Reason == "" {
|
||||
e.Reason = "shared-digest"
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
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 fmt.Errorf("%s's %s of %s@%s: %w", seat, event, o.Name, o.Version, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -9,23 +9,14 @@ import (
|
||||
)
|
||||
|
||||
// **A publish that ends badly is loud** (design 51 *Health and conditions*; review round 1): the builder raises the
|
||||
// finding publish-refused when a holder says refused, and publish-unanswered when a version it built and numbered is
|
||||
// neither published nor refused within PublishBound. Each is about the name, so a later published of any version of it
|
||||
// clears both. A seat's outcome that does not read is the finding seat-outcome-unread about the seat, cleared by its
|
||||
// next outcome that reads.
|
||||
//
|
||||
// The bound is a key of the builder's state bounds per version (PublishBoundKey), written with its own time to live
|
||||
// when the build is done and the version is still numbered, deleted at the holder's word; the bus's marker of its end,
|
||||
// heard on the watch, is what raises publish-unanswered while the version is still numbered. No timer.
|
||||
// finding publish-refused when a holder says refused, about the name, so a later published of any version of it clears
|
||||
// it. A seat's outcome that does not read is the finding seat-outcome-unread about the seat, cleared by its next outcome
|
||||
// that reads. A reserved version left unpublished past its bound is the reservation's finding (version-unreleased,
|
||||
// design 47 G §369); the numbered version's bound goes with the numbering from before G (design 47 H §756).
|
||||
const (
|
||||
// BoundsState is the builder's state of its expiring keys, each with its own time to live: a publish's bound
|
||||
// (PublishBoundKey), a node's seven days holding the old form's window (OldFormBoundKey) and a build key left
|
||||
// BoundsState is the builder's state of its expiring keys, each with its own time to live: a node's seven days holding the old form's window (OldFormBoundKey) and a build key left
|
||||
// building unput (UnputBoundKey). Its end, the bus's marker heard on the watch, is what acts.
|
||||
BoundsState = "bounds"
|
||||
// PublishBound is the build module's own wait for the holder's word (design 51 *How a publish ends*: at most
|
||||
// 10 minutes), so a version unanswered past it is one the holder never answered.
|
||||
PublishBound = 10 * time.Minute
|
||||
|
||||
BoundsState = "bounds"
|
||||
PublishRefused = "publish-refused"
|
||||
PublishUnanswered = "publish-unanswered"
|
||||
SeatOutcomeUnread = "seat-outcome-unread"
|
||||
@@ -33,7 +24,6 @@ const (
|
||||
|
||||
// The prefixes of the keys of BoundsState.
|
||||
const (
|
||||
publishBoundPrefix = "publish."
|
||||
oldFormBoundPrefix = "old-form."
|
||||
unputBoundPrefix = "unput."
|
||||
stepsBoundPrefix = "steps."
|
||||
@@ -62,16 +52,9 @@ func StepsBoundOf(key string) (module, askID string, ok bool) {
|
||||
// UnputBoundOf is the build key an unput bound names, and whether key is one.
|
||||
func UnputBoundOf(key string) (string, bool) { return strings.CutPrefix(key, unputBoundPrefix) }
|
||||
|
||||
// PublishBoundKey is the bound of name's version: `publish.<versions key>`.
|
||||
func PublishBoundKey(name, version string) string { return publishBoundPrefix + Key(name, version) }
|
||||
|
||||
// OldFormBoundKey is the bound of node's seven days holding the old form's window: `old-form.<node>`.
|
||||
func OldFormBoundKey(node string) string { return oldFormBoundPrefix + EscapeToken(node) }
|
||||
|
||||
// PublishBoundOf is the versions key a publish's bound names, and whether key is one; a key that is no publish's
|
||||
// bound is an old form's (IsOldFormBound) or nothing the builder wrote.
|
||||
func PublishBoundOf(key string) (string, bool) { return strings.CutPrefix(key, publishBoundPrefix) }
|
||||
|
||||
// IsOldFormBound says key is a node's bound of the old form's window: its end steps the window, which raises the
|
||||
// finding for every node past FindingAfter.
|
||||
func IsOldFormBound(key string) bool { return strings.HasPrefix(key, oldFormBoundPrefix) }
|
||||
@@ -81,7 +64,7 @@ const BoundsTool = "builder_bounds"
|
||||
|
||||
// BoundsDescription is builder_bounds' description.
|
||||
const BoundsDescription = "The builder's expiring keys, its state " + BoundsState + " (design 51 *Health and conditions*): each key with what it " +
|
||||
"bounds (a version's publish, whose end unanswered is the finding " + PublishUnanswered + "; or a node's seven days holding the old " +
|
||||
"bounds (a node's seven days holding the old " +
|
||||
"form's window, whose end is the finding " + OldFormHeld + "; or a build key left building because its end could not be written, " +
|
||||
"whose end is the finding call-unanswered; or a dependent's wait for a package member of a group's run, whose end fails its " +
|
||||
"step), when it ends, and how long is left. The bus ends each key by its own time to live."
|
||||
|
||||
@@ -3,9 +3,7 @@ package versions
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// AllFilter is the key filter of every version of every name: two tokens.
|
||||
@@ -37,123 +35,3 @@ type Store interface {
|
||||
// KeysOf are the keys under a filter (NameFilter, or AllFilter for every key).
|
||||
KeysOf(ctx context.Context, filter string) ([]string, error)
|
||||
}
|
||||
|
||||
// Versions is the builder's state.
|
||||
type Versions struct {
|
||||
Store Store
|
||||
Now func() time.Time
|
||||
}
|
||||
|
||||
// Of is every entry of name.
|
||||
func (v Versions) Of(ctx context.Context, name string) ([]Entry, error) {
|
||||
keys, err := v.Store.KeysOf(ctx, NameFilter(name))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the versions of %s cannot be listed: %w", name, err)
|
||||
}
|
||||
var out []Entry
|
||||
for _, k := range keys {
|
||||
raw, _, found, err := v.Store.Get(ctx, k)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: %w", k, err)
|
||||
}
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
e, err := Decode(raw)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s holds what is not a version: %w", k, err)
|
||||
}
|
||||
out = append(out, e)
|
||||
}
|
||||
return InOrder(out), nil
|
||||
}
|
||||
|
||||
// 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")
|
||||
|
||||
// Mark moves one version to a new state by compare-and-set, as the holders' events say (published, refused, removed):
|
||||
// change edits the entry read; a version the state does not hold is an error naming it.
|
||||
func (v Versions) Mark(ctx context.Context, name, version string, change func(*Entry)) (Entry, error) {
|
||||
key := Key(name, version)
|
||||
for attempt := 0; attempt < 16; attempt++ {
|
||||
raw, rev, found, err := v.Store.Get(ctx, key)
|
||||
if err != nil {
|
||||
return Entry{}, fmt.Errorf("%s: %w", key, err)
|
||||
}
|
||||
if !found {
|
||||
return Entry{}, fmt.Errorf("%s@%s is %w", name, version, ErrNotNumbered)
|
||||
}
|
||||
e, err := Decode(raw)
|
||||
if err != nil {
|
||||
return Entry{}, fmt.Errorf("%s holds what is not a version: %w", key, err)
|
||||
}
|
||||
change(&e)
|
||||
e.At = v.now()
|
||||
out, err := Encode(e)
|
||||
if err != nil {
|
||||
return Entry{}, err
|
||||
}
|
||||
if _, err := v.Store.Update(ctx, key, out, rev); errors.Is(err, ErrConflict) {
|
||||
continue
|
||||
} else if err != nil {
|
||||
return Entry{}, fmt.Errorf("%s: %w", key, err)
|
||||
}
|
||||
return e, nil
|
||||
}
|
||||
return Entry{}, fmt.Errorf("%s@%s kept changing under 16 marks", name, version)
|
||||
}
|
||||
|
||||
// Recorded is the holder's question through builder_versions (ADR 0605 §4): whether name, version and digest are a
|
||||
// version the builder numbered. It answers the entry when they are, and why not otherwise.
|
||||
func (v Versions) Recorded(ctx context.Context, name, version, digest string) (Entry, bool, string, error) {
|
||||
raw, _, found, err := v.Store.Get(ctx, Key(name, version))
|
||||
if err != nil {
|
||||
return Entry{}, false, "", err
|
||||
}
|
||||
if !found {
|
||||
return Entry{}, false, fmt.Sprintf("%s@%s is not a version the builder numbered", name, version), nil
|
||||
}
|
||||
e, err := Decode(raw)
|
||||
if err != nil {
|
||||
return Entry{}, false, "", err
|
||||
}
|
||||
switch {
|
||||
case e.State == Removed:
|
||||
return e, false, fmt.Sprintf("%s@%s was removed (%s)", name, version, e.Reason), nil
|
||||
case e.Digest != "" && digest != "" && e.Digest != digest:
|
||||
return e, false, fmt.Sprintf("%s@%s is recorded with digest %s, not %s", name, version, e.Digest, digest), nil
|
||||
}
|
||||
return e, true, "", nil
|
||||
}
|
||||
|
||||
func (v Versions) now() time.Time {
|
||||
if v.Now != nil {
|
||||
return v.Now().UTC()
|
||||
}
|
||||
return time.Now().UTC()
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the versions cannot be listed: %w", err)
|
||||
}
|
||||
var out []Entry
|
||||
for _, k := range keys {
|
||||
raw, _, found, err := v.Store.Get(ctx, k)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: %w", k, err)
|
||||
}
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
e, err := Decode(raw)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s holds what is not a version: %w", k, err)
|
||||
}
|
||||
out = append(out, e)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
@@ -75,10 +75,77 @@ func (r Reader) values(state string) (map[string]json.RawMessage, *StateCapped,
|
||||
return out, nil, nil
|
||||
}
|
||||
|
||||
// readStore is a Store over a Reader that refuses every write: the tools bundle only reads versions.
|
||||
// VersionsAnswer is what builder_versions answers, from the reservations alone (design 47 H §756, G §372, §381): what the
|
||||
// seat mesh-builds' verb reserved answers for the name, and, asked for a version and a digest, whether the reservation holds
|
||||
// that version with that digest.
|
||||
type VersionsAnswer struct {
|
||||
Name string `json:"name"`
|
||||
// Asked, Recorded and Why answer a holder's question for one version and digest (ADR 0605 §4).
|
||||
Asked string `json:"asked,omitempty"`
|
||||
Recorded *bool `json:"recorded,omitempty"`
|
||||
Why string `json:"why,omitempty"`
|
||||
// Reserved is what the seat mesh-builds' verb reserved answers for the name (and version): the reserved or released version
|
||||
// with each artifact's digest, or its error (design 47 G §572, §582).
|
||||
Reserved *meshbuilds.ReservedAnswer `json:"reserved,omitempty"`
|
||||
}
|
||||
|
||||
// AnswerVersions is builder_versions: what the reservation answers for a name, read through reserve (the seat mesh-builds'
|
||||
// verb reserved); with a version and a digest, recorded says whether that version is the one reserved or released and an
|
||||
// artifact of it has that digest or none recorded yet, the question a registry seat's holder asks before it stores
|
||||
// (ADR 0605 §4, design 47 G §381, A-490j).
|
||||
func AnswerVersions(name, version, digest string, reserve func(name, version string) (meshbuilds.ReservedAnswer, error)) (VersionsAnswer, error) {
|
||||
name, version, digest = strings.TrimSpace(name), strings.TrimSpace(version), strings.TrimSpace(digest)
|
||||
if name == "" {
|
||||
return VersionsAnswer{}, errors.New("name is required: the package, image, bundle or archive name")
|
||||
}
|
||||
if reserve == nil {
|
||||
return VersionsAnswer{}, errors.New("the seat mesh-builds' reserved cannot be asked")
|
||||
}
|
||||
ra, err := reserve(name, version)
|
||||
if err != nil {
|
||||
return VersionsAnswer{}, fmt.Errorf("the seat mesh-builds' reserved did not answer for %s: %w", name, err)
|
||||
}
|
||||
out := VersionsAnswer{Name: name, Reserved: &ra}
|
||||
if version == "" {
|
||||
return out, nil
|
||||
}
|
||||
ok, why := recordedIn(ra, name, version, digest)
|
||||
out.Asked, out.Recorded, out.Why = version, &ok, why
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// recordedIn is whether the reservation answer ra holds name@version with digest, and why not.
|
||||
func recordedIn(ra meshbuilds.ReservedAnswer, name, version, digest string) (bool, string) {
|
||||
switch {
|
||||
case ra.Error != "":
|
||||
return false, ra.Error
|
||||
case ra.Version != version:
|
||||
return false, fmt.Sprintf("%s has no reservation of version %s of %s (it holds %s)", ra.Module, version, name, ra.Version)
|
||||
}
|
||||
var held []string
|
||||
for _, a := range ra.Artifacts {
|
||||
if a.Digest == digest || a.Digest == "" {
|
||||
return true, ""
|
||||
}
|
||||
held = append(held, a.Digest)
|
||||
}
|
||||
if len(held) == 0 {
|
||||
return false, fmt.Sprintf("%s holds %s@%s with no artifact, so no digest takes %s", ra.Module, name, version, digest)
|
||||
}
|
||||
return false, fmt.Sprintf("%s holds %s@%s for digest %s, not %s", ra.Module, name, version, strings.Join(held, ", "), digest)
|
||||
}
|
||||
|
||||
// VersionsDescription is builder_versions' description.
|
||||
const VersionsDescription = "A name's reservation, from the reservations alone (the numbering from before G is gone, design 47 H §756): " +
|
||||
"what the seat mesh-builds' verb reserved answers for the package, image, bundle or archive name, the reserved or released version " +
|
||||
"with each artifact's digest. With version, and digest, it also answers recorded: whether that version is the one reserved or " +
|
||||
"released and an artifact of it has that digest (or none recorded yet), and why not: the question a registry seat's holder asks " +
|
||||
"before it stores a publish (ADR 0605 §4). Read-only."
|
||||
|
||||
// readStore is a Store over a Reader that refuses every write: the tools bundle only reads the builder's states.
|
||||
type readStore struct{ r Reader }
|
||||
|
||||
var errReadOnly = errors.New("the versions are written by the builder alone")
|
||||
var errReadOnly = errors.New("the builder's states are written by the builder alone")
|
||||
|
||||
func (s readStore) Get(_ context.Context, key string) ([]byte, uint64, bool, error) {
|
||||
v, ok, err := s.r.Get(key)
|
||||
@@ -101,49 +168,3 @@ func (s readStore) KeysOf(_ context.Context, filter string) ([]string, error) {
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// VersionsAnswer is what builder_versions answers.
|
||||
type VersionsAnswer struct {
|
||||
Name string `json:"name"`
|
||||
Versions []Entry `json:"versions"`
|
||||
// Asked, Recorded and Why answer a holder's question for one version and digest (ADR 0605 §4).
|
||||
Asked string `json:"asked,omitempty"`
|
||||
Recorded *bool `json:"recorded,omitempty"`
|
||||
Why string `json:"why,omitempty"`
|
||||
// Reserved is what the seat mesh-builds' verb reserved answers for the name (and version): the reserved or released version
|
||||
// with each artifact's digest, or its error (design 47 G §572, §582).
|
||||
Reserved *meshbuilds.ReservedAnswer `json:"reserved,omitempty"`
|
||||
}
|
||||
|
||||
// AnswerVersions is builder_versions: a name's versions in order, in one call; with a version (and a digest), whether
|
||||
// the builder numbered it with that digest, which the holder asks before it stores (ADR 0605 §4).
|
||||
func AnswerVersions(ctx context.Context, r Reader, name, version, digest string) (VersionsAnswer, error) {
|
||||
name = strings.TrimSpace(name)
|
||||
if name == "" {
|
||||
return VersionsAnswer{}, errors.New("name is required: the package, image, bundle or archive name")
|
||||
}
|
||||
v := Versions{Store: readStore{r}}
|
||||
all, err := v.Of(ctx, name)
|
||||
if err != nil {
|
||||
return VersionsAnswer{}, err
|
||||
}
|
||||
out := VersionsAnswer{Name: name, Versions: all}
|
||||
if out.Versions == nil {
|
||||
out.Versions = []Entry{}
|
||||
}
|
||||
if version = strings.TrimSpace(version); version != "" {
|
||||
_, ok, why, err := v.Recorded(ctx, name, version, strings.TrimSpace(digest))
|
||||
if err != nil {
|
||||
return VersionsAnswer{}, fmt.Errorf("%s@%s: %w", name, version, err)
|
||||
}
|
||||
out.Asked, out.Recorded, out.Why = version, &ok, why
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// VersionsDescription is builder_versions' description.
|
||||
const VersionsDescription = "A name's versions as the builder numbered them (its state versions, design 51): every trunk and tagged " +
|
||||
"version of a package, image, bundle or archive in order, each with its kind, series, fingerprint, commit, source revision, digest, " +
|
||||
"seat, state (numbered, published, refused with its reason, removed with its time, reason and the event that removed it, or kept: its seat kept it whole on remove, its digest shared, with the reason and the other tags naming it, kept_with) and when. " +
|
||||
"With version, and digest, it also answers recorded: whether the builder numbered that version with that digest, and why not: the " +
|
||||
"question a registry seat's holder asks before it stores a publish (ADR 0605 §4). Read-only."
|
||||
|
||||
@@ -1,46 +1,19 @@
|
||||
// Package versions is the builder's state `versions` (novox/hq design 51 *The versions*, ADR 0606): one key per name,
|
||||
// tag and version, written only by the builder under compare-and-set, read by others only through the builder's tool
|
||||
// builder_versions or its events (ADR 0596 §2). It holds what each version is (its fingerprint, commit, source revision
|
||||
// and digest) and where it stands: numbered, published, refused with its reason, or removed with its time, reason and the
|
||||
// event that removed it.
|
||||
//
|
||||
// The state is declared in the builder's old `state` section (ADR 0619: the builder is one of the foundation's nine
|
||||
// parts), history one; its cap is 64 MiB, the most the template state allows (ADR 0595 §3), and past 80 % of it the
|
||||
// builder writes a finding, cleared below it (Fill).
|
||||
// Package versions holds the builder's versions as the reservation numbers them (novox/hq design 47 G §369): the state
|
||||
// reserved, its index and releases, the publish queue, the old form's window and the builder's bounds. The state versions
|
||||
// numbered before G goes with its numbering (design 47 H §756); builder_versions answers from the reservations alone.
|
||||
package versions
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// State is the builder state's name; its bucket is `<module>_versions` of the credential's module.
|
||||
const (
|
||||
State = "versions"
|
||||
// Cap is the bucket's cap in bytes (64 MiB); FullPercent the share of it past which the builder writes its finding.
|
||||
Cap = 64 << 20
|
||||
FullPercent = 80
|
||||
// DefaultSeries is the series of a name whose manifest declares none (design 32).
|
||||
DefaultSeries = "0.1"
|
||||
)
|
||||
|
||||
// The states a version is in.
|
||||
const (
|
||||
Numbered = "numbered"
|
||||
Published = "published"
|
||||
Refused = "refused"
|
||||
Removed = "removed"
|
||||
// Kept is a tagged version its seat kept whole on remove: another tag names its digest, so the store cannot remove the
|
||||
// tag alone (review round 2; the registry seats' `kept`). Its Reason is the seat's (shared-digest), KeptWith the
|
||||
// other tags; it is asked no more.
|
||||
Kept = "kept"
|
||||
)
|
||||
|
||||
// The kinds the builder numbers: a package per source revision, the rest per fingerprint (design 51).
|
||||
const (
|
||||
KindPackage = "package"
|
||||
@@ -49,82 +22,8 @@ const (
|
||||
KindArchive = "archive"
|
||||
)
|
||||
|
||||
// Entry is one key of the state: a version of a name, tagged or not.
|
||||
type Entry struct {
|
||||
Name string `json:"name"`
|
||||
Kind string `json:"kind"`
|
||||
Series string `json:"series"`
|
||||
Version string `json:"version"`
|
||||
// Tag is the cleaned tag of a tagged version (`feat-x`); empty for a trunk version.
|
||||
Tag string `json:"tag,omitempty"`
|
||||
Module string `json:"module"`
|
||||
Fingerprint string `json:"fingerprint"`
|
||||
Commit string `json:"commit,omitempty"`
|
||||
// Revision is the source revision a package's version is numbered for (one version per revision, design 51).
|
||||
Revision string `json:"revision,omitempty"`
|
||||
// Digest is the digest the build recorded (an image's manifest, a blob's, Go's h1: hash).
|
||||
Digest string `json:"digest,omitempty"`
|
||||
// Seat is the registry seat it is published to.
|
||||
Seat string `json:"seat,omitempty"`
|
||||
State string `json:"state"`
|
||||
At time.Time `json:"at"`
|
||||
// Reason is why it was refused or removed: the holder's reason, a branch's end, retention, the sweep.
|
||||
Reason string `json:"reason,omitempty"`
|
||||
// Repository is a tagged version's repository: its branch's end removes it (Untagged).
|
||||
Repository string `json:"repository,omitempty"`
|
||||
// KeptWith are the other tags naming its digest, when its seat kept it (Kept).
|
||||
KeptWith []string `json:"kept_with,omitempty"`
|
||||
// RemovedBy is the id of the event that removed it.
|
||||
RemovedBy string `json:"removed_by,omitempty"`
|
||||
// RefusedDigest is the digest the holder refused: one other than Digest means the seat was offered other bytes under
|
||||
// this number, which builder_publish_again refuses to publish again (design 51 *Tools of the builder*).
|
||||
RefusedDigest string `json:"refused_digest,omitempty"`
|
||||
// Merge is the forge bridge's sequence of the merge that numbered it, for merge order.
|
||||
Merge uint64 `json:"merge,omitempty"`
|
||||
}
|
||||
|
||||
// Valid says what is wrong with an entry, or nil.
|
||||
func (e Entry) Valid() error {
|
||||
switch {
|
||||
case strings.TrimSpace(e.Name) == "":
|
||||
return errors.New("a version names no name")
|
||||
case e.Version == "":
|
||||
return fmt.Errorf("%s: a version with no version", e.Name)
|
||||
}
|
||||
switch e.State {
|
||||
case Numbered, Published, Refused, Removed, Kept:
|
||||
default:
|
||||
return fmt.Errorf("%s@%s: unknown state %q", e.Name, e.Version, e.State)
|
||||
}
|
||||
switch e.Kind {
|
||||
case KindPackage, KindImage, KindBundle, KindArchive:
|
||||
default:
|
||||
return fmt.Errorf("%s@%s: unknown kind %q", e.Name, e.Version, e.Kind)
|
||||
}
|
||||
if _, _, err := SplitSeries(e.Series); err != nil {
|
||||
return fmt.Errorf("%s@%s: %w", e.Name, e.Version, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Encode and Decode are the value's bytes.
|
||||
func Encode(e Entry) ([]byte, error) {
|
||||
if err := e.Valid(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return json.Marshal(e)
|
||||
}
|
||||
|
||||
func Decode(raw []byte) (Entry, error) {
|
||||
var e Entry
|
||||
if err := json.Unmarshal(raw, &e); err != nil {
|
||||
return Entry{}, err
|
||||
}
|
||||
return e, e.Valid()
|
||||
}
|
||||
|
||||
// Key is the state's key of a name's version: two tokens, the name and the version each escaped (EscapeToken), so a
|
||||
// name's versions are the keys under NameFilter and no name's keys fall under another's.
|
||||
// Key is a key of two tokens, a name and a version (or series) each escaped (EscapeToken), so a name's keys are the keys
|
||||
// under NameFilter and no name's keys fall under another's.
|
||||
func Key(name, version string) string { return EscapeToken(name) + "." + EscapeToken(version) }
|
||||
|
||||
// NameFilter is the key filter of every version of name.
|
||||
@@ -181,55 +80,3 @@ func Patch(series, version string) (int, bool) {
|
||||
}
|
||||
return n, true
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return 0, false
|
||||
}
|
||||
share = float64(bytes) / float64(capacity)
|
||||
return share, bytes*100 >= capacity*FullPercent
|
||||
}
|
||||
|
||||
// InOrder sorts a name's entries by version, trunk versions by count and tagged ones after the trunk version they stand
|
||||
// below: the order builder_versions answers.
|
||||
func InOrder(entries []Entry) []Entry {
|
||||
out := append([]Entry(nil), entries...)
|
||||
sort.SliceStable(out, func(i, j int) bool {
|
||||
ki, kj := orderKey(out[i]), orderKey(out[j])
|
||||
if ki.n != kj.n {
|
||||
return ki.n < kj.n
|
||||
}
|
||||
if ki.tagged != kj.tagged {
|
||||
return ki.tagged // a tagged version stands below the trunk version of its count
|
||||
}
|
||||
return out[i].Version < out[j].Version
|
||||
})
|
||||
return out
|
||||
}
|
||||
|
||||
type order struct {
|
||||
n int
|
||||
tagged bool
|
||||
}
|
||||
|
||||
func orderKey(e Entry) order {
|
||||
v := e.Version
|
||||
tagged := false
|
||||
if i := strings.IndexByte(v, '-'); i >= 0 {
|
||||
v, tagged = v[:i], true
|
||||
}
|
||||
n, ok := Patch(e.Series, v)
|
||||
if !ok {
|
||||
n = -1
|
||||
}
|
||||
return order{n: n, tagged: tagged}
|
||||
}
|
||||
|
||||
func latestFirst(entries []Entry) []Entry {
|
||||
out := InOrder(entries)
|
||||
for i, j := 0, len(out)-1; i < j; i, j = i+1, j-1 {
|
||||
out[i], out[j] = out[j], out[i]
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds/forms"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
)
|
||||
|
||||
// mem is a Store in memory; before runs once before the next Create, to stage a race.
|
||||
@@ -92,18 +93,6 @@ func (p packagesMem) Get(_ context.Context, key string) ([]byte, bool, error) {
|
||||
|
||||
func (p packagesMem) failing() packagesMem { return nil }
|
||||
|
||||
// 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.
|
||||
func TestTheBuildersVersions(t *testing.T) {
|
||||
@@ -124,35 +113,39 @@ func TestTheBuildersVersions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
})
|
||||
t.Run("recorded", func(t *testing.T) {
|
||||
st := newMem()
|
||||
v := Versions{Store: st}
|
||||
ctx := context.Background()
|
||||
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)})
|
||||
t.Run("builder_versions answers from the reservations alone", func(t *testing.T) { // B1/AC2 (DMC-5: design 47 H §756, G §372)
|
||||
asked := ""
|
||||
reserve := func(name, version string) (meshbuilds.ReservedAnswer, error) {
|
||||
asked = name + "@" + version
|
||||
return meshbuilds.ReservedAnswer{Module: "m", Version: "0.1.4", Artifacts: []meshbuilds.ReservedAnswerArtifactsItem{
|
||||
{Artifact: "m:program", Digest: "sha256:aa"}}}, nil
|
||||
}
|
||||
for _, c := range []struct {
|
||||
version, digest string
|
||||
ok bool
|
||||
}{{"0.1.0", "sha256:aa", true}, {"0.1.0", "sha256:bb", false}, {"0.1.7", "sha256:aa", false}} {
|
||||
if _, ok, why, err := v.Recorded(ctx, "n", c.version, c.digest); err != nil || ok != c.ok || (!ok && why == "") {
|
||||
t.Errorf("Recorded(%s, %s) = %v, %q, %v; want %v", c.version, c.digest, ok, why, err, c.ok)
|
||||
}{{"0.1.4", "sha256:aa", true}, {"0.1.4", "sha256:bb", false}, {"0.1.7", "sha256:aa", false}} {
|
||||
a, err := AnswerVersions("m/program", c.version, c.digest, reserve)
|
||||
if err != nil || a.Recorded == nil || *a.Recorded != c.ok || (!c.ok && a.Why == "") || a.Reserved == nil || asked != "m/program@"+c.version {
|
||||
t.Errorf("builder_versions(%s, %s) = %+v, %v, asked %s; want recorded %v from the reservation", c.version, c.digest, a, err, asked, c.ok)
|
||||
}
|
||||
}
|
||||
// builder_versions answers the same through the tools bundle's read-only view.
|
||||
r := Reader{Keys: func() ([]string, error) {
|
||||
var all []string
|
||||
for k := range st.vals {
|
||||
all = append(all, k)
|
||||
}
|
||||
return all, nil
|
||||
}, Get: func(k string) (json.RawMessage, bool, error) {
|
||||
v, _, ok, err := st.Get(ctx, k)
|
||||
return v, ok, err
|
||||
}}
|
||||
a, err := AnswerVersions(ctx, r, "n", "0.1.0", "sha256:bb")
|
||||
if err != nil || len(a.Versions) != 1 || a.Recorded == nil || *a.Recorded || a.Why == "" {
|
||||
t.Errorf("builder_versions = %+v, %v; want one version and not recorded for another digest", a, err)
|
||||
// A digest not recorded yet takes the publish (A-490j); a name the reservation does not know is a no naming it.
|
||||
unbuilt := func(string, string) (meshbuilds.ReservedAnswer, error) {
|
||||
return meshbuilds.ReservedAnswer{Module: "m", Version: "0.1.5", Artifacts: []meshbuilds.ReservedAnswerArtifactsItem{{Artifact: "m:program"}}}, nil
|
||||
}
|
||||
if _, err := AnswerVersions(ctx, r, " ", "", ""); err == nil {
|
||||
if a, _ := AnswerVersions("m/program", "0.1.5", "sha256:cc", unbuilt); a.Recorded == nil || !*a.Recorded {
|
||||
t.Errorf("an artifact with no digest recorded yet = %+v, want recorded", a)
|
||||
}
|
||||
unknown := func(string, string) (meshbuilds.ReservedAnswer, error) {
|
||||
return meshbuilds.ReservedAnswer{Error: "no entry carries the name x"}, nil
|
||||
}
|
||||
if a, _ := AnswerVersions("x", "0.1.0", "sha256:aa", unknown); a.Recorded == nil || *a.Recorded || !strings.Contains(a.Why, "no entry carries") {
|
||||
t.Errorf("a name no entry carries = %+v, want not recorded naming it", a)
|
||||
}
|
||||
if a, err := AnswerVersions("m/program", "", "", reserve); err != nil || a.Recorded != nil || a.Reserved == nil {
|
||||
t.Errorf("builder_versions with no version = %+v, %v; want the reservation alone", a, err)
|
||||
}
|
||||
if _, err := AnswerVersions(" ", "", "", reserve); err == nil {
|
||||
t.Error("builder_versions with no name answered")
|
||||
}
|
||||
})
|
||||
@@ -218,34 +211,6 @@ func TestTheBuildersVersions(t *testing.T) {
|
||||
t.Error("a closed window closes again: old-form-closed would be said twice")
|
||||
}
|
||||
})
|
||||
t.Run("the registry seats' words mark an entry", func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
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) {
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
all, _ := n.Versions.Of(ctx, "m/program")
|
||||
if all[0].State != h.state {
|
||||
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 {
|
||||
t.Fatal("a published of a version the builder never numbered is not said")
|
||||
}
|
||||
})
|
||||
t.Run("the packages state's names", func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
state := packagesMem{
|
||||
@@ -262,27 +227,4 @@ func TestTheBuildersVersions(t *testing.T) {
|
||||
t.Error("a packages state that cannot be read is no error")
|
||||
}
|
||||
})
|
||||
t.Run("fill", func(t *testing.T) {
|
||||
if _, full := Fill(Cap*79/100, Cap); full {
|
||||
t.Error("79 % is full")
|
||||
}
|
||||
if _, full := Fill((Cap*80+99)/100, Cap); !full {
|
||||
t.Error("80 % is not full")
|
||||
}
|
||||
})
|
||||
t.Run("a refusal records its digest", func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
st := newMem()
|
||||
v := Versions{Store: st}
|
||||
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[0].RefusedDigest != "sha256:old" {
|
||||
t.Errorf("refused records no digest: %+v", es[0])
|
||||
}
|
||||
if all, err := v.All(ctx); err != nil || len(all) != 1 {
|
||||
t.Errorf("All = %d entries, %v", len(all), err)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -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: "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: "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
|
||||
|
||||
@@ -140,7 +140,6 @@
|
||||
{ "name": "acted", "history": 1, "max-mib": 1 },
|
||||
{ "name": "asked", "history": 1, "max-mib": 8 },
|
||||
{ "name": "reasks", "history": 1, "max-mib": 8 },
|
||||
{ "name": "versions", "history": 1, "max-mib": 32 },
|
||||
{ "name": "first-views", "history": 1, "max-mib": 8 },
|
||||
{ "name": "unbuildable", "history": 1, "max-mib": 8 },
|
||||
{ "name": "consumers", "history": 1, "max-mib": 8 }
|
||||
|
||||
Reference in New Issue
Block a user