A8: a placement's build names the want's version
The pass reads each node's placement before the rule: a placement naming a build has its want name that build, by the version released at it (the kept end's when it is that build, else the release whose parts the build made), with no pipeline and no rank; with no released version known no want is written, said once. A placement's build is no longer made a held put: placementPuts and its test go, and a placement naming no build any more gives the node back to the rule. Builds: design 47 H §750, H-A-5, H-A-37, H-A-39, H-A-99 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
||||
mma "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-assigner/asks"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient"
|
||||
@@ -288,6 +289,7 @@ func (p *passer) wants(ctx context.Context) {
|
||||
p.clearStaleCalls()
|
||||
placed := p.w.placedNodes()
|
||||
puts := p.putsByModule()
|
||||
builds := placementBuilds(p.w.assignments())
|
||||
p.staleAsks(ctx, trunk)
|
||||
names := map[string]bool{}
|
||||
for name := range trunk {
|
||||
@@ -308,7 +310,13 @@ func (p *passer) wants(ctx context.Context) {
|
||||
ReadsVersion: func(node string) bool {
|
||||
return slices.Contains(nodes.Reads[node], nodeengine.ManifestReadWordWantVersion)
|
||||
},
|
||||
Target: func(string) (assign.Target, bool) { return target, ok },
|
||||
// H §750, H-A-5, H-A-99: a placement's build is read before the rule and names the want's version.
|
||||
Target: func(node string) (assign.Target, bool) {
|
||||
if build := builds[node][name]; build != "" {
|
||||
return p.buildTarget(name, g.branch, node, build)
|
||||
}
|
||||
return target, ok
|
||||
},
|
||||
Allowed: func(node, digest string) bool {
|
||||
key, err := asks.RecordAskKey(node, name, digest)
|
||||
return err == nil && p.answeredWith(key, assign.OptionYes)
|
||||
@@ -869,3 +877,41 @@ func (p *passer) movedTo(wanted map[string]map[string]mwc.Want, n assign.Nodes)
|
||||
return ok && !w.Removed && !n.RunsHealthy(node, owner, w.Fp)
|
||||
}
|
||||
}
|
||||
|
||||
// placementBuilds is, by node and module, the build a placement names (the placement's value `build`, design 47 H §750, H-A-39):
|
||||
// a return to an earlier build.
|
||||
func placementBuilds(assignments map[string]mma.Assignments) map[string]map[string]string {
|
||||
out := map[string]map[string]string{}
|
||||
for node, a := range assignments {
|
||||
for _, m := range a.Modules {
|
||||
if m.Build == "" {
|
||||
continue
|
||||
}
|
||||
if out[node] == nil {
|
||||
out[node] = map[string]string{}
|
||||
}
|
||||
out[node][m.Module] = m.Build
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// buildTarget is the want of module on node whose placement names build (design 47 H §750, H-A-5, H-A-99): that build, named by
|
||||
// the version released at it, with no pipeline and no rank (H-A-37). The version is the kept end's when it is that build, else
|
||||
// the version whose release names the parts the build made; with none known no want is written, said once per build.
|
||||
func (p *passer) buildTarget(module, branch, node, build string) (assign.Target, bool) {
|
||||
version := ""
|
||||
if end, ok := p.ends.endOf(module, branch); p.ends != nil && ok && end.Fp == build {
|
||||
version = end.Version
|
||||
} else if k, ok := p.w.released.withParts(module, p.w.ends.madeOf(module, build)); ok {
|
||||
version = k.Version
|
||||
}
|
||||
if version == "" {
|
||||
if key := "build-unreleased." + node + "." + module + "." + build; !p.said[key] {
|
||||
p.said[key] = true
|
||||
p.logf("the placement of %s on %s names build %s, at which no released version is known; its want is written once one is", module, node, shortFP(build))
|
||||
}
|
||||
return assign.Target{}, false
|
||||
}
|
||||
return assign.Target{Fp: build, Version: version}, true
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-assigner/asks"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
mdc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient"
|
||||
mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient"
|
||||
@@ -136,7 +137,7 @@ func TestAnAnswerCountsOnlyForTheAskingItAnswered(t *testing.T) {
|
||||
t.Error("an answer to an ask taken away was taken")
|
||||
}
|
||||
t.Run("a put of the bus acts on the operator's warrant alone", putOfTheBus)
|
||||
t.Run("a placement's build is put held, and released when the placement names it no more", aPlacementsBuildIsPut)
|
||||
t.Run("a placement's build names the want's version", aPlacementsBuildNamesTheWantsVersion)
|
||||
// ADR 0614 §4: the rules read what each node's engine states it reads from its record in `<node>.node`; a node with no
|
||||
// record, or one that states nothing, is read as stating nothing (the rules then read the baseline).
|
||||
t.Run("the rules read what each node's engine reads", func(t *testing.T) {
|
||||
@@ -351,60 +352,71 @@ func (b *fakeBus) Emit(eventType string, body any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Design 47 line 912 and line 914 ("a placement's `build` delivers the earlier build"; ADR 0666 §24, B-K1): a placed
|
||||
// module's build becomes a held put of that build, which then goes a put's steps; a placement naming no build any more
|
||||
// releases the put it made, never a person's.
|
||||
func aPlacementsBuildIsPut(t *testing.T) {
|
||||
// A8/AC1 (design 47 H §750, H-A-5, H-A-37, H-A-99): a placement's build is read before the rule and names the want's version,
|
||||
// the version released at that build, with no pipeline and no rank and no put; the node whose placement names none follows the
|
||||
// newest passed version; a placement naming no build any more gives the node back to the rule.
|
||||
func aPlacementsBuildNamesTheWantsVersion(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
putsKV := &memKV{values: map[string][]byte{}}
|
||||
p := newPasser(kvSet{buckets.Puts(): putsKV}, time.Date(2026, 11, 10, 18, 0, 0, 0, time.UTC))
|
||||
earlier := meshcatalogclient.SourcePrefix2 + strings.Repeat("e", 64)
|
||||
wantsKV, putsKV := &memKV{values: map[string][]byte{}}, &memKV{values: map[string][]byte{}}
|
||||
p := newPasser(kvSet{buckets.Wants(): wantsKV, buckets.Asks(): &memKV{values: map[string][]byte{}}, buckets.Puts(): putsKV}, time.Now())
|
||||
p.say = func(oc.Condition) error { return nil }
|
||||
earlier, newer := meshcatalogclient.SourcePrefix2+strings.Repeat("e", 64), meshcatalogclient.SourcePrefix2+strings.Repeat("f", 64)
|
||||
mdigest := strings.Repeat("a", 64)
|
||||
mod, _ := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: newer, Manifest: mdigest, Repository: "novox/web", Commit: strings.Repeat("1", 40), Path: meshcatalogclient.RootPath})
|
||||
putModuleRaw(p.w, trunkBranch, "web", mod)
|
||||
p.w.manifests[mdigest] = parsed{module: "web", manifest: catalogue.Manifest{Module: "web"}}
|
||||
// The earlier build's release: its parts are what the build made.
|
||||
rel, _ := json.Marshal(meshcatalog.VersionReleasedEvent{Module: "web", Source: 3, Version: "0.1.1", Artifacts: []meshcatalog.VersionArtifact{{Artifact: "web:image", Digest: "sha256:1"}}})
|
||||
if err := p.w.released.put(rel); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
end, _ := json.Marshal(builds.BuildEnded{Module: "web", Fingerprint: earlier, Outcome: builds.BuildDone, Made: map[string]string{"image": "sha256:1"}})
|
||||
if err := p.w.ends.put(end); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
place := func(build string) {
|
||||
values, err := mmac.AssignmentsValues(mma.Assignments{Node: "g14", Modules: []mma.PlacedModule{{Module: "web", Build: build}, {Module: "db"}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for key, raw := range values {
|
||||
p.w.putEntry(plc.AssignmentsBucket(), key, raw, uint64(len(raw)), time.Now())
|
||||
for _, node := range []string{"g14", "ace"} {
|
||||
pm := mma.PlacedModule{Module: "web"}
|
||||
if node == "g14" {
|
||||
pm.Build = build
|
||||
}
|
||||
values, err := mmac.AssignmentsValues(mma.Assignments{Node: node, Modules: []mma.PlacedModule{pm}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for key, raw := range values {
|
||||
p.w.putEntry(plc.AssignmentsBucket(), key, raw, uint64(len(raw)), time.Now())
|
||||
}
|
||||
}
|
||||
}
|
||||
read := func() (puts.Put, bool) {
|
||||
raw, ok := putsKV.values["g14.web"]
|
||||
if !ok {
|
||||
return puts.Put{}, false
|
||||
}
|
||||
got, err := puts.Decode(raw)
|
||||
p.ends = newPipelineEnds(newMemEnds(), func() {}, t.Logf)
|
||||
p.ends.trunk = p.w.trunkName
|
||||
if _, err := p.ends.take(ended(trunkBranch, 5, mpr.PipelineEndedOutcomePassed, mover("web", newer, "0.1.2", 1, mpr.StepResultOutcomePassed))); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
read := func(node string) mwc.Want {
|
||||
key, _ := mwc.WantKey(node, "web")
|
||||
w, err := mwc.DecodeWant(wantsKV.values[key])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
t.Fatalf("no want of web on %s: %v", node, err)
|
||||
}
|
||||
return got, true
|
||||
return w
|
||||
}
|
||||
place(earlier)
|
||||
p.placementPuts(ctx)
|
||||
got, ok := read()
|
||||
if !ok || got.FP != earlier || !got.Hold || got.By != placementBy || got.Step != puts.Asked {
|
||||
t.Fatalf("the placement's build made the put %+v (there %v)", got, ok)
|
||||
p.wants(ctx)
|
||||
if w := read("g14"); w.Fp != earlier || w.Version != "0.1.1" || w.Pipeline != "" || w.Rank != 0 || w.Put {
|
||||
t.Errorf("the placement's build names the want %+v, want %s at 0.1.1, no pipeline, rank or put", w, earlier)
|
||||
}
|
||||
if _, there := putsKV.values["g14.db"]; there {
|
||||
t.Error("a placed module naming no build was put")
|
||||
if w := read("ace"); w.Fp != newer || w.Version != "0.1.2" {
|
||||
t.Errorf("the node naming no build wants %+v", w)
|
||||
}
|
||||
p.placementPuts(ctx) // again: the same build makes nothing new
|
||||
if again, _ := read(); !again.At.Equal(got.At) || again.Step != puts.Asked {
|
||||
t.Errorf("a second pass made the put again: %+v", again)
|
||||
if len(putsKV.values) != 0 {
|
||||
t.Errorf("a placement's build made a put: %v", putsKV.values)
|
||||
}
|
||||
place("")
|
||||
p.placementPuts(ctx)
|
||||
if got, _ := read(); got.Step != puts.Released || !strings.Contains(got.Words, placementBy) {
|
||||
t.Errorf("the placement naming no build left the put %+v", got)
|
||||
}
|
||||
// A person's put stands while the placement names no build.
|
||||
person := puts.Put{FP: earlier, Hold: true, Why: "a try", By: "lead@shanks", At: time.Now()}.Said(time.Now(), puts.Holding, "held")
|
||||
raw, _ := puts.Encode(person)
|
||||
putsKV.values["g14.web"] = raw
|
||||
p.w.put(buckets.Puts(), "g14.web", raw)
|
||||
p.placementPuts(ctx)
|
||||
if got, _ := read(); got.Step != puts.Holding || got.By != "lead@shanks" {
|
||||
t.Errorf("a person's put was released by the placement: %+v", got)
|
||||
p.wants(ctx)
|
||||
if w := read("g14"); w.Fp != newer || w.Version != "0.1.2" {
|
||||
t.Errorf("a placement naming no build any more left the want %+v", w)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"mesh-delivery-assigner/internal/buckets"
|
||||
"mesh-delivery-assigner/internal/puts"
|
||||
)
|
||||
|
||||
// placementBy is who a put the placement's build makes names as its asker: the placement, whose proposal the operator
|
||||
// approved, is the warrant (design 47 *Going back is one act*; ADR 0666 §24).
|
||||
const placementBy = "the placement"
|
||||
|
||||
// placementPuts makes each placed module's `build` a held put of that build, and releases a put the placement made once its
|
||||
// placement names that build no more (design 47 line 912: "a return to an earlier build is one value in the placement, the
|
||||
// module's `build` in its placement key, set by a placement proposal"; ADR 0666 §24; B-K1). The put then goes its own steps
|
||||
// (the builder's build, the composition, an ask where the module's policy needs one, the want, holding) and is read with
|
||||
// `assigner_puts` and released with `assigner_release` like any other; a placement's build the builder never built is refused
|
||||
// by its build step, said in the put's words. A put asked by a person stands until the placement names another build.
|
||||
func (p *passer) placementPuts(ctx context.Context) {
|
||||
kv := p.kvs[buckets.Puts()]
|
||||
if kv == nil {
|
||||
return
|
||||
}
|
||||
now := p.clock().UTC()
|
||||
named := map[string]string{} // put key -> the build its placement names
|
||||
for node, a := range p.w.assignments() {
|
||||
for _, m := range a.Modules {
|
||||
if m.Build == "" {
|
||||
continue
|
||||
}
|
||||
if key, err := puts.Key(node, m.Module); err == nil {
|
||||
named[key] = m.Build
|
||||
}
|
||||
}
|
||||
}
|
||||
held := p.w.read(buckets.Puts())
|
||||
keys := make([]string, 0, len(named)+len(held))
|
||||
for k := range named {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
for k := range held {
|
||||
if _, there := named[k]; !there {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
}
|
||||
sort.Strings(keys)
|
||||
for _, key := range keys {
|
||||
build, names := named[key]
|
||||
var before *puts.Put
|
||||
if raw, ok := held[key]; ok {
|
||||
if got, err := puts.Decode(raw); err == nil {
|
||||
before = &got
|
||||
}
|
||||
}
|
||||
var next puts.Put
|
||||
switch {
|
||||
case names && before != nil && before.FP == build:
|
||||
continue // made already, or a person's put of the same build: it goes its own steps, ended or not
|
||||
case names:
|
||||
words := fmt.Sprintf("asked by %s: it names build %s of %s", placementBy, shortFP(build), key)
|
||||
if before != nil && !puts.Ended(before.Step) {
|
||||
words += fmt.Sprintf("; it replaces the put of %s, which stood at %s", shortFP(before.FP), before.Step)
|
||||
}
|
||||
next = puts.Put{FP: build, Hold: true, Why: "the placement names this build (ADR 0666 §24)", By: placementBy, At: now}.Said(now, puts.Asked, words)
|
||||
case before != nil && before.By == placementBy && !puts.Ended(before.Step):
|
||||
next = before.Said(now, puts.Released, fmt.Sprintf("released by %s: it names no build of its own any more; the assigner's rules write the want again", placementBy))
|
||||
default:
|
||||
continue
|
||||
}
|
||||
data, err := puts.Encode(next)
|
||||
if err != nil {
|
||||
p.logf("the placement's put %s is not written: %v", key, err)
|
||||
continue
|
||||
}
|
||||
if before == nil {
|
||||
_, err = kv.Create(ctx, key, data)
|
||||
} else if e, gerr := kv.Get(ctx, key); gerr != nil {
|
||||
err = gerr
|
||||
} else {
|
||||
_, err = kv.Update(ctx, key, data, e.Revision())
|
||||
}
|
||||
if err != nil {
|
||||
p.logf("the placement's put %s could not be written, and is written at the next pass: %v", key, err)
|
||||
continue
|
||||
}
|
||||
p.w.put(buckets.Puts(), key, data)
|
||||
p.logf("put %s: %s: %s", key, next.Step, next.Words)
|
||||
if p.acts != nil {
|
||||
p.acts.say(key, next)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,7 +106,6 @@ func (p *passer) puts(ctx context.Context) {
|
||||
if p.acts == nil {
|
||||
return
|
||||
}
|
||||
p.placementPuts(ctx)
|
||||
all := p.putsByModule()
|
||||
defer func() { p.putWaits(ctx, p.putsByModule()) }()
|
||||
if len(all) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user