A14 put-newest-passed, A15 put-by-prefix: the program resolves newest and a prefix at the put's first step
The tool writes the put as asked; StepPut's first step resolves newest to the end kept for the node's branch (refused naming the branch when none) and a 12 to 63 digit prefix to the one done build that starts with it (refused naming each match). Builds: design 47 H2b §833, §834 (H-A-848, H-A-862)
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"maps"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -60,6 +61,20 @@ func (b *builtEnds) endOf(module, fp string) (builds.BuildEnded, bool) {
|
||||
return e, ok
|
||||
}
|
||||
|
||||
// doneStarting is the done builds of module the assigner hears whose fingerprint starts with prefix, in fingerprint order.
|
||||
func (b *builtEnds) doneStarting(module, prefix string) []builds.BuildEnded {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
var out []builds.BuildEnded
|
||||
for _, e := range b.ends {
|
||||
if e.Module == module && e.Outcome == builds.BuildDone && strings.HasPrefix(e.Fingerprint, prefix) {
|
||||
out = append(out, e)
|
||||
}
|
||||
}
|
||||
sort.Slice(out, func(i, j int) bool { return out[i].Fingerprint < out[j].Fingerprint })
|
||||
return out
|
||||
}
|
||||
|
||||
// partsOf is the parts of module's build at fp as its end names them (each artifact's digest by `<module>:<artifact>`), with the
|
||||
// node that keeps it, for a kept build or a build of another watched branch; false for a build of the trunk not kept, whose
|
||||
// parts the version's release says (releasedVersions).
|
||||
|
||||
@@ -444,7 +444,8 @@ func putOfTheBus(t *testing.T) {
|
||||
before, _ := nodeengineclient.EncodeHave(nodeengine.HaveByNodeModuleValue{Fp: meshcatalogclient.SourcePrefix2 + strings.Repeat("a", 64), Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK})
|
||||
world(buckets.Have, hkey, before)
|
||||
|
||||
// Issue 1966: newest is asked of the indexer's first view of modules, never read from its bus state.
|
||||
// The tool asks nobody for newest (design 47 H2b §833): the program resolves it. The indexer's view is asked only for the
|
||||
// older-than-newest of the puts listed (issue 1966).
|
||||
indexer := &fakeIndexer{views: map[string]map[string][]byte{"mesh-delivery-indexer.modules": {"mesh-catalog": mod, "nats": mod}}}
|
||||
s := newPutTools(memStore{putsState: putsKV}, func(key string, body any) (json.RawMessage, error) {
|
||||
if raw, ok, err := indexer.answer(key, body); ok {
|
||||
@@ -456,19 +457,19 @@ func putOfTheBus(t *testing.T) {
|
||||
was := answerWithin
|
||||
answerWithin = 0
|
||||
defer func() { answerWithin = was }()
|
||||
if _, err := s.doPut(map[string]any{"node": "novox", "module": "nats", "version": "fd497ab8ffff", "why": "x"}, "shanks.node-tools"); err == nil {
|
||||
t.Error("a prefix of a fingerprint was taken: a put names the whole fingerprint (A-181)")
|
||||
// Design 47 H2b §833, §834: the tool reads nothing; it takes newest, a whole fingerprint, or its first 12 hex digits as asked.
|
||||
prefix := meshcatalogclient.SourcePrefix2 + "fd497ab80000"
|
||||
for _, ok := range []string{"newest", fp, prefix, strings.ToUpper(prefix)} {
|
||||
if _, err := s.version("nats", ok); err != nil {
|
||||
t.Errorf("%q is a version: %v", ok, err)
|
||||
}
|
||||
}
|
||||
if _, err := s.version("nats", "fd497ab80000"); err == nil {
|
||||
t.Error("the prefix of the fingerprint built was read: a put names the whole fingerprint (A-181)")
|
||||
for _, bad := range []string{"fd497ab80000", meshcatalogclient.SourcePrefix2 + "fd497ab800", "main", ""} {
|
||||
if _, err := s.version("nats", bad); err == nil {
|
||||
t.Errorf("%q was taken as a version", bad)
|
||||
}
|
||||
}
|
||||
if got, err := s.version("nats", "newest"); err != nil || got != fp || indexer.asks["mesh-delivery-indexer.modules"] != 2 {
|
||||
t.Errorf("newest reads %q, %v, asking %d pages of the indexer's first view (want its 2)", got, err, indexer.asks["mesh-delivery-indexer.modules"])
|
||||
}
|
||||
if _, err := s.version("ghost", "newest"); err == nil || !strings.Contains(err.Error(), "holds no module ghost") {
|
||||
t.Errorf("newest of a module the indexer does not hold: %v", err)
|
||||
}
|
||||
ans, err := s.doPut(map[string]any{"node": "novox", "module": "nats", "version": fp, "hold": "true", "why": "the bus's user list"}, "shanks.node-tools")
|
||||
ans, err := s.doPut(map[string]any{"node": "novox", "module": "nats", "version": prefix, "hold": "true", "why": "the bus's user list"}, "shanks.node-tools")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -486,8 +487,8 @@ func putOfTheBus(t *testing.T) {
|
||||
}
|
||||
return got
|
||||
}
|
||||
if got := step(); got.Step != puts.Compose || !strings.Contains(got.Words, "no composition") {
|
||||
t.Fatalf("the first pass left the put at %s: %s", got.Step, got.Words)
|
||||
if got := step(); got.Step != puts.Compose || !strings.Contains(got.Words, "no composition") || got.FP != fp {
|
||||
t.Fatalf("the first pass left the put at %s (%s) at %q: it resolves the prefix to the whole fingerprint %s", got.Step, got.Words, got.FP, fp)
|
||||
}
|
||||
select {
|
||||
case call := <-bus.calls:
|
||||
@@ -594,6 +595,38 @@ func putOfTheBus(t *testing.T) {
|
||||
if string(wantsKV.values["want.novox.nats"]) != string(oldWant) {
|
||||
t.Errorf("a want was written for a put released meanwhile: %s", wantsKV.values["want.novox.nats"])
|
||||
}
|
||||
// §833, H-A-862: newest is the end kept for the node's branch, whatever newer build the trunk has; none kept is refused
|
||||
// naming the branch and the words of the tool's description. §834: a prefix two builds share is refused naming both.
|
||||
trunkNewer := meshcatalogclient.SourcePrefix2 + strings.Repeat("9", 64)
|
||||
p.ends = newPipelineEnds(newMemEnds(), func() {}, t.Logf)
|
||||
p.ends.trunk = p.w.trunkName
|
||||
if _, err := s.doPut(map[string]any{"node": "novox", "module": "nats", "version": "newest", "why": "the newest that passed"}, "shanks.node-tools"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := step(); got.Step != puts.Refused || !strings.Contains(got.Words, "no version of nats passed a pipeline: name a fingerprint, or read assigner_written") || !strings.Contains(got.Words, trunkBranch) {
|
||||
t.Fatalf("newest with no end kept stands at %s: %s", got.Step, got.Words)
|
||||
}
|
||||
end, _ := json.Marshal(End{Pipeline: "main.7", Source: 7, Seq: 1, Fp: fp, Version: "2.10.1", Rank: 1})
|
||||
p.ends.st.(*memEnds).vals[endKey("nats", trunkBranch)] = end
|
||||
p.w.put(buckets.Puts(), pkey, putsKV.values[pkey])
|
||||
if _, err := s.doPut(map[string]any{"node": "novox", "module": "nats", "version": "newest", "why": "again"}, "shanks.node-tools"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := step(); got.FP != fp || !strings.Contains(got.Steps[0].Words+got.Steps[1].Words, "which newest resolves to") {
|
||||
t.Fatalf("newest with an end kept at %s stands at %s at %q: %s (the trunk's %s passed no pipeline)", fp, got.Step, got.FP, got.Words, trunkNewer)
|
||||
}
|
||||
for _, other := range []string{"1", "2"} {
|
||||
two, _ := json.Marshal(builds.BuildEnded{Module: "nats", Fingerprint: fp[:len(fp)-1] + other, Outcome: builds.BuildDone})
|
||||
if p.w.ends.put(two) != nil {
|
||||
t.Fatal("a build is not heard")
|
||||
}
|
||||
}
|
||||
if _, err := s.doPut(map[string]any{"node": "novox", "module": "nats", "version": meshcatalogclient.SourcePrefix2 + "fd497ab80000", "why": "shared prefix"}, "shanks.node-tools"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := step(); got.Step != puts.Refused || strings.Count(got.Words, "fd497ab80000") < 3 {
|
||||
t.Fatalf("a prefix three builds share stands at %s: %s", got.Step, got.Words)
|
||||
}
|
||||
}
|
||||
|
||||
// 1906 note 28: an ask outlives its fingerprint. Each pass takes away the hold, restore and record asks of a module whose
|
||||
|
||||
@@ -138,6 +138,12 @@ func (p *passer) puts(ctx context.Context) {
|
||||
world := p.putWorld(node, module, put, manifest, assigned[node])
|
||||
world.Snapshot, world.Snapshotting, world.SnapshotFailed = p.acts.state(id)
|
||||
next := assign.StepPut(world)
|
||||
if puts.Unresolved(put.FP) && puts.Whole(next.Put.FP) {
|
||||
// The first step resolved the version (H-A-848, H-A-862): the rest is read at the fingerprint it named.
|
||||
world = p.putWorld(node, module, next.Put, manifest, assigned[node])
|
||||
world.Snapshot, world.Snapshotting, world.SnapshotFailed = p.acts.state(id)
|
||||
next = assign.StepPut(world)
|
||||
}
|
||||
// The bus's want is written only for the act the operator's yes bound (ADR 0546 clause 8).
|
||||
if next.Put.Step == puts.Wanted && put.Step != puts.Wanted && world.Bus && next.Put.Ask != "" {
|
||||
if err := p.performs(next.Put.Ask, assign.PutAct(node, module, next.Put.FP, next.Put.Composed)); err != nil {
|
||||
@@ -183,6 +189,19 @@ func (p *passer) putWorld(node, module string, put puts.Put, manifest catalogue.
|
||||
if e, ok := p.w.ends.endOf(module, put.FP); ok { // the build's end heard (A-181): none heard, no state
|
||||
w.Build, w.BuildWords = e.Outcome, e.Error
|
||||
}
|
||||
if puts.Unresolved(put.FP) {
|
||||
for _, e := range p.w.ends.doneStarting(module, put.FP) {
|
||||
v, _ := p.w.releasedOf(module, e.Fingerprint)
|
||||
w.Matches = append(w.Matches, assign.PutMatch{FP: e.Fingerprint, Version: v})
|
||||
}
|
||||
w.Branch = p.w.trunkName()
|
||||
if p.ends.following() {
|
||||
w.Branch = p.ends.branchOf(module, p.w.placedBranches()[module][node])
|
||||
}
|
||||
if end, ok := p.ends.endOf(module, w.Branch); ok {
|
||||
w.BranchEnd = end.Fp
|
||||
}
|
||||
}
|
||||
w.Version, _ = p.w.releasedOf(module, put.FP) // matched by its build's parts, as the pass matches a mover's (H-A-490 addendum)
|
||||
w.Composed, w.Granted = p.composedFor(node, module, put.FP)
|
||||
if d := w.Composed; d != nil {
|
||||
@@ -278,7 +297,7 @@ func (p *passer) performs(key string, act occ.Act) error {
|
||||
|
||||
// samePut says two puts say the same: their step, words and what they found.
|
||||
func samePut(a, b puts.Put) bool {
|
||||
return a.Step == b.Step && a.Words == b.Words && a.Composed == b.Composed && a.Ask == b.Ask && a.Snapshot == b.Snapshot
|
||||
return a.FP == b.FP && a.Step == b.Step && a.Words == b.Words && a.Composed == b.Composed && a.Ask == b.Ask && a.Snapshot == b.Snapshot
|
||||
}
|
||||
|
||||
// writePut writes a put's next value over the one the pass read, by compare-and-set, unless the tool has put again or
|
||||
|
||||
@@ -74,33 +74,18 @@ func (s *putTools) hear(key string, value []byte) {
|
||||
// fullFP is a fingerprint of the new form, whole.
|
||||
var fullFP = regexp.MustCompile(`^src2:[0-9a-f]{64}$`)
|
||||
|
||||
// version reads the version a put names: newest (the indexer's fingerprint at the trunk) or a whole fingerprint (design 47 G A-181:
|
||||
// a put names the whole fingerprint, the builder's builds being no bucket to list).
|
||||
// prefixFP is a fingerprint's first 12 to 63 hex digits behind src2:.
|
||||
var prefixFP = regexp.MustCompile(`^src2:[0-9a-f]{12,64}$`)
|
||||
|
||||
// version reads the version a put names: newest, or a fingerprint whole or by its first 12 hex digits. The tool reads nothing:
|
||||
// the program resolves newest to the end kept for the node's branch, and a prefix among the builds it hears, at the put's first
|
||||
// step (design 47 H2b §833, §834; H-A-848, H-A-862).
|
||||
func (s *putTools) version(module, version string) (string, error) {
|
||||
v := strings.ToLower(strings.TrimSpace(version))
|
||||
switch {
|
||||
case v == "newest":
|
||||
// Asked of the indexer's first view of modules, never read from its bus state (ADR 0596, ADR 0621; issue 1966).
|
||||
mods, err := indexerView(s.ask, indexerModules)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("the indexer's modules cannot be read: %w", err)
|
||||
}
|
||||
raw, found := mods[module]
|
||||
if !found {
|
||||
return "", fmt.Errorf("the indexer holds no module %s at the trunk", module)
|
||||
}
|
||||
m, err := meshcatalogclient.DecodeModule(raw)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("the indexer's %s cannot be read: %w", module, err)
|
||||
}
|
||||
if m.Fp2 == "" {
|
||||
return "", fmt.Errorf("the indexer holds no fingerprint of the new form for %s: %s", module, m.None2)
|
||||
}
|
||||
return m.Fp2, nil
|
||||
case fullFP.MatchString(v):
|
||||
if v == puts.Newest || fullFP.MatchString(v) || prefixFP.MatchString(v) {
|
||||
return v, nil
|
||||
}
|
||||
return "", fmt.Errorf("%q is no version: newest, a fingerprint (src2: and 64 hex digits) whole", version)
|
||||
return "", fmt.Errorf("%q is no version of %s: newest (the version whose pipeline passed), or a fingerprint (src2: and 64 hex digits, or at least its first 12)", version, module)
|
||||
}
|
||||
|
||||
// putAnswer is what assigner_put and assigner_puts answer of one put.
|
||||
@@ -155,7 +140,7 @@ func (s *putTools) doPut(args map[string]any, by string) (any, error) {
|
||||
return nil, fmt.Errorf("the put of %s on %s cannot be read: %w", module, node, err)
|
||||
} else if found {
|
||||
if before, err := puts.Decode(raw); err == nil && !puts.Ended(before.Step) {
|
||||
if before.FP == fp && before.Hold == hold {
|
||||
if (before.FP == fp || (puts.Unresolved(fp) && fp != puts.Newest && strings.HasPrefix(before.FP, fp))) && before.Hold == hold {
|
||||
a := answerOf(node, module, before)
|
||||
a.Follow = followPut(node, module)
|
||||
return a, nil
|
||||
@@ -332,7 +317,7 @@ func (s *putTools) tools() []stdio.Tool {
|
||||
Input: schema(map[string]string{
|
||||
"node": "the machine, where the module is assigned",
|
||||
"module": "the module",
|
||||
"version": "newest, a fingerprint (src2: and 64 hex digits), or at least its first 12 hex digits",
|
||||
"version": "newest (the version of the node's branch whose pipeline passed), a fingerprint (src2: and 64 hex digits), or at least its first 12 hex digits",
|
||||
"hold": "\"true\": the want stays at this version until released; \"false\" (the default): the rules move it again once it runs",
|
||||
"why": "why, kept with the put and said in any ask",
|
||||
}, []string{"node", "module", "version", "why"}, "hold"),
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"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"
|
||||
"mesh-delivery-assigner/internal/puts"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
occ "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient"
|
||||
@@ -56,6 +57,43 @@ type PutWorld struct {
|
||||
// ends on it, never on the have.
|
||||
Running *nodeengine.Running
|
||||
Now time.Time
|
||||
// Matches are the done builds of the module the assigner hears whose fingerprint starts with the put's prefix, with the
|
||||
// version released at each ("" none); Branch is the watched branch the pass uses for the module on the node and
|
||||
// BranchEnd the fingerprint of the end kept there ("" when none is kept). They resolve a put's version at its first
|
||||
// step (design 47 H2b §833, §834; H-A-848, H-A-862).
|
||||
Matches []PutMatch
|
||||
Branch string
|
||||
BranchEnd string
|
||||
}
|
||||
|
||||
// PutMatch is one done build that starts with a put's prefix.
|
||||
type PutMatch struct{ FP, Version string }
|
||||
|
||||
// resolvePut is the put with its version resolved to the whole fingerprint, or the words that refuse it (design 47 H2b §833,
|
||||
// §834): newest is the end kept for the node's branch, a prefix the one done build that starts with it.
|
||||
func resolvePut(w PutWorld) (puts.Put, string) {
|
||||
p := w.Put
|
||||
asked := p.FP
|
||||
if asked == puts.Newest {
|
||||
if w.BranchEnd == "" {
|
||||
return p, fmt.Sprintf("no version of %s passed a pipeline: name a fingerprint, or read assigner_written (the end of branch %s is the one read)", w.Module, w.Branch)
|
||||
}
|
||||
p.FP = w.BranchEnd
|
||||
} else {
|
||||
switch len(w.Matches) {
|
||||
case 0:
|
||||
return p, fmt.Sprintf("no build of %s that the assigner hears is done at a fingerprint starting %s: name another fingerprint", w.Module, asked)
|
||||
case 1:
|
||||
p.FP = w.Matches[0].FP
|
||||
default:
|
||||
var each []string
|
||||
for _, m := range w.Matches {
|
||||
each = append(each, fmt.Sprintf("%s (%s)", short(m.FP), m.Version))
|
||||
}
|
||||
return p, fmt.Sprintf("%s names more than one build of %s: %s; name more of the fingerprint", asked, w.Module, strings.Join(each, ", "))
|
||||
}
|
||||
}
|
||||
return p.Said(w.Now, p.Step, fmt.Sprintf("the put of %s names %s, which %s resolves to", w.Module, p.FP, asked)), ""
|
||||
}
|
||||
|
||||
// PutNext is what a step decides: the put as it stands after it, and the acts the pass does for it.
|
||||
@@ -78,6 +116,13 @@ func StepPut(w PutWorld) PutNext {
|
||||
say := func(step, format string, args ...any) PutNext {
|
||||
return PutNext{Put: p.Said(w.Now, step, fmt.Sprintf(format, args...))}
|
||||
}
|
||||
if puts.Unresolved(p.FP) {
|
||||
resolved, refused := resolvePut(w)
|
||||
if refused != "" {
|
||||
return PutNext{Put: p.Said(w.Now, puts.Refused, refused)}
|
||||
}
|
||||
p = resolved
|
||||
}
|
||||
fp := short(p.FP)
|
||||
if !w.Assigned {
|
||||
return say(puts.Refused, "%s is not assigned to %s: a put moves a module where it stands assigned (propose its assignments first)", w.Module, w.Node)
|
||||
|
||||
@@ -112,9 +112,28 @@ func (p Put) StandsSince() time.Time {
|
||||
|
||||
var digestForm = regexp.MustCompile(`^sha256:[0-9a-f]{64}$`)
|
||||
|
||||
// Newest is the version a put names to take the newest version whose pipeline passed on the node's branch (design 47 H2b
|
||||
// §833); the program resolves it at the put's first step (H-A-862), as it resolves a prefix of a fingerprint (§834, H-A-848).
|
||||
const Newest = "newest"
|
||||
|
||||
var prefixForm = regexp.MustCompile(`^src2:[0-9a-f]{12,64}$`)
|
||||
|
||||
// Whole says fp is a whole fingerprint of the new form.
|
||||
func Whole(fp string) bool {
|
||||
_, err := catalogkey.KeyPart(fp)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// Unresolved says fp is what a put names before its first step resolves it: Newest, or src2: and 12 to 63 hex digits.
|
||||
func Unresolved(fp string) bool {
|
||||
return fp == Newest || (prefixForm.MatchString(fp) && !Whole(fp))
|
||||
}
|
||||
|
||||
func (p Put) check() error {
|
||||
if _, err := catalogkey.KeyPart(p.FP); err != nil {
|
||||
return fmt.Errorf("puts: a put's fingerprint: %w", err)
|
||||
if !Unresolved(p.FP) {
|
||||
if _, err := catalogkey.KeyPart(p.FP); err != nil {
|
||||
return fmt.Errorf("puts: a put's fingerprint: %w", err)
|
||||
}
|
||||
}
|
||||
if p.Why == "" {
|
||||
return fmt.Errorf("puts: a put says why")
|
||||
|
||||
Reference in New Issue
Block a user