Merge pull request 'Design 47 H2's corrections: movers carried beside a failed one, validate, acted lifetimes, publish asked again (issue 1984)' (#365) from feat/47-H2-corrections into main
This commit was merged in pull request #365.
This commit is contained in:
@@ -2,4 +2,4 @@
|
||||
|
||||
Novox Mesh — delivery: the parts that build, check and deliver a change by watching and writing keys on the bus (ADR 0429).
|
||||
|
||||
Made by the mesh from the gitea module's config value `repositories` (novox/hq ADR 0428). Main takes no push: a change reaches it by a pull request whose `mesh/repo-check` (this repository's `merge-check.sh`) and `mesh/merge-gate` passed.
|
||||
Made by the mesh from the gitea module's config value `repositories` (novox/hq ADR 0428). Main takes no push: a change reaches it by a pull request, which the checker judges. The forge's branch protection of main requires no status today (read from the forge on 2026-11-25: no required check, no status on the pull request read); this repository holds no `merge-check.sh`.
|
||||
|
||||
@@ -101,7 +101,7 @@ func TestAStepsInputsAreAskedOfEachMachine(t *testing.T) {
|
||||
t.Errorf("ace: %+v", got[0])
|
||||
}
|
||||
// Design 47 H2 §775, H-A-405: each machine is asked as a kept call under the step's ask with the node, until compose-ask-bound.
|
||||
if asks["ace"] != (process.KeptAsk{ID: "step-1.ace", Bound: time.Second}) || asks["g14"].ID != "step-1.g14" {
|
||||
if asks["ace"].ID != "step-1.ace" || asks["ace"].Bound != time.Second || asks["g14"].ID != "step-1.g14" {
|
||||
t.Errorf("the kept asks %+v", asks)
|
||||
}
|
||||
if !strings.Contains(got[1].Why, "no responders") || !strings.Contains(got[2].Why, "unready") || got[1].Body != nil || got[2].Body != nil {
|
||||
|
||||
@@ -4,29 +4,69 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
mccond "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
|
||||
mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||
"git.novox.be/novox/mesh-sdk/go/busretry"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
"mesh-delivery-assigner/internal/assign"
|
||||
)
|
||||
|
||||
// The reads of a composition step (design 47 G §354, A-252, A-261): the entries of one catalog revision are read once and shared by
|
||||
// every composition step of that revision, since an entry is content-addressed and a revision never changes; a read that times out
|
||||
// or fails in transport is made again with a growing wait for a bounded time, said in the journal, and only then ends the step as
|
||||
// could not run.
|
||||
// every composition step of that revision, since an entry is content-addressed and a revision never changes. Every read of the
|
||||
// seats mesh-catalog and mesh-builds is a kept call (§775), paced by the form, and all of one run's reads stop at one deadline: its
|
||||
// first read's time plus the setting reads-bound (design 47 H2 H-A-708 (3)); past it the run ends could not run with every call's
|
||||
// time and words.
|
||||
|
||||
const (
|
||||
// readsBound is how long a read is made again before the step could not run.
|
||||
readsBound = 3 * time.Minute
|
||||
// readsFirstWait and readsMaxWait bound the wait between two tries.
|
||||
readsFirstWait = time.Second
|
||||
readsMaxWait = 15 * time.Second
|
||||
// defaultReadsBound is the setting reads-bound's default, 8 minutes: it spans the six minutes a seat went unanswered on
|
||||
// 2026-11-23 and stays below the runner's ask-unanswered-bound (10 minutes, counted from the pull), so the step ends with the
|
||||
// assigner's words.
|
||||
defaultReadsBound = 8 * time.Minute
|
||||
// readsKept is how many catalog revisions' halves are kept; the oldest read goes first.
|
||||
readsKept = 8
|
||||
)
|
||||
|
||||
// readsBoundSetting is the setting reads-bound, in minutes, read at the start from the file the manifest declares with the content
|
||||
// ${config:reads-bound}; its default for a file missing or empty.
|
||||
func readsBoundSetting(getenv func(string) string) (time.Duration, error) {
|
||||
minutes, err := settingFile(getenv("MESH_ASSIGNER_READS_BOUND_FILE"))
|
||||
if err != nil || minutes == 0 {
|
||||
return defaultReadsBound, err
|
||||
}
|
||||
return time.Duration(minutes) * time.Minute, nil
|
||||
}
|
||||
|
||||
// readsClock is the deadline of one run's reads: it begins at the run's first read.
|
||||
type readsClock struct {
|
||||
mu sync.Mutex
|
||||
first time.Time
|
||||
last string
|
||||
}
|
||||
|
||||
type readsClockKey struct{}
|
||||
|
||||
// withReadsClock gives ctx the clock of one run's reads; a ctx that has one keeps it.
|
||||
func withReadsClock(ctx context.Context) context.Context {
|
||||
if ctx.Value(readsClockKey{}) != nil {
|
||||
return ctx
|
||||
}
|
||||
return context.WithValue(ctx, readsClockKey{}, &readsClock{})
|
||||
}
|
||||
|
||||
// readsClockOf is the clock of the run ctx belongs to, or a clock of its own for a read made outside a run.
|
||||
func readsClockOf(ctx context.Context) *readsClock {
|
||||
if c, ok := ctx.Value(readsClockKey{}).(*readsClock); ok {
|
||||
return c
|
||||
}
|
||||
return &readsClock{}
|
||||
}
|
||||
|
||||
// readKey names one revision of one watched branch.
|
||||
type readKey struct {
|
||||
branch string
|
||||
@@ -48,65 +88,71 @@ type compositionReads struct {
|
||||
seats map[string]json.RawMessage // by seat and digest: the definition, raw
|
||||
}
|
||||
|
||||
// transient says whether a read's fault is of the transport or a timeout, so that it is worth reading again.
|
||||
func transient(err error, said string) bool {
|
||||
text := said
|
||||
// callRead calls the seat verb key as a kept call that stops at the run's deadline (design 47 H2 H-A-708 (3)); it answers the body
|
||||
// of a good answer, or the holder's own words of an answer that is none, or the fault naming the holder, its machine and every
|
||||
// call of the form.
|
||||
func (r *compositionRun) callRead(ctx context.Context, key string, body any) (json.RawMessage, string, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
clock := readsClockOf(ctx)
|
||||
left, bound, first := r.readsLeft(clock)
|
||||
if left <= 0 {
|
||||
clock.mu.Lock()
|
||||
last := clock.last
|
||||
clock.mu.Unlock()
|
||||
return nil, "", fmt.Errorf("%s is not read: the run's reads passed their deadline of %s (the setting reads-bound) counted from its first read at %s%s",
|
||||
key, bound, first.UTC().Format(time.RFC3339), last)
|
||||
}
|
||||
id := readFindingID(key)
|
||||
r.waiting(id, +1)
|
||||
raw, err := r.call(process.KeptAsk{Bound: left, Hook: r.readHook}, key, body)
|
||||
r.waiting(id, -1)
|
||||
if err != nil {
|
||||
text = err.Error() + " " + said
|
||||
words := fmt.Errorf("%s%s: %w", key, r.holderWords(key), err)
|
||||
clock.mu.Lock()
|
||||
clock.last = "; the last read said: " + words.Error()
|
||||
clock.mu.Unlock()
|
||||
return nil, "", words
|
||||
}
|
||||
text = strings.ToLower(text)
|
||||
for _, w := range []string{"deadline exceeded", "timeout", "timed out", "no responders", "connection", "i/o", "eof", "broken pipe", "unavailable"} {
|
||||
if strings.Contains(text, w) {
|
||||
return true
|
||||
}
|
||||
inner, said, ok := buscalls.Unwrap(raw)
|
||||
if ok {
|
||||
return inner, "", nil
|
||||
}
|
||||
return false
|
||||
return nil, said, nil
|
||||
}
|
||||
|
||||
// callRetry calls the seat verb key, again with a growing wait while its fault is transient, for readsBound; it answers the body of
|
||||
// a good answer, or the last fault.
|
||||
func (r *compositionRun) callRetry(ctx context.Context, key string, body any) (json.RawMessage, string, error) {
|
||||
start := r.now()
|
||||
wait := readsFirstWait
|
||||
for try := 1; ; try++ {
|
||||
raw, err := r.call(key, body)
|
||||
var inner json.RawMessage
|
||||
var said string
|
||||
if err == nil {
|
||||
var ok bool
|
||||
if inner, said, ok = buscalls.Unwrap(raw); ok {
|
||||
return inner, "", nil
|
||||
}
|
||||
}
|
||||
if !transient(err, said) {
|
||||
return nil, said, err
|
||||
}
|
||||
if r.now().Sub(start)+wait > readsBound {
|
||||
return nil, said, err
|
||||
}
|
||||
r.logf("composition step: %s is not read (try %d, %v %s), read again in %s", key, try, err, said, wait)
|
||||
if serr := r.waitFor(ctx, wait); serr != nil {
|
||||
return nil, said, serr
|
||||
}
|
||||
if wait *= 2; wait > readsMaxWait {
|
||||
wait = readsMaxWait
|
||||
}
|
||||
// readsLeft is what stays of the run's reads' deadline, with the deadline's length and its first read's time; the first read
|
||||
// begins it.
|
||||
func (r *compositionRun) readsLeft(clock *readsClock) (left, bound time.Duration, first time.Time) {
|
||||
bound = r.readsBound
|
||||
if bound <= 0 {
|
||||
bound = defaultReadsBound
|
||||
}
|
||||
now := r.now()
|
||||
clock.mu.Lock()
|
||||
defer clock.mu.Unlock()
|
||||
if clock.first.IsZero() {
|
||||
clock.first = now
|
||||
}
|
||||
return bound - now.Sub(clock.first), bound, clock.first
|
||||
}
|
||||
|
||||
// waitFor waits d, or until ctx ends.
|
||||
func (r *compositionRun) waitFor(ctx context.Context, d time.Duration) error {
|
||||
if r.sleep != nil {
|
||||
return r.sleep(ctx, d)
|
||||
// holderWords name the module that holds the seat of key and the machines it runs on, as the seat list names them (design 47 H2
|
||||
// H-A-708 (3)); nothing where they are not read.
|
||||
func (r *compositionRun) holderWords(key string) string {
|
||||
seat, _, _ := strings.Cut(strings.TrimPrefix(key, "seat:"), ".")
|
||||
if r.holder == nil || seat == "" {
|
||||
return ""
|
||||
}
|
||||
t := time.NewTimer(d)
|
||||
defer t.Stop()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
case <-t.C:
|
||||
return nil
|
||||
module, nodes := r.holder(seat)
|
||||
if module == "" {
|
||||
return ""
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return " (its holder " + module + ")"
|
||||
}
|
||||
return " (its holder " + module + " on " + strings.Join(nodes, ", ") + ")"
|
||||
}
|
||||
|
||||
// half is the revision's half, read once for every step of it: a step that finds it being read waits for that read, and a read that
|
||||
@@ -179,3 +225,89 @@ func unreadErr(what string, err error, said string) error {
|
||||
}
|
||||
return fmt.Errorf("%s: %s", what, said)
|
||||
}
|
||||
|
||||
// readFindingID is the id of the finding call-unanswered of a read of key: `<seat>.<verb>`.
|
||||
func readFindingID(key string) string { return strings.TrimPrefix(key, "seat:") }
|
||||
|
||||
// readKey is the key of the finding call-unanswered of a read: one per seat verb.
|
||||
func readFindingKey(id string) string {
|
||||
return mccond.Key(mccond.ScopeCall, assign.KeyID(id), mccond.KindCallUnanswered)
|
||||
}
|
||||
|
||||
// readHook is the kept-call form's hook (design 47 H2 H-A-708 (4), H-A-731): told when a read has waited five minutes, it writes the
|
||||
// finding call-unanswered of its seat verb naming its holder, its machine, the last fault and since when; told of the answer, it
|
||||
// clears it.
|
||||
func (r *compositionRun) readHook(w busretry.Waited) {
|
||||
id := w.Seat + "." + w.Verb
|
||||
if w.Answered {
|
||||
r.clearRead(id, true)
|
||||
return
|
||||
}
|
||||
if r.findings.Put == nil {
|
||||
return
|
||||
}
|
||||
holder, nodes := "", []string(nil)
|
||||
if r.holder != nil {
|
||||
holder, nodes = r.holder(w.Seat)
|
||||
}
|
||||
f := assign.ReadUnanswered(w.Seat, w.Verb, holder, nodes, w.Last, w.Since).Finding(r.now())
|
||||
if err := r.findings.Put(f); err != nil {
|
||||
r.logf("the finding %s is not written: %v", readFindingKey(id), err)
|
||||
return
|
||||
}
|
||||
r.readMu.Lock()
|
||||
if r.raised == nil {
|
||||
r.raised = map[string]bool{}
|
||||
}
|
||||
r.raised[id] = true
|
||||
r.readMu.Unlock()
|
||||
}
|
||||
|
||||
// waiting counts the reads of one seat verb now waiting for an answer; when the last one ends, the finding it raised is cleared:
|
||||
// no run waits on it any more, and each run's could-not-run says it (design 47 H2 H-A-708 (4)).
|
||||
func (r *compositionRun) waiting(id string, d int) {
|
||||
r.readMu.Lock()
|
||||
if r.inflight == nil {
|
||||
r.inflight = map[string]int{}
|
||||
}
|
||||
r.inflight[id] += d
|
||||
none := r.inflight[id] <= 0
|
||||
if none {
|
||||
delete(r.inflight, id)
|
||||
}
|
||||
r.readMu.Unlock()
|
||||
if d < 0 && none {
|
||||
r.clearRead(id, false)
|
||||
}
|
||||
}
|
||||
|
||||
// clearRead clears the finding of a read's seat verb: at the verb's answer (answered), or once no read waits on it. The finding is
|
||||
// read from the findings bucket's keys, never from what this process raised, so one written before a restart is cleared as well
|
||||
// (design 47 H2 H-A-708 (4), H-A-722).
|
||||
func (r *compositionRun) clearRead(id string, answered bool) {
|
||||
r.readMu.Lock()
|
||||
was := r.raised[id]
|
||||
clear := answered || r.inflight[id] <= 0
|
||||
if clear {
|
||||
delete(r.raised, id)
|
||||
}
|
||||
r.readMu.Unlock()
|
||||
if !clear || r.findings.Delete == nil {
|
||||
return
|
||||
}
|
||||
key := readFindingKey(id)
|
||||
if r.findings.Keys != nil {
|
||||
ks, err := r.findings.Keys()
|
||||
if err != nil {
|
||||
r.logf("the finding %s is not cleared, the findings are not read: %v", key, err)
|
||||
return
|
||||
}
|
||||
was = slices.Contains(ks, key)
|
||||
}
|
||||
if !was {
|
||||
return
|
||||
}
|
||||
if err := r.findings.Delete(key); err != nil {
|
||||
r.logf("the finding %s is not cleared: %v", key, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,8 +58,20 @@ type compositionRun struct {
|
||||
runs *compositionRuns
|
||||
inputs *compositionInputs
|
||||
keeper *inputKeeper
|
||||
// call asks a seat verb held once for the mesh (process.Conn.CallKept).
|
||||
call func(key string, body any) (json.RawMessage, error)
|
||||
// call asks a seat verb held once for the mesh as a kept call that stops at the ask's bound (process.Conn.CallKeptAsk).
|
||||
call func(ask process.KeptAsk, key string, body any) (json.RawMessage, error)
|
||||
// readsBound is the setting reads-bound: the run's reads stop at its first read's time plus it (H-A-708 (3)); zero: its default.
|
||||
readsBound time.Duration
|
||||
// holder is the module holding a seat and the machines it runs on, for the words of a read that met a fault; nil: none named.
|
||||
holder func(seat string) (module string, nodes []string)
|
||||
// engineReads is what each node's engine states it reads (the state engine-reads), for the validate run's refusal of a node-engine
|
||||
// that needs what none states (design 47 H2 H-A-682 (5)); nil: none is judged.
|
||||
engineReads *engineReadsKept
|
||||
// readMu guards inflight, the reads now waiting by seat verb, and raised, the seat verbs whose finding call-unanswered this
|
||||
// process wrote (H-A-708 (4)).
|
||||
readMu sync.Mutex
|
||||
inflight map[string]int
|
||||
raised map[string]bool
|
||||
// callFile asks a seat verb held once for the mesh whose answer comes in chunks, as a kept call (process.Conn.CallFileKept),
|
||||
// answering the verb's answer with the bytes received as its member `file`, base64: the validate step's seat-list (H-A-443).
|
||||
callFile func(ask process.KeptAsk, key string, body any) (json.RawMessage, error)
|
||||
@@ -87,9 +99,8 @@ type compositionRun struct {
|
||||
// own is the assigner's own context: a run's start, and its wait for a package's publish, run on it as the take-up's do, never
|
||||
// on the starting step's, which a supersede or a drop ends while other steps share the run (design 47 H2 H-A-630 (3)).
|
||||
own context.Context
|
||||
// reads shares the catalog reads among steps (compositionreads.go); sleep waits between two tries of a read (nil: a timer).
|
||||
// reads shares the catalog reads among steps (compositionreads.go).
|
||||
reads *compositionReads
|
||||
sleep func(ctx context.Context, d time.Duration) error
|
||||
// ask asks a seat verb on one node, for the run's answer kept as the build seat's object (buildstep.StepEnded.ReadOutput).
|
||||
ask buildstep.AskVerb
|
||||
now func() time.Time
|
||||
@@ -258,6 +269,7 @@ func (p *runPrep) get(ctx context.Context) error {
|
||||
// start composes the machine of the run the step asked under stepAsk started (§718): the node's input of this moment, its request kept once in `inputs`,
|
||||
// the composer program chosen and recorded with the request's digest, and one run ask put. A fault ends the run could not run.
|
||||
func (r *compositionRun) start(ctx context.Context, key string, run meshwants.CompositionRun, prep *runPrep, stepAsk string) {
|
||||
ctx = withReadsClock(ctx) // all the run's reads stop at one deadline (design 47 H2 H-A-708 (3))
|
||||
node, ask := run.Machine, run.Ask
|
||||
end := func(said string) {
|
||||
if _, err := r.runs.endRun(key, ask, meshwants.CompositionRunOutcomeCouldNotRun, said, nil); err != nil {
|
||||
@@ -477,7 +489,7 @@ func (r *compositionRun) readRevision(ctx context.Context, run meshwants.StepRun
|
||||
half := mcc.Half{Entries: map[string]meshcatalog.CatalogEntry{}}
|
||||
in := meshcatalog.RevisionInput{Branch: keys.EscapeName(run.Branch), Revision: run.Revision}
|
||||
for {
|
||||
body, said, err := r.callRetry(ctx, mcc.RevisionVerb, in)
|
||||
body, said, err := r.callRead(ctx, mcc.RevisionVerb, in)
|
||||
if err != nil {
|
||||
return mcc.Half{}, err
|
||||
}
|
||||
@@ -526,7 +538,7 @@ func (r *compositionRun) seats(ctx context.Context, defs []meshcatalog.CatalogRe
|
||||
// trunkSeats are the definitions of every seat of the trunk's seat list (seat-definitions with no seat names them with their digests).
|
||||
func (r *compositionRun) trunkSeats(ctx context.Context) ([]json.RawMessage, error) {
|
||||
what := "the trunk's seat list is not read"
|
||||
body, said, err := r.callRetry(ctx, seatDefinitionsKey, meshcatalog.SeatDefinitionsInput{})
|
||||
body, said, err := r.callRead(ctx, seatDefinitionsKey, meshcatalog.SeatDefinitionsInput{})
|
||||
if err != nil || body == nil {
|
||||
return nil, unreadErr(what, err, said)
|
||||
}
|
||||
@@ -554,7 +566,7 @@ func (r *compositionRun) seatAt(ctx context.Context, seat, digest string) (json.
|
||||
return def, nil
|
||||
}
|
||||
what := "the definition of the seat " + seat + " is not read"
|
||||
body, said, err := r.callRetry(ctx, seatDefinitionsKey, meshcatalog.SeatDefinitionsInput{Seat: seat})
|
||||
body, said, err := r.callRead(ctx, seatDefinitionsKey, meshcatalog.SeatDefinitionsInput{Seat: seat})
|
||||
if err != nil || body == nil {
|
||||
return nil, unreadErr(what, err, said)
|
||||
}
|
||||
@@ -998,7 +1010,7 @@ func (r *compositionRun) takeUpWaits(ctx context.Context) {
|
||||
// publishedOf asks the seat mesh-builds' verb published whether by's build is published, answering the pin it is published at
|
||||
// (vMAJOR.MINOR.PATCH, spec S9) when it is.
|
||||
func (r *compositionRun) publishedOf(ctx context.Context, by packagePublisher) (string, bool, error) {
|
||||
body, said, err := r.callRetry(ctx, publishedVerbKey, builds.PublishedInput{Module: by.module, Artifact: by.artifact, Fingerprint: by.fingerprint})
|
||||
body, said, err := r.callRead(ctx, publishedVerbKey, builds.PublishedInput{Module: by.module, Artifact: by.artifact, Fingerprint: by.fingerprint})
|
||||
if err != nil || body == nil {
|
||||
return "", false, unreadErr(builds.VerbPublished+" did not answer", err, said)
|
||||
}
|
||||
@@ -1052,7 +1064,7 @@ func (r *compositionRun) programs(ctx context.Context, half mcc.Half) (func(node
|
||||
return b.program, fp, b.pins, nil
|
||||
}
|
||||
what := "the entry of the node-engine's build " + fp + " is not read"
|
||||
body, said, err := r.callRetry(ctx, entryVerbKey, meshcatalog.EntryInput{Fingerprint: fp})
|
||||
body, said, err := r.callRead(ctx, entryVerbKey, meshcatalog.EntryInput{Fingerprint: fp})
|
||||
if err != nil || body == nil {
|
||||
return buildstep.RunProgram{}, fp, nil, unreadErr(what, err, said)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.novox.be/novox/mesh-sdk/go/busretry"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
"maps"
|
||||
@@ -17,6 +18,7 @@ import (
|
||||
mmac "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"
|
||||
mma "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||
ne "git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||
mccond "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
|
||||
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||
mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
builds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
@@ -25,6 +27,7 @@ import (
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/composer"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
"mesh-delivery-assigner/internal/assign"
|
||||
)
|
||||
|
||||
@@ -201,7 +204,7 @@ func newRunStand(t *testing.T, revisionEngine, trunkEngine, seatDigest string) *
|
||||
s.runs = newCompositionRuns(newRunsMem(), defaultRunSettings, time.Now, t.Logf)
|
||||
s.r = &compositionRun{runs: s.runs,
|
||||
inputs: &compositionInputs{machines: func(string, string) []string { return []string{"ace", "g14", "shanks"} }, callFile: engines, bound: time.Second},
|
||||
keeper: keeper, reads: &compositionReads{}, call: call, away: away, own: context.Background(), now: time.Now, logf: t.Logf,
|
||||
keeper: keeper, reads: &compositionReads{}, call: asKept(call), away: away, own: context.Background(), now: time.Now, logf: t.Logf,
|
||||
trunk: func() (mcc.Half, bool) {
|
||||
return mcc.Half{Entries: map[string]meshcatalog.CatalogEntry{"engine": engine(trunkEngine, commitE1)}}, true
|
||||
},
|
||||
@@ -663,51 +666,40 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 G §354, A-252: the entries of one catalog revision are read once for every step of it, and a read that times out is
|
||||
// made again with a growing wait for a bounded time, said in the journal, before the step could not run.
|
||||
func TestTheCompositionStepReadsTheRevisionOnceAndAgainOnATimeout(t *testing.T) {
|
||||
// asKept is a fake seat call as the kept call the run makes: the bound and the hook are the call's own, a fake answers at once.
|
||||
func asKept(call func(key string, body any) (json.RawMessage, error)) func(process.KeptAsk, string, any) (json.RawMessage, error) {
|
||||
return func(_ process.KeptAsk, key string, body any) (json.RawMessage, error) { return call(key, body) }
|
||||
}
|
||||
|
||||
// Design 47 G §354, A-252: the entries of one catalog revision are read once for every step of it, and a fault of the holder's own
|
||||
// answer is not read again.
|
||||
func TestTheCompositionStepReadsTheRevisionOnce(t *testing.T) {
|
||||
step := meshwants.StepRun{Module: "m", Branch: "main", Revision: 7, Step: meshwants.StepRunStepComposition}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
faults int // consecutive faults of the `revision` read before it answers
|
||||
fault error // the fault
|
||||
fault error // the fault of the `revision` read, none: it answers
|
||||
steps int
|
||||
want string // the outcome of the last step
|
||||
revisionCalls int
|
||||
waits int
|
||||
}{
|
||||
{"two steps of one revision read it once", 0, nil, 2, meshwants.StepEndedOutcomeFailed, 2, 0},
|
||||
{"a timeout is read again", 3, errors.New("context deadline exceeded"), 1, meshwants.StepEndedOutcomeFailed, 5, 3},
|
||||
{"a fault that stays ends could not run", 1000, errors.New("nats: timeout"), 1, meshwants.StepEndedOutcomeCouldNotRun, -1, -1},
|
||||
{"a fault of the answer is not read again", 1, errors.New("no such revision"), 1, meshwants.StepEndedOutcomeCouldNotRun, 1, 0},
|
||||
{"two steps of one revision read it once", nil, 2, meshwants.StepEndedOutcomeFailed, 2},
|
||||
{"a fault of the answer is not read again", errors.New("no such revision"), 1, meshwants.StepEndedOutcomeCouldNotRun, 1},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
s := newRunStand(t, "src2:e1", "src2:e1", "d1")
|
||||
inner := s.r.call
|
||||
var mu sync.Mutex
|
||||
calls, faults := 0, tc.faults
|
||||
s.r.call = func(key string, body any) (json.RawMessage, error) {
|
||||
calls := 0
|
||||
s.r.call = func(ask process.KeptAsk, key string, body any) (json.RawMessage, error) {
|
||||
if key == mcc.RevisionVerb {
|
||||
mu.Lock()
|
||||
calls++
|
||||
f := faults > 0
|
||||
faults--
|
||||
mu.Unlock()
|
||||
if f {
|
||||
if tc.fault != nil {
|
||||
return nil, tc.fault
|
||||
}
|
||||
}
|
||||
return inner(key, body)
|
||||
}
|
||||
clock := time.Unix(1000, 0)
|
||||
var waits []time.Duration
|
||||
s.r.now = func() time.Time { mu.Lock(); defer mu.Unlock(); return clock }
|
||||
s.r.sleep = func(_ context.Context, d time.Duration) error {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
waits = append(waits, d)
|
||||
clock = clock.Add(d)
|
||||
return nil
|
||||
return inner(ask, key, body)
|
||||
}
|
||||
var wg sync.WaitGroup
|
||||
outs := make([]stepOutcome, tc.steps)
|
||||
@@ -721,29 +713,127 @@ func TestTheCompositionStepReadsTheRevisionOnceAndAgainOnATimeout(t *testing.T)
|
||||
t.Fatalf("a step came to %+v, want %s", o, tc.want)
|
||||
}
|
||||
}
|
||||
if tc.waits == -1 { // never answers: bounded, growing waits
|
||||
if len(waits) < 3 || waits[0] != readsFirstWait || waits[1] != 2*readsFirstWait || waits[len(waits)-1] != readsMaxWait {
|
||||
t.Errorf("the waits %v do not grow to %s", waits, readsMaxWait)
|
||||
}
|
||||
var total time.Duration
|
||||
for _, w := range waits {
|
||||
total += w
|
||||
}
|
||||
if total > readsBound {
|
||||
t.Errorf("read again for %s, bound %s", total, readsBound)
|
||||
}
|
||||
if !strings.Contains(outs[0].Said, "catalog revision is not read") || !strings.Contains(outs[0].Said, "timeout") {
|
||||
t.Errorf("the step said %q", outs[0].Said)
|
||||
}
|
||||
return
|
||||
}
|
||||
if calls != tc.revisionCalls || len(waits) != tc.waits {
|
||||
t.Errorf("`revision` asked %d times with %d waits, want %d and %d", calls, len(waits), tc.revisionCalls, tc.waits)
|
||||
if calls != tc.revisionCalls {
|
||||
t.Errorf("`revision` asked %d times, want %d", calls, tc.revisionCalls)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 H2 H-A-708 (3), AC-A6: every read of a run is a kept call that stops at one deadline, the run's first read's time plus
|
||||
// reads-bound (default 8 minutes): two reads each unanswered in turn end the run could not run with the assigner's words before
|
||||
// the runner's bound of 10 minutes, naming the holder and its machine, the last fault and the calls; a read answered after a
|
||||
// fault of two minutes composes.
|
||||
func TestARunsReadsShareOneDeadline(t *testing.T) {
|
||||
step := meshwants.StepRun{Module: "m", Branch: "main", Revision: 7, Step: meshwants.StepRunStepComposition}
|
||||
away := &busretry.Away{Part: "the trunk's revision 512", Words: "not read yet since 23:35:40"}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
answer func(clock *time.Time, ask process.KeptAsk, key string) error // a fault of the read, none: it answers
|
||||
want string
|
||||
bounds []time.Duration // the bound each kept call was given, in order
|
||||
}{
|
||||
{"seat-definitions met by no responders for two minutes and then answered composes", func(clock *time.Time, ask process.KeptAsk, key string) error {
|
||||
if key == seatDefinitionsKey && clock.Before(time.Unix(1000, 0).Add(2*time.Minute)) {
|
||||
*clock = clock.Add(2 * time.Minute) // the form met no responders for two minutes, then the holder answered
|
||||
}
|
||||
return nil
|
||||
}, meshwants.StepEndedOutcomeFailed, nil},
|
||||
{"two reads each unanswered in turn end the run at the shared deadline", func(clock *time.Time, ask process.KeptAsk, key string) error {
|
||||
if key == mcc.RevisionVerb || key == seatDefinitionsKey {
|
||||
*clock = clock.Add(ask.Bound) // the form asks again until the bound it is given
|
||||
return &busretry.Unanswered{Seat: "mesh-catalog", Verb: "x", Bound: ask.Bound, Tries: []busretry.Try{{At: *clock, Words: away.Error()}}, Last: away}
|
||||
}
|
||||
return nil
|
||||
}, meshwants.StepEndedOutcomeCouldNotRun, []time.Duration{8 * time.Minute}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
s := newRunStand(t, "src2:e1", "src2:e1", "d1")
|
||||
inner := s.r.call
|
||||
clock := time.Unix(1000, 0)
|
||||
var mu sync.Mutex
|
||||
var bounds []time.Duration
|
||||
s.r.now = func() time.Time { mu.Lock(); defer mu.Unlock(); return clock }
|
||||
s.r.holder = func(seat string) (string, []string) { return "mesh-delivery-indexer", []string{"novox"} }
|
||||
s.r.call = func(ask process.KeptAsk, key string, body any) (json.RawMessage, error) {
|
||||
mu.Lock()
|
||||
bounds = append(bounds, ask.Bound)
|
||||
err := tc.answer(&clock, ask, key)
|
||||
mu.Unlock()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return inner(ask, key, body)
|
||||
}
|
||||
out := s.r.run(context.Background(), "ask-step", step)
|
||||
if out.Outcome != tc.want {
|
||||
t.Fatalf("the step came to %+v, want %s", out, tc.want)
|
||||
}
|
||||
if tc.bounds == nil {
|
||||
return
|
||||
}
|
||||
total := clock.Sub(time.Unix(1000, 0))
|
||||
if total > 9*time.Minute || bounds[0] != 8*time.Minute {
|
||||
t.Errorf("the reads took %s with bounds %v, want the first at 8m and all before the runner's 10m", total, bounds)
|
||||
}
|
||||
for _, w := range []string{"mesh-delivery-indexer on novox", "not read yet since 23:35:40", "mesh-catalog"} {
|
||||
if !strings.Contains(out.Said, w) {
|
||||
t.Errorf("the step said %q, which does not name %q", out.Said, w)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 H2 H-A-708 (4), H-A-731, AC-A7: a read that waited five minutes writes the finding call-unanswered, id `<seat>.<verb>`,
|
||||
// naming its holder and machine, the last fault and since when; the verb's answer clears it, and so does the end of the last read
|
||||
// waiting on it past its bound; a finding written before a restart, which no process of this run raised, is cleared the same way
|
||||
// (H-A-722: the clear reads the findings bucket's keys).
|
||||
func TestAReadUnansweredForFiveMinutesIsTheFindingCallUnanswered(t *testing.T) {
|
||||
step := meshwants.StepRun{Module: "m", Branch: "main", Revision: 7, Step: meshwants.StepRunStepComposition}
|
||||
for _, c := range []struct{ answered, restarted bool }{{true, false}, {false, false}, {true, true}, {false, true}} {
|
||||
answered, restarted := c.answered, c.restarted
|
||||
s := newRunStand(t, "src2:e1", "src2:e1", "d1")
|
||||
inner := s.r.call
|
||||
findings := map[string]mcseat.Finding{}
|
||||
s.r.findings = assign.Findings{Put: func(f mcseat.Finding) error { findings[views.FindingKey(f.Scope, f.ID, f.Kind)] = f; return nil },
|
||||
Keys: func() ([]string, error) { return slices.Collect(maps.Keys(findings)), nil },
|
||||
Delete: func(key string) error { delete(findings, key); return nil }}
|
||||
s.r.holder = func(string) (string, []string) { return "mesh-delivery-indexer", []string{"novox"} }
|
||||
since := time.Unix(500, 0)
|
||||
key := mccond.Key(mccond.ScopeCall, "mesh-catalog.revision", mccond.KindCallUnanswered)
|
||||
if restarted { // written before a restart: this process raised nothing
|
||||
findings[key] = mcseat.Finding{}
|
||||
}
|
||||
s.r.call = func(ask process.KeptAsk, k string, body any) (json.RawMessage, error) {
|
||||
if k != mcc.RevisionVerb {
|
||||
return inner(ask, k, body)
|
||||
}
|
||||
if !restarted {
|
||||
ask.Hook(busretry.Waited{Seat: "mesh-catalog", Verb: "revision", Since: since, Last: "away: the trunk's revision 512 not read yet"})
|
||||
}
|
||||
if f, ok := findings[key]; !restarted && (!ok || !strings.Contains(f.Summary, "mesh-delivery-indexer on novox") || !strings.Contains(f.Summary, "the trunk's revision 512") ||
|
||||
!strings.Contains(f.Summary, since.UTC().Format(time.RFC3339))) {
|
||||
t.Errorf("at five minutes the findings are %+v", findings)
|
||||
}
|
||||
if answered {
|
||||
ask.Hook(busretry.Waited{Seat: "mesh-catalog", Verb: "revision", Since: since, Answered: true})
|
||||
if _, ok := findings[key]; ok {
|
||||
t.Error("the answer left the finding")
|
||||
}
|
||||
return inner(ask, k, body)
|
||||
}
|
||||
return nil, &busretry.Unanswered{Seat: "mesh-catalog", Verb: "revision", Bound: ask.Bound}
|
||||
}
|
||||
if out := s.r.run(context.Background(), "ask-step", step); answered == (out.Outcome == meshwants.StepEndedOutcomeCouldNotRun) {
|
||||
t.Errorf("answered %v: the step came to %+v", answered, out)
|
||||
}
|
||||
if len(findings) != 0 {
|
||||
t.Errorf("answered %v: the findings stand after the read: %+v", answered, findings)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 G §718, §719, §720: three composition steps of one revision on two machines start two runs, one request and one run
|
||||
// ask per machine, and each step reads both verdicts; the run records its program with the node-engine fingerprint it was chosen
|
||||
// from and the digest of its kept request, which names no module of the asking pipeline; a step of another candidate starts its
|
||||
|
||||
@@ -104,9 +104,9 @@ func (c *compositionSteps) drop(r *compositionRuns, record func(meshhandactsclie
|
||||
return answer, err
|
||||
}
|
||||
|
||||
// compositionVerbs are the process's handlers of the seat mesh-wants' verbs compositions and compositions-drop.
|
||||
func compositionVerbs(r *compositionRuns, c *compositionSteps, record func(meshhandactsclient.Request) error) map[string]process.SeatHandler {
|
||||
return map[string]process.SeatHandler{
|
||||
// compositionVerbs are the process's handlers of the seat mesh-wants' verbs compositions, compositions-drop and validate.
|
||||
func compositionVerbs(r *compositionRuns, c *compositionSteps, record func(meshhandactsclient.Request) error, validate *compositionRun) map[string]process.SeatHandler {
|
||||
verbs := map[string]process.SeatHandler{
|
||||
meshwants.VerbCompositions: func(_ string, raw json.RawMessage) (any, error) {
|
||||
var in meshwants.CompositionsInput
|
||||
if len(raw) > 0 {
|
||||
@@ -124,6 +124,17 @@ func compositionVerbs(r *compositionRuns, c *compositionSteps, record func(meshh
|
||||
return c.drop(r, record, caller, in)
|
||||
},
|
||||
}
|
||||
if validate != nil {
|
||||
// The seat's verb validate (design 47 H2 H-A-727): the tool assigner_validate reaches the process, which keeps the runs.
|
||||
verbs[meshwants.VerbValidate] = func(caller string, raw json.RawMessage) (any, error) {
|
||||
var in meshwants.ValidateInput
|
||||
if err := json.Unmarshal(raw, &in); err != nil {
|
||||
return nil, fmt.Errorf("the arguments are not JSON: %w", err)
|
||||
}
|
||||
return validate.validateOnRequest(validate.own, record, caller, in)
|
||||
}
|
||||
}
|
||||
return verbs
|
||||
}
|
||||
|
||||
// compositionsTools are the module's tools of §728's names, each calling its verb (A-469f).
|
||||
|
||||
+2
-2
@@ -45,14 +45,14 @@ func TestTheCompositionRunsAreReadAndDroppedByTheirVerbs(t *testing.T) {
|
||||
})
|
||||
var recorded []meshhandactsclient.Request
|
||||
record := func(q meshhandactsclient.Request) error { recorded = append(recorded, q); return nil }
|
||||
verbs := compositionVerbs(r, c, record)
|
||||
verbs := compositionVerbs(r, c, record, nil)
|
||||
out, err := verbs[meshwants.VerbCompositions]("op", json.RawMessage(`{"machine":"n2"}`))
|
||||
read, _ := out.(meshwants.CompositionsAnswer)
|
||||
if err != nil || len(read.Runs) != 1 || read.Runs[0].Key != runKeyOf("main.3", "n2") || read.Runs[0].Ask != "run-n2" || len(read.Runs[0].Readers) != 3 ||
|
||||
read.Fill.Store != "composition-runs" || read.Fill.Cap != 16<<20 || read.Fill.Bytes == 0 {
|
||||
t.Fatalf("compositions = %+v %v", out, err)
|
||||
}
|
||||
refuse := compositionVerbs(r, c, func(meshhandactsclient.Request) error { return errors.New("no holder") })
|
||||
refuse := compositionVerbs(r, c, func(meshhandactsclient.Request) error { return errors.New("no holder") }, nil)
|
||||
if _, err := refuse[meshwants.VerbCompositionsDrop]("op", json.RawMessage(`{"candidate":"main.3","machine":"n2","why":"stuck"}`)); err == nil ||
|
||||
!strings.Contains(err.Error(), "nothing was dropped") || len(drops) != 0 {
|
||||
t.Fatalf("a drop not recorded: %v, drops %v", err, drops)
|
||||
|
||||
+13
@@ -152,8 +152,21 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T)
|
||||
case <-time.After(30 * time.Second):
|
||||
t.Fatal("the assigner did not read the seat list within 30 s")
|
||||
}
|
||||
// H2 H-A-708 (3), AC-A6b: the seat mesh-catalog's holder is stopped while the composition reads its entry: the read is a kept
|
||||
// call, the journal says the seat does not answer, and the step goes on and passes once the holder answers again.
|
||||
b.cat.stop()
|
||||
outage := b.journal.mark()
|
||||
putStep(b.ctx, t, b.js, "step-ask-1", meshwants.StepRun{Pipeline: "main.3.m", Step: meshwants.StepRunStepComposition, Module: "m", Branch: trunkBranch,
|
||||
Revision: 3, Commit: engineCommit, Fingerprint: "src2:m1"})
|
||||
select { // the read met the stopped holder, and the step has gone no further
|
||||
case <-b.cat.met:
|
||||
case <-time.After(30 * time.Second):
|
||||
t.Fatal("no read reached the stopped seat mesh-catalog")
|
||||
}
|
||||
if b.journal.has(outage, "the composition step of m says fetch") {
|
||||
t.Fatal("the step went on while the seat mesh-catalog's holder was stopped")
|
||||
}
|
||||
b.cat.serve()
|
||||
// Each machine's run waits for x/go's publish, the step saying fetch; the publish heard, each puts its run ask (1984/AC11).
|
||||
for _, node := range []string{"n1", "n2"} {
|
||||
b.journal.await(t, from, "the composition run main=2e3."+node+" waits for package "+pkg, "the run of "+node+" waits", 30*time.Second)
|
||||
|
||||
@@ -54,6 +54,15 @@ func (h *halves) follow() error {
|
||||
h.changed(branch, module, entry, deleted)
|
||||
}
|
||||
b.Adopted = h.adopted
|
||||
// An entry read by fingerprint never changes: each catalog revision taken in releases only the entries that no want and no
|
||||
// `running` the assigner holds names any more (design 47 H2 H-A-757, amending H-A-682 (2)).
|
||||
b.Held = func(string, meshcatalog.CatalogRevision) {
|
||||
for _, r := range b.Entries.Rows() {
|
||||
if !h.w.namesFingerprint(r.Fingerprint) {
|
||||
b.Entries.Release(r.Fingerprint)
|
||||
}
|
||||
}
|
||||
}
|
||||
// The one handler of registration-changed is the follower's (H-A-270 (3)): the pipeline ends are told each change from it,
|
||||
// never from a second handler on the hub.
|
||||
reconcile := b.Registrations.Follower.Changed
|
||||
|
||||
@@ -4,7 +4,14 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||
mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient"
|
||||
mpr "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
"mesh-delivery-assigner/internal/buckets"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -105,3 +112,107 @@ func TestAModulesWatchedBranchesAreItsRegistrations(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// H-A-682 (2): the entries read by fingerprint are kept until the next catalog revision the assigner takes in, and each revision
|
||||
// held releases those no want or running names (H-A-757).
|
||||
func TestACatalogRevisionTakenInReleasesTheEntriesKept(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
call := func(key string, _ any) (json.RawMessage, error) {
|
||||
if key == mcc.EntryVerb {
|
||||
return json.Marshal(seat.EntryAnswer{Entry: seat.CatalogEntry{Module: "m", Needs: []string{"x"}}})
|
||||
}
|
||||
return nil, errors.New("not answered here")
|
||||
}
|
||||
reader := &views.ProcessReader{Module: "mesh-delivery-assigner", Call: call, Logf: t.Logf}
|
||||
h := &halves{w: newWorld(), call: call, reader: reader, wake: func() {}, logf: t.Logf, ctx: ctx}
|
||||
if err := h.follow(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
answered := make(chan struct{}, 1)
|
||||
h.branches.Entries.Changed = func(mcc.EntryRow) { answered <- struct{}{} }
|
||||
old := mcc.SourcePrefix2 + strings.Repeat("a", 64)
|
||||
for _, fp := range []string{old, "src2:unnamed"} {
|
||||
h.branches.Entries.Need(ctx, fp)
|
||||
select {
|
||||
case <-answered:
|
||||
case <-ctx.Done():
|
||||
t.Fatal("the entry is never answered")
|
||||
}
|
||||
}
|
||||
raw, _ := mwc.EncodeWant(mwc.Want{Fp: old, Version: "1.0.0", Pipeline: trunkBranch + ".5", Rank: 1, Run: "205", Self: true})
|
||||
key, _ := mwc.WantKey("g14", "web")
|
||||
h.w.putEntry(buckets.Wants(), key, raw, 1, time.Now())
|
||||
// A pass over the want at the older fingerprint: the module's trunk entry names a newer one, so its needs come from the entry
|
||||
// read by fingerprint. The want stands as the pass writes it, so a revision taken in and a pass after it write nothing.
|
||||
writes := 0
|
||||
wantsKV := &writeCountingKV{memKV: memKV{values: map[string][]byte{}}, writes: &writes, key: key}
|
||||
p := newPasser(kvSet{buckets.Wants(): wantsKV, buckets.Asks(): &memKV{values: map[string][]byte{}}}, time.Now())
|
||||
p.w, p.entries = h.w, h.branches.Entries
|
||||
p.w.setTrunk(trunkBranch)
|
||||
p.publishWants = func(string, any, string) error { return nil }
|
||||
p.ends = newPipelineEnds(newMemEnds(), func() {}, t.Logf)
|
||||
p.ends.trunk = p.w.trunkName
|
||||
p.reads = &engineReadsKept{} // g14 states want:version and the capability the entry needs
|
||||
words, _ := json.Marshal(engineWords{Words: []string{nodeengine.ManifestReadWordWantVersion, "x"}, At: time.Now()})
|
||||
if err := p.reads.take("g14", words, false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
digest := strings.Repeat("4", 64)
|
||||
mod, _ := mcc.EncodeModule(seat.ModulesByModuleValue{Fp2: mcc.SourcePrefix2 + strings.Repeat("b", 64), Manifest: digest, Repository: "novox/web", Commit: strings.Repeat("1", 40), Path: mcc.RootPath})
|
||||
putModuleRaw(p.w, trunkBranch, "web", mod)
|
||||
p.w.manifests[digest] = parsed{module: "web", manifest: catalogue.Manifest{Module: "web"}}
|
||||
placeOn(t, p.w, "g14", "web")
|
||||
p.w.mu.Lock()
|
||||
p.w.runningHeard = true
|
||||
p.w.mu.Unlock()
|
||||
runningRaw, _ := json.Marshal(nodeengine.Running{Node: "g14", Module: "web", Fingerprint: old})
|
||||
if err := p.w.hearRunning("running.g14.web", runningRaw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The pipeline that passed names the older fingerprint: it is the want's target, its entry the one read by fingerprint.
|
||||
e := ended(trunkBranch, 5, mpr.PipelineEndedOutcomePassed, mover("web", old, "1.0.0", 1, mpr.StepResultOutcomePassed))
|
||||
e.Source, e.Pipeline = 4, trunkBranch+".5"
|
||||
if _, err := p.ends.take(e); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p.wants(ctx)
|
||||
p.wants(ctx)
|
||||
settled := writes
|
||||
h.branches.Held("main", seat.CatalogRevision{Branch: "main", Revision: 2})
|
||||
if rows := h.branches.Entries.Rows(); len(rows) != 1 || rows[0].Fingerprint != old {
|
||||
t.Errorf("a catalog revision taken in keeps %+v, want the entry a want names and releases the one nothing names", rows)
|
||||
}
|
||||
p.wants(ctx)
|
||||
if writes != settled {
|
||||
t.Errorf("a pass after a revision taken in wrote %d wants: the want at the older fingerprint is rewritten", writes-settled)
|
||||
}
|
||||
}
|
||||
|
||||
// writeCountingKV counts every write of one key of the wants bucket, a create or an update as a put.
|
||||
type writeCountingKV struct {
|
||||
memKV
|
||||
writes *int
|
||||
key string
|
||||
}
|
||||
|
||||
func (c *writeCountingKV) count(key string) {
|
||||
if key == c.key {
|
||||
*c.writes++
|
||||
}
|
||||
}
|
||||
|
||||
func (c *writeCountingKV) Put(ctx context.Context, key string, value []byte) (uint64, error) {
|
||||
c.count(key)
|
||||
return c.memKV.Put(ctx, key, value)
|
||||
}
|
||||
|
||||
func (c *writeCountingKV) Create(ctx context.Context, key string, value []byte, o ...jetstream.KVCreateOpt) (uint64, error) {
|
||||
c.count(key)
|
||||
return c.memKV.Create(ctx, key, value, o...)
|
||||
}
|
||||
|
||||
func (c *writeCountingKV) Update(ctx context.Context, key string, value []byte, revision uint64) (uint64, error) {
|
||||
c.count(key)
|
||||
return c.memKV.Update(ctx, key, value, revision)
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -98,6 +99,10 @@ type catalogBed struct {
|
||||
// at is, by branch and revision, a revision's entries a test keeps whole: the verb revision answers a revision asked by its
|
||||
// number from here, and the current one otherwise.
|
||||
at map[string]map[int64][]meshcatalog.CatalogEntry
|
||||
// stop makes the seat's holder unheard, as a holder stopped is (no responders); serve makes it heard again (serveCatalog).
|
||||
stop, serve func()
|
||||
// met says a call reached the holder while it was stopped.
|
||||
met chan struct{}
|
||||
}
|
||||
|
||||
// journal is a program's journal as the bed hears it: a test awaits a line in it (await) where the line is the only sign
|
||||
@@ -124,6 +129,13 @@ func (j *journal) mark() int {
|
||||
return j.text.Len()
|
||||
}
|
||||
|
||||
// has says whether the journal holds, after from (mark), a line with words.
|
||||
func (j *journal) has(from int, words string) bool {
|
||||
j.mu.Lock()
|
||||
defer j.mu.Unlock()
|
||||
return strings.Contains(j.text.String()[from:], words)
|
||||
}
|
||||
|
||||
// await returns once the journal holds, after from (mark), a line with words, and fails the test when none came within
|
||||
// bound.
|
||||
func (j *journal) await(t *testing.T, from int, words, what string, bound time.Duration) {
|
||||
@@ -1831,13 +1843,6 @@ func serveCatalog(t *testing.T, b *bed, nc *nats.Conn) {
|
||||
}
|
||||
t.Cleanup(func() { _ = sub.Unsubscribe() })
|
||||
}
|
||||
for _, subject := range []string{"mesh.seat.mesh-catalog.tool.revision", "mesh.seat.mesh-catalog.call.revision.*", "mesh.seat.mesh-catalog.tool.revision.*"} {
|
||||
sub, err := nc.Subscribe(subject, answer)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = sub.Unsubscribe() })
|
||||
}
|
||||
// The verb entry answers an entry by its fingerprint from every branch's half, and a fingerprint no half holds as not found,
|
||||
// as the seat's holder does: an entry the assigner asks for a form change is answered, never left asked (orderwaits.go).
|
||||
entry := func(m *nats.Msg) {
|
||||
@@ -1856,8 +1861,24 @@ func serveCatalog(t *testing.T, b *bed, nc *nats.Conn) {
|
||||
}
|
||||
_ = m.Respond([]byte(`{"error":"no catalog entry has the fingerprint ` + in.Fingerprint + `","node":"n0"}`))
|
||||
}
|
||||
for _, subject := range []string{"mesh.seat.mesh-catalog.tool.entry", "mesh.seat.mesh-catalog.call.entry.*"} {
|
||||
sub, err := nc.Subscribe(subject, entry)
|
||||
// A holder stopped answers each call as the bus does a subject nobody serves, no responders, and says it met one (b.cat.met).
|
||||
var down atomic.Bool
|
||||
b.cat.met = make(chan struct{}, 16)
|
||||
b.cat.stop = func() { down.Store(true) }
|
||||
b.cat.serve = func() { down.Store(false) }
|
||||
for subject, handler := range map[string]nats.MsgHandler{"mesh.seat.mesh-catalog.tool.revision": answer, "mesh.seat.mesh-catalog.call.revision.*": answer,
|
||||
"mesh.seat.mesh-catalog.tool.revision.*": answer, "mesh.seat.mesh-catalog.tool.entry": entry, "mesh.seat.mesh-catalog.call.entry.*": entry} {
|
||||
sub, err := nc.Subscribe(subject, func(m *nats.Msg) {
|
||||
if down.Load() {
|
||||
select {
|
||||
case b.cat.met <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
_ = m.RespondMsg(&nats.Msg{Header: nats.Header{"Status": []string{"503"}}})
|
||||
return
|
||||
}
|
||||
handler(m)
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -690,7 +690,11 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
run := &compositionRun{runs: runs, inputs: &compositionInputs{machines: w.machinesOf, callFile: bus.CallFileKept, bound: askBound}, keeper: inputs, reads: &compositionReads{}, call: bus.CallKept, callFile: bus.CallFileKept,
|
||||
readsBound, err := readsBoundSetting(getenv)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
run := &compositionRun{runs: runs, inputs: &compositionInputs{machines: w.machinesOf, callFile: bus.CallFileKept, bound: askBound}, keeper: inputs, reads: &compositionReads{}, call: bus.CallKeptAsk, callFile: bus.CallFileKept, readsBound: readsBound, holder: holderOf(bus, w), engineReads: reads,
|
||||
trunk: trunkOf(iv, w.trunkName), newest: iv.newestOf(), watched: iv.watchedOf, assigned: w.assignedOn, assignment: w.assignmentOf, findings: findings, running: w.runningOf, away: func(machine string) bool { return w.awayNow()[machine] }, put: runAskPublisher(js), own: ctx, ask: bus.CallFile, now: time.Now, logf: logger.Printf}
|
||||
// The seat's work queue (design 47 H2 §777): pulled through its one worker, each ask taken once in the state taken.
|
||||
takenBound, err := askTakenBound()
|
||||
@@ -720,7 +724,7 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
||||
_, err := meshhandactsclient.Recorder{Ask: bus.Call}.Record(q)
|
||||
return err
|
||||
}
|
||||
verbs := compositionVerbs(runs, steps, record)
|
||||
verbs := compositionVerbs(runs, steps, record, run)
|
||||
maps.Copy(verbs, dropVerb(steps)) // the seat's act drop (§778, H-A-404)
|
||||
if p.graph != nil {
|
||||
maps.Copy(verbs, keepNowVerb(ctx, p)) // the keeping by hand (§813 (2), H-A-417)
|
||||
@@ -862,6 +866,25 @@ func hearReadsChanged(ctx context.Context, js jetstream.JetStream, hub *process.
|
||||
}()
|
||||
}
|
||||
|
||||
// holderOf names the module holding a seat, asked of the seat that places modules (seatlist.HolderOf), and the machines whose
|
||||
// assignments place it, for the words of a read that met a fault (design 47 H2 H-A-708 (3)).
|
||||
func holderOf(bus caller, w *world) func(seat string) (string, []string) {
|
||||
return func(seat string) (string, []string) {
|
||||
module, err := seatlist.HolderOf(bus.Call, seat)
|
||||
if err != nil {
|
||||
return "", nil
|
||||
}
|
||||
var nodes []string
|
||||
for node, modules := range w.assigned() {
|
||||
if slices.Contains(modules, module) {
|
||||
nodes = append(nodes, node)
|
||||
}
|
||||
}
|
||||
slices.Sort(nodes)
|
||||
return module, nodes
|
||||
}
|
||||
}
|
||||
|
||||
// entriesOf are the catalog entries the passer asks by fingerprint: the followed branches' own, so each catalog-revision asks
|
||||
// again an entry whose ask failed to reach the holder, at most asks times (the setting entry-asks, 0 its default), and the
|
||||
// assigner's finding writer writes entry-not-found and entry-unanswered of them (design 47 H, H-A-60). Each change wakes a pass.
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/graph"
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
|
||||
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
|
||||
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||
|
||||
"mesh-delivery-assigner/internal/assign"
|
||||
@@ -60,8 +61,6 @@ type passer struct {
|
||||
whys map[string]string
|
||||
// findings is the assigner's findings bucket (its said conditions, ADR 0564 §2).
|
||||
findings assign.Findings
|
||||
// unplaced are the nodes whose unplaced finding this process wrote.
|
||||
unplaced map[string]bool
|
||||
// listed says whether a module's watched branches list it (catalogViews.listed), for the clear of assignment-unlisted.
|
||||
listed func(module string) bool
|
||||
// answeredAt is, by the id of a backup ask, how many values the have had when its answer was written into the want.
|
||||
@@ -252,6 +251,7 @@ func (p *passer) wants(ctx context.Context) {
|
||||
for name := range wanted {
|
||||
names[name] = true
|
||||
}
|
||||
unversioned := map[string]unversionedWant{}
|
||||
for name := range names {
|
||||
groups := p.groups(name, nodesOf[name], assignedBranches[name])
|
||||
for gi, g := range groups {
|
||||
@@ -264,6 +264,10 @@ func (p *passer) wants(ctx context.Context) {
|
||||
ReadsVersion: func(node string) bool {
|
||||
return slices.Contains(nodes.Reads[node], nodeengine.ManifestReadWordWantVersion)
|
||||
},
|
||||
// H-A-682 (2), H-A-698: a want's needs are those of its entry, the node's missing ones the want held for.
|
||||
MissingNeeds: func(node, fp string) ([]string, bool) {
|
||||
return p.missingNeeds(ctx, bv.trunk[name], nodes.Reads[node], fp)
|
||||
},
|
||||
// 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 != "" {
|
||||
@@ -279,6 +283,9 @@ func (p *passer) wants(ctx context.Context) {
|
||||
p.outsideReview(ctx, name, target.Fp, m.Nodes, bv.nodes, bv.manifests[name].ClaimsSeat(mcseat.Seat), p.movedTo(wanted, bv.nodes))
|
||||
}
|
||||
out := assign.Wants(m, wantedOf)
|
||||
for node, fp := range out.Unversioned {
|
||||
unversioned[assign.UnversionedKey(name, node)] = unversionedWant{module: name, node: node, fp: fp}
|
||||
}
|
||||
p.sayWhy(ctx, name, m.Nodes, wantWhy{Branch: g.branch, Fp: target.Fp, Version: target.Version, Pipeline: target.Pipeline, Step: whyStep(ok)}, wantedOf, &out)
|
||||
if ok {
|
||||
p.yeses(ctx, name, m, wantedOf, &out)
|
||||
@@ -288,6 +295,31 @@ func (p *passer) wants(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
p.unversionedFindings(unversioned, trunk)
|
||||
}
|
||||
|
||||
// missingNeeds reads what a want at fp lacks of its node's words (design 47 H2 H-A-682 (2), H-A-698): the needs of the entry at fp,
|
||||
// those of the module's held entry when it names fp, else the seat `mesh-catalog`'s `entry` for it, asked once and kept; read is
|
||||
// false while that ask stands out, is not found or is unanswered, and the answer wakes a pass. The pass never waits on it.
|
||||
func (p *passer) missingNeeds(ctx context.Context, held meshcatalog.ModulesByModuleValue, words []string, fp string) (missing []string, read bool) {
|
||||
needs := held.Needs
|
||||
if held.Fp2 != fp {
|
||||
if p.entries == nil {
|
||||
return nil, true
|
||||
}
|
||||
e, state := p.entries.Need(ctx, fp)
|
||||
if state != meshcatalogclient.EntryAnswered {
|
||||
return nil, false
|
||||
}
|
||||
needs = e.Needs
|
||||
}
|
||||
for _, need := range needs {
|
||||
if !slices.Contains(words, need) {
|
||||
missing = append(missing, need)
|
||||
}
|
||||
}
|
||||
slices.Sort(missing)
|
||||
return slices.Compact(missing), true
|
||||
}
|
||||
|
||||
// put writes one key of the assigner's own bucket; a write that fails is said and made again at the next pass.
|
||||
@@ -767,17 +799,37 @@ func chosenOf(chosen map[string]catalogue.PersonPolicy, module string) *catalogu
|
||||
return nil
|
||||
}
|
||||
|
||||
// findingKeys is the keys the assigner's findings bucket holds now; false when it cannot be read (no bucket, or a read that
|
||||
// failed, said), so that nothing is written or cleared from what was not read (H-A-722: a finding is cleared from what the bucket
|
||||
// holds, never from what a process remembers).
|
||||
func (p *passer) findingKeys(what string) (map[string]bool, bool) {
|
||||
if p.findings.Keys == nil || p.findings.Put == nil || p.findings.Delete == nil {
|
||||
return nil, false
|
||||
}
|
||||
ks, err := p.findings.Keys()
|
||||
if err != nil {
|
||||
p.logf("the findings are not read, so %s is not written or cleared in this pass: %v", what, err)
|
||||
return nil, false
|
||||
}
|
||||
have := make(map[string]bool, len(ks))
|
||||
for _, k := range ks {
|
||||
have[k] = true
|
||||
}
|
||||
return have, true
|
||||
}
|
||||
|
||||
// unplacedFindings writes, from the lease write, the finding `machine.<node>.unplaced` for each node that runs but no
|
||||
// assignments names, which gets no want (ADR 0571 §6), and deletes it once the node is placed.
|
||||
// assignments names, which gets no want (ADR 0571 §6), and deletes it at the pass that finds the node placed or gone: the
|
||||
// findings' keys are read from the bucket at each pass (H-A-722).
|
||||
func (p *passer) unplacedFindings() {
|
||||
if p.findings.Put == nil {
|
||||
have, ok := p.findingKeys("the finding unplaced")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
now := []string(p.w.unplacedNodes())
|
||||
is := map[string]bool{}
|
||||
for _, node := range now {
|
||||
for _, node := range p.w.unplacedNodes() {
|
||||
is[node] = true
|
||||
if p.unplaced[node] {
|
||||
if have[assign.UnplacedKey(node)] {
|
||||
continue
|
||||
}
|
||||
f, err := assign.UnplacedFinding(node, p.clock())
|
||||
@@ -786,23 +838,71 @@ func (p *passer) unplacedFindings() {
|
||||
}
|
||||
if err != nil {
|
||||
p.logf("the unplaced node %s is not said: %v", node, err)
|
||||
continue
|
||||
}
|
||||
if p.unplaced == nil {
|
||||
p.unplaced = map[string]bool{}
|
||||
}
|
||||
p.unplaced[node] = true
|
||||
}
|
||||
for node := range p.unplaced {
|
||||
if is[node] {
|
||||
for key := range have {
|
||||
node, found := unplacedOfKey(key)
|
||||
if !found || is[node] {
|
||||
continue
|
||||
}
|
||||
if err := p.findings.Delete(assign.UnplacedKey(node)); err == nil {
|
||||
delete(p.unplaced, node)
|
||||
if err := p.findings.Delete(key); err != nil {
|
||||
p.logf("the finding %s is not cleared: %v", key, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// unplacedOfKey is the node of an unplaced finding's key `machine.<node>.unplaced`, or false for another finding's.
|
||||
func unplacedOfKey(key string) (string, bool) {
|
||||
rest, ok := strings.CutPrefix(key, mcc.ScopeMachine+".")
|
||||
if !ok {
|
||||
return "", false
|
||||
}
|
||||
node, ok := strings.CutSuffix(rest, "."+assign.KindUnplaced)
|
||||
return node, ok && node != "" && assign.UnplacedKey(node) == key
|
||||
}
|
||||
|
||||
// unversionedWant is a want of no version for which no target is held, as a pass finds it (design 47 H2 H-A-673, H-A-706).
|
||||
type unversionedWant struct{ module, node, fp string }
|
||||
|
||||
// unversionedFindings writes the finding want-unversioned (id `<module>.<node>`) of each want a pass found with no version and no
|
||||
// target, naming its fingerprint and why no target is held, and clears, at the pass that finds its cause gone, each one the
|
||||
// bucket holds that the pass did not find: the want names a version, the module is no longer assigned to the node, or the node
|
||||
// is gone (H-A-722). Nothing is cleared while the trunk is unread.
|
||||
func (p *passer) unversionedFindings(found map[string]unversionedWant, trunk map[string]meshcatalog.ModulesByModuleValue) {
|
||||
have, ok := p.findingKeys("the finding want-unversioned")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
for key, u := range found {
|
||||
if have[key] {
|
||||
continue
|
||||
}
|
||||
f, err := assign.UnversionedFinding(u.module, u.node, u.fp, "no version of it released on its branch has a passed pipeline whose tier is written, and no placement names a build", p.clock())
|
||||
if err == nil {
|
||||
err = p.findings.Put(f)
|
||||
}
|
||||
if err != nil {
|
||||
p.logf("the finding want-unversioned of %s on %s is not written: %v", u.module, u.node, err)
|
||||
}
|
||||
}
|
||||
if len(trunk) == 0 {
|
||||
return
|
||||
}
|
||||
for key := range have {
|
||||
if _, _, is := assign.UnversionedOfKey(key); !is {
|
||||
continue
|
||||
}
|
||||
if _, still := found[key]; still {
|
||||
continue
|
||||
}
|
||||
if err := p.findings.Delete(key); err != nil {
|
||||
p.logf("the finding %s is not cleared: %v", key, err)
|
||||
continue
|
||||
}
|
||||
p.logf("the finding %s is cleared: its want names a version, or its module or its node is gone", key)
|
||||
}
|
||||
}
|
||||
|
||||
// clearUnlisted clears, in the pass over the assignments, each finding assignment-unlisted whose assignment is gone or whose module
|
||||
// one of its watched branches lists again, so the clear never waits for the next composition step on that machine (H-A-149).
|
||||
func (p *passer) clearUnlisted() {
|
||||
|
||||
@@ -7,11 +7,13 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
mpr "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
"git.novox.be/novox/mesh-sdk/go/busretry"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
"mesh-delivery-assigner/internal/buckets"
|
||||
"mesh-delivery-assigner/internal/puts"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -317,6 +319,9 @@ func (b *fakeBus) CallOn(node, key string, body any) (json.RawMessage, error) {
|
||||
return b.Call(node+"/"+key, body)
|
||||
}
|
||||
func (b *fakeBus) CallKept(key string, body any) (json.RawMessage, error) { return b.Call(key, body) }
|
||||
func (b *fakeBus) CallKeptAsk(_ process.KeptAsk, key string, body any) (json.RawMessage, error) {
|
||||
return b.Call(key, body)
|
||||
}
|
||||
func (b *fakeBus) CallFile(key string, body any) (json.RawMessage, error) { return b.Call(key, body) }
|
||||
func (b *fakeBus) CallFileKept(_ process.KeptAsk, key string, body any) (json.RawMessage, error) {
|
||||
return b.Call(key, body)
|
||||
@@ -1038,3 +1043,77 @@ func TestAnActingPartsNewVersionHoldsNoWant(t *testing.T) {
|
||||
t.Errorf("an acting part's version held the want: kept %v, said %v", waits.values, said)
|
||||
}
|
||||
}
|
||||
|
||||
// H-A-682 (2), H-A-698 (1), (2): the needs of a want are those of the module's held entry when it names the fingerprint, else those
|
||||
// the seat `mesh-catalog`'s `entry` answers; the pass never waits on that ask, the entry is not read while it is out, not found or
|
||||
// unanswered, and the answer wakes a pass.
|
||||
func TestAWantsNeedsAreReadFromItsEntryAndNeverWaitedFor(t *testing.T) {
|
||||
const held, older, gone, lost = "src2:held", "src2:older", "src2:gone", "src2:lost"
|
||||
words := []string{"want:version", "approval-mark/1"}
|
||||
answered := make(chan struct{}, 8)
|
||||
p := &passer{}
|
||||
p.entries = meshcatalogclient.NewEntries(func(_ string, body any) (json.RawMessage, error) {
|
||||
switch fp := body.(meshcatalog.EntryInput).Fingerprint; fp {
|
||||
case gone:
|
||||
return nil, &busretry.Answered{Words: "no entry"}
|
||||
case lost:
|
||||
return nil, errors.New("no responders")
|
||||
default:
|
||||
return json.Marshal(meshcatalog.EntryAnswer{Entry: meshcatalog.CatalogEntry{Module: "m", Fp: fp, Needs: []string{"directory-contents-owner", "approval-mark/1"}}})
|
||||
}
|
||||
})
|
||||
p.entries.Changed = func(meshcatalogclient.EntryRow) { answered <- struct{}{} }
|
||||
value := meshcatalog.ModulesByModuleValue{Fp2: held, Needs: []string{"want:version", "zeta", "approval-mark/1"}}
|
||||
ctx := context.Background()
|
||||
for _, c := range []struct {
|
||||
fp string
|
||||
missing []string
|
||||
read bool
|
||||
asked bool
|
||||
}{
|
||||
{held, []string{"zeta"}, true, false},
|
||||
{older, nil, false, true}, // asked: not read yet
|
||||
{older, []string{"directory-contents-owner"}, true, false}, // answered, and kept
|
||||
{gone, nil, false, true},
|
||||
{lost, nil, false, false}, // out and failed in transport: asked again at the next revision, its answer awaited by no pass
|
||||
} {
|
||||
missing, read := p.missingNeeds(ctx, value, words, c.fp)
|
||||
if !slices.Equal(missing, c.missing) || read != c.read {
|
||||
t.Errorf("%s: missing %v read %v, want %v %v", c.fp, missing, read, c.missing, c.read)
|
||||
}
|
||||
if c.asked {
|
||||
select {
|
||||
case <-answered:
|
||||
case <-time.After(10 * time.Second): // a bound on a failure only
|
||||
t.Fatalf("%s: the ask is never answered", c.fp)
|
||||
}
|
||||
}
|
||||
}
|
||||
if _, read := p.missingNeeds(ctx, value, words, gone); read {
|
||||
t.Error("an entry not found is read")
|
||||
}
|
||||
}
|
||||
|
||||
// H-A-698 (2): the why of a want held awaiting its entry names the ask: its state, how often it was asked again and its last failure.
|
||||
func TestTheWhyOfAWantAwaitingItsEntryNamesTheAsk(t *testing.T) {
|
||||
const fp = "src2:lost"
|
||||
kv := &memKV{values: map[string][]byte{}}
|
||||
p := &passer{kvs: map[string]jetstream.KeyValue{writtenBucket(): kv}}
|
||||
p.entries = meshcatalogclient.NewEntries(func(string, any) (json.RawMessage, error) { return nil, errors.New("no responders") })
|
||||
p.entries.Need(context.Background(), fp)
|
||||
deadline := time.Now().Add(10 * time.Second) // a bound on a failure only
|
||||
for len(p.entries.Rows()) == 0 || p.entries.Rows()[0].Detail == "" {
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatal("the ask never failed")
|
||||
}
|
||||
runtime.Gosched() // the ask runs on its own goroutine
|
||||
}
|
||||
held := mwc.Want{Fp: fp, Hold: true, Words: mwc.HoldAwaitsEntryPrefix + fp}
|
||||
p.sayWhy(context.Background(), "m", []string{"ace"}, wantWhy{Branch: "main", Fp: fp, Step: whyPassed}, nil, &assign.Outcome{Wants: map[string]mwc.Want{"ace": held}})
|
||||
raw, ok := kv.values[whyKey("ace", "m")]
|
||||
var got wantWhy
|
||||
if !ok || json.Unmarshal(raw, &got) != nil || got.Entry == nil || got.Entry.Fingerprint != fp || got.Entry.State != meshcatalogclient.EntryAsked ||
|
||||
!strings.Contains(got.Entry.Detail, "no responders") {
|
||||
t.Errorf("the why = %s, want the ask of %s named with its state and last failure", raw, fp)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,7 +360,7 @@ func (e *pipelineEnds) branchOf(module, placed string) string {
|
||||
|
||||
// writtenTools is the tool assigner_written: every key of the state written, with its end.
|
||||
func writtenTools(st store) []stdio.Tool {
|
||||
return []stdio.Tool{{Name: writtenTool, Description: "the pipeline ends the assigner's wants follow: per module and watched branch, the newest version released whose pipeline passed, with its pipeline and rank; per pipeline whose wants are written tier by tier, its tier progress (tier, since, movers); with why, why each want is what it is (as assigner_why).",
|
||||
return []stdio.Tool{{Name: writtenTool, Description: "the pipeline ends the assigner's wants follow: per module and watched branch, the newest version released whose pipeline passed, with its pipeline and rank; per pipeline whose wants are written tier by tier, its tier progress (tier, since, movers, and clock-from and paused-from: the time tier-bound counts from, and when a pause of the count by an ask of the operator began); with why, why each want is what it is (as assigner_why).",
|
||||
Input: schema(map[string]string{"why": "true: why each want is what it is", "module": "with why: a module's name", "node": "with why: a node's name"}, nil, "why"),
|
||||
Run: func(args map[string]any) (any, error) {
|
||||
if args["why"] == true || args["why"] == "true" {
|
||||
|
||||
@@ -43,6 +43,8 @@ type caller interface {
|
||||
CallOn(node, key string, body any) (json.RawMessage, error)
|
||||
// CallKept is Call for a kept call, safe to call again (process.Conn.CallKept; ADR 0668).
|
||||
CallKept(key string, body any) (json.RawMessage, error)
|
||||
// CallKeptAsk is CallKept stopping at its caller's bound and carrying the ask's id and hook (process.Conn.CallKeptAsk; H2 §775).
|
||||
CallKeptAsk(ask process.KeptAsk, key string, body any) (json.RawMessage, error)
|
||||
// CallFile is Call of a verb marked chunks, its answer read whole (process.Conn.CallFile; design 47 G A-291).
|
||||
CallFile(key string, body any) (json.RawMessage, error)
|
||||
// CallFileKept is CallFile as a kept call carrying its ask's id, until its bound (process.Conn.CallFileKept; H2 §775).
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||
"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"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/catalogkey"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
@@ -287,17 +288,68 @@ func TestTheSeatsVerbs(t *testing.T) {
|
||||
findings := map[string][]byte{}
|
||||
p := &passer{w: w, logf: func(string, ...any) {}, findings: assign.Findings{
|
||||
Put: putInto(findings),
|
||||
Keys: func() ([]string, error) { return slices.Collect(maps.Keys(findings)), nil },
|
||||
Delete: func(k string) error { delete(findings, k); return nil }}}
|
||||
p.unplacedFindings()
|
||||
if _, ok := findings[assign.UnplacedKey("g14")]; !ok || len(findings) != 1 {
|
||||
t.Fatalf("findings = %v", findings)
|
||||
}
|
||||
putAssignments(w, mma.Assignments{V: keys.Version, Node: "g14", Modules: []mma.PlacedModule{{Module: "web"}}})
|
||||
p.unplacedFindings()
|
||||
// A process that starts again knows nothing of what the first said: it clears the finding from the bucket (H-A-722).
|
||||
restarted := &passer{w: w, logf: func(string, ...any) {}, findings: p.findings}
|
||||
restarted.unplacedFindings()
|
||||
if len(findings) != 0 {
|
||||
t.Errorf("placed again: findings %v", findings)
|
||||
}
|
||||
})
|
||||
t.Run("H-A-673, H-A-706, H-A-722: want-unversioned is written, and cleared from the bucket by a pass after a restart", func(t *testing.T) {
|
||||
fp := meshcatalogclient.SourcePrefix2 + strings.Repeat("3", 64)
|
||||
wantsKV := &memKV{values: map[string][]byte{}}
|
||||
findings := map[string][]byte{}
|
||||
pass := func(version string, assigned ...string) *passer {
|
||||
p := newPasser(kvSet{buckets.Wants(): wantsKV, buckets.Asks(): &memKV{values: map[string][]byte{}}}, time.Now())
|
||||
p.publishWants = func(string, any, string) error { return nil }
|
||||
p.findings = assign.Findings{Put: putInto(findings), Keys: func() ([]string, error) { return slices.Collect(maps.Keys(findings)), nil },
|
||||
Delete: func(k string) error { delete(findings, k); return nil }}
|
||||
digest := strings.Repeat("4", 64)
|
||||
mod, _ := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: fp, Manifest: digest, Repository: "novox/web", Commit: strings.Repeat("1", 40), Path: meshcatalogclient.RootPath})
|
||||
putModuleRaw(p.w, trunkBranch, "web", mod)
|
||||
p.w.manifests[digest] = parsed{module: "web", manifest: catalogue.Manifest{Module: "web"}}
|
||||
if len(assigned) > 0 { // none: the node is gone, no assignments name it
|
||||
placeOn(t, p.w, "g14", assigned...)
|
||||
}
|
||||
raw, _ := mwc.EncodeWant(mwc.Want{Fp: fp, Version: version})
|
||||
key, _ := mwc.WantKey("g14", "web")
|
||||
wantsKV.values[key] = raw
|
||||
p.w.putEntry(buckets.Wants(), key, raw, 1, time.Now())
|
||||
return p
|
||||
}
|
||||
key := assign.UnversionedKey("web", "g14")
|
||||
pass("", "web").wants(context.Background())
|
||||
if _, ok := findings[key]; !ok || len(findings) != 1 {
|
||||
t.Fatalf("a want of no version and no target: findings %v", findings)
|
||||
}
|
||||
pass("", "web").wants(context.Background()) // a process that starts again: written once, and it stands
|
||||
if _, ok := findings[key]; !ok || len(findings) != 1 {
|
||||
t.Fatalf("a restarted pass changed the finding: %v", findings)
|
||||
}
|
||||
pass("1.0.0", "web").wants(context.Background()) // the want names a version now
|
||||
if len(findings) != 0 {
|
||||
t.Errorf("the want names a version: findings %v", findings)
|
||||
}
|
||||
pass("", "web").wants(context.Background())
|
||||
pass("", "other").wants(context.Background()) // the module is no longer assigned to the node
|
||||
if len(findings) != 0 {
|
||||
t.Errorf("the module is no longer assigned to the node: findings %v", findings)
|
||||
}
|
||||
if pass("", "web").wants(context.Background()); len(findings) != 1 {
|
||||
t.Fatalf("a want of no version again: findings %v", findings)
|
||||
}
|
||||
pass("").wants(context.Background()) // the node is gone: no assignments name it
|
||||
if len(findings) != 0 {
|
||||
t.Errorf("the node is gone: findings %v", findings)
|
||||
}
|
||||
})
|
||||
t.Run("1955/L7 (ADR 0571 §4): seat-holders is written from assignments, only the keys a change moves, and answered by assignments seats", func(t *testing.T) {
|
||||
writes := 0
|
||||
kv := &countingKV{memKV: memKV{values: map[string][]byte{}}, writes: &writes}
|
||||
|
||||
@@ -17,7 +17,9 @@ import (
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-assigner/asks"
|
||||
"mesh-delivery-assigner/internal/assign"
|
||||
"mesh-delivery-assigner/internal/buckets"
|
||||
)
|
||||
|
||||
// One pipeline's wants are written tier by tier (design 47 H §751, H-A-10, H-A-56): on a passed pipeline-ended the assigner
|
||||
@@ -55,6 +57,20 @@ type tierProgress struct {
|
||||
Since time.Time `json:"since"`
|
||||
Movers []tierMover `json:"movers"`
|
||||
Source int64 `json:"source,omitempty"`
|
||||
// ClockFrom is the time tier-bound counts from, in Since's form: Since when the progress starts, moved later by each
|
||||
// pause; absent reads as Since (design 47 H2 H-A-627).
|
||||
ClockFrom time.Time `json:"clock-from,omitzero"`
|
||||
// PausedFrom is the time the standing pause began: a key of the state asks names a mover of the tier that is not running,
|
||||
// and the count stands still. Absent while the bound counts (H-A-627).
|
||||
PausedFrom time.Time `json:"paused-from,omitzero"`
|
||||
}
|
||||
|
||||
// clockFrom is the time tier-bound counts from; Since in a progress kept before the field.
|
||||
func (t tierProgress) clockFrom() time.Time {
|
||||
if t.ClockFrom.IsZero() {
|
||||
return t.Since
|
||||
}
|
||||
return t.ClockFrom
|
||||
}
|
||||
|
||||
// tierKey is the key of pipeline's tier progress; pipeline is the runner's key `<branch>.<source>`, its branch escaped.
|
||||
@@ -87,7 +103,8 @@ func (e *pipelineEnds) startTiers(pipeline string, source int64, movers []tierMo
|
||||
for _, m := range movers {
|
||||
first = min(first, m.Tier)
|
||||
}
|
||||
t = tierProgress{Tier: first, Since: e.clock().UTC(), Source: source}
|
||||
at := e.clock().UTC()
|
||||
t = tierProgress{Tier: first, Since: at, ClockFrom: at, Source: source}
|
||||
}
|
||||
moved := false
|
||||
for i := range t.Movers {
|
||||
@@ -169,6 +186,14 @@ func (p *passer) tiers(n assign.Nodes, placedOn func(module, branch string) []st
|
||||
now := p.clock().UTC()
|
||||
bound := p.tierBoundOf()
|
||||
var next time.Time
|
||||
standing := p.w.read(buckets.Asks())
|
||||
followed := map[string]bool{}
|
||||
for _, key := range ks {
|
||||
if isTierKey(key) {
|
||||
followed[assign.KeyID(strings.TrimPrefix(key, tierPrefix))] = true
|
||||
}
|
||||
}
|
||||
defer p.clearTierLate(followed)
|
||||
for _, key := range ks {
|
||||
if !isTierKey(key) {
|
||||
continue
|
||||
@@ -185,13 +210,46 @@ func (p *passer) tiers(n assign.Nodes, placedOn func(module, branch string) []st
|
||||
break
|
||||
}
|
||||
notRunning := p.notRunning(n, placedOn, pipeline, branch, t, t.Tier)
|
||||
late := !now.Before(t.Since.Add(bound))
|
||||
// The count stands still while an ask of the operator names a mover of the tier that is not running (H-A-627): the first
|
||||
// pass that finds one writes paused-from, the first that finds none moves clock-from later by the time it stood still.
|
||||
clock := t.clockFrom()
|
||||
paused := pausedBy(standing, t, notRunning)
|
||||
if paused && t.PausedFrom.IsZero() && now.Before(clock.Add(bound)) {
|
||||
t.PausedFrom = now
|
||||
if now.Before(t.Since) {
|
||||
t.PausedFrom = t.Since // never earlier than the progress's own start
|
||||
}
|
||||
err := p.writeTier(key, t, rev, "paused-from")
|
||||
if err == nil {
|
||||
p.logf("pipeline %s: tier %d's count of tier-bound stands still: %s", pipeline, t.Tier, pauseNamed(standing, t, notRunning))
|
||||
}
|
||||
if err == nil || errors.Is(err, errSwapped) {
|
||||
continue // written, or a lost race: read the progress again
|
||||
}
|
||||
break // refused (said): reading it again would spin the pass
|
||||
}
|
||||
if !paused && !t.PausedFrom.IsZero() {
|
||||
held := now.Sub(t.PausedFrom)
|
||||
t.ClockFrom, t.PausedFrom = clock.Add(held), time.Time{}
|
||||
err := p.writeTier(key, t, rev, "clock-from")
|
||||
if err == nil {
|
||||
p.logf("pipeline %s: tier %d's count of tier-bound stood still for %s and goes on; the tier is late at %s", pipeline, t.Tier, held.Round(time.Second), t.ClockFrom.Add(bound).Format(time.RFC3339))
|
||||
}
|
||||
if err == nil || errors.Is(err, errSwapped) {
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
if !t.PausedFrom.IsZero() {
|
||||
break // paused: no lateness, and no timer armed
|
||||
}
|
||||
late := !now.Before(clock.Add(bound))
|
||||
if late {
|
||||
p.tierLate(pipeline, branch, number, t, notRunning)
|
||||
break
|
||||
}
|
||||
if len(notRunning) > 0 {
|
||||
if d := t.Since.Add(bound); next.IsZero() || d.Before(next) {
|
||||
if d := clock.Add(bound); next.IsZero() || d.Before(next) {
|
||||
next = d
|
||||
}
|
||||
break
|
||||
@@ -211,7 +269,7 @@ func (p *passer) tiers(n assign.Nodes, placedOn func(module, branch string) []st
|
||||
p.sayPipelineWanted(pipeline, branch, number, t.Source, meshwants.PipelineWantedOutcomeRunning, nil)
|
||||
break
|
||||
}
|
||||
value, err := json.Marshal(tierProgress{Tier: later, Since: now, Movers: t.Movers, Source: t.Source})
|
||||
value, err := json.Marshal(tierProgress{Tier: later, Since: now, ClockFrom: now, Movers: t.Movers, Source: t.Source})
|
||||
if err == nil {
|
||||
err = p.ends.st.swap(key, value, rev)
|
||||
}
|
||||
@@ -366,3 +424,85 @@ func tierBoundSetting(getenv func(string) string) (time.Duration, error) {
|
||||
// tierBoundUnit is the unit of the setting tier-bound, a minute; the whole test sets a shorter one, so a tier passes its bound
|
||||
// without a test waiting minutes.
|
||||
var tierBoundUnit = time.Minute
|
||||
|
||||
// writeTier swaps the tier progress at key by compare-and-set at rev; its error when it was not written: errSwapped for a lost race
|
||||
// (the caller reads the progress again), any other said (what field the write was for names it) and the caller goes on.
|
||||
func (p *passer) writeTier(key string, t tierProgress, rev uint64, field string) error {
|
||||
value, err := json.Marshal(t)
|
||||
if err == nil {
|
||||
err = p.ends.st.swap(key, value, rev)
|
||||
}
|
||||
if err != nil && !errors.Is(err, errSwapped) {
|
||||
p.logf("the tier progress %s is not written (%s): %v", key, field, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// pausingAsks are the keys of asks (the assigner's state asks, G §717) that pause the count of tier t of its pipeline: a key of
|
||||
// any kind but assignments that names a mover of the tier by its module, by the mover's fingerprint where the kind's key names
|
||||
// one (every kind but record, whose key names the composition), and, where it names a machine (every kind but hold), one of
|
||||
// the machines on which the mover is not running (H-A-627 (1)); sorted.
|
||||
func pausingAsks(standing map[string][]byte, t tierProgress, notRunning []meshwants.NotRunning) []string {
|
||||
var out []string
|
||||
for key := range standing {
|
||||
k, err := asks.ParseAnyAskKey(key)
|
||||
if err != nil || k.Kind == asks.AskKindAssignments || k.Module == "" {
|
||||
continue
|
||||
}
|
||||
for _, m := range t.Movers {
|
||||
if m.Tier != t.Tier || m.Module != k.Module || (k.Kind != asks.AskKindRecord && m.Fp != k.FP) {
|
||||
continue
|
||||
}
|
||||
if k.Kind == asks.AskKindHold || notRunningOn(notRunning, m.Module, k.Node) {
|
||||
out = append(out, key)
|
||||
}
|
||||
}
|
||||
}
|
||||
sort.Strings(out)
|
||||
return out
|
||||
}
|
||||
|
||||
func notRunningOn(notRunning []meshwants.NotRunning, module, node string) bool {
|
||||
return slices.ContainsFunc(notRunning, func(nr meshwants.NotRunning) bool { return nr.Module == module && slices.Contains(nr.Machines, node) })
|
||||
}
|
||||
|
||||
// pausedBy says whether an ask of the operator pauses tier t's count (pausingAsks).
|
||||
func pausedBy(standing map[string][]byte, t tierProgress, notRunning []meshwants.NotRunning) bool {
|
||||
return len(pausingAsks(standing, t, notRunning)) > 0
|
||||
}
|
||||
|
||||
// pauseNamed names the ask that pauses the count, for the journal: its key and the movers of the tier it names.
|
||||
func pauseNamed(standing map[string][]byte, t tierProgress, notRunning []meshwants.NotRunning) string {
|
||||
var named []string
|
||||
for _, key := range pausingAsks(standing, t, notRunning) {
|
||||
k, _ := asks.ParseAnyAskKey(key)
|
||||
named = append(named, fmt.Sprintf("the ask %s about %s on %s", key, k.Module, k.Node))
|
||||
}
|
||||
return strings.Join(named, "; ")
|
||||
}
|
||||
|
||||
// clearTierLate clears, at the pass that finds its pipeline no longer followed (no tier progress stands for it), each finding
|
||||
// tier-late the findings bucket holds, read from the bucket, never from what a process said (H-A-722). followed are the
|
||||
// pipelines' ids as a finding's key holds them.
|
||||
func (p *passer) clearTierLate(followed map[string]bool) {
|
||||
have, ok := p.findingKeys("the finding tier-late")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
for key := range have {
|
||||
rest, is := strings.CutPrefix(key, mcc.ScopeDelivery+".")
|
||||
if !is {
|
||||
continue
|
||||
}
|
||||
id, is := strings.CutSuffix(rest, "."+kindTierLate)
|
||||
if !is || followed[id] {
|
||||
continue
|
||||
}
|
||||
if err := p.findings.Delete(key); err != nil {
|
||||
p.logf("the finding %s is not cleared: %v", key, err)
|
||||
continue
|
||||
}
|
||||
delete(p.said, key+".raised")
|
||||
p.logf("the finding %s is cleared: its pipeline is no longer followed", key)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"maps"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -18,6 +21,7 @@ import (
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-assigner/asks"
|
||||
"mesh-delivery-assigner/internal/assign"
|
||||
"mesh-delivery-assigner/internal/buckets"
|
||||
)
|
||||
@@ -32,7 +36,10 @@ func TestAPipelinesWantsAreWrittenTierByTier(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
runs bool
|
||||
pipeline string
|
||||
}{{true, trunkBranch + ".5"}, {false, trunkBranch + ".5"}, {true, trunkBranch + ".5.again.2"}, {false, trunkBranch + ".5.again.2"}} {
|
||||
paused bool // H-A-627: the provider's record ask stands in asks from minute 5 to minute 45, and the count stands still
|
||||
held bool // H-A-682 (2), (4): the provider's entry needs a capability g14's node-engine does not state, so its want there is held
|
||||
}{{true, trunkBranch + ".5", false, false}, {false, trunkBranch + ".5", false, false}, {true, trunkBranch + ".5.again.2", false, false}, {false, trunkBranch + ".5.again.2", false, false},
|
||||
{true, trunkBranch + ".5", true, false}, {false, trunkBranch + ".5", true, false}, {false, trunkBranch + ".5", false, true}} {
|
||||
runs, pipeline := c.runs, c.pipeline
|
||||
start := time.Date(2026, 11, 20, 4, 0, 0, 0, time.UTC)
|
||||
now := start
|
||||
@@ -42,7 +49,10 @@ func TestAPipelinesWantsAreWrittenTierByTier(t *testing.T) {
|
||||
p.say = func(oc.Condition) error { return nil }
|
||||
findings := map[string]mcseat.Finding{}
|
||||
p.findings = assign.Findings{Put: func(f mcseat.Finding) error { findings[views.FindingKey(f.Scope, f.ID, f.Kind)] = f; return nil },
|
||||
Keys: func() ([]string, error) { return slices.Collect(maps.Keys(findings)), nil },
|
||||
Delete: func(key string) error { delete(findings, key); return nil }}
|
||||
// H-A-722: a tier-late of a pipeline no longer followed, written before a restart, is cleared at the first pass.
|
||||
findings["delivery.main.3.tier-late"] = mcseat.Finding{Scope: "delivery", ID: "main.3", Kind: kindTierLate}
|
||||
var said []meshwants.PipelineWanted
|
||||
p.publishWants = func(event string, body any, _ string) error {
|
||||
if b, ok := body.(meshwants.PipelineWantedEvent); ok {
|
||||
@@ -55,13 +65,26 @@ func TestAPipelinesWantsAreWrittenTierByTier(t *testing.T) {
|
||||
}
|
||||
for i, m := range []struct{ name, fp string }{{"db", db}, {"web", web}} {
|
||||
digest := strings.Repeat(string(rune('e'+i)), 64)
|
||||
mod, _ := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: m.fp, Manifest: digest, Repository: "novox/" + m.name, Commit: strings.Repeat("1", 40), Path: meshcatalogclient.RootPath})
|
||||
value := meshcatalog.ModulesByModuleValue{Fp2: m.fp, Manifest: digest, Repository: "novox/" + m.name, Commit: strings.Repeat("1", 40), Path: meshcatalogclient.RootPath}
|
||||
if c.held && m.name == "db" {
|
||||
value.Needs = []string{"directory-contents-owner"}
|
||||
}
|
||||
mod, _ := meshcatalogclient.EncodeModule(value)
|
||||
putModuleRaw(p.w, trunkBranch, m.name, mod)
|
||||
p.w.manifests[digest] = parsed{module: m.name, manifest: catalogue.Manifest{Module: m.name}}
|
||||
}
|
||||
placeOn(t, p.w, "g14", "db", "web")
|
||||
placeOn(t, p.w, "ace", "db", "web")
|
||||
p.w.heardPresence("ace", true, start) // away: not waited for
|
||||
if c.held { // both engines state want:version; neither states the capability db needs
|
||||
p.reads = &engineReadsKept{}
|
||||
for _, node := range []string{"g14", "ace"} {
|
||||
raw, _ := json.Marshal(engineWords{Words: []string{nodeengine.ManifestReadWordWantVersion}, At: start})
|
||||
if err := p.reads.take(node, raw, false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
p.w.mu.Lock()
|
||||
p.w.runningHeard = true
|
||||
p.w.mu.Unlock()
|
||||
@@ -80,15 +103,49 @@ func TestAPipelinesWantsAreWrittenTierByTier(t *testing.T) {
|
||||
return ok
|
||||
}
|
||||
p.wants(context.Background())
|
||||
if _, old := findings["delivery.main.3.tier-late"]; old {
|
||||
t.Errorf("%s: a tier-late of a pipeline no longer followed stands after a pass: %v", pipeline, findings)
|
||||
}
|
||||
if !wanted("g14", "db") || !wanted("ace", "db") || wanted("g14", "web") || wanted("ace", "web") {
|
||||
t.Fatalf("%s runs %v: tier 1 alone is not what is wanted first: %v", pipeline, runs, wantsKV.values)
|
||||
}
|
||||
if c.held {
|
||||
key, _ := mwc.WantKey("g14", "db")
|
||||
if w, err := mwc.DecodeWant(wantsKV.values[key]); err != nil || !w.Hold || w.Words != mwc.HoldAwaitsReadsPrefix+"directory-contents-owner" {
|
||||
t.Fatalf("%s: db's want on g14 is not held awaiting its reads: %+v (%v)", pipeline, w, err)
|
||||
}
|
||||
}
|
||||
runAt, lateBefore, lateAt := time.Minute, 29*time.Minute, 30*time.Minute
|
||||
if c.paused {
|
||||
runAt, lateBefore, lateAt = 50*time.Minute, 69*time.Minute, 70*time.Minute
|
||||
akey, err := asks.RecordAskKey("g14", "db", "sha256:"+strings.Repeat("a", 64))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
now = start.Add(5 * time.Minute)
|
||||
p.w.put(buckets.Asks(), akey, []byte(`{}`))
|
||||
p.wants(context.Background())
|
||||
now = start.Add(30 * time.Minute) // past tier-bound had the count not stood still
|
||||
p.wants(context.Background())
|
||||
if len(findings) != 0 || len(said) != 0 {
|
||||
t.Fatalf("%s: late at minute 30 while its provider's ask stands: %v, %+v", pipeline, findings, said)
|
||||
}
|
||||
if prog, _, _ := p.ends.tiersOf(pipeline); prog.PausedFrom.IsZero() || !prog.PausedFrom.Equal(start.Add(5*time.Minute)) {
|
||||
t.Fatalf("%s: the pause's start is not kept: %+v", pipeline, prog)
|
||||
}
|
||||
now = start.Add(45 * time.Minute)
|
||||
p.w.put(buckets.Asks(), akey, nil)
|
||||
p.wants(context.Background())
|
||||
if prog, _, _ := p.ends.tiersOf(pipeline); !prog.PausedFrom.IsZero() || !prog.ClockFrom.Equal(start.Add(40*time.Minute)) {
|
||||
t.Fatalf("%s: the pause's end does not move clock-from to minute 40: %+v", pipeline, prog)
|
||||
}
|
||||
}
|
||||
if runs {
|
||||
raw, _ := json.Marshal(nodeengine.Running{Node: "g14", Module: "db", Fingerprint: db})
|
||||
if err := p.w.hearRunning("running.g14.db", raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
now = start.Add(time.Minute)
|
||||
now = start.Add(runAt)
|
||||
p.wants(context.Background())
|
||||
if !wanted("g14", "web") || !wanted("ace", "web") {
|
||||
t.Fatalf("%s: the consumer's want is not written once its provider runs: %v", pipeline, wantsKV.values)
|
||||
@@ -104,12 +161,12 @@ func TestAPipelinesWantsAreWrittenTierByTier(t *testing.T) {
|
||||
}
|
||||
continue
|
||||
}
|
||||
now = start.Add(29 * time.Minute)
|
||||
now = start.Add(lateBefore)
|
||||
p.wants(context.Background())
|
||||
if len(findings) != 0 || len(said) != 0 {
|
||||
t.Fatalf("late before tier-bound: %v, %+v", findings, said)
|
||||
}
|
||||
now = start.Add(30 * time.Minute)
|
||||
now = start.Add(lateAt)
|
||||
p.wants(context.Background())
|
||||
p.wants(context.Background())
|
||||
f, ok := findings["delivery."+assign.KeyID(pipeline)+".tier-late"]
|
||||
@@ -213,3 +270,43 @@ func TestALateMoverHoldsItsTier(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// H-A-627 (2): a write of the tier progress that is refused (a full bucket), not lost to another writer, is said and not read
|
||||
// again within the pass: the pass would spin on the same progress for ever.
|
||||
func TestARefusedTierWriteDoesNotSpinThePass(t *testing.T) {
|
||||
start := time.Date(2026, 11, 20, 4, 0, 0, 0, time.UTC)
|
||||
for _, field := range []string{"paused-from", "clock-from"} {
|
||||
st := &refusingEnds{memEnds: newMemEnds(), t: t}
|
||||
p := newPasser(kvSet{buckets.Asks(): &memKV{values: map[string][]byte{}}}, start.Add(5*time.Minute))
|
||||
p.ends = newPipelineEnds(st, func() {}, func(string, ...any) {})
|
||||
prog := tierProgress{Tier: 1, Since: start, ClockFrom: start, Movers: []tierMover{{Module: "db", Fp: "fp", Tier: 1, NoVersion: true}}}
|
||||
if field == "clock-from" {
|
||||
prog.PausedFrom = start.Add(time.Minute) // the ask is gone: the pause ends
|
||||
} else if akey, err := asks.RecordAskKey("g14", "db", "sha256:"+strings.Repeat("a", 64)); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
p.w.put(buckets.Asks(), akey, []byte(`{}`))
|
||||
}
|
||||
raw, _ := json.Marshal(prog)
|
||||
st.vals[tierKey(trunkBranch+".5")], st.revs[tierKey(trunkBranch+".5")] = raw, 1
|
||||
p.tiers(assign.Nodes{Online: map[string]bool{}}, func(string, string) []string { return []string{"g14"} })
|
||||
if st.swaps != 1 {
|
||||
t.Errorf("%s: the refused write was made %d times in one pass", field, st.swaps)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// refusingEnds is memEnds whose every swap is refused for a cause other than a lost race; it fails the test on the third.
|
||||
type refusingEnds struct {
|
||||
*memEnds
|
||||
t *testing.T
|
||||
swaps int
|
||||
}
|
||||
|
||||
func (r *refusingEnds) swap(string, []byte, uint64) error {
|
||||
r.swaps++
|
||||
if r.swaps > 2 {
|
||||
r.t.Fatal("the pass reads the refused progress again and writes it again")
|
||||
}
|
||||
return errors.New("the bucket is full")
|
||||
}
|
||||
|
||||
@@ -409,6 +409,7 @@ func serveTools() error {
|
||||
tools = append(tools, wants.tools()...)
|
||||
keeper := &inputKeeper{vals: stateobjects.ForState(buckets.InputsState), now: time.Now, logf: func(string, ...any) {}}
|
||||
tools = append(tools, inputsRead(keeper), inputsDrop(keeper, stdio.Ask))
|
||||
tools = append(tools, validateTools(stdio.Ask)...) // judge a pipeline's candidate on request, through the seat mesh-wants' verb validate (H-A-727)
|
||||
tools = append(tools, compositionsTools(stdio.Ask)...) // the composition runs' read and drop, through their verbs (§728)
|
||||
tools = append(tools, viewTools(os.Getenv, keptSource, time.Now)...)
|
||||
// What each node's engine reads, as the assigner uses it: its own state engine-reads (design 47 H-A-104).
|
||||
|
||||
@@ -13,13 +13,17 @@ import (
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
ne "git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||
mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
meshcatalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
mpr "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/composer"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/graph"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
|
||||
"mesh-delivery-assigner/internal/buckets"
|
||||
@@ -124,7 +128,13 @@ func (r *compositionRun) judgeValidate(ctx context.Context, step meshwants.StepR
|
||||
if half.Revision.Base <= 0 {
|
||||
empty = emptyBeforeWords
|
||||
}
|
||||
if problems := causedProblems(v.Change, v.Before); len(problems) > 0 {
|
||||
// H-A-682 (5): the node-engine's own build is refused, never held; the run adds the problem to its verdict, for the mover's
|
||||
// manifest, so the run kept in composition-runs holds it and every step reads it as it reads the validator's.
|
||||
if needs := r.engineNeedProblems(half)[step.Module]; len(needs) > 0 {
|
||||
v = r.keepEngineNeeds(step, v, needs)
|
||||
}
|
||||
problems := causedProblems(v.Change, v.Before)
|
||||
if len(problems) > 0 {
|
||||
said := reasonManifestRefused + ": " + strings.Join(problems, "; ")
|
||||
if empty != "" {
|
||||
said += " (" + empty + ")"
|
||||
@@ -134,6 +144,105 @@ func (r *compositionRun) judgeValidate(ctx context.Context, step meshwants.StepR
|
||||
return stepOutcome{Outcome: meshwants.StepEndedOutcomePassed, Said: empty}
|
||||
}
|
||||
|
||||
// keepEngineNeeds adds needs, the problems of step's module, to the verdict the validate run of its revision keeps, as the refusal of
|
||||
// that module's manifest in the change case (none the verdict holds already), and answers the verdict as it is then; where the run
|
||||
// cannot be written, the verdict it was read as with them added, said in the journal.
|
||||
func (r *compositionRun) keepEngineNeeds(step meshwants.StepRun, read validateVerdict, needs []string) validateVerdict {
|
||||
add := func(v *validateVerdict) bool {
|
||||
m := v.Change.Manifests[step.Module]
|
||||
held := strings.Split(m.Refused, "\n")
|
||||
changed := false
|
||||
for _, p := range needs {
|
||||
if !slices.Contains(held, p) {
|
||||
held, changed = append(held, p), true
|
||||
}
|
||||
}
|
||||
if !changed {
|
||||
return false
|
||||
}
|
||||
m.Accepted, m.Refused = false, strings.Join(slices.DeleteFunc(held, func(p string) bool { return p == "" }), "\n")
|
||||
if v.Change.Manifests == nil {
|
||||
v.Change.Manifests = map[string]composer.ManifestRead{}
|
||||
}
|
||||
v.Change.Manifests[step.Module] = m
|
||||
return true
|
||||
}
|
||||
if !add(&read) {
|
||||
return read
|
||||
}
|
||||
key, err := validateKeyOf(step)
|
||||
if err == nil {
|
||||
_, _, err = r.runs.change(key, func(c *meshwants.CompositionRun) bool {
|
||||
var v validateVerdict
|
||||
if raw, e := json.Marshal(c.Verdict); e != nil || json.Unmarshal(raw, &v) != nil || !add(&v) {
|
||||
return false
|
||||
}
|
||||
verdict, e := v.asVerdict()
|
||||
if e != nil {
|
||||
return false
|
||||
}
|
||||
c.Verdict = verdict
|
||||
return true
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
r.logf("the validate run's verdict is not written with the problems of %s: %v", step.Module, err)
|
||||
}
|
||||
return read
|
||||
}
|
||||
|
||||
// engineNeedProblems are, by module, the problems of the revision's entries that claim the seat node-engine and need a reader capability
|
||||
// that no node's words in the state engine-reads hold: such an engine would be held on every machine and none could state it, so its
|
||||
// validate run refuses it (design 47 H2 H-A-682 (5)), counted as a new problem. None while no node's words are held.
|
||||
func (r *compositionRun) engineNeedProblems(half mcc.Half) map[string][]string {
|
||||
if r.engineReads == nil {
|
||||
return nil
|
||||
}
|
||||
var stated []string
|
||||
nodes := r.engineReads.nodes()
|
||||
for _, node := range nodes {
|
||||
words, _ := r.engineReads.words(node)
|
||||
stated = append(stated, words...)
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil
|
||||
}
|
||||
out := map[string][]string{}
|
||||
for module, e := range half.Entries {
|
||||
if !claimsSeat(e.Manifest, ne.Seat) {
|
||||
continue
|
||||
}
|
||||
for _, need := range e.Needs {
|
||||
if !slices.Contains(stated, need) {
|
||||
out[module] = append(out[module], "needs "+need+", which no node-engine states")
|
||||
}
|
||||
}
|
||||
slices.Sort(out[module])
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// claimsSeat says whether a manifest, as the catalog entry keeps it, claims the seat.
|
||||
func claimsSeat(manifest map[string]any, seat string) bool {
|
||||
raw, err := json.Marshal(manifest)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
var m struct {
|
||||
Claims []struct {
|
||||
Name string `json:"name"`
|
||||
} `json:"claims"`
|
||||
}
|
||||
if json.Unmarshal(raw, &m) != nil {
|
||||
return false
|
||||
}
|
||||
return slices.ContainsFunc(m.Claims, func(c struct {
|
||||
Name string `json:"name"`
|
||||
}) bool {
|
||||
return c.Name == seat
|
||||
})
|
||||
}
|
||||
|
||||
// emptyBeforeWords say, in a validate step's end, that its revision names no base: the branch's first take-in, judged against
|
||||
// an empty case before (H-A-151, H-A-154).
|
||||
const emptyBeforeWords = "the case before is empty: the revision names no base, the branch's first take-in"
|
||||
@@ -250,6 +359,7 @@ func manifestsOf(half mcc.Half) (map[string]composer.Manifest, error) {
|
||||
// is kept once in `inputs`, its program and input recorded on the run, and one run ask put on the Go build seat. A fault ends
|
||||
// the run could not run.
|
||||
func (r *compositionRun) startValidate(ctx context.Context, key string, run meshwants.CompositionRun, step meshwants.StepRun) {
|
||||
ctx = withReadsClock(ctx) // all the run's reads stop at one deadline (design 47 H2 H-A-708 (3))
|
||||
ask := run.Ask
|
||||
end := func(outcome, said string, verdict map[string]any) {
|
||||
if _, err := r.runs.endRun(key, ask, outcome, said, verdict); err != nil {
|
||||
@@ -438,7 +548,7 @@ const seatListKey = "seat:" + meshcatalog.Seat + "." + meshcatalog.VerbSeatList
|
||||
// seat-list hands, asked as a kept call under the run's ask.
|
||||
func (r *compositionRun) validateSeats(ctx context.Context, ask string, defs []meshcatalog.CatalogRevisionDefinitionsItem) ([]json.RawMessage, string, error) {
|
||||
if len(defs) == 0 {
|
||||
return r.seatList(ask)
|
||||
return r.seatList(ctx, ask)
|
||||
}
|
||||
sorted := slices.Clone(defs)
|
||||
slices.SortStableFunc(sorted, func(a, b meshcatalog.CatalogRevisionDefinitionsItem) int { return strings.Compare(a.Seat, b.Seat) })
|
||||
@@ -466,8 +576,12 @@ func seatListDigest(raw []byte) string {
|
||||
// seatList is the trunk's seat list as the verb seat-list hands it (H-A-443): its digest and size, then the object's bytes in
|
||||
// chunks; bytes whose size or sha256 is not the answer's, or that are no JSON array, are refused, so every run of one digest
|
||||
// judges the same bytes.
|
||||
func (r *compositionRun) seatList(ask string) ([]json.RawMessage, string, error) {
|
||||
func (r *compositionRun) seatList(ctx context.Context, ask string) ([]json.RawMessage, string, error) {
|
||||
what := "the trunk's seat list is not read through " + seatListKey
|
||||
left, bound, _ := r.readsLeft(readsClockOf(ctx))
|
||||
if left <= 0 {
|
||||
return nil, "", errors.New(what + ": the run's reads passed their deadline of " + bound.String() + " (the setting reads-bound)")
|
||||
}
|
||||
if r.callFile == nil {
|
||||
return nil, "", errors.New(what + ": the assigner holds no chunked call")
|
||||
}
|
||||
@@ -475,8 +589,11 @@ func (r *compositionRun) seatList(ask string) ([]json.RawMessage, string, error)
|
||||
if _, err := rand.Read(bits[:]); err != nil {
|
||||
return nil, "", fmt.Errorf("%s: %w", what, err)
|
||||
}
|
||||
raw, err := r.callFile(process.KeptAsk{ID: ask + "." + meshcatalog.VerbSeatList, Bound: readsBound}, seatListKey,
|
||||
id := readFindingID(seatListKey)
|
||||
r.waiting(id, +1)
|
||||
raw, err := r.callFile(process.KeptAsk{ID: ask + "." + meshcatalog.VerbSeatList, Bound: left, Hook: r.readHook}, seatListKey,
|
||||
meshcatalog.SeatListInput{Call: hex.EncodeToString(bits[:])})
|
||||
r.waiting(id, -1)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("%s: %w", what, err)
|
||||
}
|
||||
@@ -504,3 +621,203 @@ func (r *compositionRun) seatList(ask string) ([]json.RawMessage, string, error)
|
||||
}
|
||||
return list, a.Digest, nil
|
||||
}
|
||||
|
||||
// validateTool is the tool that judges a pipeline's candidate on request (design 47 H2 H-A-684, H-A-702, H-A-727).
|
||||
const validateTool = "assigner_validate"
|
||||
|
||||
// showKey is the seat mesh-pipeline-runner's verb show, which names a pipeline's candidate (H-A-684 (1), H-A-739).
|
||||
const showKey = "seat:" + mpr.Seat + "." + mpr.VerbShow
|
||||
|
||||
// validateVerbKey is the seat mesh-wants' verb validate, answered by the assigner's process, which keeps the runs (H-A-727).
|
||||
const validateVerbKey = "seat:" + meshwants.Seat + "." + meshwants.VerbValidate
|
||||
|
||||
// validateOnRequest is the process's answer of the seat mesh-wants' verb validate: it reads the pipeline's candidate from the runner's
|
||||
// `show` (H-A-739), answers at once, starting nothing, a pipeline the runner does not know and a candidate the indexer does not
|
||||
// hold; for a run that has ended it answers its verdict, narrowed by the module; otherwise it records the hand act through the seat
|
||||
// mesh-hand-acts with its why (H-A-702) and joins or starts the run `<pipeline>.validate` as the step does (H-A-684 (1), H-A-727),
|
||||
// and answers the run as it stands.
|
||||
func (r *compositionRun) validateOnRequest(ctx context.Context, record func(meshhandactsclient.Request) error, caller string, in meshwants.ValidateInput) (meshwants.ValidateAnswer, error) {
|
||||
why, pipeline := strings.TrimSpace(in.Why), strings.TrimSpace(in.Pipeline)
|
||||
if pipeline == "" || why == "" {
|
||||
return meshwants.ValidateAnswer{}, errors.New("name the pipeline and why its candidate is judged")
|
||||
}
|
||||
couldNot := func(words string) (meshwants.ValidateAnswer, error) {
|
||||
return meshwants.ValidateAnswer{Outcome: meshwants.ValidateAnswerOutcomeCouldNotRun, Why: words}, nil
|
||||
}
|
||||
body, said, err := r.callRead(withReadsClock(ctx), showKey, mpr.ShowInput{Pipeline: pipeline, Bound: 4096})
|
||||
if err != nil {
|
||||
return couldNot("the runner's show of " + pipeline + " is not read: " + err.Error())
|
||||
}
|
||||
if body == nil {
|
||||
return couldNot("the runner knows no pipeline " + pipeline + ": " + said)
|
||||
}
|
||||
var shown mpr.ShowAnswer
|
||||
if err := json.Unmarshal(body, &shown); err != nil || shown.Pipeline.Pipeline == "" {
|
||||
return couldNot("the runner's show of " + pipeline + " names no pipeline")
|
||||
}
|
||||
p := shown.Pipeline
|
||||
step := meshwants.StepRun{Pipeline: pipeline, Branch: p.Branch, Revision: p.Revision, Run: p.Run, Source: p.Source, Module: strings.TrimSpace(in.Module),
|
||||
Step: meshwants.StepRunStepValidate}
|
||||
candidate, err := candidateKeyOf(step)
|
||||
if err != nil {
|
||||
return couldNot("the pipeline " + pipeline + " names no candidate: " + err.Error())
|
||||
}
|
||||
if in.Candidate != "" && in.Candidate != candidate {
|
||||
return couldNot(fmt.Sprintf("the candidate %s is not the pipeline %s's, %s", in.Candidate, pipeline, candidate))
|
||||
}
|
||||
half, err := r.revision(withReadsClock(ctx), step)
|
||||
if err != nil {
|
||||
return couldNot(fmt.Sprintf("the indexer holds no candidate %s of the pipeline %s: %v", candidate, pipeline, err))
|
||||
}
|
||||
key, err := validateKeyOf(step)
|
||||
if err != nil {
|
||||
return couldNot(err.Error())
|
||||
}
|
||||
run, _, ok, err := r.runs.read(key)
|
||||
if err != nil {
|
||||
return meshwants.ValidateAnswer{}, err
|
||||
}
|
||||
if !ok || run.Ended == nil {
|
||||
if err := record(meshhandactsclient.Request{What: meshwants.VerbValidate + " " + key, Why: why + " (" + caller + ")", Cause: "validate"}); err != nil {
|
||||
return meshwants.ValidateAnswer{}, fmt.Errorf("the hand act was not recorded, so no run was started: %w", err)
|
||||
}
|
||||
now := r.now().UTC()
|
||||
reader := readerOf("validate."+buildstep.NewID(), step)
|
||||
reader.Ended = &now // a reader of a hand act owes no step end; the run's later steps join it
|
||||
j, err := r.runs.joinAt(key, reader, candidate, "", buildstep.NewID())
|
||||
if err != nil {
|
||||
return meshwants.ValidateAnswer{}, fmt.Errorf("the validate run %s is not joined: %w", key, err)
|
||||
}
|
||||
if j.started {
|
||||
go r.startValidate(r.own, key, j.run, step)
|
||||
}
|
||||
if run, _, ok, err = r.runs.read(key); err != nil || !ok {
|
||||
run = j.run
|
||||
}
|
||||
}
|
||||
run.Key = key
|
||||
return validateAnswerOf(run, step.Module, r.engineNeedProblems(half))
|
||||
}
|
||||
|
||||
// validateAnswerOf is the validate run as it stands: running with its start, or its end: passed, failed `cycle` naming the
|
||||
// cycle, failed `manifest-refused` with every problem per manifest (those the case before holds too marked), or could not run with
|
||||
// why; the problems narrowed to module when one is named (H-A-684 (1)).
|
||||
func validateAnswerOf(run meshwants.CompositionRun, module string, engine map[string][]string) (meshwants.ValidateAnswer, error) {
|
||||
out := meshwants.ValidateAnswer{Run: &run}
|
||||
if run.Ended == nil {
|
||||
out.Outcome, out.Started = meshwants.ValidateAnswerOutcomeRunning, run.Started
|
||||
return out, nil
|
||||
}
|
||||
if run.Outcome != meshwants.CompositionRunOutcomePassed {
|
||||
out.Outcome, out.Why = meshwants.ValidateAnswerOutcomeCouldNotRun, run.Said
|
||||
return out, nil
|
||||
}
|
||||
var v validateVerdict
|
||||
if raw, err := json.Marshal(run.Verdict); err != nil || json.Unmarshal(raw, &v) != nil {
|
||||
out.Outcome, out.Why = meshwants.ValidateAnswerOutcomeCouldNotRun, "the validate run's verdict does not read"
|
||||
return out, nil
|
||||
}
|
||||
if len(v.Cycle) > 0 {
|
||||
out.Outcome, out.Reason = meshwants.ValidateAnswerOutcomeFailed, meshwants.ValidateAnswerReasonCycle
|
||||
for _, a := range v.Cycle {
|
||||
out.Cycle = append(out.Cycle, string(a))
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
counted := false
|
||||
for _, name := range slices.Sorted(maps.Keys(v.Change.Manifests)) {
|
||||
read := v.Change.Manifests[name]
|
||||
if read.Accepted || read.Refused == "" || (module != "" && name != module) {
|
||||
continue
|
||||
}
|
||||
held := map[string]bool{}
|
||||
for _, p := range strings.Split(v.Before.Manifests[name].Refused, "\n") {
|
||||
held[p] = true
|
||||
}
|
||||
for _, p := range strings.Split(read.Refused, "\n") {
|
||||
if p != "" {
|
||||
out.Problems = append(out.Problems, meshwants.ValidateAnswerProblemsItem{Module: name, Problem: p, Before: held[p]})
|
||||
counted = counted || !held[p]
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, name := range slices.Sorted(maps.Keys(engine)) { // H-A-682 (5): a node-engine's needs no node-engine states
|
||||
if module != "" && name != module {
|
||||
continue
|
||||
}
|
||||
for _, p := range engine[name] {
|
||||
if slices.ContainsFunc(out.Problems, func(q meshwants.ValidateAnswerProblemsItem) bool { return q.Module == name && q.Problem == p }) {
|
||||
continue // the run's verdict holds it already
|
||||
}
|
||||
out.Problems = append(out.Problems, meshwants.ValidateAnswerProblemsItem{Module: name, Problem: p})
|
||||
counted = true
|
||||
}
|
||||
}
|
||||
out.Outcome = meshwants.ValidateAnswerOutcomePassed
|
||||
if counted {
|
||||
out.Outcome, out.Reason = meshwants.ValidateAnswerOutcomeFailed, meshwants.ValidateAnswerReasonManifestRefused
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// validateTools is the module's tool assigner_validate: it reads the pipeline's candidate from the seat mesh-pipeline-runner's `show`
|
||||
// (answering a pipeline the runner does not know, starting nothing), then calls the seat mesh-wants' verb validate, which the
|
||||
// process answers; it writes no state and answers what the verb answers (H-A-727).
|
||||
func validateTools(ask func(string, any) (json.RawMessage, error)) []stdio.Tool {
|
||||
return []stdio.Tool{{Name: validateTool, Description: "Judge a manifest on request (design 47 H2 H-A-684, H-A-702): the manifest validator's verdict " +
|
||||
"on a pipeline's candidate, a delivering pipeline's or a run on request's, the one revision's manifests together. It joins or starts the " +
|
||||
"validate run `<pipeline>.validate` as the step does, so the pipeline's own validate step joins it, recorded as a hand act with why, " +
|
||||
"and answers at once the run as it stands: running, passed, failed (cycle, or manifest-refused with every problem per manifest, those " +
|
||||
"the case before holds too marked) or could-not-run. A pipeline the runner does not know, or a candidate the indexer does not hold, " +
|
||||
"is answered so and starts nothing; a run on request's later steps run until its cancel.",
|
||||
Input: schema(map[string]string{"pipeline": "the pipeline's key as the runner names it", "module": "narrows the answer to one module's manifest", "why": "why the candidate is judged, kept in the hand act"},
|
||||
[]string{"pipeline", "why"}),
|
||||
Run: func(args map[string]any) (any, error) {
|
||||
pipeline, why := strings.TrimSpace(arg(args, "pipeline")), strings.TrimSpace(arg(args, "why"))
|
||||
if pipeline == "" || why == "" {
|
||||
return nil, errors.New("name the pipeline and why its candidate is judged")
|
||||
}
|
||||
body, said, err := unwrapAnswer(ask(showKey, mpr.ShowInput{Pipeline: pipeline, Bound: 4096}))
|
||||
if err != nil || body == nil {
|
||||
return meshwants.ValidateAnswer{Outcome: meshwants.ValidateAnswerOutcomeCouldNotRun, Why: "the runner knows no pipeline " + pipeline + ": " + orWords(said, err)}, nil
|
||||
}
|
||||
var shown mpr.ShowAnswer
|
||||
if err := json.Unmarshal(body, &shown); err != nil || shown.Pipeline.Pipeline == "" {
|
||||
return meshwants.ValidateAnswer{Outcome: meshwants.ValidateAnswerOutcomeCouldNotRun, Why: "the runner's show of " + pipeline + " names no pipeline"}, nil
|
||||
}
|
||||
p := shown.Pipeline
|
||||
candidate, err := candidateKeyOf(meshwants.StepRun{Branch: p.Branch, Revision: p.Revision, Run: p.Run})
|
||||
if err != nil {
|
||||
return meshwants.ValidateAnswer{Outcome: meshwants.ValidateAnswerOutcomeCouldNotRun, Why: "the pipeline " + pipeline + " names no candidate: " + err.Error()}, nil
|
||||
}
|
||||
raw, err := ask(validateVerbKey, meshwants.ValidateInput{Pipeline: pipeline, Candidate: candidate, Module: strings.TrimSpace(arg(args, "module")), Why: why})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var out any
|
||||
if err := json.Unmarshal(raw, &out); err != nil {
|
||||
return nil, fmt.Errorf("validate answered what is not JSON: %w", err)
|
||||
}
|
||||
return out, nil
|
||||
}}}
|
||||
}
|
||||
|
||||
// unwrapAnswer reads a verb's answer as a tool call gave it: the body of a good answer, else the holder's words; err when the call
|
||||
// failed.
|
||||
func unwrapAnswer(raw json.RawMessage, err error) (json.RawMessage, string, error) {
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
body, said, ok := buscalls.Unwrap(raw)
|
||||
if !ok {
|
||||
return nil, said, nil
|
||||
}
|
||||
return body, "", nil
|
||||
}
|
||||
|
||||
func orWords(said string, err error) string {
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
return said
|
||||
}
|
||||
|
||||
@@ -11,9 +11,11 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||
mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
builds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
meshcatalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
mpr "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/composer"
|
||||
@@ -64,9 +66,24 @@ func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) {
|
||||
}
|
||||
return b
|
||||
}
|
||||
// The runner's show of each pipeline it knows (H-A-739): a delivering pipeline's, a run on request's, and one whose candidate the
|
||||
// indexer holds not.
|
||||
shown := map[string]mpr.Pipeline{
|
||||
"main.12": {Pipeline: "main.12", Branch: "main", Revision: 12, Source: 12},
|
||||
"main.run.r1": {Pipeline: "main.run.r1", Branch: "main", Revision: 7, Run: "r1"},
|
||||
"main.50": {Pipeline: "main.50", Branch: "main", Revision: 50, Source: 50},
|
||||
}
|
||||
call := func(key string, body any) (json.RawMessage, error) {
|
||||
raw, _ := json.Marshal(body)
|
||||
switch key {
|
||||
case showKey:
|
||||
var in mpr.ShowInput
|
||||
_ = json.Unmarshal(raw, &in)
|
||||
p, ok := shown[in.Pipeline]
|
||||
if !ok {
|
||||
return json.Marshal(map[string]string{"error": "no pipeline " + in.Pipeline})
|
||||
}
|
||||
return json.Marshal(mpr.ShowAnswer{Pipeline: p})
|
||||
case mcc.RevisionVerb:
|
||||
var in meshcatalog.RevisionInput
|
||||
_ = json.Unmarshal(raw, &in)
|
||||
@@ -128,7 +145,7 @@ func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
r := &compositionRun{runs: runs, keeper: keeper, reads: &compositionReads{}, call: call, callFile: callFile, own: context.Background(), now: time.Now, logf: t.Logf,
|
||||
r := &compositionRun{runs: runs, keeper: keeper, reads: &compositionReads{}, call: asKept(call), callFile: callFile, own: context.Background(), now: time.Now, logf: t.Logf,
|
||||
put: func(_ context.Context, a buildstep.StepAsk) error {
|
||||
body, err := keeper.body(a.Run.Input.Digest)
|
||||
if err != nil {
|
||||
@@ -234,7 +251,7 @@ func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) {
|
||||
{"an empty list", listAnswer([]byte(`[]`), seatListDigest([]byte(`[]`)), 2)},
|
||||
} {
|
||||
listed = row.answer
|
||||
if seats, digest, err := r.seatList("ask-row"); err == nil || !strings.Contains(err.Error(), seatListKey) {
|
||||
if seats, digest, err := r.seatList(context.Background(), "ask-row"); err == nil || !strings.Contains(err.Error(), seatListKey) {
|
||||
t.Errorf("%s: the seat list read %s %s, %v; want it refused, naming the verb", row.name, digest, seats, err)
|
||||
}
|
||||
}
|
||||
@@ -276,12 +293,131 @@ func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) {
|
||||
key, _ := validateKeyOf(step("web", 14))
|
||||
run := runs.awaitEach(ctx, []string{key}, nil)[key]
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if run.Ended == nil || run.Outcome != meshwants.CompositionRunOutcomePassed || len(asks) != 5 || asks[4].Packages["git.novox.be/novox/mesh-sdk/go"] != "v0.1.36" {
|
||||
t.Errorf("the validate run its starting step left ended %v %s %q with %d validator asks, want it put after the publish and passed", run.Ended, run.Outcome, run.Said, len(asks))
|
||||
}
|
||||
mu.Unlock()
|
||||
if len(held) < 2 || !strings.HasPrefix(held[len(held)-2], waitOnPublish+"git.novox.be/novox/mesh-sdk/go (") ||
|
||||
!strings.HasPrefix(held[len(held)-1], waitOnBuildNode+" (") || !strings.HasSuffix(held[len(held)-1], ".held.put)") {
|
||||
t.Errorf("the validate run's reader was said waiting %v; want mesh-sdk's publish, then a build node again at the put (H-A-632)", held)
|
||||
}
|
||||
|
||||
// H2 H-A-682 (5) (A4): a mover claiming the seat node-engine whose entry needs a capability no node's words hold ends
|
||||
// manifest-refused naming it, counted as new; one that a node states is not refused for it; the verb's answer lists it.
|
||||
engine := meshcatalog.CatalogEntry{Module: "engine", Fp: "src2:eng", Needs: []string{"directory-contents-owner"}, ManifestDigest: "d-eng",
|
||||
Manifest: map[string]any{"module": "engine", "claims": []any{map[string]any{"name": "node-engine"}}}}
|
||||
revisions[15], revisions[16] = []meshcatalog.CatalogEntry{indexer, engine}, []meshcatalog.CatalogEntry{indexer, engine}
|
||||
engineStep := func(revision int64) meshwants.StepRun {
|
||||
return meshwants.StepRun{Step: meshwants.StepRunStepValidate, Pipeline: "main." + string(rune('0'+revision)), Branch: "main", Module: "engine", Revision: revision, Source: revision}
|
||||
}
|
||||
r.engineReads = &engineReadsKept{by: map[string]engineWords{"ace": {Words: []string{"want:version"}}}}
|
||||
if o := r.validate(ctx, "ask-engine", engineStep(15)); o.Outcome != meshwants.StepEndedOutcomeFailed || !strings.HasPrefix(o.Said, reasonManifestRefused+": ") ||
|
||||
!strings.Contains(o.Said, "engine: needs directory-contents-owner, which no node-engine states") {
|
||||
t.Errorf("a node-engine needing what no node states ended %+v", o)
|
||||
}
|
||||
// The run kept in composition-runs holds the problem in its verdict, for the mover's manifest (H-A-682 (5)).
|
||||
if k, _ := validateKeyOf(engineStep(15)); true {
|
||||
kept, _, _, _ := r.runs.read(k)
|
||||
var v validateVerdict
|
||||
raw, _ := json.Marshal(kept.Verdict)
|
||||
if json.Unmarshal(raw, &v) != nil || v.Change.Manifests["engine"].Accepted || !strings.Contains(v.Change.Manifests["engine"].Refused, "needs directory-contents-owner, which no node-engine states") {
|
||||
t.Errorf("the kept validate run's verdict is %+v, want the engine's manifest refused for its need", kept.Verdict)
|
||||
}
|
||||
}
|
||||
r.engineReads = &engineReadsKept{by: map[string]engineWords{"ace": {Words: []string{"want:version"}}, "g14": {Words: []string{"directory-contents-owner"}}}}
|
||||
if o := r.validate(ctx, "ask-engine-2", engineStep(16)); strings.Contains(o.Said, "which no node-engine states") {
|
||||
t.Errorf("a node-engine needing what g14 states ended %+v", o)
|
||||
}
|
||||
ended := time.Now()
|
||||
passed := meshwants.CompositionRun{Started: &ended, Ended: &ended, Outcome: meshwants.CompositionRunOutcomePassed, Verdict: map[string]any{}}
|
||||
if a, _ := validateAnswerOf(passed, "", map[string][]string{"engine": {"needs directory-contents-owner, which no node-engine states"}}); a.Outcome != meshwants.ValidateAnswerOutcomeFailed ||
|
||||
len(a.Problems) != 1 || a.Problems[0].Before || a.Problems[0].Module != "engine" {
|
||||
t.Errorf("the verb's answer for a node-engine needing what none states is %+v", a)
|
||||
}
|
||||
// H2 H-A-684, H-A-702, H-A-727, H-A-739 (A5): the verb validate, which the tool assigner_validate calls, joins or starts the run.
|
||||
var acts []meshhandactsclient.Request
|
||||
record := func(q meshhandactsclient.Request) error { acts = append(acts, q); return nil }
|
||||
onRequest := func(pipeline, module, why string) meshwants.ValidateAnswer {
|
||||
t.Helper()
|
||||
a, err := r.validateOnRequest(ctx, record, "op@shanks", meshwants.ValidateInput{Pipeline: pipeline, Module: module, Why: why})
|
||||
if err != nil {
|
||||
t.Fatalf("validate of %s: %v", pipeline, err)
|
||||
}
|
||||
return a
|
||||
}
|
||||
if _, err := r.validateOnRequest(ctx, record, "op", meshwants.ValidateInput{Pipeline: "main.12"}); err == nil || len(acts) != 0 {
|
||||
t.Errorf("a call with no why is not refused (%v), or recorded %d hand acts", err, len(acts))
|
||||
}
|
||||
mu.Lock()
|
||||
asked := len(asks)
|
||||
mu.Unlock()
|
||||
if a := onRequest("main.12", "", "judge the fix before its merge"); a.Outcome != meshwants.ValidateAnswerOutcomeRunning || a.Started == nil || len(acts) != 1 ||
|
||||
!strings.Contains(acts[0].What, "main.12"+validateKeySuffix) || !strings.Contains(acts[0].Why, "judge the fix before its merge (op@shanks)") {
|
||||
t.Errorf("a pipeline with no validate run answered %+v after %d hand acts %+v", a, len(acts), acts)
|
||||
}
|
||||
// The pipeline's own validate step joins that run: no second manifest validator is asked.
|
||||
if o := r.validate(ctx, "ask-web-12", meshwants.StepRun{Step: meshwants.StepRunStepValidate, Pipeline: "main.12", Branch: "main", Module: "web", Revision: 12, Source: 12}); o.Outcome != meshwants.StepEndedOutcomeFailed || len(asks) != asked+1 {
|
||||
t.Errorf("the step after the call ended %+v with %d validator asks, want one for the call and the step", o, len(asks)-asked)
|
||||
}
|
||||
// On an ended run it starts nothing, records none and answers its verdict, narrowed by the module.
|
||||
got := onRequest("main.12", "web", "again")
|
||||
if got.Outcome != meshwants.ValidateAnswerOutcomeFailed || got.Reason != meshwants.ValidateAnswerReasonManifestRefused || len(acts) != 1 || len(asks) != asked+1 ||
|
||||
len(got.Problems) != 2 || got.Problems[0].Module != "web" || got.Problems[0].Before || got.Problems[1].Problem != "an inherited problem" || !got.Problems[1].Before {
|
||||
t.Errorf("an ended run answered %+v after %d hand acts and %d asks", got, len(acts), len(asks)-asked)
|
||||
}
|
||||
// An unknown pipeline and a candidate the indexer does not hold are answered so, and start nothing.
|
||||
for _, pipeline := range []string{"main.99", "main.50"} {
|
||||
if a := onRequest(pipeline, "", "why"); a.Outcome != meshwants.ValidateAnswerOutcomeCouldNotRun || a.Why == "" || len(acts) != 1 || len(asks) != asked+1 {
|
||||
t.Errorf("%s answered %+v after %d hand acts, %d asks", pipeline, a, len(acts), len(asks)-asked)
|
||||
}
|
||||
}
|
||||
// H-A-739: a run on request's candidate (run-r1) is judged at the revision show names, 7.
|
||||
if a := onRequest("main.run.r1", "", "judge the run's members"); a.Outcome != meshwants.ValidateAnswerOutcomeRunning || len(acts) != 2 {
|
||||
t.Errorf("a run on request answered %+v after %d hand acts", a, len(acts))
|
||||
}
|
||||
if run, _, ok, _ := runs.read("main.run.r1" + validateKeySuffix); !ok || run.Candidate != "run-r1" {
|
||||
t.Errorf("the run on request's validate run is %+v (kept %v), want its candidate run-r1", run, ok)
|
||||
}
|
||||
}
|
||||
|
||||
// H-A-684 (1), H-A-727, H-A-739: the tool reads the runner's show for the candidate and calls the seat mesh-wants' verb validate with
|
||||
// it, answering what the verb answers; a pipeline the runner does not know is answered so with no verb called, and a call with no
|
||||
// why is refused.
|
||||
func TestTheToolValidateReadsTheCandidateAndCallsTheVerb(t *testing.T) {
|
||||
var verbs []meshwants.ValidateInput
|
||||
ask := func(key string, body any) (json.RawMessage, error) {
|
||||
raw, _ := json.Marshal(body)
|
||||
switch key {
|
||||
case showKey:
|
||||
var in mpr.ShowInput
|
||||
_ = json.Unmarshal(raw, &in)
|
||||
if in.Pipeline == "main.12" {
|
||||
return json.Marshal(mpr.ShowAnswer{Pipeline: mpr.Pipeline{Pipeline: "main.12", Branch: "main", Revision: 12}})
|
||||
}
|
||||
return json.Marshal(map[string]string{"error": "no pipeline " + in.Pipeline})
|
||||
case validateVerbKey:
|
||||
var in meshwants.ValidateInput
|
||||
_ = json.Unmarshal(raw, &in)
|
||||
verbs = append(verbs, in)
|
||||
return json.Marshal(meshwants.ValidateAnswer{Outcome: meshwants.ValidateAnswerOutcomePassed})
|
||||
}
|
||||
return nil, errors.New("no such verb " + key)
|
||||
}
|
||||
tool := validateTools(ask)[0]
|
||||
if d := strings.ToLower(tool.Description); tool.Name != validateTool || !strings.Contains(d, "judge a manifest on request") || !strings.Contains(d, "the manifest validator's verdict") ||
|
||||
!strings.Contains(d, "validate") {
|
||||
t.Errorf("the tool %s says %q", tool.Name, tool.Description)
|
||||
}
|
||||
out, err := tool.Run(map[string]any{"pipeline": "main.12", "module": "web", "why": "before the merge"})
|
||||
if b, _ := json.Marshal(out); err != nil || !strings.Contains(string(b), `"outcome":"passed"`) || len(verbs) != 1 ||
|
||||
verbs[0] != (meshwants.ValidateInput{Pipeline: "main.12", Candidate: "main.12", Module: "web", Why: "before the merge"}) {
|
||||
t.Errorf("a known pipeline answered %s, %v and called the verb with %+v", out, err, verbs)
|
||||
}
|
||||
out, err = tool.Run(map[string]any{"pipeline": "main.99", "why": "why"})
|
||||
if a, _ := out.(meshwants.ValidateAnswer); err != nil || a.Outcome != meshwants.ValidateAnswerOutcomeCouldNotRun || len(verbs) != 1 {
|
||||
t.Errorf("an unknown pipeline answered %+v, %v and called the verb %d times", out, err, len(verbs))
|
||||
}
|
||||
if _, err := tool.Run(map[string]any{"pipeline": "main.12"}); err == nil || len(verbs) != 1 {
|
||||
t.Errorf("a call with no why answered %v and called the verb", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
|
||||
@@ -50,6 +51,28 @@ type wantWhy struct {
|
||||
// Before is the want that stood before the pass, After the one the pass wrote (none: it kept Before).
|
||||
Before *mwc.Want `json:"before,omitempty"`
|
||||
After *mwc.Want `json:"after,omitempty"`
|
||||
// Entry is the ask of the catalog entry a want held awaiting its entry waits on: its state, how often it was asked again and its
|
||||
// last failure (design 47 H2 H-A-698 (2)).
|
||||
Entry *entryAsk `json:"entry,omitempty"`
|
||||
}
|
||||
|
||||
// entryAsk is where the ask of one catalog entry stands.
|
||||
type entryAsk struct {
|
||||
Fingerprint string `json:"fingerprint"`
|
||||
State meshcatalogclient.EntryState `json:"state"`
|
||||
Asks int `json:"asks"`
|
||||
Detail string `json:"detail,omitempty"`
|
||||
}
|
||||
|
||||
// heldWant is the want a why says stands after the pass: the one written, else the one before.
|
||||
func heldWant(w wantWhy) mwc.Want {
|
||||
switch {
|
||||
case w.After != nil:
|
||||
return *w.After
|
||||
case w.Before != nil:
|
||||
return *w.Before
|
||||
}
|
||||
return mwc.Want{}
|
||||
}
|
||||
|
||||
func whyKey(node, module string) string { return whyPrefix + node + "." + module }
|
||||
@@ -74,6 +97,14 @@ func (p *passer) sayWhy(ctx context.Context, module string, nodes []string, w wa
|
||||
one.After = &a
|
||||
}
|
||||
}
|
||||
if held := heldWant(one); p.entries != nil && strings.HasPrefix(held.Words, mwc.HoldAwaitsEntryPrefix) {
|
||||
fp := strings.TrimPrefix(held.Words, mwc.HoldAwaitsEntryPrefix)
|
||||
for _, row := range p.entries.Rows() {
|
||||
if row.Fingerprint == fp {
|
||||
one.Entry = &entryAsk{Fingerprint: fp, State: row.State, Asks: row.Asks, Detail: row.Detail}
|
||||
}
|
||||
}
|
||||
}
|
||||
same := one
|
||||
same.At = time.Time{}
|
||||
cmp, _ := json.Marshal(same)
|
||||
|
||||
@@ -362,6 +362,26 @@ func (w *world) online() map[string]bool {
|
||||
return out
|
||||
}
|
||||
|
||||
// namesFingerprint says whether a want the assigner wrote or a `running` it holds names fp: the entry at fp is still read by it
|
||||
// (design 47 H2 H-A-757).
|
||||
func (w *world) namesFingerprint(fp string) bool {
|
||||
for _, nodes := range w.wantsOf() {
|
||||
for _, want := range nodes {
|
||||
if want.Fp == fp {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
w.mu.Lock()
|
||||
defer w.mu.Unlock()
|
||||
for _, r := range w.running {
|
||||
if r.Fingerprint == fp {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// wantsOf is the wants the assigner wrote, by module then node.
|
||||
func (w *world) wantsOf() map[string]map[string]mwc.Want {
|
||||
out := map[string]map[string]mwc.Want{}
|
||||
|
||||
@@ -75,6 +75,27 @@ func CallUnanswered(id, callee, machine, fault, source string, since time.Time)
|
||||
Source: source}
|
||||
}
|
||||
|
||||
// ReadUnanswered is the observation of a seat verb a run's read waited five minutes on (design 47 H2 H-A-708 (4), ADR 0668 §3): id
|
||||
// `<seat>.<verb>`, the summary naming its holder, the machines it runs on, the last fault and since when; the id is one finding per
|
||||
// seat verb.
|
||||
func ReadUnanswered(seat, verb, holder string, machines []string, fault string, since time.Time) Observed {
|
||||
who := "its holder is not read"
|
||||
if holder != "" {
|
||||
who = "its holder " + holder
|
||||
if len(machines) > 0 {
|
||||
who += " on " + strings.Join(machines, ", ")
|
||||
}
|
||||
}
|
||||
callee := seat + "." + verb
|
||||
return Observed{Scope: mcc.ScopeCall, ID: callee, Kind: mcc.KindCallUnanswered, Severity: mcseat.FindingSeverityWarning,
|
||||
Summary: fmt.Sprintf("%s is unanswered since %s (%s); the last fault: %s", callee, since.UTC().Format(time.RFC3339), who, fault),
|
||||
Said: fault, Headline: "A read of a run is not answered",
|
||||
Explanation: fmt.Sprintf("A composition or validate run's read of %s is asked again at the kept-call pace and has not been answered since %s; %s. "+
|
||||
"The last fault: %s.", callee, since.UTC().Format(time.RFC3339), who, fault),
|
||||
Needs: "the holder of the seat " + seat + " to answer",
|
||||
Source: "assigner." + mcc.KindCallUnanswered}
|
||||
}
|
||||
|
||||
// FindingOf is a said condition as a finding: from the condition's own key `mesh-delivery-assigner.<kind>.<id…>` (the
|
||||
// subject's id when the key names none), its words unchanged but the resolved ones. raised is false for a clear, whose
|
||||
// finding names only its scope, id and kind.
|
||||
|
||||
@@ -44,3 +44,35 @@ func UnlistedFinding(node, module string, at time.Time) (mcseat.Finding, error)
|
||||
"Take it off, or register the module on a watched branch.",
|
||||
Source: "assigner." + KindAssignmentUnlisted}, at)
|
||||
}
|
||||
|
||||
// KindWantUnversioned is a want that names no version, for a module whose target no release gives (design 47 H2 H-A-673,
|
||||
// H-A-706 on DQ-40): scope delivery, id `<module>.<node>`, severity warning.
|
||||
const KindWantUnversioned = "want-unversioned"
|
||||
|
||||
// UnversionedKey is its finding's key, `delivery.<module>.<node>.want-unversioned`.
|
||||
func UnversionedKey(module, node string) string {
|
||||
return views.FindingKey(ScopeAssignmentUnlisted, KeyID(module+"."+node), KindWantUnversioned)
|
||||
}
|
||||
|
||||
// UnversionedOfKey is the module and node of a want-unversioned finding's key, or false for another finding's.
|
||||
func UnversionedOfKey(key string) (module, node string, ok bool) {
|
||||
rest, ok := strings.CutPrefix(key, ScopeAssignmentUnlisted+".")
|
||||
if !ok {
|
||||
return "", "", false
|
||||
}
|
||||
if rest, ok = strings.CutSuffix(rest, "."+KindWantUnversioned); !ok {
|
||||
return "", "", false
|
||||
}
|
||||
module, node, ok = strings.Cut(rest, ".")
|
||||
return module, node, ok && module != "" && node != "" && !strings.Contains(node, ".")
|
||||
}
|
||||
|
||||
// UnversionedFinding is the finding of the want of module on node that names fingerprint fp and no version, while no target is
|
||||
// held (why).
|
||||
func UnversionedFinding(module, node, fp, why string, at time.Time) (mcseat.Finding, error) {
|
||||
summary := fmt.Sprintf("the want of %s on %s names %s and no version, and no target is held for it: %s", module, node, short(fp), why)
|
||||
return encode(Observed{Scope: ScopeAssignmentUnlisted, ID: module + "." + node, Kind: KindWantUnversioned, Machine: node,
|
||||
Severity: mcseat.FindingSeverityWarning, Summary: summary, Headline: clipHeadline(module + " on " + node + " is wanted with no version"),
|
||||
Explanation: summary + ". The want stands as written, so the node composes nothing new for it; it clears once the want names a version.",
|
||||
Source: "assigner." + KindWantUnversioned}, at)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
|
||||
// A want names the newest released version whose pipeline passed (design 47 H §750): for every node whose assignment places
|
||||
// a module on a watched branch, the want names the version, the pipeline and the mover's rank in it, written tier by tier
|
||||
// (§751). It is held for nothing else: the rules of ADR 0429 §6 (the build done, not held, the canary and step, every
|
||||
// (§751). It is held for nothing else than a reader capability its node-engine does not state (ADR 0614 §4, §772 being its first case, H-A-682); the rules of ADR 0429 §6 (the build done, not held, the canary and step, every
|
||||
// provider healthy, the grant, the composition and the reader capabilities, the provisions, the served verbs and the bus
|
||||
// state), the network hold and A-428's exceptions end (H-A-55). A put owns its node's want as before (ADR 0546), and the
|
||||
// operator's yes on a module of policy record is the node-engine's have and the asker's (the pass's yeses).
|
||||
@@ -58,6 +58,10 @@ type Module struct {
|
||||
// node-engine, design 47 H §772, H-A-45); a node whose engine does not is written its want held, awaiting its hand placement
|
||||
// (H-A-73). Nil: every node does.
|
||||
ReadsVersion func(node string) bool
|
||||
// MissingNeeds says what the want of node at fp lacks of its node-engine's words: the reader capabilities the entry at fp
|
||||
// needs that the node's words in `engine-reads` do not hold, sorted; read false while the entry's needs are not read yet
|
||||
// (design 47 H2 H-A-682 (2), H-A-698 (2)). Nil: no want needs more than want:version.
|
||||
MissingNeeds func(node, fp string) (missing []string, read bool)
|
||||
}
|
||||
|
||||
func (m Module) selfOn(node string) bool { return m.Self != nil && m.Self(node) }
|
||||
@@ -96,13 +100,16 @@ func (n Nodes) RunsHealthy(node, module, fp string) bool {
|
||||
// Outcome is what one module's pass decides: each node's want to write (only those that change).
|
||||
type Outcome struct {
|
||||
Wants map[string]mwc.Want
|
||||
// Unversioned is, by node, the fingerprint of a want that names no version and for which Target answers none: the want
|
||||
// stands as written, and the pass says it with the finding want-unversioned (design 47 H2 H-A-673, H-A-706 on DQ-40).
|
||||
Unversioned map[string]string
|
||||
}
|
||||
|
||||
// Wants is the pass of one module m: for each of its nodes, the want naming its Target, starting from the want written before
|
||||
// (wants, by node). A put that owns a node's want writes the put's; a node with no target keeps the want written. A node that
|
||||
// wants m but is no longer among its nodes gets its want written removed, never deleted (ADR 0408 §4).
|
||||
func Wants(m Module, wants map[string]mwc.Want) Outcome {
|
||||
out := Outcome{Wants: map[string]mwc.Want{}}
|
||||
out := Outcome{Wants: map[string]mwc.Want{}, Unversioned: map[string]string{}}
|
||||
for _, node := range m.Nodes {
|
||||
before, had := wants[node]
|
||||
p, put := m.Puts[node]
|
||||
@@ -124,6 +131,9 @@ func Wants(m Module, wants map[string]mwc.Want) Outcome {
|
||||
t, ok = m.Target(node)
|
||||
}
|
||||
if !ok || t.Fp == "" {
|
||||
if had && !before.Removed && !before.Put && before.Version == "" && before.Fp != "" {
|
||||
out.Unversioned[node] = before.Fp
|
||||
}
|
||||
continue
|
||||
}
|
||||
next := mwc.Want{Fp: t.Fp, Version: t.Version, Pipeline: t.Pipeline, Rank: t.Rank, Self: m.selfOn(node)}
|
||||
@@ -137,6 +147,19 @@ func Wants(m Module, wants map[string]mwc.Want) Outcome {
|
||||
if m.ReadsVersion != nil && !m.ReadsVersion(node) {
|
||||
// A node-engine that cannot read a want by version is placed by hand when its machine is back (design 47 H §772).
|
||||
next.Hold, next.Words, next.Backup, next.Revert = true, mwc.HoldAwaitsHandPlacement, "", ""
|
||||
} else if m.MissingNeeds != nil {
|
||||
// A node-engine whose words lack a reader capability the entry needs reads the want no better (ADR 0614 §4): the want is
|
||||
// held, saying which, or saying the entry is not read yet (design 47 H2 H-A-682 (2), H-A-698 (2)).
|
||||
missing, read := m.MissingNeeds(node, t.Fp)
|
||||
switch {
|
||||
case !read:
|
||||
next.Hold, next.Words, next.Backup, next.Revert = true, mwc.HoldAwaitsEntryPrefix+t.Fp, "", ""
|
||||
case len(missing) > 0:
|
||||
next.Hold, next.Words, next.Backup, next.Revert = true, mwc.HoldAwaitsReadsPrefix+strings.Join(missing, ","), "", ""
|
||||
}
|
||||
}
|
||||
if !next.Hold && holdWords(next.Words) {
|
||||
next.Words = "" // the hold ended: its words with it
|
||||
}
|
||||
if !had || !mwc.SameWant(normal(before), normal(next)) {
|
||||
out.Wants[node] = next
|
||||
@@ -150,6 +173,11 @@ func Wants(m Module, wants map[string]mwc.Want) Outcome {
|
||||
return out
|
||||
}
|
||||
|
||||
// holdWords says whether words are those of a want the assigner holds for what its node-engine does not read.
|
||||
func holdWords(words string) bool {
|
||||
return words == mwc.HoldAwaitsHandPlacement || strings.HasPrefix(words, mwc.HoldAwaitsReadsPrefix) || strings.HasPrefix(words, mwc.HoldAwaitsEntryPrefix)
|
||||
}
|
||||
|
||||
// failed says whether a have's health check failed once the node is done moving: phase running or failed (never removed, held, or
|
||||
// moving).
|
||||
func failed(h nodeengine.HaveByNodeModuleValue) bool {
|
||||
|
||||
@@ -69,6 +69,34 @@ func TestAWantNamesTheNewestPassedVersion(t *testing.T) {
|
||||
m.ReadsVersion = func(node string) bool { return node == "ace" }
|
||||
return m
|
||||
}, nil, map[string]mwc.Want{"ace": want, "g14": {Fp: fNew, Version: "1.2.3", Pipeline: "main.12", Rank: 2, Hold: true, Words: mwc.HoldAwaitsHandPlacement}}},
|
||||
{"A3a (H-A-682 (2)): a node whose words lack a need of the entry is held, awaiting its reads; one whose words hold it is not", func() Module {
|
||||
m := released()
|
||||
m.MissingNeeds = func(node, fp string) ([]string, bool) {
|
||||
if node == "ace" {
|
||||
return []string{"directory-contents-owner", "approval-mark/1"}, true
|
||||
}
|
||||
return nil, true
|
||||
}
|
||||
return m
|
||||
}, nil, map[string]mwc.Want{"ace": {Fp: fNew, Version: "1.2.3", Pipeline: "main.12", Rank: 2, Hold: true, Words: mwc.HoldAwaitsReadsPrefix + "directory-contents-owner,approval-mark/1"}, "g14": want}},
|
||||
{"A3a: a node without want:version keeps awaiting its hand placement, whatever its needs", func() Module {
|
||||
m := released()
|
||||
m.ReadsVersion = func(node string) bool { return node == "g14" }
|
||||
m.MissingNeeds = func(string, string) ([]string, bool) { return []string{"directory-contents-owner"}, true }
|
||||
return m
|
||||
}, nil, map[string]mwc.Want{"ace": {Fp: fNew, Version: "1.2.3", Pipeline: "main.12", Rank: 2, Hold: true, Words: mwc.HoldAwaitsHandPlacement},
|
||||
"g14": {Fp: fNew, Version: "1.2.3", Pipeline: "main.12", Rank: 2, Hold: true, Words: mwc.HoldAwaitsReadsPrefix + "directory-contents-owner"}}},
|
||||
{"A3a: the node's next manifest-reads-changed naming the need writes the want with no hold", func() Module {
|
||||
m := released()
|
||||
m.MissingNeeds = func(string, string) ([]string, bool) { return nil, true }
|
||||
return m
|
||||
}, map[string]mwc.Want{"ace": {Fp: fNew, Version: "1.2.3", Pipeline: "main.12", Rank: 2, Hold: true, Words: mwc.HoldAwaitsReadsPrefix + "directory-contents-owner"}, "g14": want},
|
||||
map[string]mwc.Want{"ace": want}},
|
||||
{"A3b (H-A-698 (2)): a want whose entry is not read yet is held awaiting its entry", func() Module {
|
||||
m := released()
|
||||
m.MissingNeeds = func(node, fp string) ([]string, bool) { return nil, node != "ace" }
|
||||
return m
|
||||
}, wantedOld(), map[string]mwc.Want{"ace": {Fp: fNew, Version: "1.2.3", Pipeline: "main.12", Rank: 2, Hold: true, Words: mwc.HoldAwaitsEntryPrefix + fNew}, "g14": want}},
|
||||
{"a node no longer assigned is removed", func() Module {
|
||||
m := released()
|
||||
m.Nodes = []string{"ace"}
|
||||
@@ -86,6 +114,28 @@ func TestAWantNamesTheNewestPassedVersion(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// H-A-673, H-A-706 (DQ-40): a node whose want names no version and for which Target answers none is named in the outcome
|
||||
// beside the wants, with the fingerprint; one whose want names a version, one with a target (rewritten) and one removed are not.
|
||||
none := func() Module {
|
||||
m := released()
|
||||
m.Target = func(string) (Target, bool) { return Target{}, false }
|
||||
return m
|
||||
}
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
module func() Module
|
||||
before map[string]mwc.Want
|
||||
named map[string]string
|
||||
}{
|
||||
{"no version and no target", none, map[string]mwc.Want{"ace": {Fp: fOld}, "g14": {Fp: fOld, Version: "1.2.2"}}, map[string]string{"ace": fOld}},
|
||||
{"a target rewrites the want", released, map[string]mwc.Want{"ace": {Fp: fOld}}, map[string]string{}},
|
||||
{"a removed want", none, map[string]mwc.Want{"ace": {Removed: true}}, map[string]string{}},
|
||||
} {
|
||||
got := Wants(c.module(), c.before).Unversioned
|
||||
if len(got) != len(c.named) || (len(got) > 0 && got["ace"] != c.named["ace"]) {
|
||||
t.Errorf("%s: unversioned = %v, want %v", c.name, got, c.named)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ADR 0546: a put owns the node's want from its asking until it ends; while it waits the rule writes nothing there, once wanted its
|
||||
|
||||
@@ -104,7 +104,7 @@ func TestManifest(t *testing.T) {
|
||||
// revision, entry and difference from its revisions kept as objects in the old section, form 1, capped at 512 MiB.
|
||||
if len(m.Claims) != 2 || m.Claims[0].Name != meshmoduleassigner.Seat || m.Claims[0].At() != catalogue.ScopeMesh ||
|
||||
!slices.Equal(m.Claims[0].Serves, []string{"assignments", "proposals", "propose", "withdraw", "again", "placement"}) ||
|
||||
m.Claims[1].Name != meshwants.Seat || m.Claims[1].At() != catalogue.ScopeMesh || !slices.Equal(m.Claims[1].Serves, []string{"upgrade", "bus", "revision", "entry", "difference", "input", "compositions", "compositions-drop", "keep-now", "drop"}) {
|
||||
m.Claims[1].Name != meshwants.Seat || m.Claims[1].At() != catalogue.ScopeMesh || !slices.Equal(m.Claims[1].Serves, []string{"upgrade", "bus", "revision", "entry", "difference", "input", "compositions", "compositions-drop", "validate", "keep-now", "drop"}) {
|
||||
t.Errorf("the assigner claims %+v, want mesh-module-assigner with its five verbs and mesh-wants with its five", m.Claims)
|
||||
}
|
||||
if len(m.Objects) != 1 || m.Objects[0].Name != "assignment-revisions" || m.Objects[0].MaxMiB != 512 || m.Objects[0].Form != 1 {
|
||||
@@ -116,7 +116,7 @@ func TestManifest(t *testing.T) {
|
||||
// which lists and asks again what each node's engine reads.
|
||||
if !slices.Equal(m.Tools, []string{"assigner_put", "assigner_release", "assigner_puts", "assigner_waits", "assigner_inputs", "assigner_inputs_drop", "assigner_compositions", "assigner_compositions_drop", "assignments", "seat-holders", "wants", "asks",
|
||||
"assigner_read_assignments", "assigner_read_seat_holders", "assigner_read_wants", "assigner_read_findings", "assigner_read_differences", "assigner_read_copies",
|
||||
"assigner_first_views", "assigner_first_view_again", "assigner_engine_reads", "assigner_seat_list", "assigner_seat_list_again", "assigner_ask_again", "assigner_written", "assigner_why", "assigner_want_drop", "assigner_assignment_drop", "assigner_asks", "assigner_ask_drop", "assigner_keep_now", "assigner_validate_before"}) {
|
||||
"assigner_first_views", "assigner_first_view_again", "assigner_engine_reads", "assigner_seat_list", "assigner_seat_list_again", "assigner_ask_again", "assigner_written", "assigner_why", "assigner_want_drop", "assigner_assignment_drop", "assigner_asks", "assigner_ask_drop", "assigner_keep_now", "assigner_validate_before", "assigner_validate"}) {
|
||||
t.Errorf("the assigner serves tools %v, want its three put tools, three first views, six read tools, assigner_engine_reads, the seat list's two (ADR 0636 §7) assigner_ask_again (ADR 0668 §5), assigner_why (design 47 G A-439) and assigner_assignment_drop after assigner_want_drop (design 47 H2 H-A-509)", m.Tools)
|
||||
}
|
||||
if m.RunsAs != m.Module || m.SecretsOwner != m.RunsAs {
|
||||
@@ -164,6 +164,7 @@ func TestManifest(t *testing.T) {
|
||||
"seat:mesh-conditions.conditions", // design 47 G §706: the conditions read at each judging of an outside wait
|
||||
"seat:mesh-delivery.source", // §507: the branches the gate keeps a source revision of, before the first registrations
|
||||
"seat:mesh-hand-acts.hand-act", "seat:mesh-hand-acts.hand-acts", "seat:mesh-hand-acts.warranted", // ADR 0565 §9, §11: the seat alone
|
||||
"seat:mesh-pipeline-runner.show", // design 47 H2 H-A-684 (1), H-A-739: the candidate of the pipeline assigner_validate judges
|
||||
"seat:node-backup.backed-up", "seat:node-backup.now",
|
||||
"seat:node-build-go.accept.check", // A-231
|
||||
"seat:node-build-go.answer", // A-254, H-A-412: a composition run's answer over the inline bound, read through the build seat's verb answer
|
||||
@@ -185,7 +186,7 @@ func TestManifest(t *testing.T) {
|
||||
}
|
||||
file, _ := os.ReadFile("module.json")
|
||||
if err := json.Unmarshal(file, &raw); err != nil || raw.Config["outside-wait-minutes"].Default != float64(30) || raw.Config["outside-settle-seconds"].Default != float64(90) ||
|
||||
raw.Config["ask-operator-for"].Default != "take-off,remove-node,stops" || len(raw.Config) != 17 || raw.Config["tier-bound"].Default != float64(30) || raw.Config["entry-asks"].Default != float64(5) ||
|
||||
raw.Config["ask-operator-for"].Default != "take-off,remove-node,stops" || len(raw.Config) != 18 || raw.Config["tier-bound"].Default != float64(30) || raw.Config["entry-asks"].Default != float64(5) || raw.Config["reads-bound"].Default != float64(8) ||
|
||||
raw.Config["composition-runs-cap-mib"].Default != float64(16) || raw.Config["composition-runs-kept"].Default != "24h" ||
|
||||
raw.Config["composition-step-bound"].Default != "30m" || raw.Config["run-untaken-bound"].Default != "24h" || raw.Config["blame-tries"].Default != float64(20) ||
|
||||
// design 47 H2 H-A-628 (3): the bound of a run's wait for a package's publish, the builder's default
|
||||
@@ -210,6 +211,7 @@ func TestManifest(t *testing.T) {
|
||||
{"MESH_ASSIGNER_PASS_STALL_FILE", "${dir:state}/pass-stall-seconds", "pass-stall-seconds"}, // design 47 H2 H-A-635
|
||||
{"MESH_ASSIGNER_TIER_BOUND_FILE", "${dir:state}/tier-bound", "tier-bound"}, // design 47 H §751
|
||||
{"MESH_ASSIGNER_ENTRY_ASKS_FILE", "${dir:state}/entry-asks", "entry-asks"}, // design 47 H H-A-60
|
||||
{"MESH_ASSIGNER_READS_BOUND_FILE", "${dir:state}/reads-bound", "reads-bound"}, // design 47 H2 H-A-708 (3)
|
||||
} {
|
||||
if !strings.Contains(string(file), `"`+f.env+`": "`+f.path+`"`) || !strings.Contains(string(file), `"path": "`+f.path+`"`) ||
|
||||
!strings.Contains(string(file), `"content": "${config:`+f.key+`}"`) {
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
"input",
|
||||
"compositions",
|
||||
"compositions-drop",
|
||||
"validate",
|
||||
"keep-now",
|
||||
"drop"
|
||||
]
|
||||
@@ -81,6 +82,7 @@
|
||||
"seat:mesh-hand-acts.hand-act",
|
||||
"seat:mesh-hand-acts.hand-acts",
|
||||
"seat:mesh-hand-acts.warranted",
|
||||
"seat:mesh-pipeline-runner.show",
|
||||
"seat:node-backup.backed-up",
|
||||
"seat:node-backup.now",
|
||||
"seat:node-build-go.answer",
|
||||
@@ -140,7 +142,8 @@
|
||||
"assigner_asks",
|
||||
"assigner_ask_drop",
|
||||
"assigner_keep_now",
|
||||
"assigner_validate_before"
|
||||
"assigner_validate_before",
|
||||
"assigner_validate"
|
||||
],
|
||||
"state": [
|
||||
{ "name": "assignments", "history": 64, "max-mib": 8 },
|
||||
@@ -197,6 +200,14 @@
|
||||
"trusted": false,
|
||||
"default": 30
|
||||
},
|
||||
"reads-bound": {
|
||||
"type": "number",
|
||||
"description": "minutes a composition or validate run's reads of the seats mesh-catalog and mesh-builds may take in all, counted from the run's first read: the reads are kept calls paced by the form, and past it the run ends could not run with every call's time and words. Kept below the runner's ask-unanswered-bound (default 10 minutes, counted from the pull), so the step ends with the assigner's words; one set above it has the runner's bound end the step with its own (design 47 H2 H-A-708 (3)).",
|
||||
"minimum": 1,
|
||||
"maximum": 9,
|
||||
"trusted": false,
|
||||
"default": 8
|
||||
},
|
||||
"entry-asks": {
|
||||
"type": "number",
|
||||
"description": "how often the assigner asks a catalog entry again, on each catalog-revision and when its link to the bus opens again, after its ask failed to reach the holder of the seat mesh-catalog; one more failure leaves it unanswered, with the finding entry-unanswered (design 47 H, H-A-60).",
|
||||
@@ -346,6 +357,14 @@
|
||||
"mode": "0600",
|
||||
"content": "${config:tier-bound}"
|
||||
},
|
||||
{
|
||||
"id": "reads-bound",
|
||||
"type": "file",
|
||||
"path": "${dir:state}/reads-bound",
|
||||
"owner": "mesh-delivery-assigner",
|
||||
"mode": "0600",
|
||||
"content": "${config:reads-bound}"
|
||||
},
|
||||
{
|
||||
"id": "entry-asks",
|
||||
"type": "file",
|
||||
@@ -425,6 +444,7 @@
|
||||
"MESH_ASSIGNER_ASK_OPERATOR_FOR_FILE": "${dir:state}/ask-operator-for",
|
||||
"MESH_ASSIGNER_TIER_BOUND_FILE": "${dir:state}/tier-bound",
|
||||
"MESH_ASSIGNER_ENTRY_ASKS_FILE": "${dir:state}/entry-asks",
|
||||
"MESH_ASSIGNER_READS_BOUND_FILE": "${dir:state}/reads-bound",
|
||||
"MESH_ASSIGNER_COMPOSITION_RUNS_CAP_MIB_FILE": "${dir:state}/composition-runs-cap-mib",
|
||||
"MESH_ASSIGNER_COMPOSITION_RUNS_KEPT_FILE": "${dir:state}/composition-runs-kept",
|
||||
"MESH_ASSIGNER_COMPOSITION_STEP_BOUND_FILE": "${dir:state}/composition-step-bound",
|
||||
|
||||
@@ -329,7 +329,7 @@ const (
|
||||
|
||||
func main() {
|
||||
reasks := stdio.State(build.ReAsksState)
|
||||
r := build.StuckReader{Logf: func(f string, a ...any) { fmt.Fprintf(os.Stderr, "[mesh-delivery-builder-tools] "+f+"\n", a...) }, Builds: read(stdio.State("builds")), ReAsks: read(reasks), StepsOf: stepsOfHolder(func(seat string) (string, error) { return seatlist.HolderOf(stdio.Ask, seat) }, func(name string) build.StateRead { return read(stdio.State(name)) }),
|
||||
r := build.StuckReader{Logf: func(f string, a ...any) { fmt.Fprintf(os.Stderr, "[mesh-delivery-builder-tools] "+f+"\n", a...) }, Builds: read(stdio.State("builds")), ReAsks: read(reasks), Waits: read(stdio.State(build.WaitsState)), StepsOf: stepsOfHolder(func(seat string) (string, error) { return seatlist.HolderOf(stdio.Ask, seat) }, func(name string) build.StateRead { return read(stdio.State(name)) }),
|
||||
Hearing: read(stdio.State(buildrun.HearingState))}
|
||||
put := func(key string, value []byte) error {
|
||||
_, err := reasks.Put(key, json.RawMessage(value))
|
||||
@@ -400,7 +400,7 @@ func main() {
|
||||
tools = append(tools, reservedTools(rr, buildAgain, time.Now, meshhandactsclient.Recorder{Ask: stdio.Ask})...)
|
||||
as := stdio.State(versions.ActedState)
|
||||
tools = append(tools, publishActTools(buildAgain, time.Now, meshhandactsclient.Recorder{Ask: stdio.Ask})...)
|
||||
tools = append(tools, republishTools(publishQueueVia(stdio.Ask), readerOf(as), readerOf(reasks), buildAgain, time.Now, meshhandactsclient.Recorder{Ask: stdio.Ask})...)
|
||||
tools = append(tools, republishTools(publishQueueVia(stdio.Ask), readerOf(as), buildAgain, time.Now, meshhandactsclient.Recorder{Ask: stdio.Ask})...)
|
||||
ws := stdio.State(build.WaitsState)
|
||||
wr := versions.Reader{Keys: ws.Keys, Get: func(key string) (json.RawMessage, bool, error) {
|
||||
e, err := ws.Get(key)
|
||||
|
||||
@@ -114,7 +114,7 @@ func publishActTools(ask queueAsker, now func() time.Time, acts meshhandactsclie
|
||||
// republishTools are builder_publish_again and builder_publish_queue (design 47 G §588). The publish again is a hand act:
|
||||
// it is recorded in the hand-act log first, then written to reasks for the builder, which owns the queue, to answer
|
||||
// with the versions it queued.
|
||||
func republishTools(queue func(module, version string) (meshbuilds.PublishQueueAnswer, error), acted, reasks versions.Reader, ask queueAsker, now func() time.Time, acts meshhandactsclient.Recorder) []stdio.Tool {
|
||||
func republishTools(queue func(module, version string) (meshbuilds.PublishQueueAnswer, error), acted versions.Reader, ask queueAsker, now func() time.Time, acts meshhandactsclient.Recorder) []stdio.Tool {
|
||||
str := func(args map[string]any, k string) string { s, _ := args[k].(string); return strings.TrimSpace(s) }
|
||||
return []stdio.Tool{
|
||||
{Name: versions.PublishAgainTool, Description: versions.PublishAgainDescription,
|
||||
@@ -153,7 +153,7 @@ func republishTools(queue func(module, version string) (meshbuilds.PublishQueueA
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return versions.AnswerQueue(q, acted, reasks)
|
||||
return versions.AnswerQueue(q, acted)
|
||||
}},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ func TestAStateIsReadInOnePage(t *testing.T) {
|
||||
Queue: []meshbuilds.PublishQueueAnswerQueueItem{{Holder: "oci", Module: "m", Version: "0.1.0", Class: versions.PublishClassStart}}})
|
||||
}
|
||||
none := versions.Reader{Keys: func() ([]string, error) { return nil, nil }}
|
||||
tools := republishTools(publishQueueVia(ask), none, none, nil, time.Now, meshhandactsclient.Recorder{})
|
||||
tools := republishTools(publishQueueVia(ask), none, nil, time.Now, meshhandactsclient.Recorder{})
|
||||
raw, err := tools[1].Run(map[string]any{"module": "m"})
|
||||
a, _ := raw.(versions.Queued)
|
||||
if err != nil || fmt.Sprint(asked) != "[seat:mesh-builds.publish-queue m]" || a.Total != 9000 || len(a.Queue) != 1 || a.Queue[0].Module != "m" ||
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"mesh-delivery-builder/internal/versions"
|
||||
)
|
||||
|
||||
// reservedTools are builder_reserved, builder_reserved_drop and builder_reserve_done (A-455) (design 47 G section 369), served as tools of the bundle. The drop is a hand act: it is recorded in the hand-act log first, then written to
|
||||
// reservedTools are builder_reserved and builder_reserved_drop (design 47 G section 369), served as tools of the bundle. The drop is a hand act: it is recorded in the hand-act log first, then written to
|
||||
// reasks for the builder, which owns the reservations, to answer.
|
||||
//
|
||||
// The seat's verb reserved is the builder's process's (design 47 G A-115, A-127), not the bundle's.
|
||||
@@ -25,16 +25,17 @@ func reservedTools(rr versions.Reader, ask queueAsker, now func() time.Time, act
|
||||
"module": map[string]any{"type": "string", "description": "only this module's reservations"}}},
|
||||
Run: func(args map[string]any) (any, error) { return versions.AnswerReserved(rr, str(args, "module")) }},
|
||||
{Name: versions.ReservedDropTool, Description: versions.ReservedDropDescription,
|
||||
Input: map[string]any{"type": "object", "required": []string{"module", "series", "why"}, "properties": map[string]any{
|
||||
"module": map[string]any{"type": "string", "description": "the module"},
|
||||
"series": map[string]any{"type": "string", "description": "its MAJOR.MINOR"},
|
||||
"why": map[string]any{"type": "string", "description": "why, in plain words"}}},
|
||||
Input: map[string]any{"type": "object", "required": []string{"module", "series", "version", "why"}, "properties": map[string]any{
|
||||
"module": map[string]any{"type": "string", "description": "the module"},
|
||||
"series": map[string]any{"type": "string", "description": "its MAJOR.MINOR"},
|
||||
"version": map[string]any{"type": "string", "description": "the MAJOR.MINOR.PATCH the reservation stands at, as builder_reserved shows it: a newer one is never dropped"},
|
||||
"why": map[string]any{"type": "string", "description": "why, in plain words"}}},
|
||||
Run: func(args map[string]any) (any, error) {
|
||||
key, value, err := build.NewReservedDrop(str(args, "module"), str(args, "series"), str(args, "why"), stdio.CallerOf(args), now())
|
||||
key, value, err := build.NewReservedDrop(str(args, "module"), str(args, "series"), str(args, "version"), str(args, "why"), stdio.CallerOf(args), now())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := acts.Record(meshhandactsclient.Request{What: fmt.Sprintf("dropped the reservation of %s %s by hand", str(args, "module"), str(args, "series")),
|
||||
if _, err := acts.Record(meshhandactsclient.Request{What: fmt.Sprintf("dropped the reservation of %s %s by hand", str(args, "module"), str(args, "version")),
|
||||
Why: str(args, "why"), Cause: versions.ReservedDropTool, Verb: "reserved-drop"}); err != nil {
|
||||
return nil, fmt.Errorf("the hand act was not recorded through mesh-hand-acts, so nothing was dropped: %w", err)
|
||||
}
|
||||
@@ -51,32 +52,5 @@ func reservedTools(rr versions.Reader, ask queueAsker, now func() time.Time, act
|
||||
}
|
||||
return map[string]any{"key": key, "answer": a.Answer}, nil
|
||||
}},
|
||||
{Name: versions.ReserveDoneTool, Description: versions.ReserveDoneDescription,
|
||||
Input: map[string]any{"type": "object", "required": []string{"module", "fp", "why"}, "properties": map[string]any{
|
||||
"module": map[string]any{"type": "string", "description": "the module"},
|
||||
"fp": map[string]any{"type": "string", "description": "the fingerprint of its done trunk build"},
|
||||
"why": map[string]any{"type": "string", "description": "why, in plain words"}}},
|
||||
Run: func(args map[string]any) (any, error) {
|
||||
key, value, err := build.NewReserveDone(str(args, "module"), str(args, "fp"), str(args, "why"), stdio.CallerOf(args), now())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := acts.Record(meshhandactsclient.Request{What: fmt.Sprintf("reserved a version for the done build of %s at %s by hand", str(args, "module"), str(args, "fp")),
|
||||
Why: str(args, "why"), Cause: versions.ReserveDoneTool, Verb: "reserve-done"}); err != nil {
|
||||
return nil, fmt.Errorf("the hand act was not recorded through mesh-hand-acts, so nothing was reserved: %w", err)
|
||||
}
|
||||
raw, err := ask(key, value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
a, err := build.DecodeReAsk(raw)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if a.Refused {
|
||||
return nil, errors.New(a.Answer)
|
||||
}
|
||||
return map[string]any{"key": key, "answer": a.Answer}, nil
|
||||
}},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func waitsTools(rr versions.Reader, ask queueAsker, now func() time.Time, acts m
|
||||
return []stdio.Tool{
|
||||
{Name: build.WaitsTool,
|
||||
Description: "The builder's toolchain waits: each entry held because its fingerprint names a toolchain version of its language other than the " +
|
||||
"agreed one, with its module, fingerprint, what it waits on (toolchain:<language>@<version>) and since when. It ends when the agreed toolchain " +
|
||||
"agreed one, and each build waiting for a package's blank pin (package:<path>, with its publisher, the catalog revision it holds and until when), with its module, fingerprint, what it waits on (toolchain:<language>@<version>) and since when. It ends when the agreed toolchain " +
|
||||
"names that version (ran) or when " + build.ReleaseTool + " builds it with the running build module (released). Read-only.",
|
||||
Input: map[string]any{"type": "object", "properties": map[string]any{}},
|
||||
Run: func(map[string]any) (any, error) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -45,56 +44,3 @@ func TestWaitsToolsListTheWaitsAndReleaseAfterTheHandAct(t *testing.T) {
|
||||
t.Fatalf("release: %v, %d recorded, asked %+v", err, recorded, asked)
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 G A-455: builder_reserve_done records the hand act first and only then asks the builder through reasks; the builder's
|
||||
// answer (the version and its queued publish) is the tool's answer, its refusal the tool's error, and an act that was not
|
||||
// recorded asks nothing.
|
||||
func TestReserveDoneRecordsTheHandActFirstAndAnswersTheBuilders(t *testing.T) {
|
||||
var order []string
|
||||
var asked []build.ReAsk
|
||||
reply := func(refuse bool) func(string, []byte) (json.RawMessage, error) {
|
||||
return func(key string, value []byte) (json.RawMessage, error) {
|
||||
order = append(order, "asked")
|
||||
a, _ := build.DecodeReAsk(value)
|
||||
asked = append(asked, a)
|
||||
a.Answered, a.Answer, a.Refused = time.Now(), "reserved 0.1.13 for node-tools and queued 1 versions to publish: node-tools@0.1.13", refuse
|
||||
if refuse {
|
||||
a.Answer = "the build key is not done"
|
||||
}
|
||||
return json.Marshal(a)
|
||||
}
|
||||
}
|
||||
record := func(fail bool) meshhandactsclient.Recorder {
|
||||
return meshhandactsclient.Recorder{Ask: func(string, any) (json.RawMessage, error) {
|
||||
order = append(order, "recorded")
|
||||
if fail {
|
||||
return nil, errors.New("no responders")
|
||||
}
|
||||
return json.RawMessage(`{}`), nil
|
||||
}}
|
||||
}
|
||||
run := func(ask func(string, []byte) (json.RawMessage, error), acts meshhandactsclient.Recorder, args map[string]any) (any, error) {
|
||||
for _, tl := range reservedTools(versions.Reader{}, ask, time.Now, acts) {
|
||||
if tl.Name == versions.ReserveDoneTool {
|
||||
return tl.Run(args)
|
||||
}
|
||||
}
|
||||
t.Fatal("the bundle serves no builder_reserve_done")
|
||||
return nil, nil
|
||||
}
|
||||
args := map[string]any{"module": "node-tools", "fp": "src2:7df8", "why": "its build ended done with no version"}
|
||||
out, err := run(reply(false), record(false), args)
|
||||
if err != nil || len(order) != 2 || order[0] != "recorded" || order[1] != "asked" || asked[0].Mode != build.ModeReserveDone || asked[0].Name != "node-tools" || asked[0].FP != "src2:7df8" {
|
||||
t.Fatalf("answer %v, %v; order %v, asked %+v", out, err, order, asked)
|
||||
}
|
||||
if ans := out.(map[string]any)["answer"].(string); !strings.Contains(ans, "reserved 0.1.13") || !strings.Contains(ans, "queued 1 versions") {
|
||||
t.Errorf("the answer %q names no version and queued publish", ans)
|
||||
}
|
||||
if _, err := run(reply(true), record(false), args); err == nil || !strings.Contains(err.Error(), "not done") {
|
||||
t.Errorf("the builder's refusal is not the tool's error: %v", err)
|
||||
}
|
||||
order = nil
|
||||
if _, err := run(reply(false), record(true), args); err == nil || len(order) != 1 || order[0] != "recorded" {
|
||||
t.Errorf("an unrecorded act was asked of the builder: %v, %v", err, order)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
//go:build integration
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"mesh-delivery-builder/internal/versions"
|
||||
)
|
||||
|
||||
// Design 47 H2 H-A-720 (1), H-A-741: a mark is updated by one publish carrying its lifetime and the expected last sequence of its
|
||||
// key: the update at the right revision succeeds and the key keeps its lifetime; one at a stale revision is a conflict.
|
||||
func TestAMarkIsUpdatedWithItsLifetimeInOnePublish(t *testing.T) {
|
||||
b := startBed(t)
|
||||
kv, err := b.js.CreateKeyValue(b.ctx, jetstream.KeyValueConfig{Bucket: "acted-test", LimitMarkerTTL: time.Minute})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
key := versions.ActedKey("retake:x")
|
||||
rev, err := kv.Create(b.ctx, key, []byte("1"), jetstream.KeyTTL(time.Hour))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
next, err := updateWithLifetime(b.ctx, b.js, "acted-test", key, []byte("2"), rev, 2*time.Hour)
|
||||
if err != nil || next <= rev {
|
||||
t.Fatalf("update at the key's revision: %d, %v", next, err)
|
||||
}
|
||||
if e, err := kv.Get(b.ctx, key); err != nil || string(e.Value()) != "2" || e.Revision() != next {
|
||||
t.Fatalf("the key holds %v, %v after the update", e, err)
|
||||
}
|
||||
if _, err := updateWithLifetime(b.ctx, b.js, "acted-test", key, []byte("3"), rev, time.Hour); !errors.Is(err, versions.ErrConflict) {
|
||||
t.Fatalf("update at a stale revision: %v, want a conflict", err)
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
// handlers is where a part of the builder registers its handler of the events it hears: the event hub, or agedHub over it.
|
||||
type handlers interface {
|
||||
Handle(pattern string, handle func(jetstream.Msg)) error
|
||||
HandleByKey(pattern string, key process.EventKey, handle func(jetstream.Msg)) error
|
||||
}
|
||||
|
||||
// ledgers are the builder's durable consumers' ledgers, one per consumer as a message's metadata names it (the events consumer
|
||||
@@ -56,7 +57,16 @@ type agedHub struct {
|
||||
}
|
||||
|
||||
func (a agedHub) Handle(pattern string, handle func(jetstream.Msg)) error {
|
||||
return a.hub.Handle(pattern, func(m jetstream.Msg) {
|
||||
return a.hub.Handle(pattern, a.aged(handle))
|
||||
}
|
||||
|
||||
// HandleByKey registers handle held by key, each message noted as Handle's are.
|
||||
func (a agedHub) HandleByKey(pattern string, key process.EventKey, handle func(jetstream.Msg)) error {
|
||||
return a.hub.HandleByKey(pattern, key, a.aged(handle))
|
||||
}
|
||||
|
||||
func (a agedHub) aged(handle func(jetstream.Msg)) func(jetstream.Msg) {
|
||||
return func(m jetstream.Msg) {
|
||||
led := a.ledgers.of(m)
|
||||
if led == nil {
|
||||
handle(m)
|
||||
@@ -64,7 +74,7 @@ func (a agedHub) Handle(pattern string, handle func(jetstream.Msg)) error {
|
||||
}
|
||||
led.Delivered(m)
|
||||
handle(&agedMsg{Msg: m, ledger: led})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// agedMsg is a message whose acknowledgement or end is noted applied on its consumer's ledger, once.
|
||||
|
||||
@@ -3,12 +3,12 @@ package main
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"slices"
|
||||
"sync"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
|
||||
@@ -60,78 +60,29 @@ func takeEvent(m jetstream.Msg, takers []eventTaker, rest eventTaker, slow time.
|
||||
}
|
||||
}
|
||||
|
||||
// eventWorkers hands each event of the builder's durable to a worker of its key (design 47 H2 H-A-514 addenda): the name the
|
||||
// event carries (a registry seat's outcome's package name, a version-released's module), one shared worker for the events that
|
||||
// name none. One key's events are handled in the order heard, the keys side by side, so a slow event of one name delays no
|
||||
// other name's. A worker ends when its queue is empty. The builder holds no timer (ADR 0437 §8), so the events still waiting in
|
||||
// a queue are said in progress to the bus each time its worker ends a handling, and none waits out the ack wait behind another.
|
||||
type eventWorkers struct {
|
||||
handle func(jetstream.Msg)
|
||||
keyOf func(jetstream.Msg) string
|
||||
|
||||
mu sync.Mutex
|
||||
queues map[string]*eventQueue
|
||||
}
|
||||
|
||||
// eventQueue is one key's events not yet handled, the one handled now first.
|
||||
type eventQueue struct{ msgs []jetstream.Msg }
|
||||
|
||||
// take queues m on its key's worker, starting the worker when none runs.
|
||||
func (w *eventWorkers) take(m jetstream.Msg) {
|
||||
key := w.keyOf(m)
|
||||
w.mu.Lock()
|
||||
if w.queues == nil {
|
||||
w.queues = map[string]*eventQueue{}
|
||||
}
|
||||
q, running := w.queues[key]
|
||||
if !running {
|
||||
q = &eventQueue{}
|
||||
w.queues[key] = q
|
||||
}
|
||||
q.msgs = append(q.msgs, m)
|
||||
w.mu.Unlock()
|
||||
if !running {
|
||||
go w.run(key, q)
|
||||
}
|
||||
}
|
||||
|
||||
// run handles key's events in order until its queue is empty, saying those still waiting in progress after each.
|
||||
func (w *eventWorkers) run(key string, q *eventQueue) {
|
||||
for {
|
||||
w.mu.Lock()
|
||||
if len(q.msgs) == 0 {
|
||||
delete(w.queues, key)
|
||||
w.mu.Unlock()
|
||||
return
|
||||
}
|
||||
m := q.msgs[0]
|
||||
w.mu.Unlock()
|
||||
w.handle(m)
|
||||
w.mu.Lock()
|
||||
q.msgs = q.msgs[1:]
|
||||
waiting := slices.Clone(q.msgs)
|
||||
w.mu.Unlock()
|
||||
for _, m := range waiting {
|
||||
_ = m.InProgress()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// eventKey is the worker key of a builder's event (H-A-514 second addendum): a registry seat's outcome's name, a
|
||||
// version-released's module, else "" (one worker for the events naming none).
|
||||
func eventKey(m jetstream.Msg) string {
|
||||
if _, ok := seatEvents[m.Subject()]; ok {
|
||||
// eventKey is the key the hub holds a builder's event under (design 47 H2 H-A-683 (1), H-A-737 (1)): a registry seat's outcome's
|
||||
// name, a version-released's module, the node the subject of the seat node-engine's running and manifest-reads-changed names,
|
||||
// else "" (the events naming none share one key). One key's events are handled one at a time in the order heard, the keys side by
|
||||
// side, so a slow handling of one node's event holds back no other node's.
|
||||
func eventKey(subject string, data []byte) string {
|
||||
if _, ok := seatEvents[subject]; ok {
|
||||
var o versions.Outcome
|
||||
if json.Unmarshal(m.Data(), &o) == nil {
|
||||
if json.Unmarshal(data, &o) == nil {
|
||||
return "name " + o.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
if m.Subject() == meshcatalog.SubjectVersionReleased {
|
||||
if subject == meshcatalog.SubjectVersionReleased {
|
||||
var ev meshcatalog.VersionReleasedEvent
|
||||
if json.Unmarshal(m.Data(), &ev) == nil {
|
||||
if json.Unmarshal(data, &ev) == nil {
|
||||
return "module " + ev.Module
|
||||
}
|
||||
return ""
|
||||
}
|
||||
// mesh.seat.node-engine.event.running.<node>.<module> and mesh.seat.node-engine.event.manifest-reads-changed.<node>
|
||||
if t := strings.Split(subject, "."); len(t) >= 6 && t[2] == "node-engine" && t[3] == "event" &&
|
||||
(t[4] == nodeengine.EventRunning || t[4] == nodeengine.EventManifestReadsChanged) {
|
||||
return "node " + t[5]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -19,6 +19,10 @@ import (
|
||||
// A-29); its `findings-asked` subject is the seat's, from the generated contract (A-17).
|
||||
type heldWriter = views.HeldWriter[mcseat.Finding, mcseat.FindingCleared, mcseat.FindingsStated, mcseat.FindingsAskedEvent]
|
||||
|
||||
// retiredFindingKinds are kinds no code of the builder raises any more, which its writer clears once at its start (design 47 H2
|
||||
// H-A-578 (1), H-A-247 (3)): floor-silent went with the version floor.
|
||||
var retiredFindingKinds = []views.RetiredKind{{Kind: "floor-silent"}}
|
||||
|
||||
// findingWriter is the part of the held writer the builder's findings use; Held answers the findings it holds (design 47 G A-38).
|
||||
type findingWriter interface {
|
||||
Write(ctx context.Context, f mcseat.Finding) error
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||
|
||||
"github.com/nats-io/nats-server/v2/server"
|
||||
@@ -700,8 +701,9 @@ func TestBuilderMakesADoneKeyWithTheDigests(t *testing.T) { // 1607/AC7
|
||||
}
|
||||
// The reservations' states, as the controller makes them from the builder's manifest, and the catalog seat's versions, which
|
||||
// a first reservation reads (none released yet).
|
||||
// The state acted is declared key-ttl (design 47 H2 H-A-720 (1)): its marks take a lifetime, so the bucket holds per-message lifetimes.
|
||||
for _, state := range []string{versions.ReservedState, versions.ActedState} { // acted keeps the release record
|
||||
if _, err := b.js.CreateKeyValue(b.ctx, jetstream.KeyValueConfig{Bucket: builds.StateBucket(builds.BuilderModule, state)}); err != nil {
|
||||
if _, err := b.js.CreateKeyValue(b.ctx, jetstream.KeyValueConfig{Bucket: builds.StateBucket(builds.BuilderModule, state), LimitMarkerTTL: time.Second}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -748,11 +750,26 @@ func TestBuilderMakesADoneKeyWithTheDigests(t *testing.T) { // 1607/AC7
|
||||
}
|
||||
}
|
||||
b.awaitSaid(t, "package "+pkg+" has no published version")
|
||||
goPublished(reserved.Version, pkgDigest)
|
||||
want := "v" + reserved.Version
|
||||
// Design 47 H2 H-A-707 (3), (4) (B18, whole): the same fingerprint taken in again at a later revision, its entry at a later commit
|
||||
// naming the version, while the earlier build waits on its blank pin: the build takes that pin, said once, with no published
|
||||
// heard, and is one build, its key written done once and never failed.
|
||||
later := b.entry("netcheck", "modules/netcheck", "89abcdef0123456789abcdef0123456789abcdef", fourth, digest, b.manifestOf(t, netcheck), bothToolchains, 0)
|
||||
later.Packages = map[string]string{pkg: want}
|
||||
b.catalog.put(t, later)
|
||||
b.awaitSaid(t, pkg+" takes "+want)
|
||||
if v := b.awaitFP(t, "netcheck", fourth, isState(builds.BuildDone)); v.Packages[pkg] != want {
|
||||
t.Errorf("netcheck built with %v, want %s at %s, its publisher's reservation at the key's origin (H-A-547 (3))", v.Packages, pkg, want)
|
||||
}
|
||||
goPublished(reserved.Version, pkgDigest) // heard after the build: nothing builds again
|
||||
if st, err := b.js.Stream(b.ctx, "BUILDER_BUILDS"); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if subject := "mesh.stream.mesh-delivery-builder.event." + builds.BuildEndedEventName("netcheck", fourth); true {
|
||||
info, err := st.Info(b.ctx, jetstream.WithSubjectFilter(subject))
|
||||
if err != nil || info.State.Subjects[subject] != 1 {
|
||||
t.Errorf("netcheck at %s ended %d times (%v), want its one build done, never one failed (H-A-707 (3), (4))", fourth, info.State.Subjects[subject], err)
|
||||
}
|
||||
}
|
||||
released, _ := json.Marshal(meshcatalog.VersionReleasedEvent{V: 1, Module: "disk-load", Version: reserved.Version})
|
||||
msg := nats.NewMsg(meshcatalog.SubjectVersionReleased)
|
||||
msg.Header.Set("x-event-id", "released-disk-load-"+reserved.Version)
|
||||
@@ -793,6 +810,43 @@ func TestBuilderMakesADoneKeyWithTheDigests(t *testing.T) { // 1607/AC7
|
||||
if v := b.awaitFP(t, "netcheck", fifth, isState(builds.BuildDone)); v.Packages[pkg] != want {
|
||||
t.Errorf("netcheck built with %v once disk-load %s was released, want %s at %s from its release record (H-A-551)", v.Packages, reserved.Version, pkg, want)
|
||||
}
|
||||
|
||||
// Design 47 H2 H-A-695 (AC-B16c, whole): the manifest-reads-changed of node n2 asks its engine, which never answers (no engine of n2 is
|
||||
// listening); the running of the build module on node n1, stopped, is handled all the same (its toolchain key is deleted), and no event
|
||||
// of the builder's durable is given again or ends in the dead letters (a delivery limit reached is advised on the bus).
|
||||
deadLetters, err := b.js.Conn().SubscribeSync("$JS.EVENT.ADVISORY.CONSUMER.MAX_DELIVERIES." + eventsStream + ".*")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer deadLetters.Unsubscribe()
|
||||
toolchainKey, _ := sdkstep.ToolchainKey("n1", "go")
|
||||
if _, err := b.heard.Get(b.ctx, toolchainKey); err != nil {
|
||||
t.Fatalf("the builder holds no toolchain of n1 before the events: %v", err)
|
||||
}
|
||||
changed, _ := json.Marshal(nodeengine.ManifestReadsChanged{Node: "n2", Why: "changed", At: time.Now().UTC().Format(time.RFC3339Nano)})
|
||||
if _, err := b.js.Publish(b.ctx, nodeengine.SubjectManifestReadsChanged("n2"), changed); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
stopped, _ := json.Marshal(nodeengine.Running{Module: testGo, Node: "n1", At: time.Now().UTC()})
|
||||
if _, err := b.js.Publish(b.ctx, nodeengine.SubjectRunning("n1", testGo), stopped); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for deadline := time.Now().Add(20 * time.Second); ; time.Sleep(20 * time.Millisecond) {
|
||||
if _, err := b.heard.Get(b.ctx, toolchainKey); errors.Is(err, jetstream.ErrKeyNotFound) {
|
||||
break
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatal("the running of n1 was not handled within 20 s while the manifest-reads-changed of n2 waited on its ask")
|
||||
}
|
||||
}
|
||||
if m, err := deadLetters.NextMsg(10 * time.Millisecond); err == nil {
|
||||
t.Errorf("the bus advised a delivery limit reached: %s", m.Subject)
|
||||
}
|
||||
if c, err := b.js.Consumer(b.ctx, eventsStream, "n1_mesh-delivery-builder"); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if info, err := c.Info(b.ctx); err != nil || info.NumRedelivered != 0 {
|
||||
t.Errorf("the builder's durable gave %d events again (%v), want none", info.NumRedelivered, err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestAnArchiveOnlyModuleAndARootModuleAreBuilt: the indexer gives an archive no language, so modules.ca-trust has no
|
||||
|
||||
@@ -99,7 +99,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
// The builder's findings are raised as they happen, so its one finding writer holds them (design 47 G A-29, §689): it
|
||||
// is started once the state is bound, and what is written before is stated at its start.
|
||||
fw, err := views.NewHeldWriter(views.WriterConfig[mcseat.Finding, mcseat.FindingCleared, mcseat.FindingsStated, mcseat.FindingsAskedEvent]{
|
||||
Module: cred.Module, State: calls.State("findings"), Node: cred.Node, Asked: mcseat.SubjectFindingsAsked, JS: js, Conn: conn, Logf: logger.Printf})
|
||||
Module: cred.Module, State: calls.State("findings"), Node: cred.Node, Asked: mcseat.SubjectFindingsAsked, Retired: retiredFindingKinds, JS: js, Conn: conn, Logf: logger.Printf})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -235,6 +235,11 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
// heard (design 47 H2 H-A-552: no fill is waited for).
|
||||
reservedKV := process.AwaitBucket(ctx, js, conn, own.reserved, "no version is reserved: builds are made unreserved", logger.Printf)
|
||||
reserved := newReservations(awaitedReserved{awaitedState{b: reservedKV, bucket: own.reserved}}, calls.Call, pubBoundsKV.KV, found, logger.Printf)
|
||||
publishAck, err := numberFile(getenv("MESH_BUILDER_PUBLISH_ACK_FILE"), defaultPublishAckMinutes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
reserved.setBound(time.Duration(publishAck) * time.Minute) // the finding version-unreleased is timed by the same setting (H-A-613 (3))
|
||||
// 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).
|
||||
@@ -247,6 +252,10 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
b.Reserved = reserved
|
||||
// A take-over of a series' reservation by another fingerprint withdraws the older build (H-A-225).
|
||||
reserved.withdraw = b.Withdraw
|
||||
reserved.looking = func(module, fp string) bool {
|
||||
key, err := builds.BuilderBuildKey(module, fp)
|
||||
return err == nil && b.Looking(key)
|
||||
}
|
||||
reserved.recordAgain = b.RecordAgain // a done build's digests its end did not record are recorded at the start (H-A-492)
|
||||
// The versions' hand acts (builder_publish_again, builder_reserved_drop) come through reasks, as builder_build_again.
|
||||
acts := versions.Acts{DropReserved: reserved.dropped}
|
||||
@@ -255,13 +264,19 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
actedKV := process.AwaitBucket(ctx, js, conn, own.acted, "no version is published again on an event or by builder_publish_again", logger.Printf)
|
||||
pq := &publishQueue{js: js, logf: logger.Printf, binding: publishesOf(cred.Module)}
|
||||
republish := &versions.Republisher{Reserved: reserved.r, Put: pq.put,
|
||||
Entry: entryVia(calls.Call), Send: sendVia(calls.CallKeptAsk),
|
||||
Entry: entryVia(calls.Call), Send: sendVia(calls.CallKeptAsk, publishUnanswered(ctx, found)),
|
||||
Unreleased: reserved.unreleasedWords, Logf: logger.Printf,
|
||||
Holders: holders, // a registry seat's holder from the seat-holders view, from the start (design 47 G A-416, A-416a)
|
||||
Started: time.Now()} // a build ended from now on is of the live class (H-A-290 (1))
|
||||
// A number a registry seat already holds is never reserved (H-A-275): read before reserving, through the seats' verb versions.
|
||||
reserved.r.HeldNumbers = func(ctx context.Context, module, fp string, refs []string) ([]string, error) {
|
||||
return republish.HeldNumbers(ctx, module, fp, refs, registryVersionsVia(calls.Call))
|
||||
reserved.r.HeldRecords = func(ctx context.Context, module, fp string, refs []string) ([]versions.HeldArtifact, error) {
|
||||
return republish.HeldRecords(ctx, module, fp, refs, registryVersionsVia(calls.Call))
|
||||
}
|
||||
reserved.r.MovedFrom = reserved.movedFrom
|
||||
republish.Unstored = reserved.unstoredAgain
|
||||
republish.AsHeld = reserved.sayPublished // an artifact held for this very build is published as held (H-A-738 (1))
|
||||
reserved.judge = func(ctx context.Context, v versions.ReservedVersion) (versions.Judged, error) {
|
||||
return republish.Held(ctx, v, registryVersionsVia(calls.Call))
|
||||
}
|
||||
// A done build whose number a registry holds elsewhere is built again at the next free number (H-A-279), on the builder's context.
|
||||
reserved.rebuild = func(_ context.Context, module, fp, why string) error {
|
||||
@@ -279,49 +294,62 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
reserved.r.HeldElsewhere = func(ctx context.Context, module string, skipped []string) {
|
||||
reserved.heldElsewhere(ctx, module, "the registries hold "+strings.Join(skipped, ", ")+", so the reserve skipped them")
|
||||
}
|
||||
publishSet, err := publishSettingsOf(getenv)
|
||||
republishMax, err := numberFile(getenv("MESH_BUILDER_REPUBLISH_MAX_FILE"), versions.DefaultRepublishMaxVersions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pq.ackWait = publishSet.PauseMax // a sent item unheard is delivered again after the longest pause (H-A-440 (1))
|
||||
pq.ackWait = time.Duration(publishAck) * time.Minute // a sent item unheard is given again after the publish bound (H-A-613 (3))
|
||||
republish.Bound = pq.ackWait // a send's calls wait that long at most, then the item is given again (H-A-613 (3), H-A-745)
|
||||
actedDays, err := numberFile(getenv("MESH_BUILDER_ACTED_DAYS_FILE"), versions.DefaultActedDays)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if actedDays > 365 {
|
||||
return fmt.Errorf("the setting acted-days is %d, at most 365", actedDays)
|
||||
}
|
||||
releasedKept, err := numberFile(getenv("MESH_BUILDER_RELEASED_KEPT_FILE"), versions.DefaultReleasedKept)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
reasksKV := process.AwaitBucket(ctx, js, conn, builds.StateBucket(cred.Module, build.ReAsksState), "builder_ask_again is not heard; an ask that can no longer be answered is still asked again by itself", logger.Printf)
|
||||
// A version's publish is the builder's own work until its release is written (design 47 G A-457a): an item of the re-ask state.
|
||||
items := &publishItems{reasks: reasksKV.KV, set: publishSet, now: time.Now, logf: logger.Printf,
|
||||
// A version's publish is the builder's own work until its release is written (design 47 G A-457a); a publish dropped by hand is
|
||||
// kept on its reservation (H-A-746).
|
||||
items := &publishItems{now: time.Now, logf: logger.Printf, unreleased: republish.Unreleased,
|
||||
dropMark: func(ctx context.Context, module, version, by, why string) error {
|
||||
found, err := reserved.r.MarkDropped(ctx, module, version, by, why, time.Now())
|
||||
if err == nil && !found {
|
||||
err = fmt.Errorf("no reservation of %s stands at %s: there is no publish to drop", module, version)
|
||||
}
|
||||
return err
|
||||
},
|
||||
reserved: func(ctx context.Context, module, version string) (versions.ReservedVersion, bool, error) {
|
||||
return reserved.r.Of(ctx, module, version)
|
||||
},
|
||||
republish: republish.Republish, endedWith: reserved.unreleased,
|
||||
republish: republish.Republish,
|
||||
// A publish is asked again while the registry's record lacks it (H-A-269 (2), H-A-272; H-A-514 addendum: no backlog count).
|
||||
judge: func(ctx context.Context, v versions.ReservedVersion) (versions.Judged, error) {
|
||||
return republish.Held(ctx, v, registryVersionsVia(calls.Call))
|
||||
},
|
||||
markHeld: reserved.markHeld, moveElsewhere: reserved.movedElsewhere,
|
||||
allDone: func(ctx context.Context) ([]versions.ReservedVersion, error) { return reserved.r.All(ctx) },
|
||||
send: republish.SendQueued,
|
||||
retired: reserved.r.Retired} // only each module's newest done build is asked at the start (H-A-291 (1))
|
||||
send: republish.SendQueued}
|
||||
// A version that never publishes (withdrawn or taken over) has its publish item ended by the queue too (H-A-290 (2)).
|
||||
republish.Ended = items.Ended
|
||||
pq.take = items.take
|
||||
// At the start, a built reservation the catalog holds released is taken in as its version-released would (H-A-484 addendum),
|
||||
// before the publish items of the rest are asked.
|
||||
reasksKV.Ready(func(jetstream.KeyValue) {
|
||||
reasksKV.Ready(func(kv jetstream.KeyValue) {
|
||||
carryDrops(ctx, kv, reserved.r, logger.Printf) // before any event is heard: a drop made before is kept (H-A-749)
|
||||
reserved.releasedAtStart(ctx)
|
||||
items.AskAllDone(ctx)
|
||||
})
|
||||
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)
|
||||
}
|
||||
// builder_reserve_done: a done trunk build that reserved none is given a version, and its publish queued as publish again does.
|
||||
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{awaitedState{b: actedKV, bucket: own.acted}}
|
||||
retakeActed := markLifetime{awaitedReserved{awaitedState{b: actedKV, bucket: own.acted}}, actedDays, js}
|
||||
actedKV.Ready(func(kv jetstream.KeyValue) { deleteUnknown(ctx, kv, logger.Printf) })
|
||||
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}
|
||||
@@ -331,6 +359,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
if err := operator.Listen(); err != nil {
|
||||
return fmt.Errorf("hearing the operator's answers: %w", err)
|
||||
}
|
||||
again := &publishingAgain{a: &versions.Againer{Republisher: republish, Acted: retakeActed, MaxVersions: republishMax, Nodes: branches.SeatHolderNodes(ctx)}}
|
||||
retake := &retaking{rt: &build.Retaker{Builder: b, Acted: retakeActed, Entry: entryVia(calls.Call), Ask: operator.Ask, Logf: logger.Printf}}
|
||||
// What waits on the work queue is pulled, and the old state's items are put on it once (§793).
|
||||
go func() {
|
||||
@@ -469,6 +498,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
takers := []eventTaker{
|
||||
{"the operator's answer to an ask about a key", decided.heard}, // §568
|
||||
{"the retake of a key failed on a transport fault", func(m jetstream.Msg) bool { return retake.heard(ctx, m, logger.Printf) }}, // §568
|
||||
{"the publish again of reserved versions", func(m jetstream.Msg) bool { return again.heard(ctx, m, logger.Printf) }}, // ADR 0674 §2
|
||||
{"what a node's engine reads", func(m jetstream.Msg) bool { return reads.heard(m, logger.Printf) }}, // manifest-reads-changed (ADR 0618 §4)
|
||||
{"the toolchains reported", func(m jetstream.Msg) bool { return heardTools.Reported(ctx, m) }},
|
||||
{"the toolchains running", func(m jetstream.Msg) bool { return heardTools.Running(ctx, m) }},
|
||||
@@ -476,9 +506,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
{"the registry seats' outcomes", func(m jetstream.Msg) bool { return seatHeard.heard(ctx, m) }},
|
||||
}
|
||||
gone := eventTaker{"the artifacts gone", func(m jetstream.Msg) bool { heardGone(ctx, b, m, logger.Printf); return true }}
|
||||
// Each event goes to a worker of the name it carries, one name's events in order, the names side by side (H-A-514 addenda).
|
||||
workers := &eventWorkers{keyOf: eventKey, handle: func(m jetstream.Msg) { takeEvent(m, takers, gone, slow, nil, logger.Printf) }}
|
||||
events := workers.take
|
||||
// The hub holds each event under its key (eventKey), one key's events in order, the keys side by side (H-A-683 (1), H-A-737 (1)).
|
||||
events := func(m jetstream.Msg) { takeEvent(m, takers, gone, slow, nil, logger.Printf) }
|
||||
// The seats' events (artifacts-gone, the registry seats' words, the build seats' toolchain-reported, the indexer's take-in.taken and
|
||||
// manifest-reads-changed and the seat mesh-conditions' condition-cleared: seatEventPatterns); the owners' views events and the
|
||||
// catalog half's catalog-revision and registration-changed and the gate's source-moved are the views reader's (a message has
|
||||
@@ -527,7 +556,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
seatGate.Follow(seatlist.ProcessBus(calls.Call, aged), func() { seatsChanged(ctx); b.SayUnbuildable(ctx) }, logger.Printf)
|
||||
half.holders = func() { seatsChanged(ctx) }
|
||||
for _, pattern := range seatEventPatterns {
|
||||
if err := aged.Handle(pattern, events); err != nil {
|
||||
if err := aged.HandleByKey(pattern, eventKey, events); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
+611
-30
@@ -16,12 +16,15 @@ import (
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
gitseat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/git"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/gopackageregistry"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatlist"
|
||||
"git.novox.be/novox/mesh-sdk/go/testbus"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
|
||||
@@ -46,12 +49,11 @@ func TestThePublishQueueLosesNoItemAndNeverSendsADroppedItem(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// One consumer per holder (H-A-483 and its addenda): the holder's class durables of an earlier release are retired, the item
|
||||
// one of them held unacknowledged reaches the one consumer; no item is lost; a failed send comes back after its pause, and a
|
||||
// live item put while it waits is sent before it returns; a dropped item never comes back.
|
||||
// one of them held unacknowledged reaches the one consumer; no item is lost; a failed send ends its item and is never sent again
|
||||
// on a timer; a dropped item never comes back.
|
||||
t.Run("one consumer", func(t *testing.T) {
|
||||
const holder, pause = "paused", 3 * time.Second // the pause is far longer than a send of an item put now
|
||||
const holder = "paused"
|
||||
bound := testbus.SetupBound(t)
|
||||
kv := &itemKV{vals: map[string][]byte{}, revs: map[string]uint64{}}
|
||||
type send struct {
|
||||
module string
|
||||
at time.Time
|
||||
@@ -59,7 +61,7 @@ func TestThePublishQueueLosesNoItemAndNeverSendsADroppedItem(t *testing.T) {
|
||||
var mu sync.Mutex
|
||||
published, failed := map[string]bool{}, map[string]bool{}
|
||||
sentCh := make(chan send, 16)
|
||||
items := &publishItems{reasks: func() jetstream.KeyValue { return kv }, set: publishSettings{Pause: pause, PauseMax: time.Minute, Tries: 5},
|
||||
items := &publishItems{dropMark: func(context.Context, string, string, string, string) error { return nil },
|
||||
now: time.Now, logf: t.Logf,
|
||||
reserved: func(_ context.Context, m, v string) (versions.ReservedVersion, bool, error) {
|
||||
mu.Lock()
|
||||
@@ -109,22 +111,20 @@ func TestThePublishQueueLosesNoItemAndNeverSendsADroppedItem(t *testing.T) {
|
||||
}
|
||||
return send{}
|
||||
}
|
||||
// The two class durables an earlier release made, the live one holding an item given and not acknowledged.
|
||||
for _, class := range []string{versions.PublishClassLive, versions.PublishClassStart} {
|
||||
if _, err := b.js.CreateOrUpdateConsumer(ctx, bind.Stream, jetstream.ConsumerConfig{Durable: publishesConsumer(holder) + "-" + class,
|
||||
FilterSubject: bind.Subject + ".publish." + holder + "." + class + ".>", AckPolicy: jetstream.AckExplicitPolicy, AckWait: time.Hour}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The one durable an earlier build made, holding an item given and not acknowledged (H-A-700 (2)).
|
||||
if _, err := b.js.CreateOrUpdateConsumer(ctx, bind.Stream, jetstream.ConsumerConfig{Durable: publishesOneConsumer(holder),
|
||||
FilterSubject: bind.Subject + ".publish." + holder + ".>", AckPolicy: jetstream.AckExplicitPolicy, AckWait: time.Hour}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
put("given", versions.PublishClassLive)
|
||||
old, err := b.js.Consumer(ctx, bind.Stream, publishesConsumer(holder)+"-"+versions.PublishClassLive)
|
||||
old, err := b.js.Consumer(ctx, bind.Stream, publishesOneConsumer(holder))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if m, err := old.Next(); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if md, _ := m.Metadata(); md.NumDelivered != 1 {
|
||||
t.Fatalf("the old live durable gave %+v", md)
|
||||
t.Fatalf("the old durable gave %+v", md)
|
||||
}
|
||||
pq.learn(ctx, holder)
|
||||
stream, err := b.js.Stream(ctx, bind.Stream)
|
||||
@@ -133,38 +133,68 @@ func TestThePublishQueueLosesNoItemAndNeverSendsADroppedItem(t *testing.T) {
|
||||
}
|
||||
var names []string
|
||||
for n := range stream.ConsumerNames(ctx).Name() {
|
||||
if strings.HasPrefix(n, publishesConsumer(holder)) {
|
||||
if strings.HasPrefix(n, publishesOneConsumer(holder)) {
|
||||
names = append(names, n)
|
||||
}
|
||||
}
|
||||
if !slices.Equal(names, []string{publishesConsumer(holder)}) {
|
||||
t.Fatalf("the consumers of %s are %v, want only %s: the class durables retired", holder, names, publishesConsumer(holder))
|
||||
want := []string{publishesConsumer(holder, versions.PublishClassLive), publishesConsumer(holder, versions.PublishClassStart)}
|
||||
slices.Sort(names)
|
||||
slices.Sort(want)
|
||||
if !slices.Equal(names, want) {
|
||||
t.Fatalf("the consumers of %s are %v, want %v: the one durable removed", holder, names, want)
|
||||
}
|
||||
// H-A-719, H-A-700 (1), H-A-620 (2): each of the two carries the stream's maximum age as its inactive threshold; four live sends
|
||||
// in flight and one again.
|
||||
sinfo, err := stream.Info(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for class, inflight := range map[string]int{versions.PublishClassLive: 4, versions.PublishClassStart: 1} {
|
||||
c, err := b.js.Consumer(ctx, bind.Stream, publishesConsumer(holder, class))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
info, err := c.Info(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if info.Config.InactiveThreshold != sinfo.Config.MaxAge || sinfo.Config.MaxAge == 0 || info.Config.MaxAckPending != inflight {
|
||||
t.Fatalf("%s: inactive threshold %s (stream max age %s), %d in flight, want the stream's max age and %d", class, info.Config.InactiveThreshold, sinfo.Config.MaxAge, info.Config.MaxAckPending, inflight)
|
||||
}
|
||||
}
|
||||
if s := next(); s.module != "given" {
|
||||
t.Fatalf("sent %s first, want the item the old durable held unacknowledged", s.module)
|
||||
}
|
||||
put("fail", versions.PublishClassStart)
|
||||
put("dropme", versions.PublishClassStart)
|
||||
var firstFail time.Time
|
||||
for range 2 {
|
||||
if s := next(); s.module == "fail" {
|
||||
firstFail = s.at
|
||||
}
|
||||
for range 2 { // the first send of each fails: its item ends, the version stays reserved, nothing hands it back after a pause (H-A-606)
|
||||
next()
|
||||
}
|
||||
put("live", versions.PublishClassLive) // put while both failed items wait out their pause
|
||||
put("live", versions.PublishClassLive)
|
||||
if s := next(); s.module != "live" {
|
||||
t.Fatalf("sent %s, want the live item put while the failed ones wait their pause", s.module)
|
||||
t.Fatalf("sent %s, want the live item put after the failed ones", s.module)
|
||||
}
|
||||
// design 47 H2 H-A-654, H-A-703: the consumer deleted under a running dispatch and made again, the dispatch binds again on the
|
||||
// bus's created advisory and sends the next item.
|
||||
if err := b.js.DeleteConsumer(ctx, bind.Stream, publishesConsumer(holder, versions.PublishClassLive)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := b.js.CreateOrUpdateConsumer(ctx, bind.Stream, jetstream.ConsumerConfig{Durable: publishesConsumer(holder, versions.PublishClassLive),
|
||||
FilterSubject: bind.Subject + ".publish." + holder + ".live.>", AckPolicy: jetstream.AckExplicitPolicy, AckWait: time.Minute,
|
||||
MaxAckPending: 4, MaxDeliver: publishesMaxDeliver}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
put("rebound", versions.PublishClassLive)
|
||||
if s := next(); s.module != "rebound" {
|
||||
t.Fatalf("sent %s, want the item put after the consumer was made again", s.module)
|
||||
}
|
||||
if answer, err := pq.drop(ctx, items, "dropme", "0.1.0", "op@node", "a test drops it"); err != nil {
|
||||
t.Fatalf("drop: %v", err)
|
||||
} else {
|
||||
t.Log(answer)
|
||||
}
|
||||
if s := next(); s.module != "fail" || s.at.Sub(firstFail) < pause {
|
||||
t.Fatalf("sent %s %s after the failed send, want fail again after its pause %s", s.module, s.at.Sub(firstFail), pause)
|
||||
}
|
||||
// Every item is acknowledged and the dropped one is gone: nothing is left to come back.
|
||||
c, err := b.js.Consumer(ctx, bind.Stream, publishesConsumer(holder))
|
||||
c, err := b.js.Consumer(ctx, bind.Stream, publishesConsumer(holder, versions.PublishClassLive))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -197,12 +227,11 @@ func TestThePublishQueueLosesNoItemAndNeverSendsADroppedItem(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("the queue, the move, tags and backlog", func(t *testing.T) {
|
||||
kv := &itemKV{vals: map[string][]byte{}, revs: map[string]uint64{}}
|
||||
var mu sync.Mutex
|
||||
var sent []string
|
||||
published := map[string]bool{} // the modules whose publish is heard
|
||||
sentCh := make(chan string, 200)
|
||||
items := &publishItems{reasks: func() jetstream.KeyValue { return kv }, set: publishSettings{Pause: time.Second, PauseMax: time.Minute, Tries: 5},
|
||||
items := &publishItems{dropMark: func(context.Context, string, string, string, string) error { return nil },
|
||||
now: time.Now, logf: t.Logf,
|
||||
reserved: func(_ context.Context, m, v string) (versions.ReservedVersion, bool, error) {
|
||||
mu.Lock()
|
||||
@@ -248,7 +277,7 @@ func TestThePublishQueueLosesNoItemAndNeverSendsADroppedItem(t *testing.T) {
|
||||
if err := pq.learnAll(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for range 4 { // the items in flight: at most four held unacknowledged, their publish unheard
|
||||
for range 1 { // the again items in flight: at most one held unacknowledged, its publish unheard (H-A-620 (2))
|
||||
select {
|
||||
case <-sentCh:
|
||||
case <-time.After(30 * time.Second):
|
||||
@@ -466,4 +495,556 @@ func TestThePublishQueueLosesNoItemAndNeverSendsADroppedItem(t *testing.T) {
|
||||
t.Errorf("the health four minutes in = %+v, want healthy", a)
|
||||
}
|
||||
})
|
||||
// Design 47 H2 H-A-613 (4), H-A-620 (3), H-A-593 (5), H-A-588 to H-A-590 (whole, against the bus and a fake registry holder): the
|
||||
// builder's reserving, its publish items and its work queue as main joins them, the publish a kept call through a process
|
||||
// connection to a holder on the bus, which answers `versions` with each version's digest and kept fingerprint and `publish` as the
|
||||
// seats do (held, other bytes, a refusal). A publish met by no responders is called again and passes once the holder answers; a
|
||||
// refused one is ended and waits for the next running; a build whose two of three artifacts a holder holds for its fingerprint
|
||||
// stores the third and releases the same number; the same with no fingerprint kept withdraws the number, builds again and releases
|
||||
// the next number, clearing version-held-elsewhere; other bytes of another build end the item at once.
|
||||
t.Run("a publish is a kept call and a registry's record is read", func(t *testing.T) {
|
||||
const holder, fpOf = "goreg", "src2:"
|
||||
reg := &fakeRegistry{held: map[string]map[string]heldRecord{}, away: true, firstAway: make(chan struct{}, 1)}
|
||||
reg.listen(t, b.js.Conn())
|
||||
conn, err := process.Connect(process.Account{URL: b.srvURL, Module: "mesh-delivery-builder", User: "ctl", Password: "pw"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
entries := map[string]meshcatalog.CatalogEntry{}
|
||||
entryOf := func(module, fp string, arts ...string) {
|
||||
e := meshcatalog.CatalogEntry{Module: module, Fp: fp}
|
||||
for _, a := range arts {
|
||||
e.Artifacts = append(e.Artifacts, meshcatalog.Artifact{Ref: module + ":" + a, Kind: versions.KindPackage, Language: "go",
|
||||
Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "x.example/" + module + "/" + a}})
|
||||
}
|
||||
entries[fp] = e
|
||||
}
|
||||
call := func(string, any) (json.RawMessage, error) {
|
||||
return json.Marshal(meshcatalog.VersionsAnswer{Module: "m"})
|
||||
}
|
||||
found := &memFindings{vals: map[string][]byte{}}
|
||||
rv := newReservations(&lockedReserve{memReserve: &memReserve{vals: map[string][]byte{}, revs: map[string]uint64{}}}, call,
|
||||
func() jetstream.KeyValue { return nil },
|
||||
&findings{module: builds.BuilderModule, w: found, logf: t.Logf, now: time.Now}, t.Logf)
|
||||
rv.say = func(context.Context, meshbuilds.PackagePublished) error { return nil }
|
||||
pq := &publishQueue{js: b.js, ackWait: time.Minute, logf: t.Logf, binding: publishesOf("mesh-delivery-builder")}
|
||||
republish := &versions.Republisher{Reserved: rv.r, Put: pq.put, Logf: t.Logf, Started: time.Now(),
|
||||
Entry: func(_ context.Context, fp string) (meshcatalog.CatalogEntry, error) {
|
||||
if e, ok := entries[fp]; ok {
|
||||
return e, nil
|
||||
}
|
||||
return meshcatalog.CatalogEntry{}, fmt.Errorf("no entry %s", fp)
|
||||
},
|
||||
Send: sendVia(conn.CallKeptAsk, publishUnanswered(ctx, &findings{module: builds.BuilderModule, w: found, logf: t.Logf, now: time.Now})),
|
||||
Unreleased: rv.unreleasedWords, Holders: func(string) []string { return []string{holder} }}
|
||||
rv.r.HeldRecords = func(ctx context.Context, module, fp string, refs []string) ([]versions.HeldArtifact, error) {
|
||||
return republish.HeldRecords(ctx, module, fp, refs, registryVersionsVia(conn.Call))
|
||||
}
|
||||
rv.r.MovedFrom = rv.movedFrom
|
||||
republish.Unstored = rv.unstoredAgain
|
||||
republish.AsHeld = rv.sayPublished
|
||||
rv.judge = func(ctx context.Context, v versions.ReservedVersion) (versions.Judged, error) {
|
||||
return republish.Held(ctx, v, registryVersionsVia(conn.Call))
|
||||
}
|
||||
rv.r.HeldElsewhere = func(ctx context.Context, module string, skipped []string) {
|
||||
rv.heldElsewhere(ctx, module, "the registries hold "+strings.Join(skipped, ", ")+", so the reserve skipped them")
|
||||
}
|
||||
items := &publishItems{now: time.Now, logf: t.Logf, unreleased: republish.Unreleased, republish: republish.Republish,
|
||||
dropMark: func(context.Context, string, string, string, string) error { return nil },
|
||||
reserved: func(ctx context.Context, module, version string) (versions.ReservedVersion, bool, error) {
|
||||
return rv.r.Of(ctx, module, version)
|
||||
},
|
||||
judge: rv.judge, markHeld: rv.markHeld, moveElsewhere: rv.movedElsewhere, send: republish.SendQueued}
|
||||
republish.Ended = items.Ended
|
||||
pq.take = items.take
|
||||
wirePublishItems(rv, items, &lockedReserve{memReserve: &memReserve{vals: map[string][]byte{}, revs: map[string]uint64{}}}, versions.DefaultReleasedKept)
|
||||
// The publish again hears the node-engine seat's events from the bus, as the builder's events consumer gives them (H-A-606, ADR 0674 §2):
|
||||
// the registry holder's module runs on the node ace, and its catalog entry serves the registry seat.
|
||||
entries[fpOf+holder] = meshcatalog.CatalogEntry{Module: holder, Fp: fpOf + holder, Serves: []string{versions.SeatGoPackages + ".publish"}}
|
||||
againer := &publishingAgain{a: &versions.Againer{Republisher: republish, Acted: &lockedReserve{memReserve: &memReserve{vals: map[string][]byte{}, revs: map[string]uint64{}}},
|
||||
Nodes: func(seat string) []seatlist.HolderNode {
|
||||
if seat == versions.SeatGoPackages {
|
||||
return []seatlist.HolderNode{{Module: holder, Node: "ace"}}
|
||||
}
|
||||
return nil
|
||||
}}}
|
||||
handled := make(chan uint64, 16)
|
||||
engineEvents, err := b.js.CreateOrUpdateConsumer(ctx, eventsStream, jetstream.ConsumerConfig{Durable: "publish-again-test", AckPolicy: jetstream.AckExplicitPolicy,
|
||||
DeliverPolicy: jetstream.DeliverNewPolicy, FilterSubjects: []string{nodeengine.SubjectRunningAll, nodeengine.SubjectManifestReadsChanged("*")}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
hearing, err := engineEvents.Consume(func(m jetstream.Msg) {
|
||||
againer.heard(ctx, m, t.Logf)
|
||||
_ = m.Ack()
|
||||
if md, err := m.Metadata(); err == nil {
|
||||
handled <- md.Sequence.Stream
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer hearing.Stop()
|
||||
// said puts one event of the node-engine seat on the bus and waits until the publish again has handled it; it answers its stream sequence.
|
||||
said := func(subject string, body any) uint64 {
|
||||
t.Helper()
|
||||
data, _ := json.Marshal(body)
|
||||
ack, err := b.js.Publish(ctx, subject, data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for bound := time.After(testbus.SetupBound(t)); ; {
|
||||
select {
|
||||
case seq := <-handled:
|
||||
if seq == ack.Sequence {
|
||||
return seq
|
||||
}
|
||||
case <-bound:
|
||||
t.Fatalf("the publish again did not handle %s", subject)
|
||||
}
|
||||
}
|
||||
}
|
||||
returned := func() uint64 {
|
||||
return said(nodeengine.SubjectManifestReadsChanged("ace"), nodeengine.ManifestReadsChanged{Node: "ace", Why: nodeengine.ManifestReadsChangedWhyReturned})
|
||||
}
|
||||
// build is the reserve and the end of a build of module at fp: its digests are built+artifact.
|
||||
build := func(module, fp, built string, arts ...string) versions.ReservedVersion {
|
||||
t.Helper()
|
||||
var refs []string
|
||||
digests := map[string]string{}
|
||||
for _, a := range arts {
|
||||
refs = append(refs, module+":"+a)
|
||||
digests[module+":"+a] = "sha256:" + built + a
|
||||
}
|
||||
res, err := rv.Reserve(ctx, module, "0.1", refs, versions.Source{Fingerprint: fp})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := rv.Built(ctx, module, res.Version, digests, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return res
|
||||
}
|
||||
stored := func(module, version, a string) string { return reg.digest("x.example/"+module+"/"+a, version) }
|
||||
|
||||
// H-A-613 (4): the first call finds no responders; the holder answers, and the publish passes, called again by itself.
|
||||
entryOf("kept", fpOf+"k", "a")
|
||||
build("kept", fpOf+"k", "k", "a")
|
||||
select {
|
||||
case <-reg.firstAway:
|
||||
case <-time.After(testbus.SetupBound(t)):
|
||||
t.Fatal("the publish was not called")
|
||||
}
|
||||
reg.answer()
|
||||
reg.await(t, "x.example/kept/a", "0.1.0")
|
||||
if got := reg.callsOf("x.example/kept/a"); got < 2 {
|
||||
t.Errorf("the publish was called %d times, want it met by no responders and called again", got)
|
||||
}
|
||||
reg.published(t, rv, "x.example/kept/a", "0.1.0") // its publish heard: the item is acknowledged
|
||||
reg.settle(t, b.js, bind.Stream, holder, func() { items.heard(ctx, "kept", "0.1.0") })
|
||||
|
||||
// H-A-613 (4): an answered refusal ends the send; nothing calls again; the next running puts it again and it passes.
|
||||
entryOf("refused", fpOf+"r", "a")
|
||||
reg.refuse("x.example/refused/a", "the cap")
|
||||
build("refused", fpOf+"r", "r", "a")
|
||||
reg.await(t, "x.example/refused/a", "0.1.0")
|
||||
reg.settle(t, b.js, bind.Stream, holder, nil)
|
||||
if got := reg.callsOf("x.example/refused/a"); got != 1 {
|
||||
t.Errorf("the refused publish was called %d times, want once: it waits for the next running", got)
|
||||
}
|
||||
reg.refuse("x.example/refused/a", "")
|
||||
// The holder's running, heard from the bus, puts it again once, as an item of the class again (H-A-606, H-A-613 (1), H-A-620 (1)).
|
||||
liveBefore, againBefore := delivered(t, b.js, bind.Stream, holder, versions.PublishClassLive), delivered(t, b.js, bind.Stream, holder, versions.PublishClassStart)
|
||||
said(nodeengine.SubjectRunning("ace", holder), nodeengine.Running{Module: holder, Node: "ace", Fingerprint: fpOf + holder})
|
||||
reg.await(t, "x.example/refused/a", "0.1.0")
|
||||
if got := stored("refused", "0.1.0", "a"); got != "sha256:ra" {
|
||||
t.Errorf("the refused publish put again stored %q, want sha256:ra", got)
|
||||
}
|
||||
reg.published(t, rv, "x.example/refused/a", "0.1.0")
|
||||
reg.settle(t, b.js, bind.Stream, holder, func() { items.heard(ctx, "refused", "0.1.0") })
|
||||
if l, a := delivered(t, b.js, bind.Stream, holder, versions.PublishClassLive), delivered(t, b.js, bind.Stream, holder, versions.PublishClassStart); l != liveBefore || a != againBefore+1 {
|
||||
t.Errorf("the running put %d live and %d again items, want one item of the class again", l-liveBefore, a-againBefore)
|
||||
}
|
||||
|
||||
// H-A-620 (1) (AC-B8a): two returns of one holder queue a version once while its send runs: the holder is away, the first return puts
|
||||
// the version and its send waits at the kept call's pace, the second finds the version held by the work queue and puts nothing.
|
||||
entryOf("twice", fpOf+"t", "a")
|
||||
reg.refuse("x.example/twice/a", "the cap")
|
||||
build("twice", fpOf+"t", "t", "a")
|
||||
reg.await(t, "x.example/twice/a", "0.1.0")
|
||||
reg.settle(t, b.js, bind.Stream, holder, nil)
|
||||
reg.refuse("x.example/twice/a", "")
|
||||
reg.goAway()
|
||||
againBefore = delivered(t, b.js, bind.Stream, holder, versions.PublishClassStart)
|
||||
returned()
|
||||
select {
|
||||
case <-reg.firstAway:
|
||||
case <-time.After(testbus.SetupBound(t)):
|
||||
t.Fatal("the first return did not put the version")
|
||||
}
|
||||
returned()
|
||||
if st, err := b.js.Stream(ctx, bind.Stream); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if info, err := st.Info(ctx, jetstream.WithSubjectFilter(bind.Subject+".publish."+holder+".again."+versions.EscapeToken("twice")+".>")); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if n := func() (n uint64) {
|
||||
for _, c := range info.State.Subjects {
|
||||
n += c
|
||||
}
|
||||
return
|
||||
}(); n != 1 {
|
||||
t.Errorf("two returns left %d items of twice on the work queue (%v), want one", n, info.State.Subjects)
|
||||
}
|
||||
reg.answer()
|
||||
reg.await(t, "x.example/twice/a", "0.1.0")
|
||||
reg.published(t, rv, "x.example/twice/a", "0.1.0")
|
||||
reg.settle(t, b.js, bind.Stream, holder, func() { items.heard(ctx, "twice", "0.1.0") })
|
||||
if got := delivered(t, b.js, bind.Stream, holder, versions.PublishClassStart); got != againBefore+1 {
|
||||
t.Errorf("two returns made %d deliveries of again items, want one", got-againBefore)
|
||||
}
|
||||
|
||||
// H-A-593 (5): a build of F publishes two of three artifacts at V and fails on the third (the holder refuses it). Built again, the
|
||||
// two held for F keep their held digests, the third is stored and V is released, with no refusal and no new number.
|
||||
entryOf("three", fpOf+"3", "a", "b", "c")
|
||||
reg.refuse("x.example/three/c", "the cap")
|
||||
res := build("three", fpOf+"3", "first-", "a", "b", "c")
|
||||
reg.await(t, "x.example/three/c", res.Version)
|
||||
reg.settle(t, b.js, bind.Stream, holder, nil)
|
||||
for _, a := range []string{"a", "b"} {
|
||||
if got := stored("three", res.Version, a); got != "sha256:first-"+a {
|
||||
t.Fatalf("%s of three at %s is held at %q, want what the first run stored", a, res.Version, got)
|
||||
}
|
||||
}
|
||||
reg.refuse("x.example/three/c", "")
|
||||
republish.Started = time.Now().Add(time.Hour) // the build again is of a run before the next: its put is of the start class
|
||||
again, err := rv.Reserve(ctx, "three", "0.1", []string{"three:a", "three:b", "three:c"}, versions.Source{Fingerprint: fpOf + "3"})
|
||||
if err != nil || again.Version != res.Version {
|
||||
t.Fatalf("the build of three again reserved %q (%v), want the standing %s", again.Version, err, res.Version)
|
||||
}
|
||||
rv.MarkRegistryHeld(ctx, again) // before a build module is asked again (H-A-588 (4))
|
||||
if err := rv.Built(ctx, "three", res.Version, map[string]string{"three:c": "sha256:again-c"}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
reg.await(t, "x.example/three/c", res.Version)
|
||||
reg.published(t, rv, "x.example/three/c", res.Version)
|
||||
reg.settle(t, b.js, bind.Stream, holder, func() { items.heard(ctx, "three", res.Version) })
|
||||
cur, ok, _ := rv.r.Of(ctx, "three", "")
|
||||
if !ok || cur.Version != res.Version || len(cur.Withdrawn) != 0 || len(cur.Missing()) != 0 || cur.Artifacts["three:a"] != "sha256:first-a" || cur.Artifacts["three:c"] != "sha256:again-c" {
|
||||
t.Errorf("three stands %+v, want %s with every artifact published, the held digests of a and b and the third stored, and no number withdrawn", cur, res.Version)
|
||||
}
|
||||
if got := reg.callsOf("x.example/three/a"); got != 1 {
|
||||
t.Errorf("a of three was published %d times, want once: the second run answered it from the registry's record", got)
|
||||
}
|
||||
|
||||
// H-A-593 (5): the same with no fingerprint kept withdraws V, builds again and releases the next number, clearing
|
||||
// version-held-elsewhere at that release.
|
||||
entryOf("bare", fpOf+"b", "a", "b", "c")
|
||||
rv.rebuild = func(ctx context.Context, module, fp, _ string) error {
|
||||
var refs []string
|
||||
digests := map[string]string{}
|
||||
for _, a := range []string{"a", "b", "c"} {
|
||||
refs = append(refs, module+":"+a)
|
||||
digests[module+":"+a] = "sha256:next-" + a
|
||||
}
|
||||
again, err := rv.Reserve(ctx, module, "0.1", refs, versions.Source{Fingerprint: fp, Rebuild: true})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return rv.Built(ctx, module, again.Version, digests, nil)
|
||||
}
|
||||
first := func() versions.ReservedVersion {
|
||||
res, err := rv.Reserve(ctx, "bare", "0.1", []string{"bare:a", "bare:b", "bare:c"}, versions.Source{Fingerprint: fpOf + "b"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return res
|
||||
}()
|
||||
reg.hold("x.example/bare/a", first.Version, "sha256:old-a", "")
|
||||
reg.hold("x.example/bare/b", first.Version, "sha256:old-b", "")
|
||||
if err := rv.Built(ctx, "bare", first.Version, map[string]string{"bare:a": "sha256:mine-a", "bare:b": "sha256:mine-b", "bare:c": "sha256:mine-c"}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
reg.await(t, "x.example/bare/c", "0.1.1")
|
||||
raised := func() bool {
|
||||
for k := range found.vals {
|
||||
if strings.Contains(k, versions.VersionHeldElsewhere) && strings.Contains(k, "bare") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
if !raised() {
|
||||
t.Errorf("no version-held-elsewhere raised about bare: %v", found.vals)
|
||||
}
|
||||
if got := reg.digest("x.example/bare/a", first.Version); got != "sha256:old-a" {
|
||||
t.Errorf("a of bare at %s is held at %q, want what the holder held, never overwritten", first.Version, got)
|
||||
}
|
||||
for _, a := range []string{"a", "b", "c"} {
|
||||
reg.published(t, rv, "x.example/bare/"+a, "0.1.1")
|
||||
}
|
||||
if err := rv.release(ctx, meshcatalog.VersionReleasedEvent{V: 1, Module: "bare", Version: "0.1.1"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if raised() {
|
||||
t.Errorf("version-held-elsewhere still raised about bare after its release: %v", found.vals)
|
||||
}
|
||||
reg.settle(t, b.js, bind.Stream, holder, func() { items.heard(ctx, "bare", "0.1.1") })
|
||||
|
||||
// H-A-588, H-A-590: a holder answering other bytes of another build ends the item at once, its tries unspent: it is called once.
|
||||
entryOf("other", fpOf+"o", "a")
|
||||
res, err = rv.Reserve(ctx, "other", "0.1", []string{"other:a"}, versions.Source{Fingerprint: fpOf + "o"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
reg.hold("x.example/other/a", res.Version, "sha256:theirs", fpOf+"another")
|
||||
reg.hide("x.example/other/a") // the record is not read, so the item is sent and the holder answers other bytes (H-A-729)
|
||||
if err := rv.Built(ctx, "other", res.Version, map[string]string{"other:a": "sha256:mine"}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
reg.await(t, "x.example/other/a", res.Version)
|
||||
// The item is ended at once, never held for its publish nor left on either durable (H-A-593 (5), H-A-729): the build is of a run
|
||||
// before the last start here, so its item is of the class again, which the settle reads as the live class.
|
||||
reg.settle(t, b.js, bind.Stream, holder, nil)
|
||||
if st, err := b.js.Stream(ctx, bind.Stream); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if info, err := st.Info(ctx, jetstream.WithSubjectFilter(bind.Subject+".publish."+holder+".*.other.>")); err != nil || len(info.State.Subjects) != 0 {
|
||||
t.Errorf("after other bytes the work queue holds %v (%v) of the item, want it terminated", info.State.Subjects, err)
|
||||
}
|
||||
if got := reg.callsOf("x.example/other/a"); got != 1 {
|
||||
t.Errorf("other bytes of another build: called %d times, want once", got)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// lockedReserve is the unit tests' reservations store, safe for the pull goroutines of a queue and a test at once.
|
||||
type lockedReserve struct {
|
||||
mu sync.Mutex
|
||||
*memReserve
|
||||
}
|
||||
|
||||
func (l *lockedReserve) Get(ctx context.Context, key string) ([]byte, uint64, bool, error) {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
return l.memReserve.Get(ctx, key)
|
||||
}
|
||||
func (l *lockedReserve) Create(ctx context.Context, key string, v []byte) (uint64, error) {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
return l.memReserve.Create(ctx, key, v)
|
||||
}
|
||||
func (l *lockedReserve) Update(ctx context.Context, key string, v []byte, rev uint64) (uint64, error) {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
return l.memReserve.Update(ctx, key, v, rev)
|
||||
}
|
||||
func (l *lockedReserve) KeysOf(ctx context.Context, filter string) ([]string, error) {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
return l.memReserve.KeysOf(ctx, filter)
|
||||
}
|
||||
func (l *lockedReserve) Delete(ctx context.Context, key string) error {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
return l.memReserve.Delete(ctx, key)
|
||||
}
|
||||
|
||||
// heldRecord is what a fake registry holder keeps of one name at one version: its digest and the fingerprint it keeps (none: "").
|
||||
type heldRecord struct{ digest, fingerprint string }
|
||||
|
||||
// fakeRegistry is a registry seat's holder on the bus (the seat go-package-registry): it answers `versions` with each version's digest
|
||||
// and kept fingerprint, and `publish` as the seats do: stored when it holds nothing there, held for the same digest, other bytes
|
||||
// (with the kept fingerprint) for another digest, or a refusal in words. While away it answers as the bus does when no one is
|
||||
// listening (a 503 status without data), which the caller meets as no responders.
|
||||
type fakeRegistry struct {
|
||||
mu sync.Mutex
|
||||
held map[string]map[string]heldRecord // name -> version -> record
|
||||
away bool
|
||||
firstAway chan struct{}
|
||||
refused map[string]string // name -> the words it is refused in
|
||||
hidden map[string]bool
|
||||
calls map[string]int
|
||||
answered chan string // "<name> <version>" of each publish answered, not away
|
||||
}
|
||||
|
||||
func (r *fakeRegistry) listen(t *testing.T, nc *nats.Conn) {
|
||||
t.Helper()
|
||||
r.answered = make(chan string, 64)
|
||||
sub, err := nc.Subscribe("mesh.seat."+versions.SeatGoPackages+".call.>", func(m *nats.Msg) {
|
||||
reply := func(result any, words string) {
|
||||
data, _ := json.Marshal(map[string]any{"result": result, "error": words, "node": "ctl"})
|
||||
_ = m.Respond(data)
|
||||
}
|
||||
switch strings.Split(m.Subject, ".")[4] {
|
||||
case "versions":
|
||||
var in struct{ Name string }
|
||||
_ = json.Unmarshal(m.Data, &in)
|
||||
r.mu.Lock()
|
||||
list := []map[string]string{}
|
||||
if !r.hidden[in.Name] {
|
||||
for v, rec := range r.held[in.Name] {
|
||||
list = append(list, map[string]string{"version": v, "digest": rec.digest, "fingerprint": rec.fingerprint})
|
||||
}
|
||||
}
|
||||
r.mu.Unlock()
|
||||
reply(map[string]any{"versions": list}, "")
|
||||
case "publish":
|
||||
var in gopackageregistry.PublishInput
|
||||
_ = json.Unmarshal(m.Data, &in)
|
||||
r.mu.Lock()
|
||||
if r.calls == nil {
|
||||
r.calls = map[string]int{}
|
||||
}
|
||||
r.calls[in.Name]++
|
||||
if r.away {
|
||||
r.mu.Unlock()
|
||||
select {
|
||||
case r.firstAway <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
_ = m.RespondMsg(&nats.Msg{Header: nats.Header{"Status": {"503"}}})
|
||||
return
|
||||
}
|
||||
var answer gopackageregistry.PublishAnswer
|
||||
words := r.refused[in.Name]
|
||||
if rec, ok := r.held[in.Name][in.Version]; words == "" && ok {
|
||||
if rec.digest == in.Digest {
|
||||
answer.Held = true
|
||||
} else {
|
||||
answer.OtherBytes = &gopackageregistry.PublishAnswerOtherBytes{Digest: rec.digest, Fingerprint: rec.fingerprint}
|
||||
}
|
||||
} else if words == "" {
|
||||
if r.held[in.Name] == nil {
|
||||
r.held[in.Name] = map[string]heldRecord{}
|
||||
}
|
||||
r.held[in.Name][in.Version] = heldRecord{digest: in.Digest, fingerprint: in.Fingerprint}
|
||||
answer.Transfer = "t"
|
||||
}
|
||||
r.mu.Unlock()
|
||||
reply(answer, words)
|
||||
r.answered <- in.Name + " " + in.Version
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = sub.Unsubscribe() })
|
||||
}
|
||||
|
||||
func (r *fakeRegistry) answer() { r.mu.Lock(); r.away = false; r.mu.Unlock() }
|
||||
|
||||
func (r *fakeRegistry) refuse(name, words string) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
if r.refused == nil {
|
||||
r.refused = map[string]string{}
|
||||
}
|
||||
if words == "" {
|
||||
delete(r.refused, name)
|
||||
return
|
||||
}
|
||||
r.refused[name] = words
|
||||
}
|
||||
|
||||
func (r *fakeRegistry) hide(name string) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
if r.hidden == nil {
|
||||
r.hidden = map[string]bool{}
|
||||
}
|
||||
r.hidden[name] = true
|
||||
}
|
||||
|
||||
func (r *fakeRegistry) hold(name, version, digest, fingerprint string) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
if r.held[name] == nil {
|
||||
r.held[name] = map[string]heldRecord{}
|
||||
}
|
||||
r.held[name][version] = heldRecord{digest: digest, fingerprint: fingerprint}
|
||||
}
|
||||
|
||||
func (r *fakeRegistry) digest(name, version string) string {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
return r.held[name][version].digest
|
||||
}
|
||||
|
||||
func (r *fakeRegistry) callsOf(name string) int {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
return r.calls[name]
|
||||
}
|
||||
|
||||
// await reads the publishes answered until name's at version, within the level's set-up share.
|
||||
func (r *fakeRegistry) await(t *testing.T, name, version string) {
|
||||
t.Helper()
|
||||
bound := time.After(testbus.SetupBound(t))
|
||||
for {
|
||||
select {
|
||||
case got := <-r.answered:
|
||||
if got == name+" "+version {
|
||||
return
|
||||
}
|
||||
case <-bound:
|
||||
t.Fatalf("no publish of %s %s was answered", name, version)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// settle waits until the holder's queue holds nothing sent and unacknowledged on either durable, the live class's and the again
|
||||
// class's: every item taken is ended.
|
||||
func (r *fakeRegistry) settle(t *testing.T, js jetstream.JetStream, stream string, holder string, each func()) {
|
||||
t.Helper()
|
||||
var cs []jetstream.Consumer
|
||||
for _, class := range []string{versions.PublishClassLive, versions.PublishClassStart} {
|
||||
c, err := js.Consumer(context.Background(), stream, publishesConsumer(holder, class))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cs = append(cs, c)
|
||||
}
|
||||
for deadline := time.Now().Add(testbus.SetupBound(t)); ; {
|
||||
if each != nil {
|
||||
each()
|
||||
}
|
||||
var ack, pending int
|
||||
for _, c := range cs {
|
||||
info, err := c.Info(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ack, pending = ack+info.NumAckPending, pending+int(info.NumPending)
|
||||
}
|
||||
if ack == 0 && pending == 0 {
|
||||
return
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatalf("the queue of %s holds %d unacknowledged and %d pending", holder, ack, pending)
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
// delivered is how many items the holder's durable of a class has given since it was made.
|
||||
func delivered(t *testing.T, js jetstream.JetStream, stream, holder, class string) uint64 {
|
||||
t.Helper()
|
||||
c, err := js.Consumer(context.Background(), stream, publishesConsumer(holder, class))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
info, err := c.Info(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return info.Delivered.Consumer
|
||||
}
|
||||
|
||||
// goAway makes the holder answer as the bus does when no one listens: its publish is met by no responders.
|
||||
func (r *fakeRegistry) goAway() { r.mu.Lock(); r.away = true; r.mu.Unlock() }
|
||||
|
||||
// published says the holder's published of name at version, as it says it after a publish: the reservation marks it from the digest held.
|
||||
func (r *fakeRegistry) published(t *testing.T, rv *reservations, name, version string) {
|
||||
t.Helper()
|
||||
rv.published(context.Background(), versions.Outcome{Name: name, Version: version, Digest: r.digest(name, version), Kind: versions.KindPackage, Holder: "go-registry"}, nil)
|
||||
}
|
||||
|
||||
@@ -17,47 +17,26 @@ import (
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
"git.novox.be/novox/mesh-sdk/go/buscompose"
|
||||
"git.novox.be/novox/mesh-sdk/go/busretry"
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
|
||||
"mesh-delivery-builder/internal/build"
|
||||
"mesh-delivery-builder/internal/versions"
|
||||
)
|
||||
|
||||
// **A version's publish is the builder's own work until its release is written** (design 47 G A-457a, §588; H2 §793): each
|
||||
// reservation of a done build is a publish item in the builder's re-ask state, asked when the build ends and at the builder's
|
||||
// start; its try puts the publish on the work queue publishes, and each send counts one try in the item and hands a failed one
|
||||
// back with a longer pause; the release deletes it; after its tries it ends loudly and stays readable in builder_publish_queue.
|
||||
// **A version's publish is the builder's own work until its release is written** (design 47 G A-457a, §588; H2 §793, H-A-606): the
|
||||
// ask at a build's end is the first try, and it puts the publish on the work queue publishes; a publish that is refused or fails stays
|
||||
// reserved, with version-unreleased naming the holder's words, and is put again only on ADR 0674 §2's events (a registry holder's
|
||||
// running, a returned of its node: versions.Againer) or by builder_publish_again. No timer, pause or count of tries stands on this path.
|
||||
|
||||
// publishSettings are the settings publish-pause, publish-pause-max and publish-tries.
|
||||
type publishSettings struct {
|
||||
Pause, PauseMax time.Duration
|
||||
Tries int
|
||||
}
|
||||
|
||||
// defaultPublishSettings are the settings' defaults: 30 s, 30 min and 5 tries (H-A-446 (2)).
|
||||
var defaultPublishSettings = publishSettings{Pause: 30 * time.Second, PauseMax: 30 * time.Minute, Tries: 5}
|
||||
|
||||
// pauseAfter is the pause after the try-th try: the setting doubled per try, up to the maximum.
|
||||
func (s publishSettings) pauseAfter(try int) time.Duration {
|
||||
d := s.Pause
|
||||
for i := 1; i < try && d < s.PauseMax; i++ {
|
||||
d *= 2
|
||||
}
|
||||
return min(d, s.PauseMax)
|
||||
}
|
||||
|
||||
// publishItems asks, tries and ends the publish items.
|
||||
// publishItems asks and takes the publishes of reserved versions.
|
||||
type publishItems struct {
|
||||
reasks func() jetstream.KeyValue // the re-ask state, nil until it is bound
|
||||
// dropMark records on a version's reservation that its publish was dropped by hand, by whom and why (design 47 H2 H-A-746); nil
|
||||
// drops none.
|
||||
dropMark func(ctx context.Context, module, version, by, why string) error
|
||||
now func() time.Time
|
||||
reserved func(ctx context.Context, module, version string) (versions.ReservedVersion, bool, error)
|
||||
republish func(ctx context.Context, module, version string) ([]string, error)
|
||||
endedWith func(ctx context.Context, v versions.ReservedVersion, why string) // raises the finding version-unreleased
|
||||
// allDone are the reservations, done or not: those whose build is done are asked at the start (builtOf).
|
||||
allDone func(ctx context.Context) ([]versions.ReservedVersion, error)
|
||||
// retired are the done builds a newer reservation or release of the same module supersedes, with why (H-A-291 (1)); nil
|
||||
// retires none.
|
||||
retired func(ctx context.Context, all []versions.ReservedVersion) (map[string]string, error)
|
||||
// judge is what the registries' own record says of a version's missing artifacts (H-A-272, H-A-274, H-A-275); nil judges none.
|
||||
judge func(ctx context.Context, v versions.ReservedVersion) (versions.Judged, error)
|
||||
// markHeld marks the artifacts the registries hold with the built digest published from their record, as their published heard
|
||||
@@ -66,142 +45,52 @@ type publishItems struct {
|
||||
markHeld func(ctx context.Context, v versions.ReservedVersion, held []versions.HeldArtifact)
|
||||
moveElsewhere func(ctx context.Context, v versions.ReservedVersion, j versions.Judged) error
|
||||
// send sends one item pulled from the work queue (Republisher.SendQueued); nil sends none.
|
||||
send func(ctx context.Context, q versions.QueuedPublish) versions.SendFate
|
||||
set publishSettings
|
||||
now func() time.Time
|
||||
after func(time.Duration) <-chan time.Time
|
||||
logf func(string, ...any)
|
||||
send func(ctx context.Context, q versions.QueuedPublish) versions.SendFate
|
||||
// unreleased raises version-unreleased about a version with the words given (Republisher's Unreleased); nil raises none.
|
||||
unreleased func(ctx context.Context, v versions.ReservedVersion, why string)
|
||||
logf func(string, ...any)
|
||||
// progressEvery is the pace the bus is told an item is in progress at while its send's calls wait: the kept call's pace
|
||||
// (busretry.KeptPace's most) when zero (design 47 H2 H-A-613 (3)).
|
||||
progressEvery time.Duration
|
||||
|
||||
mu sync.Mutex
|
||||
held map[string][]heldItem // "<module> <version>": the items sent, their publish not yet heard
|
||||
}
|
||||
|
||||
func (p *publishItems) wait(ctx context.Context, d time.Duration) bool {
|
||||
if d <= 0 {
|
||||
return ctx.Err() == nil
|
||||
}
|
||||
after := p.after
|
||||
if after == nil {
|
||||
after = time.After
|
||||
}
|
||||
select {
|
||||
case <-after(d):
|
||||
return true
|
||||
case <-ctx.Done():
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Ask writes the publish item of a version whose build is done, when none stands: its first try is now.
|
||||
// Ask puts the publish of a version whose build is done on the work queue: its first try, at the build's end (A-473).
|
||||
func (p *publishItems) Ask(ctx context.Context, module, version string) error {
|
||||
kv := p.reasks()
|
||||
if kv == nil {
|
||||
return errors.New("the re-ask state is not on the bus yet")
|
||||
}
|
||||
raw, err := json.Marshal(build.ReAsk{V: 1, Why: "the build ended with its version unreleased", By: "the builder", At: p.now().UTC(), Mode: build.ModePublish, Module: module, Version: version, NextTry: p.now().UTC()})
|
||||
queued, err := p.republish(ctx, module, version)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("the publish of %s %s is not put on the work queue %s: %w", module, version, versions.PublishesLocal, err)
|
||||
}
|
||||
if _, err := kv.Create(ctx, versions.PublishItemKey(module, version), raw); err != nil && !errors.Is(err, jetstream.ErrKeyExists) {
|
||||
return fmt.Errorf("the publish item of %s %s cannot be written: %w", module, version, err)
|
||||
if len(queued) == 0 {
|
||||
p.logf("%s %s: the publish is not put on the work queue %s: nothing of it is left to queue", module, version, versions.PublishesLocal)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AskAllDone asks the publish item of every reservation whose build is done and that has no release: at the builder's start, so
|
||||
// what stood before this change moves too, whatever its artifacts.
|
||||
func (p *publishItems) AskAllDone(ctx context.Context) {
|
||||
all, err := p.allDone(ctx)
|
||||
if err != nil {
|
||||
p.logf("the reservations of done builds are not asked to publish at the start: %v", err)
|
||||
return
|
||||
}
|
||||
var retired map[string]string
|
||||
if p.retired != nil {
|
||||
if retired, err = p.retired(ctx, all); err != nil {
|
||||
p.logf("the superseded builds are not retired at the start: %v", err)
|
||||
}
|
||||
}
|
||||
for _, v := range builtOf(all) {
|
||||
if why := retired[v.Module+" "+v.Version]; why != "" { // only each module's newest is asked (H-A-291 (1), H-A-275)
|
||||
p.logf("%s %s is not asked to publish at the start: %s; its publish item is ended", v.Module, v.Version, why)
|
||||
p.Done(ctx, v.Module, v.Version)
|
||||
continue
|
||||
}
|
||||
if why := versions.NotStanding(v, true); why != "" { // withdrawn: it never publishes (H-A-290 (2))
|
||||
p.logf("%s %s is not asked to publish at the start: %s; its publish item is ended", v.Module, v.Version, why)
|
||||
p.Done(ctx, v.Module, v.Version)
|
||||
continue
|
||||
}
|
||||
if err := p.Ask(ctx, v.Module, v.Version); err != nil {
|
||||
p.logf("%v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Done deletes a version's publish item and acknowledges its held items: its release is written.
|
||||
// Done acknowledges a version's held items: its release is written.
|
||||
func (p *publishItems) Done(ctx context.Context, module, version string) {
|
||||
for _, h := range p.settle(module, version, func(heldItem) bool { return true }) {
|
||||
_ = h.m.Ack()
|
||||
}
|
||||
kv := p.reasks()
|
||||
if kv == nil {
|
||||
return
|
||||
}
|
||||
if err := kv.Delete(ctx, versions.PublishItemKey(module, version)); err != nil && !errors.Is(err, jetstream.ErrKeyNotFound) {
|
||||
p.logf("the publish item of %s %s is not deleted: %v", module, version, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Try waits for the item's next try, then, while the version is still reserved, puts its publish on the work queue publishes
|
||||
// under its message id (design 47 H2 §793; H-A-448): an item the queue holds already is put once. It counts no try: each send
|
||||
// does, and hands its item back with the pause (take). A put that queued nothing is put again after the pause. A version no
|
||||
// longer reserved (released, dropped or taken over) has its item deleted.
|
||||
func (p *publishItems) Try(ctx context.Context, kv jetstream.KeyValue, e jetstream.KeyValueEntry, r build.ReAsk) {
|
||||
if !p.wait(ctx, r.NextTry.Sub(p.now())) {
|
||||
return
|
||||
}
|
||||
cur, err := kv.Get(ctx, e.Key())
|
||||
if err != nil || cur.Revision() != e.Revision() {
|
||||
return // deleted by the release, or written again
|
||||
}
|
||||
v, held, err := p.reserved(ctx, r.Module, r.Version)
|
||||
if err != nil {
|
||||
p.logf("%s %s: its reservation cannot be read, the publish item waits: %v", r.Module, r.Version, err)
|
||||
return
|
||||
}
|
||||
if why := versions.NotStanding(v, held); why != "" { // dropped, taken over, released or withdrawn (A-456b, H-A-290 (2))
|
||||
p.logf("%s %s: the publish item is ended: %s", r.Module, r.Version, why)
|
||||
_ = kv.Delete(ctx, e.Key())
|
||||
return
|
||||
}
|
||||
queued, err := p.republish(ctx, r.Module, r.Version)
|
||||
if err == nil && len(queued) > 0 {
|
||||
return
|
||||
}
|
||||
r.NextTry = p.now().UTC().Add(p.set.pauseAfter(r.Tries))
|
||||
p.logf("%s %s: the publish is not on the work queue %s (%v); it is put again after %s", r.Module, r.Version, versions.PublishesLocal, err, p.set.pauseAfter(r.Tries))
|
||||
if data, err := json.Marshal(r); err == nil {
|
||||
if _, err := kv.Update(ctx, e.Key(), data, e.Revision()); err != nil && !errors.Is(err, jetstream.ErrKeyExists) && !errors.Is(err, jetstream.ErrKeyRevisionMismatch) {
|
||||
p.logf("%s: the publish item could not be written: %v", e.Key(), err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// itemMsg is what take reads of an item pulled from the work queue (jetstream.Msg).
|
||||
type itemMsg interface {
|
||||
Data() []byte
|
||||
InProgress() error
|
||||
Ack() error
|
||||
NakWithDelay(time.Duration) error
|
||||
Term() error
|
||||
Metadata() (*jetstream.MsgMetadata, error)
|
||||
}
|
||||
|
||||
// take handles one item pulled from the work queue (§793; H-A-440 (2), H-A-448): an item whose publish item ended (dropped, or
|
||||
// its tries spent) or whose version never publishes is terminated; one whose artifacts are all published is acknowledged; once
|
||||
// publish-tries sends are spent it is terminated and version-unreleased said; while a published of it may be unheard it is handed
|
||||
// back with the pause, and one the registries' record confirms is acknowledged (H-A-274); else it is sent, the try counted in its
|
||||
// publish item, and a send that fails handed back with the pause as its delay, so the queue delivers it again and nothing is put
|
||||
// again. A sent item is acknowledged when its publish is heard (heard, Done) and delivered again after the ack wait, unheard.
|
||||
// take handles one item pulled from the work queue (§793; H-A-440 (2), H-A-448, H-A-606): an item whose version never publishes is
|
||||
// terminated; one whose artifacts are all published is acknowledged; one the registries' record confirms is acknowledged (H-A-274);
|
||||
// else it is sent. A sent item is acknowledged when its publish is heard (heard, Done) and given again after the ack wait, unheard.
|
||||
// A send that fails or is refused ends the item, the version staying reserved with version-unreleased naming the holder's words
|
||||
// (said by the send): it is put again only on the next event of ADR 0674 §2 or by builder_publish_again, never on a timer.
|
||||
func (p *publishItems) take(ctx context.Context, m itemMsg) {
|
||||
var q versions.QueuedPublish
|
||||
if err := json.Unmarshal(m.Data(), &q); err != nil || q.Module == "" || q.Version == "" {
|
||||
@@ -209,44 +98,24 @@ func (p *publishItems) take(ctx context.Context, m itemMsg) {
|
||||
_ = m.Term()
|
||||
return
|
||||
}
|
||||
kv := p.reasks()
|
||||
if kv == nil {
|
||||
p.logf("%s %s: the re-ask state is not on the bus yet; the item is handed back", q.Module, q.Version)
|
||||
_ = m.NakWithDelay(p.set.Pause)
|
||||
return
|
||||
}
|
||||
key := versions.PublishItemKey(q.Module, q.Version)
|
||||
e, err := kv.Get(ctx, key)
|
||||
if errors.Is(err, jetstream.ErrKeyNotFound) { // put by builder_publish_again or the move: its tries are counted from now
|
||||
if err = p.Ask(ctx, q.Module, q.Version); err == nil {
|
||||
e, err = kv.Get(ctx, key)
|
||||
if md, err := m.Metadata(); err == nil && md.NumDelivered >= publishesMaxDeliver {
|
||||
// The delivery where an item reaches the queue's ten ends it, said, never left dead on the queue (design 47 H2 H-A-653, H-A-703).
|
||||
words := fmt.Sprintf("given up after %d deliveries", publishesMaxDeliver)
|
||||
p.logf("%s %s at %s is terminated: %s", q.Module, q.Version, q.Holder, words)
|
||||
if v, found, err := p.reserved(ctx, q.Module, q.Version); err == nil && found && p.unreleased != nil {
|
||||
p.unreleased(ctx, v, words)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
p.logf("%s %s: its publish item cannot be read (%v); the item is handed back", q.Module, q.Version, err)
|
||||
_ = m.NakWithDelay(p.set.Pause)
|
||||
return
|
||||
}
|
||||
r, err := build.DecodeReAsk(e.Value())
|
||||
if err != nil {
|
||||
_ = m.Term()
|
||||
return
|
||||
}
|
||||
if r.Answer != "" {
|
||||
p.logf("%s %s at %s is terminated: its publish item ended: %s", q.Module, q.Version, q.Holder, r.Answer)
|
||||
_ = m.Term()
|
||||
return
|
||||
}
|
||||
v, found, err := p.reserved(ctx, q.Module, q.Version)
|
||||
if err != nil {
|
||||
p.logf("%s %s: its reservation cannot be read (%v); the item is handed back", q.Module, q.Version, err)
|
||||
_ = m.NakWithDelay(p.set.pauseAfter(r.Tries))
|
||||
p.logf("%s %s: its reservation cannot be read (%v); the item is given again after the ack wait", q.Module, q.Version, err)
|
||||
return
|
||||
}
|
||||
if why := versions.NotStanding(v, found); why != "" {
|
||||
p.logf("%s %s at %s is terminated: %s", q.Module, q.Version, q.Holder, why)
|
||||
_ = m.Term()
|
||||
_ = kv.Delete(ctx, key)
|
||||
return
|
||||
}
|
||||
if allPublished(v, q) {
|
||||
@@ -254,17 +123,6 @@ func (p *publishItems) take(ctx context.Context, m itemMsg) {
|
||||
_ = m.Ack()
|
||||
return
|
||||
}
|
||||
if r.Tries >= p.set.Tries {
|
||||
_ = m.Term()
|
||||
r.Answer = fmt.Sprintf("the publish of %s %s was tried %d times and the version is not released; builder_publish_again tries it again", r.Module, r.Version, r.Tries)
|
||||
r.Answered = p.now().UTC()
|
||||
p.logf("%s: %s", key, r.Answer)
|
||||
if p.endedWith != nil {
|
||||
p.endedWith(ctx, v, "the publish ended after "+fmt.Sprint(r.Tries)+" tries")
|
||||
}
|
||||
p.write(ctx, kv, key, r, e.Revision())
|
||||
return
|
||||
}
|
||||
if why, gone := p.notAgain(ctx, v); gone {
|
||||
_ = m.Term() // moved to another number, whose own item is asked (H-A-275)
|
||||
return
|
||||
@@ -274,39 +132,66 @@ func (p *publishItems) take(ctx context.Context, m itemMsg) {
|
||||
_ = m.Ack()
|
||||
return
|
||||
}
|
||||
p.logf("%s %s: the publish is not sent again: %s; handed back for %s", q.Module, q.Version, why, p.set.pauseAfter(r.Tries))
|
||||
_ = m.NakWithDelay(p.set.pauseAfter(r.Tries))
|
||||
p.logf("%s %s at %s: the publish is not sent: %s; the item is ended, the version stays reserved", q.Module, q.Version, q.Holder, why)
|
||||
_ = m.Term()
|
||||
return
|
||||
}
|
||||
fate := versions.SendFate{Failed: "this builder sends no publish"}
|
||||
if p.send != nil {
|
||||
// The item is marked in progress while its calls wait, so the bus gives it again only when the builder itself stopped
|
||||
// (design 47 H2 H-A-613 (3)).
|
||||
stop := p.inProgress(m)
|
||||
fate = p.send(ctx, q)
|
||||
stop()
|
||||
}
|
||||
if fate.Unread != "" {
|
||||
// A read of the builder's own state that failed is no answer of a holder: the item is left unacknowledged, given again after the
|
||||
// ack wait, and the queue's tenth delivery ends it loud (design 47 H2 H-A-745, H-A-653).
|
||||
p.logf("%s %s at %s: sent no publish: %s; the item is left, given again after the ack wait", q.Module, q.Version, q.Holder, fate.Unread)
|
||||
return
|
||||
}
|
||||
if fate.Ended != "" {
|
||||
p.logf("%s %s at %s is terminated: %s", q.Module, q.Version, q.Holder, fate.Ended)
|
||||
_ = m.Term()
|
||||
return
|
||||
}
|
||||
r.Tries++
|
||||
r.NextTry = p.now().UTC().Add(p.set.pauseAfter(r.Tries))
|
||||
p.write(ctx, kv, key, r, e.Revision())
|
||||
if fate.Failed != "" {
|
||||
p.logf("%s %s at %s: try %d sent no publish: %s; handed back for %s", q.Module, q.Version, q.Holder, r.Tries, fate.Failed, p.set.pauseAfter(r.Tries))
|
||||
_ = m.NakWithDelay(p.set.pauseAfter(r.Tries))
|
||||
p.logf("%s %s at %s: sent no publish: %s; the item is ended, the version stays reserved and is put again on the next event of its holder (H-A-606)", q.Module, q.Version, q.Holder, fate.Failed)
|
||||
_ = m.Term()
|
||||
return
|
||||
}
|
||||
p.hold(q, m)
|
||||
// Its publish heard between the send and the hold would be missed by both: read again once held.
|
||||
p.heard(ctx, q.Module, q.Version)
|
||||
}
|
||||
|
||||
// write writes a publish item at its revision; a newer write wins.
|
||||
func (p *publishItems) write(ctx context.Context, kv jetstream.KeyValue, key string, r build.ReAsk, rev uint64) {
|
||||
data, err := json.Marshal(r)
|
||||
if err != nil {
|
||||
return
|
||||
// inProgress tells the bus the item is in progress now and at the kept call's pace until the returned function is called.
|
||||
func (p *publishItems) inProgress(m itemMsg) (stop func()) {
|
||||
every := p.progressEvery
|
||||
if every <= 0 {
|
||||
every = busretry.KeptPace().Max
|
||||
}
|
||||
if _, err := kv.Update(ctx, key, data, rev); err != nil && !errors.Is(err, jetstream.ErrKeyExists) && !errors.Is(err, jetstream.ErrKeyRevisionMismatch) {
|
||||
p.logf("%s: the publish item could not be written: %v", key, err)
|
||||
say := func() {
|
||||
if err := m.InProgress(); err != nil {
|
||||
p.logf("an item in progress is not said to the bus: %v", err)
|
||||
}
|
||||
}
|
||||
done, ended := make(chan struct{}), make(chan struct{})
|
||||
go func() {
|
||||
defer close(ended)
|
||||
say()
|
||||
t := time.NewTicker(every)
|
||||
defer t.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-t.C:
|
||||
say()
|
||||
case <-done:
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
return func() { close(done); <-ended }
|
||||
}
|
||||
|
||||
// allPublished says none of q's artifacts is missing from v: its publish is heard.
|
||||
@@ -421,8 +306,9 @@ func registryVersionsVia(call toolCaller) func(context.Context, string, string)
|
||||
}
|
||||
var a struct { // the four registry seats answer versions alike: each version with its digest
|
||||
Versions []struct {
|
||||
Version string `json:"version"`
|
||||
Digest string `json:"digest"`
|
||||
Version string `json:"version"`
|
||||
Digest string `json:"digest"`
|
||||
Fingerprint string `json:"fingerprint"`
|
||||
} `json:"versions"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &a); err != nil {
|
||||
@@ -430,7 +316,7 @@ func registryVersionsVia(call toolCaller) func(context.Context, string, string)
|
||||
}
|
||||
out := make([]versions.HeldVersion, 0, len(a.Versions))
|
||||
for _, v := range a.Versions {
|
||||
out = append(out, versions.HeldVersion{Version: v.Version, Digest: v.Digest})
|
||||
out = append(out, versions.HeldVersion{Version: v.Version, Digest: v.Digest, Fingerprint: v.Fingerprint})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
@@ -460,24 +346,6 @@ func numberFile(path string, def int) (int, error) {
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// publishSettingsOf reads publish-pause (seconds), publish-pause-max (minutes) and publish-tries from their files.
|
||||
func publishSettingsOf(getenv func(string) string) (publishSettings, error) {
|
||||
s := defaultPublishSettings
|
||||
pause, err := numberFile(getenv("MESH_BUILDER_PUBLISH_PAUSE_FILE"), int(s.Pause/time.Second))
|
||||
if err != nil {
|
||||
return s, err
|
||||
}
|
||||
pmax, err := numberFile(getenv("MESH_BUILDER_PUBLISH_PAUSE_MAX_FILE"), int(s.PauseMax/time.Minute))
|
||||
if err != nil {
|
||||
return s, err
|
||||
}
|
||||
tries, err := numberFile(getenv("MESH_BUILDER_PUBLISH_TRIES_FILE"), s.Tries)
|
||||
if err != nil {
|
||||
return s, err
|
||||
}
|
||||
return publishSettings{Pause: time.Duration(pause) * time.Second, PauseMax: time.Duration(pmax) * time.Minute, Tries: tries}, nil
|
||||
}
|
||||
|
||||
// wirePublishItems joins the reservations to the publish items (design 47 G A-457a, A-456a, A-456b, H2 §793): a done build asks its
|
||||
// item, a release ends it and acknowledges its held items, a drop and a takeover end it and terminate them, a published heard
|
||||
// acknowledges those it publishes, and a release is recorded in releases, the last kept of each module.
|
||||
@@ -526,16 +394,29 @@ func publishesOf(module string) func() (publishesStream, error) {
|
||||
return func() (publishesStream, error) { return b, nil }
|
||||
}
|
||||
|
||||
// The consumer's numbers (H-A-446 (2)): at most four sends in flight per holder, and ten deliveries, the work queue's largest;
|
||||
// the builder ends an item at publish-tries anyway.
|
||||
const (
|
||||
publishesMaxAckPending = versions.PublishSendsAtOnce
|
||||
publishesMaxDeliver = 10
|
||||
)
|
||||
// defaultPublishAckMinutes is the setting publish-ack-minutes' default: G section 369's publish bound (H-A-606 round 3 (3)).
|
||||
const defaultPublishAckMinutes = 10
|
||||
|
||||
// publishesConsumer is the one durable consumer of holder's items (H-A-483 addendum).
|
||||
func publishesConsumer(holder string) string {
|
||||
return versions.PublishesLocal + "-" + holder
|
||||
// The consumers' numbers (H-A-700 (1), H-A-620 (2)): per holder, at most four `live` sends in flight and one `again` send, and ten
|
||||
// deliveries, the work queue's largest.
|
||||
const publishesMaxDeliver = 10
|
||||
|
||||
// publishesConsumer is the durable consumer of holder's items of a class: `publishes-<holder>-live` and `publishes-<holder>-again`
|
||||
// (H-A-700 (1)).
|
||||
func publishesConsumer(holder, class string) string {
|
||||
return versions.PublishesLocal + "-" + holder + "-" + class
|
||||
}
|
||||
|
||||
// publishesOneConsumer is the one durable of holder's items an earlier build made: its filter overlaps both classes', which a work
|
||||
// queue refuses, so a pull deletes it before it makes the two (H-A-700 (2)).
|
||||
func publishesOneConsumer(holder string) string { return versions.PublishesLocal + "-" + holder }
|
||||
|
||||
// inFlight is the sends of a class at once: four `live`, one `again` (ADR 0674 §3, H-A-620 (2)).
|
||||
func inFlight(class string) int {
|
||||
if class == versions.PublishClassStart {
|
||||
return 1
|
||||
}
|
||||
return versions.PublishSendsAtOnce
|
||||
}
|
||||
|
||||
// subject is the item's subject on the bus.
|
||||
@@ -554,7 +435,19 @@ func (pq *publishQueue) put(ctx context.Context, q versions.QueuedPublish) (bool
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
ack, err := pq.js.PublishMsg(ctx, &nats.Msg{Subject: pq.subject(b, q), Data: data}, jetstream.WithMsgID(versions.PublishMsgID(q.Holder, q.Class, q.Module, q.Version)))
|
||||
// No form of a manifest's stream refuses a new message while one is held, so the subject's last message is read first: one held
|
||||
// there means the version is queued or being sent, and nothing is put (design 47 H2 H-A-620 (1); ADR 0674 §3).
|
||||
st, err := pq.js.Stream(ctx, b.Stream)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if _, err := st.GetLastMsgForSubject(ctx, pq.subject(b, q)); err == nil {
|
||||
pq.learn(ctx, q.Holder)
|
||||
return true, nil
|
||||
} else if !errors.Is(err, jetstream.ErrMsgNotFound) {
|
||||
return false, err
|
||||
}
|
||||
ack, err := pq.js.PublishMsg(ctx, &nats.Msg{Subject: pq.subject(b, q), Data: data}, jetstream.WithMsgID(q.MsgID()))
|
||||
if err != nil {
|
||||
if w := err.Error(); strings.Contains(w, "maximum bytes") || strings.Contains(w, "maximum messages") || errors.Is(err, jetstream.ErrMaxBytesExceeded) {
|
||||
return false, fmt.Errorf("%w: %v", versions.ErrQueueFull, err)
|
||||
@@ -614,72 +507,111 @@ func (pq *publishQueue) learn(ctx context.Context, holder string) {
|
||||
}
|
||||
}
|
||||
|
||||
// pull makes holder's one consumer and dispatches its items (design 47 H2 §793, H-A-483 and its addenda): first it retires the
|
||||
// holder's class durables an earlier release made (`-live`, `-again`), whose filters a work queue refuses beside the one; their
|
||||
// unacknowledged items stay on the queue and reach the one consumer.
|
||||
// pull makes holder's two consumers and dispatches their items (design 47 H2 §793, H-A-700, H-A-719): first it deletes the one
|
||||
// consumer `publishes-<holder>` an earlier build made, whose filter overlaps both and a work queue refuses overlapping filters, not
|
||||
// found ignored and a removal said; its unacknowledged items stay on the queue and reach the two. Each of the two takes the bus's
|
||||
// inactive threshold equal to the stream's own maximum age, so the bus removes the durable of a holder nothing pulled for that long
|
||||
// and no deleter is built here (H-A-719).
|
||||
func (pq *publishQueue) pull(ctx context.Context, holder string) error {
|
||||
b, err := pq.binding()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
st, err := pq.js.Stream(ctx, b.Stream)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
info, err := st.Info(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
old := publishesOneConsumer(holder)
|
||||
switch err := pq.js.DeleteConsumer(ctx, b.Stream, old); {
|
||||
case err == nil:
|
||||
pq.logf("the consumer %s of an earlier build is removed: the publishes of %s have two, one per class (H-A-700)", old, holder)
|
||||
case !errors.Is(err, jetstream.ErrConsumerNotFound):
|
||||
return fmt.Errorf("the consumer %s of an earlier build is not removed: %w", old, err)
|
||||
}
|
||||
for _, class := range []string{versions.PublishClassLive, versions.PublishClassStart} {
|
||||
old := publishesConsumer(holder) + "-" + class
|
||||
err := pq.js.DeleteConsumer(ctx, b.Stream, old)
|
||||
switch {
|
||||
case err == nil:
|
||||
pq.logf("the consumer %s of an earlier release is removed: the publishes of %s have one consumer (H-A-483)", old, holder)
|
||||
case !errors.Is(err, jetstream.ErrConsumerNotFound):
|
||||
return fmt.Errorf("the consumer %s of an earlier release is not removed: %w", old, err)
|
||||
_, err := pq.js.CreateOrUpdateConsumer(ctx, b.Stream, jetstream.ConsumerConfig{Durable: publishesConsumer(holder, class),
|
||||
FilterSubject: b.Subject + ".publish." + versions.EscapeToken(holder) + "." + class + ".>", AckPolicy: jetstream.AckExplicitPolicy,
|
||||
AckWait: pq.ackWait, MaxAckPending: inFlight(class), MaxDeliver: publishesMaxDeliver, InactiveThreshold: info.Config.MaxAge})
|
||||
if err != nil {
|
||||
return fmt.Errorf("the consumer %s: %w", publishesConsumer(holder, class), err)
|
||||
}
|
||||
}
|
||||
c, err := pq.js.CreateOrUpdateConsumer(ctx, b.Stream, jetstream.ConsumerConfig{Durable: publishesConsumer(holder),
|
||||
FilterSubject: b.Subject + ".publish." + versions.EscapeToken(holder) + ".>", AckPolicy: jetstream.AckExplicitPolicy,
|
||||
AckWait: pq.ackWait, MaxAckPending: publishesMaxAckPending, MaxDeliver: publishesMaxDeliver})
|
||||
if err != nil {
|
||||
return fmt.Errorf("the consumer %s: %w", publishesConsumer(holder), err)
|
||||
}
|
||||
pq.logf("pulling the publishes of %s", holder)
|
||||
go pq.dispatch(ctx, holder, c)
|
||||
for _, class := range []string{versions.PublishClassLive, versions.PublishClassStart} {
|
||||
if err := pq.dispatch(ctx, b.Stream, holder, class); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// dispatch runs the items of one holder in the order its one consumer gives them, at most four at once (design 47 H2 §793,
|
||||
// H-A-483): each free slot takes the next item through a pull that waits, so an item put or handed back after its pause is
|
||||
// received the moment the bus gives it; an item handed back reappears only after its pause, so an item put meanwhile goes
|
||||
// before it. A pull the bus refuses ends the dispatch, said; the holder is pulled again when an item of it is put.
|
||||
func (pq *publishQueue) dispatch(ctx context.Context, holder string, c jetstream.Consumer) {
|
||||
sem := make(chan struct{}, versions.PublishSendsAtOnce)
|
||||
for {
|
||||
select {
|
||||
case sem <- struct{}{}:
|
||||
case <-ctx.Done():
|
||||
return
|
||||
// dispatch runs the items of one holder's class as the consumer gives them, at most inFlight(class) at once (design 47 H2 §793,
|
||||
// H-A-483, H-A-700, H-A-654): in the step queue's shape (serveSteps), a Consume bound to the durable, which the bus's advisories of
|
||||
// the consumer's creation and deletion bind again, so a pull error never ends it.
|
||||
func (pq *publishQueue) dispatch(ctx context.Context, stream, holder, class string) error {
|
||||
name := publishesConsumer(holder, class)
|
||||
var mu sync.Mutex
|
||||
var pulling jetstream.ConsumeContext
|
||||
bind := func() bool {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if pulling != nil || ctx.Err() != nil {
|
||||
return pulling != nil
|
||||
}
|
||||
var got jetstream.Msg
|
||||
b, err := c.Fetch(1)
|
||||
if err == nil {
|
||||
for m := range b.Messages() {
|
||||
got = m
|
||||
}
|
||||
err = b.Error()
|
||||
c, err := pq.js.Consumer(ctx, stream, name)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if err != nil && !errors.Is(err, jetstream.ErrNoMessages) && !errors.Is(err, nats.ErrTimeout) && ctx.Err() == nil {
|
||||
<-sem
|
||||
pq.logf("the publishes of %s are not pulled: %v; they are pulled when an item of it is put", holder, err)
|
||||
pq.mu.Lock()
|
||||
delete(pq.pulling, holder)
|
||||
pq.mu.Unlock()
|
||||
return
|
||||
cc, err := c.Consume(func(m jetstream.Msg) { go pq.take(ctx, m) }, jetstream.PullMaxMessages(inFlight(class)),
|
||||
jetstream.ConsumeErrHandler(func(_ jetstream.ConsumeContext, err error) {
|
||||
pq.logf("the %s publishes of %s: the pull met %v; it goes on", class, holder, err)
|
||||
}))
|
||||
if err != nil {
|
||||
pq.logf("the %s publishes of %s are not pulled: %v; they are pulled when the bus says the consumer was created", class, holder, err)
|
||||
return false
|
||||
}
|
||||
if got == nil {
|
||||
<-sem
|
||||
continue
|
||||
}
|
||||
go func(m jetstream.Msg) {
|
||||
defer func() { <-sem }()
|
||||
pq.take(ctx, m)
|
||||
}(got)
|
||||
pulling = cc
|
||||
return true
|
||||
}
|
||||
release := func() {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if pulling == nil {
|
||||
return
|
||||
}
|
||||
pulling.Stop()
|
||||
pulling = nil
|
||||
pq.logf("the consumer %s was deleted: its items wait, and it is pulled again when the bus says it was created", name)
|
||||
}
|
||||
conn := pq.js.Conn()
|
||||
created, err := conn.Subscribe("$JS.EVENT.ADVISORY.CONSUMER.CREATED."+stream+"."+name, func(*nats.Msg) { go bind() })
|
||||
if err != nil {
|
||||
return fmt.Errorf("hearing the creation of the consumer %s: %w", name, err)
|
||||
}
|
||||
deleted, err := conn.Subscribe("$JS.EVENT.ADVISORY.CONSUMER.DELETED."+stream+"."+name, func(*nats.Msg) {
|
||||
go func() {
|
||||
release()
|
||||
bind() // made again before the deletion was heard
|
||||
}()
|
||||
})
|
||||
if err != nil {
|
||||
_ = created.Unsubscribe()
|
||||
return fmt.Errorf("hearing the deletion of the consumer %s: %w", name, err)
|
||||
}
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
_ = created.Unsubscribe()
|
||||
_ = deleted.Unsubscribe()
|
||||
release()
|
||||
}()
|
||||
if !bind() {
|
||||
return fmt.Errorf("the consumer %s is not bound", name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// itemsOf are the items the work queue holds of module's version in class (empty for any class), each with its subject.
|
||||
@@ -761,14 +693,17 @@ func (pq *publishQueue) reader(ctx context.Context) versions.Reader {
|
||||
}}
|
||||
}
|
||||
|
||||
// drop is builder_publish_drop (§793): the version's publish item is ended with who dropped it and why, so no item of it is ever
|
||||
// drop is builder_publish_drop (§793): the version's reservation keeps who dropped its publish and why (H-A-746), so no item of it is ever
|
||||
// sent or put again; its items waiting on the work queue are removed, and one held is terminated.
|
||||
func (pq *publishQueue) drop(ctx context.Context, items *publishItems, module, version, by, why string) (string, error) {
|
||||
qs, st, err := pq.itemsOf(ctx, module, version, "")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("the work queue %s cannot be read: %w", versions.PublishesLocal, err)
|
||||
}
|
||||
if err := items.endItem(ctx, module, version, fmt.Sprintf("dropped by %s: %s", by, why)); err != nil {
|
||||
if items.dropMark == nil {
|
||||
return "", errors.New("this builder keeps no reservations")
|
||||
}
|
||||
if err := items.dropMark(ctx, module, version, by, why); err != nil {
|
||||
return "", err
|
||||
}
|
||||
for subj := range qs {
|
||||
@@ -782,48 +717,6 @@ func (pq *publishQueue) drop(ctx context.Context, items *publishItems, module, v
|
||||
return fmt.Sprintf("the publish of %s %s is dropped: %d items terminated, and none is sent or put again", module, version, len(qs)), nil
|
||||
}
|
||||
|
||||
// endItem writes the version's publish item ended with answer, made when none stands: Try and take then leave it, and a start
|
||||
// asks it no more.
|
||||
func (p *publishItems) endItem(ctx context.Context, module, version, answer string) error {
|
||||
kv := p.reasks()
|
||||
if kv == nil {
|
||||
return errors.New("the re-ask state is not on the bus yet")
|
||||
}
|
||||
key := versions.PublishItemKey(module, version)
|
||||
for range 5 {
|
||||
r := build.ReAsk{V: 1, Why: "the build ended with its version unreleased", By: "the builder", At: p.now().UTC(), Mode: build.ModePublish, Module: module, Version: version}
|
||||
e, err := kv.Get(ctx, key)
|
||||
var rev uint64
|
||||
switch {
|
||||
case errors.Is(err, jetstream.ErrKeyNotFound):
|
||||
case err != nil:
|
||||
return err
|
||||
default:
|
||||
if r, err = build.DecodeReAsk(e.Value()); err != nil {
|
||||
return err
|
||||
}
|
||||
rev = e.Revision()
|
||||
}
|
||||
r.Answer, r.Answered = answer, p.now().UTC()
|
||||
data, err := json.Marshal(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if rev == 0 {
|
||||
_, err = kv.Create(ctx, key, data)
|
||||
} else {
|
||||
_, err = kv.Update(ctx, key, data, rev)
|
||||
}
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
if !errors.Is(err, jetstream.ErrKeyExists) && !errors.Is(err, jetstream.ErrKeyRevisionMismatch) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return errors.New("the publish item of " + module + " " + version + " changed five times while it was ended")
|
||||
}
|
||||
|
||||
// moveOld puts the items of the old state publish-queue on the work queue once at the start (§793): each under its message id, so
|
||||
// a move run twice puts each once within the duplicates window; then the builder, which made that bucket, removes it itself
|
||||
// (H-A-461 (1): the bus module's keeper holds no entry for it, so its drop refuses it). A builder whose bus holds no such
|
||||
|
||||
@@ -5,20 +5,15 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
|
||||
"mesh-delivery-builder/internal/build"
|
||||
"mesh-delivery-builder/internal/versions"
|
||||
)
|
||||
@@ -90,15 +85,48 @@ func (k *itemKV) Delete(_ context.Context, key string, _ ...jetstream.KVDeleteOp
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListKeys lists the keys the state holds, as the bus's key lister does.
|
||||
func (k *itemKV) ListKeys(context.Context, ...jetstream.WatchOpt) (jetstream.KeyLister, error) {
|
||||
k.mu.Lock()
|
||||
defer k.mu.Unlock()
|
||||
ch := make(chan string, len(k.vals))
|
||||
for key := range k.vals {
|
||||
ch <- key
|
||||
}
|
||||
close(ch)
|
||||
return itemKeys{ch}, nil
|
||||
}
|
||||
|
||||
type itemKeys struct{ ch chan string }
|
||||
|
||||
func (l itemKeys) Keys() <-chan string { return l.ch }
|
||||
func (l itemKeys) Stop() error { return nil }
|
||||
|
||||
// itemMsgFake is an item pulled from the work queue: what take settled it with.
|
||||
type itemMsgFake struct {
|
||||
data []byte
|
||||
settled []string // ack, term, nak <delay>
|
||||
progress atomic.Int64 // InProgress calls
|
||||
onWorking func(n int64) // told the count after each
|
||||
data []byte
|
||||
delivered uint64 // the delivery count Metadata says; 0 says none
|
||||
settled []string // ack, term, nak <delay>
|
||||
}
|
||||
|
||||
func (m *itemMsgFake) Data() []byte { return m.data }
|
||||
func (m *itemMsgFake) Ack() error { m.settled = append(m.settled, "ack"); return nil }
|
||||
func (m *itemMsgFake) Term() error { m.settled = append(m.settled, "term"); return nil }
|
||||
func (m *itemMsgFake) InProgress() error {
|
||||
n := m.progress.Add(1)
|
||||
if m.onWorking != nil {
|
||||
m.onWorking(n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (m *itemMsgFake) Ack() error { m.settled = append(m.settled, "ack"); return nil }
|
||||
func (m *itemMsgFake) Term() error { m.settled = append(m.settled, "term"); return nil }
|
||||
func (m *itemMsgFake) Metadata() (*jetstream.MsgMetadata, error) {
|
||||
if m.delivered == 0 {
|
||||
return nil, errors.New("no metadata")
|
||||
}
|
||||
return &jetstream.MsgMetadata{NumDelivered: m.delivered}, nil
|
||||
}
|
||||
func (m *itemMsgFake) NakWithDelay(d time.Duration) error {
|
||||
m.settled = append(m.settled, "nak "+d.String())
|
||||
return nil
|
||||
@@ -122,26 +150,19 @@ func decodeItem(t *testing.T, raw []byte) build.ReAsk {
|
||||
return r
|
||||
}
|
||||
|
||||
// TestAPublishItemIsTriedWithAGrowingPauseAndEndsLoudly: design 47 G A-457a, H2 §793 (H-A-440 (2), H-A-448) — a version's publish
|
||||
// item is asked once; its try puts the publish on the work queue and counts no try; each send counts one and a failed send hands
|
||||
// the item back with the pause doubled up to its maximum; after the setting's tries the item is terminated and ends with its words,
|
||||
// raises the condition and stays; an item whose artifacts are published is acknowledged; the release deletes it; a version no
|
||||
// longer reserved has it deleted.
|
||||
func TestAPublishItemIsTriedWithAGrowingPauseAndEndsLoudly(t *testing.T) {
|
||||
// TestAPublishIsPutOnceAtABuildsEndAndNeverOnATimer: design 47 H2 H-A-606 (A-473) — the ask at a build's end puts the publish on the
|
||||
// work queue once; a send that fails or is refused ends its item, the version stays reserved and nothing hands it back after a pause;
|
||||
// an item whose artifacts are published is acknowledged; a version no longer reserved is terminated; a publish its drop ended is
|
||||
// terminated whatever puts it again.
|
||||
func TestAPublishIsPutOnceAtABuildsEndAndNeverOnATimer(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
kv := &itemKV{vals: map[string][]byte{}, revs: map[string]uint64{}}
|
||||
now := time.Date(2026, 11, 17, 1, 0, 0, 0, time.UTC)
|
||||
var queued, ended, sent []string
|
||||
var queued, sent []string
|
||||
reserved := true
|
||||
v := versions.ReservedVersion{Module: "m", Version: "0.1.2", Artifacts: map[string]string{"m:a": "sha256:a"}, BuiltAt: now}
|
||||
p := &publishItems{reasks: func() jetstream.KeyValue { return kv }, set: publishSettings{Pause: 30 * time.Second, PauseMax: 2 * time.Minute, Tries: 4},
|
||||
now: func() time.Time { return now }, logf: t.Logf,
|
||||
after: func(d time.Duration) <-chan time.Time {
|
||||
now = now.Add(d)
|
||||
c := make(chan time.Time, 1)
|
||||
c <- now
|
||||
return c
|
||||
},
|
||||
fate := versions.SendFate{Failed: "no holder answers"}
|
||||
p := &publishItems{now: func() time.Time { return now }, logf: t.Logf,
|
||||
reserved: func(_ context.Context, _, ver string) (versions.ReservedVersion, bool, error) {
|
||||
if ver == "0.3.0" { // every artifact published, its release not written yet
|
||||
return versions.ReservedVersion{Module: "m", Version: ver, Artifacts: map[string]string{"m:a": "sha256:a"}, Published: map[string]bool{"m:a": true}, BuiltAt: now}, true, nil
|
||||
@@ -154,295 +175,120 @@ func TestAPublishItemIsTriedWithAGrowingPauseAndEndsLoudly(t *testing.T) {
|
||||
},
|
||||
send: func(_ context.Context, q versions.QueuedPublish) versions.SendFate {
|
||||
sent = append(sent, q.Module+" "+q.Version)
|
||||
return versions.SendFate{Failed: "no holder answers"}
|
||||
},
|
||||
endedWith: func(_ context.Context, v versions.ReservedVersion, why string) {
|
||||
ended = append(ended, v.Version+": "+why)
|
||||
return fate
|
||||
}}
|
||||
key := versions.PublishItemKey("m", "0.1.2")
|
||||
if err := p.Ask(ctx, "m", "0.1.2"); err != nil || p.Ask(ctx, "m", "0.1.2") != nil || len(kv.vals) != 1 {
|
||||
t.Fatalf("asked: %v, %d items, want one item however often it is asked", err, len(kv.vals))
|
||||
}
|
||||
e, _ := kv.Get(ctx, key)
|
||||
p.Try(ctx, kv, e, decodeItem(t, e.Value()))
|
||||
if len(queued) != 1 || decodeItem(t, kv.vals[key]).Tries != 0 {
|
||||
t.Fatalf("the try queued %v, tries %d: want the publish put once, no try counted", queued, decodeItem(t, kv.vals[key]).Tries)
|
||||
}
|
||||
var settled []string
|
||||
for range 5 {
|
||||
m := queuedMsg(t, "m", "0.1.2")
|
||||
p.take(ctx, m)
|
||||
settled = append(settled, m.settled...)
|
||||
}
|
||||
got := decodeItem(t, kv.vals[key])
|
||||
if len(sent) != 4 || got.Tries != 4 || got.Answer == "" || got.Answered.IsZero() || len(ended) != 1 || !strings.Contains(ended[0], "4 tries") {
|
||||
t.Fatalf("sent %v, item %+v, ended %v: want four sends, then the end said with its words and the condition", sent, got, ended)
|
||||
}
|
||||
if want := "[nak 30s nak 1m0s nak 2m0s nak 2m0s term]"; fmt.Sprint(settled) != want {
|
||||
t.Errorf("the items were settled %v, want %s (handed back with the pause doubled and capped, then terminated)", settled, want)
|
||||
if err := p.Ask(ctx, "m", "0.1.2"); err != nil || len(queued) != 1 || len(kv.vals) != 0 {
|
||||
t.Fatalf("asked: %v, queued %v, %d items: want the publish put once and no item kept", err, queued, len(kv.vals))
|
||||
}
|
||||
m := queuedMsg(t, "m", "0.1.2")
|
||||
if p.take(ctx, m); fmt.Sprint(m.settled) != "[term]" || len(sent) != 4 {
|
||||
t.Errorf("an item of an ended publish item was settled %v, sent %d: want it terminated unsent", m.settled, len(sent))
|
||||
p.take(ctx, m)
|
||||
if len(sent) != 1 || !slices.Equal(m.settled, []string{"term"}) {
|
||||
t.Fatalf("a failed send: sent %v, settled %v, want one send and the item terminated, never handed back with a pause", sent, m.settled)
|
||||
}
|
||||
// design 47 H2 H-A-745: a read of the builder's own state that failed leaves the item unacknowledged, ended nowhere.
|
||||
fate = versions.SendFate{Unread: "its reservation cannot be read: down"}
|
||||
m = queuedMsg(t, "m", "0.1.2")
|
||||
p.take(ctx, m)
|
||||
if len(sent) != 2 || len(m.settled) != 0 {
|
||||
t.Fatalf("an unread send: sent %v, settled %v, want it left unacknowledged", sent, m.settled)
|
||||
}
|
||||
// design 47 H2 H-A-613 (3): while its calls wait the item is marked in progress at the kept call's pace, so the bus gives it again only
|
||||
// when the builder itself stopped; the send here answers once the bus has been told three times.
|
||||
told := make(chan struct{})
|
||||
p.progressEvery = time.Millisecond
|
||||
p.send = func(context.Context, versions.QueuedPublish) versions.SendFate {
|
||||
select {
|
||||
case <-told:
|
||||
return versions.SendFate{Unread: "not answered within the bound"}
|
||||
case <-time.After(10 * time.Second):
|
||||
return versions.SendFate{Failed: "the item was never marked in progress"}
|
||||
}
|
||||
}
|
||||
m = queuedMsg(t, "m", "0.1.2")
|
||||
var once sync.Once
|
||||
m.onWorking = func(n int64) {
|
||||
if n >= 3 {
|
||||
once.Do(func() { close(told) })
|
||||
}
|
||||
}
|
||||
p.take(ctx, m)
|
||||
if n := m.progress.Load(); n < 3 || len(m.settled) != 0 {
|
||||
t.Fatalf("a send whose call waits: told in progress %d times, settled %v, want 3 or more and the item left, never ended", n, m.settled)
|
||||
}
|
||||
p.send = func(_ context.Context, q versions.QueuedPublish) versions.SendFate {
|
||||
sent = append(sent, q.Module+" "+q.Version)
|
||||
return fate
|
||||
}
|
||||
fate = versions.SendFate{Sent: true}
|
||||
m = queuedMsg(t, "m", "0.1.2")
|
||||
p.take(ctx, m)
|
||||
if len(m.settled) != 0 {
|
||||
t.Fatalf("a sent item is settled %v, want it held until its publish is heard", m.settled)
|
||||
}
|
||||
// An item whose artifacts are all published is acknowledged unsent; its publish item stays until its release is written (A-456b).
|
||||
_ = p.Ask(ctx, "m", "0.3.0")
|
||||
pk := versions.PublishItemKey("m", "0.3.0")
|
||||
m = queuedMsg(t, "m", "0.3.0")
|
||||
if p.take(ctx, m); fmt.Sprint(m.settled) != "[ack]" || len(sent) != 4 || !kv.has(pk) {
|
||||
t.Errorf("an item whose artifacts are published was settled %v, sent %d, kept %v: want it acknowledged unsent, its publish item kept", m.settled, len(sent), kv.has(pk))
|
||||
p.take(ctx, m)
|
||||
if !slices.Equal(m.settled, []string{"ack"}) {
|
||||
t.Errorf("an item whose artifacts are published settled %v, want ack", m.settled)
|
||||
}
|
||||
kv.vals, kv.revs = map[string][]byte{}, map[string]uint64{}
|
||||
// At the start every reservation of a done build with no release is asked, one item each.
|
||||
kv.vals, kv.revs = map[string][]byte{}, map[string]uint64{}
|
||||
p.allDone = func(context.Context) ([]versions.ReservedVersion, error) {
|
||||
published := versions.ReservedVersion{Module: "n", Version: "0.2.0", Artifacts: map[string]string{"n:a": "sha256:a"}, Published: map[string]bool{"n:a": true}, BuiltAt: now}
|
||||
withdrawn := versions.ReservedVersion{Module: "w", Version: "0.4.0", BuiltAt: now, Withdrawn: map[string]string{"0.4.0": "fp"}}
|
||||
return builtOf([]versions.ReservedVersion{v, published, withdrawn, {Module: "o", Version: "0.1.0"}}), nil // the last build has not ended
|
||||
}
|
||||
_ = p.Ask(ctx, "w", "0.4.0") // asked before its reservation was withdrawn
|
||||
p.AskAllDone(ctx)
|
||||
if _, ok := kv.vals[versions.PublishItemKey("w", "0.4.0")]; len(kv.vals) != 2 || ok {
|
||||
t.Errorf("the start left %d items (withdrawn's kept: %v), want one per done unreleased reservation and none for a withdrawn one (H-A-290 (2))", len(kv.vals), ok)
|
||||
}
|
||||
// A start with three unreleased done versions of one module asks only the newest and retires the two (H-A-291 (1), H-A-275).
|
||||
kv.vals, kv.revs = map[string][]byte{}, map[string]uint64{}
|
||||
_ = p.Ask(ctx, "s", "0.1.3") // asked in an earlier run
|
||||
p.allDone = func(context.Context) ([]versions.ReservedVersion, error) {
|
||||
var out []versions.ReservedVersion
|
||||
for _, ver := range []string{"0.1.3", "0.1.10", "0.1.2"} { // one series (H-A-293)
|
||||
out = append(out, versions.ReservedVersion{Module: "s", Version: ver, Artifacts: map[string]string{"s:a": "sha256:a"}, BuiltAt: now})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
p.retired = (&versions.Reserver{}).Retired
|
||||
p.AskAllDone(ctx)
|
||||
if _, ok := kv.vals[versions.PublishItemKey("s", "0.1.10")]; len(kv.vals) != 1 || !ok {
|
||||
t.Errorf("the start left the items %v, want only the newest, s 0.1.10, asked and the two older retired", slices.Collect(maps.Keys(kv.vals)))
|
||||
}
|
||||
kv.vals, kv.revs = map[string][]byte{}, map[string]uint64{}
|
||||
// A released version's item is deleted; a version no longer reserved has it deleted at its next try.
|
||||
p.Done(ctx, "m", "0.1.2")
|
||||
p.Done(ctx, "n", "0.2.0")
|
||||
if len(kv.vals) != 0 {
|
||||
t.Errorf("the release left %v", kv.vals)
|
||||
}
|
||||
// A withdrawn reservation has its item ended at its try, nothing queued (H-A-290 (2)).
|
||||
queued = nil
|
||||
_ = p.Ask(ctx, "m", "0.1.2")
|
||||
v.Withdrawn = map[string]string{"0.1.2": "fp"}
|
||||
e, _ = kv.Get(ctx, key)
|
||||
p.Try(ctx, kv, e, decodeItem(t, e.Value()))
|
||||
if len(kv.vals) != 0 || len(queued) != 0 {
|
||||
t.Errorf("a withdrawn reservation left its item %v, queued %v", kv.vals, queued)
|
||||
}
|
||||
v.Withdrawn = nil
|
||||
_ = p.Ask(ctx, "m", "0.1.2")
|
||||
reserved = false
|
||||
e, _ = kv.Get(ctx, key)
|
||||
p.Try(ctx, kv, e, decodeItem(t, e.Value()))
|
||||
if len(kv.vals) != 0 {
|
||||
t.Errorf("a dropped reservation left its item %v", kv.vals)
|
||||
m = queuedMsg(t, "m", "0.1.2")
|
||||
p.take(ctx, m)
|
||||
if !slices.Equal(m.settled, []string{"term"}) {
|
||||
t.Errorf("an item of a version no longer reserved settled %v, want term", m.settled)
|
||||
}
|
||||
}
|
||||
|
||||
// TestThePublishSettingsAreReadFromTheirFiles: design 47 G A-457a, H2 H-A-446 (2) — the three settings, 30 s, 30 min and 5 tries
|
||||
// unless set, and a
|
||||
// content that is no number is refused naming its file.
|
||||
func TestThePublishSettingsAreReadFromTheirFiles(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
write := func(name, v string) string {
|
||||
p := filepath.Join(dir, name)
|
||||
if err := os.WriteFile(p, []byte(v), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return p
|
||||
reserved = true
|
||||
// design 47 H2 H-A-746: a publish dropped by hand is kept on the reservation, read as its standing: the item is terminated unsent.
|
||||
v.Dropped = &versions.PublishDropped{By: "a person", Why: "why", At: now}
|
||||
before := len(sent)
|
||||
m = queuedMsg(t, "m", "0.1.2")
|
||||
p.take(ctx, m)
|
||||
if !slices.Equal(m.settled, []string{"term"}) || len(sent) != before {
|
||||
t.Errorf("a dropped publish: settled %v, sent %d more, want it terminated and not sent", m.settled, len(sent)-before)
|
||||
}
|
||||
env := map[string]string{}
|
||||
got, err := publishSettingsOf(func(k string) string { return env[k] })
|
||||
if err != nil || got != defaultPublishSettings || got.Pause != 30*time.Second || got.PauseMax != 30*time.Minute || got.Tries != 5 {
|
||||
t.Fatalf("defaults = %+v (%v)", got, err)
|
||||
v.Dropped = nil
|
||||
// design 47 H2 H-A-653, H-A-703: the delivery where an item reaches the queue's ten ends it and raises version-unreleased.
|
||||
var words []string
|
||||
p.unreleased = func(_ context.Context, _ versions.ReservedVersion, why string) { words = append(words, why) }
|
||||
before = len(sent)
|
||||
m = queuedMsg(t, "m", "0.1.2")
|
||||
m.delivered = publishesMaxDeliver - 1
|
||||
p.take(ctx, m)
|
||||
if len(words) != 0 || len(sent) != before+1 {
|
||||
t.Errorf("a ninth delivery: said %v, sent %d more, want it sent", words, len(sent)-before)
|
||||
}
|
||||
env["MESH_BUILDER_PUBLISH_PAUSE_FILE"], env["MESH_BUILDER_PUBLISH_PAUSE_MAX_FILE"], env["MESH_BUILDER_PUBLISH_TRIES_FILE"] = write("p", "5\n"), write("m", "2"), write("t", "3")
|
||||
if got, err = publishSettingsOf(func(k string) string { return env[k] }); err != nil || got != (publishSettings{5 * time.Second, 2 * time.Minute, 3}) {
|
||||
t.Errorf("set = %+v (%v)", got, err)
|
||||
m = queuedMsg(t, "m", "0.1.2")
|
||||
m.delivered = publishesMaxDeliver
|
||||
p.take(ctx, m)
|
||||
if !slices.Equal(m.settled, []string{"term"}) || len(sent) != before+1 || len(words) != 1 || words[0] != "given up after 10 deliveries" {
|
||||
t.Errorf("a tenth delivery: settled %v, said %v, want it terminated unsent with %q", m.settled, words, "given up after 10 deliveries")
|
||||
}
|
||||
env["MESH_BUILDER_PUBLISH_TRIES_FILE"] = write("bad", "many")
|
||||
if _, err = publishSettingsOf(func(k string) string { return env[k] }); err == nil || !strings.Contains(err.Error(), "bad") {
|
||||
t.Errorf("a content that is no number: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestThePublishItemsAreWiredToTheReservationsAndTheReAskWatch: design 47 G A-457a, A-456b — a mode-publish value of the re-ask state
|
||||
// reaches the item's try through reAsked; a done build gets an item; the catalog's version-released, a drop and a takeover delete it
|
||||
// and the release is kept by module.
|
||||
func TestThePublishItemsAreWiredToTheReservationsAndTheReAskWatch(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
kv := &itemKV{vals: map[string][]byte{}, revs: map[string]uint64{}}
|
||||
st := &memFindings{vals: map[string][]byte{}}
|
||||
found := &findings{module: builds.BuilderModule, w: st, logf: t.Logf, now: func() time.Time { return time.Unix(0, 0) }}
|
||||
call := func(string, any) (json.RawMessage, error) {
|
||||
return json.Marshal(meshcatalog.VersionsAnswer{Module: "m"})
|
||||
}
|
||||
rv := newReservations(&memReserve{vals: map[string][]byte{}, revs: map[string]uint64{}}, call, func() jetstream.KeyValue { return &boundsKV{keys: map[string]bool{}} }, found, t.Logf)
|
||||
tried := make(chan string, 4)
|
||||
items := &publishItems{reasks: func() jetstream.KeyValue { return kv }, set: defaultPublishSettings, now: time.Now, logf: t.Logf,
|
||||
reserved: func(ctx context.Context, m, v string) (versions.ReservedVersion, bool, error) {
|
||||
return rv.r.Of(ctx, m, v)
|
||||
},
|
||||
republish: func(_ context.Context, m, v string) ([]string, error) { tried <- m + " " + v; return nil, nil }}
|
||||
releases := &memReserve{vals: map[string][]byte{}, revs: map[string]uint64{}}
|
||||
wirePublishItems(rv, items, releases, 2)
|
||||
done := func(fp string) versions.ReservedVersion {
|
||||
v, err := rv.Reserve(ctx, "m", "0.1", []string{"m:a"}, versions.Source{Fingerprint: fp})
|
||||
// design 47 H2 H-A-749 (2): at the start an answered publish-drop ask is carried onto its version's reservation as dropped, where
|
||||
// it stands and holds none; a refused one is not; each record of mode publish is deleted, the drop's own ask staying.
|
||||
res := &versions.Reserver{Store: &memReserve{vals: map[string][]byte{}, revs: map[string]uint64{}}, Now: func() time.Time { return now },
|
||||
ReleasedOf: func(context.Context, string) ([]string, error) { return nil, nil }}
|
||||
for _, m := range []string{"m", "n"} {
|
||||
rv, err := res.Reserve(ctx, m, "0.1", []string{m + ":a"}, versions.Source{Fingerprint: "src2:" + m})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := rv.Built(ctx, "m", v.Version, map[string]string{"m:a": "sha256:a"}, nil); err != nil {
|
||||
if _, _, err := res.Built(ctx, m, rv.Version, map[string]string{m + ":a": "sha256:a"}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
first := done("src2:one")
|
||||
key := versions.PublishItemKey("m", first.Version)
|
||||
if !kv.has(key) {
|
||||
t.Fatalf("a done build has no publish item: %v", kv.vals)
|
||||
old := &itemKV{vals: map[string][]byte{}, revs: map[string]uint64{}}
|
||||
put := func(key string, r build.ReAsk) {
|
||||
raw, _ := json.Marshal(r)
|
||||
old.vals[key], old.revs[key] = raw, 1
|
||||
}
|
||||
// A build whose artifacts are all published still gets its item, until its release is written (A-456b).
|
||||
if _, _, err := rv.r.Published(ctx, versions.NameOf("m", "a"), first.Version, "sha256:a"); err != nil {
|
||||
t.Fatal(err)
|
||||
put("publish-drop.1", build.ReAsk{V: 1, Mode: build.ModePublishDrop, Module: "m", Version: "0.1.0", By: "op@node", Why: "a person's drop", At: now, Answered: now})
|
||||
put("publish-drop.2", build.ReAsk{V: 1, Mode: build.ModePublishDrop, Module: "n", Version: "0.1.0", By: "op@node", Why: "refused", At: now, Answered: now, Refused: true})
|
||||
put("publish.m.0.1.0", build.ReAsk{V: 1, Mode: "publish", Module: "m", Version: "0.1.0", Answer: "dropped by op@node: a person's drop", Answered: now})
|
||||
carryDrops(ctx, old, res, t.Logf)
|
||||
if m0, _, _ := res.Of(ctx, "m", "0.1.0"); m0.Dropped == nil || m0.Dropped.By != "op@node" || m0.Dropped.Why != "a person's drop" || !m0.Dropped.At.Equal(now) {
|
||||
t.Errorf("m's reservation reads dropped %+v, want the earlier drop carried onto it", m0.Dropped)
|
||||
}
|
||||
items.Done(ctx, "m", first.Version)
|
||||
if err := rv.Built(ctx, "m", first.Version, map[string]string{"m:a": "sha256:a"}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !kv.has(key) {
|
||||
t.Fatalf("a build with every artifact published has no item: %v", kv.vals)
|
||||
}
|
||||
// The watch hands the item to its try, which queues the publish.
|
||||
e, _ := kv.Get(ctx, key)
|
||||
reAsked(ctx, nil, versions.Acts{}, items, kv, e, t.Logf)
|
||||
select {
|
||||
case got := <-tried:
|
||||
if got != "m "+first.Version {
|
||||
t.Errorf("tried %q", got)
|
||||
}
|
||||
case <-time.After(10 * time.Second):
|
||||
t.Fatal("a mode-publish value was not handed to the item's try")
|
||||
}
|
||||
// A takeover by another build deletes the older's item and asks the newer's.
|
||||
second := done("src2:two")
|
||||
if kv.has(key) {
|
||||
t.Errorf("the taken-over reservation kept its item")
|
||||
}
|
||||
secondKey := versions.PublishItemKey("m", second.Version)
|
||||
if !kv.has(secondKey) {
|
||||
t.Fatalf("the newer build has no item: %v", kv.vals)
|
||||
}
|
||||
// version-released deletes the item and keeps the release.
|
||||
msg := &wakeMsg{subject: meshcatalog.SubjectVersionReleased, data: []byte(`{"v":1,"module":"m","version":"` + second.Version + `","source":1,"artifacts":[]}`)}
|
||||
if !rv.heard(ctx, msg) || !msg.acked {
|
||||
t.Fatal("version-released was not taken in")
|
||||
}
|
||||
if kv.has(secondKey) {
|
||||
t.Errorf("a released version kept its publish item")
|
||||
}
|
||||
if ok, _ := rv.ReleasedFor(ctx, "m", "src2:two"); !ok {
|
||||
t.Errorf("the release is not kept by fingerprint")
|
||||
}
|
||||
// A drop deletes the item too.
|
||||
third := done("src2:three")
|
||||
if _, err := rv.dropped(ctx, "m", "0.1", "op", "never", time.Unix(0, 0)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if kv.has(versions.PublishItemKey("m", third.Version)) {
|
||||
t.Errorf("a dropped reservation kept its item")
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 H H-A-269 (2), H-A-272, H-A-274, H-A-275, and design 47 H2 H-A-514 addendum: a publish is asked again judged from
|
||||
// what the builder recorded and the registries' record alone, never from how many events its consumer holds unheard: a
|
||||
// reservation marking every artifact published is acknowledged; a record holding every missing artifact with the built digest
|
||||
// marks them published from it; a record holding the version at another digest moves the build to the next free number and
|
||||
// ends this item; a record lacking it is asked again; a skipped try spends no try and is written again with its pause.
|
||||
func TestAPublishIsAskedAgainFromWhatTheBuilderRecorded(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
now := time.Date(2026, 11, 21, 15, 21, 0, 0, time.UTC)
|
||||
v := versions.ReservedVersion{Module: "node-tools", Version: "0.1.37", Artifacts: map[string]string{"node-tools:program": "sha256:7c9b10"}, BuiltAt: now}
|
||||
at := versions.HeldArtifact{Ref: "node-tools:program", Seat: versions.SeatArtifacts, Name: "node-tools/program", Version: "0.1.37", Digest: "sha256:7c9b10"}
|
||||
other := at
|
||||
other.Digest = "sha256:83bec1"
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
published bool
|
||||
judged versions.Judged
|
||||
wantAsked, wantMark, wantMov bool
|
||||
}{
|
||||
{name: "its reservation marks it published: acknowledged, no ask", published: true},
|
||||
{name: "the registry holds it: marked from its record, no ask", judged: versions.Judged{All: true, Held: []versions.HeldArtifact{at}}, wantMark: true},
|
||||
{name: "the registry holds the number at another digest: moved, no ask", judged: versions.Judged{Elsewhere: []versions.HeldArtifact{other}}, wantMov: true},
|
||||
{name: "the registry lacks it: asked, whatever the events consumer holds", judged: versions.Judged{Lacks: "none"}, wantAsked: true},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
kv := &itemKV{vals: map[string][]byte{}, revs: map[string]uint64{}}
|
||||
asked, judged, marked, moved := 0, 0, 0, 0
|
||||
p := &publishItems{reasks: func() jetstream.KeyValue { return kv }, set: defaultPublishSettings, now: func() time.Time { return now }, logf: t.Logf,
|
||||
reserved: func(context.Context, string, string) (versions.ReservedVersion, bool, error) {
|
||||
if c.published {
|
||||
w := v
|
||||
w.Published = map[string]bool{"node-tools:program": true}
|
||||
return w, true, nil
|
||||
}
|
||||
return v, true, nil
|
||||
},
|
||||
send: func(context.Context, versions.QueuedPublish) versions.SendFate {
|
||||
asked++
|
||||
return versions.SendFate{Sent: true}
|
||||
},
|
||||
judge: func(context.Context, versions.ReservedVersion) (versions.Judged, error) {
|
||||
judged++
|
||||
return c.judged, nil
|
||||
},
|
||||
markHeld: func(_ context.Context, _ versions.ReservedVersion, h []versions.HeldArtifact) {
|
||||
if len(h) == 1 && h[0].Digest == "sha256:7c9b10" {
|
||||
marked++
|
||||
}
|
||||
},
|
||||
moveElsewhere: func(context.Context, versions.ReservedVersion, versions.Judged) error {
|
||||
moved++
|
||||
delete(kv.vals, versions.PublishItemKey(v.Module, v.Version)) // the takeover ends the old item
|
||||
return nil
|
||||
}}
|
||||
if err := p.Ask(ctx, v.Module, v.Version); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
key := versions.PublishItemKey(v.Module, v.Version)
|
||||
m := queuedMsg(t, v.Module, v.Version)
|
||||
m.data = []byte(strings.ReplaceAll(string(m.data), `"node-tools:a"`, `"node-tools:program"`))
|
||||
p.take(ctx, m)
|
||||
if (asked == 1) != c.wantAsked || (marked == 1) != c.wantMark || (moved == 1) != c.wantMov {
|
||||
t.Fatalf("asked %d, marked %d, moved %d; want asked %v, marked %v, moved %v", asked, marked, moved, c.wantAsked, c.wantMark, c.wantMov)
|
||||
}
|
||||
if c.published {
|
||||
if fmt.Sprint(m.settled) != "[ack]" || judged != 0 {
|
||||
t.Errorf("a version its reservation marks published settled %v, the registry read %d times; want acknowledged, none read", m.settled, judged)
|
||||
}
|
||||
return
|
||||
}
|
||||
if c.wantMov {
|
||||
if _, ok := kv.vals[key]; ok || fmt.Sprint(m.settled) != "[term]" {
|
||||
t.Errorf("the moved version's old item is written again, or its item settled %v, not terminated", m.settled)
|
||||
}
|
||||
return
|
||||
}
|
||||
got := decodeItem(t, kv.vals[key])
|
||||
if got.Tries != map[bool]int{true: 1, false: 0}[c.wantAsked] || (c.wantAsked && !got.NextTry.After(now)) {
|
||||
t.Errorf("tries %d, next try %s: want a try spent only when sent, the item written with its pause", got.Tries, got.NextTry)
|
||||
}
|
||||
if !c.wantAsked && fmt.Sprint(m.settled) != "[nak 30s]" {
|
||||
t.Errorf("an item not sent was settled %v, want it handed back with the pause and no try spent", m.settled)
|
||||
}
|
||||
})
|
||||
if n0, _, _ := res.Of(ctx, "n", "0.1.0"); n0.Dropped != nil || old.has("publish.m.0.1.0") || !old.has("publish-drop.1") || !old.has("publish-drop.2") {
|
||||
t.Errorf("n dropped %+v, publish record left %v: want a refused drop not carried, the record gone and the asks kept", n0.Dropped, old.has("publish.m.0.1.0"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,13 +45,6 @@ func reAsked(ctx context.Context, b askAgainer, acts versions.Acts, items *publi
|
||||
if r.Answer != "" {
|
||||
return
|
||||
}
|
||||
if r.Mode == build.ModePublish {
|
||||
// A version's publish item (design 47 G A-457a): its try waits for its pause, so it is made beside the watch.
|
||||
if items != nil {
|
||||
go items.Try(ctx, kv, e, r)
|
||||
}
|
||||
return
|
||||
}
|
||||
if r.Mode == build.ModeBuild {
|
||||
// The answer comes when the claim and the asks are written, so it is made beside the watch, not in it.
|
||||
go builtAgain(ctx, b, kv, e, r, logf)
|
||||
@@ -65,7 +58,7 @@ func reAsked(ctx context.Context, b askAgainer, acts versions.Acts, items *publi
|
||||
released(ctx, b, kv, e, r, logf)
|
||||
return
|
||||
}
|
||||
if r.Mode == build.ModeRepublish || r.Mode == build.ModePublishDrop || r.Mode == build.ModeOldFormDrop || r.Mode == build.ModeReservedDrop || r.Mode == build.ModeReserveDone {
|
||||
if r.Mode == build.ModeRepublish || r.Mode == build.ModePublishDrop || r.Mode == build.ModeOldFormDrop || r.Mode == build.ModeReservedDrop {
|
||||
// A version's hand act (design 51 *Tools of the builder*) may build again, so it is answered beside the watch.
|
||||
go versionActed(ctx, acts, kv, e, r, logf)
|
||||
return
|
||||
@@ -196,7 +189,7 @@ func emitBuildEnded(ctx context.Context, js jetstream.JetStream, cred process.Ac
|
||||
return nil
|
||||
}
|
||||
|
||||
// versionActed answers a reasks value of builder_publish_again, builder_publish_drop, builder_reserve_done, builder_reserved_drop or builder_old_form's drop, a hand act said in the log.
|
||||
// versionActed answers a reasks value of builder_publish_again, builder_publish_drop, builder_reserved_drop or builder_old_form's drop, a hand act said in the log.
|
||||
func versionActed(ctx context.Context, acts versions.Acts, kv jetstream.KeyValue, e jetstream.KeyValueEntry, r build.ReAsk, logf func(string, ...any)) {
|
||||
var err error
|
||||
if r.Mode == build.ModeRepublish {
|
||||
@@ -215,17 +208,11 @@ func versionActed(ctx context.Context, acts versions.Acts, kv jetstream.KeyValue
|
||||
} else {
|
||||
r.Answer, err = act(ctx, r.Module, r.Version, r.By, r.Why)
|
||||
}
|
||||
} else if r.Mode == build.ModeReserveDone {
|
||||
if acts.ReserveDone == nil {
|
||||
err = errors.New("this builder keeps no reservations")
|
||||
} else {
|
||||
r.Answer, err = acts.ReserveDone(ctx, r.Name, r.FP, r.By, r.Why, r.At)
|
||||
}
|
||||
} else if r.Mode == build.ModeReservedDrop {
|
||||
if acts.DropReserved == nil {
|
||||
err = errors.New("this builder keeps no reservations")
|
||||
} else {
|
||||
r.Answer, err = acts.DropReserved(ctx, r.Name, r.FP, r.By, r.Why, r.At)
|
||||
r.Answer, err = acts.DropReserved(ctx, r.Name, r.FP, r.Version, r.By, r.Why, r.At)
|
||||
}
|
||||
} else if acts.DropOldForm == nil {
|
||||
err = errors.New("this builder keeps no old-form window")
|
||||
|
||||
@@ -566,4 +566,8 @@ func TestTheBuildersFindingsAreObservedByItsCredentialsModule(t *testing.T) {
|
||||
if err != nil || got.Observer != "acme-builder" {
|
||||
t.Fatalf("the finding = %+v, %v; want the observer acme-builder", got, err)
|
||||
}
|
||||
// H2 H-A-578 (1): floor-silent, which no code of the builder raises any more, is cleared at the writer's start
|
||||
if !slices.ContainsFunc(retiredFindingKinds, func(r views.RetiredKind) bool { return r.Kind == "floor-silent" && len(r.IDs) == 0 }) || slices.ContainsFunc(retiredFindingKinds, func(r views.RetiredKind) bool { return r.Kind == BuildFailed }) {
|
||||
t.Error("the writer's retired kinds are not floor-silent alone")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,11 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/gopackageregistry"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/busretry"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
|
||||
"mesh-delivery-builder/internal/versions"
|
||||
@@ -47,9 +49,15 @@ func publishAskID(p versions.Publish) string {
|
||||
// artifact store, addressed by digest. The four seats' publish take one wire form; an answer that lacks parts, or a fault of
|
||||
// the call, is the holder's refusal, said in its words (not stored when the holder lacks the bytes). The publish is a kept
|
||||
// call carrying its ask id (design 47 H2 §775), made again through transport faults at the kept-call pace within ctx's bound.
|
||||
func sendVia(call keptCaller) func(ctx context.Context, p versions.Publish) error {
|
||||
//
|
||||
// said is told when the call has waited five minutes unanswered and once at its answer (busretry.WaitSaid; design 47 H2 H-A-613 (4),
|
||||
// H-A-620 (3): call-unanswered written after five minutes, ADR 0668 §3); nil is told nothing.
|
||||
func sendVia(call keptCaller, said func(p versions.Publish, w busretry.Waited)) func(ctx context.Context, p versions.Publish) error {
|
||||
return func(ctx context.Context, p versions.Publish) error {
|
||||
ask := process.KeptAsk{ID: publishAskID(p)}
|
||||
if said != nil {
|
||||
ask.Hook = func(w busretry.Waited) { said(p, w) }
|
||||
}
|
||||
if d, ok := ctx.Deadline(); ok {
|
||||
ask.Bound = time.Until(d)
|
||||
}
|
||||
@@ -62,6 +70,11 @@ func sendVia(call keptCaller) func(ctx context.Context, p versions.Publish) erro
|
||||
if err := json.Unmarshal(raw, &a); err != nil {
|
||||
return fmt.Errorf("%s answered what is no publish answer: %w", p.Seat, err)
|
||||
}
|
||||
// A version held with other bytes is answered, never failed (design 47 H2 H-A-729); it is read before the transfer, which is
|
||||
// absent exactly then (H-A-732).
|
||||
if a.OtherBytes != nil {
|
||||
return &versions.OtherBytes{Seat: p.Seat, Name: p.Name, Version: p.Version, Digest: a.OtherBytes.Digest, Fingerprint: a.OtherBytes.Fingerprint}
|
||||
}
|
||||
if len(a.Lacks) > 0 {
|
||||
return fmt.Errorf("%s%s holds %d of the parts of %s %s", versions.NotStoredWords, p.Seat, len(a.Lacks), p.Name, p.Version)
|
||||
}
|
||||
@@ -96,3 +109,18 @@ func callWithin(ctx context.Context, call toolCaller, key string, body any) (jso
|
||||
func publishBody(p versions.Publish) gopackageregistry.PublishInput {
|
||||
return gopackageregistry.PublishInput{Commit: p.Commit, Digest: p.Digest, Fingerprint: p.Fingerprint, Kind: p.Kind, Name: p.Name, Transfer: p.Transfer, Version: p.Version}
|
||||
}
|
||||
|
||||
// publishUnanswered is what a publish's kept call tells when it has waited five minutes and at its answer (design 47 H2 H-A-613 (4),
|
||||
// H-A-620 (3); ADR 0668 §3): the finding call-unanswered about the publish's ask id is raised at the first and cleared at the second.
|
||||
func publishUnanswered(ctx context.Context, f *findings) func(versions.Publish, busretry.Waited) {
|
||||
return func(p versions.Publish, w busretry.Waited) {
|
||||
id := publishAskID(p)
|
||||
if w.Answered {
|
||||
f.clear(ctx, meshconditionsclient.KindCallUnanswered, meshconditionsclient.ScopeCall, id)
|
||||
return
|
||||
}
|
||||
o := callUnanswered(id, "seat:"+p.Seat+"."+versions.VerbPublish+" of "+p.Name+" "+p.Version, "", w.Last, "builder."+meshconditionsclient.KindCallUnanswered, w.Since)
|
||||
o.needs = "the call is made again by itself until the holder answers; builder_publish_queue shows the item."
|
||||
f.raise(ctx, o)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@ import (
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
"git.novox.be/novox/mesh-sdk/go/busretry"
|
||||
"mesh-delivery-builder/internal/build"
|
||||
"mesh-delivery-builder/internal/versions"
|
||||
)
|
||||
@@ -54,7 +57,7 @@ func TestRepublishSend(t *testing.T) {
|
||||
send := sendVia(func(ask process.KeptAsk, key string, body any) (json.RawMessage, error) {
|
||||
asked, id = key, ask.ID
|
||||
return json.RawMessage(c.answer), c.err
|
||||
})
|
||||
}, nil)
|
||||
err := send(context.Background(), p)
|
||||
// design 47 H2 §775: the publish carries its ask id, the same for the same publish
|
||||
if asked != "seat:oci-artifact-registry.publish" || id != publishAskID(p) || strings.Contains(id, ".") || (c.want == "") != (err == nil) || (err != nil && !strings.Contains(err.Error(), c.want)) {
|
||||
@@ -73,7 +76,7 @@ func TestRepublishSend(t *testing.T) {
|
||||
}
|
||||
for name, call := range map[string]func(context.Context) error{
|
||||
"the publish": func(ctx context.Context) error {
|
||||
return sendVia(func(_ process.KeptAsk, k string, b any) (json.RawMessage, error) { return slow(k, b) })(ctx, p)
|
||||
return sendVia(func(_ process.KeptAsk, k string, b any) (json.RawMessage, error) { return slow(k, b) }, nil)(ctx, p)
|
||||
},
|
||||
"the entry": func(ctx context.Context) error { _, err := entryVia(slow)(ctx, "fp"); return err },
|
||||
} {
|
||||
@@ -89,3 +92,29 @@ func TestRepublishSend(t *testing.T) {
|
||||
}
|
||||
|
||||
func versionsNow() time.Time { return time.Unix(1, 0) }
|
||||
|
||||
// Design 47 H2 H-A-613 (4), H-A-620 (3): a publish's kept call that has waited five minutes raises call-unanswered about its ask id,
|
||||
// and its answer clears it; the call carries the hook that says so.
|
||||
func TestAPublishWaitedFiveMinutesIsCallUnanswered(t *testing.T) {
|
||||
p := versions.Publish{Seat: versions.SeatArtifacts, Kind: "bundle", Name: "m/prog", Version: "0.1.3", Digest: "sha256:aa"}
|
||||
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) }}
|
||||
said := publishUnanswered(context.Background(), f)
|
||||
var hook func(busretry.Waited)
|
||||
_ = sendVia(func(ask process.KeptAsk, _ string, _ any) (json.RawMessage, error) {
|
||||
hook = ask.Hook
|
||||
return json.RawMessage(`{"held":true}`), nil
|
||||
}, said)(context.Background(), p)
|
||||
if hook == nil {
|
||||
t.Fatal("the publish's kept call carries no hook")
|
||||
}
|
||||
key := meshconditionsclient.Key(meshconditionsclient.ScopeCall, publishAskID(p), meshconditionsclient.KindCallUnanswered)
|
||||
hook(busretry.Waited{Since: time.Unix(0, 0), Last: "no responders"})
|
||||
if got, err := decodeFinding(st.vals[key]); err != nil || got.Kind != meshconditionsclient.KindCallUnanswered || !strings.Contains(got.Summary, "m/prog 0.1.3") {
|
||||
t.Fatalf("the call waited: finding %+v, %v", got, err)
|
||||
}
|
||||
hook(busretry.Waited{Answered: true})
|
||||
if st.vals[key] != nil {
|
||||
t.Error("the call answered: the finding stands")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -58,6 +59,10 @@ type reservations struct {
|
||||
recordAgain func(ctx context.Context, module, fp, when string) (string, error)
|
||||
// rebuild builds a done key of module at fp again (the build-again path, A-490; H-A-279); nil builds none.
|
||||
rebuild func(ctx context.Context, module, fp, why string) error
|
||||
// looking says a look of the builder holds the build key of module at fp now (builder_reserved_drop refuses it); nil says none.
|
||||
looking func(module, fp string) bool
|
||||
// judge reads the registries' record of a reservation's artifacts at its version (the republisher's Held); nil reads none.
|
||||
judge func(ctx context.Context, v versions.ReservedVersion) (versions.Judged, error)
|
||||
// say says package-published on the seat mesh-builds; nil says none.
|
||||
say func(context.Context, meshbuilds.PackagePublished) error
|
||||
// names is each package's name as its series key names it (for Go, its module path), and sayReserved says version-reserved on
|
||||
@@ -114,7 +119,7 @@ func sayReservedOn(js jetstream.JetStream, cred process.Account) func(context.Co
|
||||
// newReservations makes the reserving over store; the released versions of a module are asked of the seat mesh-catalog's
|
||||
// verb versions through call (design 47 G §348), the only source numbering reads them from.
|
||||
func newReservations(store versions.ReserveStore, call toolCaller, bounds func() jetstream.KeyValue, found *findings, logf func(string, ...any)) *reservations {
|
||||
rv := &reservations{bounds: bounds, found: found, bound: versions.UnreleasedBound, logf: logf}
|
||||
rv := &reservations{bounds: bounds, found: found, bound: defaultPublishAckMinutes * time.Minute, logf: logf}
|
||||
rv.r = &versions.Reserver{Store: store, ReleasedOf: func(_ context.Context, module string) ([]string, error) {
|
||||
raw, err := call("seat:"+meshcatalog.Seat+".versions", meshcatalog.VersionsInput{Module: module})
|
||||
if err != nil {
|
||||
@@ -131,9 +136,17 @@ func newReservations(store versions.ReserveStore, call toolCaller, bounds func()
|
||||
return out, nil
|
||||
}}
|
||||
rv.r.Took, rv.r.Logf, rv.r.Reserved = rv.took, logf, rv.reservedSaid
|
||||
rv.setBound(rv.bound)
|
||||
return rv
|
||||
}
|
||||
|
||||
// setBound sets the publish's bound, the setting publish-ack-minutes (design 47 H2 H-A-613 (3)): past it a built reservation
|
||||
// with an artifact unpublished is the finding version-unreleased, armed and judged by this one value.
|
||||
func (rv *reservations) setBound(d time.Duration) {
|
||||
rv.bound = d
|
||||
rv.r.Bound = d
|
||||
}
|
||||
|
||||
// reindex writes the reservations' index again from the reservations, once at the builder's start (H-A-269 (1), H-A-271), and
|
||||
// says so.
|
||||
func (rv *reservations) reindex(ctx context.Context) {
|
||||
@@ -186,9 +199,9 @@ func (rv *reservations) TakenOver(ctx context.Context, module, fingerprint strin
|
||||
return rv.r.TakenOver(ctx, module, fingerprint)
|
||||
}
|
||||
|
||||
// VersionAt is the version module's artifact is published at from the source revision of branch (H-A-547 (3), H-A-551).
|
||||
func (rv *reservations) VersionAt(ctx context.Context, module, artifact, branch string, source int64) (string, bool, error) {
|
||||
return rv.r.VersionAt(ctx, module, artifact, branch, source)
|
||||
// PublishedOf answers the seat mesh-builds' published rule for the build's pins (H-A-328, design 47 H2 H-A-707 (4)).
|
||||
func (rv *reservations) PublishedOf(ctx context.Context, module, artifact, fingerprint string) (meshbuilds.PublishedAnswer, error) {
|
||||
return rv.r.PublishedOf(ctx, module, artifact, fingerprint)
|
||||
}
|
||||
|
||||
func (rv *reservations) Reserve(ctx context.Context, module, series string, artifacts []string, src versions.Source) (versions.ReservedVersion, error) {
|
||||
@@ -501,22 +514,55 @@ func (rv *reservations) sayPublished(ctx context.Context, m versions.Marked, dig
|
||||
}
|
||||
}
|
||||
|
||||
// dropped is builder_reserved_drop: the reservation is deleted and its bound ended.
|
||||
func (rv *reservations) dropped(ctx context.Context, module, series, by, why string, at time.Time) (string, error) {
|
||||
cur, held, _ := rv.r.At(ctx, versions.ReservedKey(module, series))
|
||||
// dropped is builder_reserved_drop (design 47 H2 H-A-592): it names its version, and the reservation of the series is deleted whole
|
||||
// only when it stands at that version and its fingerprint is not building; the publish item and the version-unreleased go with it,
|
||||
// the bound ends, and the answer names what was forgotten.
|
||||
func (rv *reservations) dropped(ctx context.Context, module, series, version, by, why string, at time.Time) (string, error) {
|
||||
cur, held, err := rv.r.At(ctx, versions.ReservedKey(module, series))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if !held {
|
||||
return "", fmt.Errorf("%s holds no reservation of %s", module, series)
|
||||
}
|
||||
if cur.Version != version {
|
||||
return "", fmt.Errorf("%s's reservation of %s stands at %s, not %s: a reservation a newer build took is never dropped", module, series, cur.Version, version)
|
||||
}
|
||||
if rv.looking != nil && rv.looking(module, cur.Fingerprint) {
|
||||
return "", fmt.Errorf("the build of %s at %s, which holds %s, is building: drop it when that build ends or its ask is dropped (builder_stuck reads it)", module, cur.Fingerprint, version)
|
||||
}
|
||||
atRegistries := "the registries' record was not read"
|
||||
if rv.judge != nil {
|
||||
if j, jerr := rv.judge(ctx, cur); jerr == nil {
|
||||
var names []string
|
||||
for _, h := range append(append([]versions.HeldArtifact{}, j.Held...), j.Elsewhere...) {
|
||||
names = append(names, h.Seat+" "+h.Name)
|
||||
}
|
||||
atRegistries = "the registries keep " + strings.Join(names, ", ") + " at it, a gap the next reserve skips"
|
||||
if len(names) == 0 {
|
||||
atRegistries = "no registry holds an artifact at it"
|
||||
}
|
||||
}
|
||||
}
|
||||
ok, err := rv.r.Drop(ctx, module, series)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if ok && held && rv.itemEnded != nil {
|
||||
rv.itemEnded(ctx, module, cur.Version) // its publish item goes with its reservation (A-456b), its items terminated (§793)
|
||||
}
|
||||
if !ok {
|
||||
return "", fmt.Errorf("%s holds no reservation of %s", module, series)
|
||||
}
|
||||
if rv.itemEnded != nil {
|
||||
rv.itemEnded(ctx, module, cur.Version) // its publish item goes with its reservation (A-456b), its items terminated (§793)
|
||||
}
|
||||
rv.dropBound(ctx, versions.ReservedKey(module, series))
|
||||
rv.found.clear(ctx, versions.VersionUnreleased, meshconditionsclient.ScopeModule, module)
|
||||
return fmt.Sprintf("the reservation of %s %s is dropped (%s, %s)", module, series, by, why), nil
|
||||
withdrawn := make([]string, 0, len(cur.Withdrawn))
|
||||
for v := range cur.Withdrawn {
|
||||
withdrawn = append(withdrawn, v)
|
||||
}
|
||||
sort.Strings(withdrawn)
|
||||
return fmt.Sprintf("the reservation of %s %s is dropped (%s, %s): forgot version %s of fingerprint %s, %d recorded digests, withdrawn numbers %v and its publish item and version-unreleased; %s",
|
||||
module, series, by, why, cur.Version, cur.Fingerprint, len(cur.Artifacts), withdrawn, atRegistries), nil
|
||||
}
|
||||
|
||||
// noMark says why a published marked nothing, from the reservations the published read (design 47 H H-A-280: no second read):
|
||||
@@ -544,35 +590,49 @@ func (rv *reservations) noMark(ctx context.Context, o versions.Outcome, read []v
|
||||
return strings.Join(out, "; ") + " (" + standing + "; a published heard before the build recorded its digests is kept until it does)"
|
||||
}
|
||||
|
||||
// reserveDoneAct is builder_reserve_done's act (design 47 G A-455): the next version of the series is reserved for a done trunk build
|
||||
// that reserved none, and its publish is queued as builder_publish_again queues it. Its answer says the version and the queued
|
||||
// publishes; a reservation whose publish could not be queued is said so, with the tool that queues it.
|
||||
func reserveDoneAct(reserve func(ctx context.Context, module, fp string) (versions.ReservedVersion, error),
|
||||
republish func(ctx context.Context, module, version string) ([]string, error), logf func(string, ...any)) func(ctx context.Context, module, fp, by, why string, at time.Time) (string, error) {
|
||||
return func(ctx context.Context, module, fp, by, why string, at time.Time) (string, error) {
|
||||
res, err := reserve(ctx, module, fp)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
logf("%s at %s: version %s is reserved by hand (%s, %s) for the done build", module, fp, res.Version, by, why)
|
||||
queued, err := republish(ctx, module, res.Version)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("%s is reserved for %s at %s, but its publish is not queued (builder_publish_again queues it): %w", res.Version, module, fp, err)
|
||||
}
|
||||
return fmt.Sprintf("reserved %s for %s at %s and queued %d versions to publish: %s; builder_publish_queue shows them", res.Version, module, fp, len(queued), strings.Join(queued, ", ")), nil
|
||||
}
|
||||
}
|
||||
|
||||
// ReleasedFor says whether a version was released for the build of fingerprint (design 47 G A-456a).
|
||||
func (rv *reservations) ReleasedFor(ctx context.Context, module, fingerprint string) (bool, error) {
|
||||
return rv.r.ReleasedFor(ctx, module, fingerprint)
|
||||
}
|
||||
|
||||
// MarkRegistryHeld reads the registries' record of v's artifacts and writes the held digest of each artifact a registry holds at v's version
|
||||
// for the build's fingerprint on the reservation, marked published, and says package-published of each once (design 47 H2 H-A-588
|
||||
// (4)); what the registries do not hold loses its recorded digest (H-A-664). A read that does not answer is said and nothing is
|
||||
// written, so the build goes on.
|
||||
func (rv *reservations) MarkRegistryHeld(ctx context.Context, v versions.ReservedVersion) {
|
||||
if rv.judge == nil {
|
||||
return
|
||||
}
|
||||
j, err := rv.judge(ctx, v)
|
||||
if err != nil {
|
||||
rv.logf("%s %s: the registries' record of its artifacts is not read before the build module is asked again, so none is marked held: %v", v.Module, v.Version, err)
|
||||
return
|
||||
}
|
||||
marked, _, err := rv.r.MarkHeld(ctx, v.Module, v.Version, j.Held)
|
||||
if err != nil {
|
||||
rv.logf("%s %s: what the registries hold is not written on the reservation: %v", v.Module, v.Version, err)
|
||||
return
|
||||
}
|
||||
for _, m := range marked {
|
||||
var held versions.HeldArtifact
|
||||
for _, h := range j.Held {
|
||||
if h.Ref == m.Artifact {
|
||||
held = h
|
||||
}
|
||||
}
|
||||
rv.logf("%s %s: %s holds %s %s at %s for this build: marked published from its record before the build is asked again", v.Module, v.Version, held.Seat, held.Name, held.Version, held.Digest)
|
||||
rv.sayPublished(ctx, m, held.Digest)
|
||||
}
|
||||
}
|
||||
|
||||
// markHeld marks the artifacts the registries' record holds at their version with the built digest published, as their published
|
||||
// heard would, and says package-published of each (design 47 H H-A-274): a published heard and lost never leaves the publish
|
||||
// asked for ever. The version's release follows from the catalog as for any published.
|
||||
func (rv *reservations) markHeld(ctx context.Context, v versions.ReservedVersion, held []versions.HeldArtifact) {
|
||||
for _, h := range held {
|
||||
if v.Published[h.Ref] {
|
||||
continue // marked already: its package-published was said (design 47 H2 H-A-588 (4): once)
|
||||
}
|
||||
rv.logf("%s %s: %s holds %s %s with the built digest %s: marked published from its record", v.Module, v.Version, h.Seat, h.Name, h.Version, h.Digest)
|
||||
rv.published(ctx, versions.Outcome{Name: h.Name, Version: h.Version, Digest: h.Digest, Holder: h.Seat}, nil)
|
||||
}
|
||||
@@ -605,11 +665,40 @@ func (rv *reservations) movedElsewhere(ctx context.Context, v versions.ReservedV
|
||||
}
|
||||
return err
|
||||
}
|
||||
var at []string
|
||||
for _, h := range j.Elsewhere {
|
||||
at = append(at, fmt.Sprintf("%s holds %s %s at %s, built %s", h.Seat, h.Name, h.Version, h.Digest, v.Artifacts[h.Ref]))
|
||||
}
|
||||
why := fmt.Sprintf("%s is withdrawn and the build of %s is built again at the next free number: %s", v.Version, v.Fingerprint, strings.Join(at, "; "))
|
||||
why := elsewhereWords(v, j.Elsewhere)
|
||||
rv.heldElsewhere(ctx, v.Module, why)
|
||||
return rv.rebuild(ctx, v.Module, v.Fingerprint, why)
|
||||
}
|
||||
|
||||
// elsewhereWords says what withdrew v's number: each artifact a registry holds there for another build, with the seat, both digests and
|
||||
// the fingerprint the registry keeps for it when one is kept (design 47 H2 H-A-590 (1), H-A-279).
|
||||
func elsewhereWords(v versions.ReservedVersion, elsewhere []versions.HeldArtifact) string {
|
||||
var at []string
|
||||
for _, h := range elsewhere {
|
||||
w := fmt.Sprintf("%s holds %s %s at %s, built %s", h.Seat, h.Name, h.Version, h.Digest, v.Artifacts[h.Ref])
|
||||
if h.Fingerprint != "" {
|
||||
w += ", for fingerprint " + h.Fingerprint
|
||||
}
|
||||
at = append(at, w)
|
||||
}
|
||||
return fmt.Sprintf("%s is withdrawn and the build of %s is built again at the next free number: %s", v.Version, v.Fingerprint, strings.Join(at, "; "))
|
||||
}
|
||||
|
||||
// unstoredAgain builds a key again whose reservation's first artifact a holder refused as not stored (design 47 H2 H-A-662): the
|
||||
// build under its standing version completes what the registries lack, as the person's builder_build_again would. A key the
|
||||
// build again refuses (not a first branch's trunk build, or released) is said and left to the person's tool.
|
||||
func (rv *reservations) unstoredAgain(ctx context.Context, v versions.ReservedVersion, ref, words string) {
|
||||
if rv.rebuild == nil {
|
||||
return
|
||||
}
|
||||
why := fmt.Sprintf("%s refused by its holder as not stored (%s): the build of %s is built again under %s", ref, words, v.Fingerprint, v.Version)
|
||||
if err := rv.rebuild(ctx, v.Module, v.Fingerprint, why); err != nil {
|
||||
rv.logf("%s %s: the build again is not started: %v; builder_build_again builds it", v.Module, v.Version, err)
|
||||
}
|
||||
}
|
||||
|
||||
// movedFrom is told by the reserver a standing number it withdrew at a build again (design 47 H2 H-A-590 (1)): the finding is raised;
|
||||
// the reserve itself takes the next number no registry holds.
|
||||
func (rv *reservations) movedFrom(ctx context.Context, v versions.ReservedVersion, elsewhere []versions.HeldArtifact) {
|
||||
rv.heldElsewhere(ctx, v.Module, elsewhereWords(v, elsewhere))
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -19,6 +18,7 @@ import (
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
|
||||
"mesh-delivery-builder/internal/build"
|
||||
"mesh-delivery-builder/internal/versions"
|
||||
@@ -143,13 +143,14 @@ func TestTheCatalogsWordsMoveTheReservations(t *testing.T) {
|
||||
if all, _ := rv.r.All(ctx); len(all) != 0 || bounds.keys[boundKey] || len(st.vals) != 0 {
|
||||
t.Errorf("after version-released: reservations %v, bounds %v, findings %v; want none", all, bounds.keys, st.vals)
|
||||
}
|
||||
if _, err := rv.Reserve(ctx, "m", "1.4", []string{"m:a"}, versions.Source{}); err != nil {
|
||||
again, err := rv.Reserve(ctx, "m", "1.4", []string{"m:a"}, versions.Source{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if answer, err := rv.dropped(ctx, "m", "1.4", "op", "never released", time.Unix(0, 0)); err != nil || !strings.Contains(answer, "dropped") {
|
||||
if answer, err := rv.dropped(ctx, "m", "1.4", again.Version, "op", "never released", time.Unix(0, 0)); err != nil || !strings.Contains(answer, "dropped") {
|
||||
t.Errorf("builder_reserved_drop: %q (%v)", answer, err)
|
||||
}
|
||||
if _, err := rv.dropped(ctx, "m", "1.4", "op", "again", time.Unix(0, 0)); err == nil {
|
||||
if _, err := rv.dropped(ctx, "m", "1.4", again.Version, "op", "again", time.Unix(0, 0)); err == nil {
|
||||
t.Error("a reservation that is gone was dropped again")
|
||||
}
|
||||
}
|
||||
@@ -494,13 +495,27 @@ func TestABuiltReservationIsTakenInFromItsState(t *testing.T) {
|
||||
if !slices.Equal(said, []string{"look:a@" + v.Version + " sha256:looka"}) || !slices.Equal(asked, []string{"look " + v.Version}) {
|
||||
t.Errorf("at a look: said %v, publish items asked %v; want look:a's package-published said and its item asked", said, asked)
|
||||
}
|
||||
if ends := boundEnds("look"); !ends.Equal(v.BuiltAt.Add(versions.UnreleasedBound)) {
|
||||
t.Errorf("the bound armed at a look ends %v, want %v: counted from the build's end", ends, v.BuiltAt.Add(versions.UnreleasedBound))
|
||||
if ends := boundEnds("look"); !ends.Equal(v.BuiltAt.Add(defaultPublishAckMinutes * time.Minute)) {
|
||||
t.Errorf("the bound armed at a look ends %v, want %v: counted from the build's end", ends, v.BuiltAt.Add(defaultPublishAckMinutes*time.Minute))
|
||||
}
|
||||
if cur, _, _ := rv.r.Of(ctx, "look", v.Version); len(cur.Kept) != 0 || !cur.Published["look:a"] {
|
||||
t.Errorf("after the look: kept %v, published %v; want the kept published taken in", cur.Kept, cur.Published)
|
||||
}
|
||||
})
|
||||
t.Run("at a look with publish-ack-minutes at 30", func(t *testing.T) {
|
||||
rv.setBound(30 * time.Minute)
|
||||
defer rv.setBound(defaultPublishAckMinutes * time.Minute)
|
||||
v := recordedLost("thirty", now.Add(-5*time.Minute), "a")
|
||||
if err := rv.Built(ctx, "thirty", v.Version, v.Artifacts, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if ends := boundEnds("thirty"); !ends.Equal(v.BuiltAt.Add(30 * time.Minute)) {
|
||||
t.Errorf("the bound armed ends %v, want %v: the setting's 30 minutes, not 10", ends, v.BuiltAt.Add(30*time.Minute))
|
||||
}
|
||||
if unreleased("thirty") != "" {
|
||||
t.Errorf("a build 5 minutes old raised %s with the bound at 30 minutes", unreleased("thirty"))
|
||||
}
|
||||
})
|
||||
t.Run("at the start", func(t *testing.T) {
|
||||
v := recordedLost("start", now.Add(-time.Minute), "a")
|
||||
said = nil
|
||||
@@ -515,7 +530,7 @@ func TestABuiltReservationIsTakenInFromItsState(t *testing.T) {
|
||||
t.Run("past its bound", func(t *testing.T) {
|
||||
for _, when := range []string{"a look", "the start"} {
|
||||
module := map[string]string{"a look": "pastlook", "the start": "paststart"}[when]
|
||||
v := recordedLost(module, now.Add(-versions.UnreleasedBound-time.Minute), "a")
|
||||
v := recordedLost(module, now.Add(-defaultPublishAckMinutes*time.Minute-time.Minute), "a")
|
||||
takeIn := func() {
|
||||
if when == "a look" {
|
||||
if err := rv.Built(ctx, module, v.Version, v.Artifacts, nil); err != nil {
|
||||
@@ -542,7 +557,7 @@ func TestABuiltReservationIsTakenInFromItsState(t *testing.T) {
|
||||
// Note 8's own case: every artifact's published kept on it is taken in before its bound is judged, so nothing is
|
||||
// unpublished and nothing is raised; each is said as package-published.
|
||||
module = map[string]string{"a look": "keptlook", "the start": "keptstart"}[when]
|
||||
v = recordedLost(module, now.Add(-versions.UnreleasedBound-time.Minute), "a", "b")
|
||||
v = recordedLost(module, now.Add(-defaultPublishAckMinutes*time.Minute-time.Minute), "a", "b")
|
||||
said = nil
|
||||
takeIn()
|
||||
if got := unreleased(module); got != "" {
|
||||
@@ -666,59 +681,36 @@ func (e ansEntry) Revision() uint64 { return 1 }
|
||||
func (e ansEntry) Value() []byte { return e.value }
|
||||
func (e ansEntry) Operation() jetstream.KeyValueOp { return jetstream.KeyValuePut }
|
||||
|
||||
// TestAReserveDoneIsAnsweredWithTheVersionAndItsQueuedPublish: design 47 G A-455 — the reasks value of builder_reserve_done reaches
|
||||
// the act, which reserves for the done build and queues the publish as publish again does, and its answer names both; a
|
||||
// refusal of the reserving queues nothing and is the answer; a publish that cannot be queued says the version is reserved.
|
||||
func TestAReserveDoneIsAnsweredWithTheVersionAndItsQueuedPublish(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
var queued []string
|
||||
var logged []string
|
||||
logf := func(f string, a ...any) { logged = append(logged, fmt.Sprintf(f, a...)) }
|
||||
reserve := func(_ context.Context, module, fp string) (versions.ReservedVersion, error) {
|
||||
if fp == "refused" {
|
||||
return versions.ReservedVersion{}, fmt.Errorf("the build key of %s at %s is not done", module, fp)
|
||||
}
|
||||
return versions.ReservedVersion{Module: module, Version: "0.1.13", Fingerprint: fp}, nil
|
||||
}
|
||||
republish := func(_ context.Context, module, version string) ([]string, error) {
|
||||
if module == "nope" {
|
||||
return nil, fmt.Errorf("the queue is full")
|
||||
}
|
||||
queued = append(queued, module+"@"+version)
|
||||
return []string{module + "@" + version}, nil
|
||||
}
|
||||
acts := versions.Acts{ReserveDone: reserveDoneAct(reserve, republish, logf)}
|
||||
for _, c := range []struct {
|
||||
module, fp, want string
|
||||
refused bool
|
||||
}{
|
||||
{"node-tools", "src2:7df8", "reserved 0.1.13 for node-tools at src2:7df8 and queued 1 versions to publish: node-tools@0.1.13", false},
|
||||
{"node-tools", "refused", "not done", true},
|
||||
{"nope", "src2:1", "0.1.13 is reserved for nope at src2:1, but its publish is not queued", true},
|
||||
} {
|
||||
value, err := json.Marshal(build.ReAsk{V: 1, Why: "w", By: "me", Mode: build.ModeReserveDone, Name: c.module, FP: c.fp})
|
||||
if err != nil {
|
||||
// noAskKnown is a builder none of whose lanes waits: it records the keys asked again and builds, announces and releases nothing.
|
||||
type noAskKnown struct{ asked []string }
|
||||
|
||||
func (n *noAskKnown) AskAgain(key, _ string) []string { n.asked = append(n.asked, key); return nil }
|
||||
func (n *noAskKnown) BuildAgain(context.Context, string, string, string, string, time.Duration) build.BuildAgainResult {
|
||||
return build.BuildAgainResult{}
|
||||
}
|
||||
func (n *noAskKnown) AnnounceAgain(context.Context, string, string, string, string) build.BuildAgainResult {
|
||||
return build.BuildAgainResult{}
|
||||
}
|
||||
func (n *noAskKnown) Release(context.Context, string, string, string, string) string { return "" }
|
||||
|
||||
// TestAReserveDoneReAskIsNoAskTheBuilderKnows: design 47 H2 H-A-706 (DQ-39), AC-B14b — builder_reserve_done is gone, so a re-ask of its mode
|
||||
// reserve-done is no hand act of a version: it is answered as any ask of a key no lane of the builder waits on, and writes no reservation.
|
||||
func TestAReserveDoneReAskIsNoAskTheBuilderKnows(t *testing.T) {
|
||||
kv := &ansKV{wrote: make(chan []byte, 1)}
|
||||
raw, _ := json.Marshal(build.ReAsk{V: 1, Why: "a test asks it", By: "op@node", At: time.Now(), Mode: "reserve-done", Name: "m", Version: "0.1.0"})
|
||||
b := &noAskKnown{}
|
||||
reAsked(context.Background(), b, versions.Acts{}, nil, kv, ansEntry{key: "m.fp", value: raw}, t.Logf)
|
||||
var got build.ReAsk
|
||||
select {
|
||||
case v := <-kv.wrote:
|
||||
if err := json.Unmarshal(v, &got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
kv := &ansKV{wrote: make(chan []byte, 1)}
|
||||
// reAsked sends a reserve-done to the version acts (b is not asked), and the answer is written back to the key.
|
||||
reAsked(ctx, nil, acts, nil, kv, ansEntry{key: "reserve-done." + c.module, value: value}, logf)
|
||||
var wrote []byte
|
||||
select {
|
||||
case wrote = <-kv.wrote:
|
||||
case <-time.After(10 * time.Second):
|
||||
t.Fatalf("%s at %s: no answer was written to the key", c.module, c.fp)
|
||||
}
|
||||
var got build.ReAsk
|
||||
if err := json.Unmarshal(wrote, &got); err != nil || got.Refused != c.refused || !strings.Contains(got.Answer, c.want) || got.Answered.IsZero() {
|
||||
t.Errorf("%s at %s: written %s (%v), want refused=%v containing %q", c.module, c.fp, wrote, err, c.refused, c.want)
|
||||
}
|
||||
default:
|
||||
t.Fatal("the re-ask was not answered")
|
||||
}
|
||||
if !slices.Equal(queued, []string{"node-tools@0.1.13"}) {
|
||||
t.Errorf("queued %v, want only node-tools@0.1.13", queued)
|
||||
}
|
||||
if !slices.ContainsFunc(logged, func(l string) bool { return strings.Contains(l, "0.1.13 is reserved by hand") }) {
|
||||
t.Errorf("the reserving by hand is not said in the log: %q", logged)
|
||||
if !strings.Contains(got.Answer, "no ask of this key waits in this builder") || !slices.Equal(b.asked, []string{"m.fp"}) || got.Answered.IsZero() {
|
||||
t.Errorf("a re-ask of mode reserve-done answered %q (asked %v), want it answered as an ask no lane waits on", got.Answer, b.asked)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -742,7 +734,13 @@ func TestARegistrysRecordEndsOrMovesAPublish(t *testing.T) {
|
||||
rv.released = func(_ context.Context, m, v string) { ended = append(ended, m+" "+v) }
|
||||
rv.itemEnded = rv.released // a build withdrawn or superseded ends its publish item too (§793)
|
||||
registry := []string{"0.1.37"}
|
||||
rv.r.HeldNumbers = func(context.Context, string, string, []string) ([]string, error) { return registry, nil }
|
||||
rv.r.HeldRecords = func(context.Context, string, string, []string) ([]versions.HeldArtifact, error) {
|
||||
var out []versions.HeldArtifact
|
||||
for _, v := range registry {
|
||||
out = append(out, versions.HeldArtifact{Version: v})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
res, err := rv.Reserve(ctx, "node-tools", "0.1", []string{"node-tools:program"}, versions.Source{Fingerprint: "fp1"})
|
||||
if err != nil || res.Version != "0.1.0" {
|
||||
t.Fatalf("reserved %q (%v)", res.Version, err)
|
||||
@@ -925,62 +923,35 @@ func TestAPublishedThatMarksNothingIsSaidFromWhatItRead(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// Design 47 H2 H-A-514 addenda: each event goes to the worker of the name it carries, so a slow handling of one name holds
|
||||
// no other name's events, one name's events are handled in the order heard, and an event waiting in its worker's queue is
|
||||
// said in progress at each tick, so the bus does not give it again.
|
||||
func TestEventsAreHandledByAWorkerPerName(t *testing.T) {
|
||||
pub := func(name, v string) *queuedEvent {
|
||||
return &queuedEvent{wakeMsg: wakeMsg{subject: gopackageregistry.SubjectPublished, data: []byte(`{"name":"` + name + `","version":"` + v + `","digest":"sha256:aa"}`)}}
|
||||
}
|
||||
if got := eventKey(&pub("a", "1").wakeMsg); got != "name a" {
|
||||
t.Errorf("a published's key is %q, want its name", got)
|
||||
}
|
||||
if got := eventKey(&wakeMsg{subject: meshcatalog.SubjectVersionReleased, data: []byte(`{"module":"m","version":"0.1.0"}`)}); got != "module m" {
|
||||
t.Errorf("a version-released's key is %q, want its module", got)
|
||||
}
|
||||
if got := eventKey(&wakeMsg{subject: "mesh.seat.mesh-artifact-sweep.event.artifacts-gone", data: []byte(`{}`)}); got != "" {
|
||||
t.Errorf("an event naming no name has the key %q, want the shared worker's", got)
|
||||
}
|
||||
release := make(chan struct{})
|
||||
handled := make(chan string, 4)
|
||||
w := &eventWorkers{keyOf: eventKey, handle: func(m jetstream.Msg) {
|
||||
var o versions.Outcome
|
||||
_ = json.Unmarshal(m.Data(), &o)
|
||||
if o.Name == "a" && o.Version == "1" {
|
||||
<-release
|
||||
// Design 47 H2 H-A-683 (1), H-A-737 (1): the builder gives the hub each pattern's key: a registry seat's outcome by its name,
|
||||
// version-released by its module, the seat node-engine's running and manifest-reads-changed by the node their subject names;
|
||||
// the hub holds one key's events in order and the keys side by side (mesh-sdk's tests).
|
||||
func TestEventsAreHeldByTheKeyTheyName(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
name, subject, body, want string
|
||||
}{
|
||||
{"a registry seat's outcome by its name", gopackageregistry.SubjectPublished, `{"name":"a","version":"1","digest":"sha256:aa"}`, "name a"},
|
||||
{"a version-released by its module", meshcatalog.SubjectVersionReleased, `{"module":"m","version":"0.1.0"}`, "module m"},
|
||||
{"a running by its node", "mesh.seat.node-engine.event.running.ace.mod", `{}`, "node ace"},
|
||||
{"a manifest-reads-changed by its node", "mesh.seat.node-engine.event.manifest-reads-changed.g14", `{}`, "node g14"},
|
||||
{"another node's manifest-reads-changed by its node", "mesh.seat.node-engine.event.manifest-reads-changed.ace", `{}`, "node ace"},
|
||||
{"another event of the seat node-engine shares", "mesh.seat.node-engine.event.composed.ace", `{}`, ""},
|
||||
{"an event naming none shares", "mesh.seat.mesh-artifact-sweep.event.artifacts-gone", `{}`, ""},
|
||||
} {
|
||||
if got := eventKey(c.subject, []byte(c.body)); got != c.want {
|
||||
t.Errorf("%s: the key is %q, want %q", c.name, got, c.want)
|
||||
}
|
||||
handled <- o.Name + "@" + o.Version
|
||||
}}
|
||||
a1, a2, a3, b1 := pub("a", "1"), pub("a", "2"), pub("a", "3"), pub("b", "1")
|
||||
w.take(a1)
|
||||
w.take(a2)
|
||||
w.take(a3)
|
||||
w.take(b1)
|
||||
if got := <-handled; got != "b@1" {
|
||||
t.Fatalf("handled %s first, want b's event while a's first one is slow", got)
|
||||
}
|
||||
close(release)
|
||||
if got := []string{<-handled, <-handled, <-handled}; !slices.Equal(got, []string{"a@1", "a@2", "a@3"}) {
|
||||
t.Errorf("a's events handled %v, want in the order heard", got)
|
||||
}
|
||||
// a's worker said its waiting events in progress at each end: a2 and a3 after a1, a3 again after a2.
|
||||
if a1.progressed.Load() != 0 || a2.progressed.Load() != 1 || a3.progressed.Load() != 2 {
|
||||
t.Errorf("in progress said %d, %d and %d times of a's events, want 0, 1 and 2", a1.progressed.Load(), a2.progressed.Load(), a3.progressed.Load())
|
||||
}
|
||||
}
|
||||
|
||||
// queuedEvent is an event of the builder's durable that counts its in-progress.
|
||||
type queuedEvent struct {
|
||||
wakeMsg
|
||||
progressed atomic.Int32
|
||||
}
|
||||
|
||||
func (m *queuedEvent) InProgress() error { m.progressed.Add(1); return nil }
|
||||
|
||||
// oneHandler is an event hub with one handler.
|
||||
type oneHandler struct{ handle func(jetstream.Msg) }
|
||||
|
||||
func (h *oneHandler) Handle(_ string, f func(jetstream.Msg)) error { h.handle = f; return nil }
|
||||
func (h *oneHandler) HandleByKey(_ string, _ process.EventKey, f func(jetstream.Msg)) error {
|
||||
h.handle = f
|
||||
return nil
|
||||
}
|
||||
|
||||
// agedTestMsg is a message of the builder's events consumer, with the metadata a ledger reads.
|
||||
type agedTestMsg struct {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"mesh-delivery-builder/internal/build"
|
||||
"mesh-delivery-builder/internal/versions"
|
||||
)
|
||||
|
||||
// The builder's retake of a key failed on a transport fault, on the node-engine seat's events (design 47 G §568, ADR 0673): the
|
||||
@@ -87,3 +88,26 @@ func (d *decisions) heard(m jetstream.Msg) bool {
|
||||
d.handle(m)
|
||||
return true
|
||||
}
|
||||
|
||||
// publishingAgain is the builder's publish again on ADR 0674 §2's events (design 47 H2 H-A-606): the wiring of versions.Againer to the
|
||||
// events consumer.
|
||||
type publishingAgain struct{ a *versions.Againer }
|
||||
|
||||
// heard hands a message of the events consumer to the publish again: one whose state cannot take it is left for the bus to give
|
||||
// again (Nak); every message goes on to the other parts.
|
||||
func (g *publishingAgain) heard(ctx context.Context, m jetstream.Msg, logf func(string, ...any)) (stop bool) {
|
||||
meta, err := m.Metadata()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
handled, err := g.a.Heard(ctx, m.Subject(), m.Data(), meta.Sequence.Stream)
|
||||
if handled && err != nil {
|
||||
logf("%v; heard again", err)
|
||||
if nakErr := m.Nak(); nakErr != nil {
|
||||
logf("leaving %s for the bus to give again: %v", m.Subject(), nakErr)
|
||||
}
|
||||
givenUp(m, "its event", err, logf)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -68,6 +68,33 @@ func TestTheRunnersBuildStepAskIsAnsweredAsStepEnded(t *testing.T) {
|
||||
case <-time.After(20 * time.Second):
|
||||
t.Fatal("no step-ended within 20 s")
|
||||
}
|
||||
// Design 47 H2 H-A-577 (1), AC-B2: an ask whose revision the picture does not hold says wait-held (step build, on revision:<R>, kept
|
||||
// under <module>.<fingerprint>.revision) and wait-ended with how ran once it does.
|
||||
waits := make(chan *nats.Msg, 8)
|
||||
for _, ev := range []string{"wait-held", "wait-ended"} {
|
||||
w, err := sub.ChanSubscribe("mesh.mod.*.event."+ev+".netcheck.>", waits)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer w.Unsubscribe()
|
||||
}
|
||||
revisionWait := func(event string) waitBody {
|
||||
t.Helper()
|
||||
for bound := time.After(20 * time.Second); ; {
|
||||
select {
|
||||
case m := <-waits:
|
||||
var w waitBody
|
||||
if err := json.Unmarshal(m.Data, &w); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(m.Subject, ".event."+event+".") && strings.HasSuffix(m.Subject, ".revision") {
|
||||
return w
|
||||
}
|
||||
case <-bound:
|
||||
t.Fatalf("no %s of the revision wait within 20 s", event)
|
||||
}
|
||||
}
|
||||
}
|
||||
// H-A-155: an ask naming a source revision the builder's picture of main does not hold yet waits for it, said in the
|
||||
// journal, and is answered once a revision taken in from it arrives.
|
||||
run.Pipeline, run.Revision, run.Source = "main.2.netcheck", 2, 2
|
||||
@@ -79,6 +106,9 @@ func TestTheRunnersBuildStepAskIsAnsweredAsStepEnded(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b.awaitSaid(t, "main.2.netcheck: revision 2 of main not in the builder's picture yet")
|
||||
if w := revisionWait("wait-held"); w.On != "revision:2" || w.Step != "build" || w.Module != "netcheck" || w.Fingerprint != fp {
|
||||
t.Errorf("wait-held of the ask for revision 2 = %+v, want step build, on revision:2, netcheck at %s", w, fp)
|
||||
}
|
||||
b.catalog.mu.Lock()
|
||||
b.catalog.source = 2
|
||||
b.catalog.mu.Unlock()
|
||||
@@ -93,6 +123,9 @@ func TestTheRunnersBuildStepAskIsAnsweredAsStepEnded(t *testing.T) {
|
||||
case <-time.After(20 * time.Second):
|
||||
t.Fatal("no step-ended for ask-2 within 20 s")
|
||||
}
|
||||
if w := revisionWait("wait-ended"); w.On != "revision:2" || w.How != "ran" {
|
||||
t.Errorf("wait-ended of the ask for revision 2 = %+v, want on revision:2 ended ran", w)
|
||||
}
|
||||
// Each ask is acknowledged once its end was said: the seat's worker holds none pending.
|
||||
stream, worker := buscompose.SeatQueueStreamName(meshbuilds.Seat), buscompose.SeatQueueWorkerName(meshbuilds.Seat)
|
||||
deadline := time.Now().Add(10 * time.Second)
|
||||
|
||||
@@ -4,6 +4,9 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/nats-io/nats.go"
|
||||
@@ -11,6 +14,7 @@ import (
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
|
||||
"mesh-delivery-builder/internal/build"
|
||||
"mesh-delivery-builder/internal/versions"
|
||||
)
|
||||
|
||||
@@ -123,3 +127,144 @@ func emitSeatEvent(ctx context.Context, js jetstream.JetStream, cred process.Acc
|
||||
_, err = js.PublishMsg(pub, msg, jetstream.WithMsgID(id))
|
||||
return err
|
||||
}
|
||||
|
||||
// markLifetime writes the marks of the state acted with the bus's per-message lifetime of the setting acted-days, each write giving
|
||||
// it again (design 47 H2 H-A-720 (1)); the release record and every other key it writes with none (H-A-720 (2)). An update is the
|
||||
// one publish carrying the lifetime and the expected last sequence of the key (H-A-741).
|
||||
type markLifetime struct {
|
||||
awaitedReserved
|
||||
days int
|
||||
js jetstream.JetStream
|
||||
}
|
||||
|
||||
func (s markLifetime) life(key string) (time.Duration, bool) {
|
||||
if mark, _ := versions.ActedFormOf(key); mark {
|
||||
return time.Duration(s.days) * 24 * time.Hour, true
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
|
||||
func (s markLifetime) Create(ctx context.Context, key string, value []byte) (uint64, error) {
|
||||
ttl, ok := s.life(key)
|
||||
if !ok {
|
||||
return s.awaitedReserved.Create(ctx, key, value)
|
||||
}
|
||||
kv, err := s.kv()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
rev, err := kv.Create(ctx, key, value, jetstream.KeyTTL(ttl))
|
||||
return rev, versionsConflict(err)
|
||||
}
|
||||
|
||||
func (s markLifetime) Update(ctx context.Context, key string, value []byte, revision uint64) (uint64, error) {
|
||||
ttl, ok := s.life(key)
|
||||
if !ok {
|
||||
return s.awaitedReserved.Update(ctx, key, value, revision)
|
||||
}
|
||||
kv, err := s.kv()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
_ = kv
|
||||
return updateWithLifetime(ctx, s.js, s.bucket, key, value, revision, ttl)
|
||||
}
|
||||
|
||||
// updateWithLifetime is one publish to the key's subject carrying the per-message lifetime and the expected last sequence of the
|
||||
// key: the compare-and-set update that gives the lifetime again (design 47 H2 H-A-741).
|
||||
func updateWithLifetime(ctx context.Context, js jetstream.JetStream, bucket, key string, value []byte, revision uint64, ttl time.Duration) (uint64, error) {
|
||||
msg := nats.NewMsg("$KV." + bucket + "." + key)
|
||||
msg.Data = value
|
||||
msg.Header.Set("Nats-TTL", fmt.Sprintf("%ds", int64(ttl/time.Second)))
|
||||
msg.Header.Set("Nats-Expected-Last-Subject-Sequence", strconv.FormatUint(revision, 10))
|
||||
ack, err := js.PublishMsg(ctx, msg)
|
||||
if err != nil {
|
||||
var apiErr *jetstream.APIError
|
||||
if errors.As(err, &apiErr) && apiErr.ErrorCode == jetstream.JSErrCodeStreamWrongLastSequence {
|
||||
return 0, versions.ErrConflict
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
return ack.Sequence, nil
|
||||
}
|
||||
|
||||
// deleteUnknown deletes each key of the state acted of a form the builder does not write (design 47 H2 H-A-720 (3)) and says the
|
||||
// count once.
|
||||
func deleteUnknown(ctx context.Context, kv jetstream.KeyValue, logf func(string, ...any)) {
|
||||
l, err := kv.ListKeys(ctx)
|
||||
if err != nil {
|
||||
logf("the keys of the state %s are not listed, so none of no form is deleted: %v", versions.ActedState, err)
|
||||
return
|
||||
}
|
||||
var gone []string
|
||||
for k := range l.Keys() {
|
||||
if _, known := versions.ActedFormOf(k); !known {
|
||||
gone = append(gone, k)
|
||||
}
|
||||
}
|
||||
_ = l.Stop()
|
||||
n := 0
|
||||
for _, k := range gone {
|
||||
if err := kv.Delete(ctx, k); err != nil {
|
||||
logf("the key %s of the state %s, of no form the builder writes, is not deleted: %v", k, versions.ActedState, err)
|
||||
continue
|
||||
}
|
||||
n++
|
||||
}
|
||||
if len(gone) > 0 {
|
||||
logf("the state %s: %d keys of no form the builder writes were deleted at the start", versions.ActedState, n)
|
||||
}
|
||||
}
|
||||
|
||||
// carryDrops is the builder's start of the re-ask state (design 47 H2 H-A-749 (2)): each answered publish-drop ask is carried onto
|
||||
// its version's reservation as dropped (the ask's by, why and at) where the reservation stands and holds none, so a drop made before
|
||||
// is kept; then each record of mode publish, whose readers are gone, is deleted. It says the counts once.
|
||||
func carryDrops(ctx context.Context, kv jetstream.KeyValue, r *versions.Reserver, logf func(string, ...any)) {
|
||||
l, err := kv.ListKeys(ctx)
|
||||
if err != nil {
|
||||
logf("the keys of the state %s are not listed, so no earlier drop is carried and no publish record deleted: %v", build.ReAsksState, err)
|
||||
return
|
||||
}
|
||||
var keys []string
|
||||
for k := range l.Keys() {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
_ = l.Stop()
|
||||
slices.Sort(keys)
|
||||
var carried, deleted int
|
||||
var records []string
|
||||
for _, k := range keys {
|
||||
e, err := kv.Get(ctx, k)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
ask, err := build.DecodeReAsk(e.Value())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
switch {
|
||||
case ask.Mode == "publish": // the record of a version's publish item, written before H-A-746
|
||||
records = append(records, k)
|
||||
case ask.Mode == build.ModePublishDrop && !ask.Answered.IsZero() && !ask.Refused:
|
||||
v, found, err := r.Of(ctx, ask.Module, ask.Version)
|
||||
if err != nil || !found || v.Dropped != nil {
|
||||
continue
|
||||
}
|
||||
if ok, err := r.MarkDropped(ctx, ask.Module, ask.Version, ask.By, ask.Why, ask.At); err != nil {
|
||||
logf("the drop of %s %s by %s is not carried onto its reservation: %v", ask.Module, ask.Version, ask.By, err)
|
||||
} else if ok {
|
||||
carried++
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, k := range records {
|
||||
if err := kv.Delete(ctx, k); err != nil {
|
||||
logf("the publish record %s of the state %s is not deleted: %v", k, build.ReAsksState, err)
|
||||
continue
|
||||
}
|
||||
deleted++
|
||||
}
|
||||
if carried > 0 || deleted > 0 {
|
||||
logf("the state %s at the start: %d earlier drops carried onto their reservations as dropped, %d publish records deleted", build.ReAsksState, carried, deleted)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,9 +27,16 @@ type waitBody struct {
|
||||
Since time.Time `json:"since"`
|
||||
Bound string `json:"bound,omitempty"`
|
||||
How string `json:"how,omitempty"`
|
||||
// Publisher, Revision and Until are a pin wait's (design 47 H2 H-A-707 (5), DQ-53).
|
||||
Publisher string `json:"publisher,omitempty"`
|
||||
Revision int64 `json:"revision,omitempty"`
|
||||
Until time.Time `json:"until,omitzero"`
|
||||
}
|
||||
|
||||
const waitStepBuilding = "building"
|
||||
const (
|
||||
waitStepBuilding = "building"
|
||||
waitStepBuild = "build"
|
||||
)
|
||||
|
||||
// waitsKept keeps the builder's toolchain waits in its old state waits, one key <module>.<fingerprint> (design 47 G §672),
|
||||
// and says wait-held and wait-ended on its old stream waits; at its start it says wait-held again for every key.
|
||||
@@ -48,7 +55,24 @@ func newWaitsKept(kv *process.AwaitedBucket, say func(context.Context, string, s
|
||||
}
|
||||
|
||||
func (w *waitsKept) body(t build.ToolchainWait, how string) waitBody {
|
||||
return waitBody{Step: waitStepBuilding, On: t.On(), Part: t.Package, Module: t.Module, Fingerprint: t.Fingerprint, Since: t.Since, Bound: w.bound.String(), How: how}
|
||||
b := waitBody{Step: waitStepBuilding, On: t.On(), Part: t.Package, Module: t.Module, Fingerprint: t.Fingerprint, Since: t.Since, Bound: w.bound.String(), How: how,
|
||||
Publisher: t.Publisher, Until: t.Until}
|
||||
if !t.Until.IsZero() { // a pin wait says the bound of `package-wait-minutes`, which it carries, and the revision it holds
|
||||
b.Bound, b.Revision = t.Bound, t.Revision
|
||||
}
|
||||
if t.IsRevision() { // a step ask's wait for its revision: `step` build, its own bound (design 47 H2 H-A-577 (1))
|
||||
b.Step, b.Bound = waitStepBuild, t.Bound
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// slotOf is the part of a wait's key and subject after `<module>.<fingerprint>`: a revision wait keeps its own, so it is told apart
|
||||
// from that key's toolchain wait.
|
||||
func slotOf(t build.ToolchainWait) string {
|
||||
if t.IsRevision() {
|
||||
return ".revision"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// start reads the state whole and says wait-held again for each key.
|
||||
@@ -76,26 +100,33 @@ func (w *waitsKept) start(ctx context.Context, kv jetstream.KeyValue) {
|
||||
}
|
||||
|
||||
func (w *waitsKept) said(ctx context.Context, event string, t build.ToolchainWait, how string) {
|
||||
if err := w.say(ctx, event+"."+t.Module+"."+t.Fingerprint, event+"-"+t.Module+"-"+t.Fingerprint+"-"+t.Since.UTC().Format(time.RFC3339Nano)+how, w.body(t, how)); err != nil {
|
||||
if err := w.say(ctx, event+"."+t.Module+"."+t.Fingerprint+slotOf(t), event+"-"+t.Module+"-"+t.Fingerprint+slotOf(t)+"-"+t.Since.UTC().Format(time.RFC3339Nano)+how, w.body(t, how)); err != nil {
|
||||
w.logf("saying %s of %s at %s: %v", event, t.Module, t.Fingerprint, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Hold keeps the wait and says wait-held, once.
|
||||
// Hold keeps the wait and says wait-held, once. A key holds the build's one current wait (design 47 H2 H-A-723 (1)): a Hold over a
|
||||
// standing wait of another kind or other fields ends that wait, said wait-ended with how replaced, and holds the new one; a Hold equal
|
||||
// to the standing wait changes nothing.
|
||||
func (w *waitsKept) Hold(ctx context.Context, t build.ToolchainWait) {
|
||||
key, err := builds.BuilderBuildKey(t.Module, t.Fingerprint)
|
||||
if err != nil {
|
||||
w.logf("a wait of %s at %s has no key: %v", t.Module, t.Fingerprint, err)
|
||||
return
|
||||
}
|
||||
key += slotOf(t)
|
||||
w.mu.Lock()
|
||||
if _, had := w.held[key]; had {
|
||||
old, had := w.held[key]
|
||||
if had && old.SameWait(t) {
|
||||
w.mu.Unlock()
|
||||
return
|
||||
}
|
||||
w.held[key] = t
|
||||
w.mu.Unlock()
|
||||
if kv := w.kv.KV(); kv != nil {
|
||||
if had {
|
||||
w.said(ctx, "wait-ended", old, build.WaitReplaced)
|
||||
}
|
||||
if kv := w.bucket(); kv != nil {
|
||||
data, _ := json.Marshal(t)
|
||||
if _, err := kv.Put(ctx, key, data); err != nil {
|
||||
w.logf("%s.%s could not be written, so the wait is kept in memory only: %v", build.WaitsState, key, err)
|
||||
@@ -106,14 +137,25 @@ func (w *waitsKept) Hold(ctx context.Context, t build.ToolchainWait) {
|
||||
|
||||
// End deletes the wait and says wait-ended with how; it answers whether one was held.
|
||||
func (w *waitsKept) End(ctx context.Context, module, fp, how string) bool {
|
||||
return w.end(ctx, module, fp, "", how)
|
||||
}
|
||||
|
||||
// EndRevision ends the revision wait of module's fingerprint, kept under its own key.
|
||||
func (w *waitsKept) EndRevision(ctx context.Context, module, fp, how string) bool {
|
||||
return w.end(ctx, module, fp, ".revision", how)
|
||||
}
|
||||
|
||||
func (w *waitsKept) end(ctx context.Context, module, fp, slot, how string) bool {
|
||||
key, err := builds.BuilderBuildKey(module, fp)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
key += slot
|
||||
w.mu.Lock()
|
||||
t, had := w.held[key]
|
||||
// A key queued behind a package ends only when it is published, and a toolchain wait never by that (design 47 G A-192).
|
||||
if had && (t.Package != "") != (how == build.WaitPublished) {
|
||||
// A key queued behind a package ends only when it is published, and a toolchain wait never by that (design 47 G A-192); a wait
|
||||
// ended failed is ended whatever its kind (design 47 H2 H-A-723 (2)).
|
||||
if had && slot == "" && how != build.WaitFailed && (t.Package != "") != (how == build.WaitPublished) {
|
||||
had = false
|
||||
}
|
||||
if had {
|
||||
@@ -123,7 +165,7 @@ func (w *waitsKept) End(ctx context.Context, module, fp, how string) bool {
|
||||
if !had {
|
||||
return false
|
||||
}
|
||||
if kv := w.kv.KV(); kv != nil {
|
||||
if kv := w.bucket(); kv != nil {
|
||||
if err := kv.Delete(ctx, key); err != nil && !errors.Is(err, jetstream.ErrKeyNotFound) {
|
||||
w.logf("%s.%s could not be deleted: %v", build.WaitsState, key, err)
|
||||
}
|
||||
@@ -131,3 +173,11 @@ func (w *waitsKept) End(ctx context.Context, module, fp, how string) bool {
|
||||
w.said(ctx, "wait-ended", t, how)
|
||||
return true
|
||||
}
|
||||
|
||||
// bucket is the state waits once it is on the bus; none before, and none for a form kept in memory alone.
|
||||
func (w *waitsKept) bucket() jetstream.KeyValue {
|
||||
if w.kv == nil {
|
||||
return nil
|
||||
}
|
||||
return w.kv.KV()
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -18,4 +21,50 @@ func TestAWaitBodyNamesItsPart(t *testing.T) {
|
||||
if tc := w.body(build.ToolchainWait{Module: "m", Fingerprint: "src2:f", Language: "go", Version: "go1.26.0"}, ""); tc.Part != "" || tc.On != "toolchain:go@go1.26.0" {
|
||||
t.Errorf("a toolchain wait says %+v", tc)
|
||||
}
|
||||
// H2 H-A-577 (1): a revision wait says `step` build, `on` revision:<R> and its own bound, under the subject token `.revision`
|
||||
rev := build.ToolchainWait{Module: "m", Fingerprint: "src2:f", Kind: build.WaitKindRevision, Revision: 7, Bound: "2m0s"}
|
||||
if rv := w.body(rev, ""); rv.Step != "build" || rv.On != "revision:7" || rv.Bound != "2m0s" || slotOf(rev) != ".revision" || slotOf(build.ToolchainWait{}) != "" {
|
||||
t.Errorf("a revision wait says %+v, slot %q", rv, slotOf(rev))
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 H2 H-A-723, H-A-707 (5), DQ-53 (H-A-717): a key holds one wait. A pin wait held over a toolchain wait ends it as `replaced`
|
||||
// and stands; an equal Hold writes nothing; a pin wait ended `failed` is deleted; its body says `package-wait-minutes` as its bound
|
||||
// and carries publisher, revision and until, the package its path alone.
|
||||
func TestAKeyHoldsTheBuildsOneWait(t *testing.T) {
|
||||
var said []string
|
||||
var bodies []waitBody
|
||||
w := newWaitsKept(nil, func(_ context.Context, event, _ string, body any) error {
|
||||
said = append(said, strings.SplitN(event, ".", 2)[0])
|
||||
bodies = append(bodies, body.(waitBody))
|
||||
return nil
|
||||
}, time.Hour, t.Logf)
|
||||
ctx := context.Background()
|
||||
since := time.Unix(100, 0)
|
||||
tc := build.ToolchainWait{Module: "m", Fingerprint: fpw, Language: "go", Version: "go1.26.0", Since: since}
|
||||
pin := build.ToolchainWait{Module: "m", Fingerprint: fpw, Package: "git.x/y/sdk", Publisher: "sdk@src2:p", Revision: 7, Bound: "10m0s", Since: since, Until: since.Add(10 * time.Minute)}
|
||||
w.Hold(ctx, tc)
|
||||
w.Hold(ctx, tc)
|
||||
if !slices.Equal(said, []string{"wait-held"}) {
|
||||
t.Fatalf("a toolchain wait held twice said %v, want one wait-held", said)
|
||||
}
|
||||
w.Hold(ctx, pin)
|
||||
if !slices.Equal(said, []string{"wait-held", "wait-ended", "wait-held"}) || bodies[1].How != build.WaitReplaced || bodies[1].On != "toolchain:go@go1.26.0" {
|
||||
t.Fatalf("a pin wait over a toolchain wait said %v, %+v, want the toolchain wait ended replaced", said, bodies)
|
||||
}
|
||||
if p := bodies[2]; p.Bound != "10m0s" || p.Publisher != "sdk@src2:p" || p.Revision != 7 || !p.Until.Equal(pin.Until) || p.Part != "git.x/y/sdk" || p.On != "package:git.x/y/sdk" {
|
||||
t.Errorf("the pin wait says %+v", p)
|
||||
}
|
||||
w.Hold(ctx, pin)
|
||||
if len(said) != 3 {
|
||||
t.Errorf("a Hold equal to the standing wait said %v, want nothing", said[3:])
|
||||
}
|
||||
if w.End(ctx, "m", fpw, build.WaitRan) {
|
||||
t.Error("a pin wait ended ran")
|
||||
}
|
||||
if !w.End(ctx, "m", fpw, build.WaitFailed) || len(w.held) != 0 || bodies[len(bodies)-1].How != build.WaitFailed {
|
||||
t.Errorf("a pin wait ended failed: held %v, said %v", w.held, said)
|
||||
}
|
||||
}
|
||||
|
||||
var fpw = "src2:" + strings.Repeat("a", 64)
|
||||
|
||||
@@ -106,4 +106,13 @@ func TestBuilderStuckAnswersTheFingerprintWhole(t *testing.T) {
|
||||
if len(rows) != 1 || rows[0].FP != fp1 {
|
||||
t.Fatalf("stuck = %+v, want the fingerprint %s whole", rows, fp1)
|
||||
}
|
||||
// design 47 H2 H-A-707 (5): a key building with no ask names the wait the state waits holds for it
|
||||
pin, _ := json.Marshal(ToolchainWait{Module: "m", Fingerprint: fp1, Package: "git.x/y/sdk", Publisher: "sdk@src2:p", Revision: 7})
|
||||
out, err = StuckReader{Builds: stateOf(map[string][]byte{k: building}), Waits: stateOf(map[string][]byte{k: pin})}.Stuck("m")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if rows = out["stuck"].([]Stuck); len(rows) != 1 || len(rows[0].Waits) != 1 || rows[0].Waits[0].Publisher != "sdk@src2:p" || rows[0].Waits[0].Package != "git.x/y/sdk" {
|
||||
t.Errorf("a key building with no ask: stuck = %+v, want its pin wait", rows)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
"sync"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
)
|
||||
|
||||
// Faulted is the set of build keys whose newest revision failed on a transport fault, with the seat and node the fault names
|
||||
// (design 47 H2 H-A-683 (2), H-A-696): filled by the start sweep (Builder.Sweep) and kept by every write of a build (the store
|
||||
// Builder.init wraps), held in memory so that an event retakes only the keys whose seat or node it names, and lists no key of the
|
||||
// bucket. An event heard before the sweep has filled the set waits (WaitFilled) until it has.
|
||||
type Faulted struct {
|
||||
mu sync.Mutex
|
||||
revs map[string]uint64 // the newest revision noted of each key, so that an older read never replaces a newer write
|
||||
faults map[string]fault
|
||||
filled chan struct{}
|
||||
once sync.Once
|
||||
}
|
||||
|
||||
type fault struct{ seat, node string }
|
||||
|
||||
func newFaulted() *Faulted {
|
||||
return &Faulted{revs: map[string]uint64{}, faults: map[string]fault{}, filled: make(chan struct{})}
|
||||
}
|
||||
|
||||
// note keeps what key holds at revision rev: in the set when it failed on a transport fault, else out of it.
|
||||
func (f *Faulted) note(key string, value []byte, rev uint64) {
|
||||
var fl fault
|
||||
in := false
|
||||
if v, err := builds.DecodeBuilderBuild(value); err == nil && v.State == builds.BuildFailed {
|
||||
_, seat, node, _, ok := builds.TransportFaultOf(v.Error)
|
||||
fl, in = fault{seat, node}, ok
|
||||
}
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
if rev < f.revs[key] {
|
||||
return
|
||||
}
|
||||
f.revs[key] = rev
|
||||
if in {
|
||||
f.faults[key] = fl
|
||||
} else {
|
||||
delete(f.faults, key)
|
||||
}
|
||||
}
|
||||
|
||||
// Fill says the start sweep has read every key, and returns how many keys the set holds.
|
||||
func (f *Faulted) Fill() int {
|
||||
f.once.Do(func() { close(f.filled) })
|
||||
return f.Len()
|
||||
}
|
||||
|
||||
// Len is how many keys the set holds.
|
||||
func (f *Faulted) Len() int {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
return len(f.faults)
|
||||
}
|
||||
|
||||
// WaitFilled returns once the start sweep has filled the set, or ctx ends.
|
||||
func (f *Faulted) WaitFilled(ctx context.Context) error {
|
||||
select {
|
||||
case <-f.filled:
|
||||
return nil
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
}
|
||||
}
|
||||
|
||||
// Matching are the keys of the set whose seat and node want says passed, in order.
|
||||
func (f *Faulted) Matching(want func(seat, node string) bool) []string {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
var out []string
|
||||
for k, fl := range f.faults {
|
||||
if want(fl.seat, fl.node) {
|
||||
out = append(out, k)
|
||||
}
|
||||
}
|
||||
sort.Strings(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// faultNoting is the builds store that notes every write in the set.
|
||||
type faultNoting struct {
|
||||
Store
|
||||
set *Faulted
|
||||
}
|
||||
|
||||
func (s faultNoting) Create(ctx context.Context, key string, value []byte) (uint64, error) {
|
||||
rev, err := s.Store.Create(ctx, key, value)
|
||||
if err == nil {
|
||||
s.set.note(key, value, rev)
|
||||
}
|
||||
return rev, err
|
||||
}
|
||||
|
||||
func (s faultNoting) Update(ctx context.Context, key string, value []byte, revision uint64) (uint64, error) {
|
||||
rev, err := s.Store.Update(ctx, key, value, revision)
|
||||
if err == nil {
|
||||
s.set.note(key, value, rev)
|
||||
}
|
||||
return rev, err
|
||||
}
|
||||
|
||||
// WaitFaults returns once the start sweep has filled the set of faulted keys, or ctx ends.
|
||||
func (b *Builder) WaitFaults(ctx context.Context) error {
|
||||
b.init()
|
||||
return b.Faults.WaitFilled(ctx)
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package build
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
@@ -133,9 +132,13 @@ type Reservations interface {
|
||||
// TakenOver is the reservation of module's series that took the series over from the build of fingerprint, whose number
|
||||
// it keeps withdrawn (design 47 H H-A-226), and whether one does (H-A-244).
|
||||
TakenOver(ctx context.Context, module, fingerprint string) (versions.ReservedVersion, bool, error)
|
||||
// VersionAt is the version module's artifact is published at from the source revision of branch: its reservation of that
|
||||
// origin with the artifact published, else its release recorded at that source revision (design 47 H2 H-A-547 (3), H-A-551).
|
||||
VersionAt(ctx context.Context, module, artifact, branch string, source int64) (string, bool, error)
|
||||
// MarkRegistryHeld reads the registries' record of v's artifacts at its version and writes on the reservation the held digest of each
|
||||
// artifact a registry holds there for the build's fingerprint, marking it published, before a build module is asked for the
|
||||
// fingerprint again (design 47 H2 H-A-588 (4)). A read that does not answer is said and the build goes on.
|
||||
MarkRegistryHeld(ctx context.Context, v versions.ReservedVersion)
|
||||
// PublishedOf is the seat mesh-builds' published rule (design 47 H-A-328): whether artifact of module built at fingerprint is
|
||||
// published, and its version; the pin a blank package takes is the publisher's build in the build's revision (H2 H-A-707 (4)).
|
||||
PublishedOf(ctx context.Context, module, artifact, fingerprint string) (meshbuilds.PublishedAnswer, error)
|
||||
}
|
||||
|
||||
// reserves says whether a look at a trunk build is one that reserves: the build has a series of the form MAJOR.MINOR
|
||||
@@ -178,67 +181,3 @@ func (b *Builder) reserve(ctx context.Context, module string, m meshcatalog.Modu
|
||||
b.logf("%s: version %s is reserved for this build", module, res.Version)
|
||||
return res, true
|
||||
}
|
||||
|
||||
// ReserveDone is builder_reserve_done (design 47 G A-455): a done trunk build of the first watched branch that reserved no
|
||||
// version (its key is done, so a look never reserves for it, and a done key cannot be built again) reserves the next version of
|
||||
// its series now, with the digests the done key holds, as a build that started would, and its build ends with every digest
|
||||
// recorded. It answers the reserved version; the caller queues its publish (versions.Republisher). A fingerprint whose key is not
|
||||
// done, whose entry no watched branch carries now, that is no first branch's, or that holds a reservation already is refused, saying which.
|
||||
func (b *Builder) ReserveDone(ctx context.Context, module, fp string) (versions.ReservedVersion, error) {
|
||||
b.init()
|
||||
if b.Reserved == nil {
|
||||
return versions.ReservedVersion{}, errors.New("this builder reserves no versions")
|
||||
}
|
||||
key, err := builds.BuilderBuildKey(module, fp)
|
||||
if err != nil {
|
||||
return versions.ReservedVersion{}, err
|
||||
}
|
||||
b.mu.Lock()
|
||||
var m meshcatalog.ModulesByModuleValue
|
||||
found := false
|
||||
for hk, v := range b.heard {
|
||||
if strings.HasSuffix(hk, "\x00"+module) && v.Fp2 == fp {
|
||||
m, found = v, true
|
||||
}
|
||||
}
|
||||
trunk, first := b.trunkFP[key], b.origin[key].First
|
||||
b.mu.Unlock()
|
||||
switch {
|
||||
case !found:
|
||||
return versions.ReservedVersion{}, fmt.Errorf("no watched branch carries an entry of %s at %s now, so there is nothing to reserve it from", module, fp)
|
||||
case !trunk || !first:
|
||||
return versions.ReservedVersion{}, fmt.Errorf("%s at %s is not the first watched branch's build: only that one reserves a version (§371)", module, fp)
|
||||
}
|
||||
digests := b.doneDigests(ctx, module, fp)
|
||||
if digests == nil {
|
||||
return versions.ReservedVersion{}, fmt.Errorf("the build key of %s at %s is not done", module, fp)
|
||||
}
|
||||
plan, planErr, _ := b.planOf(ctx, m.Manifest)
|
||||
switch {
|
||||
case planErr != nil:
|
||||
return versions.ReservedVersion{}, fmt.Errorf("the plan of %s at %s cannot be read: %w", module, fp, planErr)
|
||||
case len(plan.Tasks) == 0 || strings.Count(plan.Series, ".") != 1:
|
||||
return versions.ReservedVersion{}, fmt.Errorf("%s at %s builds nothing or has no MAJOR.MINOR series (%q): it reserves no version", module, fp, plan.Series)
|
||||
}
|
||||
if cur, ok, err := b.Reserved.ReservedFor(ctx, module, fp); err != nil {
|
||||
return versions.ReservedVersion{}, err
|
||||
} else if ok {
|
||||
return versions.ReservedVersion{}, fmt.Errorf("%s at %s holds the reservation of %s already", module, fp, cur.Version)
|
||||
}
|
||||
res, ok := b.reserve(ctx, module, m, plan, b.originOf(key), false)
|
||||
if !ok {
|
||||
return versions.ReservedVersion{}, fmt.Errorf("no version could be reserved for %s at %s (the builder's journal says why)", module, fp)
|
||||
}
|
||||
refs := map[string]string{}
|
||||
for _, t := range plan.Tasks {
|
||||
d, have := digests[t.Artifact]
|
||||
if !have {
|
||||
return res, fmt.Errorf("%s is reserved for %s at %s, but the done key holds no digest of %s", res.Version, module, fp, t.Artifact)
|
||||
}
|
||||
refs[module+":"+t.Artifact] = d
|
||||
}
|
||||
if err := b.Reserved.Built(ctx, module, res.Version, refs, nil); err != nil {
|
||||
return res, fmt.Errorf("%s is reserved for %s at %s, but its digests are not recorded: %w", res.Version, module, fp, err)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
@@ -34,25 +34,35 @@ type fakeReservations struct {
|
||||
tookBy map[string]versions.ReservedVersion // by fingerprint, the reservation that took its series over (H-A-244)
|
||||
held map[string]versions.ReservedVersion // by fingerprint, the reservation ReservedFor answers as it stands (H-A-492)
|
||||
lost error // the record of the digests fails, as a store refusing it would
|
||||
marks []string // the versions MarkRegistryHeld was told, with the asks the build module had by then (H-A-588 (4))
|
||||
asked func() int
|
||||
atMu sync.Mutex
|
||||
at map[string]string // by "<module>:<artifact>@<branch>.<source>", the version VersionAt answers (H-A-547 (3))
|
||||
at map[string]string // by "<module>:<artifact>@<fingerprint>", the version PublishedOf answers (H2 H-A-707 (4))
|
||||
}
|
||||
|
||||
func (f *fakeReservations) VersionAt(_ context.Context, module, artifact, branch string, source int64) (string, bool, error) {
|
||||
func (f *fakeReservations) PublishedOf(_ context.Context, module, artifact, fingerprint string) (meshbuilds.PublishedAnswer, error) {
|
||||
f.atMu.Lock()
|
||||
defer f.atMu.Unlock()
|
||||
v, ok := f.at[fmt.Sprintf("%s:%s@%s.%d", module, artifact, branch, source)]
|
||||
return v, ok, nil
|
||||
v, ok := f.at[fmt.Sprintf("%s@%s", artifact, fingerprint)]
|
||||
return meshbuilds.PublishedAnswer{Published: ok, Version: v}, nil
|
||||
}
|
||||
|
||||
// publishAt makes VersionAt answer version for module's artifact at the origin branch and source.
|
||||
func (f *fakeReservations) publishAt(module, artifact, branch string, source int64, version string) {
|
||||
// publishAt makes PublishedOf answer version for module's artifact built at fingerprint (design 47 H2 H-A-707 (4)).
|
||||
func (f *fakeReservations) publishAt(module, artifact, fingerprint, version string) {
|
||||
f.atMu.Lock()
|
||||
defer f.atMu.Unlock()
|
||||
if f.at == nil {
|
||||
f.at = map[string]string{}
|
||||
}
|
||||
f.at[fmt.Sprintf("%s:%s@%s.%d", module, artifact, branch, source)] = version
|
||||
f.at[fmt.Sprintf("%s:%s@%s", module, artifact, fingerprint)] = version
|
||||
}
|
||||
|
||||
func (f *fakeReservations) MarkRegistryHeld(_ context.Context, v versions.ReservedVersion) {
|
||||
n := 0
|
||||
if f.asked != nil {
|
||||
n = f.asked()
|
||||
}
|
||||
f.marks = append(f.marks, fmt.Sprintf("%s@%d asks", v.Version, n))
|
||||
}
|
||||
|
||||
func (f *fakeReservations) TakenOver(_ context.Context, _, fp string) (versions.ReservedVersion, bool, error) {
|
||||
@@ -270,15 +280,16 @@ func (unreadable) Get(context.Context, string) ([]byte, uint64, bool, error) {
|
||||
// reasks, under a key of the reservation (never a build key), refusing a module with no MAJOR.MINOR or no why.
|
||||
func TestADropOfAReservationIsAReasksValueOfItsOwnKey(t *testing.T) {
|
||||
at := time.Unix(0, 0)
|
||||
key, data, err := NewReservedDrop("m", "1.4", "never released", "op@x", at)
|
||||
key, data, err := NewReservedDrop("m", "1.4", "1.4.3", "never released", "op@x", at)
|
||||
if err != nil || key != "reserved."+versions.ReservedKey("m", "1.4") {
|
||||
t.Fatalf("key %q (%v)", key, err)
|
||||
}
|
||||
if r, err := DecodeReAsk(data); err != nil || r.Mode != ModeReservedDrop || r.Name != "m" || r.FP != "1.4" || r.By != "op@x" {
|
||||
if r, err := DecodeReAsk(data); err != nil || r.Mode != ModeReservedDrop || r.Name != "m" || r.FP != "1.4" || r.Version != "1.4.3" || r.By != "op@x" {
|
||||
t.Errorf("value = %+v (%v)", r, err)
|
||||
}
|
||||
for name, args := range map[string][3]string{"no module": {"", "1.4", "why"}, "no series": {"m", "1", "why"}, "three numbers": {"m", "1.4.2", "why"}, "no why": {"m", "1.4", " "}} {
|
||||
if _, _, err := NewReservedDrop(args[0], args[1], args[2], "op", at); err == nil {
|
||||
for name, args := range map[string][4]string{"no module": {"", "1.4", "1.4.3", "why"}, "no series": {"m", "1", "1.4.3", "why"}, "three numbers": {"m", "1.4.2", "1.4.3", "why"}, "no why": {"m", "1.4", "1.4.3", " "},
|
||||
"no version": {"m", "1.4", "", "why"}, "another series": {"m", "1.4", "1.5.3", "why"}} {
|
||||
if _, _, err := NewReservedDrop(args[0], args[1], args[2], args[3], "op", at); err == nil {
|
||||
t.Errorf("%s: a drop was made", name)
|
||||
}
|
||||
}
|
||||
@@ -429,6 +440,7 @@ func TestAReservingTrunkBuildNeverEndsDoneWithoutItsVersion(t *testing.T) {
|
||||
}
|
||||
r.b.Reserved = res
|
||||
asked := len(r.asks.Asks())
|
||||
res.asked = func() int { return len(r.asks.Asks()) - asked }
|
||||
got := r.b.BuildAgain(context.Background(), "m", fp1, "its publish was refused", "shanks.lead", 2*time.Second)
|
||||
r.b.Wait()
|
||||
if c.refuse != "" {
|
||||
@@ -447,6 +459,10 @@ func TestAReservingTrunkBuildNeverEndsDoneWithoutItsVersion(t *testing.T) {
|
||||
if _, ok := res.built[want]; !ok || len(res.reserved) != 1 {
|
||||
t.Fatalf("built %v after %d reservations; want the digests recorded under the freshly reserved %s so the build's end asks its publish", res.built, len(res.reserved), want)
|
||||
}
|
||||
// H2 H-A-588 (4): what the registries hold is marked once the version is reserved and before the build module is asked
|
||||
if len(res.marks) != 1 || res.marks[0] != want+"@0 asks" {
|
||||
t.Errorf("MarkRegistryHeld was told %v; want %s once, before any ask of the build module", res.marks, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -457,6 +473,7 @@ type realReserve struct {
|
||||
reservations map[string][]byte
|
||||
}
|
||||
|
||||
func (r *realReserve) MarkRegistryHeld(context.Context, versions.ReservedVersion) {}
|
||||
func (r *realReserve) ReleasedFor(context.Context, string, string) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"context"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
)
|
||||
|
||||
// TestADoneTrunkBuildThatReservedNoneIsGivenAVersionByHand: design 47 G A-455 — builder_reserve_done reserves the series' next
|
||||
// version for a done key that reserved none, with the digests the key holds; a key not done, a fingerprint no entry carries and
|
||||
// a build that holds a reservation already are refused; the value it writes is a reasks value of its own key.
|
||||
func TestADoneTrunkBuildThatReservedNoneIsGivenAVersionByHand(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
r := newRig(t, goBundle)
|
||||
r.mf.byDigest[mdigest('a')] = catalogue.Manifest{Module: "m", Version: "0.1", Build: &catalogue.Build{Artifacts: []catalogue.Artifact{goBundle}}}
|
||||
res := &fakeReservations{}
|
||||
r.b.Reserved = res
|
||||
if _, err := r.b.ReserveDone(ctx, "m", fp1); err == nil {
|
||||
t.Fatal("a version was reserved for a key that is not built")
|
||||
}
|
||||
// The build ran while the builder reserved nothing (as the live key did): done, with no reservation.
|
||||
r.b.Reserved = nil
|
||||
if v := r.consider(t, "modules/m"); v.State != builds.BuildDone {
|
||||
t.Fatalf("build = %+v, want done", v)
|
||||
}
|
||||
r.b.Reserved = res
|
||||
if _, err := r.b.ReserveDone(ctx, "m", "src2:"+strings.Repeat("9", 64)); err == nil || !strings.Contains(err.Error(), "no watched branch carries") {
|
||||
t.Errorf("a fingerprint no entry carries: %v", err)
|
||||
}
|
||||
got, err := r.b.ReserveDone(ctx, "m", fp1)
|
||||
if err != nil || got.Version != "0.1.5" || !slices.Equal(res.series, []string{"0.1"}) || !slices.Equal(res.reserved[0], []string{"m:tool"}) {
|
||||
t.Fatalf("reserved %+v (%v) in %v for %v, want 0.1.5 of m:tool in 0.1", got, err, res.series, res.reserved)
|
||||
}
|
||||
if res.built["m:tool"] != digest || res.sources[0].Fingerprint != fp1 {
|
||||
t.Errorf("recorded %v from %+v, want the done key's digest for the entry %s", res.built, res.sources, fp1)
|
||||
}
|
||||
if _, err := r.b.ReserveDone(ctx, "m", fp1); err == nil || !strings.Contains(err.Error(), "reservation") {
|
||||
t.Errorf("a build that holds a reservation was given another: %v", err)
|
||||
}
|
||||
at := time.Unix(0, 0)
|
||||
key, _, err := NewReserveDone("m", fp1, "why", "op", at)
|
||||
if err != nil || !strings.HasPrefix(key, "reserve-done.") {
|
||||
t.Errorf("key %q (%v)", key, err)
|
||||
}
|
||||
for _, args := range [][3]string{{"", fp1, "why"}, {"m", "", "why"}, {"m", fp1, " "}} {
|
||||
if _, _, err := NewReserveDone(args[0], args[1], args[2], "op", at); err == nil {
|
||||
t.Errorf("%q made a value", args)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,6 +104,10 @@ func (r *Retaker) Heard(ctx context.Context, subject string, data []byte, seq ui
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
// An event heard before the start sweep has filled the set of faulted keys waits for it (H-A-696), held under its node's key.
|
||||
if err := r.Builder.WaitFaults(ctx); err != nil {
|
||||
return true, err
|
||||
}
|
||||
var want func(seat, node string) bool
|
||||
if running {
|
||||
want, err = r.runningWant(ctx, data)
|
||||
@@ -135,7 +139,7 @@ func (r *Retaker) runningWant(ctx context.Context, data []byte) (func(seat, node
|
||||
r.logf("a running that does not read is not acted on: %v", err)
|
||||
return nil, nil
|
||||
}
|
||||
if ev.Stopped || ev.Fingerprint == "" {
|
||||
if ev.Stopped || ev.Fingerprint == "" || r.Builder.Faults.Len() == 0 { // no key to retake: no call (H-A-683 (2))
|
||||
return nil, nil
|
||||
}
|
||||
e, err := r.Entry(ctx, ev.Fingerprint)
|
||||
@@ -167,25 +171,9 @@ func (r *Retaker) returnedWant(data []byte) (func(seat, node string) bool, error
|
||||
return func(_, node string) bool { return node == ev.Node }, nil
|
||||
}
|
||||
|
||||
// retakeAll builds again every key failed on a transport fault whose seat and node want says passed.
|
||||
// retakeAll builds again every key of the set of faulted keys whose seat and node want says passed; it lists no key of the bucket.
|
||||
func (r *Retaker) retakeAll(ctx context.Context, want func(seat, node string) bool) error {
|
||||
keys, err := r.Builder.Claimer.Store.Keys(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("the build keys cannot be listed: %w", err)
|
||||
}
|
||||
for _, key := range keys {
|
||||
raw, _, found, err := r.Builder.Claimer.Store.Get(ctx, key)
|
||||
if err != nil || !found {
|
||||
continue
|
||||
}
|
||||
v, err := builds.DecodeBuilderBuild(raw)
|
||||
if err != nil || v.State != builds.BuildFailed {
|
||||
continue
|
||||
}
|
||||
_, seat, node, _, ok := builds.TransportFaultOf(v.Error)
|
||||
if !ok || !want(seat, node) {
|
||||
continue
|
||||
}
|
||||
for _, key := range r.Builder.Faults.Matching(want) {
|
||||
started, ask, cur, rev, err := r.Builder.Retake(ctx, key)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -5,7 +5,9 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
@@ -52,6 +54,9 @@ func TestRetakeOnAnEvent(t *testing.T) {
|
||||
if v := r.consider(t, "modules/m"); !builds.FailedOnTransportFault(v.Error) {
|
||||
t.Fatalf("the key = %+v, want failed on a transport fault", v)
|
||||
}
|
||||
if err := r.b.Sweep(context.Background()); err != nil { // the start sweep fills the set of faulted keys (H-A-696)
|
||||
t.Fatal(err)
|
||||
}
|
||||
var asked []string
|
||||
rt := &Retaker{Builder: r.b, Acted: &actedStore{},
|
||||
Entry: func(context.Context, string) (meshcatalog.CatalogEntry, error) {
|
||||
@@ -113,6 +118,9 @@ func TestRetakeOnANodeReturned(t *testing.T) {
|
||||
r.consider(t, "modules/m")
|
||||
seed(t, r.st, builds.BuilderBuild{State: builds.BuildFailed, By: "novox.builder", Manifest: mdigest('a'),
|
||||
Error: "transport fault: connection, node-build-go ace, dial tcp: connection refused"})
|
||||
if err := r.b.Sweep(context.Background()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rt := &Retaker{Builder: r.b, Acted: &actedStore{}}
|
||||
for seq, c := range []struct {
|
||||
node, why string
|
||||
@@ -128,3 +136,45 @@ func TestRetakeOnANodeReturned(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 H2 H-A-683 (2), H-A-696: a running heard before the start sweep has filled the set of faulted keys waits for it, then
|
||||
// retakes the keys its node names; one heard after, with the set empty, reads no entry and starts nothing.
|
||||
func TestRetakeWaitsForTheStartSweep(t *testing.T) {
|
||||
r := newRig(t, goBundle)
|
||||
r.consider(t, "modules/m")
|
||||
seed(t, r.st, builds.BuilderBuild{State: builds.BuildFailed, By: "novox.builder", Manifest: mdigest('a'),
|
||||
Error: "transport fault: connection, node-build-go ace, dial tcp: connection refused"})
|
||||
var entries atomic.Int32
|
||||
rt := &Retaker{Builder: r.b, Acted: &actedStore{}, Entry: func(context.Context, string) (meshcatalog.CatalogEntry, error) {
|
||||
entries.Add(1)
|
||||
return meshcatalog.CatalogEntry{Serves: []string{"node-build-go.steps"}}, nil
|
||||
}}
|
||||
running, _ := json.Marshal(nodeengine.Running{Module: "mesh-build-go", Node: "ace", Fingerprint: "f1"})
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
_, err := rt.Heard(context.Background(), "mesh.seat.node-engine.event.running.ace.mesh-build-go", running, 1)
|
||||
done <- err
|
||||
}()
|
||||
select {
|
||||
case err := <-done:
|
||||
t.Fatalf("a running heard before the sweep ended returned (%v), want it waiting", err)
|
||||
case <-time.After(50 * time.Millisecond):
|
||||
}
|
||||
if err := r.b.Sweep(context.Background()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := <-done; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.b.Wait()
|
||||
if v := valueOf(t, r.st, r.key); v.State != builds.BuildDone || entries.Load() != 1 {
|
||||
t.Fatalf("after the sweep: the key = %+v, entries read %d, want built and one entry read", v, entries.Load())
|
||||
}
|
||||
// The set is empty now: another running reads no entry.
|
||||
if _, err := rt.Heard(context.Background(), "mesh.seat.node-engine.event.running.ace.mesh-build-go", running, 2); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if entries.Load() != 1 {
|
||||
t.Fatalf("a running with the set empty read %d entries, want none more", entries.Load()-1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,9 @@ func theOperatorAnswers(t *testing.T, option string) {
|
||||
r.consider(t, "modules/m")
|
||||
seed(t, r.st, builds.BuilderBuild{State: builds.BuildFailed, By: "novox.builder", Manifest: mdigest('a'), EventBuilds: 3,
|
||||
Error: "transport fault: connection, node-build-go ace, dial tcp: connection refused"})
|
||||
if err := r.b.Sweep(context.Background()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var published []oc.Ask
|
||||
acted := &actedStore{}
|
||||
asker := &OperatorAsk{Builder: r.b, Acted: acted, Ctx: context.Background(), Now: askedAt,
|
||||
|
||||
@@ -2,6 +2,7 @@ package build
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"slices"
|
||||
@@ -163,26 +164,71 @@ func (b *Builder) awaitRevision(ctx context.Context, run meshbuilds.StepRun) (ou
|
||||
wait, stop := context.WithTimeout(ctx, bound) // a context's bound, no timer (ADR 0437 §8)
|
||||
defer stop()
|
||||
told := false
|
||||
var keys []string
|
||||
// Each entry of the ask is a wait said on the builder's stream waits (design 47 H2 H-A-577 (1)): `wait-held` while the picture
|
||||
// does not hold the revision, `wait-ended` with how it ended: ran, failed at the bound, released by builder_release.
|
||||
endWaits := func(how string) {
|
||||
for _, e := range run.Entries {
|
||||
if b.Waits != nil {
|
||||
b.Waits.EndRevision(context.WithoutCancel(ctx), e.Module, e.Fingerprint, how)
|
||||
}
|
||||
}
|
||||
b.mu.Lock()
|
||||
for _, k := range keys {
|
||||
delete(b.revisionWaiting, k)
|
||||
delete(b.revisionReleased, k)
|
||||
}
|
||||
b.mu.Unlock()
|
||||
}
|
||||
for {
|
||||
b.mu.Lock()
|
||||
moved := b.moved
|
||||
released := false
|
||||
for _, k := range keys {
|
||||
released = released || b.revisionReleased[k]
|
||||
}
|
||||
b.mu.Unlock()
|
||||
if b.holdsRevision(run.Branch, run.Source, run.Entries) {
|
||||
if told {
|
||||
b.logf("%s: revision %d of %s is in the builder's picture: the build goes on", run.Pipeline, run.Source, run.Branch)
|
||||
endWaits(WaitRan)
|
||||
}
|
||||
return "", ""
|
||||
}
|
||||
if released {
|
||||
endWaits(WaitReleased)
|
||||
b.logf("%s: %s: the wait was released by hand, the step fails, nothing is built", run.Pipeline, notHeld)
|
||||
return meshbuilds.StepEndedOutcomeFailed, notHeld + ": the wait was released by hand, and a build with no version is never made"
|
||||
}
|
||||
if !told {
|
||||
b.logf("%s: %s yet: the ask waits for it, at most %s", run.Pipeline, notHeld, bound)
|
||||
told = true
|
||||
since := b.now()
|
||||
for _, e := range run.Entries {
|
||||
if run.Revision <= 0 {
|
||||
break // an ask naming no revision has no `revision:<R>` to say
|
||||
}
|
||||
k, err := builds.BuilderBuildKey(e.Module, e.Fingerprint)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
keys = append(keys, k)
|
||||
b.mu.Lock()
|
||||
b.revisionWaiting[k] = true
|
||||
b.mu.Unlock()
|
||||
if b.Waits != nil {
|
||||
b.Waits.Hold(ctx, ToolchainWait{Module: e.Module, Fingerprint: e.Fingerprint, Since: since, Kind: WaitKindRevision, Revision: run.Revision, Bound: bound.String()})
|
||||
}
|
||||
}
|
||||
}
|
||||
select {
|
||||
case <-moved:
|
||||
case <-wait.Done():
|
||||
if ctx.Err() != nil {
|
||||
endWaits(WaitFailed)
|
||||
return meshbuilds.StepEndedOutcomeCouldNotRun, notHeld + ": the builder stopped before it was"
|
||||
}
|
||||
endWaits(WaitFailed)
|
||||
b.logf("%s: %s within %s: the step fails, nothing is built", run.Pipeline, notHeld, bound)
|
||||
return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s within %s", notHeld, bound)
|
||||
}
|
||||
@@ -217,36 +263,92 @@ func (b *Builder) PackagePublished(name, version string) {
|
||||
b.pictureMoved()
|
||||
}
|
||||
|
||||
// versionAtOrigin is the version, as Go names it, the module that publishes the package holds at the source revision of the
|
||||
// key's origin (H-A-547 (3), H-A-551), and words saying why there is none.
|
||||
func (b *Builder) versionAtOrigin(ctx context.Context, key, pkg string) (version, none string) {
|
||||
if b.Members == nil || b.Reserved == nil {
|
||||
return "", "no module that publishes it can be read"
|
||||
}
|
||||
module, artifact, found, err := b.Members(ctx, pkg)
|
||||
if err != nil || !found {
|
||||
if err != nil {
|
||||
return "", fmt.Sprintf("the module that publishes it cannot be read: %v", err)
|
||||
}
|
||||
return "", "no entry names the module that publishes it"
|
||||
}
|
||||
// pinOf is the version of package pkg for the build of module at fp, which holds origin, and what it waited for when there is none
|
||||
// (design 47 H2 H-A-707 (3), (4)). First the entry the picture holds for the module on the branch of origin, when it is of fp and
|
||||
// names a version for the package: a newer entry of the key's fingerprint has the pin its earlier entry lacked, and an entry of
|
||||
// another branch is never read. Else the version of the publisher's build in the build's revision: the module that publishes the
|
||||
// package (Members), its fingerprint in the catalog revision origin names (the picture while it holds that revision, else the
|
||||
// revision read by number, once), and the version the seat mesh-builds' published rule answers (Reserver.PublishedOf, H-A-328).
|
||||
// publisher is `<module>@<fingerprint>` of that build, empty where no module publishes the package.
|
||||
func (b *Builder) pinOf(ctx context.Context, module, fp, pkg string, origin Origin) (version, publisher, none string) {
|
||||
hk := origin.Branch + "\x00" + module
|
||||
b.mu.Lock()
|
||||
o := b.origin[key]
|
||||
h, heard := b.heard[hk]
|
||||
at := b.heardAt[hk]
|
||||
b.mu.Unlock()
|
||||
v, found, err := b.Reserved.VersionAt(ctx, module, artifact, o.Branch, o.Source)
|
||||
if heard && h.Fp2 == fp && h.Packages[pkg] != "" {
|
||||
if _, told := b.pinTold.LoadOrStore(module+"@"+fp+" "+pkg, true); !told {
|
||||
b.logf("%s at %s: %s takes %s, the pin of the entry of revision %d, heard while the build from revision %d waited", module, fp, pkg, h.Packages[pkg], at.Revision, origin.Revision)
|
||||
}
|
||||
return h.Packages[pkg], "", ""
|
||||
}
|
||||
if b.Members == nil || b.Reserved == nil {
|
||||
return "", "", "no module that publishes it can be read"
|
||||
}
|
||||
pubModule, artifact, found, err := b.Members(ctx, pkg)
|
||||
if err != nil {
|
||||
return "", fmt.Sprintf("the version %s holds at source revision %d cannot be read: %v", module, o.Source, err)
|
||||
return "", "", fmt.Sprintf("the module that publishes it cannot be read: %v", err)
|
||||
}
|
||||
if !found {
|
||||
return "", fmt.Sprintf("%s publishes no version of it at source revision %d of %s", module, o.Source, o.Branch)
|
||||
return "", "", fmt.Sprintf("no module of revision %d publishes it", origin.Revision)
|
||||
}
|
||||
return "v" + strings.TrimPrefix(v, "v"), ""
|
||||
pubFP, err := b.fingerprintAt(ctx, origin, pubModule)
|
||||
if err != nil {
|
||||
return "", pubModule + "@", fmt.Sprintf("%s's fingerprint in revision %d cannot be read: %v", pubModule, origin.Revision, err)
|
||||
}
|
||||
publisher = pubModule + "@" + pubFP
|
||||
if pubFP == "" {
|
||||
return "", publisher, fmt.Sprintf("%s has no entry in revision %d of %s", pubModule, origin.Revision, origin.Branch)
|
||||
}
|
||||
a, err := b.Reserved.PublishedOf(ctx, pubModule, pubModule+":"+artifact, pubFP) // the reservation keeps an artifact by its ref
|
||||
if err != nil {
|
||||
return "", publisher, fmt.Sprintf("the version %s holds at %s cannot be read: %v", pubModule, pubFP, err)
|
||||
}
|
||||
if !a.Published {
|
||||
return "", publisher, fmt.Sprintf("%s at %s (revision %d) is not published", pubModule, pubFP, origin.Revision)
|
||||
}
|
||||
return "v" + strings.TrimPrefix(a.Version, "v"), publisher, ""
|
||||
}
|
||||
|
||||
// awaitPublished fills each package of packages with no pin from the version its publisher holds at the key's origin
|
||||
// (versionAtOrigin), waiting for one (H-A-521, H-A-165). It answers the packages with every pin, or an outcome and its words:
|
||||
// failed past the bound naming the package, could not run when the builder stops.
|
||||
func (b *Builder) awaitPublished(ctx context.Context, module, fp string, packages map[string]string) (map[string]string, string, string) {
|
||||
// fingerprintAt is module's fingerprint in the catalog revision origin names: in the picture of the branch while the picture holds
|
||||
// that revision (or the origin names none), else in the revision read by number through the seat mesh-catalog, kept once read.
|
||||
func (b *Builder) fingerprintAt(ctx context.Context, origin Origin, module string) (string, error) {
|
||||
hk := origin.Branch + "\x00" + module
|
||||
b.mu.Lock()
|
||||
h, heard := b.heard[hk]
|
||||
at := b.heardAt[hk]
|
||||
b.mu.Unlock()
|
||||
if heard && (origin.Revision <= 0 || at.Revision == origin.Revision) {
|
||||
return h.Fp2, nil
|
||||
}
|
||||
if b.KeptRevision == nil || origin.Revision <= 0 {
|
||||
return "", errors.New("the picture does not hold the revision and none can be read by its number")
|
||||
}
|
||||
rk := fmt.Sprintf("%s\x00%d", origin.Branch, origin.Revision)
|
||||
b.mu.Lock()
|
||||
fps, ok := b.keptFPs[rk]
|
||||
b.mu.Unlock()
|
||||
if !ok {
|
||||
_, read, err := b.KeptRevision(ctx, origin.Branch, origin.Revision)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
fps = read
|
||||
b.mu.Lock()
|
||||
if b.keptFPs == nil {
|
||||
b.keptFPs = map[string]map[string]string{}
|
||||
}
|
||||
b.keptFPs[rk] = fps
|
||||
b.mu.Unlock()
|
||||
}
|
||||
return fps[module], nil
|
||||
}
|
||||
|
||||
// awaitPublished fills each package of packages with no pin (pinOf), waiting for one (H-A-521, H-A-165). The wait is kept in the
|
||||
// state waits in the one wait form, held under the build's key with the package's path, the publisher, the catalog revision and the
|
||||
// time it ends, ended published or failed (H-A-707 (5)). It answers the packages with every pin, or an outcome and its words: failed
|
||||
// past the bound naming the publisher and its fingerprint, could not run when the builder stops.
|
||||
func (b *Builder) awaitPublished(ctx context.Context, module, fp string, packages map[string]string, origin Origin) (map[string]string, string, string) {
|
||||
var unpinned []string
|
||||
for p, v := range packages {
|
||||
if v == "" {
|
||||
@@ -257,25 +359,30 @@ func (b *Builder) awaitPublished(ctx context.Context, module, fp string, package
|
||||
return packages, "", ""
|
||||
}
|
||||
slices.Sort(unpinned)
|
||||
key, err := builds.BuilderBuildKey(module, fp)
|
||||
if err != nil {
|
||||
if _, err := builds.BuilderBuildKey(module, fp); err != nil {
|
||||
return nil, meshbuilds.StepEndedOutcomeCouldNotRun, err.Error()
|
||||
}
|
||||
bound := b.packageWait()
|
||||
wait, stop := context.WithTimeout(ctx, bound) // a context's bound, no timer (ADR 0437 §8)
|
||||
defer stop()
|
||||
told := false
|
||||
since := b.now()
|
||||
endWait := func(how string) {
|
||||
if told && b.Waits != nil {
|
||||
b.Waits.End(ctx, module, fp, how)
|
||||
}
|
||||
}
|
||||
for {
|
||||
b.mu.Lock()
|
||||
moved := b.moved
|
||||
b.mu.Unlock()
|
||||
pins := map[string]string{}
|
||||
missing, why := "", ""
|
||||
missing, why, publisher := "", "", ""
|
||||
for _, p := range unpinned {
|
||||
v, none := b.versionAtOrigin(wait, key, p)
|
||||
v, pub, none := b.pinOf(wait, module, fp, p, origin)
|
||||
pins[p] = v
|
||||
if v == "" && missing == "" {
|
||||
missing, why = p, none
|
||||
missing, why, publisher = p, none, pub
|
||||
}
|
||||
}
|
||||
if missing == "" {
|
||||
@@ -283,6 +390,7 @@ func (b *Builder) awaitPublished(ctx context.Context, module, fp string, package
|
||||
maps.Copy(out, pins)
|
||||
if told {
|
||||
b.logf("%s at %s: every package it names is published: built with %v", module, fp, pins)
|
||||
endWait(WaitPublished)
|
||||
}
|
||||
return out, "", ""
|
||||
}
|
||||
@@ -291,6 +399,10 @@ func (b *Builder) awaitPublished(ctx context.Context, module, fp string, package
|
||||
b.logf("%s at %s: %s yet: the build waits for its publish, at most %s", module, fp, notPublished, bound)
|
||||
told = true
|
||||
}
|
||||
if b.Waits != nil {
|
||||
b.Waits.Hold(ctx, ToolchainWait{Module: module, Fingerprint: fp, Since: since, Package: missing, Publisher: publisher,
|
||||
Revision: origin.Revision, Bound: bound.String(), Until: since.Add(bound)})
|
||||
}
|
||||
select {
|
||||
case <-moved:
|
||||
case <-wait.Done():
|
||||
@@ -298,6 +410,7 @@ func (b *Builder) awaitPublished(ctx context.Context, module, fp string, package
|
||||
return nil, meshbuilds.StepEndedOutcomeCouldNotRun, notPublished + ": the builder stopped before it was"
|
||||
}
|
||||
b.logf("%s at %s: %s within %s: the build fails, nothing is built", module, fp, notPublished, bound)
|
||||
endWait(WaitFailed)
|
||||
return nil, meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s within %s", notPublished, bound)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,10 +133,16 @@ type Builder struct {
|
||||
// its single reference, and its needs. Nil: no node states anything, and the first forms are kept.
|
||||
Forms func() (present, counted map[string][]string)
|
||||
|
||||
once sync.Once
|
||||
sem chan struct{}
|
||||
wg sync.WaitGroup
|
||||
mu sync.Mutex
|
||||
once sync.Once
|
||||
// Faults are the keys whose newest revision failed on a transport fault (H-A-683 (2)), filled by Sweep and kept by every write.
|
||||
Faults *Faulted
|
||||
sem chan struct{}
|
||||
wg sync.WaitGroup
|
||||
mu sync.Mutex
|
||||
// pinTold are the pins taken from a newer entry, said once each; keptFPs the fingerprints of a kept catalog revision, by branch and
|
||||
// revision, read once (design 47 H2 H-A-707 (3), (4)).
|
||||
pinTold sync.Map
|
||||
keptFPs map[string]map[string]string
|
||||
known map[string]meshcatalog.ModulesByModuleValue // by modules key: the first watched branch's
|
||||
heard map[string]meshcatalog.ModulesByModuleValue // by branch and module (take): what supersedes what
|
||||
heardAt map[string]Origin // by branch and module (take): the revision the heard entry came from (H-A-557)
|
||||
@@ -165,6 +171,9 @@ type Builder struct {
|
||||
events map[string]bool
|
||||
// released are the keys builder_release is building now, whatever toolchain their fingerprint names (§276, §672).
|
||||
released map[string]bool
|
||||
// revisionWaiting are the keys whose step ask waits for its revision now, revisionReleased those builder_release ended
|
||||
// (design 47 H2 H-A-577 (1)).
|
||||
revisionWaiting, revisionReleased map[string]bool
|
||||
// builds are the ends that withdraw the asks of a key's build in flight, by build key (ADR 0664 §4): a newer fingerprint of
|
||||
// the module takes its older one's build out, and the asker drops that build's asks.
|
||||
builds map[string]context.CancelCauseFunc
|
||||
@@ -191,6 +200,8 @@ func (b *Builder) Looking(key string) bool {
|
||||
|
||||
func (b *Builder) init() {
|
||||
b.once.Do(func() {
|
||||
b.Faults = newFaulted()
|
||||
b.Claimer.Store = faultNoting{Store: b.Claimer.Store, set: b.Faults}
|
||||
limit := b.Limit
|
||||
if limit <= 0 {
|
||||
limit = 256
|
||||
@@ -205,6 +216,7 @@ func (b *Builder) init() {
|
||||
b.hands, b.events = map[string]*handWatch{}, map[string]bool{}
|
||||
b.builds = map[string]context.CancelCauseFunc{}
|
||||
b.moved = make(chan struct{})
|
||||
b.revisionWaiting, b.revisionReleased = map[string]bool{}, map[string]bool{}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -307,7 +319,11 @@ func (b *Builder) take(ctx context.Context, o Origin, key string, m meshcatalog.
|
||||
if bk, err := builds.BuilderBuildKey(key, m.Fp2); err == nil && m.Fp2 != "" {
|
||||
// A fingerprint a watched branch carries is built from that branch's commit, whoever asked for it first.
|
||||
b.trunkFP[bk] = true
|
||||
b.origin[bk] = o
|
||||
// The key's origin is never moved back (design 47 H2 H-A-707 (2)): an entry of an older revision with the same fingerprint
|
||||
// leaves the origin of the newer one as it was.
|
||||
if cur, held := b.origin[bk]; !held || !originNewer(cur, o) {
|
||||
b.origin[bk] = o
|
||||
}
|
||||
b.edges[bk] = e
|
||||
}
|
||||
b.mu.Unlock()
|
||||
@@ -335,7 +351,7 @@ const withdrawnPrefix = "withdrawn: "
|
||||
|
||||
// supersededBy is the fingerprint that supersedes fp, a fingerprint of module whose build key is key, when fp is of its
|
||||
// registration's first watched branch and is no longer the newest entry heard on that branch (H-A-489); "" otherwise. A key no
|
||||
// entry named is of the first branch, as originOf has it.
|
||||
// entry named is of the first branch, as originLocked has it.
|
||||
func (b *Builder) supersededBy(module, key, fp string) string {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
@@ -429,17 +445,38 @@ func everyArtifactNamesPaths(e meshcatalog.CatalogEntry) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// originOf is the catalog revision the entry of a build key came from; a key no entry named is of the first branch, as a build
|
||||
// of the trunk's value was before branches were watched.
|
||||
func (b *Builder) originOf(key string) Origin {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
// originLocked is the catalog revision the entry of a build key came from; a key no entry named is of the first branch, as a build
|
||||
// of the trunk's value was before branches were watched. It is read under the lock the caller holds.
|
||||
func (b *Builder) originLocked(key string) Origin {
|
||||
if o, ok := b.origin[key]; ok {
|
||||
return o
|
||||
}
|
||||
return Origin{First: true}
|
||||
}
|
||||
|
||||
// originNewer says whether the origin cur is of a newer module graph revision than o: known by their revisions, else their sources.
|
||||
func originNewer(cur, o Origin) bool {
|
||||
newer, known := newerRevision(cur, o)
|
||||
return known && newer
|
||||
}
|
||||
|
||||
// entryAndOrigin is what a build holds from its start (design 47 H2 H-A-707 (1)): the entry its picture holds for the module on the
|
||||
// branch of the key's origin when that entry is of the key's fingerprint, with the origin it was heard at, else the entry that woke it
|
||||
// with the key's origin. Taken under one lock, it is read by the build's reservation, pins and revision wait, never the key's origin
|
||||
// as it stands later.
|
||||
func (b *Builder) entryAndOrigin(module, key string, woke meshcatalog.ModulesByModuleValue) (meshcatalog.ModulesByModuleValue, Origin) {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
o := b.originLocked(key)
|
||||
if h, ok := b.heard[o.Branch+"\x00"+module]; ok && h.Fp2 == woke.Fp2 {
|
||||
if at, ok := b.heardAt[o.Branch+"\x00"+module]; ok {
|
||||
return h, at
|
||||
}
|
||||
return h, o
|
||||
}
|
||||
return woke, o
|
||||
}
|
||||
|
||||
// NodesChanged is Reconsider after a toolchain moved, so a build that waited for the nodes to agree on one may go on.
|
||||
func (b *Builder) NodesChanged(ctx context.Context) { b.Reconsider(ctx) }
|
||||
|
||||
@@ -481,6 +518,7 @@ func (b *Builder) Sweep(ctx context.Context, pictured ...string) error {
|
||||
if err != nil || !found {
|
||||
continue
|
||||
}
|
||||
b.Faults.note(key, value, rev)
|
||||
cur, err := builds.DecodeBuilderBuild(value)
|
||||
if err != nil {
|
||||
continue
|
||||
@@ -500,6 +538,7 @@ func (b *Builder) Sweep(ctx context.Context, pictured ...string) error {
|
||||
}
|
||||
b.logf("%s: closed, left building by %s for a fingerprint the module no longer has", key, cur.By)
|
||||
}
|
||||
b.logf("the start sweep read %d keys and put %d in the set of keys failed on a transport fault", len(keys), b.Faults.Fill())
|
||||
if newly {
|
||||
// A key read before the scan may wait for a package the scan found published (ADR 0500 clause 6).
|
||||
b.Reconsider(ctx)
|
||||
@@ -700,6 +739,7 @@ func (b *Builder) startOnce(ctx context.Context, key, module string, m meshcatal
|
||||
// building by this builder: it takes it again when it starts (ADR 0478 clause 5).
|
||||
func (b *Builder) try(ctx context.Context, module string, m meshcatalog.ModulesByModuleValue) {
|
||||
key, _ := builds.BuilderBuildKey(module, m.Fp2)
|
||||
m, origin := b.entryAndOrigin(module, key, m) // the build holds one entry and its origin (design 47 H2 H-A-707 (1))
|
||||
whyEnded := ""
|
||||
defer func() { b.handEnded(key, whyEnded) }()
|
||||
defer b.unrelease(key)
|
||||
@@ -748,8 +788,8 @@ func (b *Builder) try(ctx context.Context, module string, m meshcatalog.ModulesB
|
||||
delete(b.events, key)
|
||||
b.mu.Unlock()
|
||||
// Only a build of the registration's first watched branch reserves and releases a version (design 47 G §371).
|
||||
reserving := trunk && b.originOf(key).First && planErr == nil && !nothing && b.reserves(ctx, module, m, plan)
|
||||
if trunk && b.originOf(key).First && planErr == nil && !nothing && !reserving {
|
||||
reserving := trunk && origin.First && planErr == nil && !nothing && b.reserves(ctx, module, m, plan)
|
||||
if trunk && origin.First && planErr == nil && !nothing && !reserving {
|
||||
// A done build whose digests its end did not record is recorded at the next look (design 47 H2 H-A-492).
|
||||
if _, err := b.RecordAgain(ctx, module, m.Fp2, "at a look"); err != nil {
|
||||
b.logf("%v", err)
|
||||
@@ -803,14 +843,20 @@ func (b *Builder) try(ctx context.Context, module string, m meshcatalog.ModulesB
|
||||
// Reserved as A-490b amended by H-A-225 has it: this fingerprint's standing reservation is kept while it is unreleased
|
||||
// and above the highest the catalog's versions answers, else the next above that highest is taken (A-455); the build's
|
||||
// own publish then runs.
|
||||
reserved, hasReserved = b.reserve(ctx, module, m, plan, b.originOf(key), true)
|
||||
reserved, hasReserved = b.reserve(ctx, module, m, plan, origin, true)
|
||||
reserving = true
|
||||
} else if reserving && cl.Build.State != builds.BuildDone {
|
||||
// Looked at again just before it reserves (H-A-489): a newer entry heard since the claim is not taken over.
|
||||
if supersededNow = b.supersededBy(module, key, m.Fp2); supersededNow == "" {
|
||||
reserved, hasReserved = b.reserve(ctx, module, m, plan, b.originOf(key), false)
|
||||
reserved, hasReserved = b.reserve(ctx, module, m, plan, origin, false)
|
||||
}
|
||||
}
|
||||
if hasReserved && supersededNow == "" && cl.Build.State != builds.BuildDone {
|
||||
// Before a build module is asked for the fingerprint again, what a registry holds of it at its version is on the reservation
|
||||
// and marked published, so a version a failed build left partly published is completed, never built whole again over a
|
||||
// refusal (design 47 H2 H-A-588 (4), H-A-666: between the reserve and the build).
|
||||
b.Reserved.MarkRegistryHeld(ctx, reserved)
|
||||
}
|
||||
var result builds.BuilderBuild
|
||||
if supersededNow != "" {
|
||||
// Ended as the newer entry's take-in withdraws a build in flight: final for this fingerprint.
|
||||
@@ -828,7 +874,7 @@ func (b *Builder) try(ctx context.Context, module string, m meshcatalog.ModulesB
|
||||
b.mu.Lock()
|
||||
b.builds[key] = withdraw
|
||||
b.mu.Unlock()
|
||||
result = b.build(run, module, m, plan, planErr, prior, only, b.notes(cl), reserved.Version)
|
||||
result = b.build(run, module, m, plan, planErr, prior, only, b.notes(cl, origin), reserved.Version)
|
||||
b.mu.Lock()
|
||||
delete(b.builds, key)
|
||||
b.mu.Unlock()
|
||||
@@ -1167,10 +1213,12 @@ type askNotes struct {
|
||||
resumed map[string]string
|
||||
// step is the step words of a key taken over at start: an ask asked again says its asking there (askingOf).
|
||||
step string
|
||||
// origin is the origin the build holds from its start (design 47 H2 H-A-707 (1)), which its pins are read at.
|
||||
origin Origin
|
||||
}
|
||||
|
||||
func (b *Builder) notes(cl *Claim) *askNotes {
|
||||
n := &askNotes{b: b, cl: cl}
|
||||
func (b *Builder) notes(cl *Claim, origin Origin) *askNotes {
|
||||
n := &askNotes{b: b, cl: cl, origin: origin}
|
||||
if cl.Build.State == builds.BuildBuilding && len(cl.Build.Asks) > 0 {
|
||||
n.resumed, n.step = maps.Clone(cl.Build.Asks), cl.Build.Step
|
||||
}
|
||||
@@ -1239,7 +1287,7 @@ func (b *Builder) runLane(ctx context.Context, l *lane, repository string, m mes
|
||||
// them into the workspace, whatever the repository's go.mod names. A package the entry names with no pin waits for
|
||||
// its publish and is built with the version its publisher holds at the key's origin; past the bound the lane fails
|
||||
// naming it, and no ask is put (H-A-521, H-A-547 (3), H-A-165).
|
||||
pinned, outcome, said := b.awaitPublished(ctx, module, m.Fp2, m.Packages)
|
||||
pinned, outcome, said := b.awaitPublished(ctx, module, m.Fp2, m.Packages, asked.origin)
|
||||
if outcome != "" {
|
||||
l.err = errors.New(said)
|
||||
return
|
||||
|
||||
@@ -32,6 +32,11 @@ func (b *Builder) BuildStep(ctx context.Context, ask string, run meshbuilds.Step
|
||||
if d := DroppedOf(ctx); d != nil {
|
||||
outcome, said = meshbuilds.StepEndedOutcomeCouldNotRun, d.Error()
|
||||
}
|
||||
// A superseded end names the revision of the entry that supersedes it (H-A-561); where the builder heard none, it ends the
|
||||
// step could-not-run itself, naming that, never superseded with a zero revision (design 47 H2 H-A-650).
|
||||
if outcome == meshbuilds.StepEndedOutcomeSuperseded && end.Revision <= 0 {
|
||||
outcome, said = meshbuilds.StepEndedOutcomeCouldNotRun, "superseded by a newer entry, but the builder heard no superseding revision for it to name: "+said
|
||||
}
|
||||
at := b.now()
|
||||
end.Ended, end.Outcome, end.Said = &at, outcome, said
|
||||
if outcome != meshbuilds.StepEndedOutcomeSuperseded {
|
||||
@@ -148,7 +153,10 @@ func (b *Builder) buildEntry(ctx context.Context, pipeline string, e meshbuilds.
|
||||
}
|
||||
// A package the entry names with no pin is built against its publisher's version at the key's origin, waited for
|
||||
// (H-A-521, H-A-547 (3), H-A-165).
|
||||
pinned, outcome, said := b.awaitPublished(ctx, entry.Module, entry.Fp, entry.Packages)
|
||||
b.mu.Lock()
|
||||
origin := b.originLocked(func() string { k, _ := builds.BuilderBuildKey(entry.Module, entry.Fp); return k }())
|
||||
b.mu.Unlock()
|
||||
pinned, outcome, said := b.awaitPublished(ctx, entry.Module, entry.Fp, entry.Packages, origin)
|
||||
if outcome != "" {
|
||||
return outcome, said
|
||||
}
|
||||
@@ -207,7 +215,7 @@ func (b *Builder) buildEntry(ctx context.Context, pipeline string, e meshbuilds.
|
||||
|
||||
// passedWithItsVersion is the verdict of a build that ended done (design 47 G A-456): a build that reserves a version (a build
|
||||
// of the first watched branch's trunk, with a MAJOR.MINOR series and artifacts) passes only when a version is reserved for its
|
||||
// fingerprint; one that ended done with none fails loudly, naming builder_reserve_done, so no pipeline says passed for a build
|
||||
// fingerprint; one that ended done with none fails loudly, naming builder_build_again, so no pipeline says passed for a build
|
||||
// that can never be released, and one whose series another fingerprint took over fails saying it is stale, naming that
|
||||
// fingerprint and its version (design 47 H H-A-244). A build that reserves none (a candidate's, a series of before G) passes as it did.
|
||||
func (b *Builder) passedWithItsVersion(ctx context.Context, entry meshcatalog.CatalogEntry) (outcome, said string) {
|
||||
@@ -252,7 +260,7 @@ func (b *Builder) passedWithItsVersion(ctx context.Context, entry meshcatalog.Ca
|
||||
// H-A-244 (2): the series was taken over by a newer fingerprint, whose number it carries now: the build is stale.
|
||||
return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s: built at %s but its series moved to %s %s: stale", entry.Module, entry.Fp, by.Fingerprint, by.Version)
|
||||
}
|
||||
return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s: built at %s, but no version is reserved for it; builder_reserve_done reserves one for the done build", entry.Module, entry.Fp)
|
||||
return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s: built at %s, but no version is reserved for it; builder_build_again builds it again under a reserved one", entry.Module, entry.Fp)
|
||||
}
|
||||
return meshbuilds.StepEndedOutcomePassed, ""
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ func TestAStepAskIsWokenByItsBuildsEnd(t *testing.T) {
|
||||
}
|
||||
|
||||
// A build step passes a build that reserves a version only when a version is reserved for its fingerprint (design 47 G A-456):
|
||||
// a trunk build that ended done with none fails naming builder_reserve_done, and passes once one is reserved for it; a build
|
||||
// a trunk build that ended done with none fails naming builder_build_again, and passes once one is reserved for it; a build
|
||||
// that reserves none (a manifest of before G, version "1") passes as it did.
|
||||
func TestABuildStepPassesAReservingBuildOnlyWithItsReservedVersion(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
@@ -158,7 +158,7 @@ func TestABuildStepPassesAReservingBuildOnlyWithItsReservedVersion(t *testing.T)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.b.Module(t.Context(), "m", newer)
|
||||
hearAtRevision(t, r.b, "m", newer, 9)
|
||||
r.b.Wait()
|
||||
}
|
||||
r.b.Reserved = res
|
||||
@@ -169,7 +169,8 @@ func TestABuildStepPassesAReservingBuildOnlyWithItsReservedVersion(t *testing.T)
|
||||
return meshcatalog.CatalogEntry{Module: "m", Repository: "novox/m", Commit: "c1", Fp: fp1, ManifestDigest: digestOf(c.unreadable), Path: "modules/m"}, nil
|
||||
}
|
||||
end := r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.1.m", Step: meshbuilds.StepRunStepBuild, Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}})
|
||||
if end.Outcome != c.want || !strings.Contains(end.Said, c.said) || (c.want == meshbuilds.StepEndedOutcomeFailed && strings.Contains(end.Said, "builder_reserve_done") == c.takenOver) {
|
||||
// H2 H-A-665: the failure words of a build with no version name builder_build_again, the person's tool
|
||||
if end.Outcome != c.want || !strings.Contains(end.Said, c.said) || (c.want == meshbuilds.StepEndedOutcomeFailed && strings.Contains(end.Said, "builder_build_again") == c.takenOver) {
|
||||
t.Errorf("end = %+v, want %s saying %q", end, c.want, c.said)
|
||||
}
|
||||
// The verdict of a build that ended done, as a build ended now is judged, says the same (H-A-508: the newest entry first).
|
||||
@@ -182,6 +183,8 @@ func TestABuildStepPassesAReservingBuildOnlyWithItsReservedVersion(t *testing.T)
|
||||
})
|
||||
}
|
||||
t.Run("H-A-508: built now, superseded: a newer entry heard while the build runs ends the step superseded", aNewerEntryWhileTheBuildRunsSupersedesTheStep)
|
||||
t.Run("H-A-650: a superseded end the builder knows no revision for is could-not-run, never superseded with a zero", aSupersededEndWithNoRevisionIsCouldNotRun)
|
||||
t.Run("H-A-707 (1) (2): a build holds the newest entry of its fingerprint and its origin, which an older entry never moves back", aBuildHoldsItsNewestEntryAndOrigin)
|
||||
t.Run("H-A-155: an ask waits for the picture to take its revision in, then builds with its version reserved", aStepAskWaitsForItsRevision)
|
||||
t.Run("H-A-155: past the bound the ask fails naming its revision, and nothing is built", aStepAskPastItsRevisionBoundFails)
|
||||
t.Run("H-A-205: an ask of a revision below the picture's newest is read by number and built", anOlderKeptRevisionIsReadByNumber)
|
||||
@@ -191,6 +194,7 @@ func TestABuildStepPassesAReservingBuildOnlyWithItsReservedVersion(t *testing.T)
|
||||
t.Run("H-A-547 (3): a package with no pin waits for its publisher's version at the key's origin and is built with it", aPackageWithNoPinWaitsForItsRelease)
|
||||
t.Run("H-A-165: past its bound a package with no version at the origin fails the step", aPackageWithNoReleaseFailsPastItsBound)
|
||||
t.Run("H-A-547 (3): a lane waits for an unpinned package's version at its origin and fails past its bound", aLaneWaitsForAnUnpinnedPackage)
|
||||
t.Run("H-A-707 (3) (5): a newer entry of the branch names the pin and ends the wait, never one of another branch", aNewerEntrysPinEndsTheWait)
|
||||
}
|
||||
|
||||
// unpinnedRig is a rig whose step entry m names the package x with no version, x published by the artifact x of the module xm,
|
||||
@@ -207,6 +211,8 @@ func unpinnedRig(t *testing.T) (*rig, *fakeReservations, meshcatalog.CatalogEntr
|
||||
r.b.init()
|
||||
r.b.mu.Lock()
|
||||
r.b.origin[r.key] = Origin{Branch: "main", Source: 41, First: true}
|
||||
// the publisher's entry of the build's revision the picture holds (H2 H-A-707 (4))
|
||||
r.b.heard["main\x00xm"], r.b.heardAt["main\x00xm"] = meshcatalog.ModulesByModuleValue{Fp2: fpX}, Origin{Branch: "main", Source: 41, First: true}
|
||||
r.b.mu.Unlock()
|
||||
waiting := make(chan struct{}, 1)
|
||||
r.b.Logf = func(format string, args ...any) {
|
||||
@@ -221,6 +227,11 @@ func unpinnedRig(t *testing.T) (*rig, *fakeReservations, meshcatalog.CatalogEntr
|
||||
return r, res, entry, waiting
|
||||
}
|
||||
|
||||
var (
|
||||
fpX = "src2:" + strings.Repeat("c", 64) // the publisher xm's fingerprint in the build's revision
|
||||
fpXOld = "src2:" + strings.Repeat("d", 64)
|
||||
)
|
||||
|
||||
const unpinnedX = "git.novox.be/novox/mesh-contracts/go/seats/x"
|
||||
|
||||
// awaitWaiting fails the test unless the build started its wait before ended said anything.
|
||||
@@ -251,8 +262,8 @@ func aPackageWithNoPinWaitsForItsRelease(t *testing.T) {
|
||||
mu.Unlock()
|
||||
}
|
||||
}
|
||||
res.publishAt("xm", "x", "main", 40, "0.1.2") // another source revision than the key's origin: no pin
|
||||
r.b.PackagePublished(unpinnedX, "v0.1.9") // the newest heard: no pin (H-A-547 (3))
|
||||
res.publishAt("xm", "x", fpXOld, "0.1.2") // another fingerprint of the publisher than its build in the revision: no pin
|
||||
r.b.PackagePublished(unpinnedX, "v0.1.9") // the newest heard: no pin (H-A-547 (3))
|
||||
ended := make(chan meshbuilds.StepEnded, 1)
|
||||
go func() {
|
||||
ended <- r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41,
|
||||
@@ -262,7 +273,7 @@ func aPackageWithNoPinWaitsForItsRelease(t *testing.T) {
|
||||
if _, ok := r.st.vals[r.key]; ok {
|
||||
t.Fatal("the build was made before the package was published")
|
||||
}
|
||||
res.publishAt("xm", "x", "main", 41, "0.1.3")
|
||||
res.publishAt("xm", "x", fpX, "0.1.3")
|
||||
r.b.PackagePublished(unpinnedX, "v0.1.3")
|
||||
var end meshbuilds.StepEnded
|
||||
select {
|
||||
@@ -281,7 +292,7 @@ func aPackageWithNoPinWaitsForItsRelease(t *testing.T) {
|
||||
t.Errorf("the end reports the pins %v; want the ones it was built with", end.Packages)
|
||||
}
|
||||
// A done key reports the pins it keeps it was built with, never a newer one published now (H-A-207).
|
||||
res.publishAt("xm", "x", "main", 41, "0.1.5")
|
||||
res.publishAt("xm", "x", fpX, "0.1.5")
|
||||
again := r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41,
|
||||
Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}})
|
||||
if again.Outcome != meshbuilds.StepEndedOutcomePassed || again.Packages[unpinnedX] != "v0.1.3" {
|
||||
@@ -317,11 +328,11 @@ func aPackageWithNoReleaseFailsPastItsBound(t *testing.T) {
|
||||
Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}})
|
||||
r.b.Wait()
|
||||
if _, built := r.st.vals[r.key]; end.Outcome != meshbuilds.StepEndedOutcomeFailed || built ||
|
||||
!strings.Contains(end.Said, "package "+unpinnedX+" has no published version: xm publishes no version of it at source revision 41 of main") {
|
||||
!strings.Contains(end.Said, "package "+unpinnedX+" has no published version: xm at "+fpX+" (revision 0) is not published") {
|
||||
t.Errorf("end = %+v, built %v; want failed naming the package, nothing built", end, built)
|
||||
}
|
||||
// A version its publisher holds at the origin gives the pin at once.
|
||||
res.publishAt("xm", "x", "main", 41, "0.1.2")
|
||||
res.publishAt("xm", "x", fpX, "0.1.2")
|
||||
if end := r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41,
|
||||
Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}); strings.Contains(end.Said, "no published version") {
|
||||
t.Errorf("a version at the origin did not pin the package: %+v", end)
|
||||
@@ -342,7 +353,7 @@ func aLaneWaitsForAnUnpinnedPackage(t *testing.T) {
|
||||
if asks := r.asks.Asks(); len(asks) != 0 {
|
||||
t.Fatalf("a build was asked without the package's pin: %+v", asks)
|
||||
}
|
||||
res.publishAt("xm", "x", "main", 41, "0.1.5")
|
||||
res.publishAt("xm", "x", fpX, "0.1.5")
|
||||
r.b.PackagePublished(unpinnedX, "0.1.5")
|
||||
select {
|
||||
case <-done:
|
||||
@@ -417,6 +428,8 @@ func aStepAskWaitsForItsRevision(t *testing.T) {
|
||||
held.Store(40)
|
||||
asked := make(chan struct{}, 1)
|
||||
r, res, entry := revisionRig(t, &held, asked)
|
||||
rw := &memWaits{}
|
||||
r.b.Waits = rw
|
||||
var keptReads atomic.Int64 // H-A-205, H-A-222: a revision above the newest is read by number once; not answered, it is waited for
|
||||
r.b.KeptRevision = func(context.Context, string, int64) (int64, map[string]string, error) {
|
||||
keptReads.Add(1)
|
||||
@@ -449,6 +462,11 @@ func aStepAskWaitsForItsRevision(t *testing.T) {
|
||||
if end.Outcome != meshbuilds.StepEndedOutcomePassed || len(res.sources) != 1 || res.sources[0].Revision != 41 || keptReads.Load() != 1 {
|
||||
t.Errorf("end = %+v, reserved from %+v, kept revisions read %d; want passed with one version reserved from revision 41, read by number once", end, res.sources, keptReads.Load())
|
||||
}
|
||||
// H-A-577 (1): the wait is held `revision:7` while the picture lacks it and ended `ran` once it holds it
|
||||
if rw.mu.Lock(); !slices.Equal(rw.ons, []string{"revision:7"}) || !slices.Equal(rw.ended, []string{"revision:ran"}) || len(rw.held) != 0 {
|
||||
t.Errorf("the revision wait: held %v, ended %v, standing %v; want one revision:7 ended ran", rw.ons, rw.ended, rw.held)
|
||||
}
|
||||
rw.mu.Unlock()
|
||||
|
||||
}
|
||||
|
||||
@@ -488,7 +506,7 @@ func anOlderKeptRevisionIsReadByNumber(t *testing.T) {
|
||||
return 45, map[string]string{"m": fp1}, nil
|
||||
}
|
||||
entryn.Fp = fp2
|
||||
rn.b.Entry(context.Background(), Origin{Branch: "main", Source: 46, First: true}, entryn)
|
||||
rn.b.Entry(context.Background(), Origin{Branch: "main", Source: 46, Revision: 48, First: true}, entryn)
|
||||
rn.b.Wait()
|
||||
if endn := rn.b.BuildStep(t.Context(), "a1", run); endn.Outcome != meshbuilds.StepEndedOutcomeSuperseded || !strings.Contains(endn.Said, "superseded by "+fp2) {
|
||||
t.Errorf("the older ask after the newer entry: end = %+v; want superseded by %s", endn, fp2)
|
||||
@@ -643,12 +661,19 @@ func aStepAskPastItsRevisionBoundFails(t *testing.T) {
|
||||
held.Store(40)
|
||||
r, res, _ := revisionRig(t, &held, make(chan struct{}, 1))
|
||||
r.b.RevisionWait = time.Nanosecond
|
||||
rw := &memWaits{}
|
||||
r.b.Waits = rw
|
||||
end := r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.7.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Revision: 7, Source: 41,
|
||||
Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}})
|
||||
r.b.Wait()
|
||||
if _, built := r.st.vals[r.key]; end.Outcome != meshbuilds.StepEndedOutcomeFailed || !strings.Contains(end.Said, "revision 41 of main not in the builder's picture") || built || len(res.sources) != 0 {
|
||||
t.Errorf("end = %+v, built %v, reserved %+v; want failed naming revision 41 of main, nothing built", end, built, res.sources)
|
||||
}
|
||||
// H-A-577 (1): the wait is held and ended `failed` at its bound
|
||||
if rw.mu.Lock(); !slices.Equal(rw.ended, []string{"revision:failed"}) || len(rw.held) != 0 {
|
||||
t.Errorf("the revision wait: ended %v, standing %v; want one ended failed", rw.ended, rw.held)
|
||||
}
|
||||
rw.mu.Unlock()
|
||||
// A step ask with no source (a run on request) does not wait (H-A-156).
|
||||
end = r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "run.1.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}})
|
||||
if strings.Contains(end.Said, "not in the builder's picture") {
|
||||
@@ -710,7 +735,7 @@ func aNewerEntryWhileTheBuildRunsSupersedesTheStep(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.b.Module(t.Context(), "m", newer)
|
||||
hearAtRevision(t, r.b, "m", newer, 9)
|
||||
var end meshbuilds.StepEnded
|
||||
select {
|
||||
case end = <-ended:
|
||||
@@ -725,3 +750,130 @@ func aNewerEntryWhileTheBuildRunsSupersedesTheStep(t *testing.T) {
|
||||
t.Errorf("end = %+v, want superseded by %s", end, fp2)
|
||||
}
|
||||
}
|
||||
|
||||
// hearAtRevision takes a module's value in as the picture hears an entry of catalog revision rev on the first branch, so a step it
|
||||
// supersedes names that revision (design 47 H H-A-561; H2 H-A-650: none heard is no superseded end).
|
||||
func hearAtRevision(t *testing.T, b *Builder, module string, value []byte, rev int64) {
|
||||
t.Helper()
|
||||
m, err := meshcatalogclient.DecodeModule(value)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b.init()
|
||||
b.take(t.Context(), Origin{First: true, Revision: rev}, module, m, nil)
|
||||
b.Wait()
|
||||
}
|
||||
|
||||
func aSupersededEndWithNoRevisionIsCouldNotRun(t *testing.T) {
|
||||
r := newRig(t, goBundle)
|
||||
r.mf.byDigest[mdigest('a')] = catalogue.Manifest{Module: "m", Version: "0.1", Build: &catalogue.Build{Artifacts: []catalogue.Artifact{goBundle}}}
|
||||
if v := r.consider(t, "modules/m"); v.State != builds.BuildDone {
|
||||
t.Fatalf("build = %+v, want done", v)
|
||||
}
|
||||
newer, err := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Repository: "novox/mesh-catalog", Commit: "7a74cee83f88e6585a5511c3cc53bdf0f5303d20",
|
||||
Fp2: fp2, Manifest: mdigest('a'), Path: "modules/m", Toolchains: CatalogToolchains(agreedToolchains)})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.b.Module(t.Context(), "m", newer) // heard with no catalog revision
|
||||
r.b.Wait()
|
||||
r.b.Reserved = &fakeReservations{}
|
||||
r.b.StepEntry = func(context.Context, string) (meshcatalog.CatalogEntry, error) {
|
||||
return meshcatalog.CatalogEntry{Module: "m", Repository: "novox/m", Commit: "c1", Fp: fp1, ManifestDigest: digestOf(false), Path: "modules/m"}, nil
|
||||
}
|
||||
end := r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.1.m", Step: meshbuilds.StepRunStepBuild, Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}})
|
||||
if end.Outcome != meshbuilds.StepEndedOutcomeCouldNotRun || end.Revision != 0 || !strings.Contains(end.Said, "no superseding revision") {
|
||||
t.Errorf("end = %+v, want could not run naming that no superseding revision was heard", end)
|
||||
}
|
||||
}
|
||||
|
||||
func aBuildHoldsItsNewestEntryAndOrigin(t *testing.T) {
|
||||
var held atomic.Int64
|
||||
r, _, entry := revisionRig(t, &held, make(chan struct{}, 1))
|
||||
key, _ := builds.BuilderBuildKey("m", fp1)
|
||||
val := func(commit string) meshcatalog.ModulesByModuleValue {
|
||||
v, err := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Repository: "novox/mesh-catalog", Commit: commit, Fp2: fp1, Manifest: mdigest('a'), Path: "modules/m", Toolchains: CatalogToolchains(agreedToolchains)})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m, _ := meshcatalogclient.DecodeModule(v)
|
||||
return m
|
||||
}
|
||||
_ = entry
|
||||
r.b.init()
|
||||
o511 := Origin{Branch: "main", Source: 155, Revision: 511, First: true}
|
||||
o510 := Origin{Branch: "main", Source: 154, Revision: 510, First: true}
|
||||
r.b.take(t.Context(), o511, "m", val("7a74cee83f88e6585a5511c3cc53bdf0f5303d20"), nil)
|
||||
r.b.Wait()
|
||||
r.b.take(t.Context(), o510, "m", val("1111111111111111111111111111111111111111"), nil) // the same fingerprint, an older revision's entry
|
||||
r.b.Wait()
|
||||
r.b.mu.Lock()
|
||||
got := r.b.origin[key]
|
||||
r.b.mu.Unlock()
|
||||
if got != o511 {
|
||||
t.Errorf("the key's origin is %+v after an older revision's entry was taken; want revision 511's %+v as it was", got, o511)
|
||||
}
|
||||
// a build woken by revision 510's value takes the entry its picture holds, revision 511's, with its origin
|
||||
m, o := r.b.entryAndOrigin("m", key, val("1111111111111111111111111111111111111111"))
|
||||
if o != o511 || m.Commit != "7a74cee83f88e6585a5511c3cc53bdf0f5303d20" {
|
||||
t.Errorf("the build woken by revision 510's value holds %+v at %+v; want revision 511's entry and origin", m.Commit, o)
|
||||
}
|
||||
}
|
||||
|
||||
// H-A-707 (3), (5): while a build waits for a blank pin its wait stands in the state waits with the package's path, the publisher and its
|
||||
// fingerprint, the revision and its end; an entry of another branch with the pin changes nothing, and a newer entry of the key's
|
||||
// branch and fingerprint that names it ends the wait published and the build is made with it; one never published fails past the bound
|
||||
// naming the publisher and its fingerprint, its wait ended failed.
|
||||
func aNewerEntrysPinEndsTheWait(t *testing.T) {
|
||||
r, _, _, waiting := unpinnedRig(t)
|
||||
w := &memWaits{}
|
||||
r.b.Waits = w
|
||||
ended := make(chan meshbuilds.StepEnded, 1)
|
||||
go func() {
|
||||
ended <- r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41,
|
||||
Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}})
|
||||
}()
|
||||
awaitWaiting(t, waiting, ended)
|
||||
w.mu.Lock()
|
||||
held := w.held["m."+fp1]
|
||||
w.mu.Unlock()
|
||||
if held.Package != unpinnedX || held.Publisher != "xm@"+fpX || held.Until.IsZero() || held.Bound == "" {
|
||||
t.Fatalf("the pin wait held is %+v, want the package's path, xm@%s, its end and bound", held, fpX)
|
||||
}
|
||||
pin := func(branch string) {
|
||||
r.b.mu.Lock()
|
||||
r.b.heard[branch+"\x00m"], r.b.heardAt[branch+"\x00m"] = meshcatalog.ModulesByModuleValue{Fp2: fp1, Manifest: mdigest('a'), Path: "modules/m", Repository: "novox/m", Commit: "3333333333333333333333333333333333333333", Toolchains: CatalogToolchains(agreedToolchains), Packages: map[string]string{unpinnedX: "v0.1.8"}}, Origin{Branch: branch, Source: 42, First: true}
|
||||
r.b.mu.Unlock()
|
||||
r.b.pictureMoved()
|
||||
}
|
||||
pin("feature")
|
||||
select {
|
||||
case end := <-ended:
|
||||
t.Fatalf("an entry of another branch ended the wait: %+v", end)
|
||||
case <-time.After(100 * time.Millisecond):
|
||||
}
|
||||
pin("main")
|
||||
var end meshbuilds.StepEnded
|
||||
select {
|
||||
case end = <-ended:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("a newer entry's pin did not end the wait")
|
||||
}
|
||||
r.b.Wait()
|
||||
asks := r.asks.Asks()
|
||||
w.mu.Lock()
|
||||
endedWaits := slices.Clone(w.ended)
|
||||
w.mu.Unlock()
|
||||
if end.Outcome != meshbuilds.StepEndedOutcomePassed || len(asks) == 0 || asks[0].Packages[unpinnedX] != "v0.1.8" || !slices.Equal(endedWaits, []string{WaitPublished}) {
|
||||
t.Errorf("end %+v, asks %+v, waits ended %v; want passed, built with v0.1.8, the wait ended published", end, asks, endedWaits)
|
||||
}
|
||||
// Never published: past the bound the key fails naming the publisher and its fingerprint, and the wait ends failed.
|
||||
r2, _, _, _ := unpinnedRig(t)
|
||||
w2 := &memWaits{}
|
||||
r2.b.Waits, r2.b.PackageWait = w2, time.Nanosecond
|
||||
end = r2.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41,
|
||||
Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}})
|
||||
if end.Outcome != meshbuilds.StepEndedOutcomeFailed || !strings.Contains(end.Said, "xm at "+fpX+" (revision 0) is not published within") || !slices.Equal(w2.ended, []string{WaitFailed}) {
|
||||
t.Errorf("end %+v, waits ended %v; want failed naming xm and its fingerprint, the wait ended failed", end, w2.ended)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,15 +61,8 @@ type ReAsk struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
Queued []string `json:"queued,omitempty"`
|
||||
// Tries and NextTry are a ModePublish value's (design 47 G A-457a): the publishes tried so far, and when the next is.
|
||||
Tries int `json:"tries,omitempty"`
|
||||
NextTry time.Time `json:"next-try,omitzero"`
|
||||
}
|
||||
|
||||
// ModePublish is the Mode of a reasks value that is a version's publish item (design 47 G A-457a): Module and Version name it,
|
||||
// Tries and NextTry say where it stands; it is written by the builder itself, when a build ends and at its start.
|
||||
const ModePublish = "publish"
|
||||
|
||||
// ModeRepublish is the Mode of a reasks value of builder_publish_again (design 47 G §588): Module and Version, each
|
||||
// optional, name what to publish again; the builder answers with the versions it queued (Queued).
|
||||
const ModeRepublish = "republish"
|
||||
@@ -129,9 +122,10 @@ func NewOldFormDrop(node, why, by string, at time.Time) (string, []byte, error)
|
||||
const ModeReservedDrop = "reserved-drop"
|
||||
|
||||
// NewReservedDrop is the value builder_reserved_drop writes: the key `reserved.<module>.<MAJOR.MINOR>` (never a build key)
|
||||
// and the value.
|
||||
func NewReservedDrop(module, series, why, by string, at time.Time) (string, []byte, error) {
|
||||
module, series = strings.TrimSpace(module), strings.TrimSpace(series)
|
||||
// and the value, which names the version to drop (design 47 H2 H-A-592 (1)): a reservation a newer build took after it was read
|
||||
// is never dropped.
|
||||
func NewReservedDrop(module, series, version, why, by string, at time.Time) (string, []byte, error) {
|
||||
module, series, version = strings.TrimSpace(module), strings.TrimSpace(series), strings.TrimSpace(version)
|
||||
if module == "" {
|
||||
return "", nil, errors.New("module is required")
|
||||
}
|
||||
@@ -141,28 +135,13 @@ func NewReservedDrop(module, series, why, by string, at time.Time) (string, []by
|
||||
if strings.TrimSpace(why) == "" {
|
||||
return "", nil, errors.New("say why the reservation is dropped (why)")
|
||||
}
|
||||
data, err := json.Marshal(ReAsk{V: 1, Why: strings.TrimSpace(why), By: by, At: at.UTC(), Mode: ModeReservedDrop, Name: module, FP: series})
|
||||
if s, _, err := versions.SplitVersion(version); err != nil || s != series {
|
||||
return "", nil, fmt.Errorf("version %q is not a MAJOR.MINOR.PATCH of the series %s (version is required)", version, series)
|
||||
}
|
||||
data, err := json.Marshal(ReAsk{V: 1, Why: strings.TrimSpace(why), By: by, At: at.UTC(), Mode: ModeReservedDrop, Name: module, FP: series, Version: version})
|
||||
return "reserved." + versions.ReservedKey(module, series), data, err
|
||||
}
|
||||
|
||||
// ModeReserveDone is the Mode of a reasks value of builder_reserve_done (design 47 G A-455): Name is the module and FP the
|
||||
// fingerprint of a done trunk build that reserved no version.
|
||||
const ModeReserveDone = "reserve-done"
|
||||
|
||||
// NewReserveDone is the value builder_reserve_done writes: the key `reserve-done.<module>.<fingerprint>` (never a build key) and
|
||||
// the value.
|
||||
func NewReserveDone(module, fp, why, by string, at time.Time) (string, []byte, error) {
|
||||
module, fp = strings.TrimSpace(module), strings.TrimSpace(fp)
|
||||
if module == "" || fp == "" {
|
||||
return "", nil, errors.New("module and fp are required")
|
||||
}
|
||||
if strings.TrimSpace(why) == "" {
|
||||
return "", nil, errors.New("say why a version is reserved for the done build (why)")
|
||||
}
|
||||
data, err := json.Marshal(ReAsk{V: 1, Why: strings.TrimSpace(why), By: by, At: at.UTC(), Mode: ModeReserveDone, Name: module, FP: fp})
|
||||
return "reserve-done." + versions.EscapeToken(module) + "." + versions.EscapeToken(fp), data, err
|
||||
}
|
||||
|
||||
// ModeBuild is the Mode of a reasks value that asks the key to be built again, not its waiting asks to be asked again.
|
||||
const ModeBuild = "build"
|
||||
|
||||
@@ -243,24 +222,28 @@ type StuckAsk struct {
|
||||
|
||||
// Stuck is one build key that waits on an ask.
|
||||
type Stuck struct {
|
||||
Key string `json:"key"`
|
||||
Module string `json:"module"`
|
||||
FP string `json:"fp"`
|
||||
State string `json:"state"`
|
||||
Step string `json:"step"`
|
||||
By string `json:"by"`
|
||||
Since time.Time `json:"since,omitzero"`
|
||||
Age string `json:"age,omitempty"`
|
||||
Asks []StuckAsk `json:"asks"`
|
||||
ReAsk *ReAsk `json:"reask,omitempty"`
|
||||
Unasked bool `json:"unasked,omitempty"`
|
||||
NoneStep int `json:"asks_with_no_step"`
|
||||
Key string `json:"key"`
|
||||
Module string `json:"module"`
|
||||
FP string `json:"fp"`
|
||||
State string `json:"state"`
|
||||
Step string `json:"step"`
|
||||
By string `json:"by"`
|
||||
Since time.Time `json:"since,omitzero"`
|
||||
Age string `json:"age,omitempty"`
|
||||
Asks []StuckAsk `json:"asks"`
|
||||
ReAsk *ReAsk `json:"reask,omitempty"`
|
||||
// Waits is the wait a key building with no ask holds in the state waits, so a key waiting for a pin is told apart from one stuck.
|
||||
Waits []ToolchainWait `json:"waits,omitempty"`
|
||||
Unasked bool `json:"unasked,omitempty"`
|
||||
NoneStep int `json:"asks_with_no_step"`
|
||||
}
|
||||
|
||||
// StuckReader reads what builder_stuck answers.
|
||||
type StuckReader struct {
|
||||
Builds StateRead
|
||||
ReAsks StateRead
|
||||
// Waits is the builder's state waits: a key building with no ask gains the wait it holds, read from it (design 47 H2 H-A-707 (5)).
|
||||
Waits StateRead
|
||||
// Steps are the build seats' steps states (`<seat>.steps`, design 47 G A-82), by build seat.
|
||||
Steps map[string]StateRead
|
||||
// StepsOf, when set, reads the steps state of a build seat the seat list names (`<seat>.steps`), instead of Steps: the seats
|
||||
@@ -418,6 +401,15 @@ func (r StuckReader) Stuck(module string) (map[string]any, error) {
|
||||
}
|
||||
sort.Slice(s.Asks, func(i, j int) bool { return s.Asks[i].Language < s.Asks[j].Language })
|
||||
s.Unasked = v.State == builds.BuildBuilding && len(v.Asks) == 0
|
||||
if s.Unasked && r.Waits.Get != nil {
|
||||
reads++
|
||||
if raw, _, err := r.Waits.Get(key); err == nil && raw != nil {
|
||||
var w ToolchainWait
|
||||
if json.Unmarshal(raw, &w) == nil && w.Module != "" {
|
||||
s.Waits = append(s.Waits, w)
|
||||
}
|
||||
}
|
||||
}
|
||||
if r.ReAsks.Get != nil {
|
||||
reads++
|
||||
if raw, _, err := r.ReAsks.Get(key); err == nil && raw != nil {
|
||||
|
||||
@@ -29,6 +29,12 @@ const (
|
||||
// WaitPublished ends the wait of a key queued behind a package, when the key is claimed (the package is published).
|
||||
WaitPublished = "published"
|
||||
WaitReleased = "released"
|
||||
// WaitFailed ends a revision wait at its bound (design 47 H2 H-A-577 (1)).
|
||||
WaitFailed = "failed"
|
||||
// WaitReplaced ends a wait a build's next wait took the key from (design 47 H2 H-A-723 (1)).
|
||||
WaitReplaced = "replaced"
|
||||
// WaitKindRevision is the Kind of a revision wait.
|
||||
WaitKindRevision = "revision"
|
||||
)
|
||||
|
||||
// ToolchainWait is one wait: the entry's module and fingerprint, and the toolchain it waits for.
|
||||
@@ -41,13 +47,36 @@ type ToolchainWait struct {
|
||||
// Package is the package version a key queued behind it waits for, `<name>@<version>` (ADR 0603 §8; design 47 G A-192): the wait is the
|
||||
// package's, not a toolchain's, and Language and Version are empty.
|
||||
Package string `json:"package,omitempty"`
|
||||
// Kind is "revision" on a step ask's wait for its revision; Revision is then the module graph revision the ask names (design
|
||||
// 47 H2 H-A-577 (1)); Bound is that wait's own bound, said as `bound` (the toolchain wait's is the builder's).
|
||||
Kind string `json:"kind,omitempty"`
|
||||
Revision int64 `json:"revision,omitempty"`
|
||||
Bound string `json:"bound,omitempty"`
|
||||
// Publisher (`<module>@<fingerprint>`) and Until are the pin wait's: a build waiting for a blank pin's version holds Package, the
|
||||
// package's path alone, Publisher the build it waits for, Revision the catalog revision the build holds and Until its start plus
|
||||
// `package-wait-minutes` (design 47 H2 H-A-707 (5), DQ-53, H-A-717).
|
||||
Publisher string `json:"publisher,omitempty"`
|
||||
Until time.Time `json:"until,omitzero"`
|
||||
}
|
||||
|
||||
// SameWait says w and o are one wait: every field but when it began and when it ends, so a Hold of the wait that stands changes
|
||||
// nothing (design 47 H2 H-A-723 (1)).
|
||||
func (w ToolchainWait) SameWait(o ToolchainWait) bool {
|
||||
w.Since, w.Until, o.Since, o.Until = time.Time{}, time.Time{}, time.Time{}, time.Time{}
|
||||
return w == o
|
||||
}
|
||||
|
||||
// IsRevision says whether the wait is a step ask's wait for its revision, kept under `<module>.<fingerprint>.revision`.
|
||||
func (w ToolchainWait) IsRevision() bool { return w.Kind == WaitKindRevision }
|
||||
|
||||
// On is what the wait waits for, as the wait's `on` says it.
|
||||
func (w ToolchainWait) On() string {
|
||||
if w.Package != "" {
|
||||
return "package:" + w.Package
|
||||
}
|
||||
if w.IsRevision() {
|
||||
return fmt.Sprintf("revision:%d", w.Revision)
|
||||
}
|
||||
return "toolchain:" + w.Language + "@" + w.Version
|
||||
}
|
||||
|
||||
@@ -56,6 +85,9 @@ func (w ToolchainWait) On() string {
|
||||
type Waits interface {
|
||||
Hold(ctx context.Context, w ToolchainWait)
|
||||
End(ctx context.Context, module, fp, how string) bool
|
||||
// EndRevision ends the revision wait of module's fingerprint, saying how (ran, failed or released), and answers whether
|
||||
// one was held (design 47 H2 H-A-577 (1)).
|
||||
EndRevision(ctx context.Context, module, fp, how string) bool
|
||||
}
|
||||
|
||||
// toolchainWait is the toolchain wait of a module's fingerprint, or false when no language of its plan names a version
|
||||
@@ -100,7 +132,18 @@ func (b *Builder) Release(ctx context.Context, module, fp, why, by string) strin
|
||||
if !b.Waits.End(ctx, module, fp, WaitReleased) {
|
||||
b.mu.Lock()
|
||||
delete(b.released, key)
|
||||
revision := b.revisionWaiting[key]
|
||||
b.mu.Unlock()
|
||||
// A step ask's wait for its revision ends as its bound does (design 47 H2 H-A-577 (1)): the ask fails, since a build
|
||||
// with no version is never made (H-A-155).
|
||||
if revision {
|
||||
b.mu.Lock()
|
||||
b.revisionReleased[key] = true
|
||||
b.mu.Unlock()
|
||||
b.pictureMoved()
|
||||
b.logf("%s: the revision wait is released by %s (%s): the ask fails, nothing is built", key, by, why)
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("%s holds no toolchain wait: %s builds a failed key again", key, BuildAgainTool)
|
||||
}
|
||||
b.logf("%s: released by %s (%s): built with the running build module", key, by, why)
|
||||
|
||||
@@ -13,6 +13,7 @@ type memWaits struct {
|
||||
mu sync.Mutex
|
||||
held map[string]ToolchainWait
|
||||
ended []string
|
||||
ons []string // what each wait held waited on, in the order held
|
||||
}
|
||||
|
||||
func (w *memWaits) Hold(_ context.Context, t ToolchainWait) {
|
||||
@@ -21,7 +22,20 @@ func (w *memWaits) Hold(_ context.Context, t ToolchainWait) {
|
||||
if w.held == nil {
|
||||
w.held = map[string]ToolchainWait{}
|
||||
}
|
||||
w.held[t.Module+"."+t.Fingerprint] = t
|
||||
w.ons = append(w.ons, t.On())
|
||||
w.held[t.Module+"."+t.Fingerprint+map[bool]string{true: ".revision"}[t.IsRevision()]] = t
|
||||
}
|
||||
|
||||
func (w *memWaits) EndRevision(_ context.Context, module, fp, how string) bool {
|
||||
w.mu.Lock()
|
||||
defer w.mu.Unlock()
|
||||
k := module + "." + fp + ".revision"
|
||||
if _, ok := w.held[k]; !ok {
|
||||
return false
|
||||
}
|
||||
delete(w.held, k)
|
||||
w.ended = append(w.ended, "revision:"+how)
|
||||
return true
|
||||
}
|
||||
|
||||
func (w *memWaits) End(_ context.Context, module, fp, how string) bool {
|
||||
@@ -29,7 +43,7 @@ func (w *memWaits) End(_ context.Context, module, fp, how string) bool {
|
||||
defer w.mu.Unlock()
|
||||
k := module + "." + fp
|
||||
t, ok := w.held[k]
|
||||
if !ok || (t.Package != "") != (how == WaitPublished) { // as the builder's waitsKept ends them: a package wait by its publishing alone
|
||||
if !ok || (how != WaitFailed && (t.Package != "") != (how == WaitPublished)) { // as the builder's waitsKept ends them: a package wait by its publishing alone
|
||||
return false
|
||||
}
|
||||
delete(w.held, k)
|
||||
|
||||
@@ -11,11 +11,8 @@ type Acts struct {
|
||||
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.
|
||||
DropOldForm func(ctx context.Context, node, by, why string, at time.Time) (string, error)
|
||||
// ReserveDone reserves the next version for a done trunk build that reserved none and queues its publish (builder_reserve_done):
|
||||
// its answer, or why not.
|
||||
ReserveDone func(ctx context.Context, module, fp, by, why string, at time.Time) (string, error)
|
||||
// DropReserved drops a module's reservation of one MAJOR.MINOR by hand (builder_reserved_drop): its answer, or why not.
|
||||
DropReserved func(ctx context.Context, module, series, by, why string, at time.Time) (string, error)
|
||||
DropReserved func(ctx context.Context, module, series, version, by, why string, at time.Time) (string, error)
|
||||
// PublishDrop terminates one publish item (builder_publish_drop, design 47 H2 §793): the answer, or why not.
|
||||
PublishDrop func(ctx context.Context, module, version, by, why string) (string, error)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
package versions
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatlist"
|
||||
)
|
||||
|
||||
// DefaultRepublishMaxVersions is the setting republish-max-versions' default: the most versions one event queues (design 47 G §633).
|
||||
const DefaultRepublishMaxVersions = 50
|
||||
|
||||
// Againer puts the publish of every reserved version again on the events of ADR 0674 §2 (design 47 H2 H-A-606, G §588): the node-engine
|
||||
// seat's `running` of a module whose catalog entry claims a registry seat, and its `manifest-reads-changed` with `why` `returned` of a
|
||||
// node a registry seat's holder runs on. Each message is acted on once, by its stream sequence (state `acted`, key `publish:<subject>`),
|
||||
// and queues at most MaxVersions versions per event, newest first, at that holder only; what the work queue holds already is not queued
|
||||
// again (ADR 0674 §3).
|
||||
type Againer struct {
|
||||
Republisher *Republisher
|
||||
// Acted is the state acted, written with the lifetime of acted-days.
|
||||
Acted ReserveStore
|
||||
// Nodes answers each holder of a registry seat with its node, from the seat-holders view (seatlist.HolderNodesIn); nil answers none.
|
||||
Nodes func(seat string) []seatlist.HolderNode
|
||||
// MaxVersions is the setting republish-max-versions; zero is DefaultRepublishMaxVersions.
|
||||
MaxVersions int
|
||||
}
|
||||
|
||||
func (a *Againer) logf(f string, args ...any) { a.Republisher.logf(f, args...) }
|
||||
|
||||
func againKey(subject string) string { return ActedKey("publish:" + subject) }
|
||||
|
||||
// Heard takes one message of the node-engine seat's running or manifest-reads-changed in, at stream sequence seq, and acts on it once:
|
||||
// handled is false for a subject that is neither. An error leaves it not acted on, so it is read again.
|
||||
func (a *Againer) Heard(ctx context.Context, subject string, data []byte, seq uint64) (handled bool, err error) {
|
||||
running := strings.HasPrefix(subject, strings.TrimSuffix(nodeengine.SubjectRunningAll, "*.*"))
|
||||
changed := strings.HasPrefix(subject, "mesh.seat.node-engine.event."+nodeengine.EventManifestReadsChanged+".")
|
||||
if !running && !changed {
|
||||
return false, nil
|
||||
}
|
||||
key := againKey(subject)
|
||||
raw, rev, found, err := a.Acted.Get(ctx, key)
|
||||
if err != nil {
|
||||
return true, fmt.Errorf("the acted sequence of %s cannot be read: %w", subject, err)
|
||||
}
|
||||
if found {
|
||||
var done Acted
|
||||
if json.Unmarshal(raw, &done) == nil && done.Sequence >= seq {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
var holders func(seat string) []string
|
||||
if running {
|
||||
holders = a.runningHolders(ctx, data)
|
||||
} else {
|
||||
holders = a.returnedHolders(data)
|
||||
}
|
||||
if holders != nil {
|
||||
if err := a.again(ctx, holders, seq); err != nil {
|
||||
return true, err
|
||||
}
|
||||
}
|
||||
val, _ := json.Marshal(Acted{Sequence: seq})
|
||||
if found {
|
||||
_, err = a.Acted.Update(ctx, key, val, rev)
|
||||
} else {
|
||||
_, err = a.Acted.Create(ctx, key, val)
|
||||
}
|
||||
if err != nil && !errors.Is(err, ErrConflict) {
|
||||
return true, fmt.Errorf("the acted sequence of %s cannot be kept: %w", subject, err)
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// runningHolders is the holder function of a running: the module that is running holds each registry seat its catalog entry claims.
|
||||
// nil when it holds none, or when no version waits (no call is made then).
|
||||
func (a *Againer) runningHolders(ctx context.Context, data []byte) func(seat string) []string {
|
||||
var ev nodeengine.Running
|
||||
if err := json.Unmarshal(data, &ev); err != nil || ev.Module == "" {
|
||||
a.logf("a running that does not read is not acted on: %v", err)
|
||||
return nil
|
||||
}
|
||||
if ev.Stopped || ev.Fingerprint == "" {
|
||||
return nil
|
||||
}
|
||||
if vs, err := a.unreleased(ctx); err != nil || len(vs) == 0 {
|
||||
return nil
|
||||
}
|
||||
e, err := a.Republisher.Entry(ctx, ev.Fingerprint)
|
||||
if err != nil {
|
||||
a.logf("the catalog entry %s of %s cannot be read, so no publish is put again for it: %v", ev.Fingerprint, ev.Module, err)
|
||||
return nil
|
||||
}
|
||||
var claimed []string
|
||||
for _, s := range e.Serves {
|
||||
if seat, _, _ := strings.Cut(s, "."); slices.Contains(RegistrySeats, seat) && !slices.Contains(claimed, seat) {
|
||||
claimed = append(claimed, seat)
|
||||
}
|
||||
}
|
||||
if len(claimed) == 0 {
|
||||
return nil
|
||||
}
|
||||
return func(seat string) []string {
|
||||
if slices.Contains(claimed, seat) {
|
||||
return []string{ev.Module}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// returnedHolders is the holder function of a manifest-reads-changed with why returned: the holders of each registry seat that run on
|
||||
// the node it names. nil for another why, or when none runs there.
|
||||
func (a *Againer) returnedHolders(data []byte) func(seat string) []string {
|
||||
var ev nodeengine.ManifestReadsChanged
|
||||
if err := json.Unmarshal(data, &ev); err != nil || ev.Node == "" {
|
||||
a.logf("a manifest-reads-changed that does not read is not acted on: %v", err)
|
||||
return nil
|
||||
}
|
||||
if ev.Why != nodeengine.ManifestReadsChangedWhyReturned || a.Nodes == nil {
|
||||
return nil
|
||||
}
|
||||
on := map[string]string{}
|
||||
for _, seat := range RegistrySeats {
|
||||
for _, h := range a.Nodes(seat) {
|
||||
if h.Node == ev.Node {
|
||||
on[seat] = h.Module
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(on) == 0 {
|
||||
return nil
|
||||
}
|
||||
return func(seat string) []string {
|
||||
if m, ok := on[seat]; ok {
|
||||
return []string{m}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// unreleased are the reserved versions whose build is done and with an artifact unpublished.
|
||||
func (a *Againer) unreleased(ctx context.Context) ([]ReservedVersion, error) {
|
||||
all, err := a.Republisher.Reserved.All(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var out []ReservedVersion
|
||||
for _, v := range all {
|
||||
if !v.BuiltAt.IsZero() && len(v.Missing()) > 0 {
|
||||
out = append(out, v)
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// again queues the unreleased versions at the holders holdersOf names, at most MaxVersions of them.
|
||||
func (a *Againer) again(ctx context.Context, holdersOf func(seat string) []string, seq uint64) error {
|
||||
vs, err := a.unreleased(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("the reserved versions cannot be read: %w", err)
|
||||
}
|
||||
if len(vs) == 0 {
|
||||
return nil
|
||||
}
|
||||
max := a.MaxVersions
|
||||
if max <= 0 {
|
||||
max = DefaultRepublishMaxVersions
|
||||
}
|
||||
queued, err := a.Republisher.queue(ctx, vs, holdersOf, max, seq)
|
||||
if len(queued) > 0 {
|
||||
a.logf("publish again on an event: %d versions put on the work queue: %s", len(queued), strings.Join(queued, ", "))
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-sdk/go/busretry"
|
||||
)
|
||||
|
||||
// **A reserved version of a done build is published by the builder until its release is written** (design 47 G §588, A-457a): the
|
||||
@@ -32,7 +33,7 @@ const (
|
||||
PublishesLocal = "publishes"
|
||||
// ActedState holds, one key per subject, the last stream sequence the builder acted on; capped at ActedMiB.
|
||||
ActedState = "acted"
|
||||
ActedMiB = 1
|
||||
ActedMiB = 4
|
||||
// PublishQueueTool is builder_publish_queue.
|
||||
PublishQueueTool = "builder_publish_queue"
|
||||
// QueueFull is what version-unreleased says of a version the work queue's cap refused.
|
||||
@@ -94,6 +95,19 @@ type QueuedPublish struct {
|
||||
Queued time.Time `json:"queued"`
|
||||
// Class is PublishClassLive or PublishClassStart (H-A-290 (1)); a value written before it had one is of the start.
|
||||
Class string `json:"class,omitempty"`
|
||||
// Sequence is the stream sequence of the event whose publish again this item is, the last token of its message id (H-A-613 (1)); zero
|
||||
// for an item no event asked, which is not kept on the item.
|
||||
Sequence uint64 `json:"-"`
|
||||
}
|
||||
|
||||
// MsgID is the message id of the item: PublishMsgID, and for an event's publish again the event's stream sequence after it, so the same
|
||||
// event heard again puts nothing (design 47 H2 H-A-613 (1)).
|
||||
func (q QueuedPublish) MsgID() string {
|
||||
id := PublishMsgID(q.Holder, q.Class, q.Module, q.Version)
|
||||
if q.Sequence > 0 {
|
||||
id += "." + strconv.FormatUint(q.Sequence, 10)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// streamOrder sorts the keys of the work queue's items in stream order: each key is its item's stream sequence (the builder's
|
||||
@@ -137,6 +151,21 @@ type Acted struct {
|
||||
Sequence uint64 `json:"sequence"`
|
||||
}
|
||||
|
||||
// OtherBytes is a holder's answer to a publish of a version it holds with other bytes (design 47 H2 H-A-589 (1), H-A-729): the
|
||||
// digest, and the fingerprint it keeps for the version, empty where none is kept. It is an error of Send, which the publish item
|
||||
// ends at, never as a refusal asked again: the build again of the fingerprint then takes the next free number (H-A-590 (1)).
|
||||
type OtherBytes struct {
|
||||
Seat, Name, Version, Digest, Fingerprint string
|
||||
}
|
||||
|
||||
func (o *OtherBytes) Error() string {
|
||||
w := fmt.Sprintf("%s holds %s %s with other bytes: digest %s", o.Seat, o.Name, o.Version, o.Digest)
|
||||
if o.Fingerprint != "" {
|
||||
w += ", fingerprint " + o.Fingerprint
|
||||
}
|
||||
return w
|
||||
}
|
||||
|
||||
// Publish is one artifact's publish again: what the registry seat's publish takes, without parts.
|
||||
type Publish struct {
|
||||
Seat, Kind, Name, Version, Digest, Fingerprint, Commit, Transfer string
|
||||
@@ -162,9 +191,18 @@ type Republisher struct {
|
||||
// Started is when this run of the builder started: a version whose build ended at or after it is of the live class, one
|
||||
// that ended before it of the start's (H-A-290 (1)). Zero makes every version live.
|
||||
Started time.Time
|
||||
// Unstored is told the first artifact of a reservation a holder refused as not stored, with the reservation as it stood: the
|
||||
// builder builds the key again itself (design 47 H2 H-A-662); nil is told none.
|
||||
Unstored func(ctx context.Context, v ReservedVersion, ref, words string)
|
||||
// AsHeld is told each artifact a holder answered `other-bytes` for the publish's own fingerprint, newly marked published with the held
|
||||
// digest (design 47 H2 H-A-738 (1)): the builder says package-published of it; nil says none.
|
||||
AsHeld func(ctx context.Context, m Marked, digest string)
|
||||
// Ended ends the publish item of a version that never publishes, its reservation withdrawn or taken over (H-A-290 (2));
|
||||
// nil ends none.
|
||||
Ended func(ctx context.Context, module, version string)
|
||||
// Bound is how long one item's send waits on its calls, the setting publish-ack-minutes (design 47 H2 H-A-613 (3), H-A-745); past it
|
||||
// the item is left to be given again, never ended. Zero bounds the send by its context alone.
|
||||
Bound time.Duration
|
||||
|
||||
mu sync.Mutex
|
||||
// lastQueued is the newest time a version was queued at: a clock that has not moved between two versions (a coarse clock,
|
||||
@@ -215,6 +253,8 @@ func NotStanding(v ReservedVersion, found bool) string {
|
||||
return "its reservation stands no more at the version (released, dropped or taken over)"
|
||||
case hasKey(v.Withdrawn, v.Version):
|
||||
return "its reservation was withdrawn"
|
||||
case v.Dropped != nil:
|
||||
return "its publish was dropped by " + v.Dropped.By + ": " + v.Dropped.Why
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -310,6 +350,23 @@ func (r *Republisher) end(ctx context.Context, module, version, why string) {
|
||||
}
|
||||
}
|
||||
|
||||
// The forms of the keys of the state acted (design 47 H2 H-A-720): the marks of an event or an ask acted on, each written with the
|
||||
// lifetime of the setting acted-days, and the release record `released.<module>`, written with none. A key of no form is deleted at
|
||||
// the start.
|
||||
const DefaultActedDays = 30
|
||||
|
||||
var actedMarkForms = []string{EscapeToken("retake:"), EscapeToken("retake-asked:"), EscapeToken("retake-ask:"), EscapeToken("publish:")}
|
||||
|
||||
// ActedFormOf says whether key is a mark (known, with a lifetime) or the release record (known, with none), or of no form.
|
||||
func ActedFormOf(key string) (mark, known bool) {
|
||||
for _, f := range actedMarkForms {
|
||||
if strings.HasPrefix(key, f) {
|
||||
return true, true
|
||||
}
|
||||
}
|
||||
return false, strings.HasPrefix(key, ReleasedKey(""))
|
||||
}
|
||||
|
||||
// ActedKey is the acted key of a subject.
|
||||
func ActedKey(subject string) string { return EscapeToken(subject) }
|
||||
|
||||
@@ -329,7 +386,7 @@ type view struct {
|
||||
|
||||
// queue queues vs newest first, at most max of them (0 is no limit), each artifact to the first holder holdersOf names for
|
||||
// its seat. It answers the versions queued, `<module> <version>`.
|
||||
func (r *Republisher) queue(ctx context.Context, vs []ReservedVersion, holdersOf func(seat string) []string, max int) ([]string, error) {
|
||||
func (r *Republisher) queue(ctx context.Context, vs []ReservedVersion, holdersOf func(seat string) []string, max int, event uint64) ([]string, error) {
|
||||
sort.SliceStable(vs, func(i, j int) bool { return vs[i].At.After(vs[j].At) })
|
||||
var queued []string
|
||||
var errs []error
|
||||
@@ -351,6 +408,7 @@ func (r *Republisher) queue(ctx context.Context, vs []ReservedVersion, holdersOf
|
||||
errs = append(errs, fmt.Errorf("the catalog entry %s of %s %s cannot be read: %w", v.Fingerprint, v.Module, v.Version, err))
|
||||
continue
|
||||
}
|
||||
v = r.fillUpstream(ctx, v, e)
|
||||
byHolder := map[string]map[string]string{}
|
||||
for _, ref := range v.Missing() {
|
||||
if _, no := v.Unstored[ref]; no {
|
||||
@@ -379,7 +437,7 @@ func (r *Republisher) queue(ctx context.Context, vs []ReservedVersion, holdersOf
|
||||
}
|
||||
did := false
|
||||
for holder, arts := range byHolder {
|
||||
ok, err := r.enqueue(ctx, v, holder, arts)
|
||||
ok, err := r.enqueue(ctx, v, holder, arts, event)
|
||||
if err != nil {
|
||||
return queued, err
|
||||
}
|
||||
@@ -394,8 +452,13 @@ func (r *Republisher) queue(ctx context.Context, vs []ReservedVersion, holdersOf
|
||||
|
||||
// enqueue puts one holder's artifacts of a version on the work queue under its message id: not again while the queue holds that
|
||||
// id (its duplicates window), which stands queued, and not past the queue's cap (said as queue full).
|
||||
func (r *Republisher) enqueue(ctx context.Context, v ReservedVersion, holder string, arts map[string]string) (bool, error) {
|
||||
// An event's publish again (event is its stream sequence, not zero) is always of the class again, whenever its build ended
|
||||
// (H-A-613 (1), H-A-620 (1)).
|
||||
func (r *Republisher) enqueue(ctx context.Context, v ReservedVersion, holder string, arts map[string]string, event uint64) (bool, error) {
|
||||
q := QueuedPublish{V: 1, Holder: holder, Module: v.Module, Version: v.Version, Artifacts: arts, Queued: r.queuedAt(), Class: r.classOf(v)}
|
||||
if event > 0 {
|
||||
q.Class, q.Sequence = PublishClassStart, event
|
||||
}
|
||||
dup, err := r.Put(ctx, q)
|
||||
switch {
|
||||
case errors.Is(err, ErrQueueFull):
|
||||
@@ -440,16 +503,26 @@ func (r *Republisher) Republish(ctx context.Context, module, version string) ([]
|
||||
vs = append(vs, v)
|
||||
}
|
||||
}
|
||||
// builder_publish_again asks a dropped publish anew: the drop is cleared in the write before its put (H-A-746).
|
||||
for i := range vs {
|
||||
if vs[i].Dropped == nil {
|
||||
continue
|
||||
}
|
||||
if _, err := r.Reserved.ClearDropped(ctx, vs[i].Module, vs[i].Version); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
vs[i].Dropped = nil
|
||||
}
|
||||
if len(vs) == 0 {
|
||||
return nil, fmt.Errorf("%s holds no reserved version%s with an artifact unpublished", module, map[bool]string{true: " " + version, false: ""}[version != ""])
|
||||
}
|
||||
}
|
||||
return r.queue(ctx, vs, r.holdersFn, 0)
|
||||
return r.queue(ctx, vs, r.holdersFn, 0, 0)
|
||||
}
|
||||
|
||||
// Queued is builder_publish_queue's answer, small at any size of the queue (design 47 H H-A-290 (5)): the queued versions'
|
||||
// count per holder and class with the oldest and newest queue time, the first PublishQueueListCap of them in the order they are
|
||||
// sent (each with its class), the acted keys with their sequences, and the publish items, counted and capped alike.
|
||||
// sent (each with its class) and the acted keys with their sequences, counted and capped alike.
|
||||
type Queued struct {
|
||||
Total int `json:"total"`
|
||||
Counts []QueueCount `json:"counts"`
|
||||
@@ -459,10 +532,6 @@ type Queued struct {
|
||||
// Listed says how many of Total the answer lists.
|
||||
Listed int `json:"listed"`
|
||||
Acted map[string]uint64 `json:"acted"`
|
||||
// ItemCount is how many publish items stand; Items the first of them by their next try (design 47 G A-457a), each with its
|
||||
// tries and its next try; an item that ended says why.
|
||||
ItemCount int `json:"item-count"`
|
||||
Items []PublishItem `json:"items"`
|
||||
// Capped says a state held more than the one page read of it (H-A-293); Read names each such state, the keys read and its
|
||||
// size. Every count above is then of the keys read.
|
||||
Capped bool `json:"capped,omitempty"`
|
||||
@@ -486,27 +555,6 @@ type QueueCount struct {
|
||||
Newest time.Time `json:"newest"`
|
||||
}
|
||||
|
||||
// PublishItemKeyPrefix opens the key of a publish item in the builder's re-ask state.
|
||||
const PublishItemKeyPrefix = "publish."
|
||||
|
||||
// PublishItem is the builder's own record of a version's publish (design 47 G A-457a): a value of the re-ask state, its tries and
|
||||
// its next try. It is asked when the build ends and at the builder's start, rewritten with one more try and a longer pause after
|
||||
// each, and deleted when the version is released; after the setting's number of tries it ends, saying so (Answer), and stays.
|
||||
type PublishItem struct {
|
||||
Module string `json:"module"`
|
||||
Version string `json:"version"`
|
||||
Tries int `json:"tries"`
|
||||
NextTry time.Time `json:"next-try"`
|
||||
Why string `json:"why,omitempty"`
|
||||
Answer string `json:"answer,omitempty"`
|
||||
Answered time.Time `json:"answered,omitzero"`
|
||||
}
|
||||
|
||||
// PublishItemKey is the key of module's version's publish item.
|
||||
func PublishItemKey(module, version string) string {
|
||||
return PublishItemKeyPrefix + EscapeToken(module) + "." + EscapeToken(version)
|
||||
}
|
||||
|
||||
// PublishQueueOf is the seat mesh-builds' verb publish-queue (design 47 H2 §793; H-A-454): the builder's read of its own work queue
|
||||
// publishes (queue, its items read in bulk, capped past its bound), small at any size of the queue (H-A-290 (5)): the items' count
|
||||
// per holder and class with the oldest and newest queue time, and the first PublishQueueListCap in stream order, the order the
|
||||
@@ -574,10 +622,10 @@ func PublishQueueOf(queue Reader, module, version string) (meshbuilds.PublishQue
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// AnswerQueue is builder_publish_queue: the seat mesh-builds' publish-queue answer the builder gave (q, §793, H-A-454) and the two
|
||||
// states as the tools bundle reads them (H-A-290 (5)), each read in bulk (Reader.All), capped at PublishQueueListCap.
|
||||
func AnswerQueue(q meshbuilds.PublishQueueAnswer, acted, reasks Reader) (Queued, error) {
|
||||
out := Queued{Total: int(q.Total), Counts: []QueueCount{}, Queue: []QueuedPublish{}, Listed: int(q.Listed), Acted: map[string]uint64{}, Items: []PublishItem{}}
|
||||
// AnswerQueue is builder_publish_queue: the seat mesh-builds' publish-queue answer the builder gave (q, §793, H-A-454) and the state
|
||||
// acted as the tools bundle reads it (H-A-290 (5)), read in bulk (Reader.All), capped at PublishQueueListCap.
|
||||
func AnswerQueue(q meshbuilds.PublishQueueAnswer, acted Reader) (Queued, error) {
|
||||
out := Queued{Total: int(q.Total), Counts: []QueueCount{}, Queue: []QueuedPublish{}, Listed: int(q.Listed), Acted: map[string]uint64{}}
|
||||
if q.Capped {
|
||||
out.capped(&StateCapped{State: PublishesLocal, KeysRead: int(q.ItemsRead), StateKeys: uint64(q.QueueItems), StateBytes: uint64(q.QueueBytes)})
|
||||
}
|
||||
@@ -598,25 +646,6 @@ func AnswerQueue(q meshbuilds.PublishQueueAnswer, acted, reasks Reader) (Queued,
|
||||
out.Acted[k] = a.Sequence
|
||||
}
|
||||
}
|
||||
rvals, c, err := reasks.values("reasks")
|
||||
out.capped(c)
|
||||
if err != nil {
|
||||
return out, fmt.Errorf("the re-ask state cannot be read: %w", err)
|
||||
}
|
||||
for k, raw := range rvals {
|
||||
if !strings.HasPrefix(k, PublishItemKeyPrefix) {
|
||||
continue
|
||||
}
|
||||
var it PublishItem
|
||||
if json.Unmarshal(raw, &it) == nil {
|
||||
out.Items = append(out.Items, it)
|
||||
}
|
||||
}
|
||||
out.ItemCount = len(out.Items)
|
||||
sort.SliceStable(out.Items, func(i, j int) bool { return out.Items[i].NextTry.Before(out.Items[j].NextTry) })
|
||||
if len(out.Items) > PublishQueueListCap {
|
||||
out.Items = out.Items[:PublishQueueListCap]
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
@@ -625,13 +654,12 @@ const PublishQueueDescription = "The versions the builder will publish again (it
|
||||
"how many each registry seat holder's items hold per class (live, a build a pipeline's step waits on, or again, asked again at a start) " +
|
||||
"with the oldest and newest queue time; the first 50 in stream order, the order each holder's one consumer pulls them, each with its class, its artifacts' digests and when it was " +
|
||||
"queued (module, and version, list only that module's, so one item's class can be read); the keys of the state " + ActedState + ", the last stream " +
|
||||
"sequence the builder acted on for each subject; and the publish items (design 47 G A-457a), counted, the first 50 by next try, each version's " +
|
||||
"tries and next try, and why one ended (its tries spent, or dropped). A read past its pages is answered capped, naming the items read and the " +
|
||||
"sequence the builder acted on for each subject. A read past its pages is answered capped, naming the items read and the " +
|
||||
"queue's size (H-A-293). Read-only."
|
||||
|
||||
// PublishDropDescription is builder_publish_drop's (§793).
|
||||
const PublishDropDescription = "Drop one version's publish (design 47 H2 section 793): its items on the work queue " + PublishesLocal + " are " +
|
||||
"terminated at every holder, and its publish item ended with who dropped it and why, so it is never sent or put again; builder_publish_again " +
|
||||
"terminated at every holder, and its reservation says who dropped it and why, so it is never sent or put again (design 47 H2 H-A-746); builder_publish_again " +
|
||||
"asks it anew. A hand act, recorded in the hand-act log first."
|
||||
|
||||
// PublishAgainDescription is builder_publish_again's description.
|
||||
@@ -687,21 +715,26 @@ func (r *Republisher) MoveQueued(ctx context.Context, vals []json.RawMessage) (i
|
||||
|
||||
// SendFate is what SendQueued did with one item (§793): Sent, every artifact sent (its item acknowledged when its publish is
|
||||
// heard or confirmed); Ended, why the version never publishes (its item terminated); Failed, the holder's or the call's words
|
||||
// (its item handed back with the pause).
|
||||
// (its item ended, the version staying reserved); Unread, why a read of the builder's own state failed or a call was not answered within the bound:
|
||||
// the item is left unacknowledged and given again after the ack wait (design 47 H2 H-A-745, H-A-613 (3)).
|
||||
type SendFate struct {
|
||||
Sent bool
|
||||
Ended, Failed string
|
||||
Sent bool
|
||||
Ended, Failed, Unread string
|
||||
}
|
||||
|
||||
// SendQueued publishes one item's artifacts and says the outcome. Every call it makes honours the one bound it is given,
|
||||
// UnreleasedBound (a context's bound, no timer, ADR 0437 §8), and a send that returns without sending says why (H-A-290 (4)).
|
||||
// SendQueued publishes one item's artifacts and says the outcome. Every call it makes honours the one bound it is given, Bound
|
||||
// (a context's bound, no timer, ADR 0437 §8), and a send that returns without sending says why (H-A-290 (4)). A call not answered
|
||||
// within the bound, or stopped with the builder, leaves the item to be given again (Unread), never ended (H-A-613 (3), H-A-745).
|
||||
func (r *Republisher) SendQueued(ctx context.Context, q QueuedPublish) SendFate {
|
||||
bound, cancel := context.WithTimeout(ctx, UnreleasedBound)
|
||||
bound, cancel := ctx, context.CancelFunc(func() {})
|
||||
if r.Bound > 0 {
|
||||
bound, cancel = context.WithTimeout(ctx, r.Bound)
|
||||
}
|
||||
defer cancel()
|
||||
all, err := r.Reserved.All(bound)
|
||||
if err != nil {
|
||||
r.logf("publish again: %s %s is not sent to %s: its reservation cannot be read: %v; it is handed back", q.Module, q.Version, q.Holder, err)
|
||||
return SendFate{Failed: "its reservation cannot be read: " + err.Error()}
|
||||
r.logf("publish again: %s %s is not sent to %s: its reservation cannot be read: %v; it is given again after the ack wait", q.Module, q.Version, q.Holder, err)
|
||||
return SendFate{Unread: "its reservation cannot be read: " + err.Error()}
|
||||
}
|
||||
var v ReservedVersion
|
||||
found := false
|
||||
@@ -729,9 +762,10 @@ func (r *Republisher) SendQueued(ctx context.Context, q QueuedPublish) SendFate
|
||||
e, err := r.Entry(bound, v.Fingerprint)
|
||||
if err != nil {
|
||||
words := fmt.Sprintf("the catalog entry %s cannot be read: %v", v.Fingerprint, err)
|
||||
r.say(ctx, v, words)
|
||||
return SendFate{Failed: words}
|
||||
r.logf("publish again: %s %s is not sent to %s: %s; it is given again after the ack wait", q.Module, q.Version, q.Holder, words)
|
||||
return SendFate{Unread: words}
|
||||
}
|
||||
v = r.fillUpstream(ctx, v, e)
|
||||
missing := map[string]bool{}
|
||||
for _, ref := range v.Missing() {
|
||||
missing[ref] = true
|
||||
@@ -748,7 +782,7 @@ func (r *Republisher) SendQueued(ctx context.Context, q QueuedPublish) SendFate
|
||||
return SendFate{Ended: "none of its artifacts is left to send: each is published or refused as not stored"}
|
||||
}
|
||||
var failed []string
|
||||
sent := 0
|
||||
sent, held, again := 0, 0, false
|
||||
for _, ref := range refs {
|
||||
seat, name, kind, ok := publishTarget(e, q.Module, ref)
|
||||
if !ok {
|
||||
@@ -762,6 +796,41 @@ func (r *Republisher) SendQueued(ctx context.Context, q QueuedPublish) SendFate
|
||||
sent++
|
||||
continue
|
||||
}
|
||||
var other *OtherBytes
|
||||
if errors.As(err, &other) && other.Fingerprint != "" && other.Fingerprint == v.Fingerprint {
|
||||
// The holder keeps this very build at the version, with the digest of an earlier run of it: the publish is answered as
|
||||
// published with the held digest, nothing stored (H-A-738 (1)).
|
||||
marked, _, merr := r.Reserved.MarkHeld(bound, q.Module, v.Version, []HeldArtifact{{Ref: ref, Seat: other.Seat, Name: other.Name,
|
||||
Version: other.Version, Digest: other.Digest, Fingerprint: other.Fingerprint}})
|
||||
if merr != nil {
|
||||
r.say(ctx, v, ref+": "+merr.Error())
|
||||
failed = append(failed, ref+": "+merr.Error())
|
||||
continue
|
||||
}
|
||||
r.say(ctx, v, fmt.Sprintf("%s %s: %s holds it for this build with the digest %s, built %s: published as held, nothing stored", ref, q.Version, other.Seat, other.Digest, q.Artifacts[ref]))
|
||||
for _, m := range marked {
|
||||
if r.AsHeld != nil {
|
||||
r.AsHeld(ctx, m, other.Digest)
|
||||
}
|
||||
}
|
||||
held++
|
||||
continue
|
||||
}
|
||||
if errors.As(err, &other) {
|
||||
// A version the holder holds with other bytes is never published as it stands (ADR 0605 §4): the item ends at once, spending
|
||||
// no try; the next build of the fingerprint withdraws the number and takes the next free one (H-A-590 (1), H-A-729).
|
||||
words := fmt.Sprintf("%s %s: %s; built %s, so the number is held for another build and is not published again", ref, q.Version, other, q.Artifacts[ref])
|
||||
r.say(ctx, v, words)
|
||||
r.end(ctx, q.Module, q.Version, words)
|
||||
return SendFate{Ended: words}
|
||||
}
|
||||
var unanswered *busretry.Unanswered
|
||||
if bound.Err() != nil || errors.As(err, &unanswered) {
|
||||
// Not answered within the bound, or the builder stopped: no holder refused it, so the item is left, given again after the ack
|
||||
// wait, and the queue's tenth delivery ends it loud (design 47 H2 H-A-613 (3), H-A-745, H-A-653).
|
||||
r.logf("publish again: %s %s: %s is not answered by %s: %v; the item is left, given again after the ack wait", q.Module, q.Version, ref, seat, err)
|
||||
return SendFate{Unread: fmt.Sprintf("%s is not answered by %s: %v", ref, seat, err)}
|
||||
}
|
||||
r.logf("publish again: %s %s: %s refused by %s: %v", q.Module, q.Version, ref, seat, err)
|
||||
words := err.Error()
|
||||
if strings.Contains(words, strings.TrimSuffix(NotStoredWords, ": ")) {
|
||||
@@ -769,6 +838,12 @@ func (r *Republisher) SendQueued(ctx context.Context, q QueuedPublish) SendFate
|
||||
r.logf("%s %s: the unstored %s is not kept: %v", q.Module, q.Version, ref, merr)
|
||||
} else if ok {
|
||||
r.say(ctx, v, ref+" "+NotStoredWords+words)
|
||||
// The first of the reservation's artifacts refused as not stored starts the build again, once per reservation: one
|
||||
// the kept `unstored` already holds starts none (design 47 H2 H-A-662, H-A-703).
|
||||
if len(v.Unstored) == 0 && !again && r.Unstored != nil {
|
||||
again = true
|
||||
r.Unstored(ctx, v, ref, words)
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
@@ -778,12 +853,39 @@ func (r *Republisher) SendQueued(ctx context.Context, q QueuedPublish) SendFate
|
||||
switch {
|
||||
case len(failed) > 0:
|
||||
return SendFate{Failed: strings.Join(failed, "; ")}
|
||||
case sent == 0 && held > 0:
|
||||
return SendFate{Ended: "each artifact left is published as the holder holds it for this build"}
|
||||
case sent == 0:
|
||||
return SendFate{Ended: "each artifact left was refused as not stored"}
|
||||
}
|
||||
return SendFate{Sent: true}
|
||||
}
|
||||
|
||||
// fillUpstream fills the reservation's `upstream` from the catalog entry at its fingerprint, once, by compare-and-set, so every reader
|
||||
// of the reservation agrees which of its artifacts a registry never publishes (design 47 H2 H-A-656, amending H-A-486's addendum);
|
||||
// the reservation as it stands is answered, and a write that fails is said and v answered as it was read.
|
||||
func (r *Republisher) fillUpstream(ctx context.Context, v ReservedVersion, e meshcatalog.CatalogEntry) ReservedVersion {
|
||||
if len(v.Upstream) > 0 {
|
||||
return v
|
||||
}
|
||||
var refs []string
|
||||
for _, a := range e.Artifacts {
|
||||
if _, in := v.Artifacts[a.Ref]; in && a.Kind == "upstream" {
|
||||
refs = append(refs, a.Ref)
|
||||
}
|
||||
}
|
||||
if len(refs) == 0 {
|
||||
return v
|
||||
}
|
||||
got, err := r.Reserved.FillUpstream(ctx, v.Module, v.Version, refs)
|
||||
if err != nil {
|
||||
r.logf("%s %s: its upstream artifacts %v are not written on the reservation: %v", v.Module, v.Version, refs, err)
|
||||
v.Upstream = refs
|
||||
return v
|
||||
}
|
||||
return got
|
||||
}
|
||||
|
||||
// publishTarget is the registry seat, the name and the kind module's artifact ref is published as, from its catalog entry; ok is
|
||||
// false when the entry names no registry seat for it.
|
||||
func publishTarget(e meshcatalog.CatalogEntry, module, ref string) (seat, name, kind string, ok bool) {
|
||||
@@ -843,43 +945,102 @@ func (r *Reserver) MarkUnstored(ctx context.Context, module, version, artifact,
|
||||
}
|
||||
}
|
||||
|
||||
// MarkDropped records on module's reserved version that its publish was dropped by hand, by whom, why and when, written by compare-and-set
|
||||
// (design 47 H2 H-A-746). It answers whether the reservation stands at the version; a version not reserved is no publish to drop.
|
||||
func (r *Reserver) MarkDropped(ctx context.Context, module, version, by, why string, at time.Time) (bool, error) {
|
||||
return r.setDropped(ctx, module, version, &PublishDropped{By: by, Why: why, At: at.UTC()})
|
||||
}
|
||||
|
||||
// ClearDropped clears the drop of module's version: builder_publish_again asks it anew (H-A-746). It answers whether one was cleared.
|
||||
func (r *Reserver) ClearDropped(ctx context.Context, module, version string) (bool, error) {
|
||||
return r.setDropped(ctx, module, version, nil)
|
||||
}
|
||||
|
||||
func (r *Reserver) setDropped(ctx context.Context, module, version string, d *PublishDropped) (bool, error) {
|
||||
series, _, err := SplitVersion(version)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
key := ReservedKey(module, series)
|
||||
for {
|
||||
cur, rev, found, err := r.get(ctx, key)
|
||||
if err != nil || !found || cur.Version != version {
|
||||
return false, err
|
||||
}
|
||||
if d == nil && cur.Dropped == nil {
|
||||
return false, nil
|
||||
}
|
||||
cur.Dropped = d
|
||||
raw, _ := json.Marshal(cur)
|
||||
if _, err := r.Store.Update(ctx, key, raw, rev); errors.Is(err, ErrConflict) {
|
||||
continue
|
||||
} else if err != nil {
|
||||
return false, fmt.Errorf("%s cannot be written: %w", key, err)
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// HeldVersion is one version a registry seat's verb versions answers of a name, with its digest.
|
||||
type HeldVersion struct {
|
||||
Version, Digest string
|
||||
// Fingerprint is the fingerprint the holder keeps for the version (design 47 H2 H-A-589 (3)); empty where none is kept.
|
||||
Fingerprint string
|
||||
}
|
||||
|
||||
// HeldArtifact is an artifact of a reservation as a registry seat's record holds it at the reservation's version: its reference,
|
||||
// the seat and the name it is published as, the version and the digest the seat holds.
|
||||
type HeldArtifact struct {
|
||||
Ref, Seat, Name, Version, Digest string
|
||||
// Fingerprint is the fingerprint the registry keeps for the version, empty where none is kept (design 47 H2 H-A-589 (3)).
|
||||
Fingerprint string
|
||||
}
|
||||
|
||||
// Judged is what the registries' record says of a reserved version's missing artifacts (design 47 H H-A-272, H-A-274, H-A-275):
|
||||
// those held at the version with the built digest (Held), those held at the version with another digest (Elsewhere), and, when an
|
||||
// artifact is held at neither, the first one lacking (Lacks). All says every missing artifact is held with its built digest.
|
||||
// Judged is what the registries' record says of a reserved version's artifacts (design 47 H H-A-272, H-A-274, H-A-275; H2 H-A-588
|
||||
// (4), H-A-616, H-A-663): those held at the version for the reservation's fingerprint (Held, with the digest the registry holds),
|
||||
// those held at the version for another fingerprint or with another digest (Elsewhere), and, when an artifact is held at neither,
|
||||
// the first one lacking (Lacks). All says every artifact is held for the fingerprint.
|
||||
type Judged struct {
|
||||
Held, Elsewhere []HeldArtifact
|
||||
Lacks string
|
||||
All bool
|
||||
}
|
||||
|
||||
// Held judges v's missing artifacts against the registries' record (design 47 H H-A-269 (2), H-A-272, H-A-274, H-A-275): each
|
||||
// artifact's registry seat and name as a publish again sends them, its record read through the seat's verb versions (versionsOf).
|
||||
// A version with no missing artifact is All.
|
||||
// heldFor says whether the registry's record h of an artifact at v's version is held for v's fingerprint (design 47 H2 H-A-616,
|
||||
// H-A-663): a holder that keeps a fingerprint says it, and it is the reservation's or another's; one that keeps none holds it for
|
||||
// the reservation's fingerprint when its digest is the one the reservation records for the artifact (a kept published is such a
|
||||
// record), and elsewhere when the reservation records another digest or none.
|
||||
func heldFor(v ReservedVersion, ref string, h HeldVersion) bool {
|
||||
if h.Fingerprint != "" {
|
||||
return h.Fingerprint == v.Fingerprint
|
||||
}
|
||||
return v.Artifacts[ref] != "" && h.Digest == v.Artifacts[ref]
|
||||
}
|
||||
|
||||
// Held judges every artifact of v against the registries' record (design 47 H H-A-269 (2), H-A-272, H-A-274, H-A-275; H2 H-A-588
|
||||
// (4), H-A-663: an artifact already marked published counts as held when its registry still answers it): each artifact's registry
|
||||
// seat and name as a publish again sends them, its record read through the seat's verb versions (versionsOf). An upstream artifact
|
||||
// is never read. A version with no missing artifact is All.
|
||||
func (r *Republisher) Held(ctx context.Context, v ReservedVersion, versionsOf func(ctx context.Context, seat, name string) ([]HeldVersion, error)) (Judged, error) {
|
||||
missing := v.Missing()
|
||||
if len(missing) == 0 {
|
||||
if len(v.Missing()) == 0 {
|
||||
return Judged{All: true}, nil
|
||||
}
|
||||
e, err := r.Entry(ctx, v.Fingerprint)
|
||||
if err != nil {
|
||||
return Judged{}, fmt.Errorf("the catalog entry %s of %s %s cannot be read: %w", v.Fingerprint, v.Module, v.Version, err)
|
||||
}
|
||||
refs := make([]string, 0, len(v.Artifacts))
|
||||
for ref := range v.Artifacts {
|
||||
if !slices.Contains(v.Upstream, ref) {
|
||||
refs = append(refs, ref)
|
||||
}
|
||||
}
|
||||
sort.Strings(refs)
|
||||
var out Judged
|
||||
for _, ref := range missing {
|
||||
for _, ref := range refs {
|
||||
seat, name, _, ok := publishTarget(e, v.Module, ref)
|
||||
if !ok {
|
||||
if out.Lacks == "" {
|
||||
if out.Lacks == "" && !v.Published[ref] {
|
||||
out.Lacks = ref + ": the catalog entry names no registry seat for it"
|
||||
}
|
||||
continue
|
||||
@@ -888,13 +1049,13 @@ func (r *Republisher) Held(ctx context.Context, v ReservedVersion, versionsOf fu
|
||||
if err != nil {
|
||||
return Judged{}, fmt.Errorf("%s's versions of %s cannot be read: %w", seat, name, err)
|
||||
}
|
||||
at, found := HeldArtifact{}, false
|
||||
at, found, forF := HeldArtifact{}, false, false
|
||||
for _, h := range held {
|
||||
if strings.TrimPrefix(h.Version, "v") != v.Version {
|
||||
continue
|
||||
}
|
||||
at, found = HeldArtifact{Ref: ref, Seat: seat, Name: name, Version: h.Version, Digest: h.Digest}, true
|
||||
if h.Digest == v.Artifacts[ref] {
|
||||
at, found, forF = HeldArtifact{Ref: ref, Seat: seat, Name: name, Version: h.Version, Digest: h.Digest}, true, heldFor(v, ref, h)
|
||||
if forF {
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -903,25 +1064,26 @@ func (r *Republisher) Held(ctx context.Context, v ReservedVersion, versionsOf fu
|
||||
if out.Lacks == "" {
|
||||
out.Lacks = fmt.Sprintf("%s holds no %s %s", seat, name, v.Version)
|
||||
}
|
||||
case at.Digest == v.Artifacts[ref]:
|
||||
case forF:
|
||||
out.Held = append(out.Held, at)
|
||||
default:
|
||||
out.Elsewhere = append(out.Elsewhere, at)
|
||||
}
|
||||
}
|
||||
out.All = len(out.Held) == len(missing)
|
||||
out.All = out.Lacks == "" && len(out.Elsewhere) == 0 && len(out.Held) > 0
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// HeldNumbers are the versions (MAJOR.MINOR.PATCH) a registry seat's record holds of any of module's artifacts refs, as the catalog
|
||||
// entry of fingerprint names their seats and names (design 47 H H-A-275): a number one holds is never reserved. An artifact the
|
||||
// entry names no registry seat for is read nowhere.
|
||||
func (r *Republisher) HeldNumbers(ctx context.Context, module, fingerprint string, refs []string, versionsOf func(ctx context.Context, seat, name string) ([]HeldVersion, error)) ([]string, error) {
|
||||
// HeldRecords are the versions (MAJOR.MINOR.PATCH) a registry seat's record holds of any of module's artifacts refs, as the catalog
|
||||
// entry of fingerprint names their seats and names (design 47 H H-A-275), one record per artifact and version with the digest and the
|
||||
// fingerprint the registry keeps (H2 H-A-590 (1)): a number one holds is never reserved. An artifact the entry names no registry seat
|
||||
// for is read nowhere.
|
||||
func (r *Republisher) HeldRecords(ctx context.Context, module, fingerprint string, refs []string, versionsOf func(ctx context.Context, seat, name string) ([]HeldVersion, error)) ([]HeldArtifact, error) {
|
||||
e, err := r.Entry(ctx, fingerprint)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the catalog entry %s of %s cannot be read: %w", fingerprint, module, err)
|
||||
}
|
||||
var out []string
|
||||
var out []HeldArtifact
|
||||
for _, ref := range refs {
|
||||
seat, name, _, ok := publishTarget(e, module, ref)
|
||||
if !ok {
|
||||
@@ -932,8 +1094,8 @@ func (r *Republisher) HeldNumbers(ctx context.Context, module, fingerprint strin
|
||||
return out, fmt.Errorf("%s's versions of %s cannot be read: %w", seat, name, err)
|
||||
}
|
||||
for _, h := range held {
|
||||
if v := strings.TrimPrefix(h.Version, "v"); v != "" && !slices.Contains(out, v) {
|
||||
out = append(out, v)
|
||||
if v := strings.TrimPrefix(h.Version, "v"); v != "" {
|
||||
out = append(out, HeldArtifact{Ref: ref, Seat: seat, Name: name, Version: v, Digest: h.Digest, Fingerprint: h.Fingerprint})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,11 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-sdk/go/busretry"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatlist"
|
||||
)
|
||||
|
||||
// republishBed is a Republisher over memory states: reservations of module m (a bundle by the oci seat and a Go package by
|
||||
@@ -29,7 +32,8 @@ type republishBed struct {
|
||||
sent []Publish
|
||||
said []string
|
||||
ended []string
|
||||
refuse string // the words Send fails with, empty for none
|
||||
refuse string // the words Send fails with, empty for none
|
||||
other *OtherBytes // the holder's answer of a version held with other bytes (H-A-729)
|
||||
// holders are the registry seats' holders the seat-holders view names (design 47 G A-416).
|
||||
holders map[string][]string
|
||||
// puts are the items the work queue took; window deduplicates by message id; full refuses every put; held keeps the puts
|
||||
@@ -43,7 +47,7 @@ type republishBed struct {
|
||||
func newRepublishBed(t *testing.T) *republishBed {
|
||||
t.Helper()
|
||||
b := &republishBed{reserved: &reserveMem{mem: newMem()}, now: time.Date(2026, 11, 11, 12, 0, 0, 0, time.UTC), ids: map[string]bool{}}
|
||||
res := &Reserver{Store: b.reserved, Now: func() time.Time { return b.now }, ReleasedOf: func(context.Context, string) ([]string, error) { return nil, nil }}
|
||||
res := &Reserver{Store: b.reserved, Bound: testBound, Now: func() time.Time { return b.now }, ReleasedOf: func(context.Context, string) ([]string, error) { return nil, nil }}
|
||||
b.Republisher = &Republisher{Reserved: res, Now: func() time.Time { return b.now },
|
||||
Entry: func(_ context.Context, fp string) (meshcatalog.CatalogEntry, error) {
|
||||
if fp == "src2:holder" {
|
||||
@@ -58,6 +62,9 @@ func newRepublishBed(t *testing.T) *republishBed {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
b.sent = append(b.sent, p)
|
||||
if b.other != nil {
|
||||
return b.other
|
||||
}
|
||||
if b.refuse != "" {
|
||||
return errors.New(b.refuse)
|
||||
}
|
||||
@@ -78,7 +85,7 @@ func newRepublishBed(t *testing.T) *republishBed {
|
||||
if b.full {
|
||||
return false, fmt.Errorf("%w: maximum bytes exceeded", ErrQueueFull)
|
||||
}
|
||||
id := PublishMsgID(q.Holder, q.Class, q.Module, q.Version)
|
||||
id := q.MsgID()
|
||||
if b.window && b.ids[id] {
|
||||
return true, nil
|
||||
}
|
||||
@@ -105,7 +112,7 @@ func (b *republishBed) reserve(t *testing.T, module string) ReservedVersion {
|
||||
if _, _, err := b.Reserved.Built(ctx, module, v.Version, map[string]string{module + ":prog": "sha256:aa", module + ":lib": "sha256:bb"}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b.now = b.now.Add(UnreleasedBound + time.Minute)
|
||||
b.now = b.now.Add(testBound + time.Minute)
|
||||
return v
|
||||
}
|
||||
|
||||
@@ -163,6 +170,66 @@ func TestRepublish(t *testing.T) {
|
||||
t.Errorf("sent %d, said %v: want one try and one saying of not stored", len(b.sent), b.said)
|
||||
}
|
||||
})
|
||||
t.Run("a reservation with no upstream gets it from the entry once", func(t *testing.T) {
|
||||
// design 47 H2 H-A-656: the republisher's read of the entry fills the reservation's upstream by compare-and-set, so the
|
||||
// artifact a registry never publishes is no missing one and no entry "names no registry seat" for it
|
||||
b := newRepublishBed(t)
|
||||
v := b.reserve(t, "m")
|
||||
entry := b.Entry
|
||||
b.Entry = func(ctx context.Context, fp string) (meshcatalog.CatalogEntry, error) {
|
||||
e, err := entry(ctx, fp)
|
||||
e.Artifacts = append(e.Artifacts, meshcatalog.Artifact{Ref: "m:up", Kind: "upstream"})
|
||||
return e, err
|
||||
}
|
||||
if _, _, err := b.Reserved.Built(ctx, "m", v.Version, map[string]string{"m:up": "sha256:cc"}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
|
||||
b.SendQueued(ctx, b.queueAt(v, PublishClassLive, b.now))
|
||||
cur, _, _ := b.Reserved.At(ctx, ReservedKey("m", "0.1"))
|
||||
if !slices.Equal(cur.Upstream, []string{"m:up"}) || slices.Contains(cur.Missing(), "m:up") {
|
||||
t.Errorf("the reservation's upstream is %v, missing %v; want m:up filled once and not missing", cur.Upstream, cur.Missing())
|
||||
}
|
||||
})
|
||||
t.Run("a version held with other bytes ends the item at once, no try spent", func(t *testing.T) {
|
||||
// design 47 H2 H-A-590 (2), H-A-729: never asked again as it stands; the next build of the fingerprint takes another number
|
||||
b := newRepublishBed(t)
|
||||
v := b.reserve(t, "m")
|
||||
b.other = &OtherBytes{Seat: SeatArtifacts, Name: "m/prog", Version: v.Version, Digest: "sha256:zz", Fingerprint: "src2:other"}
|
||||
f := b.SendQueued(ctx, b.queueAt(v, PublishClassLive, b.now))
|
||||
if f.Ended == "" || f.Failed != "" || f.Sent || len(b.sent) != 1 || fmt.Sprint(b.ended) != "[m "+v.Version+"]" || !strings.Contains(f.Ended, "sha256:zz") {
|
||||
t.Errorf("%+v, sent %d, ended %v: want the item ended at once naming the other digest, and no failure to try again", f, len(b.sent), b.ended)
|
||||
}
|
||||
})
|
||||
t.Run("a version held with other bytes for the publish's own fingerprint ends as published with the held digest", func(t *testing.T) {
|
||||
// design 47 H2 H-A-738 (1): equal fingerprints answer as published, nothing stored, the held digest on the reservation
|
||||
b := newRepublishBed(t)
|
||||
v := b.reserve(t, "m")
|
||||
var said []string
|
||||
b.AsHeld = func(_ context.Context, m Marked, digest string) { said = append(said, m.Artifact+" "+digest) }
|
||||
b.other = &OtherBytes{Seat: SeatArtifacts, Name: "m/prog", Version: v.Version, Digest: "sha256:zz", Fingerprint: v.Fingerprint}
|
||||
f := b.SendQueued(ctx, b.queueAt(v, PublishClassLive, b.now))
|
||||
cur, _, _ := b.Reserved.At(ctx, ReservedKey("m", "0.1"))
|
||||
if f.Ended == "" || f.Failed != "" || f.Sent || len(b.ended) != 0 || !cur.Published["m:prog"] || cur.Artifacts["m:prog"] != "sha256:zz" || fmt.Sprint(said) != "[m:prog sha256:zz]" {
|
||||
t.Errorf("%+v, ended %v, published %v, digest %q, said %v: want published with the held digest, said once, no refusal", f, b.ended, cur.Published, cur.Artifacts["m:prog"], said)
|
||||
}
|
||||
})
|
||||
t.Run("the first artifact refused as not stored starts the build again once", func(t *testing.T) {
|
||||
// design 47 H2 H-A-662, H-A-703: one start per reservation, whatever number of its artifacts are refused
|
||||
b := newRepublishBed(t)
|
||||
v := b.reserve(t, "m")
|
||||
var started []string
|
||||
b.Unstored = func(_ context.Context, v ReservedVersion, ref, _ string) {
|
||||
started = append(started, v.Version+" "+ref)
|
||||
}
|
||||
b.refuse = "oci-artifact-registry's publish of m/prog: not stored: no blob sha256:aa"
|
||||
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
|
||||
b.SendQueued(ctx, b.queueAt(v, PublishClassLive, b.now))
|
||||
b.SendQueued(ctx, b.queueAt(v, PublishClassLive, b.now))
|
||||
if len(started) != 1 || started[0] != v.Version+" m:prog" {
|
||||
t.Errorf("the build again was started %v, want once for %s", started, v.Version)
|
||||
}
|
||||
})
|
||||
t.Run("a refusal in other words is said each time", func(t *testing.T) {
|
||||
b := newRepublishBed(t)
|
||||
b.reserve(t, "m")
|
||||
@@ -234,15 +301,6 @@ func TestRepublish(t *testing.T) {
|
||||
}
|
||||
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
|
||||
_, _ = b.Republish(ctx, "", "")
|
||||
items := Reader{Keys: func() ([]string, error) { return []string{"publish.m.0.1.0", "reserve-done.m.x"}, nil },
|
||||
Get: func(k string) (json.RawMessage, bool, error) {
|
||||
return json.RawMessage(`{"mode":"publish","module":"m","version":"0.1.0","tries":3,"next-try":"2026-11-17T01:00:00Z","why":"w"}`), true, nil
|
||||
}}
|
||||
none := Reader{Keys: func() ([]string, error) { return nil, nil }}
|
||||
answer, err := answerOf(none, none, items, "", "")
|
||||
if err != nil || len(answer.Items) != 1 || answer.Items[0].Tries != 3 || answer.Items[0].Version != "0.1.0" {
|
||||
t.Errorf("builder_publish_queue items = %+v (%v), want the one publish item with its tries", answer.Items, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -262,6 +320,11 @@ func TestTheRegistriesRecordSaysWhetherAVersionIsHeld(t *testing.T) {
|
||||
{name: "held in the Go form with the built digest", holds: []HeldVersion{{Version: "v0.1.36", Digest: "sha256:z"}, {Version: "v0.1.37", Digest: "sha256:a"}}, all: true},
|
||||
{name: "another digest at the version", holds: []HeldVersion{{Version: "0.1.37", Digest: "sha256:b"}}, elsewhere: true},
|
||||
{name: "the version lacked", holds: []HeldVersion{{Version: "0.1.36", Digest: "sha256:a"}}, lacks: true},
|
||||
// H2 H-A-616: no fingerprint kept: held for F when the digest is the reserved one, elsewhere with another
|
||||
{name: "no fingerprint kept, the reserved digest", holds: []HeldVersion{{Version: "0.1.37", Digest: "sha256:a"}}, all: true},
|
||||
// H2 H-A-589 (3): a holder that keeps a fingerprint says whose it is, whatever the digest
|
||||
{name: "the fingerprint kept is F's", holds: []HeldVersion{{Version: "0.1.37", Digest: "sha256:b", Fingerprint: "fp"}}, all: true},
|
||||
{name: "the fingerprint kept is another's", holds: []HeldVersion{{Version: "0.1.37", Digest: "sha256:a", Fingerprint: "other"}}, elsewhere: true},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
var seat, name string
|
||||
@@ -273,7 +336,7 @@ func TestTheRegistriesRecordSaysWhetherAVersionIsHeld(t *testing.T) {
|
||||
if c.lacks && !strings.Contains(j.Lacks, "0.1.37") {
|
||||
t.Errorf("what the registry lacks is said as %q", j.Lacks)
|
||||
}
|
||||
nums, err := r.HeldNumbers(ctx, "m", "fp", []string{"m:lib"}, versionsOf)
|
||||
nums, err := r.HeldRecords(ctx, "m", "fp", []string{"m:lib"}, versionsOf)
|
||||
if err != nil || len(nums) != len(c.holds) {
|
||||
t.Errorf("the held numbers are %v (%v), want one per version the seat holds", nums, err)
|
||||
}
|
||||
@@ -283,6 +346,20 @@ func TestTheRegistriesRecordSaysWhetherAVersionIsHeld(t *testing.T) {
|
||||
if j, err := r.Held(ctx, v, nil); err != nil || !j.All {
|
||||
t.Errorf("a version with no missing artifact is judged %+v (%v), want all held without a read", j, err)
|
||||
}
|
||||
// H2 H-A-663: a kept published counts as held while its registry answers it at the version, and no longer when it does not
|
||||
v.Published, v.Artifacts = map[string]bool{"m:lib": true, "m:other": true}, map[string]string{"m:lib": "sha256:a", "m:other": "sha256:o"}
|
||||
v.Upstream = nil
|
||||
entry.Artifacts = append(entry.Artifacts, meshcatalog.Artifact{Ref: "m:other", Kind: "package", Language: "go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "git.example/o"}})
|
||||
v.Published["m:other"] = false
|
||||
both := func(_ context.Context, _, n string) ([]HeldVersion, error) {
|
||||
if n == "git.example/o" {
|
||||
return nil, nil
|
||||
}
|
||||
return []HeldVersion{{Version: "0.1.37", Digest: "sha256:a"}}, nil
|
||||
}
|
||||
if j, err := r.Held(ctx, v, both); err != nil || j.All || len(j.Held) != 1 || j.Held[0].Ref != "m:lib" || !strings.Contains(j.Lacks, "git.example/o") {
|
||||
t.Errorf("a kept published its registry answers is judged %+v (%v), want it held and the other lacking", j, err)
|
||||
}
|
||||
}
|
||||
|
||||
// queueAt writes a queued version of module m at holder oci directly, as a start finds it.
|
||||
@@ -381,12 +458,70 @@ func TestAQueuedItemIsSentWhileItsBuildStands(t *testing.T) {
|
||||
if f := b.SendQueued(ctx, b.queueAt(w, PublishClassLive, b.now)); f.Failed == "" || f.Sent {
|
||||
t.Errorf("a refusal in other words answered %+v, want it failed, handed back", f)
|
||||
}
|
||||
// design 47 H2 H-A-745: a read of the builder's own state that fails is no answer of a holder: nothing is sent or said and the
|
||||
// item is left to be given again, while an answered failure above ended it.
|
||||
x := b.reserve(t, "x")
|
||||
sent, said := len(b.sent), len(b.said)
|
||||
entry := b.Entry
|
||||
b.Entry = func(context.Context, string) (meshcatalog.CatalogEntry, error) {
|
||||
return meshcatalog.CatalogEntry{}, errors.New("the catalog is down")
|
||||
}
|
||||
if f := b.SendQueued(ctx, b.queueAt(x, PublishClassLive, b.now)); f.Unread == "" || f.Failed != "" || f.Ended != "" || f.Sent || len(b.sent) != sent || len(b.said) != said {
|
||||
t.Errorf("an unreadable entry answered %+v, sent %d more, said %d more: want it unread, nothing sent or said", f, len(b.sent)-sent, len(b.said)-said)
|
||||
}
|
||||
b.Entry = entry
|
||||
b.reserved.mem.down = errors.New("the state is down")
|
||||
if f := b.SendQueued(ctx, b.queueAt(x, PublishClassLive, b.now)); f.Unread == "" || f.Failed != "" || f.Ended != "" || f.Sent || len(b.sent) != sent {
|
||||
t.Errorf("an unreadable reservation answered %+v: want it unread", f)
|
||||
}
|
||||
})
|
||||
// design 47 H2 H-A-613 (3), H-A-745: a call not answered within the bound, and one stopped with the builder, is no answer of a holder: the
|
||||
// item is left to be given again, never ended as failed.
|
||||
t.Run("a call not answered within the bound leaves the item to be given again", func(t *testing.T) {
|
||||
b := newRepublishBed(t)
|
||||
v := b.reserve(t, "u")
|
||||
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
|
||||
b.Bound = time.Minute
|
||||
b.Send = func(context.Context, Publish) error {
|
||||
return fmt.Errorf("oci's publish of u: %w", &busretry.Unanswered{Seat: SeatArtifacts, Verb: VerbPublish, Bound: time.Minute, Last: errors.New("no responders")})
|
||||
}
|
||||
if f := b.SendQueued(ctx, b.queueAt(v, PublishClassLive, b.now)); f.Unread == "" || f.Failed != "" || f.Ended != "" || f.Sent {
|
||||
t.Errorf("a call not answered within the bound answered %+v, want it unread, given again", f)
|
||||
}
|
||||
stopped, stop := context.WithCancel(ctx)
|
||||
b.Send = func(c context.Context, _ Publish) error { stop(); return c.Err() }
|
||||
if f := b.SendQueued(stopped, b.queueAt(v, PublishClassLive, b.now)); f.Unread == "" || f.Failed != "" || f.Ended != "" {
|
||||
t.Errorf("a send stopped with the builder answered %+v, want it unread, given again", f)
|
||||
}
|
||||
})
|
||||
// design 47 H2 H-A-746: a publish dropped by hand is kept on its reservation, which its standing reads: an event does not put it,
|
||||
// a send ends it unsent, and builder_publish_again puts it and clears the drop.
|
||||
t.Run("a publish dropped by hand is passed over and asked anew by builder_publish_again", func(t *testing.T) {
|
||||
b := newRepublishBed(t)
|
||||
v := b.reserve(t, "d")
|
||||
b.held = true
|
||||
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
|
||||
if found, err := b.Reserved.MarkDropped(ctx, "d", v.Version, "op@node", "a test drops it", b.now); err != nil || !found {
|
||||
t.Fatalf("drop: %v %v", found, err)
|
||||
}
|
||||
if _, err := b.Republish(ctx, "", ""); err != nil || len(b.puts) != 0 {
|
||||
t.Errorf("an event put %d items (%v), want the dropped version passed over", len(b.puts), err)
|
||||
}
|
||||
if f := b.SendQueued(ctx, b.queueAt(v, PublishClassLive, b.now)); f.Ended == "" || !strings.Contains(f.Ended, "op@node") || len(b.sent) != 0 {
|
||||
t.Errorf("a send of the dropped version answered %+v, sent %d: want it ended unsent, naming who dropped it", f, len(b.sent))
|
||||
}
|
||||
if _, err := b.Republish(ctx, "d", v.Version); err != nil || len(b.puts) != 1 {
|
||||
t.Errorf("builder_publish_again put %d items (%v), want the one", len(b.puts), err)
|
||||
}
|
||||
if cur, ok, err := b.Reserved.Of(ctx, "d", v.Version); err != nil || !ok || cur.Dropped != nil {
|
||||
t.Errorf("after builder_publish_again the reservation is %+v (%v), want its drop cleared", cur, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// answerOf is builder_publish_queue whole: the builder's verb publish-queue over its work queue (queue), then the tool over the
|
||||
// verb's answer and the two states (design 47 H2 §793, H-A-454).
|
||||
func answerOf(queue, acted, reasks Reader, module, version string) (Queued, error) {
|
||||
// verb's answer and the state (design 47 H2 §793, H-A-454).
|
||||
func answerOf(queue, acted Reader, module, version string) (Queued, error) {
|
||||
q, err := PublishQueueOf(queue, module, version)
|
||||
if err != nil {
|
||||
return Queued{}, err
|
||||
@@ -399,7 +534,7 @@ func answerOf(queue, acted, reasks Reader, module, version string) (Queued, erro
|
||||
if err := json.Unmarshal(raw, &heard); err != nil {
|
||||
return Queued{}, err
|
||||
}
|
||||
return AnswerQueue(heard, acted, reasks)
|
||||
return AnswerQueue(heard, acted)
|
||||
}
|
||||
|
||||
// TestThePublishQueueToolAnswersAtAnySize: design 47 H H-A-290 (5) — builder_publish_queue over two thousand queued versions answers
|
||||
@@ -426,7 +561,7 @@ func TestThePublishQueueToolAnswersAtAnySize(t *testing.T) {
|
||||
Get: func(k string) (json.RawMessage, bool, error) { gets++; v, ok := vals[k]; return v, ok, nil }}
|
||||
none := Reader{Keys: func() ([]string, error) { return nil, nil }}
|
||||
start := time.Now()
|
||||
a, err := answerOf(queue, none, none, "", "")
|
||||
a, err := answerOf(queue, none, "", "")
|
||||
took := time.Since(start)
|
||||
raw, _ := json.Marshal(a)
|
||||
if err != nil || took > time.Second || a.Total != 2000 || len(a.Queue) != PublishQueueListCap || a.Listed != PublishQueueListCap || len(raw) > 64<<10 || gets != 0 {
|
||||
@@ -440,7 +575,7 @@ func TestThePublishQueueToolAnswersAtAnySize(t *testing.T) {
|
||||
t.Fatalf("the list holds %s at %d, want m%d: the items in stream order, whatever their holder or class", q.Module, i, i)
|
||||
}
|
||||
}
|
||||
one, err := answerOf(queue, none, none, "m1995", "")
|
||||
one, err := answerOf(queue, none, "m1995", "")
|
||||
if err != nil || len(one.Queue) != 1 || one.Queue[0].Class != PublishClassLive || one.Total != 2000 {
|
||||
t.Errorf("one module's answer %+v (%v), want its item with its class", one.Queue, err)
|
||||
}
|
||||
@@ -448,12 +583,104 @@ func TestThePublishQueueToolAnswersAtAnySize(t *testing.T) {
|
||||
t.Errorf("a state one page holds is answered capped: %+v", a.Read)
|
||||
}
|
||||
queue.All = func() (StatePage, error) { return StatePage{Values: vals, More: true, Keys: 5000, Bytes: 3 << 20}, nil }
|
||||
if c, err := answerOf(queue, none, none, "", ""); err != nil || !c.Capped || len(c.Read) != 1 || c.Read[0].State != PublishesLocal ||
|
||||
if c, err := answerOf(queue, none, "", ""); err != nil || !c.Capped || len(c.Read) != 1 || c.Read[0].State != PublishesLocal ||
|
||||
c.Read[0].KeysRead != 2000 || c.Read[0].StateKeys != 5000 || c.Read[0].StateBytes != 3<<20 || c.Total != 2000 {
|
||||
t.Errorf("a state past its one page answered capped %v, read %+v (%v): want capped, 2000 keys read of 5000, its size said (H-A-293)", c.Capped, c.Read, err)
|
||||
}
|
||||
queue.All = func() (StatePage, error) { return StatePage{}, errors.ErrUnsupported }
|
||||
if b, err := answerOf(queue, none, none, "", ""); err != nil || b.Total != 2000 || gets != 2000 {
|
||||
if b, err := answerOf(queue, none, "", ""); err != nil || b.Total != 2000 || gets != 2000 {
|
||||
t.Errorf("a reader with no bulk read answered %d (%v) with %d single reads, want every key read one by one", b.Total, err, gets)
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 H2 H-A-720: the forms of the keys of the state acted: marks take a lifetime, the release record none, any other key of no
|
||||
// form is deleted at the start.
|
||||
func TestActedKeysHaveForms(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
key string
|
||||
mark, known bool
|
||||
}{
|
||||
{ActedKey("retake:mesh.seat.node-engine.event.running.ace.m"), true, true},
|
||||
{ActedKey("retake-asked:m\x00abc"), true, true},
|
||||
{ActedKey("retake-ask:ask-1"), true, true},
|
||||
{ReleasedKey("m"), false, true},
|
||||
{"junk", false, false},
|
||||
{ActedKey("publish:mesh.seat.node-engine.event.running.ace.oci"), true, true},
|
||||
} {
|
||||
if mark, known := ActedFormOf(c.key); mark != c.mark || known != c.known {
|
||||
t.Errorf("%q: mark %v, known %v, want %v, %v", c.key, mark, known, c.mark, c.known)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestAPublishIsPutAgainOnAHoldersEventsOnceBySequence: design 47 H2 H-A-606 (ADR 0674 §2, §3) — a registry holder's running and a
|
||||
// returned of its node put each unreleased version again, at that holder, once per stream sequence, at most the bound per event, newest
|
||||
// first; a module that holds no registry seat, a stopped running and another node's returned put nothing; a mark is kept for each.
|
||||
func TestAPublishIsPutAgainOnAHoldersEventsOnceBySequence(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
b := newRepublishBed(t)
|
||||
b.window = true
|
||||
b.reserve(t, "m1")
|
||||
b.reserve(t, "m2")
|
||||
b.reserve(t, "m3")
|
||||
acted := &reserveMem{mem: newMem()}
|
||||
a := &Againer{Republisher: b.Republisher, Acted: acted, MaxVersions: 2,
|
||||
Nodes: func(seat string) []seatlist.HolderNode {
|
||||
if seat == SeatArtifacts {
|
||||
return []seatlist.HolderNode{{Module: "holder", Node: "ace"}}
|
||||
}
|
||||
return nil
|
||||
}}
|
||||
running := func(module, fp string, stopped bool) []byte {
|
||||
raw, _ := json.Marshal(nodeengine.Running{Module: module, Node: "ace", Fingerprint: fp, Stopped: stopped})
|
||||
return raw
|
||||
}
|
||||
sub := "mesh.seat.node-engine.event.running.ace."
|
||||
puts := func() []string {
|
||||
var out []string
|
||||
for _, q := range b.puts {
|
||||
out = append(out, q.Holder+" "+q.Module)
|
||||
}
|
||||
return out
|
||||
}
|
||||
if handled, err := a.Heard(ctx, "mesh.seat.node-engine.event.other.ace", nil, 1); handled || err != nil {
|
||||
t.Fatalf("another subject: handled %v, %v", handled, err)
|
||||
}
|
||||
for _, c := range []struct {
|
||||
name, subject string
|
||||
data []byte
|
||||
seq uint64
|
||||
want []string
|
||||
}{
|
||||
{"a module that holds no registry seat", sub + "m1", running("m1", "src2:m1", false), 2, nil},
|
||||
{"a stopped holder", sub + "holder", running("holder", "src2:holder", true), 3, nil},
|
||||
{"the holder's running, two of three versions, newest first", sub + "holder", running("holder", "src2:holder", false), 4, []string{"holder m3", "holder m2"}},
|
||||
{"the same sequence heard again", sub + "holder", running("holder", "src2:holder", false), 4, nil},
|
||||
{"another node's return", "mesh.seat.node-engine.event.manifest-reads-changed.bee", mustJSON(nodeengine.ManifestReadsChanged{Node: "bee", Why: nodeengine.ManifestReadsChangedWhyReturned}), 5, nil},
|
||||
{"a change that is no return", "mesh.seat.node-engine.event.manifest-reads-changed.ace", mustJSON(nodeengine.ManifestReadsChanged{Node: "ace", Why: "changed"}), 6, nil},
|
||||
{"the holder's node returned", "mesh.seat.node-engine.event.manifest-reads-changed.ace", mustJSON(nodeengine.ManifestReadsChanged{Node: "ace", Why: nodeengine.ManifestReadsChangedWhyReturned}), 7, []string{"holder m3", "holder m2"}},
|
||||
} {
|
||||
b.puts, b.ids = nil, map[string]bool{}
|
||||
handled, err := a.Heard(ctx, c.subject, c.data, c.seq)
|
||||
if !handled || err != nil || !slices.Equal(puts(), c.want) {
|
||||
t.Errorf("%s: handled %v, %v, put %v, want %v", c.name, handled, err, puts(), c.want)
|
||||
}
|
||||
// An event's publish again is always of the class again, its message id ending in the event's stream sequence (H-A-613 (1), H-A-620 (1)).
|
||||
for _, q := range b.puts {
|
||||
if id := q.Holder + ".again." + q.Module + "." + EscapeToken(q.Version) + "." + strconv.FormatUint(c.seq, 10); q.Class != PublishClassStart || q.MsgID() != id {
|
||||
t.Errorf("%s: %s %s put as class %q with the id %q, want class again and the id %q", c.name, q.Module, q.Version, q.Class, q.MsgID(), id)
|
||||
}
|
||||
}
|
||||
}
|
||||
if _, _, found, _ := acted.Get(ctx, againKey(sub+"holder")); !found {
|
||||
t.Error("the running's mark is not kept in the state acted")
|
||||
}
|
||||
}
|
||||
|
||||
func mustJSON(v any) []byte {
|
||||
raw, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return raw
|
||||
}
|
||||
|
||||
@@ -31,11 +31,6 @@ const (
|
||||
// ReservedTool is builder_reserved, ReservedDropTool builder_reserved_drop.
|
||||
ReservedTool = "builder_reserved"
|
||||
ReservedDropTool = "builder_reserved_drop"
|
||||
// ReserveDoneTool is builder_reserve_done (design 47 G A-455).
|
||||
ReserveDoneTool = "builder_reserve_done"
|
||||
// UnreleasedBound is the publish's bound: past it a built reservation with an artifact unpublished is the finding
|
||||
// version-unreleased (§369).
|
||||
UnreleasedBound = 10 * time.Minute
|
||||
// VersionUnreleased is that finding.
|
||||
VersionUnreleased = "version-unreleased"
|
||||
// VersionHeldElsewhere is the finding of a number a registry seat already holds, skipped at reserving or moved from (design 47
|
||||
@@ -77,6 +72,9 @@ type ReservedVersion struct {
|
||||
// Unstored are the artifacts a holder refused as not stored, with its words: said once, and not published again on
|
||||
// events (design 47 G §588); builder_build_again builds the key again, which reserves anew.
|
||||
Unstored map[string]string `json:"unstored,omitempty"`
|
||||
// Dropped is who dropped the version's publish by hand (builder_publish_drop), why and when: a fate of the version, read as the
|
||||
// rest of its standing (NotStanding), so no event, item or send passes it; builder_publish_again clears it (design 47 H2 H-A-746).
|
||||
Dropped *PublishDropped `json:"dropped,omitempty"`
|
||||
// Branch and Source are the watched branch and the source revision of the catalog revision whose entry the build came from
|
||||
// (design 47 G §371, A-57): what `package-published` says of the publication.
|
||||
Branch string `json:"branch,omitempty"`
|
||||
@@ -95,6 +93,13 @@ type ReservedVersion struct {
|
||||
Withdrawn map[string]string `json:"withdrawn,omitempty"`
|
||||
}
|
||||
|
||||
// PublishDropped is a publish dropped by hand: who, why and when (design 47 H2 H-A-746).
|
||||
type PublishDropped struct {
|
||||
By string `json:"by"`
|
||||
Why string `json:"why"`
|
||||
At time.Time `json:"at"`
|
||||
}
|
||||
|
||||
// markPublished marks artifact a published at at, the moment the builder heard or confirmed its publish (H-A-331).
|
||||
func (v *ReservedVersion) markPublished(a string, at time.Time) {
|
||||
if v.Published == nil {
|
||||
@@ -143,6 +148,9 @@ type ReserveStore interface {
|
||||
// Reserver reserves versions.
|
||||
type Reserver struct {
|
||||
Store ReserveStore
|
||||
// Bound is the publish's bound, the setting publish-ack-minutes (design 47 H2 H-A-613 (3)): past it a built reservation with an
|
||||
// artifact unpublished is the finding version-unreleased (§369).
|
||||
Bound time.Duration
|
||||
// ReleasedOf are the patch versions (MAJOR.MINOR.PATCH) the catalog holds released for module, from its verb versions.
|
||||
ReleasedOf func(ctx context.Context, module string) ([]string, error)
|
||||
// Took is told when a build took over the series' reservation of an older build never released (design 47 G A-455): the
|
||||
@@ -161,28 +169,46 @@ type Reserver struct {
|
||||
// Logf says an index write that failed (H-A-269 (1)): the reservation stands, and Reindex writes its index at the next
|
||||
// start. Nil says nothing.
|
||||
Logf func(string, ...any)
|
||||
// HeldNumbers are the versions a registry seat's record holds of any of module's artifacts (design 47 H H-A-275), read before a
|
||||
// number is reserved: a number one holds is skipped. Nil reads none; a read that fails is said and the reserve proceeds.
|
||||
HeldNumbers func(ctx context.Context, module, fingerprint string, refs []string) ([]string, error)
|
||||
// HeldRecords are the versions a registry seat's record holds of any of module's artifacts (design 47 H H-A-275), each with the
|
||||
// digest and the fingerprint the registry keeps, read before a number is reserved: a number one holds is skipped, and a
|
||||
// standing reservation whose number one holds for another build is withdrawn (design 47 H2 H-A-590 (1)). Nil reads none; a
|
||||
// read that fails is said and the reserve proceeds.
|
||||
HeldRecords func(ctx context.Context, module, fingerprint string, refs []string) ([]HeldArtifact, error)
|
||||
// HeldElsewhere is told the numbers of module a reserve skipped because a registry holds them (H-A-275); nil is told none.
|
||||
HeldElsewhere func(ctx context.Context, module string, skipped []string)
|
||||
// MovedFrom is told a standing reservation a reserve withdrew because a registry holds an artifact at its number for another
|
||||
// build, with those artifacts (H-A-590 (1), H-A-279); nil is told none.
|
||||
MovedFrom func(ctx context.Context, v ReservedVersion, elsewhere []HeldArtifact)
|
||||
}
|
||||
|
||||
// heldNumbers are the patches of series a registry holds of module's artifacts (H-A-275); a read that fails is said, and none.
|
||||
func (r *Reserver) heldNumbers(ctx context.Context, module, series, fingerprint string, refs []string) map[int]bool {
|
||||
if r.HeldNumbers == nil {
|
||||
return nil
|
||||
// heldNumbers are the patches of series a registry holds of module's artifacts (H-A-275), and the records they come from; a read
|
||||
// that fails is said, and none.
|
||||
func (r *Reserver) heldNumbers(ctx context.Context, module, series, fingerprint string, refs []string) (map[int]bool, []HeldArtifact) {
|
||||
if r.HeldRecords == nil {
|
||||
return nil, nil
|
||||
}
|
||||
vs, err := r.HeldNumbers(ctx, module, fingerprint, refs)
|
||||
recs, err := r.HeldRecords(ctx, module, fingerprint, refs)
|
||||
if err != nil {
|
||||
r.said(fmt.Errorf("%s: the registries' versions are not read before reserving, so a number they hold is not skipped: %w", module, err))
|
||||
}
|
||||
out := map[int]bool{}
|
||||
for _, v := range vs {
|
||||
if s, p, err := SplitVersion(v); err == nil && s == series {
|
||||
for _, h := range recs {
|
||||
if s, p, err := SplitVersion(strings.TrimPrefix(h.Version, "v")); err == nil && s == series {
|
||||
out[p] = true
|
||||
}
|
||||
}
|
||||
return out, recs
|
||||
}
|
||||
|
||||
// heldElsewhereAt are the records of recs at v's number held for another build (design 47 H2 H-A-590 (1), H-A-616): the registry
|
||||
// keeps another fingerprint, or none and the reservation records another digest or none for the artifact.
|
||||
func heldElsewhereAt(v ReservedVersion, recs []HeldArtifact) []HeldArtifact {
|
||||
var out []HeldArtifact
|
||||
for _, h := range recs {
|
||||
if strings.TrimPrefix(h.Version, "v") == v.Version && !heldFor(v, h.Ref, HeldVersion{Version: h.Version, Digest: h.Digest, Fingerprint: h.Fingerprint}) {
|
||||
out = append(out, h)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -243,13 +269,22 @@ func (r *Reserver) Reserve(ctx context.Context, module, series string, artifacts
|
||||
}
|
||||
}
|
||||
key := ReservedKey(module, series)
|
||||
held := r.heldNumbers(ctx, module, series, src.Fingerprint, artifacts)
|
||||
held, records := r.heldNumbers(ctx, module, series, src.Fingerprint, artifacts)
|
||||
for {
|
||||
cur, rev, found, err := r.get(ctx, key)
|
||||
if err != nil {
|
||||
return ReservedVersion{}, err
|
||||
}
|
||||
withdrawn := found && hasKey(cur.Withdrawn, cur.Version) // a number a registry holds elsewhere (H-A-279)
|
||||
// A standing reservation of this fingerprint whose number a registry holds for another build, or for none the reservation
|
||||
// records, is withdrawn now, as the done build's path withdraws it (design 47 H2 H-A-590 (1)); the next number no registry holds
|
||||
// is taken. A read that did not answer left no record: the standing number is kept.
|
||||
var elsewhere []HeldArtifact
|
||||
if found && !withdrawn && cur.Fingerprint == src.Fingerprint && cur.Fingerprint != "" {
|
||||
if elsewhere = heldElsewhereAt(cur, records); len(elsewhere) > 0 {
|
||||
withdrawn = true
|
||||
}
|
||||
}
|
||||
if found && !withdrawn && cur.Fingerprint == src.Fingerprint && cur.Fingerprint != "" && !slices.Contains(released, cur.Version) {
|
||||
if _, p, err := SplitVersion(cur.Version); err == nil && p > high {
|
||||
return cur, nil // kept until released (H-A-225); one at or below the catalog's highest can never be released
|
||||
@@ -270,7 +305,7 @@ func (r *Reserver) Reserve(ctx context.Context, module, series string, artifacts
|
||||
out.Upstream = slices.Clone(src.Upstream)
|
||||
if found {
|
||||
out.Withdrawn = maps.Clone(cur.Withdrawn)
|
||||
if cur.Fingerprint != src.Fingerprint {
|
||||
if cur.Fingerprint != src.Fingerprint || len(elsewhere) > 0 {
|
||||
if out.Withdrawn == nil {
|
||||
out.Withdrawn = map[string]string{}
|
||||
}
|
||||
@@ -301,6 +336,9 @@ func (r *Reserver) Reserve(ctx context.Context, module, series string, artifacts
|
||||
if len(skipped) > 0 && r.HeldElsewhere != nil {
|
||||
r.HeldElsewhere(ctx, module, skipped)
|
||||
}
|
||||
if len(elsewhere) > 0 && r.MovedFrom != nil {
|
||||
r.MovedFrom(ctx, cur, elsewhere)
|
||||
}
|
||||
if found && r.Took != nil {
|
||||
r.Took(ctx, cur, out)
|
||||
}
|
||||
@@ -416,6 +454,91 @@ func allSet(m map[string]string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// MarkHeld writes on module's reservation of version each artifact a registry holds at the version for the reservation's
|
||||
// fingerprint, with the held digest, and marks it published when it was not, in one compare-and-set; in the same write each
|
||||
// artifact that is neither held nor marked published loses its recorded digest and the reservation its built-at, since what
|
||||
// the registries do not hold is built again (design 47 H2 H-A-588 (4), H-A-664; unstored is kept). It answers the artifacts it
|
||||
// newly marked, and false when the reservation stands at another version.
|
||||
func (r *Reserver) MarkHeld(ctx context.Context, module, version string, held []HeldArtifact) ([]Marked, bool, error) {
|
||||
series, _, err := SplitVersion(version)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
key := ReservedKey(module, series)
|
||||
for {
|
||||
cur, rev, found, err := r.get(ctx, key)
|
||||
if err != nil || !found || cur.Version != version {
|
||||
return nil, false, err
|
||||
}
|
||||
was := cur
|
||||
was.Artifacts, was.Published, was.PublishedAt = maps.Clone(cur.Artifacts), maps.Clone(cur.Published), maps.Clone(cur.PublishedAt)
|
||||
var marked []Marked
|
||||
changed := false
|
||||
if cur.Artifacts == nil {
|
||||
cur.Artifacts = map[string]string{}
|
||||
}
|
||||
isHeld := map[string]bool{}
|
||||
for _, h := range held {
|
||||
isHeld[h.Ref] = true
|
||||
if cur.Artifacts[h.Ref] != h.Digest {
|
||||
cur.Artifacts[h.Ref], changed = h.Digest, true
|
||||
}
|
||||
if !cur.Published[h.Ref] {
|
||||
cur.markPublished(h.Ref, r.now())
|
||||
marked, changed = append(marked, Marked{Artifact: h.Ref}), true
|
||||
}
|
||||
}
|
||||
for ref, d := range cur.Artifacts {
|
||||
if d != "" && !isHeld[ref] && !cur.Published[ref] && !slices.Contains(cur.Upstream, ref) {
|
||||
cur.Artifacts[ref], changed = "", true
|
||||
}
|
||||
}
|
||||
if !cur.BuiltAt.IsZero() && !allSet(cur.Artifacts) {
|
||||
cur.BuiltAt, changed = time.Time{}, true
|
||||
}
|
||||
if !changed {
|
||||
return nil, true, nil
|
||||
}
|
||||
raw, _ := json.Marshal(cur)
|
||||
if _, err := r.Store.Update(ctx, key, raw, rev); errors.Is(err, ErrConflict) {
|
||||
continue
|
||||
} else if err != nil {
|
||||
return nil, false, fmt.Errorf("%s cannot be written: %w", key, err)
|
||||
}
|
||||
r.said(r.reindex(ctx, key, was, cur))
|
||||
for i := range marked {
|
||||
marked[i].Reserved = cur
|
||||
}
|
||||
return marked, true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// FillUpstream writes the artifacts of kind upstream on module's reservation of version when it names none, once, by
|
||||
// compare-and-set (design 47 H2 H-A-656); it answers the reservation as it stands (one that names some, or stands at another
|
||||
// version, is answered unchanged).
|
||||
func (r *Reserver) FillUpstream(ctx context.Context, module, version string, refs []string) (ReservedVersion, error) {
|
||||
series, _, err := SplitVersion(version)
|
||||
if err != nil {
|
||||
return ReservedVersion{}, err
|
||||
}
|
||||
key := ReservedKey(module, series)
|
||||
for {
|
||||
cur, rev, found, err := r.get(ctx, key)
|
||||
if err != nil || !found || cur.Version != version || len(cur.Upstream) > 0 {
|
||||
return cur, err
|
||||
}
|
||||
cur.Upstream = slices.Clone(refs)
|
||||
sort.Strings(cur.Upstream)
|
||||
raw, _ := json.Marshal(cur)
|
||||
if _, err := r.Store.Update(ctx, key, raw, rev); errors.Is(err, ErrConflict) {
|
||||
continue
|
||||
} else if err != nil {
|
||||
return ReservedVersion{}, fmt.Errorf("%s cannot be written: %w", key, err)
|
||||
}
|
||||
return cur, nil
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultReleasedKept is the setting released-kept unless set (design 47 G A-456b).
|
||||
const DefaultReleasedKept = 16
|
||||
|
||||
@@ -510,47 +633,6 @@ func (r *Reserver) PublishedOf(ctx context.Context, module, artifact, fingerprin
|
||||
return meshbuilds.PublishedAnswer{Published: false}, nil
|
||||
}
|
||||
|
||||
// VersionAt answers the version artifact of module is published at from the source revision of branch (design 47 H2 H-A-547
|
||||
// (3), H-A-551): the standing reservation of that branch and source revision whose artifact a registry seat said published, its
|
||||
// number not withdrawn, first; else the module's release recorded at that branch and source revision (H-A-558 (2)), the newest such. A reservation of
|
||||
// that origin not yet published answers none, so the importer's build waits for the publish (H-A-521).
|
||||
func (r *Reserver) VersionAt(ctx context.Context, module, artifact, branch string, source int64) (string, bool, error) {
|
||||
if module == "" || artifact == "" || source <= 0 {
|
||||
return "", false, nil
|
||||
}
|
||||
ref := module + ":" + artifact
|
||||
keys, err := r.Store.KeysOf(ctx, NameFilter(module))
|
||||
if err != nil {
|
||||
return "", false, fmt.Errorf("the reservations of %s cannot be listed: %w", module, err)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
for _, k := range keys {
|
||||
cur, _, found, err := r.get(ctx, k)
|
||||
if err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
if found && cur.Module == module && cur.Branch == branch && cur.Source == source && cur.Published[ref] && !hasKey(cur.Withdrawn, cur.Version) {
|
||||
return cur.Version, true, nil
|
||||
}
|
||||
}
|
||||
if r.Releases == nil {
|
||||
return "", false, nil
|
||||
}
|
||||
raw, _, found, err := r.Releases.Get(ctx, ReleasedKey(module))
|
||||
if err != nil {
|
||||
return "", false, fmt.Errorf("the releases of %s cannot be read: %w", module, err)
|
||||
}
|
||||
var rec ReleasedRecord
|
||||
if found && json.Unmarshal(raw, &rec) == nil {
|
||||
for i := len(rec.Kept) - 1; i >= 0; i-- {
|
||||
if rec.Kept[i].Branch == branch && rec.Kept[i].Source == source {
|
||||
return rec.Kept[i].Version, true, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", false, nil
|
||||
}
|
||||
|
||||
// keepRelease adds a release to the module's record, dropping the oldest past ReleasedKept.
|
||||
func (r *Reserver) keepRelease(ctx context.Context, module, fingerprint, version string, digests, withdrawn map[string]string, branch string, source int64) error {
|
||||
n := r.ReleasedKept
|
||||
@@ -636,7 +718,7 @@ func (r *Reserver) Released(ctx context.Context, module, version string) ([]stri
|
||||
return gone, nil
|
||||
}
|
||||
|
||||
// Unreleased are the reservations whose build ended more than UnreleasedBound before now with an artifact unpublished:
|
||||
// Unreleased are the reservations whose build ended more than Reserver.Bound before now with an artifact unpublished:
|
||||
// the finding version-unreleased, naming the module, the version and the artifacts missing (published says whether an
|
||||
// artifact is). A reservation whose build has not ended is not one.
|
||||
type Unreleased struct {
|
||||
@@ -657,7 +739,7 @@ func (r *Reserver) Overdue(ctx context.Context, published func(module, version,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !found || cur.BuiltAt.IsZero() || r.now().Sub(cur.BuiltAt) < UnreleasedBound {
|
||||
if !found || cur.BuiltAt.IsZero() || r.now().Sub(cur.BuiltAt) < r.Bound {
|
||||
continue
|
||||
}
|
||||
var missing []string
|
||||
@@ -767,7 +849,7 @@ type Marked struct {
|
||||
func (m Marked) PackagePublished(digest string, at time.Time) meshbuilds.PackagePublished {
|
||||
at = at.UTC()
|
||||
return meshbuilds.PackagePublished{V: 1, Artifact: m.Artifact, At: &at, Branch: m.Reserved.Branch, Source: m.Reserved.Source, Revision: m.Reserved.Revision, Module: m.Reserved.Module,
|
||||
Version: m.Reserved.Version, Digest: digest, Dependencies: m.Reserved.Dependencies[m.Artifact]}
|
||||
Version: m.Reserved.Version, Digest: digest, Fingerprint: m.Reserved.Fingerprint, Dependencies: m.Reserved.Dependencies[m.Artifact]}
|
||||
}
|
||||
|
||||
// Published takes a registry seat's published in, as PublishedRead does, answering the artifacts newly marked and the keys it is
|
||||
@@ -1128,11 +1210,10 @@ const (
|
||||
"the version its build reserved at its start, each artifact's digest once built, when the build ended and which artifacts a registry " +
|
||||
"seat said published. With module, that module's only. A key goes when the catalog says version-released for it. Read-only."
|
||||
ReservedDropDescription = "Drop a module's reservation of one MAJOR.MINOR by hand (design 47 G section 369), when its version will never be " +
|
||||
"released; the next build takes the next after the highest released. A hand act: it is recorded in the hand-act log."
|
||||
ReserveDoneDescription = "Reserve a version for a done trunk build that reserved none (design 47 G A-455): given module and fp, the next version " +
|
||||
"of the series is reserved for that fingerprint with the digests of the build's artifacts, and its publish is queued as builder_publish_again " +
|
||||
"queues it; builds nothing. For a done key that cannot be built again. Refused when the key is not done, is no first watched branch's, or " +
|
||||
"holds a reservation already. A hand act: it is recorded in the hand-act log."
|
||||
"released; given module, series and the version it stands at (version, as builder_reserved shows it). Refused when the key holds another version " +
|
||||
"(it names the one that stands) and while the reservation's fingerprint is building. It forgets the key whole (the version, its fingerprint, the " +
|
||||
"artifacts' recorded digests, its withdrawn numbers), its publish item and its version-unreleased, and the answer names what it forgot; what the " +
|
||||
"registries hold at the version stays, a gap the next reserve skips. A hand act: it is recorded in the hand-act log."
|
||||
// ReservedVerb is the seat mesh-builds' verb served as a tool of the same name.
|
||||
ReservedVerb = meshbuilds.VerbReserved
|
||||
)
|
||||
|
||||
@@ -39,7 +39,7 @@ func TestReservation(t *testing.T) {
|
||||
now := time.Date(2026, 11, 11, 12, 0, 0, 0, time.UTC)
|
||||
released := []string{"0.1.18", "0.1.19", "0.2.7"}
|
||||
store := &reserveMem{mem: newMem()}
|
||||
r := &Reserver{Store: store, Now: func() time.Time { return now },
|
||||
r := &Reserver{Store: store, Bound: testBound, Now: func() time.Time { return now },
|
||||
ReleasedOf: func(context.Context, string) ([]string, error) { return released, nil }}
|
||||
arts := []string{"m:a", "m:b"}
|
||||
|
||||
@@ -83,7 +83,7 @@ func TestReservation(t *testing.T) {
|
||||
if got, _ := r.Overdue(ctx, published); len(got) != 0 {
|
||||
t.Fatalf("unreleased before the bound: %v", got)
|
||||
}
|
||||
now = now.Add(UnreleasedBound)
|
||||
now = now.Add(testBound)
|
||||
got, err := r.Overdue(ctx, published)
|
||||
want := []Unreleased{{Module: "m", Version: "0.1.23", Missing: []string{"m:b"}}}
|
||||
if err != nil || !reflect.DeepEqual(got, want) {
|
||||
@@ -112,7 +112,7 @@ func TestReservationIsReadAndMarkedPublished(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
store := &reserveMem{mem: newMem()}
|
||||
r := &Reserver{Store: store, ReleasedOf: func(context.Context, string) ([]string, error) { return []string{"1.4.2"}, nil }}
|
||||
v, err := r.Reserve(ctx, "m", "1.4", []string{"m:a", "m:b"}, Source{Branch: "main", Revision: 41, CatalogRevision: 44})
|
||||
v, err := r.Reserve(ctx, "m", "1.4", []string{"m:a", "m:b"}, Source{Branch: "main", Revision: 41, CatalogRevision: 44, Fingerprint: "src2:f"})
|
||||
if err != nil || v.Version != "1.4.3" {
|
||||
t.Fatalf("reserved %q (%v), want 1.4.3", v.Version, err)
|
||||
}
|
||||
@@ -146,7 +146,7 @@ func TestReservationIsReadAndMarkedPublished(t *testing.T) {
|
||||
at := time.Unix(100, 0)
|
||||
said := marked[0].PackagePublished("sha256:aa", at)
|
||||
atUTC := at.UTC()
|
||||
if wantSaid := (meshbuilds.PackagePublished{V: 1, Artifact: "m:a", At: &atUTC, Branch: "main", Source: 41, Revision: 44, Module: "m", Version: "1.4.3", Digest: "sha256:aa", Dependencies: deps}); !reflect.DeepEqual(said, wantSaid) {
|
||||
if wantSaid := (meshbuilds.PackagePublished{V: 1, Artifact: "m:a", At: &atUTC, Branch: "main", Source: 41, Revision: 44, Module: "m", Version: "1.4.3", Digest: "sha256:aa", Fingerprint: "src2:f", Dependencies: deps}); !reflect.DeepEqual(said, wantSaid) {
|
||||
t.Errorf("package-published = %+v, want %+v", said, wantSaid)
|
||||
}
|
||||
if marked, _, _ := r.Published(ctx, "m-a", "1.4.3", "sha256:other"); len(marked) != 0 {
|
||||
@@ -174,6 +174,36 @@ func TestReservationIsReadAndMarkedPublished(t *testing.T) {
|
||||
if key, ok := ReservedBoundOf(ReservedBoundKey("m", "1.4")); !ok || key != ReservedKey("m", "1.4") || ReservedBoundFor(key) != ReservedBoundKey("m", "1.4") {
|
||||
t.Errorf("the bound key does not name the reservation back: %q %v", key, ok)
|
||||
}
|
||||
// Design 47 H2 H-A-588 (4): MarkHeld writes the digest a registry holds on the reservation and marks the artifact published, once.
|
||||
held := []HeldArtifact{{Ref: "m:b", Digest: "sha256:held"}}
|
||||
markedHeld, ok, err := r.MarkHeld(ctx, "m", "1.4.3", held)
|
||||
cur, _, _ = r.At(ctx, ReservedKey("m", "1.4"))
|
||||
if err != nil || !ok || len(markedHeld) != 1 || cur.Artifacts["m:b"] != "sha256:held" || !cur.Published["m:b"] || cur.Artifacts["m:a"] != "sha256:aa" || cur.PublishedAt["m:b"].IsZero() {
|
||||
t.Fatalf("marked %v (%v, %v), reservation %+v: want m:b with the held digest, published, m:a as it was", markedHeld, ok, err, cur)
|
||||
}
|
||||
if again, ok, err := r.MarkHeld(ctx, "m", "1.4.3", held); err != nil || !ok || len(again) != 0 {
|
||||
t.Errorf("a second marking marked %v (%v, %v), want none: package-published is said once", again, ok, err)
|
||||
}
|
||||
if _, ok, _ := r.MarkHeld(ctx, "m", "1.4.99", held); ok {
|
||||
t.Error("a reservation at another version was marked")
|
||||
}
|
||||
// H-A-664: in the same write what no registry holds loses its recorded digest and the reservation its built-at; unstored is kept
|
||||
nv, err := r.Reserve(ctx, "n", "0.1", []string{"n:a", "n:b"}, Source{Fingerprint: "fpn"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, _, err := r.Built(ctx, "n", nv.Version, map[string]string{"n:a": "sha256:a", "n:b": "sha256:b"}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := r.MarkUnstored(ctx, "n", nv.Version, "n:b", "not stored: no blob"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, _, err := r.MarkHeld(ctx, "n", nv.Version, []HeldArtifact{{Ref: "n:a", Digest: "sha256:a"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cur, _, _ = r.At(ctx, ReservedKey("n", "0.1")); cur.Artifacts["n:b"] != "" || cur.Artifacts["n:a"] != "sha256:a" || !cur.BuiltAt.IsZero() || cur.Unstored["n:b"] == "" || !cur.Published["n:a"] {
|
||||
t.Errorf("after the marking %+v: want n:b's digest and the built-at cleared, n:a held, unstored kept", cur)
|
||||
}
|
||||
}
|
||||
|
||||
// TestAReleaseIsRecordedByFingerprintBeforeItsReservationGoes: design 47 G A-456a — the version-released of a version records
|
||||
@@ -202,44 +232,19 @@ func TestAReleaseIsRecordedByFingerprintBeforeItsReservationGoes(t *testing.T) {
|
||||
if all, _ := r.All(ctx); len(all) != 0 {
|
||||
t.Errorf("reservations left: %v", all)
|
||||
}
|
||||
// Design 47 H2 H-A-547 (3), H-A-551: an importer's version at the source revision of its key's origin is the standing
|
||||
// reservation of that origin once its artifact is published, then the release recorded at that source revision.
|
||||
w, err := r.Reserve(ctx, "m", "0.1", []string{"m:a"}, Source{Fingerprint: "src2:cc", Branch: "main", Revision: 41})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
at := func(branch string, source int64) string {
|
||||
v, found, err := r.VersionAt(ctx, "m", "a", branch, source)
|
||||
if err != nil || found != (v != "") {
|
||||
t.Fatalf("VersionAt %s.%d: %q %v %v", branch, source, v, found, err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
if v := at("main", 41); v != "" {
|
||||
t.Errorf("a reservation not yet published answers %q, want none", v)
|
||||
}
|
||||
if _, _, err := r.Built(ctx, "m", w.Version, map[string]string{"m:a": "sha256:cc"}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, _, err := r.Published(ctx, "m/a", w.Version, "sha256:cc"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if v := at("main", 41); v != w.Version {
|
||||
t.Errorf("the published reservation at main.41 answers %q, want %s", v, w.Version)
|
||||
}
|
||||
if v, v2 := at("main", 40), at("feat", 41); v != "" || v2 != "" {
|
||||
t.Errorf("another source revision or branch answers %q %q, want none", v, v2)
|
||||
}
|
||||
if _, err := r.Released(ctx, "m", w.Version); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if v := at("main", 41); v != w.Version {
|
||||
t.Errorf("once released, main.41 answers %q, want %s from the release's record", v, w.Version)
|
||||
}
|
||||
// H-A-558 (2): the record keeps the origin's branch with its source revision, so another branch's equal number never meets it.
|
||||
if v := at("feat", 41); v != "" {
|
||||
t.Errorf("once released, feat.41 answers %q, want none", v)
|
||||
}
|
||||
// One key per module holds the last releases, the oldest dropped (A-456b).
|
||||
for _, fp := range []string{"src2:b1", "src2:b2"} {
|
||||
n, err := r.Reserve(ctx, "m", "0.1", []string{"m:a"}, Source{Fingerprint: fp})
|
||||
@@ -451,11 +456,15 @@ func TestANumberARegistryHoldsIsNeverReserved(t *testing.T) {
|
||||
var readErr error
|
||||
var skipped []string
|
||||
r := &Reserver{Store: store, ReleasedOf: func(context.Context, string) ([]string, error) { return []string{"0.1.36"}, nil },
|
||||
HeldNumbers: func(_ context.Context, module, fp string, refs []string) ([]string, error) {
|
||||
HeldRecords: func(_ context.Context, module, fp string, refs []string) ([]HeldArtifact, error) {
|
||||
if module != "node-tools" || fp != "fp1" || len(refs) != 1 {
|
||||
t.Errorf("the registries are read for %s %s %v", module, fp, refs)
|
||||
}
|
||||
return held, readErr
|
||||
var out []HeldArtifact
|
||||
for _, v := range held {
|
||||
out = append(out, HeldArtifact{Ref: "node-tools:program", Version: v})
|
||||
}
|
||||
return out, readErr
|
||||
},
|
||||
HeldElsewhere: func(_ context.Context, _ string, s []string) { skipped = append(skipped, s...) }}
|
||||
v, err := r.Reserve(ctx, "node-tools", "0.1", []string{"node-tools:program"}, Source{Fingerprint: "fp1", Repository: "o/r", Commit: "c1"})
|
||||
@@ -487,4 +496,67 @@ func TestANumberARegistryHoldsIsNeverReserved(t *testing.T) {
|
||||
if v, err := r.Reserve(ctx, "node-tools", "0.2", []string{"node-tools:program"}, Source{Fingerprint: "fp1"}); err != nil || v.Version != "0.2.1" {
|
||||
t.Errorf("with the registry down reserved %q (%v), want 0.2.1 (what it answered still skipped)", v.Version, err)
|
||||
}
|
||||
// H2 H-A-590 (1), H-A-616: a build again of F keeps F's standing number unless a registry holds an artifact at it for another
|
||||
// build: the registry keeps another fingerprint, or none and another digest; one with the reserved digest, or F's own
|
||||
// fingerprint, keeps it.
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
held HeldArtifact
|
||||
wantMoved bool
|
||||
}{
|
||||
{name: "another fingerprint kept", held: HeldArtifact{Digest: "sha256:mine", Fingerprint: "other"}, wantMoved: true},
|
||||
{name: "no fingerprint, another digest", held: HeldArtifact{Digest: "sha256:theirs"}, wantMoved: true},
|
||||
{name: "no fingerprint, the reserved digest", held: HeldArtifact{Digest: "sha256:mine"}},
|
||||
{name: "F's own fingerprint", held: HeldArtifact{Digest: "sha256:mine", Fingerprint: "fp9"}},
|
||||
} {
|
||||
st := &reserveMem{mem: newMem()}
|
||||
var told []HeldArtifact
|
||||
rr := &Reserver{Store: st, ReleasedOf: func(context.Context, string) ([]string, error) { return nil, nil }}
|
||||
first, err := rr.Reserve(ctx, "m", "0.3", []string{"m:a"}, Source{Fingerprint: "fp9"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, _, err := rr.Built(ctx, "m", first.Version, map[string]string{"m:a": "sha256:mine"}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c.held.Ref, c.held.Version, c.held.Seat = "m:a", first.Version, SeatArtifacts
|
||||
rr.HeldRecords = func(context.Context, string, string, []string) ([]HeldArtifact, error) {
|
||||
return []HeldArtifact{c.held}, nil
|
||||
}
|
||||
rr.MovedFrom = func(_ context.Context, _ ReservedVersion, e []HeldArtifact) { told = e }
|
||||
again, err := rr.Reserve(ctx, "m", "0.3", []string{"m:a"}, Source{Fingerprint: "fp9", Rebuild: true})
|
||||
if err != nil || (again.Version != first.Version) != c.wantMoved || (again.Withdrawn[first.Version] == "fp9") != c.wantMoved || (len(told) == 1) != c.wantMoved {
|
||||
t.Errorf("%s: the build again reserved %+v (%v), told %v; want the number %s %s", c.name, again, err, told, first.Version, map[bool]string{true: "withdrawn and the next taken", false: "kept"}[c.wantMoved])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// testBound is the publish bound the tests set, the setting publish-ack-minutes at its default.
|
||||
const testBound = 10 * time.Minute
|
||||
|
||||
// TestOverdueTakesTheSettingsBound: design 47 H2 H-A-613 (3): the finding version-unreleased is timed by the setting
|
||||
// publish-ack-minutes, whatever its value, not by a constant of 10 minutes.
|
||||
func TestOverdueTakesTheSettingsBound(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
now := time.Date(2026, 11, 25, 12, 0, 0, 0, time.UTC)
|
||||
r := &Reserver{Store: &reserveMem{mem: newMem()}, Bound: 30 * time.Minute, Now: func() time.Time { return now },
|
||||
ReleasedOf: func(context.Context, string) ([]string, error) { return nil, nil }}
|
||||
v, err := r.Reserve(ctx, "m", "0.1", []string{"m:a"}, Source{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, _, err := r.Built(ctx, "m", v.Version, map[string]string{"m:a": "sha256:a"}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, c := range []struct {
|
||||
after time.Duration
|
||||
want int
|
||||
}{{15 * time.Minute, 0}, {29 * time.Minute, 0}, {30 * time.Minute, 1}} {
|
||||
cur := time.Date(2026, 11, 25, 12, 0, 0, 0, time.UTC).Add(c.after)
|
||||
now = cur
|
||||
got, err := r.Overdue(ctx, func(_, _, _ string) bool { return false })
|
||||
if err != nil || len(got) != c.want {
|
||||
t.Errorf("%v after the build with the bound at 30 minutes: %v (%v), want %d findings", c.after, got, err, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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: "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, KeyTTL: true, MaxMiB: 4}, {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
|
||||
@@ -184,7 +184,7 @@ func TestManifestDeclarations(t *testing.T) { // 1607/AC1
|
||||
}
|
||||
// 1945: the builder's tools (builder_seat_queue: note 62), served by its tools bundle, and the event it says when it asks an ask again.
|
||||
if want := []string{"build_current", "builder_announce_again", "builder_ask_again", "builder_ask_drop", "builder_asks", "builder_bounds", "builder_build", "builder_build_again", "builder_builds_since", "builder_engine_reads", "builder_first_view_again", "builder_first_views",
|
||||
"builder_health", "builder_old_form", "builder_publish_again", "builder_publish_queue", "builder_release", "builder_reserve_done", "builder_reserved", "builder_reserved_drop", "builder_seat_list", "builder_seat_list_again", "builder_seat_queue", "builder_stuck", "builder_toolchains", "builder_toolchains_drop", "builder_unbuildable", "builder_versions", "builder_waits"}; !reflect.DeepEqual(sorted(m.Tools), want) {
|
||||
"builder_health", "builder_old_form", "builder_publish_again", "builder_publish_queue", "builder_release", "builder_reserved", "builder_reserved_drop", "builder_seat_list", "builder_seat_list_again", "builder_seat_queue", "builder_stuck", "builder_toolchains", "builder_toolchains_drop", "builder_unbuildable", "builder_versions", "builder_waits"}; !reflect.DeepEqual(sorted(m.Tools), want) {
|
||||
t.Errorf("tools = %v, want %v", m.Tools, want)
|
||||
}
|
||||
// Design 47 G §672: the toolchain waits' stream, kept 7 days within 16 MiB, and the bound's setting, 60 minutes.
|
||||
@@ -198,7 +198,8 @@ func TestManifestDeclarations(t *testing.T) { // 1607/AC1
|
||||
m.Streams[3].Duplicates != 24 || m.Streams[3].MaxDeliveries != 10 || m.Streams[3].MaxAgeDays != 7 || m.Streams[3].MaxMiB != 64 {
|
||||
t.Errorf("streams = %+v, want waits with wait-held.** and wait-ended.**, 7 days, 16 MiB, the builds' stream (build.ended.**, 7 days, kept last per subject: design 47 G A-181) and the findings' stream", m.Streams)
|
||||
}
|
||||
if c, ok := m.Config["toolchain-wait-minutes"]; !ok || c.Default != float64(60) || len(m.Config) != 13 ||
|
||||
if c, ok := m.Config["toolchain-wait-minutes"]; !ok || c.Default != float64(60) || len(m.Config) != 13 || m.Config["acted-days"].Default != float64(30) || m.Config["acted-days"].Maximum != 365 || // H-A-720 (1)
|
||||
|
||||
// design 47 H2 §775, H-A-381 (2): the kept-call pace and the taken key's bound, read by the process
|
||||
m.Config["kept-call-pace-first"].Default != "1s" || m.Config["kept-call-pace-max"].Default != "30s" || m.Config["ask-taken-bound"].Default != "10m" ||
|
||||
!m.Config["kept-call-pace-first"].Runtime || !m.Config["kept-call-pace-max"].Runtime || !m.Config["ask-taken-bound"].Runtime ||
|
||||
@@ -207,8 +208,9 @@ func TestManifestDeclarations(t *testing.T) { // 1607/AC1
|
||||
m.Config["revision-wait-minutes"].Default != float64(2) || m.Config["package-wait-minutes"].Default != float64(10) ||
|
||||
// H-A-492: the record of a version's digests runs under the builder's own bound, a setting of 60 s by default
|
||||
m.Config["record-bound-seconds"].Default != float64(60) ||
|
||||
m.Config["publish-pause"].Default != float64(30) || m.Config["publish-pause-max"].Default != float64(30) || m.Config["publish-tries"].Default != float64(5) || m.Config["publish-tries"].Maximum != 10 {
|
||||
t.Errorf("config = %+v, want toolchain-wait-minutes of 60, revision-wait-minutes of 2 (H-A-156), package-wait-minutes of 10 (H-A-165), record-bound-seconds of 60 (H-A-492), the publish settings 30 s, 30 min and 5 tries, at most 10 (design 47 G §588, §633, A-457a; H2 H-A-446 (2))", m.Config)
|
||||
m.Config["republish-max-versions"].Default != float64(50) || m.Config["publish-ack-minutes"].Default != float64(10) || // H-A-606: no pause, maximum or tries of a publish
|
||||
m.Config["publish-pause"].Default != nil || m.Config["publish-pause-max"].Default != nil || m.Config["publish-tries"].Default != nil {
|
||||
t.Errorf("config = %+v, want toolchain-wait-minutes of 60, revision-wait-minutes of 2 (H-A-156), package-wait-minutes of 10 (H-A-165), record-bound-seconds of 60 (H-A-492), republish-max-versions of 50 and publish-ack-minutes of 10, and no pause, maximum or tries of a publish (design 47 G §588, §633; H2 H-A-606, H-A-613 (3))", m.Config)
|
||||
}
|
||||
// Design 47 G §349: version.numbered is no longer said; old-form-closed on the family version, apart from the builds' ends.
|
||||
if want := []string{"build.asked-again", "version.old-form-closed"}; !reflect.DeepEqual(m.Emits, want) {
|
||||
@@ -267,7 +269,7 @@ func TestManifestProcess(t *testing.T) { // 1607/AC1
|
||||
t.Errorf("health = %v, want kind unit alone", p["health"])
|
||||
}
|
||||
env, _ := p["env"].(map[string]any)
|
||||
if len(env) != 9 || env["MESH_BUILDER_RECORD_BOUND_FILE"] != "${dir:state}/record-bound-seconds" || env["MESH_BUILDER_REVISION_WAIT_FILE"] != "${dir:state}/revision-wait-minutes" || env["MESH_BUILDER_PACKAGE_WAIT_FILE"] != "${dir:state}/package-wait-minutes" || env["MESH_BUILDER_PUBLISH_TRIES_FILE"] != "${dir:state}/publish-tries" || env["MESH_BROKER_FILE"] != "${dir:state}/broker" || env["MESH_BUILDER_TOOLCHAIN_WAIT_FILE"] != "${dir:state}/toolchain-wait-minutes" {
|
||||
if len(env) != 9 || env["MESH_BUILDER_RECORD_BOUND_FILE"] != "${dir:state}/record-bound-seconds" || env["MESH_BUILDER_REVISION_WAIT_FILE"] != "${dir:state}/revision-wait-minutes" || env["MESH_BUILDER_PACKAGE_WAIT_FILE"] != "${dir:state}/package-wait-minutes" || env["MESH_BUILDER_PUBLISH_ACK_FILE"] != "${dir:state}/publish-ack-minutes" || env["MESH_BUILDER_REPUBLISH_MAX_FILE"] != "${dir:state}/republish-max-versions" || env["MESH_BROKER_FILE"] != "${dir:state}/broker" || env["MESH_BUILDER_TOOLCHAIN_WAIT_FILE"] != "${dir:state}/toolchain-wait-minutes" {
|
||||
t.Errorf("env = %v, want the broker file and the path of the toolchain wait's file, never the setting itself (design 47 G §672, A-71)", p["env"])
|
||||
}
|
||||
for k, v := range env {
|
||||
@@ -350,6 +352,16 @@ func TestServesNoRequestSubjectAndHoldsNoTicker(t *testing.T) { // 1607/AC6 (ADR
|
||||
if (f == "Subscribe(" || f == "time.NewTicker") && filepath.ToSlash(path) == "cmd/mesh-delivery-builder/stepqueue.go" {
|
||||
continue
|
||||
}
|
||||
// Design 47 H2 H-A-654: the publishes' dispatch takes the step queue's shape, bound again on the consumer's created and
|
||||
// deleted advisories: the same one kind of subscription.
|
||||
// Design 47 H2 H-A-613 (3): a publish item is marked in progress while its call waits, at the kept call's pace (the
|
||||
// queue's own cadence, as the step queue's), so the bus gives it again only when the builder itself stopped.
|
||||
if f == "time.NewTicker" && filepath.ToSlash(path) == "cmd/mesh-delivery-builder/publishitem.go" {
|
||||
continue
|
||||
}
|
||||
if f == "Subscribe(" && filepath.ToSlash(path) == "cmd/mesh-delivery-builder/publishitem.go" {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(string(src), f) {
|
||||
t.Errorf("%s holds %s: the builder serves no request subject but its seat's verbs and accepted kinds (A-107) and holds no timer", path, f)
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
"builder_reserved",
|
||||
"builder_release",
|
||||
"builder_reserved_drop",
|
||||
"builder_reserve_done",
|
||||
"builder_seat_queue",
|
||||
"builder_stuck",
|
||||
"builder_toolchains",
|
||||
@@ -136,7 +135,7 @@
|
||||
{ "name": "toolchains-heard", "history": 1, "max-mib": 8 },
|
||||
{ "name": "waits", "history": 1, "max-mib": 4 },
|
||||
{ "name": "reserved", "history": 1, "max-mib": 8 },
|
||||
{ "name": "acted", "history": 1, "max-mib": 1 },
|
||||
{ "name": "acted", "history": 1, "key-ttl": true, "max-mib": 4 },
|
||||
{ "name": "asked", "history": 1, "max-mib": 8 },
|
||||
{ "name": "reasks", "history": 1, "max-mib": 8 },
|
||||
{ "name": "first-views", "history": 1, "max-mib": 8 },
|
||||
@@ -217,19 +216,11 @@
|
||||
"default": "5m",
|
||||
"runtime": true
|
||||
},
|
||||
"publish-pause": {
|
||||
"acted-days": {
|
||||
"type": "number",
|
||||
"description": "seconds before a version's second publish try, doubled per try up to publish-pause-max (design 47 G A-457a).",
|
||||
"description": "how many days a mark of an event or an ask acted on (state acted) is kept after its last write; the mark outlives every delivery of its event by far (design 47 H2 H-A-720).",
|
||||
"minimum": 1,
|
||||
"maximum": 3600,
|
||||
"trusted": false,
|
||||
"default": 30
|
||||
},
|
||||
"publish-pause-max": {
|
||||
"type": "number",
|
||||
"description": "minutes, the most a pause between a version's publish tries grows to (design 47 G A-457a).",
|
||||
"minimum": 1,
|
||||
"maximum": 1440,
|
||||
"maximum": 365,
|
||||
"trusted": false,
|
||||
"default": 30
|
||||
},
|
||||
@@ -241,13 +232,21 @@
|
||||
"trusted": false,
|
||||
"default": 16
|
||||
},
|
||||
"publish-tries": {
|
||||
"republish-max-versions": {
|
||||
"type": "number",
|
||||
"description": "how many times the builder tries a done build's publish before it ends loudly (log and condition) and leaves it readable in builder_publish_queue, at most 10, the work queue publishes' max-deliveries (design 47 G A-457a; H2 H-A-446 (2)).",
|
||||
"description": "the most versions one event of a registry seat's holder (its running, or the return of its node) puts on the work queue publishes, newest first (design 47 G section 633, H2 H-A-606).",
|
||||
"minimum": 1,
|
||||
"maximum": 10,
|
||||
"maximum": 10000,
|
||||
"trusted": false,
|
||||
"default": 5
|
||||
"default": 50
|
||||
},
|
||||
"publish-ack-minutes": {
|
||||
"type": "number",
|
||||
"description": "minutes a sent publish waits for its published before the work queue gives it again, the publish bound (design 47 G section 369, H2 H-A-613 (3)).",
|
||||
"minimum": 1,
|
||||
"maximum": 1440,
|
||||
"trusted": false,
|
||||
"default": 10
|
||||
}
|
||||
},
|
||||
"logs": [
|
||||
@@ -318,20 +317,12 @@
|
||||
"content": "${config:record-bound-seconds}"
|
||||
},
|
||||
{
|
||||
"id": "publish-pause",
|
||||
"id": "acted-days",
|
||||
"type": "file",
|
||||
"path": "${dir:state}/publish-pause",
|
||||
"path": "${dir:state}/acted-days",
|
||||
"owner": "mesh-delivery-builder",
|
||||
"mode": "0600",
|
||||
"content": "${config:publish-pause}"
|
||||
},
|
||||
{
|
||||
"id": "publish-pause-max",
|
||||
"type": "file",
|
||||
"path": "${dir:state}/publish-pause-max",
|
||||
"owner": "mesh-delivery-builder",
|
||||
"mode": "0600",
|
||||
"content": "${config:publish-pause-max}"
|
||||
"content": "${config:acted-days}"
|
||||
},
|
||||
{
|
||||
"id": "released-kept",
|
||||
@@ -342,12 +333,20 @@
|
||||
"content": "${config:released-kept}"
|
||||
},
|
||||
{
|
||||
"id": "publish-tries",
|
||||
"id": "republish-max",
|
||||
"type": "file",
|
||||
"path": "${dir:state}/publish-tries",
|
||||
"path": "${dir:state}/republish-max-versions",
|
||||
"owner": "mesh-delivery-builder",
|
||||
"mode": "0600",
|
||||
"content": "${config:publish-tries}"
|
||||
"content": "${config:republish-max-versions}"
|
||||
},
|
||||
{
|
||||
"id": "publish-ack",
|
||||
"type": "file",
|
||||
"path": "${dir:state}/publish-ack-minutes",
|
||||
"owner": "mesh-delivery-builder",
|
||||
"mode": "0600",
|
||||
"content": "${config:publish-ack-minutes}"
|
||||
},
|
||||
{
|
||||
"id": "builder",
|
||||
@@ -369,9 +368,9 @@
|
||||
"MESH_BUILDER_REVISION_WAIT_FILE": "${dir:state}/revision-wait-minutes",
|
||||
"MESH_BUILDER_PACKAGE_WAIT_FILE": "${dir:state}/package-wait-minutes",
|
||||
"MESH_BUILDER_RECORD_BOUND_FILE": "${dir:state}/record-bound-seconds",
|
||||
"MESH_BUILDER_PUBLISH_PAUSE_FILE": "${dir:state}/publish-pause",
|
||||
"MESH_BUILDER_PUBLISH_PAUSE_MAX_FILE": "${dir:state}/publish-pause-max",
|
||||
"MESH_BUILDER_PUBLISH_TRIES_FILE": "${dir:state}/publish-tries",
|
||||
"MESH_BUILDER_REPUBLISH_MAX_FILE": "${dir:state}/republish-max-versions",
|
||||
"MESH_BUILDER_PUBLISH_ACK_FILE": "${dir:state}/publish-ack-minutes",
|
||||
"MESH_BUILDER_ACTED_DAYS_FILE": "${dir:state}/acted-days",
|
||||
"MESH_BUILDER_RELEASED_KEPT_FILE": "${dir:state}/released-kept"
|
||||
},
|
||||
"user": "mesh-delivery-builder",
|
||||
|
||||
@@ -44,7 +44,11 @@ func Publish(ctx context.Context, call Call, in seat.PublishInput, ps []parts.Pa
|
||||
if err := json.Unmarshal(raw, &a); err != nil {
|
||||
return parts.Opened{}, fmt.Errorf("%s's answer to publish: %w", seat.Seat, err)
|
||||
}
|
||||
return parts.Opened{Held: a.Held, Lacks: a.Lacks}, nil
|
||||
opened := parts.Opened{Held: a.Held, Lacks: a.Lacks}
|
||||
if a.OtherBytes != nil {
|
||||
opened.Other = &parts.Other{Digest: a.OtherBytes.Digest, Fingerprint: a.OtherBytes.Fingerprint}
|
||||
}
|
||||
return opened, nil
|
||||
}
|
||||
chunk := func(_ context.Context, part string, sequence int, last bool, data []byte) error {
|
||||
raw, err := call("seat:"+seat.Seat+"."+seat.VerbPublishPart, seat.PublishPartInput{Transfer: in.Transfer, Part: part,
|
||||
|
||||
@@ -44,7 +44,11 @@ func Publish(ctx context.Context, call Call, in seat.PublishInput, ps []parts.Pa
|
||||
if err := json.Unmarshal(raw, &a); err != nil {
|
||||
return parts.Opened{}, fmt.Errorf("%s's answer to publish: %w", seat.Seat, err)
|
||||
}
|
||||
return parts.Opened{Held: a.Held, Lacks: a.Lacks}, nil
|
||||
opened := parts.Opened{Held: a.Held, Lacks: a.Lacks}
|
||||
if a.OtherBytes != nil {
|
||||
opened.Other = &parts.Other{Digest: a.OtherBytes.Digest, Fingerprint: a.OtherBytes.Fingerprint}
|
||||
}
|
||||
return opened, nil
|
||||
}
|
||||
chunk := func(_ context.Context, part string, sequence int, last bool, data []byte) error {
|
||||
raw, err := call("seat:"+seat.Seat+"."+seat.VerbPublishPart, seat.PublishPartInput{Transfer: in.Transfer, Part: part,
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/sourcebranches"
|
||||
"git.novox.be/novox/mesh-sdk/go/busretry"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatlist"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
)
|
||||
|
||||
@@ -403,6 +404,7 @@ func TestSeatHoldersFollowsTheClaimantOfTheAssignerSeat(t *testing.T) {
|
||||
t.Fatalf("holders = %v, want %s", got, want)
|
||||
}
|
||||
}
|
||||
nodes := b.SeatHolderNodes(ctx) // the same followed view, each holder with its node (design 47 H2 H-A-742)
|
||||
main, _ := w.get("mesh-catalog.catalog-revisions.main")
|
||||
seats.mu.Lock()
|
||||
seats.trunk = claims(1, "asg-a")
|
||||
@@ -411,6 +413,9 @@ func TestSeatHoldersFollowsTheClaimantOfTheAssignerSeat(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
answered("asg-a", "node-tools")
|
||||
if got := nodes("node-tool-runner"); !slices.Equal(got, []seatlist.HolderNode{{Module: "node-tools", Node: "anchor"}}) {
|
||||
t.Fatalf("holder nodes = %v, want node-tools on anchor", got)
|
||||
}
|
||||
seats.mu.Lock()
|
||||
seats.trunk = claims(2, "asg-b")
|
||||
seats.mu.Unlock()
|
||||
|
||||
@@ -108,13 +108,15 @@ func WireCatalog(r *views.Reader, call Call, branch string, changed func(module
|
||||
|
||||
// WireCatalogProcess is WireCatalog for a process's views.ProcessReader: its picture
|
||||
// (`mesh-catalog_catalog-revisions.<branch>`) reads the half as a read-only bucket, and the seat's event catalog-revision
|
||||
// on the module's durable consumer goes to Hear.
|
||||
func WireCatalogProcess(r *views.ProcessReader, call Call, branch string, changed func(module string, entry json.RawMessage, deleted bool, at time.Time)) (*Catalog, *views.Picture, error) {
|
||||
// on the module's durable consumer goes to Hear. held is told each revision the view takes in whole, whether or not an entry
|
||||
// changed, as Catalog.Held is (design 47 H2 H-A-747); it is set before the first ask. A nil held tells nothing.
|
||||
func WireCatalogProcess(r *views.ProcessReader, call Call, branch string, changed func(module string, entry json.RawMessage, deleted bool, at time.Time), held func(seat.CatalogRevision)) (*Catalog, *views.Picture, error) {
|
||||
c, err := NewCatalog(call, branch)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
c.Follower.Changed = changed
|
||||
c.Held = held
|
||||
p, err := r.Adopt(c.Follower, seat.Seat, seat.EventCatalogRevision, c.Hear)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
||||
@@ -99,25 +99,43 @@ type seatHolders struct {
|
||||
// follows the new one's (§532); with no claimant it keeps what it has. Nothing is asked on a timer. The part's manifest consumes
|
||||
// `seat:mesh-module-assigner.views.seat-holders`. A Wiring that follows no plain view answers no holders, said in the log.
|
||||
func (b *Branches) SeatHolders(ctx context.Context) func(seat string) []string {
|
||||
sh := &seatHolders{kick: make(chan struct{}, 1)}
|
||||
b.holders.Store(sh)
|
||||
fw, ok := b.w.(viewFollowing)
|
||||
if !ok {
|
||||
b.logf("meshcatalogclient: this part's reader follows no plain view, so no seat's holders are known")
|
||||
} else {
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-sh.kick:
|
||||
}
|
||||
b.refollow(sh, fw)
|
||||
return seatlist.HoldersIn(b.followHolders(ctx))
|
||||
}
|
||||
|
||||
// SeatHolderNodes is SeatHolders answering each holder of a seat with its module and its node, over the same followed view's values
|
||||
// through seatlist.HolderNodesIn, so no module reads the view's keys itself (design 47 H2 H-A-742). It follows the view as
|
||||
// SeatHolders does: a part calls one of them, or both, and the view is followed once.
|
||||
func (b *Branches) SeatHolderNodes(ctx context.Context) func(seat string) []seatlist.HolderNode {
|
||||
return seatlist.HolderNodesIn(b.followHolders(ctx))
|
||||
}
|
||||
|
||||
// followHolders starts the follow of the claimant's seat-holders view, once, and is the view's values as it holds them now.
|
||||
func (b *Branches) followHolders(ctx context.Context) func() (map[string]json.RawMessage, error) {
|
||||
sh := b.holders.Load()
|
||||
if sh == nil {
|
||||
sh = &seatHolders{kick: make(chan struct{}, 1)}
|
||||
if !b.holders.CompareAndSwap(nil, sh) {
|
||||
sh = b.holders.Load()
|
||||
} else {
|
||||
fw, ok := b.w.(viewFollowing)
|
||||
if !ok {
|
||||
b.logf("meshcatalogclient: this part's reader follows no plain view, so no seat's holders are known")
|
||||
} else {
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-sh.kick:
|
||||
}
|
||||
b.refollow(sh, fw)
|
||||
}
|
||||
}()
|
||||
sh.changed()
|
||||
}
|
||||
}()
|
||||
sh.changed()
|
||||
}
|
||||
}
|
||||
return seatlist.HoldersIn(func() (map[string]json.RawMessage, error) {
|
||||
return func() (map[string]json.RawMessage, error) {
|
||||
sh.mu.Lock()
|
||||
values := sh.values
|
||||
sh.mu.Unlock()
|
||||
@@ -125,7 +143,7 @@ func (b *Branches) SeatHolders(ctx context.Context) func(seat string) []string {
|
||||
return nil, nil
|
||||
}
|
||||
return values(), nil
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// changed asks the follow to read the claimant again, without blocking the caller (a view's change is told under its lock).
|
||||
|
||||
@@ -105,3 +105,35 @@ func StepEnded(data []byte) (seat.StepEndedEvent, error) {
|
||||
}
|
||||
return e, nil
|
||||
}
|
||||
|
||||
// MoverAdded decodes a mover-added body, refusing one that names none or more than one of from, caller and take-in
|
||||
// (design 47 H2 H-A-594 (4), H-A-609 (3), H-A-645).
|
||||
func MoverAdded(data []byte) (seat.MoverAddedEvent, error) {
|
||||
var e seat.MoverAddedEvent
|
||||
if err := json.Unmarshal(data, &e); err != nil {
|
||||
return e, fmt.Errorf("meshpipelinerunnerclient: mover-added: %w", err)
|
||||
}
|
||||
named := 0
|
||||
for _, set := range []bool{e.From != "", e.Caller != "", e.TakeIn != 0} {
|
||||
if set {
|
||||
named++
|
||||
}
|
||||
}
|
||||
if named != 1 {
|
||||
return e, fmt.Errorf("meshpipelinerunnerclient: mover-added names exactly one of from, caller and take-in, not %d", named)
|
||||
}
|
||||
return e, nil
|
||||
}
|
||||
|
||||
// PlaceUnfinished decodes the input of place-unfinished, refusing one that names none or both of key and all
|
||||
// (design 47 H2 H-A-644).
|
||||
func PlaceUnfinished(data []byte) (seat.PlaceUnfinishedInput, error) {
|
||||
var in seat.PlaceUnfinishedInput
|
||||
if err := json.Unmarshal(data, &in); err != nil {
|
||||
return in, fmt.Errorf("meshpipelinerunnerclient: place-unfinished: %w", err)
|
||||
}
|
||||
if in.All == (in.Key != "") {
|
||||
return in, fmt.Errorf("meshpipelinerunnerclient: place-unfinished names exactly one of key and all")
|
||||
}
|
||||
return in, nil
|
||||
}
|
||||
|
||||
@@ -51,4 +51,23 @@ func TestSubjectsAndBodies(t *testing.T) {
|
||||
if e, err := StepEnded([]byte(`{"v":1,"pipeline":"main.3589","module":"nats","branch":"main","commit":"c1","result":{"step":"validate","status":"required","outcome":"passed"}}`)); err != nil || e.Result.Step != "validate" {
|
||||
t.Errorf("step-ended: %+v, %v", e, err)
|
||||
}
|
||||
// design 47 H2 H-A-645, H-A-644: a mover-added names exactly one of from, caller and take-in; place-unfinished exactly one of key and all.
|
||||
base := `"fingerprint":"fp","module":"m","pipeline":"main.1","revision":1`
|
||||
for _, c := range []struct {
|
||||
given string
|
||||
ok bool
|
||||
}{{`{` + base + `,"from":"main.0"}`, true}, {`{` + base + `,"caller":"x"}`, true}, {`{` + base + `,"take-in":2}`, true},
|
||||
{`{` + base + `}`, false}, {`{` + base + `,"from":"main.0","take-in":2}`, false}, {`{` + base + `,"caller":"x","from":"main.0","take-in":2}`, false}} {
|
||||
if _, err := MoverAdded([]byte(c.given)); (err == nil) != c.ok {
|
||||
t.Errorf("mover-added %s: %v, want ok %v", c.given, err, c.ok)
|
||||
}
|
||||
}
|
||||
for _, c := range []struct {
|
||||
given string
|
||||
ok bool
|
||||
}{{`{"key":"main.m","why":"x"}`, true}, {`{"all":true,"why":"x"}`, true}, {`{"why":"x"}`, false}, {`{"all":true,"key":"main.m","why":"x"}`, false}} {
|
||||
if _, err := PlaceUnfinished([]byte(c.given)); (err == nil) != c.ok {
|
||||
t.Errorf("place-unfinished %s: %v, want ok %v", c.given, err, c.ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,20 @@ const RevertLive = seat.WantsByWantNodeModuleValueRevertLive
|
||||
// want:version: it awaits its hand placement (design 47 H §772, H-A-73). Beside a put it is the one held want.
|
||||
const HoldAwaitsHandPlacement = "awaits-hand-placement"
|
||||
|
||||
// HoldAwaitsReadsPrefix begins the words of a want the assigner holds for a reader capability the node's node-engine does
|
||||
// not state, followed by the missing capabilities (design 47 H2 H-A-682 (2), H-A-706 (DMC-14)).
|
||||
const HoldAwaitsReadsPrefix = "awaits-reads:"
|
||||
|
||||
// HoldAwaitsEntryPrefix begins the words of a want the assigner holds until the catalog entry of its fingerprint is read,
|
||||
// followed by the fingerprint (design 47 H2 H-A-698 (2), H-A-706 (DMC-14)).
|
||||
const HoldAwaitsEntryPrefix = "awaits-entry:"
|
||||
|
||||
// holdWords says whether words are a held want's other than a put's: awaiting its hand placement, or beginning with one of
|
||||
// the two prefixes.
|
||||
func holdWords(words string) bool {
|
||||
return words == HoldAwaitsHandPlacement || strings.HasPrefix(words, HoldAwaitsReadsPrefix) || strings.HasPrefix(words, HoldAwaitsEntryPrefix)
|
||||
}
|
||||
|
||||
// NodeWord is the last part of a node's own key.
|
||||
const NodeWord = "node"
|
||||
|
||||
@@ -182,8 +196,8 @@ func checkWant(w Want) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if w.Hold && !w.Put && w.Words != HoldAwaitsHandPlacement {
|
||||
return fmt.Errorf("wants: only a put, or a want awaiting its hand placement (%s), holds a want", HoldAwaitsHandPlacement)
|
||||
if w.Hold && !w.Put && !holdWords(w.Words) {
|
||||
return fmt.Errorf("wants: only a put, or a want awaiting its hand placement (%s), its reads (%s) or its entry (%s), holds a want", HoldAwaitsHandPlacement, HoldAwaitsReadsPrefix, HoldAwaitsEntryPrefix)
|
||||
}
|
||||
if err := checkFingerprint(w.Fp, "a want's fingerprint"); err != nil {
|
||||
return err
|
||||
|
||||
@@ -45,6 +45,9 @@ func TestWantsAreWhatTheEarlierCodecWrote(t *testing.T) {
|
||||
"a placement's build": {Want{Fp: a, Version: "0.1.14"}, `{"v":1,"fp":"` + a + `","version":"0.1.14"}`},
|
||||
// design 47 H §772, H-A-73: a node whose node-engine reads no want by version is held, awaiting its hand placement.
|
||||
"awaits its hand placement": {Want{Fp: a, Version: "0.1.15", Pipeline: "main.3589", Rank: 1, Hold: true, Words: HoldAwaitsHandPlacement}, `{"v":1,"fp":"` + a + `","version":"0.1.15","pipeline":"main.3589","rank":1,"hold":true,"words":"awaits-hand-placement"}`},
|
||||
// design 47 H2 H-A-682 (2), H-A-698 (2), H-A-706 (DMC-14): held for a reader capability the engine does not state, or for an entry not read yet.
|
||||
"awaits its reads": {Want{Fp: a, Version: "0.1.15", Hold: true, Words: HoldAwaitsReadsPrefix + "directory-contents-owner"}, `{"v":1,"fp":"` + a + `","version":"0.1.15","hold":true,"words":"awaits-reads:directory-contents-owner"}`},
|
||||
"awaits its entry": {Want{Fp: a, Version: "0.1.15", Hold: true, Words: HoldAwaitsEntryPrefix + a}, `{"v":1,"fp":"` + a + `","version":"0.1.15","hold":true,"words":"awaits-entry:` + a + `"}`},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
raw, err := EncodeWant(row.w)
|
||||
|
||||
@@ -44,7 +44,11 @@ func Publish(ctx context.Context, call Call, in seat.PublishInput, ps []parts.Pa
|
||||
if err := json.Unmarshal(raw, &a); err != nil {
|
||||
return parts.Opened{}, fmt.Errorf("%s's answer to publish: %w", seat.Seat, err)
|
||||
}
|
||||
return parts.Opened{Held: a.Held, Lacks: a.Lacks}, nil
|
||||
opened := parts.Opened{Held: a.Held, Lacks: a.Lacks}
|
||||
if a.OtherBytes != nil {
|
||||
opened.Other = &parts.Other{Digest: a.OtherBytes.Digest, Fingerprint: a.OtherBytes.Fingerprint}
|
||||
}
|
||||
return opened, nil
|
||||
}
|
||||
chunk := func(_ context.Context, part string, sequence int, last bool, data []byte) error {
|
||||
raw, err := call("seat:"+seat.Seat+"."+seat.VerbPublishPart, seat.PublishPartInput{Transfer: in.Transfer, Part: part,
|
||||
|
||||
@@ -44,7 +44,11 @@ func Publish(ctx context.Context, call Call, in seat.PublishInput, ps []parts.Pa
|
||||
if err := json.Unmarshal(raw, &a); err != nil {
|
||||
return parts.Opened{}, fmt.Errorf("%s's answer to publish: %w", seat.Seat, err)
|
||||
}
|
||||
return parts.Opened{Held: a.Held, Lacks: a.Lacks}, nil
|
||||
opened := parts.Opened{Held: a.Held, Lacks: a.Lacks}
|
||||
if a.OtherBytes != nil {
|
||||
opened.Other = &parts.Other{Digest: a.OtherBytes.Digest, Fingerprint: a.OtherBytes.Fingerprint}
|
||||
}
|
||||
return opened, nil
|
||||
}
|
||||
chunk := func(_ context.Context, part string, sequence int, last bool, data []byte) error {
|
||||
raw, err := call("seat:"+seat.Seat+"."+seat.VerbPublishPart, seat.PublishPartInput{Transfer: in.Transfer, Part: part,
|
||||
|
||||
@@ -13,7 +13,7 @@ const Seat = "container-image-registry"
|
||||
|
||||
// Form is the form of the seat's values, events and answers this contract was generated at (design 47 H2 §780):
|
||||
// a reader of a value of another form says "form N, this reader knows M".
|
||||
const Form = 1
|
||||
const Form = 2
|
||||
|
||||
// FormRegistry is the form of what the part registry adds.
|
||||
const FormRegistry = 1
|
||||
@@ -21,8 +21,8 @@ const FormRegistry = 1
|
||||
// The forms and the digest of the fields this contract was generated from: the generator's compare fails a definition
|
||||
// whose fields changed while its forms did not (design 47 H2 §780).
|
||||
const (
|
||||
generatedForms = "1 registry:1"
|
||||
generatedFieldsDigest = "Artifact=79361e4ab1cd HeldEvent=b6d4c12500df Hold=c5a97a2f2d5a HoldAnswer=7d536ccb729f HoldsBySeatNameDigestValue=db093998a869 KeptEvent=ec3ef89ef8a7 ListAnswer=ca49dd7f20ee Listed=b9f1d1232e64 MirrorAnswer=0d59df97b53b NameOfAnswer=cc75a2f37394 Outcome=1e66f7bf6725 PublishAnswer=a0df0b922e1e PublishPartAnswer=aebe3c6c89e9 PublishedEvent=ec3ef89ef8a7 RefusedEvent=ec3ef89ef8a7 ReleaseAnswer=d30bd6000a16 ReleasedEvent=b6d4c12500df RemoveAnswer=bccb5a322d69 RemovedEvent=ec3ef89ef8a7 Repository=740e54e0b3b0 TagsAnswer=fe178191458a TagsAnswerTagsItem=eee02e024d64 VersionsAnswer=47e11ca2aea9 WindowsByCallerValue=23d9294dde92 WindowsByCallerValueDroppedItem=d748f0e58825"
|
||||
generatedForms = "2 registry:1"
|
||||
generatedFieldsDigest = "Artifact=79361e4ab1cd HeldEvent=b6d4c12500df Hold=c5a97a2f2d5a HoldAnswer=7d536ccb729f HoldsBySeatNameDigestValue=db093998a869 KeptEvent=ec3ef89ef8a7 ListAnswer=ca49dd7f20ee Listed=b9f1d1232e64 MirrorAnswer=0d59df97b53b NameOfAnswer=cc75a2f37394 Outcome=1e66f7bf6725 PublishAnswer=1ab67aa1750a PublishAnswerOtherBytes=06b1c9853343 PublishPartAnswer=aebe3c6c89e9 PublishedEvent=ec3ef89ef8a7 RefusedEvent=ec3ef89ef8a7 ReleaseAnswer=d30bd6000a16 ReleasedEvent=b6d4c12500df RemoveAnswer=bccb5a322d69 RemovedEvent=ec3ef89ef8a7 Repository=740e54e0b3b0 TagsAnswer=fe178191458a TagsAnswerTagsItem=eee02e024d64 VersionsAnswer=47e11ca2aea9 WindowsByCallerValue=23d9294dde92 WindowsByCallerValueDroppedItem=d748f0e58825"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -329,6 +329,14 @@ const (
|
||||
PublishInputKindUpstream = "upstream"
|
||||
)
|
||||
|
||||
// PublishAnswerOtherBytes is the holder holds that name and version with another digest: the digest and the fingerprint it keeps for them, answered instead of failing the call (the fingerprint absent where it keeps none); present only in that case, and never with lacks; the holder says both digests and both fingerprints in its journal (design 47 H2 H-A-589 (1), H-A-729).
|
||||
type PublishAnswerOtherBytes struct {
|
||||
// the digest the holder holds for that name and version
|
||||
Digest string `json:"digest"`
|
||||
// the fingerprint the holder keeps for it, absent where it keeps none
|
||||
Fingerprint string `json:"fingerprint,omitempty"`
|
||||
}
|
||||
|
||||
// PublishAnswer is what publish answers.
|
||||
type PublishAnswer struct {
|
||||
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
|
||||
@@ -337,8 +345,10 @@ type PublishAnswer struct {
|
||||
Held bool `json:"held,omitempty"`
|
||||
// the digests of the parts the holder lacks, to send by publish-part
|
||||
Lacks []string `json:"lacks,omitempty"`
|
||||
// the transfer
|
||||
Transfer string `json:"transfer"`
|
||||
// the holder holds that name and version with another digest: the digest and the fingerprint it keeps for them, answered instead of failing the call (the fingerprint absent where it keeps none); present only in that case, and never with lacks; the holder says both digests and both fingerprints in its journal (design 47 H2 H-A-589 (1), H-A-729)
|
||||
OtherBytes *PublishAnswerOtherBytes `json:"other-bytes,omitempty"`
|
||||
// the transfer the publish opens for its chunks; present whenever a transfer is opened and absent exactly when other-bytes is present, never an empty name (design 47 H2 H-A-732)
|
||||
Transfer string `json:"transfer,omitempty"`
|
||||
}
|
||||
|
||||
// PublishPartInput is what publish-part takes.
|
||||
|
||||
@@ -57,6 +57,10 @@ func TestFixtures(t *testing.T) {
|
||||
decode: func(b []byte) (any, error) { var v NameOfInput; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
{name: "name-of answers the copy's reference", subject: "", given: "{\"reference\":\"container-image-registry/upstream/docker.io/library/nats@sha256:eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\"}", wire: "{\"reference\":\"container-image-registry/upstream/docker.io/library/nats@sha256:eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\"}",
|
||||
decode: func(b []byte) (any, error) { var v NameOfAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
{name: "publish answers other-bytes: the name and version are held with another digest (H-A-729)", subject: "", given: "{\"other-bytes\":{\"digest\":\"sha256:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\",\"fingerprint\":\"src2:dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\"}}", wire: "{\"other-bytes\":{\"digest\":\"sha256:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\",\"fingerprint\":\"src2:dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\"}}",
|
||||
decode: func(b []byte) (any, error) { var v PublishAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
{name: "publish answers other-bytes, the holder keeping no fingerprint (H-A-729)", subject: "", given: "{\"other-bytes\":{\"digest\":\"sha256:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\"}}", wire: "{\"other-bytes\":{\"digest\":\"sha256:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\"}}",
|
||||
decode: func(b []byte) (any, error) { var v PublishAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
}
|
||||
for _, c := range cases {
|
||||
v, err := c.decode([]byte(c.given))
|
||||
|
||||
@@ -86,7 +86,7 @@ func VerbDescription(verb string) string {
|
||||
case VerbNote:
|
||||
return "Append one line to a commit's note under refs/notes/mesh-plan. The line carries the act's id, and an id the note already holds is skipped (held)."
|
||||
case VerbMergePull:
|
||||
return "Merge one or more pull requests with the forge tools' account, each at the head the caller names: one merge call, a delivery's start and, with two or more members, its group (design 47 H §734, §735, §766; ADR 0682 §1, §2). Every member is judged before any is merged: still the pull request's head, its base a watched branch, no run at the head's build-input fingerprint failed a required step (judged from its own state failed-steps), registrations heard; no branch protection is read. A member whose repository has no watched branch is judged against nothing of the module graph and merged plainly in the order named, starting no delivery: its outcome says merged with the note no delivery (H-A-471). When one member is refused, none is merged. Then it merges them in the order named, writing the call in its state calls before the first merge, and says merge-called once. It answers once, at the call's end, naming the call and each member's outcome; a member already merged is refused already-merged, naming its commit."
|
||||
return "Merge one or more pull requests with the forge tools' account, each at the head the caller names: one merge call, a delivery's start and, with two or more members, its group (design 47 H §734, §735, §766; ADR 0682 §1, §2). Every member is judged before any is merged: still the pull request's head, no run at the head's build-input fingerprint failed a required step (judged from its own state failed-steps), registrations heard; no branch protection is read. A member whose base is no watched branch, whatever its repository, is judged against nothing of the module graph and merged plainly in the order named, starting no delivery: its outcome says merged with the note no delivery, and merge-called leaves it out (H-A-471, H-A-704). When one member is refused, none is merged. Then it merges them in the order named, writing the call in its state calls before the first merge, and says merge-called once. It answers once, at the call's end, naming the call and each member's outcome; a member already merged is refused already-merged, naming its commit."
|
||||
case VerbTag:
|
||||
return "Write the git tag of a released version, <directory>/vMAJOR.MINOR.PATCH for a Go package (design 47 H2 §796), at the commit its build was made from; the builder writes it only on the catalog's version-released (design 47 G section 370). A tag already at that commit is answered performed. An error answer carries error and error-kind."
|
||||
}
|
||||
@@ -229,12 +229,12 @@ type Call struct {
|
||||
|
||||
// CallMember is one member of a kept call.
|
||||
type CallMember struct {
|
||||
// the pull request's base, read at judging: a watched branch, but for a member noted as of a repository with no watched branch
|
||||
// the pull request's base, read at judging: a watched branch, but for a member noted as one whose base is no watched branch
|
||||
Branch string `json:"branch"`
|
||||
// for merged, the merge commit
|
||||
Commit string `json:"commit,omitempty"`
|
||||
Head string `json:"head"`
|
||||
// for a member merged plainly, its repository having no watched branch: "no delivery: the repository has no watched branch"; it starts no delivery and merge-called leaves it out (design 47 H2 H-A-471)
|
||||
// for a member merged plainly, its base being no watched branch, whatever its repository: "no delivery: its base is no watched branch"; it starts no delivery and merge-called leaves it out (design 47 H2 H-A-471, H-A-704)
|
||||
Note string `json:"note,omitempty"`
|
||||
Number int64 `json:"number"`
|
||||
Repository string `json:"repository"`
|
||||
@@ -298,7 +298,7 @@ type FailedStep struct {
|
||||
type MemberOutcome struct {
|
||||
// for merged, the merge commit; for a member refused already-merged, its commit
|
||||
Commit string `json:"commit,omitempty"`
|
||||
// for a member merged plainly, its repository having no watched branch: "no delivery: the repository has no watched branch"; it starts no delivery and merge-called leaves it out (design 47 H2 H-A-471)
|
||||
// for a member merged plainly, its base being no watched branch, whatever its repository: "no delivery: its base is no watched branch"; it starts no delivery and merge-called leaves it out (design 47 H2 H-A-471, H-A-704)
|
||||
Note string `json:"note,omitempty"`
|
||||
Number int64 `json:"number"`
|
||||
Repository string `json:"repository"`
|
||||
|
||||
@@ -43,7 +43,7 @@ func TestFixtures(t *testing.T) {
|
||||
}, subjectIs: nil},
|
||||
{name: "a merge call kept", subject: "", given: "{\"account\":\"tools-shanks\",\"at\":\"2026-11-20T02:00:00Z\",\"by\":\"lead-47@workstation\",\"members\":[{\"branch\":\"main\",\"commit\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"head\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"number\":178,\"repository\":\"novox/mesh-sdk\",\"state\":\"merged\"},{\"branch\":\"main\",\"head\":\"cccccccccccccccccccccccccccccccccccccccc\",\"number\":261,\"repository\":\"novox/mesh-delivery\",\"state\":\"judged\"}],\"said\":false}", wire: "{\"account\":\"tools-shanks\",\"at\":\"2026-11-20T02:00:00Z\",\"by\":\"lead-47@workstation\",\"members\":[{\"branch\":\"main\",\"commit\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"head\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"number\":178,\"repository\":\"novox/mesh-sdk\",\"state\":\"merged\"},{\"branch\":\"main\",\"head\":\"cccccccccccccccccccccccccccccccccccccccc\",\"number\":261,\"repository\":\"novox/mesh-delivery\",\"state\":\"judged\"}],\"said\":false}",
|
||||
decode: func(b []byte) (any, error) { var v CallsByCallCallValue; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
{name: "a merge call kept with a member merged plainly, its repository having no watched branch", subject: "", given: "{\"account\":\"tools-shanks\",\"at\":\"2026-11-20T02:00:00Z\",\"by\":\"lead-47@workstation\",\"members\":[{\"branch\":\"main\",\"commit\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"head\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"number\":178,\"repository\":\"novox/mesh-sdk\",\"state\":\"merged\"},{\"branch\":\"main\",\"commit\":\"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\",\"head\":\"cccccccccccccccccccccccccccccccccccccccc\",\"note\":\"no delivery: the repository has no watched branch\",\"number\":799,\"repository\":\"novox/hq\",\"state\":\"merged\"}],\"said\":true}", wire: "{\"account\":\"tools-shanks\",\"at\":\"2026-11-20T02:00:00Z\",\"by\":\"lead-47@workstation\",\"members\":[{\"branch\":\"main\",\"commit\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"head\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"number\":178,\"repository\":\"novox/mesh-sdk\",\"state\":\"merged\"},{\"branch\":\"main\",\"commit\":\"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\",\"head\":\"cccccccccccccccccccccccccccccccccccccccc\",\"note\":\"no delivery: the repository has no watched branch\",\"number\":799,\"repository\":\"novox/hq\",\"state\":\"merged\"}],\"said\":true}",
|
||||
{name: "a merge call kept with a member merged plainly, its base being no watched branch", subject: "", given: "{\"account\":\"tools-shanks\",\"at\":\"2026-11-20T02:00:00Z\",\"by\":\"lead-47@workstation\",\"members\":[{\"branch\":\"main\",\"commit\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"head\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"number\":178,\"repository\":\"novox/mesh-sdk\",\"state\":\"merged\"},{\"branch\":\"main\",\"commit\":\"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\",\"head\":\"cccccccccccccccccccccccccccccccccccccccc\",\"note\":\"no delivery: its base is no watched branch\",\"number\":799,\"repository\":\"novox/hq\",\"state\":\"merged\"}],\"said\":true}", wire: "{\"account\":\"tools-shanks\",\"at\":\"2026-11-20T02:00:00Z\",\"by\":\"lead-47@workstation\",\"members\":[{\"branch\":\"main\",\"commit\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"head\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"number\":178,\"repository\":\"novox/mesh-sdk\",\"state\":\"merged\"},{\"branch\":\"main\",\"commit\":\"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\",\"head\":\"cccccccccccccccccccccccccccccccccccccccc\",\"note\":\"no delivery: its base is no watched branch\",\"number\":799,\"repository\":\"novox/hq\",\"state\":\"merged\"}],\"said\":true}",
|
||||
decode: func(b []byte) (any, error) { var v CallsByCallCallValue; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
{name: "pull asks", subject: "", given: "{\"merge-commit\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"repository\":\"novox/mesh-sdk\"}", wire: "{\"merge-commit\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"repository\":\"novox/mesh-sdk\"}",
|
||||
decode: func(b []byte) (any, error) { var v PullInput; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
@@ -135,7 +135,7 @@ func TestFixtures(t *testing.T) {
|
||||
decode: func(b []byte) (any, error) { var v MergePullInput; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
{name: "merge-pull answers the call and each member merged", subject: "", given: "{\"call\":\"0123456789abcdef\",\"members\":[{\"commit\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"number\":178,\"repository\":\"novox/mesh-sdk\",\"state\":\"merged\"},{\"commit\":\"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\",\"number\":261,\"repository\":\"novox/mesh-delivery\",\"state\":\"merged\"}]}", wire: "{\"call\":\"0123456789abcdef\",\"members\":[{\"commit\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"number\":178,\"repository\":\"novox/mesh-sdk\",\"state\":\"merged\"},{\"commit\":\"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\",\"number\":261,\"repository\":\"novox/mesh-delivery\",\"state\":\"merged\"}]}",
|
||||
decode: func(b []byte) (any, error) { var v MergePullAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
{name: "merge-pull merges a member of a repository with no watched branch plainly, noted no delivery", subject: "", given: "{\"call\":\"0123456789abcdef\",\"members\":[{\"commit\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"number\":178,\"repository\":\"novox/mesh-sdk\",\"state\":\"merged\"},{\"commit\":\"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\",\"note\":\"no delivery: the repository has no watched branch\",\"number\":799,\"repository\":\"novox/hq\",\"state\":\"merged\"}]}", wire: "{\"call\":\"0123456789abcdef\",\"members\":[{\"commit\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"number\":178,\"repository\":\"novox/mesh-sdk\",\"state\":\"merged\"},{\"commit\":\"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\",\"note\":\"no delivery: the repository has no watched branch\",\"number\":799,\"repository\":\"novox/hq\",\"state\":\"merged\"}]}",
|
||||
{name: "merge-pull merges a member whose base is no watched branch plainly, noted no delivery", subject: "", given: "{\"call\":\"0123456789abcdef\",\"members\":[{\"commit\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"number\":178,\"repository\":\"novox/mesh-sdk\",\"state\":\"merged\"},{\"commit\":\"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\",\"note\":\"no delivery: its base is no watched branch\",\"number\":799,\"repository\":\"novox/hq\",\"state\":\"merged\"}]}", wire: "{\"call\":\"0123456789abcdef\",\"members\":[{\"commit\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"number\":178,\"repository\":\"novox/mesh-sdk\",\"state\":\"merged\"},{\"commit\":\"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\",\"note\":\"no delivery: its base is no watched branch\",\"number\":799,\"repository\":\"novox/hq\",\"state\":\"merged\"}]}",
|
||||
decode: func(b []byte) (any, error) { var v MergePullAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
{name: "merge-pull refuses every member when one is refused, naming why", subject: "", given: "{\"call\":\"0123456789abcdef\",\"members\":[{\"number\":178,\"repository\":\"novox/mesh-sdk\",\"state\":\"refused\",\"why\":\"the head moved: cccccccccccccccccccccccccccccccccccccccc, not the named aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"},{\"number\":261,\"repository\":\"novox/mesh-delivery\",\"state\":\"judged\"}]}", wire: "{\"call\":\"0123456789abcdef\",\"members\":[{\"number\":178,\"repository\":\"novox/mesh-sdk\",\"state\":\"refused\",\"why\":\"the head moved: cccccccccccccccccccccccccccccccccccccccc, not the named aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"},{\"number\":261,\"repository\":\"novox/mesh-delivery\",\"state\":\"judged\"}]}",
|
||||
decode: func(b []byte) (any, error) { var v MergePullAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
|
||||
@@ -12,7 +12,7 @@ const Seat = "go-package-registry"
|
||||
|
||||
// Form is the form of the seat's values, events and answers this contract was generated at (design 47 H2 §780):
|
||||
// a reader of a value of another form says "form N, this reader knows M".
|
||||
const Form = 1
|
||||
const Form = 2
|
||||
|
||||
// FormRegistry is the form of what the part registry adds.
|
||||
const FormRegistry = 1
|
||||
@@ -20,8 +20,8 @@ const FormRegistry = 1
|
||||
// The forms and the digest of the fields this contract was generated from: the generator's compare fails a definition
|
||||
// whose fields changed while its forms did not (design 47 H2 §780).
|
||||
const (
|
||||
generatedForms = "1 registry:1"
|
||||
generatedFieldsDigest = "Artifact=79361e4ab1cd KeptEvent=ec3ef89ef8a7 Outcome=1e66f7bf6725 PublishAnswer=a0df0b922e1e PublishPartAnswer=aebe3c6c89e9 PublishedEvent=ec3ef89ef8a7 RefusedEvent=ec3ef89ef8a7 RemoveAnswer=bccb5a322d69 RemovedEvent=ec3ef89ef8a7 VersionsAnswer=47e11ca2aea9"
|
||||
generatedForms = "2 registry:1"
|
||||
generatedFieldsDigest = "Artifact=79361e4ab1cd KeptEvent=ec3ef89ef8a7 Outcome=1e66f7bf6725 PublishAnswer=1ab67aa1750a PublishAnswerOtherBytes=06b1c9853343 PublishPartAnswer=aebe3c6c89e9 PublishedEvent=ec3ef89ef8a7 RefusedEvent=ec3ef89ef8a7 RemoveAnswer=bccb5a322d69 RemovedEvent=ec3ef89ef8a7 VersionsAnswer=47e11ca2aea9"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -189,6 +189,14 @@ const (
|
||||
PublishInputKindUpstream = "upstream"
|
||||
)
|
||||
|
||||
// PublishAnswerOtherBytes is the holder holds that name and version with another digest: the digest and the fingerprint it keeps for them, answered instead of failing the call (the fingerprint absent where it keeps none); present only in that case, and never with lacks; the holder says both digests and both fingerprints in its journal (design 47 H2 H-A-589 (1), H-A-729).
|
||||
type PublishAnswerOtherBytes struct {
|
||||
// the digest the holder holds for that name and version
|
||||
Digest string `json:"digest"`
|
||||
// the fingerprint the holder keeps for it, absent where it keeps none
|
||||
Fingerprint string `json:"fingerprint,omitempty"`
|
||||
}
|
||||
|
||||
// PublishAnswer is what publish answers.
|
||||
type PublishAnswer struct {
|
||||
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
|
||||
@@ -197,8 +205,10 @@ type PublishAnswer struct {
|
||||
Held bool `json:"held,omitempty"`
|
||||
// the digests of the parts the holder lacks, to send by publish-part
|
||||
Lacks []string `json:"lacks,omitempty"`
|
||||
// the transfer
|
||||
Transfer string `json:"transfer"`
|
||||
// the holder holds that name and version with another digest: the digest and the fingerprint it keeps for them, answered instead of failing the call (the fingerprint absent where it keeps none); present only in that case, and never with lacks; the holder says both digests and both fingerprints in its journal (design 47 H2 H-A-589 (1), H-A-729)
|
||||
OtherBytes *PublishAnswerOtherBytes `json:"other-bytes,omitempty"`
|
||||
// the transfer the publish opens for its chunks; present whenever a transfer is opened and absent exactly when other-bytes is present, never an empty name (design 47 H2 H-A-732)
|
||||
Transfer string `json:"transfer,omitempty"`
|
||||
}
|
||||
|
||||
// PublishPartInput is what publish-part takes.
|
||||
|
||||
@@ -37,6 +37,10 @@ func TestFixtures(t *testing.T) {
|
||||
decode: func(b []byte) (any, error) { var v VersionsAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
{name: "a tagged version sharing its digest with another tag is kept, not removed", subject: "", given: "{\"kept\":true,\"reason\":\"shared-digest\",\"removed\":false,\"tags\":[\"0.1.19\"]}", wire: "{\"kept\":true,\"reason\":\"shared-digest\",\"removed\":false,\"tags\":[\"0.1.19\"]}",
|
||||
decode: func(b []byte) (any, error) { var v RemoveAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
{name: "publish answers other-bytes: the name and version are held with another digest (H-A-729)", subject: "", given: "{\"other-bytes\":{\"digest\":\"sha256:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\",\"fingerprint\":\"src2:dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\"}}", wire: "{\"other-bytes\":{\"digest\":\"sha256:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\",\"fingerprint\":\"src2:dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\"}}",
|
||||
decode: func(b []byte) (any, error) { var v PublishAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
{name: "publish answers other-bytes, the holder keeping no fingerprint (H-A-729)", subject: "", given: "{\"other-bytes\":{\"digest\":\"sha256:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\"}}", wire: "{\"other-bytes\":{\"digest\":\"sha256:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\"}}",
|
||||
decode: func(b []byte) (any, error) { var v PublishAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
}
|
||||
for _, c := range cases {
|
||||
v, err := c.decode([]byte(c.given))
|
||||
|
||||
@@ -13,13 +13,13 @@ const Seat = "mesh-builds"
|
||||
|
||||
// Form is the form of the seat's values, events and answers this contract was generated at (design 47 H2 §780):
|
||||
// a reader of a value of another form says "form N, this reader knows M".
|
||||
const Form = 3
|
||||
const Form = 4
|
||||
|
||||
// The forms and the digest of the fields this contract was generated from: the generator's compare fails a definition
|
||||
// whose fields changed while its forms did not (design 47 H2 §780).
|
||||
const (
|
||||
generatedForms = "3"
|
||||
generatedFieldsDigest = "AskTakenEvent=6d5d3da7ac39 BuildEntry=3c829a0a3d58 Dependency=90a32b07c563 DropAnswer=7538f2f5e68e PackagePublished=34dd069a6aab PackagePublishedEvent=8e12888c1559 PublishQueueAnswer=0f1326e35e17 PublishQueueAnswerCountsItem=b770db2f0920 PublishQueueAnswerQueueItem=b1eebc09f41e PublishedAnswer=69a801982819 ReservedAnswer=2272a4d6f0f4 ReservedAnswerArtifactsItem=d74eb6e00abb Shared=c981cf6aa860 SharedAskedBy=c9b30cc4d0d0 StepAccept=18efeefb6c34 StepEnded=be571d4ff16f StepEndedEvent=207787118dac StepProgressEvent=8215e490ea8d StepRun=dc5893aef7e5 ToolchainAgreed=f3d9ce993734 ToolchainAgreedDigestsItem=1d42893a96b9 ToolchainAgreedEvent=e3502d6f194d VersionReservedEvent=984547d6ad07"
|
||||
generatedForms = "4"
|
||||
generatedFieldsDigest = "AskTakenEvent=6d5d3da7ac39 BuildEntry=3c829a0a3d58 Dependency=90a32b07c563 DropAnswer=7538f2f5e68e PackagePublished=7e20050c6260 PackagePublishedEvent=8e12888c1559 PublishQueueAnswer=0f1326e35e17 PublishQueueAnswerCountsItem=b770db2f0920 PublishQueueAnswerQueueItem=b1eebc09f41e PublishedAnswer=69a801982819 ReservedAnswer=2272a4d6f0f4 ReservedAnswerArtifactsItem=d74eb6e00abb Shared=c981cf6aa860 SharedAskedBy=c9b30cc4d0d0 StepAccept=18efeefb6c34 StepEnded=be571d4ff16f StepEndedEvent=207787118dac StepProgressEvent=8215e490ea8d StepRun=dc5893aef7e5 ToolchainAgreed=f3d9ce993734 ToolchainAgreedDigestsItem=1d42893a96b9 ToolchainAgreedEvent=e3502d6f194d VersionReservedEvent=984547d6ad07"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -146,6 +146,8 @@ type PackagePublished struct {
|
||||
Dependencies []Dependency `json:"dependencies,omitempty"`
|
||||
// the published artifact's digest
|
||||
Digest string `json:"digest"`
|
||||
// the fingerprint of the build the reservation holds, so the runner marks every running pipeline of the branch that moves the module at it; absent from a publish whose reservation names none; the builder, the assigner and the indexer read it not and decode it tolerantly (design 47 H2 H-A-707 (6))
|
||||
Fingerprint string `json:"fingerprint,omitempty"`
|
||||
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
|
||||
Form int64 `json:"form,omitempty"`
|
||||
// the module
|
||||
@@ -198,7 +200,7 @@ type StepEnded struct {
|
||||
Packages map[string]string `json:"packages,omitempty"`
|
||||
Pipeline string `json:"pipeline"`
|
||||
Rerun bool `json:"rerun,omitempty"`
|
||||
// for a step ended superseded, the module graph revision of the entry that superseded it, 0 when the builder knows none; the runner moves the mover out only for a revision newer than its pipeline's that its view holds (design 47 H2 H-A-561)
|
||||
// the module graph revision of the entry that superseded the step, present exactly when outcome is superseded and absent otherwise; the runner moves the mover out only for a revision newer than its pipeline's that its view holds (design 47 H2 H-A-574, H-A-650)
|
||||
Revision int64 `json:"revision,omitempty"`
|
||||
// why it failed, could not run or was superseded: the entry not built, the part not heard, the superseding fingerprint
|
||||
Said string `json:"said,omitempty"`
|
||||
|
||||
@@ -35,6 +35,10 @@ func TestFixtures(t *testing.T) {
|
||||
decode: func(b []byte) (any, error) { var v VersionReservedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-builds\\.event\\.version-reserved$")},
|
||||
{name: "a build step's progress while its build waits for a package", subject: "mesh.seat.mesh-builds.event.step-progress.anchor", given: "{\"ask\":\"a1b2\",\"asker\":\"mesh-delivery-pipeline\",\"at\":\"2026-11-23T02:40:00Z\",\"phase\":\"build\"}", wire: "{\"ask\":\"a1b2\",\"asker\":\"mesh-delivery-pipeline\",\"at\":\"2026-11-23T02:40:00Z\",\"phase\":\"build\"}",
|
||||
decode: func(b []byte) (any, error) { var v StepProgressEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-builds\\.event\\.step-progress\\.[^.*> ]+$")},
|
||||
{name: "the step ended superseded in form 4: revision present exactly when superseded (H-A-574, H-A-650)", subject: "mesh.seat.mesh-builds.event.step-ended.laptop", given: "{\"entries\":[{\"fingerprint\":\"fp-0123\",\"module\":\"nats\"}],\"form\":4,\"id\":\"m2kx9a1b3c4d6f\",\"node\":\"laptop\",\"outcome\":\"superseded\",\"pipeline\":\"main.12.nats\",\"revision\":14,\"said\":\"nats at fp-0123 is superseded by fp-0456, the newest entry heard on its first branch\",\"step\":\"build\",\"v\":1}", wire: "{\"entries\":[{\"fingerprint\":\"fp-0123\",\"module\":\"nats\"}],\"form\":4,\"id\":\"m2kx9a1b3c4d6f\",\"node\":\"laptop\",\"outcome\":\"superseded\",\"pipeline\":\"main.12.nats\",\"revision\":14,\"said\":\"nats at fp-0123 is superseded by fp-0456, the newest entry heard on its first branch\",\"step\":\"build\",\"v\":1}",
|
||||
decode: func(b []byte) (any, error) { var v StepEndedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-builds\\.event\\.step-ended\\.[^.*> ]+$")},
|
||||
{name: "a package published, naming the build's fingerprint (H-A-707 (6))", subject: "mesh.seat.mesh-builds.event.package-published", given: "{\"artifact\":\"mesh-sdk:go\",\"at\":\"2026-11-10T10:00:00Z\",\"branch\":\"main\",\"dependencies\":[{\"digest\":\"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"kind\":1,\"part\":\"mesh-contracts:go-nodeengine\",\"version\":\"0.1.4\"},{\"digest\":\"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"kind\":3,\"part\":\"mesh-build-go:toolchain\",\"version\":\"1.26.0\"}],\"digest\":\"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"fingerprint\":\"fp-sdk\",\"module\":\"mesh-sdk\",\"source\":3589,\"v\":1,\"version\":\"0.1.15\"}", wire: "{\"artifact\":\"mesh-sdk:go\",\"at\":\"2026-11-10T10:00:00Z\",\"branch\":\"main\",\"dependencies\":[{\"digest\":\"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"kind\":1,\"part\":\"mesh-contracts:go-nodeengine\",\"version\":\"0.1.4\"},{\"digest\":\"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"kind\":3,\"part\":\"mesh-build-go:toolchain\",\"version\":\"1.26.0\"}],\"digest\":\"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"fingerprint\":\"fp-sdk\",\"module\":\"mesh-sdk\",\"source\":3589,\"v\":1,\"version\":\"0.1.15\"}",
|
||||
decode: func(b []byte) (any, error) { var v PackagePublishedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-builds\\.event\\.package-published$")},
|
||||
{name: "reserved asks a module", subject: "", given: "{\"module\":\"mesh-sdk\"}", wire: "{\"module\":\"mesh-sdk\"}",
|
||||
decode: func(b []byte) (any, error) { var v ReservedInput; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
{name: "reserved asks a package by its name", subject: "", given: "{\"name\":\"git.novox.be/novox/mesh-sdk/go\",\"version\":\"0.1.15\"}", wire: "{\"name\":\"git.novox.be/novox/mesh-sdk/go\",\"version\":\"0.1.15\"}",
|
||||
|
||||
@@ -14,13 +14,13 @@ const Seat = "mesh-catalog"
|
||||
|
||||
// Form is the form of the seat's values, events and answers this contract was generated at (design 47 H2 §780):
|
||||
// a reader of a value of another form says "form N, this reader knows M".
|
||||
const Form = 6
|
||||
const Form = 7
|
||||
|
||||
// The forms and the digest of the fields this contract was generated from: the generator's compare fails a definition
|
||||
// whose fields changed while its forms did not (design 47 H2 §780).
|
||||
const (
|
||||
generatedForms = "6"
|
||||
generatedFieldsDigest = "ActingRule=8a83ce7e0457 Artifact=78b05c1a9ec3 ArtifactPackage=2a3a660a934d ArtifactRef=a2f06147f4b6 BuildEdge=76f0684e254a CandidatesByGroupValue=9ea8c6c580d2 CandidatesByGroupValuePullsItem=90fb03643258 CandidatesByGroupValuePullsItemFpsValue=4c6783201aa3 CatalogEntry=c0a4ea25d523 CatalogRevision=d1ecaaa484af CatalogRevisionDefinitionsItem=77fcff620d48 CatalogRevisionEvent=710cbc5bfff1 CatalogRevisionsByBranchRevisionValue=17e54f635d35 CatalogRevisionsByCandidateGroupHeadsValue=17e54f635d35 CatalogRevisionsByEntryDigestValue=8755036a3051 DependentsAnswer=7538f2f5e68e Edge=7242732afaef EntryAnswer=805c2ff28e1c EntryInputs=76a7f8690dd2 EntryRef=ff109e5089e1 Fill=80f442916429 FillingEvent=5bd4df78ed84 FingerprintInputs=99a6df7f991f FullEvent=5bd4df78ed84 Head=774b4bf88ba4 InputAnswer=cd41ee65565d InputsByTimeDigestValue=a2f06147f4b6 ManifestsByDigestValue=51b3822b29c6 ModuleAnswer=499a03ce9b27 ModuleAnswerModule=c0f679e09f08 ModulesAnswer=6d119571c69e ModulesAnswerModulesItem=a70f39c60b67 ModulesByModuleValue=fc7530ba893a ModulesByModuleValueInputs2=99a6df7f991f PackagesByModuleValue=2b62574b709f PackagesByModuleValuePackagesItem=a7d30558470d PackagesByPackageSeriesValue=07421d8d3411 PackagesByPackageSeriesValueNewest=aba144994370 PackagesByPackageSeriesValueNewestContents=eca2ccf56913 PackagesByPackageSeriesValueNewestContentsPackagesItem=a7d30558470d PackagesByPackageSeriesValueNumbered=c8ffc628599c PackagesByPackageSeriesValueNumberedContents=0def6c0794ee PackagesByPackageSeriesValueNumberedContentsPackagesItem=a7d30558470d Policy=719e2f460c6f PolicyAnswer=46cdf8430557 PredefinedByListValue=ec8e3febe8ac ProvidesAnswer=7538f2f5e68e RegisterAnswer=46cdf8430557 Registration=ef03d1b2e73f RegistrationAsked=b529a0e1c5ca RegistrationChangedEvent=99a3268edf41 RegistrationHistoryByModuleVersionValue=0999b5bb7dc7 RegistrationHistoryBySourceOwnerNameVersionValue=0999b5bb7dc7 RegistrationsAnswer=8849ef618cf3 RegistrationsByModuleValue=0999b5bb7dc7 RegistrationsBySourceOwnerNameValue=0999b5bb7dc7 RevisionAnswer=258ea5124931 RoomEvent=5bd4df78ed84 SeatDefinitionChangedEvent=e271d24d58f7 SeatDefinitionRemovedEvent=f7d6171111e6 SeatDefinitionsAnswer=0fd6a59fec59 SeatDefinitionsAnswerEntry=d006f68d2be5 SeatDefinitionsAnswerSeatsItem=e271d24d58f7 SeatListAnswer=04477a8044b1 SourceCheck=d1ed7cbbd579 StepStatuses=4f50aa633e61 TakeInEntry=545ec1528499 ToolchainUsed=43b6d42376fb UnwatchAnswer=46cdf8430557 VersionArtifact=438c49a392b0 VersionEdge=b0f80e83f4dc VersionEntry=33f5b00dbda9 VersionReleasedEvent=4ccf1ea90e7f VersionsAnswer=b59e6e057e7b VersionsByModuleVersionValue=e546dfadb913 WatchAnswer=46cdf8430557"
|
||||
generatedForms = "7"
|
||||
generatedFieldsDigest = "ActingRule=8a83ce7e0457 Artifact=0223a648b4e5 ArtifactDigestsItem=a7d30558470d ArtifactPackage=2a3a660a934d ArtifactRef=a2f06147f4b6 BuildEdge=76f0684e254a CandidatesByGroupValue=9ea8c6c580d2 CandidatesByGroupValuePullsItem=90fb03643258 CandidatesByGroupValuePullsItemFpsValue=4c6783201aa3 CatalogEntry=4c82dcc1e492 CatalogRevision=178230def2a0 CatalogRevisionDefinitionsItem=77fcff620d48 CatalogRevisionEvent=710cbc5bfff1 CatalogRevisionsByBranchRevisionValue=17e54f635d35 CatalogRevisionsByCandidateGroupHeadsValue=17e54f635d35 CatalogRevisionsByEntryDigestValue=8755036a3051 DependentsAnswer=7538f2f5e68e Edge=7242732afaef EntryAnswer=805c2ff28e1c EntryInputs=76a7f8690dd2 EntryRef=ff109e5089e1 Fill=80f442916429 FillingEvent=5bd4df78ed84 FingerprintInputs=99a6df7f991f FullEvent=5bd4df78ed84 Head=774b4bf88ba4 InputAnswer=cd41ee65565d InputsByTimeDigestValue=a2f06147f4b6 ManifestsByDigestValue=51b3822b29c6 ModuleAnswer=499a03ce9b27 ModuleAnswerModule=c0f679e09f08 ModulesAnswer=6d119571c69e ModulesAnswerModulesItem=a70f39c60b67 ModulesByModuleValue=fc7530ba893a ModulesByModuleValueInputs2=99a6df7f991f PackagesByModuleValue=2b62574b709f PackagesByModuleValuePackagesItem=a7d30558470d PackagesByPackageSeriesValue=07421d8d3411 PackagesByPackageSeriesValueNewest=aba144994370 PackagesByPackageSeriesValueNewestContents=eca2ccf56913 PackagesByPackageSeriesValueNewestContentsPackagesItem=a7d30558470d PackagesByPackageSeriesValueNumbered=c8ffc628599c PackagesByPackageSeriesValueNumberedContents=0def6c0794ee PackagesByPackageSeriesValueNumberedContentsPackagesItem=a7d30558470d Policy=719e2f460c6f PolicyAnswer=46cdf8430557 PredefinedByListValue=ec8e3febe8ac ProvidesAnswer=7538f2f5e68e RegisterAnswer=46cdf8430557 Registration=ef03d1b2e73f RegistrationAsked=b529a0e1c5ca RegistrationChangedEvent=99a3268edf41 RegistrationHistoryByModuleVersionValue=0999b5bb7dc7 RegistrationHistoryBySourceOwnerNameVersionValue=0999b5bb7dc7 RegistrationsAnswer=8849ef618cf3 RegistrationsByModuleValue=0999b5bb7dc7 RegistrationsBySourceOwnerNameValue=0999b5bb7dc7 RevisionAnswer=258ea5124931 RoomEvent=5bd4df78ed84 SeatDefinitionChangedEvent=e271d24d58f7 SeatDefinitionRemovedEvent=f7d6171111e6 SeatDefinitionsAnswer=0fd6a59fec59 SeatDefinitionsAnswerEntry=d006f68d2be5 SeatDefinitionsAnswerSeatsItem=e271d24d58f7 SeatListAnswer=04477a8044b1 SourceCheck=d1ed7cbbd579 StepStatuses=4f50aa633e61 TakeInEntry=545ec1528499 ToolchainUsed=43b6d42376fb UnwatchAnswer=46cdf8430557 VersionArtifact=438c49a392b0 VersionEdge=b0f80e83f4dc VersionEntry=33f5b00dbda9 VersionReleasedEvent=4ccf1ea90e7f VersionsAnswer=b59e6e057e7b VersionsByModuleVersionValue=e546dfadb913 WatchAnswer=46cdf8430557"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -625,6 +625,14 @@ type ActingRule struct {
|
||||
Step string `json:"step"`
|
||||
}
|
||||
|
||||
// ArtifactDigestsItem is a type of the contract.
|
||||
type ArtifactDigestsItem struct {
|
||||
// the package's digest, by its files (design 47 H2 H-A-580)
|
||||
Digest string `json:"digest"`
|
||||
// the package's Go import path or npm name
|
||||
Package string `json:"package"`
|
||||
}
|
||||
|
||||
// ArtifactPackage is the package's name read from the revision's own files at the artifact's path (the module of its go.mod, the name of its package.json, the manifest's image name), written at take-in (design 47 G section 676).
|
||||
type ArtifactPackage struct {
|
||||
// go, npm or image
|
||||
@@ -634,6 +642,8 @@ type ArtifactPackage struct {
|
||||
|
||||
// Artifact is one artifact of a module in the catalog graph entry.
|
||||
type Artifact struct {
|
||||
// the digest of each package of the artifact, kept by the indexer when it computes the entry, so an importer reads the digest of each package it imports from the entry that publishes it (design 47 H2 H-A-580)
|
||||
Digests []ArtifactDigestsItem `json:"digests,omitempty"`
|
||||
// the artifact's kind
|
||||
Kind string `json:"kind,omitempty"`
|
||||
// the artifact's language as its manifest says it (go, typescript, ...); a step's build seat is read from it (design 47 G section 323)
|
||||
@@ -670,6 +680,8 @@ type CatalogEntry struct {
|
||||
Class string `json:"class,omitempty"`
|
||||
// the merge commit it was last changed at
|
||||
Commit string `json:"commit"`
|
||||
// the subjects its accepted manifest consumes, filled by the indexer beside invokes (design 47 H2 H-A-621)
|
||||
Consumes []string `json:"consumes,omitempty"`
|
||||
// the requirements the manifest's contributes object names as keys, sorted, its local names not carried; each is also in requires (design 47 G section 709)
|
||||
Contributes []string `json:"contributes,omitempty"`
|
||||
// the edges into this module's artifacts, each from the artifact that comes first; the build and the delivery order by these alone
|
||||
@@ -690,7 +702,7 @@ type CatalogEntry struct {
|
||||
// the sha256: digest of the manifest's bytes as the forge answered them, set by the indexer at take-in and never computed again from the manifest whole; the module's value and the manifests key are this digest (design 47 G section 506)
|
||||
ManifestDigest string `json:"manifest-digest,omitempty"`
|
||||
Module string `json:"module"`
|
||||
// the manifest reads a node-engine must state to compose it, its templates' forms included, as the forge bridge read them at the merge (ADR 0614 §4, ADR 0632 §2)
|
||||
// the manifest reads a node-engine must state to compose it, its templates' forms included, as the indexer derives them at the take-in (ADR 0614 §4, ADR 0632 §2)
|
||||
Needs []string `json:"needs,omitempty"`
|
||||
// why it has none
|
||||
None string `json:"none,omitempty"`
|
||||
@@ -747,6 +759,8 @@ type CatalogRevision struct {
|
||||
Module string `json:"module,omitempty"`
|
||||
// the movers of the take-in that wrote it, so a redelivered source-moved whose revision is kept says take-in.taken again from them, recomputing nothing (design 47 H §743, H-A-92); absent for one with no mover
|
||||
Movers []TakeInEntry `json:"movers,omitempty"`
|
||||
// the version of the manifest validator's need rules this revision's entries were derived with, absent read as 0; a take-in derives the rule needs of unmoved entries again only when its own is higher than its base revision's (design 47 H2 H-A-569 (2), H-A-605 (4))
|
||||
NeedsRules int64 `json:"needs-rules,omitempty"`
|
||||
// for call-kind take-in-again, the repository taken in again (H-A-215)
|
||||
Repository string `json:"repository,omitempty"`
|
||||
// the catalog graph revision's number, counted by its holder
|
||||
|
||||
@@ -57,7 +57,7 @@ func TestFixtures(t *testing.T) {
|
||||
decode: func(b []byte) (any, error) { var v ModulesAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
{name: "the module verb (captured: xclip)", subject: "", given: "{\"module\":{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"fp\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"manifest\":{\"build\":{\"artifacts\":[{\"binary\":\"xclip-tools\",\"from\":\"cmd/xclip-tools\",\"kind\":\"bundle\",\"language\":\"go\",\"loads\":[\"xclip-tools\"],\"name\":\"tools\",\"system\":\"arch\"}]},\"capabilities\":[\"package-manager\"],\"module\":\"xclip\",\"resources\":[{\"id\":\"package\",\"package\":\"xclip\",\"type\":\"package\"}],\"tools\":[\"xclip_copy\",\"xclip_paste\",\"xclip_targets\",\"xclip_session\"],\"version\":\"1\"},\"module\":\"xclip\",\"path\":\"modules/xclip\",\"repository\":\"novox/mesh-catalog\"}}", wire: "{\"module\":{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"fp\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"manifest\":{\"build\":{\"artifacts\":[{\"binary\":\"xclip-tools\",\"from\":\"cmd/xclip-tools\",\"kind\":\"bundle\",\"language\":\"go\",\"loads\":[\"xclip-tools\"],\"name\":\"tools\",\"system\":\"arch\"}]},\"capabilities\":[\"package-manager\"],\"module\":\"xclip\",\"resources\":[{\"id\":\"package\",\"package\":\"xclip\",\"type\":\"package\"}],\"tools\":[\"xclip_copy\",\"xclip_paste\",\"xclip_targets\",\"xclip_session\"],\"version\":\"1\"},\"module\":\"xclip\",\"path\":\"modules/xclip\",\"repository\":\"novox/mesh-catalog\"}}",
|
||||
decode: func(b []byte) (any, error) { var v ModuleAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil},
|
||||
{name: "a watched branch's catalog graph revision", subject: "", given: "{\"at\":\"2026-11-09T19:00:00Z\",\"base\":9,\"branch\":\"main\",\"call\":\"release of mesh-sdk 0.1.27\",\"call-kind\":\"release\",\"definitions\":[{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"seat\":\"node-build-go\"}],\"entries\":[{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"module\":\"mesh-build-go\"},{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"module\":\"xclip\"}],\"kind\":\"trunk\",\"module\":\"mesh-sdk\",\"movers\":[{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"fingerprint\":\"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"module\":\"xclip\",\"repository\":\"novox/mesh-catalog\"}],\"revision\":12,\"source\":3589,\"trunk\":[{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"repository\":\"novox/mesh-catalog\"}],\"v\":1,\"version\":\"0.1.27\"}", wire: "{\"at\":\"2026-11-09T19:00:00Z\",\"base\":9,\"branch\":\"main\",\"call\":\"release of mesh-sdk 0.1.27\",\"call-kind\":\"release\",\"definitions\":[{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"seat\":\"node-build-go\"}],\"entries\":[{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"module\":\"mesh-build-go\"},{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"module\":\"xclip\"}],\"kind\":\"trunk\",\"module\":\"mesh-sdk\",\"movers\":[{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"fingerprint\":\"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"module\":\"xclip\",\"repository\":\"novox/mesh-catalog\"}],\"revision\":12,\"source\":3589,\"trunk\":[{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"repository\":\"novox/mesh-catalog\"}],\"v\":1,\"version\":\"0.1.27\"}",
|
||||
{name: "a watched branch's catalog graph revision", subject: "", given: "{\"at\":\"2026-11-09T19:00:00Z\",\"base\":9,\"branch\":\"main\",\"call\":\"release of mesh-sdk 0.1.27\",\"call-kind\":\"release\",\"definitions\":[{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"seat\":\"node-build-go\"}],\"entries\":[{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"module\":\"mesh-build-go\"},{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"module\":\"xclip\"}],\"kind\":\"trunk\",\"module\":\"mesh-sdk\",\"movers\":[{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"fingerprint\":\"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"module\":\"xclip\",\"repository\":\"novox/mesh-catalog\"}],\"needs-rules\":2,\"revision\":12,\"source\":3589,\"trunk\":[{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"repository\":\"novox/mesh-catalog\"}],\"v\":1,\"version\":\"0.1.27\"}", wire: "{\"at\":\"2026-11-09T19:00:00Z\",\"base\":9,\"branch\":\"main\",\"call\":\"release of mesh-sdk 0.1.27\",\"call-kind\":\"release\",\"definitions\":[{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"seat\":\"node-build-go\"}],\"entries\":[{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"module\":\"mesh-build-go\"},{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"module\":\"xclip\"}],\"kind\":\"trunk\",\"module\":\"mesh-sdk\",\"movers\":[{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"fingerprint\":\"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"module\":\"xclip\",\"repository\":\"novox/mesh-catalog\"}],\"needs-rules\":2,\"revision\":12,\"source\":3589,\"trunk\":[{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"repository\":\"novox/mesh-catalog\"}],\"v\":1,\"version\":\"0.1.27\"}",
|
||||
decode: func(b []byte) (any, error) {
|
||||
var v CatalogRevisionsByBranchRevisionValue
|
||||
err := json.Unmarshal(b, &v)
|
||||
@@ -69,7 +69,7 @@ func TestFixtures(t *testing.T) {
|
||||
err := json.Unmarshal(b, &v)
|
||||
return v, err
|
||||
}, subjectIs: nil},
|
||||
{name: "a catalog graph entry (xclip)", subject: "", given: "{\"bases\":[\"arch\"],\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"fp\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"inputs\":{\"from\":{\"bases\":[\"arch\"],\"locks\":{\"go.sum\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\"},\"packages\":[\"git.novox.be/novox/mesh-sdk/go@v0.0.0-20261101000000-f469eb387a30\"],\"tree\":\"4b825dc642cb6eb9a060e54bf8d69288fbee4904\"},\"toolchains\":{\"go\":{\"language\":\"go\",\"recipe\":\"1\",\"version\":\"1.26.0\"}}},\"invokes\":[\"node-files.read\"],\"manifest\":{\"module\":\"xclip\",\"version\":\"1\"},\"manifest-digest\":\"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"module\":\"xclip\",\"packages\":{\"git.novox.be/novox/mesh-sdk/go\":\"v0.0.0-20261101000000-f469eb387a30\"},\"path\":\"modules/xclip\",\"repository\":\"novox/mesh-catalog\",\"toolchains\":{\"go\":{\"module\":\"mesh-build-go\",\"recipe\":\"1\",\"version\":\"1.26.0\"}},\"v\":1,\"verdict\":\"accepted\"}", wire: "{\"bases\":[\"arch\"],\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"fp\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"inputs\":{\"from\":{\"bases\":[\"arch\"],\"locks\":{\"go.sum\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\"},\"packages\":[\"git.novox.be/novox/mesh-sdk/go@v0.0.0-20261101000000-f469eb387a30\"],\"tree\":\"4b825dc642cb6eb9a060e54bf8d69288fbee4904\"},\"toolchains\":{\"go\":{\"language\":\"go\",\"recipe\":\"1\",\"version\":\"1.26.0\"}}},\"invokes\":[\"node-files.read\"],\"manifest\":{\"module\":\"xclip\",\"version\":\"1\"},\"manifest-digest\":\"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"module\":\"xclip\",\"packages\":{\"git.novox.be/novox/mesh-sdk/go\":\"v0.0.0-20261101000000-f469eb387a30\"},\"path\":\"modules/xclip\",\"repository\":\"novox/mesh-catalog\",\"toolchains\":{\"go\":{\"module\":\"mesh-build-go\",\"recipe\":\"1\",\"version\":\"1.26.0\"}},\"v\":1,\"verdict\":\"accepted\"}",
|
||||
{name: "a catalog graph entry (xclip)", subject: "", given: "{\"bases\":[\"arch\"],\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"consumes\":[\"node-engine.running.*.*\"],\"fp\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"inputs\":{\"from\":{\"bases\":[\"arch\"],\"locks\":{\"go.sum\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\"},\"packages\":[\"git.novox.be/novox/mesh-sdk/go@v0.0.0-20261101000000-f469eb387a30\"],\"tree\":\"4b825dc642cb6eb9a060e54bf8d69288fbee4904\"},\"toolchains\":{\"go\":{\"language\":\"go\",\"recipe\":\"1\",\"version\":\"1.26.0\"}}},\"invokes\":[\"node-files.read\"],\"manifest\":{\"module\":\"xclip\",\"version\":\"1\"},\"manifest-digest\":\"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"module\":\"xclip\",\"packages\":{\"git.novox.be/novox/mesh-sdk/go\":\"v0.0.0-20261101000000-f469eb387a30\"},\"path\":\"modules/xclip\",\"repository\":\"novox/mesh-catalog\",\"toolchains\":{\"go\":{\"module\":\"mesh-build-go\",\"recipe\":\"1\",\"version\":\"1.26.0\"}},\"v\":1,\"verdict\":\"accepted\"}", wire: "{\"bases\":[\"arch\"],\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"consumes\":[\"node-engine.running.*.*\"],\"fp\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"inputs\":{\"from\":{\"bases\":[\"arch\"],\"locks\":{\"go.sum\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\"},\"packages\":[\"git.novox.be/novox/mesh-sdk/go@v0.0.0-20261101000000-f469eb387a30\"],\"tree\":\"4b825dc642cb6eb9a060e54bf8d69288fbee4904\"},\"toolchains\":{\"go\":{\"language\":\"go\",\"recipe\":\"1\",\"version\":\"1.26.0\"}}},\"invokes\":[\"node-files.read\"],\"manifest\":{\"module\":\"xclip\",\"version\":\"1\"},\"manifest-digest\":\"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"module\":\"xclip\",\"packages\":{\"git.novox.be/novox/mesh-sdk/go\":\"v0.0.0-20261101000000-f469eb387a30\"},\"path\":\"modules/xclip\",\"repository\":\"novox/mesh-catalog\",\"toolchains\":{\"go\":{\"module\":\"mesh-build-go\",\"recipe\":\"1\",\"version\":\"1.26.0\"}},\"v\":1,\"verdict\":\"accepted\"}",
|
||||
decode: func(b []byte) (any, error) {
|
||||
var v CatalogRevisionsByEntryDigestValue
|
||||
err := json.Unmarshal(b, &v)
|
||||
@@ -99,7 +99,7 @@ func TestFixtures(t *testing.T) {
|
||||
err := json.Unmarshal(b, &v)
|
||||
return v, err
|
||||
}, subjectIs: nil},
|
||||
{name: "an entry with its artifacts and the edges into them, per artifact", subject: "", given: "{\"artifacts\":[{\"language\":\"go\",\"ref\":\"mesh-grants:program\"},{\"language\":\"go\",\"ref\":\"mesh-grants:tools\"}],\"bases\":[\"arch\"],\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"edges\":[{\"from\":\"mesh-grants:program\",\"kind\":6,\"to\":\"node-tools:runtime\",\"why\":\"seat mesh-grants verb grants\"},{\"from\":\"node-tools:runtime\",\"kind\":4,\"to\":\"mesh-grants:tools\",\"why\":\"the tool runner runs the tools\"},{\"from\":\"mesh-sdk:go\",\"kind\":1,\"to\":\"mesh-grants:program\",\"why\":\"git.novox.be/novox/mesh-sdk/go\"},{\"declared\":true,\"from\":\"nats:program\",\"kind\":4,\"to\":\"mesh-grants:program\",\"why\":\"declared in needs\"}],\"fp\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"inputs\":{\"from\":{\"bases\":[\"arch\"],\"locks\":{\"go.sum\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\"},\"packages\":[\"git.novox.be/novox/mesh-sdk/go@v0.0.0-20261101000000-f469eb387a30\"],\"tree\":\"4b825dc642cb6eb9a060e54bf8d69288fbee4904\"},\"toolchains\":{\"go\":{\"language\":\"go\",\"recipe\":\"1\",\"version\":\"1.26.0\"}}},\"invokes\":[\"node-files.read\"],\"manifest\":{\"module\":\"mesh-grants\",\"version\":\"1\"},\"module\":\"mesh-grants\",\"packages\":{\"git.novox.be/novox/mesh-sdk/go\":\"v0.0.0-20261101000000-f469eb387a30\"},\"path\":\"modules/xclip\",\"repository\":\"novox/mesh-catalog\",\"toolchains\":{\"go\":{\"module\":\"mesh-build-go\",\"recipe\":\"1\",\"version\":\"1.26.0\"}},\"v\":1,\"verdict\":\"accepted\"}", wire: "{\"artifacts\":[{\"language\":\"go\",\"ref\":\"mesh-grants:program\"},{\"language\":\"go\",\"ref\":\"mesh-grants:tools\"}],\"bases\":[\"arch\"],\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"edges\":[{\"from\":\"mesh-grants:program\",\"kind\":6,\"to\":\"node-tools:runtime\",\"why\":\"seat mesh-grants verb grants\"},{\"from\":\"node-tools:runtime\",\"kind\":4,\"to\":\"mesh-grants:tools\",\"why\":\"the tool runner runs the tools\"},{\"from\":\"mesh-sdk:go\",\"kind\":1,\"to\":\"mesh-grants:program\",\"why\":\"git.novox.be/novox/mesh-sdk/go\"},{\"declared\":true,\"from\":\"nats:program\",\"kind\":4,\"to\":\"mesh-grants:program\",\"why\":\"declared in needs\"}],\"fp\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"inputs\":{\"from\":{\"bases\":[\"arch\"],\"locks\":{\"go.sum\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\"},\"packages\":[\"git.novox.be/novox/mesh-sdk/go@v0.0.0-20261101000000-f469eb387a30\"],\"tree\":\"4b825dc642cb6eb9a060e54bf8d69288fbee4904\"},\"toolchains\":{\"go\":{\"language\":\"go\",\"recipe\":\"1\",\"version\":\"1.26.0\"}}},\"invokes\":[\"node-files.read\"],\"manifest\":{\"module\":\"mesh-grants\",\"version\":\"1\"},\"module\":\"mesh-grants\",\"packages\":{\"git.novox.be/novox/mesh-sdk/go\":\"v0.0.0-20261101000000-f469eb387a30\"},\"path\":\"modules/xclip\",\"repository\":\"novox/mesh-catalog\",\"toolchains\":{\"go\":{\"module\":\"mesh-build-go\",\"recipe\":\"1\",\"version\":\"1.26.0\"}},\"v\":1,\"verdict\":\"accepted\"}",
|
||||
{name: "an entry with its artifacts and the edges into them, per artifact", subject: "", given: "{\"artifacts\":[{\"digests\":[{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"package\":\"git.novox.be/novox/mesh-sdk/go/keys\"}],\"language\":\"go\",\"ref\":\"mesh-grants:program\"},{\"language\":\"go\",\"ref\":\"mesh-grants:tools\"}],\"bases\":[\"arch\"],\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"edges\":[{\"from\":\"mesh-grants:program\",\"kind\":6,\"to\":\"node-tools:runtime\",\"why\":\"seat mesh-grants verb grants\"},{\"from\":\"node-tools:runtime\",\"kind\":4,\"to\":\"mesh-grants:tools\",\"why\":\"the tool runner runs the tools\"},{\"from\":\"mesh-sdk:go\",\"kind\":1,\"to\":\"mesh-grants:program\",\"why\":\"git.novox.be/novox/mesh-sdk/go\"},{\"declared\":true,\"from\":\"nats:program\",\"kind\":4,\"to\":\"mesh-grants:program\",\"why\":\"declared in needs\"}],\"fp\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"inputs\":{\"from\":{\"bases\":[\"arch\"],\"locks\":{\"go.sum\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\"},\"packages\":[\"git.novox.be/novox/mesh-sdk/go@v0.0.0-20261101000000-f469eb387a30\"],\"tree\":\"4b825dc642cb6eb9a060e54bf8d69288fbee4904\"},\"toolchains\":{\"go\":{\"language\":\"go\",\"recipe\":\"1\",\"version\":\"1.26.0\"}}},\"invokes\":[\"node-files.read\"],\"manifest\":{\"module\":\"mesh-grants\",\"version\":\"1\"},\"module\":\"mesh-grants\",\"packages\":{\"git.novox.be/novox/mesh-sdk/go\":\"v0.0.0-20261101000000-f469eb387a30\"},\"path\":\"modules/xclip\",\"repository\":\"novox/mesh-catalog\",\"toolchains\":{\"go\":{\"module\":\"mesh-build-go\",\"recipe\":\"1\",\"version\":\"1.26.0\"}},\"v\":1,\"verdict\":\"accepted\"}", wire: "{\"artifacts\":[{\"digests\":[{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"package\":\"git.novox.be/novox/mesh-sdk/go/keys\"}],\"language\":\"go\",\"ref\":\"mesh-grants:program\"},{\"language\":\"go\",\"ref\":\"mesh-grants:tools\"}],\"bases\":[\"arch\"],\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"edges\":[{\"from\":\"mesh-grants:program\",\"kind\":6,\"to\":\"node-tools:runtime\",\"why\":\"seat mesh-grants verb grants\"},{\"from\":\"node-tools:runtime\",\"kind\":4,\"to\":\"mesh-grants:tools\",\"why\":\"the tool runner runs the tools\"},{\"from\":\"mesh-sdk:go\",\"kind\":1,\"to\":\"mesh-grants:program\",\"why\":\"git.novox.be/novox/mesh-sdk/go\"},{\"declared\":true,\"from\":\"nats:program\",\"kind\":4,\"to\":\"mesh-grants:program\",\"why\":\"declared in needs\"}],\"fp\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"inputs\":{\"from\":{\"bases\":[\"arch\"],\"locks\":{\"go.sum\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\"},\"packages\":[\"git.novox.be/novox/mesh-sdk/go@v0.0.0-20261101000000-f469eb387a30\"],\"tree\":\"4b825dc642cb6eb9a060e54bf8d69288fbee4904\"},\"toolchains\":{\"go\":{\"language\":\"go\",\"recipe\":\"1\",\"version\":\"1.26.0\"}}},\"invokes\":[\"node-files.read\"],\"manifest\":{\"module\":\"mesh-grants\",\"version\":\"1\"},\"module\":\"mesh-grants\",\"packages\":{\"git.novox.be/novox/mesh-sdk/go\":\"v0.0.0-20261101000000-f469eb387a30\"},\"path\":\"modules/xclip\",\"repository\":\"novox/mesh-catalog\",\"toolchains\":{\"go\":{\"module\":\"mesh-build-go\",\"recipe\":\"1\",\"version\":\"1.26.0\"}},\"v\":1,\"verdict\":\"accepted\"}",
|
||||
decode: func(b []byte) (any, error) {
|
||||
var v CatalogRevisionsByEntryDigestValue
|
||||
err := json.Unmarshal(b, &v)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user