Compare commits
90
Commits
go/v0.1.28
...
go/v0.1.46
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
93495203b5 | ||
|
|
5628ca2919 | ||
|
|
05c59ae000 | ||
|
|
e1630b57c6 | ||
|
|
5c4c4bc821 | ||
|
|
599bf62d23 | ||
|
|
0de195c5aa | ||
|
|
3160bb1fb8 | ||
|
|
93efda5db3 | ||
|
|
f01731fd4e | ||
|
|
251745f859 | ||
|
|
d1ec9d9072 | ||
|
|
14254dd0ba | ||
|
|
1e50642e3c | ||
|
|
b0082ec04f | ||
|
|
6b6e4c81f0 | ||
|
|
374d060cc0 | ||
|
|
1f878eec58 | ||
|
|
c9515da86f | ||
|
|
5f7137e676 | ||
|
|
902947a044 | ||
|
|
b95b3ef989 | ||
|
|
0f167db73d | ||
|
|
e5f54c5cdb | ||
|
|
bdb4edd820 | ||
|
|
31c2c5c7fe | ||
|
|
ad0052c6f5 | ||
|
|
aef8632d95 | ||
|
|
dedcc3ead7 | ||
|
|
a40bbec44a | ||
|
|
fe6c5961ae | ||
|
|
588a6ff8d5 | ||
|
|
ced27928d9 | ||
|
|
2cb6971194 | ||
|
|
6a730c33e6 | ||
|
|
d1aab1d08d | ||
|
|
c6b4b6054b | ||
|
|
4df45a3793 | ||
|
|
e2e13ddd29 | ||
|
|
dcf5b7fa8f | ||
|
|
1fe6ade359 | ||
|
|
9e09767a4b | ||
|
|
59443ab3f7 | ||
|
|
92d0ab8602 | ||
|
|
3a31331ad3 | ||
|
|
d1581666d2 | ||
|
|
d4d7895392 | ||
|
|
d6c209a10c | ||
|
|
51ac838732 | ||
|
|
06a52a10e0 | ||
|
|
773e2e33a1 | ||
|
|
d817d85fca | ||
|
|
6d5000871d | ||
|
|
5c7648744d | ||
|
|
8802f16019 | ||
|
|
6087306dfd | ||
|
|
667aa87611 | ||
|
|
0f2fd1a171 | ||
|
|
e1ce5cc8ed | ||
|
|
7794ee9d2d | ||
|
|
396893dcac | ||
|
|
626a6fb358 | ||
|
|
20ee1cae7b | ||
|
|
671dc5a963 | ||
|
|
3f62410c22 | ||
|
|
4af1ba99cf | ||
|
|
91b5e8d086 | ||
|
|
189d75ad40 | ||
|
|
595510ef38 | ||
|
|
04f54d7773 | ||
|
|
07dc14bf53 | ||
|
|
9b3a728f9e | ||
|
|
83e4470757 | ||
|
|
1b1fd9a711 | ||
|
|
47ea130332 | ||
|
|
52f7a5b6f6 | ||
|
|
aee7e4c26c | ||
|
|
64d5490ea2 | ||
|
|
7199824e9d | ||
|
|
c418f49038 | ||
|
|
e29aa8aca9 | ||
|
|
64cba95a10 | ||
|
|
cb26645614 | ||
|
|
b0d2d22002 | ||
|
|
014f7b7c2f | ||
|
|
0fcc614e25 | ||
|
|
e3fed77515 | ||
|
|
94202fb651 | ||
|
|
0418a2b94b | ||
|
|
a926a40eed |
@@ -216,7 +216,7 @@ type runPrep struct {
|
||||
seats []json.RawMessage
|
||||
manifests map[string]composer.Manifest
|
||||
none map[string]string
|
||||
programOf func(node string) (buildstep.RunProgram, string, error)
|
||||
programOf func(node string) (buildstep.RunProgram, string, map[string]string, error)
|
||||
err error
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ func (r *compositionRun) start(ctx context.Context, key string, run meshwants.Co
|
||||
end(node + " gave no composition input: " + in.Why)
|
||||
return
|
||||
}
|
||||
program, engineFp, err := prep.programOf(node)
|
||||
program, engineFp, pins, err := prep.programOf(node)
|
||||
if err != nil {
|
||||
end(node + ": " + err.Error())
|
||||
return
|
||||
@@ -317,7 +317,8 @@ func (r *compositionRun) start(ctx context.Context, key string, run meshwants.Co
|
||||
return
|
||||
}
|
||||
a := buildstep.StepAsk{ID: ask, Kind: buildstep.AskCheck, Language: buildstep.AskGo, Asker: runAsker, At: r.now().UTC(),
|
||||
Run: &buildstep.RunJob{Program: program, Heads: []buildstep.RunHead{}, Input: ref, Reader: "the composition of " + node + " by the node-engine at " + program.Commit}}
|
||||
Run: &buildstep.RunJob{Program: program, Heads: []buildstep.RunHead{}, Input: ref, Reader: "the composition of " + node + " by the node-engine at " + program.Commit},
|
||||
Packages: pins} // the composer is built against its entry's pins, as every build (H-A-203, H-A-192)
|
||||
if err := r.put(ctx, a); err != nil {
|
||||
end(node + ": its run ask " + ask + " is not put: " + err.Error())
|
||||
}
|
||||
@@ -732,53 +733,76 @@ func programOfEntry(e meshcatalog.CatalogEntry) (buildstep.RunProgram, error) {
|
||||
return buildstep.RunProgram{Repository: e.Repository, Commit: e.Commit, Dir: dir, Package: composer.Package}, nil
|
||||
}
|
||||
|
||||
// pinsOfEntry are the mesh packages' versions an entry pins, the ones it names with a version (H-A-203, H-A-183): the pins
|
||||
// a run's program is built against, in the form the entry keeps and the builder sends. nil when it pins none.
|
||||
func pinsOfEntry(e meshcatalog.CatalogEntry) map[string]string {
|
||||
var out map[string]string
|
||||
for path, version := range e.Packages {
|
||||
if version == "" {
|
||||
continue
|
||||
}
|
||||
if out == nil {
|
||||
out = map[string]string{}
|
||||
}
|
||||
out[path] = version
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// programs answers, per machine, the composer its run builds and the node-engine fingerprint it was chosen from (A-226, A-243,
|
||||
// A-252, §719): where the revision's node-engine entry differs from the trunk's, that build for every machine; else the build the
|
||||
// machine's node-engine runs, as its `running` says, its entry read through mesh-catalog's `entry`; a machine whose node-engine's
|
||||
// `running` is not heard gets the revision's entry, said (A-451).
|
||||
func (r *compositionRun) programs(ctx context.Context, half mcc.Half) (func(node string) (buildstep.RunProgram, string, error), error) {
|
||||
func (r *compositionRun) programs(ctx context.Context, half mcc.Half) (func(node string) (buildstep.RunProgram, string, map[string]string, error), error) {
|
||||
engine, ok := nodeEngineEntry(half.Entries)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("the catalog revision %d holds no module claiming the seat %s", half.Revision.Revision, ne.Seat)
|
||||
}
|
||||
if trunk, ok := r.trunk(); !ok || func() bool { t, ok := nodeEngineEntry(trunk.Entries); return !ok || t.Fp != engine.Fp }() {
|
||||
p, err := programOfEntry(engine)
|
||||
return func(string) (buildstep.RunProgram, string, error) { return p, engine.Fp, err }, nil
|
||||
return func(string) (buildstep.RunProgram, string, map[string]string, error) {
|
||||
return p, engine.Fp, pinsOfEntry(engine), err
|
||||
}, nil
|
||||
}
|
||||
var mu sync.Mutex
|
||||
byFp := map[string]buildstep.RunProgram{}
|
||||
return func(node string) (buildstep.RunProgram, string, error) {
|
||||
type built struct {
|
||||
program buildstep.RunProgram
|
||||
pins map[string]string
|
||||
}
|
||||
byFp := map[string]built{}
|
||||
return func(node string) (buildstep.RunProgram, string, map[string]string, error) {
|
||||
running, ok := r.running(node, engine.Module)
|
||||
if !ok || running.Fingerprint == "" {
|
||||
r.logf("%s: no build of %s is heard running there, so its composer is the catalog revision's entry %s (A-451)", node,
|
||||
engine.Module, engine.Fp)
|
||||
p, err := programOfEntry(engine)
|
||||
return p, engine.Fp, err
|
||||
return p, engine.Fp, pinsOfEntry(engine), err
|
||||
}
|
||||
fp := running.Fingerprint
|
||||
mu.Lock()
|
||||
p, ok := byFp[fp]
|
||||
b, ok := byFp[fp]
|
||||
mu.Unlock()
|
||||
if ok {
|
||||
return p, fp, nil
|
||||
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})
|
||||
if err != nil || body == nil {
|
||||
return buildstep.RunProgram{}, fp, unreadErr(what, err, said)
|
||||
return buildstep.RunProgram{}, fp, nil, unreadErr(what, err, said)
|
||||
}
|
||||
var a meshcatalog.EntryAnswer
|
||||
if err := json.Unmarshal(body, &a); err != nil {
|
||||
return buildstep.RunProgram{}, fp, fmt.Errorf("%s: %w", what, err)
|
||||
return buildstep.RunProgram{}, fp, nil, fmt.Errorf("%s: %w", what, err)
|
||||
}
|
||||
p, err = programOfEntry(a.Entry)
|
||||
p, err := programOfEntry(a.Entry)
|
||||
if err != nil {
|
||||
return p, fp, err
|
||||
return p, fp, nil, err
|
||||
}
|
||||
pins := pinsOfEntry(a.Entry)
|
||||
mu.Lock()
|
||||
byFp[fp] = p
|
||||
byFp[fp] = built{program: p, pins: pins}
|
||||
mu.Unlock()
|
||||
return p, fp, nil
|
||||
return p, fp, pins, nil
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ func newRunStand(t *testing.T, revisionEngine, trunkEngine, seatDigest string) *
|
||||
s := &runStand{asks: map[string]buildstep.StepAsk{}, requests: map[string]composer.Request{}}
|
||||
engine := func(fp, commit string) meshcatalog.CatalogEntry {
|
||||
return meshcatalog.CatalogEntry{Module: "engine", Fp: fp, Repository: "novox/mesh-host", Commit: commit, Path: ".", Serves: []string{ne.Seat + ".composition"},
|
||||
Manifest: map[string]any{"module": "engine"}}
|
||||
Manifest: map[string]any{"module": "engine"}, Packages: map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.25-" + fp, "git.novox.be/novox/x/go": ""}}
|
||||
}
|
||||
revisionCommit := commitE1
|
||||
if revisionEngine != "src2:e1" {
|
||||
@@ -186,6 +186,13 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) {
|
||||
if s.asks["g14"].Run.Program.Commit != commitE2 {
|
||||
t.Errorf("g14's composer is built at %s, want the build its node-engine runs", s.asks["g14"].Run.Program.Commit)
|
||||
}
|
||||
// Each composer is built against the pins of the node-engine entry it is built from, a pin with no version left out
|
||||
// (H-A-203, H-A-192).
|
||||
for node, fp := range map[string]string{"ace": "src2:e1", "g14": "src2:e2"} {
|
||||
if got := s.asks[node].Packages; len(got) != 1 || got["git.novox.be/novox/mesh-sdk/go"] != "v0.1.25-"+fp {
|
||||
t.Errorf("%s's composer is built against the pins %v; want its entry's", node, got)
|
||||
}
|
||||
}
|
||||
if req.Depth != composer.DepthCompose || req.BlameTries != 20 || len(req.Machines) != 1 || req.Machines[0] != "ace" || len(req.Cases) != 1 || req.Cases[0].Name != changeCase ||
|
||||
string(req.Input) != `{"node":"ace"}` || len(req.Seats) != 1 || string(req.Seats[0]) != `{"seat":"s1"}` {
|
||||
t.Errorf("the request of ace %+v", req)
|
||||
|
||||
@@ -15,7 +15,21 @@ import (
|
||||
|
||||
// fillOf is the store's fill now: its bytes and cap, when the bucket says them and has a cap.
|
||||
func (g *graphKeeper) fillOf(ctx context.Context) (used, capacity int64, ok bool) {
|
||||
f, is := g.objects.(assigngraph.Filler)
|
||||
return fillIn(ctx, g.objects)
|
||||
}
|
||||
|
||||
// passObjects is the store as the pass reads its fill: a handle of its own where one is given, so the pass's read never shares one
|
||||
// with a keeping that runs beside it (design 47 H-A-261).
|
||||
func (g *graphKeeper) passObjects() assigngraph.Objects {
|
||||
if g.reads != nil {
|
||||
return g.reads
|
||||
}
|
||||
return g.objects
|
||||
}
|
||||
|
||||
// fillIn is the fill of the bucket o, when it says one and has a cap.
|
||||
func fillIn(ctx context.Context, o assigngraph.Objects) (used, capacity int64, ok bool) {
|
||||
f, is := o.(assigngraph.Filler)
|
||||
if !is {
|
||||
return 0, 0, false
|
||||
}
|
||||
@@ -35,13 +49,13 @@ func (p *passer) sayFill(event, about string, used, capacity int64, refused stri
|
||||
// its cap), so a fill reached while the process was down is said too.
|
||||
func (p *passer) fillAtStart(ctx context.Context) {
|
||||
g := p.graph
|
||||
used, capacity, ok := g.fillOf(ctx)
|
||||
used, capacity, ok := fillIn(ctx, g.passObjects())
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
switch {
|
||||
case used >= capacity:
|
||||
g.full = true
|
||||
g.setFull(true)
|
||||
p.sayFill(meshwants.EventFull, "start", used, capacity, "the next revision")
|
||||
case used*5 >= capacity*4:
|
||||
p.sayFill(meshwants.EventFilling, "start", used, capacity, "")
|
||||
@@ -52,20 +66,20 @@ func (p *passer) fillAtStart(ctx context.Context) {
|
||||
// 80 % again. It answers true while the store is full.
|
||||
func (p *passer) fullBefore(ctx context.Context, c assigngraph.Computed) bool {
|
||||
g := p.graph
|
||||
used, capacity, ok := g.fillOf(ctx)
|
||||
used, capacity, ok := fillIn(ctx, g.passObjects())
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
if g.full && used*5 < capacity*4 {
|
||||
g.full = false
|
||||
if g.isFull() && used*5 < capacity*4 {
|
||||
g.setFull(false)
|
||||
p.sayFill(meshwants.EventRoom, fmt.Sprint(used), used, capacity, "")
|
||||
}
|
||||
if used+assigngraph.NewBytes(ctx, g.objects, c) <= capacity {
|
||||
g.full = false
|
||||
if used+assigngraph.NewBytes(ctx, g.passObjects(), c) <= capacity {
|
||||
g.setFull(false)
|
||||
return false
|
||||
}
|
||||
if !g.full {
|
||||
g.full = true
|
||||
if !g.isFull() {
|
||||
g.setFull(true)
|
||||
p.sayFill(meshwants.EventFull, fmt.Sprint(used), used, capacity, "the next revision")
|
||||
}
|
||||
p.logf("the assignment graph revision is not kept: %s is full (%d of %d bytes), the last revision stays and no want is written until there is room", assigngraph.RevisionsObjects, used, capacity)
|
||||
|
||||
@@ -61,14 +61,14 @@ func TestTheAssignmentGraphStoreSaysFillingFullAndRoom(t *testing.T) {
|
||||
if len(events) != 0 {
|
||||
t.Fatalf("events %v", events)
|
||||
}
|
||||
o.base = 700
|
||||
o.base, o.cap = 8500, 10000 // past 80 %, with room for the next revision, which the pass judges itself (H-A-261)
|
||||
p.graph.started = false
|
||||
p.keepGraph(ctx)
|
||||
p.keepGraph(ctx) // a start again: its first pass judges the fill
|
||||
if len(events) != 1 || events[0] != meshwants.EventFilling {
|
||||
t.Fatalf("at the start past 80 %%: %v", events)
|
||||
}
|
||||
c := assigngraph.Computed{Revision: meshwants.AssignmentRevision{Entries: []meshwants.NodeEntryRef{}}}
|
||||
o.base = 990
|
||||
o.base, o.cap = 990, 1000
|
||||
if !p.fullBefore(ctx, c) || !p.graph.full || events[len(events)-1] != meshwants.EventFull {
|
||||
t.Fatalf("a revision that does not fit: events %v", events)
|
||||
}
|
||||
@@ -76,8 +76,15 @@ func TestTheAssignmentGraphStoreSaysFillingFullAndRoom(t *testing.T) {
|
||||
if n := len(events); n != 2 {
|
||||
t.Errorf("full is said once: %v", events)
|
||||
}
|
||||
// H-A-261: the verdict is the pass's own: with the store full the pass writes no want, though a revision is kept.
|
||||
if held := p.keepGraph(ctx); held != heldFull {
|
||||
t.Errorf("a pass with the store full answers %q, want %q", held, heldFull)
|
||||
}
|
||||
o.base = 100
|
||||
if p.fullBefore(ctx, c) || p.graph.full || events[len(events)-1] != meshwants.EventRoom {
|
||||
t.Errorf("room: events %v", events)
|
||||
}
|
||||
if held := p.keepGraph(ctx); held != "" {
|
||||
t.Errorf("a pass with room and a revision kept answers %q, want the wants written", held)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
@@ -24,11 +25,18 @@ import (
|
||||
// that follows are written from the revision it holds.
|
||||
type graphKeeper struct {
|
||||
objects assigngraph.Objects
|
||||
// reads is the same store through a handle of the pass's own, for the pass's read of its fill (graphfill.go); nil reads objects.
|
||||
reads assigngraph.Objects
|
||||
// halves is every followed branch's catalog graph revision held now.
|
||||
halves func() map[string]mcc.Half
|
||||
// last is the revision last computed, so a pass whose inputs did not change keeps and says nothing.
|
||||
last meshwants.AssignmentRevision
|
||||
has bool
|
||||
// mu guards what the keeping writes and the pass reads: the revision kept, full, and the need handed over (design 47 H-A-259).
|
||||
mu sync.Mutex
|
||||
// handedRev is the revision last handed to the keeping, so a pass whose inputs did not change hands nothing; handed is false
|
||||
// until one is, and again when its keeping failed or found the store full, so the next pass hands it again.
|
||||
handedRev meshwants.AssignmentRevision
|
||||
handed bool
|
||||
// handedOnce says a revision was handed: the first carries the start's removal (H-A-261).
|
||||
handedOnce bool
|
||||
// kept is the revision the wants follow, and kept's source the trunk's source revision it carries; ok is false until one is kept.
|
||||
kept meshwants.AssignmentRevision
|
||||
source int64
|
||||
@@ -40,13 +48,55 @@ type graphKeeper struct {
|
||||
revisions *revisionRemover
|
||||
// computed is the revision computed by the last pass, with its entries: its edges.
|
||||
computed assigngraph.Computed
|
||||
// The keeping off the pass loop (H-A-259): need is what waits to be kept, keeping says one runs; background runs it (nil: at
|
||||
// once, in the caller), and wake makes a pass once a keeping changed what the pass reads.
|
||||
need *keepNeed
|
||||
keeping bool
|
||||
background func(func())
|
||||
wake func()
|
||||
}
|
||||
|
||||
// keepGraph computes the revision of this pass and keeps it when the pass's inputs differ from the last computed.
|
||||
func (p *passer) keepGraph(ctx context.Context) {
|
||||
// keepNeed is one need of the keeping: a computed revision to keep (nil: none), and whether the revisions not current are judged.
|
||||
type keepNeed struct {
|
||||
c *assigngraph.Computed
|
||||
judge bool
|
||||
}
|
||||
|
||||
// keptNow is the revision the wants follow, with its trunk source, and whether one is kept.
|
||||
func (g *graphKeeper) keptNow() (meshwants.AssignmentRevision, int64, bool) {
|
||||
g.mu.Lock()
|
||||
defer g.mu.Unlock()
|
||||
return g.kept, g.source, g.ok
|
||||
}
|
||||
|
||||
// isFull says the store did not hold the last revision handed over, so no want is written (design 47 G §181).
|
||||
func (g *graphKeeper) isFull() bool {
|
||||
g.mu.Lock()
|
||||
defer g.mu.Unlock()
|
||||
return g.full
|
||||
}
|
||||
|
||||
func (g *graphKeeper) setFull(full bool) {
|
||||
g.mu.Lock()
|
||||
g.full = full
|
||||
g.mu.Unlock()
|
||||
}
|
||||
|
||||
// heldNoRevision is the pass's words while no assignment graph revision is kept: it writes no want (design 47 H-A-261).
|
||||
const heldNoRevision = "held: no assignment graph revision is kept yet, so no want is written until the first keeping ends (H-A-261)"
|
||||
|
||||
// heldFull is the pass's words while the next revision does not fit its store (design 47 G §181).
|
||||
const heldFull = "the assignment graph store is full: no want is written (design 47 G §181)"
|
||||
|
||||
// keepGraph computes the revision of this pass, judges the store's fill itself, and hands the revision to the keeping when the
|
||||
// pass's inputs differ from the last handed. The keeping and the removing of revisions run off the pass loop, one at a time, and the
|
||||
// pass never waits on them: it judges and writes the wants from the graph it holds (design 47 H-A-259). It answers why the pass
|
||||
// writes no want, or "" when it writes them: none while the next revision does not fit the store (G §181), and none while no
|
||||
// revision is kept (H-A-261), whose keeping wakes a pass when it ends.
|
||||
func (p *passer) keepGraph(ctx context.Context) string {
|
||||
g := p.graph
|
||||
if g == nil || g.objects == nil || g.halves == nil {
|
||||
return
|
||||
return ""
|
||||
}
|
||||
c := assigngraph.Compute(p.graphInputs())
|
||||
g.computed = c
|
||||
@@ -56,40 +106,130 @@ func (p *passer) keepGraph(ctx context.Context) {
|
||||
p.logf("the assignment graph leaves out %s", u)
|
||||
}
|
||||
}
|
||||
if !g.started {
|
||||
if !g.started { // the first pass judges the fill once (graphfill.go)
|
||||
g.started = true
|
||||
p.fillAtStart(ctx)
|
||||
}
|
||||
if g.has && g.ok && assigngraph.Same(g.last, c.Revision) {
|
||||
if p.fullBefore(ctx, c) {
|
||||
g.mu.Lock()
|
||||
g.handed = false // handed once it fits
|
||||
g.mu.Unlock()
|
||||
return heldFull
|
||||
}
|
||||
g.mu.Lock()
|
||||
same := g.handed && assigngraph.Same(g.handedRev, c.Revision)
|
||||
first := !g.handedOnce
|
||||
if !same {
|
||||
g.handedRev, g.handed, g.handedOnce = c.Revision, true, true
|
||||
}
|
||||
g.mu.Unlock()
|
||||
if !same {
|
||||
// The start's removal of the revisions not current folds into the first keeping: it keeps the first pass's revision, then
|
||||
// removes (H-A-261).
|
||||
p.needKeeping(ctx, keepNeed{c: &c, judge: first})
|
||||
}
|
||||
if _, _, ok := g.keptNow(); !ok {
|
||||
return heldNoRevision
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// needKeeping hands a need to the keeping: one keeping runs at a time, and a need that comes while one runs is folded into the one
|
||||
// that waits (the newest revision, and a judging asked by either), so it runs once more (design 47 H-A-259).
|
||||
func (p *passer) needKeeping(ctx context.Context, n keepNeed) {
|
||||
g := p.graph
|
||||
g.mu.Lock()
|
||||
if w := g.need; w != nil {
|
||||
n.judge = n.judge || w.judge
|
||||
if n.c == nil {
|
||||
n.c = w.c
|
||||
}
|
||||
}
|
||||
g.need = &n
|
||||
if g.keeping {
|
||||
g.mu.Unlock()
|
||||
return
|
||||
}
|
||||
g.keeping = true
|
||||
g.mu.Unlock()
|
||||
run := func() {
|
||||
for {
|
||||
g.mu.Lock()
|
||||
next := g.need
|
||||
g.need = nil
|
||||
if next == nil {
|
||||
g.keeping = false
|
||||
g.mu.Unlock()
|
||||
return
|
||||
}
|
||||
g.mu.Unlock()
|
||||
p.keepOne(ctx, *next)
|
||||
}
|
||||
}
|
||||
if g.background != nil {
|
||||
g.background(run)
|
||||
return
|
||||
}
|
||||
run()
|
||||
}
|
||||
|
||||
// keepOne keeps one computed revision, says assignment-revision for a revision kept now and removes the
|
||||
// revisions that ceased to be current; it says its duration in the journal, and wakes a pass when it changed what the pass reads.
|
||||
func (p *passer) keepOne(ctx context.Context, n keepNeed) {
|
||||
g := p.graph
|
||||
start := time.Now()
|
||||
changed := false
|
||||
defer func() {
|
||||
p.logf("the keeping of the assignment graph took %s", time.Since(start).Round(time.Millisecond))
|
||||
if changed && g.background != nil && g.wake != nil {
|
||||
g.wake()
|
||||
}
|
||||
}()
|
||||
if n.c != nil {
|
||||
_, _, had := g.keptNow()
|
||||
fresh := p.keepRevision(ctx, *n.c)
|
||||
_, _, has := g.keptNow()
|
||||
n.judge = n.judge || fresh
|
||||
changed = fresh || had != has // the first revision kept: the pass writes the wants it held (H-A-261)
|
||||
}
|
||||
if n.judge && g.revisions != nil {
|
||||
g.revisions.judge() // the revision before ceased to be current
|
||||
}
|
||||
}
|
||||
|
||||
// keepRevision keeps c when the store holds it, and says whether a revision was kept now.
|
||||
func (p *passer) keepRevision(ctx context.Context, c assigngraph.Computed) bool {
|
||||
g := p.graph
|
||||
again := func() { // the next pass hands this revision again
|
||||
g.mu.Lock()
|
||||
g.handed = false
|
||||
g.mu.Unlock()
|
||||
}
|
||||
used, _, _ := g.fillOf(ctx)
|
||||
if p.fullBefore(ctx, c) {
|
||||
return
|
||||
}
|
||||
rev, fresh, err := assigngraph.Keep(ctx, g.objects, c, meshwants.EventAssignmentRevision, p.clock())
|
||||
if err != nil {
|
||||
p.logf("the assignment graph revision is not kept, so no want is said as wanted until it is: %v", err)
|
||||
return
|
||||
again()
|
||||
return false
|
||||
}
|
||||
g.last, g.has, g.kept, g.ok = c.Revision, true, rev, true
|
||||
g.source = 0
|
||||
var source int64
|
||||
for _, cat := range rev.Catalogs {
|
||||
if cat.Branch == p.w.trunkName() {
|
||||
g.source = cat.Source
|
||||
source = cat.Source
|
||||
}
|
||||
}
|
||||
g.mu.Lock()
|
||||
g.kept, g.ok, g.source = rev, true, source
|
||||
g.mu.Unlock()
|
||||
if !fresh {
|
||||
return
|
||||
return false
|
||||
}
|
||||
p.fillingAfter(ctx, used)
|
||||
if g.revisions != nil {
|
||||
g.revisions.judge() // the revision before ceased to be current
|
||||
}
|
||||
id := fmt.Sprintf("%s-%s-%d", meshwants.EventAssignmentRevision, rev.Kind, rev.Revision)
|
||||
if err := p.wantsSay(meshwants.EventAssignmentRevision, assigngraph.Event(rev), id); err != nil {
|
||||
p.logf("the assignment revision %d is kept but not said: %v", rev.Revision, err)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// graphInputs are what the pass's assignment graph is computed from: every followed branch's catalog half, the placements, each
|
||||
@@ -147,14 +287,20 @@ func (p *passer) sayWanted(node, module, fp, pipeline string, removed bool) {
|
||||
return
|
||||
}
|
||||
g := p.graph
|
||||
if g == nil || !g.ok {
|
||||
var kept meshwants.AssignmentRevision
|
||||
var source int64
|
||||
ok := false
|
||||
if g != nil {
|
||||
kept, source, ok = g.keptNow()
|
||||
}
|
||||
if !ok {
|
||||
p.logf("the want of %s on %s is written, but no assignment graph revision is kept, so wanted is not said", module, node)
|
||||
return
|
||||
}
|
||||
at := p.clock().UTC()
|
||||
body := meshwants.WantedEvent{V: keys.Version, Node: node, Module: module, Fp: fp, Pipeline: pipeline, Removed: removed, Revision: g.kept.Revision, Source: g.source, At: &at}
|
||||
body := meshwants.WantedEvent{V: keys.Version, Node: node, Module: module, Fp: fp, Pipeline: pipeline, Removed: removed, Revision: kept.Revision, Source: source, At: &at}
|
||||
event := strings.TrimPrefix(meshwants.SubjectWanted(keys.EscapeName(node), keys.EscapeName(module)), "mesh.seat."+meshwants.Seat+".event.")
|
||||
id := fmt.Sprintf("wanted.%s.%s.%s.%t.%d.%s", keys.EscapeName(node), keys.EscapeName(module), fp, removed, g.kept.Revision, at.Format(time.RFC3339Nano))
|
||||
id := fmt.Sprintf("wanted.%s.%s.%s.%t.%d.%s", keys.EscapeName(node), keys.EscapeName(module), fp, removed, kept.Revision, at.Format(time.RFC3339Nano))
|
||||
if err := p.wantsSay(event, body, id); err != nil {
|
||||
p.logf("wanted of %s on %s is not said: %v", module, node, err)
|
||||
}
|
||||
@@ -185,7 +331,7 @@ func (p *passer) namedBuild(module, trunkFP string, unreleased ...bool) func(fp
|
||||
// the mesh-sdk merge moved its fingerprint).
|
||||
return p.w.released.withParts(module, p.w.ends.madeOf(module, fp))
|
||||
}
|
||||
if p.graph == nil || !p.graph.ok {
|
||||
if _, _, kept := p.graphKept(); !kept {
|
||||
p.unheardRelease(module, fp, "no assignment graph revision is kept yet, so no release is looked up")
|
||||
return assign.KeptBuild{}, false
|
||||
}
|
||||
@@ -212,3 +358,11 @@ func (p *passer) unheardRelease(module, fp, why string) {
|
||||
p.logf("the release of %s at fingerprint %s is not heard: %s; its wants and candidates carry no version and no parts", module, fp, why)
|
||||
}
|
||||
}
|
||||
|
||||
// graphKept is the revision the wants follow, with its trunk source, and whether one is kept; with no graph kept, none is.
|
||||
func (p *passer) graphKept() (meshwants.AssignmentRevision, int64, bool) {
|
||||
if p.graph == nil {
|
||||
return meshwants.AssignmentRevision{}, 0, false
|
||||
}
|
||||
return p.graph.keptNow()
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -12,7 +14,9 @@ import (
|
||||
mcc "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"
|
||||
mpr "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
|
||||
"mesh-delivery-assigner/internal/assigngraph"
|
||||
"mesh-delivery-assigner/internal/buckets"
|
||||
@@ -132,3 +136,141 @@ func TestTheWantsAreSaidWantedFromTheKeptAssignmentGraphRevision(t *testing.T) {
|
||||
t.Errorf("dropping the run's candidate dropped trunk: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// blockedObjects is an object bucket whose listing waits while a gate stands: a keeping that does not end until it is opened.
|
||||
type blockedObjects struct {
|
||||
memObjects
|
||||
mu sync.Mutex
|
||||
gate chan struct{}
|
||||
}
|
||||
|
||||
func (b *blockedObjects) Names(ctx context.Context) ([]string, error) {
|
||||
b.mu.Lock()
|
||||
gate := b.gate
|
||||
b.mu.Unlock()
|
||||
if gate != nil {
|
||||
<-gate
|
||||
}
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
return b.memObjects.Names(ctx)
|
||||
}
|
||||
|
||||
func (b *blockedObjects) Put(ctx context.Context, name string, data []byte) error {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
return b.memObjects.Put(ctx, name, data)
|
||||
}
|
||||
|
||||
func (b *blockedObjects) Get(ctx context.Context, name string) ([]byte, error) {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
return b.memObjects.Get(ctx, name)
|
||||
}
|
||||
|
||||
// block stands a gate, opened by the function it answers.
|
||||
func (b *blockedObjects) block() func() {
|
||||
gate := make(chan struct{})
|
||||
b.mu.Lock()
|
||||
b.gate = gate
|
||||
b.mu.Unlock()
|
||||
return func() {
|
||||
b.mu.Lock()
|
||||
b.gate = nil
|
||||
b.mu.Unlock()
|
||||
close(gate)
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 H-A-259, H-A-261: the keeping of the assignment graph runs off the pass loop. At the start, while the first keeping is
|
||||
// blocked, a pass returns and writes no want; the keeping's end wakes a pass, which writes the passed pipeline's want. Later, while a
|
||||
// keeping of new inputs is blocked, a pass writes the wants from the revision it holds, and a pass of the same inputs hands nothing
|
||||
// more. Each pass and each keeping says its duration.
|
||||
func TestAPassWritesWantsWhileAKeepingIsBlocked(t *testing.T) {
|
||||
fp := mcc.SourcePrefix2 + strings.Repeat("a", 64)
|
||||
wantsKV := &memKV{values: map[string][]byte{}}
|
||||
p := newPasser(kvSet{buckets.Wants(): wantsKV, buckets.Asks(): &memKV{values: map[string][]byte{}}}, time.Now())
|
||||
var mu sync.Mutex
|
||||
var journal strings.Builder
|
||||
p.logf = func(f string, a ...any) { mu.Lock(); fmt.Fprintf(&journal, f+"\n", a...); mu.Unlock() }
|
||||
said := func(words string) bool {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
return strings.Contains(journal.String(), words)
|
||||
}
|
||||
mdigest := strings.Repeat("e", 64)
|
||||
mod, _ := mcc.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: fp, Manifest: mdigest, Repository: "novox/web", Commit: strings.Repeat("1", 40), Path: mcc.RootPath})
|
||||
putModuleRaw(p.w, trunkBranch, "web", mod)
|
||||
p.w.manifests[mdigest] = parsed{module: "web", manifest: catalogue.Manifest{Module: "web"}}
|
||||
placeOn(t, p.w, "ace", "web")
|
||||
p.ends = newPipelineEnds(newMemEnds(), func() {}, t.Logf)
|
||||
p.ends.trunk = p.w.trunkName
|
||||
_, _ = p.ends.take(ended(trunkBranch, 5, mpr.PipelineEndedOutcomePassed, mover("web", fp, "0.1.2", 1, mpr.StepResultOutcomePassed)))
|
||||
objects := &blockedObjects{memObjects: memObjects{}}
|
||||
var kept sync.WaitGroup
|
||||
woke := make(chan struct{}, 8)
|
||||
half := mcc.Half{Revision: meshcatalog.CatalogRevision{Branch: trunkBranch, Kind: "trunk", Revision: 4, Source: 9,
|
||||
Entries: []meshcatalog.EntryRef{{Module: "web", Digest: "sha256:" + strings.Repeat("a", 64)}}},
|
||||
Entries: map[string]meshcatalog.CatalogEntry{"web": {Module: "web", Fp: fp}}}
|
||||
p.graph = &graphKeeper{objects: objects, halves: func() map[string]mcc.Half { return map[string]mcc.Half{trunkBranch: half} },
|
||||
background: func(f func()) { kept.Go(f) }, wake: func() { woke <- struct{}{} }}
|
||||
pass := func() {
|
||||
t.Helper()
|
||||
done := make(chan struct{})
|
||||
go func() { p.pass(context.Background()); close(done) }()
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(10 * time.Second):
|
||||
t.Fatal("the pass waits on the keeping of the assignment graph")
|
||||
}
|
||||
}
|
||||
wantOf := func(node string) (mwc.Want, error) {
|
||||
key, _ := mwc.WantKey(node, "web")
|
||||
return mwc.DecodeWant(wantsKV.values[key])
|
||||
}
|
||||
open := objects.block()
|
||||
t.Cleanup(func() { // the keeping ends before the test does, and says its duration
|
||||
objects.mu.Lock()
|
||||
standing := objects.gate != nil
|
||||
objects.mu.Unlock()
|
||||
if standing {
|
||||
open()
|
||||
}
|
||||
kept.Wait()
|
||||
if !said("the keeping of the assignment graph took ") {
|
||||
t.Error("the keeping does not say its duration")
|
||||
}
|
||||
})
|
||||
|
||||
pass() // the start: the first keeping is blocked
|
||||
if _, err := wantOf("ace"); err == nil {
|
||||
t.Error("a pass at the start wrote a want before an assignment graph revision is kept")
|
||||
}
|
||||
open()
|
||||
select {
|
||||
case <-woke:
|
||||
case <-time.After(10 * time.Second):
|
||||
t.Fatal("the first keeping's end wakes no pass")
|
||||
}
|
||||
pass()
|
||||
if w, err := wantOf("ace"); err != nil || w.Fp != fp || w.Version != "0.1.2" {
|
||||
t.Errorf("the want of web on ace = %+v (%v), want the passed version once a revision is kept", w, err)
|
||||
}
|
||||
|
||||
open = objects.block() // a keeping of new inputs is blocked
|
||||
placeOn(t, p.w, "g14", "web")
|
||||
pass()
|
||||
pass() // the same inputs again
|
||||
if w, err := wantOf("g14"); err != nil || w.Fp != fp || w.Version != "0.1.2" {
|
||||
t.Errorf("the want of web on g14 = %+v (%v), want the passed version while a keeping is blocked", w, err)
|
||||
}
|
||||
p.graph.mu.Lock()
|
||||
keeping, waiting := p.graph.keeping, p.graph.need
|
||||
p.graph.mu.Unlock()
|
||||
if !keeping || waiting != nil {
|
||||
t.Errorf("keeping %v, need waiting %+v: the pass of the same inputs handed its revision again", keeping, waiting)
|
||||
}
|
||||
if !said("the pass took ") {
|
||||
t.Error("the pass does not say its duration")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
"io"
|
||||
"maps"
|
||||
"mesh-delivery-assigner/internal/assigngraph"
|
||||
"mesh-delivery-assigner/internal/assignment"
|
||||
"mesh-delivery-assigner/internal/buckets"
|
||||
"mesh-delivery-assigner/internal/puts"
|
||||
@@ -190,6 +191,11 @@ func startBed(t *testing.T, leaveOut string) *bed {
|
||||
if _, err := js.CreateObjectStore(ctx, jetstream.ObjectStoreConfig{Bucket: catalogue.BusName("mesh-delivery-assigner", catalogue.StateObjectsName(buckets.InputsState))}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The assignment graph revisions' object store, which the grants part makes from the manifest's objects: no want is written
|
||||
// before a revision is kept in it (design 47 H-A-261).
|
||||
if _, err := js.CreateObjectStore(ctx, jetstream.ObjectStoreConfig{Bucket: catalogue.ObjectsBucket("mesh-delivery-assigner", assigngraph.RevisionsObjects)}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The builder's module log, as the runtime raises it (ADR 0297): the running commits are read from it (ADR 0571 clause 1).
|
||||
if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: buscompose.LogStreamName(builds.BuilderModule, builds.BuilderLog),
|
||||
Subjects: []string{buscompose.LogSubject(builds.BuilderModule, builds.BuilderLog) + ".>"}, AllowDirect: true}); err != nil {
|
||||
|
||||
@@ -613,7 +613,10 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
||||
p.publishWants = wantsPublisher(ctx, js, thisNode)
|
||||
if iv != nil && iv.h != nil {
|
||||
objects := newBusObjects(js, process.Account{Node: thisNode, Module: assignment.Module()}, assigngraph.RevisionsObjects)
|
||||
p.graph = &graphKeeper{objects: objects, halves: iv.h.views}
|
||||
// The keeping and removing of revisions runs off the pass loop, and a keeping that changed what the pass reads wakes
|
||||
// one (design 47 H-A-259).
|
||||
p.graph = &graphKeeper{objects: objects, halves: iv.h.views, background: func(f func()) { go f() }, wake: wake,
|
||||
reads: newBusObjects(js, process.Account{Node: thisNode, Module: assignment.Module()}, assigngraph.RevisionsObjects)}
|
||||
keep := func(ctx context.Context, ev meshcatalog.CatalogRevisionEvent) error {
|
||||
return p.keepCandidate(ctx, iv.call, ev)
|
||||
}
|
||||
@@ -628,7 +631,7 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
||||
// The revisions that are not current are removed when one ceases to be current and once now (revisions.go,
|
||||
// design 47 H §764, H-A-86).
|
||||
p.graph.revisions = &revisionRemover{ctx: ctx, objects: objects, inUse: inUseOf(w), logf: logger.Printf}
|
||||
p.graph.revisions.judge()
|
||||
// The start's removal of the revisions not current folds into the first pass's keeping (H-A-261).
|
||||
}
|
||||
}
|
||||
// The node-engine seat's manifest-reads-changed, for one node (design 47 H-A-104): its words are written into the state
|
||||
|
||||
@@ -88,6 +88,43 @@ func (b *busObjects) Names(ctx context.Context) ([]string, error) {
|
||||
return names, nil
|
||||
}
|
||||
|
||||
// PutDescribed stores data under name with the entry's module and fingerprint in its metadata, which the listing says (assigngraph.Describer,
|
||||
// design 47 H-A-259).
|
||||
func (b *busObjects) PutDescribed(ctx context.Context, name string, data []byte, module, fp string) error {
|
||||
o, err := b.open(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = o.Put(ctx, jetstream.ObjectMeta{Name: name, Metadata: map[string]string{entryModuleMeta: module, entryFpMeta: fp}}, bytes.NewReader(data))
|
||||
return err
|
||||
}
|
||||
|
||||
// Described is every object with the module and fingerprint its metadata says, in one listing.
|
||||
func (b *busObjects) Described(ctx context.Context) ([]assigngraph.Described, error) {
|
||||
o, err := b.open(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
infos, err := o.List(ctx)
|
||||
if errors.Is(err, jetstream.ErrNoObjectsFound) {
|
||||
return []assigngraph.Described{}, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]assigngraph.Described, 0, len(infos))
|
||||
for _, i := range infos {
|
||||
out = append(out, assigngraph.Described{Name: i.Name, Module: i.Metadata[entryModuleMeta], Fp: i.Metadata[entryFpMeta]})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// The metadata keys of an entry object's module and fingerprint.
|
||||
const (
|
||||
entryModuleMeta = "module"
|
||||
entryFpMeta = "fp"
|
||||
)
|
||||
|
||||
// Delete removes the object of that name; one not held is no error (design 47 G §579: a revision nothing pins is removed).
|
||||
func (b *busObjects) Delete(ctx context.Context, name string) error {
|
||||
o, err := b.open(ctx)
|
||||
|
||||
@@ -141,13 +141,14 @@ func (p *passer) clock() time.Time {
|
||||
}
|
||||
|
||||
func (p *passer) pass(ctx context.Context) {
|
||||
start := time.Now()
|
||||
defer func() { p.logf("the pass took %s", time.Since(start).Round(time.Millisecond)) }() // design 47 H-A-259
|
||||
p.assignmentsSeat(ctx)
|
||||
p.keepGraph(ctx)
|
||||
if p.graph == nil || !p.graph.full { // a full assignment graph store keeps the last revision and writes no new want (design 47 G §181)
|
||||
if held := p.keepGraph(ctx); held == "" {
|
||||
p.wants(ctx)
|
||||
p.sayPass(ctx, "judged")
|
||||
} else {
|
||||
p.sayPass(ctx, "the assignment graph store is full: no want is written (design 47 G §181)")
|
||||
p.sayPass(ctx, held) // a full store keeps the last revision (design 47 G §181); none kept yet writes no want (H-A-261)
|
||||
}
|
||||
p.puts(ctx)
|
||||
p.nodeWants(ctx)
|
||||
|
||||
@@ -169,7 +169,7 @@ func (e *pipelineEnds) take(p mpr.PipelineEnded) (bool, error) {
|
||||
changed := false
|
||||
var kept []tierMover
|
||||
defer func() {
|
||||
if err := e.startTiers(p.Pipeline, kept); err != nil {
|
||||
if err := e.startTiers(p.Pipeline, p.Source, kept); err != nil {
|
||||
e.logf("the tier progress of %s is not written: %v", p.Pipeline, err)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strconv"
|
||||
@@ -53,7 +54,7 @@ func trunkRevision(name string) (int64, bool) {
|
||||
// remove removes each kept revision that is not current, and then the entries no kept revision or candidate lists and no want or
|
||||
// running build names (design 47 G §179).
|
||||
func (k *revisionRemover) remove() error {
|
||||
names, err := k.objects.Names(k.ctx)
|
||||
names, described, err := k.listing()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -107,7 +108,7 @@ func (k *revisionRemover) remove() error {
|
||||
if !ok || listed[digest] {
|
||||
continue
|
||||
}
|
||||
e, err := assigngraph.ReadEntry(k.ctx, k.objects, digest)
|
||||
e, err := k.entryOf(n, digest, described)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -138,3 +139,46 @@ func inUseOf(w *world) func(module, fp string) bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// listing is every object's name in one read and, where the bucket says them, each entry object's module and fingerprint by name
|
||||
// (design 47 H-A-259); nil described where the bucket says none.
|
||||
func (k *revisionRemover) listing() ([]string, map[string]assigngraph.Described, error) {
|
||||
d, ok := k.objects.(assigngraph.Describer)
|
||||
if !ok {
|
||||
names, err := k.objects.Names(k.ctx)
|
||||
return names, nil, err
|
||||
}
|
||||
listed, err := d.Described(k.ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
names := make([]string, 0, len(listed))
|
||||
described := make(map[string]assigngraph.Described, len(listed))
|
||||
for _, l := range listed {
|
||||
names = append(names, l.Name)
|
||||
described[l.Name] = l
|
||||
}
|
||||
return names, described, nil
|
||||
}
|
||||
|
||||
// entryOf is the module and fingerprint of the entry object name: as the listing says them, with no read; an entry put before the
|
||||
// listing said them is read once and put again with them, so no later judging reads it (design 47 H-A-259).
|
||||
func (k *revisionRemover) entryOf(name, digest string, described map[string]assigngraph.Described) (meshwants.AssignmentEntry, error) {
|
||||
if l, ok := described[name]; ok && l.Module != "" && l.Fp != "" {
|
||||
return meshwants.AssignmentEntry{Module: l.Module, Fp: l.Fp}, nil
|
||||
}
|
||||
data, err := k.objects.Get(k.ctx, name)
|
||||
if err != nil {
|
||||
return meshwants.AssignmentEntry{}, fmt.Errorf("the entry %s: %w", digest, err)
|
||||
}
|
||||
var e meshwants.AssignmentEntry
|
||||
if err := json.Unmarshal(data, &e); err != nil {
|
||||
return e, fmt.Errorf("the entry %s: %w", digest, err)
|
||||
}
|
||||
if described != nil {
|
||||
if err := assigngraph.PutEntry(k.ctx, k.objects, name, data, e); err != nil {
|
||||
k.logf("the entry %s is not put again with its module and fingerprint, so the next judging reads it again: %v", digest, err)
|
||||
}
|
||||
}
|
||||
return e, nil
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||
@@ -12,42 +13,98 @@ import (
|
||||
|
||||
func (m memObjects) Delete(_ context.Context, name string) error { delete(m, name); return nil }
|
||||
|
||||
// describedObjects is memObjects whose listing says each entry's module and fingerprint (assigngraph.Describer), counting the
|
||||
// entry objects read.
|
||||
type describedObjects struct {
|
||||
memObjects
|
||||
meta map[string][2]string
|
||||
reads int
|
||||
}
|
||||
|
||||
func (d *describedObjects) Get(ctx context.Context, name string) ([]byte, error) {
|
||||
if strings.HasPrefix(name, "entry.") {
|
||||
d.reads++
|
||||
}
|
||||
return d.memObjects.Get(ctx, name)
|
||||
}
|
||||
|
||||
func (d *describedObjects) PutDescribed(_ context.Context, name string, data []byte, module, fp string) error {
|
||||
d.memObjects[name], d.meta[name] = data, [2]string{module, fp}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *describedObjects) Described(context.Context) ([]assigngraph.Described, error) {
|
||||
var out []assigngraph.Described
|
||||
for n := range d.memObjects {
|
||||
out = append(out, assigngraph.Described{Name: n, Module: d.meta[n][0], Fp: d.meta[n][1]})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Design 47 H §764, H-A-86: with the gate's pins gone, an assignment graph revision that is not current is removed, with the
|
||||
// entries no kept revision or candidate lists and no want or running build names; the current revision, the entries it lists,
|
||||
// a running build's entry and a run's kept candidate with its entries stay.
|
||||
// H-A-259: where the listing says each entry's module and fingerprint, the judging reads no entry object; an entry put before it
|
||||
// said them is read once and put again with them.
|
||||
func TestARevisionNotCurrentIsRemoved(t *testing.T) {
|
||||
objects := memObjects{}
|
||||
entry := func(module, fp string) string {
|
||||
e := meshwants.AssignmentEntry{Node: "n1", Module: module, Fp: fp}
|
||||
d := assigngraph.EntryDigest(e)
|
||||
raw, _ := json.Marshal(e)
|
||||
objects[assigngraph.EntryObject(d)] = raw
|
||||
return d
|
||||
}
|
||||
shared, old, running, cand := entry("a", "fp-a"), entry("b", "fp-b1"), entry("c", "fp-c1"), entry("d", "fp-d2")
|
||||
revision := func(n int64, digests ...string) {
|
||||
rev := meshwants.AssignmentRevision{Revision: n}
|
||||
for _, d := range digests {
|
||||
rev.Entries = append(rev.Entries, meshwants.NodeEntryRef{Node: "n1", Digest: d})
|
||||
for _, listed := range []string{"plain", "described", "described-later"} {
|
||||
objects := memObjects{}
|
||||
described := &describedObjects{memObjects: objects, meta: map[string][2]string{}}
|
||||
entry := func(module, fp string) string {
|
||||
e := meshwants.AssignmentEntry{Node: "n1", Module: module, Fp: fp}
|
||||
d := assigngraph.EntryDigest(e)
|
||||
raw, _ := json.Marshal(e)
|
||||
objects[assigngraph.EntryObject(d)] = raw
|
||||
if listed == "described" {
|
||||
described.meta[assigngraph.EntryObject(d)] = [2]string{module, fp}
|
||||
}
|
||||
return d
|
||||
}
|
||||
raw, _ := json.Marshal(rev)
|
||||
objects[assigngraph.TrunkObject(n)] = raw
|
||||
}
|
||||
candRaw, _ := json.Marshal(meshwants.AssignmentRevision{Revision: 1, Kind: "candidate", Group: "run-7", Heads: "h1",
|
||||
Entries: []meshwants.NodeEntryRef{{Node: "n1", Module: "d", Digest: cand}}})
|
||||
objects[assigngraph.CandidateObject("run-7", "h1")] = candRaw
|
||||
revision(1, shared, old, running)
|
||||
revision(2, shared, old)
|
||||
revision(3, shared)
|
||||
k := &revisionRemover{ctx: context.Background(), objects: objects, logf: t.Logf,
|
||||
inUse: func(module, fp string) bool { return module == "c" && fp == "fp-c1" }}
|
||||
k.judge()
|
||||
has := func(name string) bool { _, ok := objects[name]; return ok }
|
||||
for name, want := range map[string]bool{assigngraph.TrunkObject(1): false, assigngraph.TrunkObject(2): false, assigngraph.TrunkObject(3): true,
|
||||
assigngraph.EntryObject(old): false, assigngraph.EntryObject(running): true, assigngraph.EntryObject(shared): true,
|
||||
assigngraph.EntryObject(cand): true, assigngraph.CandidateObject("run-7", "h1"): true} {
|
||||
if has(name) != want {
|
||||
t.Errorf("%s kept = %v, want %v", name, has(name), want)
|
||||
shared, old, running, cand := entry("a", "fp-a"), entry("b", "fp-b1"), entry("c", "fp-c1"), entry("d", "fp-d2")
|
||||
revision := func(n int64, digests ...string) {
|
||||
rev := meshwants.AssignmentRevision{Revision: n}
|
||||
for _, d := range digests {
|
||||
rev.Entries = append(rev.Entries, meshwants.NodeEntryRef{Node: "n1", Digest: d})
|
||||
}
|
||||
raw, _ := json.Marshal(rev)
|
||||
objects[assigngraph.TrunkObject(n)] = raw
|
||||
}
|
||||
candRaw, _ := json.Marshal(meshwants.AssignmentRevision{Revision: 1, Kind: "candidate", Group: "run-7", Heads: "h1",
|
||||
Entries: []meshwants.NodeEntryRef{{Node: "n1", Module: "d", Digest: cand}}})
|
||||
objects[assigngraph.CandidateObject("run-7", "h1")] = candRaw
|
||||
revision(1, shared, old, running)
|
||||
revision(2, shared, old)
|
||||
revision(3, shared)
|
||||
var o revisionObjects = objects
|
||||
if listed != "plain" {
|
||||
o = described
|
||||
}
|
||||
k := &revisionRemover{ctx: context.Background(), objects: o, logf: t.Logf,
|
||||
inUse: func(module, fp string) bool { return module == "c" && fp == "fp-c1" }}
|
||||
k.judge()
|
||||
has := func(name string) bool { _, ok := objects[name]; return ok }
|
||||
for name, want := range map[string]bool{assigngraph.TrunkObject(1): false, assigngraph.TrunkObject(2): false, assigngraph.TrunkObject(3): true,
|
||||
assigngraph.EntryObject(old): false, assigngraph.EntryObject(running): true, assigngraph.EntryObject(shared): true,
|
||||
assigngraph.EntryObject(cand): true, assigngraph.CandidateObject("run-7", "h1"): true} {
|
||||
if has(name) != want {
|
||||
t.Errorf("%s: %s kept = %v, want %v", listed, name, has(name), want)
|
||||
}
|
||||
}
|
||||
switch listed {
|
||||
case "described":
|
||||
if described.reads != 0 {
|
||||
t.Errorf("described: the judging read %d entry objects, want none", described.reads)
|
||||
}
|
||||
case "described-later":
|
||||
if described.meta[assigngraph.EntryObject(running)] != [2]string{"c", "fp-c1"} {
|
||||
t.Errorf("described-later: the entry in use is not put again with its module and fingerprint: %v", described.meta)
|
||||
}
|
||||
reads := described.reads
|
||||
revision(4, shared)
|
||||
k.judge()
|
||||
if described.reads != reads {
|
||||
t.Errorf("described-later: a second judging read %d entry objects again", described.reads-reads)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,11 +42,14 @@ type tierMover struct {
|
||||
Tier int64 `json:"tier"`
|
||||
}
|
||||
|
||||
// tierProgress is a pipeline's tier progress (H-A-56): the tier whose wants are written, since when, and the movers.
|
||||
// tierProgress is a pipeline's tier progress (H-A-56): the tier whose wants are written, since when, the movers, and the source
|
||||
// revision its pipeline-ended names, said in pipeline-wanted beside the key's revision (design 47 H-A-214, H-A-216); zero in a
|
||||
// value kept before the field, read as the key's number.
|
||||
type tierProgress struct {
|
||||
Tier int64 `json:"tier"`
|
||||
Since time.Time `json:"since"`
|
||||
Movers []tierMover `json:"movers"`
|
||||
Source int64 `json:"source,omitempty"`
|
||||
}
|
||||
|
||||
// tierKey is the key of pipeline's tier progress; pipeline is the runner's key `<branch>.<source>`, its branch escaped.
|
||||
@@ -60,7 +63,7 @@ func isTierKey(key string) bool {
|
||||
|
||||
// startTiers writes the tier progress of a passed pipeline whose movers' versions are now kept, its first tier the lowest of
|
||||
// theirs, since now. A pipeline heard again writes nothing.
|
||||
func (e *pipelineEnds) startTiers(pipeline string, movers []tierMover) error {
|
||||
func (e *pipelineEnds) startTiers(pipeline string, source int64, movers []tierMover) error {
|
||||
if len(movers) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -68,7 +71,7 @@ func (e *pipelineEnds) startTiers(pipeline string, movers []tierMover) error {
|
||||
for _, m := range movers {
|
||||
first = min(first, m.Tier)
|
||||
}
|
||||
value, err := json.Marshal(tierProgress{Tier: first, Since: e.clock().UTC(), Movers: movers})
|
||||
value, err := json.Marshal(tierProgress{Tier: first, Since: e.clock().UTC(), Movers: movers, Source: source})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -131,7 +134,7 @@ func (p *passer) tiers(n assign.Nodes, placedOn func(module, branch string) []st
|
||||
continue
|
||||
}
|
||||
pipeline := strings.TrimPrefix(key, tierPrefix)
|
||||
branchEsc, source, _ := strings.Cut(pipeline, ".")
|
||||
branchEsc, number, _ := strings.Cut(pipeline, ".")
|
||||
branch, err := keys.UnescapeName(branchEsc)
|
||||
if err != nil {
|
||||
continue
|
||||
@@ -144,7 +147,7 @@ func (p *passer) tiers(n assign.Nodes, placedOn func(module, branch string) []st
|
||||
notRunning := p.notRunning(n, placedOn, pipeline, branch, t, t.Tier)
|
||||
late := !now.Before(t.Since.Add(bound))
|
||||
if late {
|
||||
p.tierLate(pipeline, branch, source, t, notRunning)
|
||||
p.tierLate(pipeline, branch, number, t, notRunning)
|
||||
break
|
||||
}
|
||||
if len(notRunning) > 0 {
|
||||
@@ -165,10 +168,10 @@ func (p *passer) tiers(n assign.Nodes, placedOn func(module, branch string) []st
|
||||
p.logf("the tier progress %s is not deleted: %v", key, err)
|
||||
break
|
||||
}
|
||||
p.sayPipelineWanted(pipeline, branch, source, meshwants.PipelineWantedOutcomeRunning, nil)
|
||||
p.sayPipelineWanted(pipeline, branch, number, t.Source, meshwants.PipelineWantedOutcomeRunning, nil)
|
||||
break
|
||||
}
|
||||
value, err := json.Marshal(tierProgress{Tier: later, Since: now, Movers: t.Movers})
|
||||
value, err := json.Marshal(tierProgress{Tier: later, Since: now, Movers: t.Movers, Source: t.Source})
|
||||
if err == nil {
|
||||
err = p.ends.st.swap(key, value, rev)
|
||||
}
|
||||
@@ -217,7 +220,7 @@ func (p *passer) notRunning(n assign.Nodes, placedOn func(module, branch string)
|
||||
// tierLate ends a pipeline's delivery at a tier past tier-bound: the finding tier-late is raised and pipeline-wanted says tier-late,
|
||||
// once each; the finding clears once the late movers run or a later pipeline moved them. The progress stays, so no later tier is
|
||||
// written, until no later tier's mover is kept at this pipeline any more.
|
||||
func (p *passer) tierLate(pipeline, branch, source string, t tierProgress, notRunning []meshwants.NotRunning) {
|
||||
func (p *passer) tierLate(pipeline, branch, number string, t tierProgress, notRunning []meshwants.NotRunning) {
|
||||
o := tierLateFinding(pipeline, t.Tier, notRunning)
|
||||
key := views.FindingKey(o.Scope, assign.KeyID(o.ID), o.Kind)
|
||||
if len(notRunning) > 0 {
|
||||
@@ -231,7 +234,7 @@ func (p *passer) tierLate(pipeline, branch, source string, t tierProgress, notRu
|
||||
p.said[key+".raised"] = true
|
||||
delete(p.said, key+".cleared")
|
||||
p.logf("pipeline %s: tier %d is late (tier-bound %s): %s; no later tier is written", pipeline, t.Tier, p.tierBoundOf(), o.Summary)
|
||||
p.sayPipelineWanted(pipeline, branch, source, meshwants.PipelineWantedOutcomeTierLate, notRunning)
|
||||
p.sayPipelineWanted(pipeline, branch, number, t.Source, meshwants.PipelineWantedOutcomeTierLate, notRunning)
|
||||
}
|
||||
} else if !p.said[key+".cleared"] {
|
||||
if p.findings.Delete != nil {
|
||||
@@ -271,11 +274,16 @@ func tierLateFinding(pipeline string, tier int64, notRunning []meshwants.NotRunn
|
||||
Source: "assigner." + kindTierLate}
|
||||
}
|
||||
|
||||
// sayPipelineWanted says the seat mesh-wants' pipeline-wanted of pipeline, once (its id the pipeline and the outcome).
|
||||
func (p *passer) sayPipelineWanted(pipeline, branch, source, outcome string, notRunning []meshwants.NotRunning) {
|
||||
var src int64
|
||||
_, _ = fmt.Sscan(source, &src)
|
||||
body := meshwants.PipelineWantedEvent{V: keys.Version, Pipeline: pipeline, Branch: branch, Source: src, Outcome: outcome, NotRunning: notRunning}
|
||||
// sayPipelineWanted says the seat mesh-wants' pipeline-wanted of pipeline, once (its id the pipeline and the outcome): its
|
||||
// revision the number of the pipeline's key `<branch>.<revision>`, its source the one the pipeline-ended named (design 47
|
||||
// H-A-214, H-A-216), the key's number for a progress kept before it held one.
|
||||
func (p *passer) sayPipelineWanted(pipeline, branch, number string, source int64, outcome string, notRunning []meshwants.NotRunning) {
|
||||
var revision int64
|
||||
_, _ = fmt.Sscan(number, &revision)
|
||||
if source <= 0 {
|
||||
source = revision
|
||||
}
|
||||
body := meshwants.PipelineWantedEvent{V: keys.Version, Pipeline: pipeline, Branch: branch, Source: source, Revision: revision, Outcome: outcome, NotRunning: notRunning}
|
||||
event := meshwants.EventPipelineWanted + "." + pipeline
|
||||
if err := p.wantsSay(event, body, "pipeline-wanted."+pipeline+"."+outcome); err != nil {
|
||||
p.logf("pipeline-wanted of %s is not said: %v", pipeline, err)
|
||||
|
||||
@@ -62,8 +62,11 @@ func TestAPipelinesWantsAreWrittenTierByTier(t *testing.T) {
|
||||
p.w.mu.Unlock()
|
||||
p.ends = newPipelineEnds(newMemEnds(), func() {}, t.Logf)
|
||||
p.ends.trunk, p.ends.now = p.w.trunkName, func() time.Time { return now }
|
||||
if _, err := p.ends.take(ended(trunkBranch, 5, mpr.PipelineEndedOutcomePassed, mover("db", db, "0.2.0", 1, mpr.StepResultOutcomePassed),
|
||||
mover("web", web, "0.1.2", 2, mpr.StepResultOutcomePassed))); err != nil {
|
||||
// The pipeline of revision 5 (its key's number) of source 4: a re-pin's revision (H-A-213, H-A-216).
|
||||
e := ended(trunkBranch, 5, mpr.PipelineEndedOutcomePassed, mover("db", db, "0.2.0", 1, mpr.StepResultOutcomePassed),
|
||||
mover("web", web, "0.1.2", 2, mpr.StepResultOutcomePassed))
|
||||
e.Source = 4
|
||||
if _, err := p.ends.take(e); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wanted := func(node, module string) bool {
|
||||
@@ -88,7 +91,7 @@ func TestAPipelinesWantsAreWrittenTierByTier(t *testing.T) {
|
||||
raw, _ = json.Marshal(nodeengine.Running{Node: "g14", Module: "web", Fingerprint: web})
|
||||
_ = p.w.hearRunning("running.g14.web", raw)
|
||||
p.wants(context.Background())
|
||||
if len(said) != 1 || said[0].Outcome != meshwants.PipelineWantedOutcomeRunning || len(findings) != 0 {
|
||||
if len(said) != 1 || said[0].Outcome != meshwants.PipelineWantedOutcomeRunning || said[0].Revision != 5 || said[0].Source != 4 || len(findings) != 0 {
|
||||
t.Errorf("every tier runs: said %+v, findings %v", said, findings)
|
||||
}
|
||||
if _, _, ok := p.ends.tiersOf(trunkBranch + ".5"); ok {
|
||||
@@ -108,8 +111,14 @@ func TestAPipelinesWantsAreWrittenTierByTier(t *testing.T) {
|
||||
if !ok || !strings.Contains(f.Summary, "db on g14") || strings.Contains(f.Summary, "ace") {
|
||||
t.Errorf("tier-late is not raised naming db on g14 alone: %v", findings)
|
||||
}
|
||||
if len(said) != 1 || said[0].Outcome != meshwants.PipelineWantedOutcomeTierLate || len(said[0].NotRunning) != 1 || said[0].NotRunning[0].Module != "db" {
|
||||
t.Errorf("pipeline-wanted tier-late is not said once: %+v", said)
|
||||
if len(said) != 1 || said[0].Outcome != meshwants.PipelineWantedOutcomeTierLate || len(said[0].NotRunning) != 1 || said[0].NotRunning[0].Module != "db" ||
|
||||
said[0].Revision != 5 || said[0].Source != 4 {
|
||||
t.Errorf("pipeline-wanted tier-late is not said once, naming revision 5 of source 4: %+v", said)
|
||||
}
|
||||
// A tier progress kept before it held its source says the key's number as both (H-A-216).
|
||||
p.sayPipelineWanted(trunkBranch+".5", trunkBranch, "5", 0, meshwants.PipelineWantedOutcomeRunning, nil)
|
||||
if len(said) != 2 || said[1].Revision != 5 || said[1].Source != 5 {
|
||||
t.Errorf("a progress with no source: said %+v, want revision and source 5", said)
|
||||
}
|
||||
if wanted("g14", "web") || wanted("ace", "web") {
|
||||
t.Error("a consumer's want is written after its provider's tier was late")
|
||||
|
||||
@@ -345,7 +345,8 @@ func (r *compositionRun) startValidate(ctx context.Context, key string, run mesh
|
||||
return
|
||||
}
|
||||
a := buildstep.StepAsk{ID: ask, Kind: buildstep.AskCheck, Language: buildstep.AskGo, Asker: runAsker, At: r.now().UTC(),
|
||||
Run: &buildstep.RunJob{Program: program, Heads: []buildstep.RunHead{}, Input: ref, Reader: "the manifest validator of " + step.Pipeline + " at " + program.Commit}}
|
||||
Run: &buildstep.RunJob{Program: program, Heads: []buildstep.RunHead{}, Input: ref, Reader: "the manifest validator of " + step.Pipeline + " at " + program.Commit},
|
||||
Packages: pinsOfEntry(entry)} // the validator is built against its entry's pins at the step's revision (H-A-203, H-A-192, H-A-205)
|
||||
if err := r.put(ctx, a); err != nil {
|
||||
couldNot("its run ask " + ask + " is not put: " + err.Error())
|
||||
}
|
||||
|
||||
@@ -25,7 +25,8 @@ import (
|
||||
// is judged against an empty case before, said in its end, and no revision below it is asked.
|
||||
func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) {
|
||||
indexer := meshcatalog.CatalogEntry{Module: "indexer", Repository: "novox/mesh-delivery", Commit: commitE3, Path: "modules/mesh-delivery-indexer",
|
||||
Fp: "src2:ix", Serves: []string{"seat:" + meshcatalog.Seat + ".revision"}, Manifest: map[string]any{"module": "indexer"}, ManifestDigest: "d-ix"}
|
||||
Fp: "src2:ix", Serves: []string{"seat:" + meshcatalog.Seat + ".revision"}, Manifest: map[string]any{"module": "indexer"}, ManifestDigest: "d-ix",
|
||||
Packages: map[string]string{"git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient": "v0.1.4"}}
|
||||
entry := func(module, digest string, edges ...meshcatalog.Edge) meshcatalog.CatalogEntry {
|
||||
return meshcatalog.CatalogEntry{Module: module, Manifest: map[string]any{"module": module, "d": digest}, ManifestDigest: digest, Edges: edges}
|
||||
}
|
||||
@@ -124,6 +125,10 @@ func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) {
|
||||
if p := asks[0].Run.Program; p.Commit != commitE3 || p.Dir != "modules/mesh-delivery-indexer" || p.Package != validatorPackage || len(asks[0].Run.Heads) != 0 {
|
||||
t.Errorf("the validator is built from %+v", asks[0].Run)
|
||||
}
|
||||
// The validator is built against the indexer entry's pins at the step's revision (H-A-203, H-A-192, H-A-205).
|
||||
if got := asks[0].Packages; len(got) != 1 || got["git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"] != "v0.1.4" {
|
||||
t.Errorf("the validator is built against the pins %v; want its entry's", got)
|
||||
}
|
||||
if c := requests[0].Cases; len(c) != 2 || c[0].Name != changeCase || c[1].Name != beforeCase || len(c[1].Manifests) != 3 || requests[0].Predefined != nil || requests[0].Packages != nil {
|
||||
t.Errorf("the validator's request is %+v", requests[0])
|
||||
}
|
||||
|
||||
@@ -30,6 +30,29 @@ type Objects interface {
|
||||
Names(ctx context.Context) ([]string, error)
|
||||
}
|
||||
|
||||
// Described is one object as the bucket's listing says it: its name, and for an entry object the module and fingerprint put beside
|
||||
// its bytes (empty for one put before them).
|
||||
type Described struct {
|
||||
Name, Module, Fp string
|
||||
}
|
||||
|
||||
// Describer is an object bucket whose listing says, in one read, each entry object's module and fingerprint, so the removal of the
|
||||
// revisions not current reads no object per entry (design 47 H-A-259).
|
||||
type Describer interface {
|
||||
// PutDescribed stores data whole under name, with module and fp beside it in the listing.
|
||||
PutDescribed(ctx context.Context, name string, data []byte, module, fp string) error
|
||||
// Described is every object, as the listing says it.
|
||||
Described(ctx context.Context) ([]Described, error)
|
||||
}
|
||||
|
||||
// PutEntry stores the entry object e under name, with its module and fingerprint beside it where the bucket says them.
|
||||
func PutEntry(ctx context.Context, o Objects, name string, data []byte, e meshwants.AssignmentEntry) error {
|
||||
if d, ok := o.(Describer); ok {
|
||||
return d.PutDescribed(ctx, name, data, e.Module, e.Fp)
|
||||
}
|
||||
return o.Put(ctx, name, data)
|
||||
}
|
||||
|
||||
// EntryObject is the object name of the entry of that digest (the seat's key form entry.<digest>).
|
||||
func EntryObject(digest string) string { return "entry." + digest }
|
||||
|
||||
@@ -144,7 +167,7 @@ func writeEntries(ctx context.Context, o Objects, c Computed, rev meshwants.Assi
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := o.Put(ctx, name, data); err != nil {
|
||||
if err := PutEntry(ctx, o, name, data, e); err != nil {
|
||||
return fmt.Errorf("the entry of %s/%s in %s: %w", ref.Node, ref.Module, RevisionsObjects, err)
|
||||
}
|
||||
held[name] = true
|
||||
|
||||
@@ -242,6 +242,11 @@ type BuilderBuild struct {
|
||||
// Imports are, on a done key, the mesh packages the built programs import, as the build module answered them
|
||||
// (BuildAnswer.Imports; novox/hq ADR 0593 §2): the builder carries them onto the build's end (BuildLogEntry.Imports).
|
||||
Imports []string `json:"imports,omitempty"`
|
||||
// Packages are, on a done key only, the mesh packages' versions its Go build was built with, by module path, the ones
|
||||
// the registry gave a package the entry named with none included (H-A-207): the build step's end reports them, so the
|
||||
// runner asks the steps that waited for the pins with what the build was built against. A reader that does not know
|
||||
// the field reads the build as reporting none.
|
||||
Packages map[string]string `json:"packages,omitempty"`
|
||||
// Needs are, on a done key only, the reader capabilities (`form:<name>`) the build's reference forms need of a
|
||||
// node-engine, beside the ones its manifest needs (novox/hq ADR 0618 §1). A reader that does not know the field
|
||||
// reads the build as needing none.
|
||||
|
||||
@@ -101,9 +101,7 @@ func (c *catalogHalf) Changed(ctx context.Context) func(branch, module string, e
|
||||
}
|
||||
origin := build.Origin{Branch: branch, First: first}
|
||||
if cat, ok := c.branches.Catalog(branch); ok {
|
||||
if half, ok := cat.View(); ok {
|
||||
origin.Source = half.Revision.Source
|
||||
}
|
||||
origin = pictureOrigin(origin, cat.View)
|
||||
}
|
||||
var e meshcatalog.CatalogEntry
|
||||
if err := json.Unmarshal(entry, &e); err != nil || e.Module != module {
|
||||
@@ -132,6 +130,16 @@ func (c *catalogHalf) Changed(ctx context.Context) func(branch, module string, e
|
||||
}
|
||||
}
|
||||
|
||||
// pictureOrigin is the origin of an entry the picture takes in: the source revision and the catalog revision number of the
|
||||
// half the view holds, one revision for both (design 47 G §371, H-A-218, H-A-220), so a build the picture starts before any
|
||||
// step ask reserves a version that names its revision; none while the view holds no half.
|
||||
func pictureOrigin(o build.Origin, view func() (meshcatalogclient.Half, bool)) build.Origin {
|
||||
if half, ok := view(); ok {
|
||||
o.Source, o.Revision = half.Revision.Source, half.Revision.Revision
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
// picture is build.Builder.Picture: the source revision the view of branch holds (design 47 H H-A-155), false while the branch
|
||||
// is not followed or its view holds none.
|
||||
func (c *catalogHalf) picture(branch string) (int64, bool) {
|
||||
|
||||
@@ -4,7 +4,9 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"mesh-delivery-builder/internal/build"
|
||||
)
|
||||
|
||||
// TestTheManifestOfAnEntryIsReadByItsDigest: the builder reads a manifest from the entry that holds it, by the entry's manifest
|
||||
@@ -25,3 +27,18 @@ func TestTheManifestOfAnEntryIsReadByItsDigest(t *testing.T) {
|
||||
t.Errorf("an entry with no manifest kept one: %v, %v", err, m.byFp)
|
||||
}
|
||||
}
|
||||
|
||||
// H-A-220: an entry the picture takes in has the source revision and the catalog revision number of the half its view holds,
|
||||
// one revision for both; a view holding no half names neither.
|
||||
func TestAnEntryThePictureTakesInNamesItsHalfsRevision(t *testing.T) {
|
||||
o := build.Origin{Branch: "main", First: true}
|
||||
got := pictureOrigin(o, func() (meshcatalogclient.Half, bool) {
|
||||
return meshcatalogclient.Half{Revision: meshcatalog.CatalogRevision{Revision: 47, Source: 45}}, true
|
||||
})
|
||||
if got != (build.Origin{Branch: "main", First: true, Source: 45, Revision: 47}) {
|
||||
t.Errorf("origin = %+v, want source 45 at revision 47", got)
|
||||
}
|
||||
if got := pictureOrigin(o, func() (meshcatalogclient.Half, bool) { return meshcatalogclient.Half{}, false }); got != o {
|
||||
t.Errorf("origin with no half = %+v, want %+v", got, o)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
)
|
||||
|
||||
// keptRevisionVia reads one kept revision of a branch by its number through the catalog seat's verb revision, page by page
|
||||
// (design 47 H H-A-205, H-A-147): the source revision it was taken in from and the fingerprint of each module it names.
|
||||
func keptRevisionVia(call toolCaller) func(context.Context, string, int64) (int64, map[string]string, error) {
|
||||
return func(_ context.Context, branch string, revision int64) (int64, map[string]string, error) {
|
||||
fps := map[string]string{}
|
||||
var source int64
|
||||
after := ""
|
||||
for {
|
||||
raw, err := call(meshcatalogclient.RevisionVerb, meshcatalog.RevisionInput{Branch: keys.EscapeName(branch), Revision: revision, After: after})
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
answer, said, ok := buscalls.Unwrap(raw)
|
||||
if !ok {
|
||||
return 0, nil, fmt.Errorf("%s answered: %s", meshcatalogclient.RevisionVerb, said)
|
||||
}
|
||||
var a meshcatalog.RevisionAnswer
|
||||
if err := json.Unmarshal(answer, &a); err != nil {
|
||||
return 0, nil, fmt.Errorf("%s answered no revision: %w", meshcatalogclient.RevisionVerb, err)
|
||||
}
|
||||
if a.NoneYet || a.Revision == nil || a.Revision.Revision != revision {
|
||||
return 0, nil, fmt.Errorf("%s answered no revision %d of %s", meshcatalogclient.RevisionVerb, revision, branch)
|
||||
}
|
||||
source = a.Revision.Source
|
||||
for _, e := range a.Entries {
|
||||
fps[e.Module] = e.Fp
|
||||
}
|
||||
if a.Next == "" {
|
||||
return source, fps, nil
|
||||
}
|
||||
after = a.Next
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -239,11 +239,15 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
// and version-released heard; nothing is reserved before the fill.
|
||||
reservedKV := process.AwaitBucket(ctx, js, conn, own.reserved, "no version is reserved: builds are made unreserved", logger.Printf)
|
||||
reserved := newReservations(awaitedReserved{awaitedVersions{b: reservedKV, bucket: own.reserved}}, calls.Call, pubBoundsKV.KV, found, b.Reconsider, logger.Printf)
|
||||
// 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).
|
||||
reserved.say = func(ctx context.Context, p meshbuilds.PackagePublished) error {
|
||||
return emitSeatEvent(context.WithoutCancel(ctx), js, cred, meshbuilds.SubjectPackagePublished, "package-published-"+p.Module+"-"+p.Version+"-"+p.Artifact, p)
|
||||
}
|
||||
b.Reserved = reserved
|
||||
// A take-over of a series' reservation by another fingerprint withdraws the older build (H-A-225).
|
||||
reserved.withdraw = b.Withdraw
|
||||
// The last versions-filled the stream keeps is read at the start (design 47 G §369, §372): a restart does not lose it.
|
||||
reserved.readFilled(ctx, lastKeptOf(js, cred, logger.Printf), sleeps)
|
||||
// A state bound later numbers the builds looked at without it.
|
||||
@@ -258,6 +262,26 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
Entry: entryVia(calls.Call), Send: sendVia(calls.Call),
|
||||
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)
|
||||
// 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))
|
||||
}
|
||||
// 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 {
|
||||
res := b.BuildAgain(ctx, module, fp, why, "the builder", buildAgainBound)
|
||||
switch {
|
||||
case res.Refused != "":
|
||||
return errors.New(res.Refused)
|
||||
case res.Failed != "":
|
||||
return errors.New(res.Failed)
|
||||
case res.Pending != "":
|
||||
logger.Printf("%s at %s is built again: %s", module, fp, res.Pending)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -273,6 +297,12 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
return reserved.r.Of(ctx, module, version)
|
||||
},
|
||||
republish: republish.Republish, endedWith: reserved.unreleased,
|
||||
// A publish is asked again only while no published of it may be unheard and the registry's record lacks it (H-A-269 (2), H-A-272).
|
||||
unheard: unheardVia(js, process.EventsStream, cred.EventConsumerName()),
|
||||
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) {
|
||||
all, err := reserved.r.All(ctx)
|
||||
return builtOf(all), err
|
||||
@@ -469,6 +499,9 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
// a holder of the seat that is down holds no other part of it).
|
||||
half.b = b
|
||||
b.Picture = half.picture
|
||||
// An ask of a revision below the newest the picture holds is read by number from the catalog seat (H-A-205).
|
||||
b.KeptRevision = keptRevisionVia(calls.Call)
|
||||
b.FirstBranch = half.first
|
||||
branches.Held = func(string, meshcatalog.CatalogRevision) { b.PictureHeld() } // a revision held wakes a step ask's wait (H-A-162)
|
||||
half.ready = func() {
|
||||
if err := b.Sweep(ctx, half.pictured()...); err != nil {
|
||||
|
||||
@@ -47,10 +47,20 @@ type publishItems struct {
|
||||
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 func(ctx context.Context) ([]versions.ReservedVersion, error)
|
||||
set publishSettings
|
||||
now func() time.Time
|
||||
after func(time.Duration) <-chan time.Time
|
||||
logf func(string, ...any)
|
||||
// unheard is how many messages the builder's durable on the events stream holds pending and unacknowledged, read before each
|
||||
// try (design 47 H H-A-269 (2), H-A-272); nil reads none.
|
||||
unheard func(ctx context.Context) (int, 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
|
||||
// would (H-A-274); moveElsewhere moves a version a registry holds at another digest to the next free number and asks its
|
||||
// publish there (H-A-275). Nil does neither.
|
||||
markHeld func(ctx context.Context, v versions.ReservedVersion, held []versions.HeldArtifact)
|
||||
moveElsewhere func(ctx context.Context, v versions.ReservedVersion, j versions.Judged) error
|
||||
set publishSettings
|
||||
now func() time.Time
|
||||
after func(time.Duration) <-chan time.Time
|
||||
logf func(string, ...any)
|
||||
}
|
||||
|
||||
func (p *publishItems) wait(ctx context.Context, d time.Duration) bool {
|
||||
@@ -138,6 +148,12 @@ func (p *publishItems) Try(ctx context.Context, kv jetstream.KeyValue, e jetstre
|
||||
if p.endedWith != nil {
|
||||
p.endedWith(ctx, v, "the publish ended after "+fmt.Sprint(r.Tries)+" tries")
|
||||
}
|
||||
} else if why, gone := p.notAgain(ctx, v); gone {
|
||||
return // moved to another number, whose own item is asked (H-A-275)
|
||||
} else if why != "" {
|
||||
// A published of the version may be unheard, or the registry's record ended it: no ask, and no try spent (H-A-272, H-A-274).
|
||||
p.logf("%s %s: the publish is not asked again: %s; tried again after %s", r.Module, r.Version, why, p.set.pauseAfter(r.Tries))
|
||||
r.NextTry = p.now().UTC().Add(p.set.pauseAfter(r.Tries))
|
||||
} else {
|
||||
r.Tries++
|
||||
if _, err := p.republish(ctx, r.Module, r.Version); err != nil {
|
||||
@@ -154,6 +170,85 @@ func (p *publishItems) Try(ctx context.Context, kv jetstream.KeyValue, e jetstre
|
||||
}
|
||||
}
|
||||
|
||||
// notAgain says why a version's publish is not asked again now, empty when it is (design 47 H H-A-269 (2), H-A-272, H-A-274,
|
||||
// H-A-275): the builder's durable holds UnheardBound messages or more not yet heard, so a published of it may be among them; or the
|
||||
// registries' own record holds every missing artifact at its version with its built digest, which marks them published from that
|
||||
// record; or a registry holds the version at another digest, which moves the build to the next free number (gone: this item is
|
||||
// ended with the old number). A count or a record that cannot be read is said, and does not hold the ask.
|
||||
func (p *publishItems) notAgain(ctx context.Context, v versions.ReservedVersion) (why string, gone bool) {
|
||||
if p.unheard != nil {
|
||||
n, err := p.unheard(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
p.logf("%s %s: the builder's events consumer cannot be read, so the publish is asked again as it stands: %v", v.Module, v.Version, err)
|
||||
case n >= versions.UnheardBound:
|
||||
return fmt.Sprintf("the builder's events consumer holds %d messages not yet heard (the bound is %d), a published of it may be among them", n, versions.UnheardBound), false
|
||||
}
|
||||
}
|
||||
if p.judge == nil {
|
||||
return "", false
|
||||
}
|
||||
j, err := p.judge(ctx, v)
|
||||
switch {
|
||||
case err != nil:
|
||||
p.logf("%s %s: the registries' record cannot be read, so the publish is asked again: %v", v.Module, v.Version, err)
|
||||
case len(j.Elsewhere) > 0 && p.moveElsewhere != nil:
|
||||
if err := p.moveElsewhere(ctx, v, j); err != nil {
|
||||
p.logf("%s %s: a registry holds the number at another digest, and the build is not moved: %v", v.Module, v.Version, err)
|
||||
return "a registry holds " + v.Version + " at another digest", false
|
||||
}
|
||||
return "", true
|
||||
case j.All:
|
||||
if p.markHeld != nil {
|
||||
p.markHeld(ctx, v, j.Held)
|
||||
}
|
||||
return "the registries hold every missing artifact at " + v.Version + " with its built digest: marked published from their record", false
|
||||
default:
|
||||
p.logf("%s %s: asked again: %s", v.Module, v.Version, j.Lacks)
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
// unheardVia reads the builder's durable on the events stream: its messages pending and those given and not yet acknowledged
|
||||
// (design 47 H H-A-272), what it has not yet heard.
|
||||
func unheardVia(js jetstream.JetStream, stream, durable string) func(context.Context) (int, error) {
|
||||
return func(ctx context.Context) (int, error) {
|
||||
c, err := js.Consumer(ctx, stream, durable)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
info, err := c.Info(ctx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return int(info.NumPending) + info.NumAckPending, nil
|
||||
}
|
||||
}
|
||||
|
||||
// registryVersionsVia asks a registry seat's verb versions for a name (H-A-272): each version it holds with its digest.
|
||||
func registryVersionsVia(call toolCaller) func(context.Context, string, string) ([]versions.HeldVersion, error) {
|
||||
return func(_ context.Context, seat, name string) ([]versions.HeldVersion, error) {
|
||||
raw, err := call("seat:"+seat+"."+versions.VerbVersions, map[string]any{"name": name})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
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"`
|
||||
} `json:"versions"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &a); err != nil {
|
||||
return nil, fmt.Errorf("%s's versions answered what is no list of versions: %w", seat, err)
|
||||
}
|
||||
out := make([]versions.HeldVersion, 0, len(a.Versions))
|
||||
for _, v := range a.Versions {
|
||||
out = append(out, versions.HeldVersion{Version: v.Version, Digest: v.Digest})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
}
|
||||
|
||||
// numberFile reads a setting's number from the file the manifest declares: no file or an empty one is def; a content that is no
|
||||
// number of at least one is an error naming the file.
|
||||
func numberFile(path string, def int) (int, error) {
|
||||
|
||||
@@ -274,3 +274,76 @@ func TestThePublishItemsAreWiredToTheReservationsAndTheReAskWatch(t *testing.T)
|
||||
t.Errorf("a dropped reservation kept its item")
|
||||
}
|
||||
}
|
||||
|
||||
// TestAPublishIsNotAskedAgainWhileItsPublishedMayBeUnheard: design 47 H H-A-269 (2), H-A-272, H-A-274, H-A-275 — a try asks the
|
||||
// publish again only while the builder's durable holds fewer than a hundred messages not yet heard and the registries' record lacks
|
||||
// an artifact; 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 skipped try spends no try and is written
|
||||
// again with its pause; a count that cannot be read holds no ask.
|
||||
func TestAPublishIsNotAskedAgainWhileItsPublishedMayBeUnheard(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
|
||||
unheard int
|
||||
countErr error
|
||||
judged versions.Judged
|
||||
wantAsked, wantMark, wantMov bool
|
||||
}{
|
||||
{name: "thousands behind: no ask, the registry not read", unheard: 2944},
|
||||
{name: "at the bound: no ask", unheard: versions.UnheardBound},
|
||||
{name: "heard up, the registry holds it: marked from its record, no ask", unheard: versions.UnheardBound - 1, judged: versions.Judged{All: true, Held: []versions.HeldArtifact{at}}, wantMark: true},
|
||||
{name: "the registry holds the number at another digest: moved, no ask", unheard: 3, judged: versions.Judged{Elsewhere: []versions.HeldArtifact{other}}, wantMov: true},
|
||||
{name: "heard up, the registry lacks it: asked", unheard: 3, judged: versions.Judged{Lacks: "none"}, wantAsked: true},
|
||||
{name: "the count unreadable, the registry lacks it: asked", countErr: errors.New("no consumer"), 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) { return v, true, nil },
|
||||
republish: func(context.Context, string, string) ([]string, error) { asked++; return nil, nil },
|
||||
unheard: func(context.Context) (int, error) { return c.unheard, c.countErr },
|
||||
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)
|
||||
e, _ := kv.Get(ctx, key)
|
||||
p.Try(ctx, kv, e, decodeItem(t, e.Value()))
|
||||
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.wantMov {
|
||||
if _, ok := kv.vals[key]; ok {
|
||||
t.Error("the moved version's old item is written again")
|
||||
}
|
||||
return
|
||||
}
|
||||
got := decodeItem(t, kv.vals[key])
|
||||
if got.Tries != map[bool]int{true: 1, false: 0}[c.wantAsked] || !got.NextTry.After(now) {
|
||||
t.Errorf("tries %d, next try %s: want a try spent only when asked, and the item written again with its pause", got.Tries, got.NextTry)
|
||||
}
|
||||
if c.unheard >= versions.UnheardBound && judged != 0 {
|
||||
t.Error("the registry is read while a published may be unheard")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -549,8 +549,14 @@ func (m memVersions) Update(_ context.Context, key string, v []byte, _ uint64) (
|
||||
m[key] = v
|
||||
return 2, nil
|
||||
}
|
||||
func (m memVersions) KeysOf(context.Context, string) ([]string, error) {
|
||||
return slices.Collect(maps.Keys(m)), nil
|
||||
func (m memVersions) KeysOf(_ context.Context, filter string) ([]string, error) {
|
||||
var out []string
|
||||
for k := range m {
|
||||
if versions.FilterMatches(filter, k) { // as the bus reads a filter
|
||||
out = append(out, k)
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// memBuilds is the builder's builds in memory.
|
||||
|
||||
@@ -50,8 +50,12 @@ type reservations struct {
|
||||
bound time.Duration
|
||||
wake func(context.Context)
|
||||
logf func(string, ...any)
|
||||
// withdraw ends the running build of a module's fingerprint, superseded, with why (H-A-225); nil ends none.
|
||||
withdraw func(module, fingerprint, why string)
|
||||
// call asks a seat's verb: the git seat's tag (design 47 G §370).
|
||||
call toolCaller
|
||||
// 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
|
||||
// say says package-published on the seat mesh-builds; nil says none.
|
||||
say func(context.Context, meshbuilds.PackagePublished) error
|
||||
}
|
||||
@@ -75,10 +79,21 @@ func newReservations(store versions.ReserveStore, call toolCaller, bounds func()
|
||||
}
|
||||
return out, nil
|
||||
}}
|
||||
rv.r.Took = rv.took
|
||||
rv.r.Took, rv.r.Logf = rv.took, logf
|
||||
return rv
|
||||
}
|
||||
|
||||
// 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) {
|
||||
n, err := rv.r.Reindex(ctx)
|
||||
if err != nil {
|
||||
rv.logf("the reservations' index is written again from %d reservations, not whole: %v", n, err)
|
||||
return
|
||||
}
|
||||
rv.logf("the reservations' index is written again from %d reservations", n)
|
||||
}
|
||||
|
||||
// took is a build's takeover of the reservation of an older build never released (design 47 G A-455): the older version is
|
||||
// dropped, its bound ended and its finding cleared (the newer build's reservation has its own), and the builder's log says so.
|
||||
func (rv *reservations) took(ctx context.Context, older, newer versions.ReservedVersion) {
|
||||
@@ -92,6 +107,11 @@ func (rv *reservations) took(ctx context.Context, older, newer versions.Reserved
|
||||
}
|
||||
rv.dropBound(ctx, versions.ReservedKey(older.Module, older.Series))
|
||||
rv.found.clear(ctx, versions.VersionUnreleased, meshconditionsclient.ScopeModule, older.Module)
|
||||
if older.Fingerprint != newer.Fingerprint && rv.withdraw != nil {
|
||||
// The older build is ended superseded, as the picture's supersession ends one (H-A-225, ADR 0664 §4): nothing publishes
|
||||
// under the dropped number.
|
||||
rv.withdraw(older.Module, older.Fingerprint, "its reservation "+older.Version+" was taken over by the build of "+newer.Fingerprint+", which reserves "+newer.Version)
|
||||
}
|
||||
}
|
||||
|
||||
var _ build.Reservations = (*reservations)(nil)
|
||||
@@ -110,6 +130,11 @@ func (rv *reservations) ReservedFor(ctx context.Context, module, fingerprint str
|
||||
return versions.ReservedVersion{}, false, nil
|
||||
}
|
||||
|
||||
// TakenOver is the reservation that took module's series over from the build of fingerprint (H-A-244).
|
||||
func (rv *reservations) TakenOver(ctx context.Context, module, fingerprint string) (versions.ReservedVersion, bool, error) {
|
||||
return rv.r.TakenOver(ctx, module, fingerprint)
|
||||
}
|
||||
|
||||
func (rv *reservations) Filled() bool { return rv.filled.Load() }
|
||||
|
||||
func (rv *reservations) Reserve(ctx context.Context, module, series string, artifacts []string, src versions.Source) (versions.ReservedVersion, error) {
|
||||
@@ -253,6 +278,7 @@ func (rv *reservations) heard(ctx context.Context, m jetstream.Msg) bool {
|
||||
rv.released(ctx, ev.Module, ev.Version)
|
||||
}
|
||||
rv.found.clear(ctx, versions.VersionUnreleased, meshconditionsclient.ScopeModule, ev.Module)
|
||||
rv.found.clear(ctx, versions.VersionHeldElsewhere, meshconditionsclient.ScopeModule, ev.Module)
|
||||
default:
|
||||
return false
|
||||
}
|
||||
@@ -337,21 +363,19 @@ func (rv *reservations) tagged(ctx context.Context, ev meshcatalog.VersionReleas
|
||||
return nil
|
||||
}
|
||||
|
||||
// noMark says why a published marked nothing: which reservation holds that version, and what it holds of digests.
|
||||
// noMark says why a published marked nothing: which reservation holds that version, and what it holds of digests, read through the
|
||||
// index by version (H-A-269 (1), H-A-271).
|
||||
func (rv *reservations) noMark(ctx context.Context, o versions.Outcome) string {
|
||||
version := strings.TrimPrefix(o.Version, "v")
|
||||
if version == "" || o.Digest == "" {
|
||||
return "it names no version or no digest (a by-digest publish)"
|
||||
}
|
||||
all, err := rv.r.All(ctx)
|
||||
at, err := rv.r.AtVersion(ctx, version) // the index by version, never every reservation (H-A-271)
|
||||
if err != nil {
|
||||
return "the reservations cannot be read: " + err.Error()
|
||||
return "the reservations at " + version + " cannot be read: " + err.Error()
|
||||
}
|
||||
var out []string
|
||||
for _, v := range all {
|
||||
if v.Version != version {
|
||||
continue
|
||||
}
|
||||
for _, v := range at {
|
||||
out = append(out, fmt.Sprintf("%s holds %d built digests %v, published %v (a published heard before the build recorded its digests is kept until it does)", v.Module, len(v.Artifacts), v.Artifacts, v.Published))
|
||||
}
|
||||
if len(out) == 0 {
|
||||
@@ -383,3 +407,49 @@ func reserveDoneAct(reserve func(ctx context.Context, module, fp string) (versio
|
||||
func (rv *reservations) ReleasedFor(ctx context.Context, module, fingerprint string) (bool, error) {
|
||||
return rv.r.ReleasedFor(ctx, module, fingerprint)
|
||||
}
|
||||
|
||||
// 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 {
|
||||
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})
|
||||
}
|
||||
}
|
||||
|
||||
// heldElsewhere raises version-held-elsewhere about module (design 47 H H-A-275): numbers a registry holds were skipped or moved
|
||||
// from, said with why.
|
||||
func (rv *reservations) heldElsewhere(ctx context.Context, module, why string) {
|
||||
rv.logf("%s: %s", module, why)
|
||||
rv.found.raise(ctx, finding{kind: versions.VersionHeldElsewhere, scope: meshconditionsclient.ScopeModule, id: module,
|
||||
summary: module + ": " + why,
|
||||
headline: "A number a registry already holds is not used",
|
||||
explanation: "A registry seat holds a version of " + module + " the builder did not publish there: " + why + ".",
|
||||
resolved: "The catalog says version-released for " + module + ".",
|
||||
needs: "builder_reserved shows the reservation and its withdrawn numbers; the registry seat's versions shows what it holds."})
|
||||
}
|
||||
|
||||
// movedElsewhere takes a done build whose number a registry holds at another digest off that number (design 47 H H-A-275,
|
||||
// H-A-279): every artifact carries its version from its build, so no digest survives a move. The number is withdrawn as a gap
|
||||
// (H-A-226), the finding raised naming both digests, and the build of the same fingerprint asked again (the build-again path of a
|
||||
// done key whose version is not released, A-490): its reserve takes the next number no registry holds, it records fresh digests
|
||||
// and its own publish runs; the takeover of the withdrawn reservation ends its publish item and bound.
|
||||
func (rv *reservations) movedElsewhere(ctx context.Context, v versions.ReservedVersion, j versions.Judged) error {
|
||||
if rv.rebuild == nil {
|
||||
return errors.New("no build again is wired")
|
||||
}
|
||||
if _, ok, err := rv.r.Withdraw(ctx, v.Module, v.Version); err != nil || !ok {
|
||||
if err == nil {
|
||||
err = fmt.Errorf("no reservation of %s stands at %s", v.Module, v.Version)
|
||||
}
|
||||
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, "; "))
|
||||
rv.heldElsewhere(ctx, v.Module, why)
|
||||
return rv.rebuild(ctx, v.Module, v.Fingerprint, why)
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func (m *memReserve) Update(_ context.Context, key string, v []byte, rev uint64)
|
||||
func (m *memReserve) KeysOf(_ context.Context, filter string) ([]string, error) {
|
||||
var out []string
|
||||
for k := range m.vals {
|
||||
if filter == versions.AllFilter || strings.HasPrefix(k, strings.TrimSuffix(filter, "*")) {
|
||||
if versions.FilterMatches(filter, k) { // as the bus reads a filter
|
||||
out = append(out, k)
|
||||
}
|
||||
}
|
||||
@@ -266,7 +266,8 @@ func TestAPublishedHeardBeforeTheDigestsIsSaidWhenTheBuildRecordsThem(t *testing
|
||||
}
|
||||
|
||||
// TestABuildTakingOverAnOlderReservationDropsItsBoundAndSaysSo: design 47 G A-455 — a build that reserves while the series is
|
||||
// reserved by an older build never released drops the older one's bound and finding and says so in the builder's journal.
|
||||
// reserved by an older build never released drops the older one's bound and finding and says so in the builder's journal; and
|
||||
// H-A-225 — the older build is withdrawn, so nothing publishes under the dropped number, while a re-run of the newer keeps it.
|
||||
func TestABuildTakingOverAnOlderReservationDropsItsBoundAndSaysSo(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
st := &memFindings{vals: map[string][]byte{}}
|
||||
@@ -279,6 +280,8 @@ func TestABuildTakingOverAnOlderReservationDropsItsBoundAndSaysSo(t *testing.T)
|
||||
rv := newReservations(&memReserve{vals: map[string][]byte{}, revs: map[string]uint64{}}, call, func() jetstream.KeyValue { return bounds }, found,
|
||||
nil, func(f string, a ...any) { journal = append(journal, fmt.Sprintf(f, a...)) })
|
||||
rv.filled.Store(true)
|
||||
var withdrawn []string
|
||||
rv.withdraw = func(module, fp, why string) { withdrawn = append(withdrawn, module+" "+fp+": "+why) }
|
||||
older, err := rv.Reserve(ctx, "m", "0.1", []string{"m:a"}, versions.Source{Fingerprint: "fp-old"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -305,6 +308,12 @@ func TestABuildTakingOverAnOlderReservationDropsItsBoundAndSaysSo(t *testing.T)
|
||||
if got, ok, _ := rv.ReservedFor(ctx, "m", "fp-new"); !ok || got.Version != "0.1.1" {
|
||||
t.Errorf("reserved for fp-new: %+v %v", got, ok)
|
||||
}
|
||||
if len(withdrawn) != 1 || withdrawn[0] != "m fp-old: its reservation 0.1.0 was taken over by the build of fp-new, which reserves 0.1.1" {
|
||||
t.Errorf("withdrawn %q; want the build of fp-old withdrawn once", withdrawn)
|
||||
}
|
||||
if again, err := rv.Reserve(ctx, "m", "0.1", []string{"m:a"}, versions.Source{Fingerprint: "fp-new"}); err != nil || again.Version != "0.1.1" || len(withdrawn) != 1 {
|
||||
t.Errorf("a re-run of fp-new reserved %q (%v), withdrew %q; want 0.1.1 kept, nothing withdrawn", again.Version, err, withdrawn)
|
||||
}
|
||||
}
|
||||
|
||||
// ansKV records the value versionActed writes back to a reasks key.
|
||||
@@ -384,3 +393,87 @@ func TestAReserveDoneIsAnsweredWithTheVersionAndItsQueuedPublish(t *testing.T) {
|
||||
t.Errorf("the reserving by hand is not said in the log: %q", logged)
|
||||
}
|
||||
}
|
||||
|
||||
// TestARegistrysRecordEndsOrMovesAPublish: design 47 H H-A-274 — the artifacts a registry's record holds with the built digest are
|
||||
// marked published from it and package-published is said, as a heard published would; H-A-275 — a done build whose number a
|
||||
// registry holds at another digest (H-A-279) has its number withdrawn, raises version-held-elsewhere naming both digests, and is
|
||||
// built again: at the next number no registry holds, with a fresh digest, published there; the old number's item ends.
|
||||
func TestARegistrysRecordEndsOrMovesAPublish(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
fs := &memFindings{vals: map[string][]byte{}}
|
||||
none := func(string, any) (json.RawMessage, error) {
|
||||
return json.Marshal(meshcatalog.VersionsAnswer{Module: "node-tools"})
|
||||
}
|
||||
bounds := &boundsKV{keys: map[string]bool{}}
|
||||
rv := newReservations(&memReserve{vals: map[string][]byte{}, revs: map[string]uint64{}}, none, func() jetstream.KeyValue { return bounds },
|
||||
&findings{module: builds.BuilderModule, w: fs, logf: t.Logf, now: time.Now}, nil, t.Logf)
|
||||
var said []meshbuilds.PackagePublished
|
||||
rv.say = func(_ context.Context, p meshbuilds.PackagePublished) error { said = append(said, p); return nil }
|
||||
var asked, ended []string
|
||||
rv.built = func(_ context.Context, m, v string) error { asked = append(asked, m+" "+v); return nil }
|
||||
rv.released = func(_ context.Context, m, v string) { ended = append(ended, m+" "+v) }
|
||||
registry := []string{"0.1.37"}
|
||||
rv.r.HeldNumbers = func(context.Context, string, string, []string) ([]string, error) { return registry, nil }
|
||||
rv.filled.Store(true)
|
||||
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)
|
||||
}
|
||||
if err := rv.Built(ctx, "node-tools", res.Version, map[string]string{"node-tools:program": "sha256:7c9b10"}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cur, _, _ := rv.r.Of(ctx, "node-tools", res.Version)
|
||||
held := versions.HeldArtifact{Ref: "node-tools:program", Seat: versions.SeatArtifacts, Name: "node-tools/program", Version: res.Version, Digest: "sha256:7c9b10"}
|
||||
rv.markHeld(ctx, cur, []versions.HeldArtifact{held})
|
||||
if len(said) != 1 || said[0].Artifact != "node-tools:program" || said[0].Version != res.Version {
|
||||
t.Fatalf("package-published said %+v, want node-tools:program at %s from the registry's record", said, res.Version)
|
||||
}
|
||||
if cur, _, _ = rv.r.Of(ctx, "node-tools", res.Version); len(cur.Missing()) != 0 {
|
||||
t.Errorf("the record marked nothing: missing %v", cur.Missing())
|
||||
}
|
||||
// Another reservation of the module, done, whose number the registry holds at another digest: withdrawn, built again at the
|
||||
// next free number with a fresh digest, and published there (H-A-279).
|
||||
if _, err := rv.r.Released(ctx, "node-tools", res.Version); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
asked, ended, said, registry = nil, nil, nil, []string{"0.1.0", "0.1.1", "0.1.2"}
|
||||
raw, _ := json.Marshal(versions.ReservedVersion{V: 1, Module: "node-tools", Series: "0.1", Version: "0.1.1", Fingerprint: "fp2",
|
||||
Artifacts: map[string]string{"node-tools:program": "sha256:7c9b10"}, BuiltAt: time.Now()})
|
||||
if _, err := rv.r.Store.Create(ctx, versions.ReservedKey("node-tools", "0.1"), raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rv.rebuild = func(ctx context.Context, module, fp, _ string) error {
|
||||
again, err := rv.Reserve(ctx, module, "0.1", []string{"node-tools:program"}, versions.Source{Fingerprint: fp, Rebuild: true})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := rv.Built(ctx, module, again.Version, map[string]string{"node-tools:program": "sha256:fresh"}, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
rv.published(ctx, versions.Outcome{Name: "node-tools/program", Version: again.Version, Digest: "sha256:fresh"})
|
||||
return nil
|
||||
}
|
||||
cur, _, _ = rv.r.Of(ctx, "node-tools", "0.1.1")
|
||||
elsewhere := held
|
||||
elsewhere.Version, elsewhere.Digest = "0.1.1", "sha256:83bec1"
|
||||
if err := rv.movedElsewhere(ctx, cur, versions.Judged{Elsewhere: []versions.HeldArtifact{elsewhere}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
again, ok, _ := rv.r.Of(ctx, "node-tools", "")
|
||||
if !ok || again.Version != "0.1.3" || again.Withdrawn["0.1.1"] != "fp2" || again.Artifacts["node-tools:program"] != "sha256:fresh" {
|
||||
t.Fatalf("built again as %+v, want 0.1.3 with a fresh digest and 0.1.1 withdrawn", again)
|
||||
}
|
||||
if len(said) != 1 || said[0].Version != "0.1.3" || said[0].Digest != "sha256:fresh" {
|
||||
t.Errorf("package-published said %+v, want the fresh build at 0.1.3", said)
|
||||
}
|
||||
if len(asked) != 1 || asked[0] != "node-tools 0.1.3" || len(ended) != 1 || ended[0] != "node-tools 0.1.1" {
|
||||
t.Errorf("asked %v, ended %v: want the new number's publish asked and the old one's item ended", asked, ended)
|
||||
}
|
||||
raised := ""
|
||||
for _, v := range fs.vals {
|
||||
raised += string(v)
|
||||
}
|
||||
if !strings.Contains(raised, versions.VersionHeldElsewhere) || !strings.Contains(raised, "sha256:83bec1") || !strings.Contains(raised, "sha256:7c9b10") {
|
||||
t.Errorf("no version-held-elsewhere naming both digests: %s", raised)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,6 +149,9 @@ type Reservations interface {
|
||||
ReservedFor(ctx context.Context, module, fingerprint string) (versions.ReservedVersion, bool, error)
|
||||
// ReleasedFor says whether a version was released for the build of fingerprint, read from the builder's own record (A-456a).
|
||||
ReleasedFor(ctx context.Context, module, fingerprint string) (bool, error)
|
||||
// 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)
|
||||
}
|
||||
|
||||
// reserves says whether a look at a trunk build is one that reserves: the build has a series of the form MAJOR.MINOR
|
||||
@@ -194,7 +197,7 @@ func (b *Builder) reserve(ctx context.Context, module string, m meshcatalog.Modu
|
||||
for _, t := range plan.Tasks {
|
||||
refs = append(refs, module+":"+t.Artifact)
|
||||
}
|
||||
src := versions.Source{Repository: m.Repository, Commit: m.Commit, Fingerprint: m.Fp2, Branch: o.Branch, Revision: o.Source, Rebuild: rebuild}
|
||||
src := versions.Source{Repository: m.Repository, Commit: m.Commit, Fingerprint: m.Fp2, Branch: o.Branch, Revision: o.Source, CatalogRevision: o.Revision, Rebuild: rebuild}
|
||||
for _, t := range plan.Tasks {
|
||||
src.GoPackage = src.GoPackage || (t.Kind == catalogue.ArtifactPackage && t.Language == "go")
|
||||
}
|
||||
|
||||
@@ -29,8 +29,14 @@ type fakeReservations struct {
|
||||
built map[string]string
|
||||
sources []versions.Source
|
||||
deps map[string][]meshbuilds.Dependency
|
||||
next string // the version Reserve answers when set, else the series' .5
|
||||
fail error // the reservation cannot be made (the catalog's versions cannot be read)
|
||||
next string // the version Reserve answers when set, else the series' .5
|
||||
fail error // the reservation cannot be made (the catalog's versions cannot be read)
|
||||
tookBy map[string]versions.ReservedVersion // by fingerprint, the reservation that took its series over (H-A-244)
|
||||
}
|
||||
|
||||
func (f *fakeReservations) TakenOver(_ context.Context, _, fp string) (versions.ReservedVersion, bool, error) {
|
||||
v, ok := f.tookBy[fp]
|
||||
return v, ok, nil
|
||||
}
|
||||
|
||||
func (f *fakeReservations) ReleasedFor(_ context.Context, _, fp string) (bool, error) {
|
||||
@@ -354,7 +360,10 @@ func (r *realReserve) Built(ctx context.Context, module, version string, digests
|
||||
|
||||
type reserveMap struct{ *memStore }
|
||||
|
||||
func (m reserveMap) KeysOf(ctx context.Context, _ string) ([]string, error) { return m.Keys(ctx) }
|
||||
func (m reserveMap) KeysOf(ctx context.Context, filter string) ([]string, error) {
|
||||
all, err := m.Keys(ctx)
|
||||
return slices.DeleteFunc(all, func(k string) bool { return !versions.FilterMatches(filter, k) }), err // as the bus reads a filter
|
||||
}
|
||||
func (m reserveMap) Delete(_ context.Context, key string) error {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
@@ -362,10 +371,10 @@ func (m reserveMap) Delete(_ context.Context, key string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TestABuildAgainReservesAboveTheCatalogsHighestNotItsOwnStandingNumber: design 47 G A-490b, at the build, through the real
|
||||
// reserver — a done key whose own fingerprint has an unreleased 0.1.30 standing, the catalog's highest 0.1.16, is built again
|
||||
// under 0.1.17 (never 0.1.31), the standing reservation taken over.
|
||||
func TestABuildAgainReservesAboveTheCatalogsHighestNotItsOwnStandingNumber(t *testing.T) {
|
||||
// TestABuildAgainKeepsItsOwnStandingNumber: design 47 G A-490b as H-A-225 amends it, at the build, through the real reserver —
|
||||
// a done key whose own fingerprint has an unreleased 0.1.30 standing, the catalog's highest 0.1.16, is built again under 0.1.30
|
||||
// (never 0.1.31, never a new number): the run building carries the standing number until it is released.
|
||||
func TestABuildAgainKeepsItsOwnStandingNumber(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 {
|
||||
@@ -381,8 +390,8 @@ func TestABuildAgainReservesAboveTheCatalogsHighestNotItsOwnStandingNumber(t *te
|
||||
r.b.Reserved = real
|
||||
got := r.b.BuildAgain(context.Background(), "m", fp1, "its publish was refused", "shanks.lead", 2*time.Second)
|
||||
r.b.Wait()
|
||||
cur, ok, err := real.Of(context.Background(), "m", "0.1.17")
|
||||
if got.Refused != "" || err != nil || !ok || cur.Fingerprint != fp1 {
|
||||
t.Fatalf("answer %+v; reservation of 0.1.17 = %+v (%v, %v); want built again under 0.1.17, the catalog's highest 0.1.16 plus one", got, cur, ok, err)
|
||||
cur, ok, err := real.Of(context.Background(), "m", "")
|
||||
if got.Refused != "" || err != nil || !ok || cur.Fingerprint != fp1 || cur.Version != "0.1.30" {
|
||||
t.Fatalf("answer %+v; reservation = %+v (%v, %v); want built again under its standing 0.1.30", got, cur, ok, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,17 @@ import (
|
||||
// revision its view holds (PictureHeld, H-A-162), never a
|
||||
// timer or a poll, up to RevisionWait (the setting revision-wait-minutes); past it the ask fails, naming the revision and the
|
||||
// branch, and nothing is built. A step ask with no source (a run on request) does not wait.
|
||||
//
|
||||
// **The picture holds every kept revision, not only the newest** (design 47 H H-A-205, H-A-147): an ask of a source revision
|
||||
// below the newest the picture holds, whose entries the picture no longer names, asks the catalog seat's verb revision for
|
||||
// its catalog revision by number, once, and is built when that kept revision is of its source and names every entry it
|
||||
// asks; it never waits, since the picture only moves on. Only a revision above the newest is waited for.
|
||||
//
|
||||
// **An ask naming a revision is held by its number** (design 47 H H-A-222): when the picture does not name the ask's
|
||||
// entries, the ask's catalog revision is read by number, and the ask is built when the catalog keeps it and it names every
|
||||
// fingerprint asked, whatever the source the picture holds says (a re-pin keeps a later revision of the same source, H-A-211,
|
||||
// H-A-213, so the source alone cannot say it). The source is compared only for an ask naming no revision; an ask whose
|
||||
// revision the catalog does not answer and whose source is not below the picture's waits as before.
|
||||
|
||||
// DefaultRevisionWait is the bound of a step ask's wait for its revision, its setting revision-wait-minutes' default (H-A-156).
|
||||
const DefaultRevisionWait = 2 * time.Minute
|
||||
@@ -68,12 +79,68 @@ func (b *Builder) holdsRevision(branch string, source int64, entries []meshbuild
|
||||
return true
|
||||
}
|
||||
|
||||
// keptRevisionHolds answers no outcome when the catalog keeps the ask's revision (its catalog revision by number) and that
|
||||
// revision names every entry of the ask (H-A-205, H-A-222); else failed or could not run, with its words.
|
||||
func (b *Builder) keptRevisionHolds(ctx context.Context, run meshbuilds.StepRun, held int64) (outcome, said string) {
|
||||
below := fmt.Sprintf("revision %d of %s is not named by the builder's picture, which holds source revision %d", run.Source, run.Branch, held)
|
||||
if run.Source < held {
|
||||
below = fmt.Sprintf("revision %d of %s is below the %d the builder's picture holds", run.Source, run.Branch, held)
|
||||
}
|
||||
if b.KeptRevision == nil || run.Revision <= 0 {
|
||||
return meshbuilds.StepEndedOutcomeFailed, below + ", and the ask names no catalog revision to read it by"
|
||||
}
|
||||
source, fps, err := b.KeptRevision(ctx, run.Branch, run.Revision)
|
||||
if err != nil {
|
||||
b.logf("%s: %s, and the catalog's revision %d cannot be read: %v", run.Pipeline, below, run.Revision, err)
|
||||
return meshbuilds.StepEndedOutcomeCouldNotRun, fmt.Sprintf("%s, and the catalog's revision %d cannot be read: %v", below, run.Revision, err)
|
||||
}
|
||||
// An ask names the revision and the source of one revision (H-A-218, H-A-219): a kept revision of another source is
|
||||
// not the ask's.
|
||||
if source != run.Source {
|
||||
b.logf("%s: %s, and the catalog's revision %d is of source revision %d, the ask names %d: the step fails, nothing is built", run.Pipeline, below, run.Revision, source, run.Source)
|
||||
return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s, and the catalog's revision %d is of source revision %d, the ask names %d", below, run.Revision, source, run.Source)
|
||||
}
|
||||
for _, e := range run.Entries {
|
||||
if fps[e.Module] != e.Fingerprint {
|
||||
b.logf("%s: %s, and the catalog's revision %d names %s at %q, not %s: the step fails, nothing is built", run.Pipeline, below, run.Revision, e.Module, fps[e.Module], e.Fingerprint)
|
||||
return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s, and the catalog's revision %d names %s at %q, not %s", below, run.Revision, e.Module, fps[e.Module], e.Fingerprint)
|
||||
}
|
||||
}
|
||||
// Each asked fingerprint is recorded as the branch's, so its build reserves its version (H-A-155) as one the picture
|
||||
// took in does; what the picture heard stays as it is, so the newer fingerprint's build is not superseded.
|
||||
b.mu.Lock()
|
||||
for _, e := range run.Entries {
|
||||
key, err := builds.BuilderBuildKey(e.Module, e.Fingerprint)
|
||||
if err != nil || b.origin[key].Branch != "" {
|
||||
continue
|
||||
}
|
||||
first := b.FirstBranch == nil || b.FirstBranch(run.Branch, e.Module)
|
||||
b.trunkFP[key] = true
|
||||
b.origin[key] = Origin{Branch: run.Branch, Source: run.Source, Revision: run.Revision, First: first}
|
||||
}
|
||||
b.mu.Unlock()
|
||||
b.logf("%s: %s; the catalog keeps revision %d with its entries: the build goes on", run.Pipeline, below, run.Revision)
|
||||
return "", ""
|
||||
}
|
||||
|
||||
// awaitRevision returns no outcome once the builder's picture of the ask's branch holds its source revision; past the bound the
|
||||
// step's outcome failed, at the builder's stop could not run, each with its words.
|
||||
func (b *Builder) awaitRevision(ctx context.Context, run meshbuilds.StepRun) (outcome, said string) {
|
||||
if b.Picture == nil || run.Source <= 0 || run.Branch == "" {
|
||||
return "", ""
|
||||
}
|
||||
if held, ok := b.Picture(run.Branch); !b.holdsRevision(run.Branch, run.Source, run.Entries) {
|
||||
below := ok && run.Source < held
|
||||
if (run.Revision > 0 && b.KeptRevision != nil) || below {
|
||||
// By its number (H-A-222), whatever the source the picture holds; for an ask naming none, only below the
|
||||
// picture (H-A-205). A kept revision of another source or naming other fingerprints is a mismatch the wait
|
||||
// cannot mend: it fails at once; only a revision the catalog does not answer is waited for.
|
||||
outcome, said := b.keptRevisionHolds(ctx, run, held)
|
||||
if outcome == "" || below || outcome == meshbuilds.StepEndedOutcomeFailed {
|
||||
return outcome, said
|
||||
}
|
||||
}
|
||||
}
|
||||
bound := b.revisionWait()
|
||||
notHeld := fmt.Sprintf("revision %d of %s not in the builder's picture", run.Source, run.Branch)
|
||||
wait, stop := context.WithTimeout(ctx, bound) // a context's bound, no timer (ADR 0437 §8)
|
||||
|
||||
@@ -110,6 +110,14 @@ type Builder struct {
|
||||
// Picture answers the source revision the builder's picture of a watched branch holds, false while it holds none (design 47
|
||||
// H H-A-155, H-A-141): a step ask naming a newer one waits for it. Nil waits for nothing.
|
||||
Picture func(branch string) (source int64, held bool)
|
||||
// KeptRevision asks the catalog seat's verb revision for one kept revision of a branch by its number (design 47 H
|
||||
// H-A-205, H-A-147): the source revision it was taken in from and the fingerprint of each module it names. A step ask of
|
||||
// a source revision below the newest the picture holds is built when that kept revision names its entries. Nil reads none.
|
||||
KeptRevision func(ctx context.Context, branch string, revision int64) (source int64, fingerprints map[string]string, err error)
|
||||
// FirstBranch says whether branch is the first watched branch of the module's registration, the one whose builds reserve
|
||||
// a version (design 47 G §371): an ask admitted by its kept revision is recorded as that branch's (H-A-205, H-A-155). Nil
|
||||
// takes every branch as the first, as an origin never heard is.
|
||||
FirstBranch func(branch, module string) bool
|
||||
// RevisionWait bounds a step ask's wait for its revision, its setting revision-wait-minutes (H-A-156); DefaultRevisionWait
|
||||
// when 0.
|
||||
RevisionWait time.Duration
|
||||
@@ -229,7 +237,9 @@ func (b *Builder) Module(ctx context.Context, key string, value []byte) {
|
||||
type Origin struct {
|
||||
Branch string
|
||||
Source int64
|
||||
First bool
|
||||
// Revision is the catalog revision number a step ask of the build named (design 47 H H-A-218), 0 until one did.
|
||||
Revision int64
|
||||
First bool
|
||||
}
|
||||
|
||||
// Entry takes the catalog graph entry of one module on one watched branch in (design 47 G §348, §614) and builds its
|
||||
@@ -256,6 +266,23 @@ func (b *Builder) EntryGone(branch string, first bool, module string) {
|
||||
}
|
||||
}
|
||||
|
||||
// Withdraw ends the running build of module's fingerprint, superseded, with why (design 47 H H-A-225, ADR 0664 §4): its key
|
||||
// fails "withdrawn" and its asks are withdrawn from the build seats. A fingerprint with no build running is left.
|
||||
func (b *Builder) Withdraw(module, fingerprint, why string) {
|
||||
key, err := builds.BuilderBuildKey(module, fingerprint)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
b.init()
|
||||
b.mu.Lock()
|
||||
withdraw := b.builds[key]
|
||||
b.mu.Unlock()
|
||||
if withdraw != nil {
|
||||
b.logf("%s at %s: the build is withdrawn: %s", module, fingerprint, why)
|
||||
withdraw(buildrun.Withdrawn{Why: why})
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Builder) take(ctx context.Context, o Origin, key string, m meshcatalog.ModulesByModuleValue, e []meshcatalog.Edge) {
|
||||
b.mu.Lock()
|
||||
hk := o.Branch + "\x00" + key
|
||||
@@ -697,8 +724,9 @@ func (b *Builder) try(ctx context.Context, module string, m meshcatalog.ModulesB
|
||||
var reserved versions.ReservedVersion
|
||||
hasReserved := false
|
||||
if rebuild && cl.Build.State == builds.BuildBuilding {
|
||||
// Reserved afresh, above the highest the catalog's versions answers, taking over the older unreleased reservation of this
|
||||
// fingerprint (A-455), never its standing number kept (A-490b); the build's own publish then runs.
|
||||
// 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.
|
||||
if b.Reserved.Filled() {
|
||||
reserved, hasReserved = b.reserve(ctx, module, m, plan, b.originOf(key), true)
|
||||
}
|
||||
@@ -833,6 +861,7 @@ type lane struct {
|
||||
tcVersion string // and the version it ran
|
||||
kept string // the digest of the artifact the build node kept instead of storing it (BuildAnswer.Kept), else empty
|
||||
outOfStep []string // the generated files its build module's compare found out of step, passed or failed
|
||||
pins map[string]string // the mesh packages' versions its Go ask was built with (H-A-207)
|
||||
err error
|
||||
}
|
||||
|
||||
@@ -982,7 +1011,7 @@ func (b *Builder) build(ctx context.Context, module string, m meshcatalog.Module
|
||||
used = nil
|
||||
}
|
||||
done := builds.BuilderBuild{State: builds.BuildDone, By: b.Claimer.By, Manifest: m.Manifest, Step: step, Artifacts: artifacts, Toolchains: used,
|
||||
Imports: importsOf(lanes), Needs: forms.Current.Needs(artifacts)} // the forms it is written in (ADR 0618 §1)
|
||||
Imports: importsOf(lanes), Needs: forms.Current.Needs(artifacts), Packages: pinsOf(lanes)} // the forms it is written in (ADR 0618 §1)
|
||||
for _, l := range lanes {
|
||||
if l.kept != "" {
|
||||
done.KeptOn = l.node // design 47 G §671: the build node that keeps the build
|
||||
@@ -1144,6 +1173,7 @@ func (b *Builder) runLane(ctx context.Context, l *lane, repository string, m mes
|
||||
for _, fb := range req.Builds {
|
||||
delete(ask.Packages, fb.Package) // a package `builds` names is named in neither packages nor package (§465)
|
||||
}
|
||||
l.pins = maps.Clone(ask.Packages) // kept with the done key, so its step's end reports them (H-A-207)
|
||||
}
|
||||
if id := asked.resume(language); id != "" {
|
||||
ask.ID = id // put before this builder started again: the stream holds it, or a node already ran it
|
||||
@@ -1326,6 +1356,20 @@ func (b *Builder) takeOutOfStep(key string) []string {
|
||||
// importsOf are the mesh packages the lanes' programs import, as their build modules answered them (novox/hq ADR 0593
|
||||
// §2): sorted and each once; nil when none answered any. A lane kept from a prior build answered none, so a build that
|
||||
// kept one reports only what it built.
|
||||
// pinsOf is the mesh packages' versions the lanes were built with (H-A-207), nil when none was pinned.
|
||||
func pinsOf(lanes []*lane) map[string]string {
|
||||
var out map[string]string
|
||||
for _, l := range lanes {
|
||||
for p, v := range l.pins {
|
||||
if out == nil {
|
||||
out = map[string]string{}
|
||||
}
|
||||
out[p] = v
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func importsOf(lanes []*lane) []string {
|
||||
seen := map[string]bool{}
|
||||
for _, l := range lanes {
|
||||
|
||||
@@ -327,6 +327,37 @@ func TestABundleAndAnArchiveAreBuiltOnOneNodeAndDone(t *testing.T) { // 1607/AC7
|
||||
}
|
||||
}
|
||||
|
||||
// H-A-225 (ADR 0664 §4): a build withdrawn while it runs (its reservation taken over by another fingerprint) ends failed
|
||||
// "withdrawn" with why, so it never publishes under the dropped number; a fingerprint with no build running is left.
|
||||
func TestAWithdrawnBuildEndsWithdrawn(t *testing.T) {
|
||||
r := newRig(t, goBundle)
|
||||
asked, release := make(chan struct{}), make(chan struct{})
|
||||
answer := r.answer
|
||||
r.asks.Answer = func(a buildstep.StepAsk) buildstep.Step {
|
||||
close(asked)
|
||||
<-release
|
||||
return answer(a)
|
||||
}
|
||||
r.b.Withdraw("m", fp1, "nothing runs yet") // left: no build of it runs
|
||||
data, err := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Repository: "novox/mesh-catalog", Commit: "7a74cee83f88e6585a5511c3cc53bdf0f5303d20",
|
||||
Fp2: fp1, Manifest: mdigest('a'), Path: "modules/m", Toolchains: CatalogToolchains(agreedToolchains)})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.b.Module(context.Background(), "m", data)
|
||||
select {
|
||||
case <-asked:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("no ask was put")
|
||||
}
|
||||
r.b.Withdraw("m", fp1, "its reservation 0.1.3 was taken over by the build of src2:b, which reserves 0.1.4")
|
||||
close(release)
|
||||
r.b.Wait()
|
||||
if v := valueOf(t, r.st, r.key); v.State != builds.BuildFailed || !strings.Contains(v.Error, "withdrawn: its reservation 0.1.3 was taken over") {
|
||||
t.Fatalf("the key = %+v, want failed withdrawn naming the take-over", v)
|
||||
}
|
||||
}
|
||||
|
||||
// 1887/AC1, AC2: a trunk fingerprint with no key is one ask on the Go seat's delivery stream, named in the building key
|
||||
// before it is put, and the builder calls no node; the step a node wrote for it makes the key done naming its reference.
|
||||
func TestATrunkFingerprintIsOneAskOnTheDeliveryStream(t *testing.T) {
|
||||
|
||||
@@ -39,9 +39,21 @@ func (b *Builder) BuildStep(ctx context.Context, run meshbuilds.StepRun) meshbui
|
||||
if outcome, said := b.awaitRevision(ctx, run); outcome != "" {
|
||||
return finish(outcome, said)
|
||||
}
|
||||
b.askedRevision(run)
|
||||
var failed []string
|
||||
for _, e := range run.Entries {
|
||||
outcome, said := b.buildEntry(ctx, e)
|
||||
var pins map[string]string
|
||||
outcome, said := b.buildEntry(ctx, e, &pins)
|
||||
// The end reports the pins each entry was built with, so the runner asks its held test steps with them (H-A-207).
|
||||
for path, version := range pins {
|
||||
if version == "" {
|
||||
continue
|
||||
}
|
||||
if end.Packages == nil {
|
||||
end.Packages = map[string]string{}
|
||||
}
|
||||
end.Packages[path] = version
|
||||
}
|
||||
switch outcome {
|
||||
case meshbuilds.StepEndedOutcomeCouldNotRun:
|
||||
return finish(outcome, said)
|
||||
@@ -55,8 +67,30 @@ func (b *Builder) BuildStep(ctx context.Context, run meshbuilds.StepRun) meshbui
|
||||
return finish(meshbuilds.StepEndedOutcomePassed, "")
|
||||
}
|
||||
|
||||
// buildEntry builds one entry at its fingerprint and waits for its end.
|
||||
func (b *Builder) buildEntry(ctx context.Context, e meshbuilds.BuildEntry) (outcome, said string) {
|
||||
// askedRevision records on the origin of each entry of run the catalog revision the ask names (design 47 H H-A-218), where
|
||||
// the origin is of the ask's branch and source revision: the version reserved for its build names it, and so does its
|
||||
// package-published, so the runner finds the publishing pipeline by branch and revision.
|
||||
func (b *Builder) askedRevision(run meshbuilds.StepRun) {
|
||||
if run.Revision <= 0 {
|
||||
return
|
||||
}
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
for _, e := range run.Entries {
|
||||
key, err := builds.BuilderBuildKey(e.Module, e.Fingerprint)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if o, ok := b.origin[key]; ok && o.Branch == run.Branch && o.Source == run.Source {
|
||||
o.Revision = run.Revision
|
||||
b.origin[key] = o
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// buildEntry builds one entry at its fingerprint and waits for its end; pins is set, when it is done, to the pins its
|
||||
// done key keeps it was built with, the registry's included (H-A-207).
|
||||
func (b *Builder) buildEntry(ctx context.Context, e meshbuilds.BuildEntry, pins *map[string]string) (outcome, said string) {
|
||||
entry, err := b.StepEntry(ctx, e.Fingerprint)
|
||||
if err != nil {
|
||||
return meshbuilds.StepEndedOutcomeCouldNotRun, fmt.Sprintf("the entry %s at %s cannot be read: %v", e.Module, e.Fingerprint, err)
|
||||
@@ -78,6 +112,8 @@ func (b *Builder) buildEntry(ctx context.Context, e meshbuilds.BuildEntry) (outc
|
||||
defer b.dropEnd(key, ended)
|
||||
if done, failedWords, found := b.keyEnd(ctx, key); found {
|
||||
if done {
|
||||
// A key done before reports the pins it was built with, kept with it, never the ones a publish gives now.
|
||||
*pins = b.keptPins(ctx, key)
|
||||
return b.passedWithItsVersion(ctx, entry)
|
||||
}
|
||||
return meshbuilds.StepEndedOutcomeFailed, failedWords
|
||||
@@ -88,6 +124,7 @@ func (b *Builder) buildEntry(ctx context.Context, e meshbuilds.BuildEntry) (outc
|
||||
select {
|
||||
case log := <-ended:
|
||||
if log.Outcome == builds.BuildDone {
|
||||
*pins = b.keptPins(ctx, key)
|
||||
return b.passedWithItsVersion(ctx, entry)
|
||||
}
|
||||
return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s at %s: %s %s", log.Module, log.FP, log.Outcome, log.Error)
|
||||
@@ -99,7 +136,8 @@ func (b *Builder) buildEntry(ctx context.Context, e meshbuilds.BuildEntry) (outc
|
||||
// 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
|
||||
// that can never be released. A build that reserves none (a candidate's, a series of before G) passes as it did.
|
||||
// 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) {
|
||||
if b.Reserved == nil {
|
||||
return meshbuilds.StepEndedOutcomePassed, ""
|
||||
@@ -131,11 +169,31 @@ func (b *Builder) passedWithItsVersion(ctx context.Context, entry meshcatalog.Ca
|
||||
} else if released {
|
||||
return meshbuilds.StepEndedOutcomePassed, "" // a released build counts as reserved (A-456a)
|
||||
}
|
||||
if by, took, err := b.Reserved.TakenOver(ctx, entry.Module, entry.Fp); err != nil {
|
||||
return meshbuilds.StepEndedOutcomeCouldNotRun, fmt.Sprintf("%s at %s: the reservations cannot be read: %v", entry.Module, entry.Fp, err)
|
||||
} else if took {
|
||||
// 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.StepEndedOutcomePassed, ""
|
||||
}
|
||||
|
||||
// keptPins are the pins a done key keeps it was built with (H-A-207); none when it keeps none or cannot be read, so the
|
||||
// runner ends the steps that waited for them could not run, loud.
|
||||
func (b *Builder) keptPins(ctx context.Context, key string) map[string]string {
|
||||
raw, _, ok, err := b.Claimer.Store.Get(ctx, key)
|
||||
if err != nil || !ok {
|
||||
return nil
|
||||
}
|
||||
v, err := builds.DecodeBuilderBuild(raw)
|
||||
if err != nil || v.State != builds.BuildDone {
|
||||
return nil
|
||||
}
|
||||
return v.Packages
|
||||
}
|
||||
|
||||
// keyEnd reads the build key: whether it is done, and its error when it failed for good; found only for a key that has ended.
|
||||
func (b *Builder) keyEnd(ctx context.Context, key string) (done bool, failed string, found bool) {
|
||||
raw, _, ok, err := b.Claimer.Store.Get(ctx, key)
|
||||
|
||||
@@ -89,18 +89,23 @@ func TestABuildStepPassesAReservingBuildOnlyWithItsReservedVersion(t *testing.T)
|
||||
for _, c := range []struct {
|
||||
name, version string
|
||||
reserve, released, unreadable bool
|
||||
takenOver bool
|
||||
want, said string
|
||||
}{
|
||||
{"no version reserved", "0.1", false, false, false, meshbuilds.StepEndedOutcomeFailed, "built at " + fp1 + ", but no version is reserved for it"},
|
||||
{"a version reserved", "0.1", true, false, false, meshbuilds.StepEndedOutcomePassed, ""},
|
||||
{"a released build whose reservation is gone", "0.1", false, true, false, meshbuilds.StepEndedOutcomePassed, ""},
|
||||
{"the plan cannot be read", "0.1", false, false, true, meshbuilds.StepEndedOutcomeCouldNotRun, "plan cannot be read"},
|
||||
{"a series of before G", "1", false, false, false, meshbuilds.StepEndedOutcomePassed, ""},
|
||||
{"no version reserved", "0.1", false, false, false, false, meshbuilds.StepEndedOutcomeFailed, "built at " + fp1 + ", but no version is reserved for it"},
|
||||
{"H-A-244: its series was taken over by a newer fingerprint", "0.1", false, false, false, true, meshbuilds.StepEndedOutcomeFailed, "m: built at " + fp1 + " but its series moved to " + fp2 + " 0.1.7: stale"},
|
||||
{"a version reserved", "0.1", true, false, false, false, meshbuilds.StepEndedOutcomePassed, ""},
|
||||
{"a released build whose reservation is gone", "0.1", false, true, false, false, meshbuilds.StepEndedOutcomePassed, ""},
|
||||
{"the plan cannot be read", "0.1", false, false, true, false, meshbuilds.StepEndedOutcomeCouldNotRun, "plan cannot be read"},
|
||||
{"a series of before G", "1", false, false, false, false, meshbuilds.StepEndedOutcomePassed, ""},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
r := newRig(t, goBundle)
|
||||
r.mf.byDigest[mdigest('a')] = catalogue.Manifest{Module: "m", Version: c.version, Build: &catalogue.Build{Artifacts: []catalogue.Artifact{goBundle}}}
|
||||
res := &fakeReservations{filled: true, released: map[string]bool{fp1: c.released}}
|
||||
if c.takenOver {
|
||||
res.tookBy = map[string]versions.ReservedVersion{fp1: {Module: "m", Series: "0.1", Version: "0.1.7", Fingerprint: fp2}}
|
||||
}
|
||||
if v := r.consider(t, "modules/m"); v.State != builds.BuildDone { // built while the builder reserved nothing, as the live key was
|
||||
t.Fatalf("build = %+v, want done", v)
|
||||
}
|
||||
@@ -112,13 +117,14 @@ 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(), 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")) {
|
||||
if end.Outcome != c.want || !strings.Contains(end.Said, c.said) || (c.want == meshbuilds.StepEndedOutcomeFailed && strings.Contains(end.Said, "builder_reserve_done") == c.takenOver) {
|
||||
t.Errorf("end = %+v, want %s saying %q", end, c.want, c.said)
|
||||
}
|
||||
})
|
||||
}
|
||||
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)
|
||||
t.Run("H-A-162: a revision held that changes no entry wakes the ask", aRevisionHeldWakesTheAsk)
|
||||
t.Run("H-A-165: a package with no pin waits for its release and is built with it", aPackageWithNoPinWaitsForItsRelease)
|
||||
t.Run("H-A-165: past its bound a package with no release fails the step", aPackageWithNoReleaseFailsPastItsBound)
|
||||
@@ -189,6 +195,32 @@ func aPackageWithNoPinWaitsForItsRelease(t *testing.T) {
|
||||
!reflect.DeepEqual(asks[0].Packages, buildstep.PackageVersions{unpinnedX: "v0.1.3", "git.novox.be/novox/mesh-sdk/go": "v0.1.20"}) {
|
||||
t.Errorf("end = %+v, asks %+v; want passed, built with x at v0.1.3", end, asks)
|
||||
}
|
||||
// The end reports the pins the build was built with, the one the publish gave included (H-A-207).
|
||||
if !reflect.DeepEqual(end.Packages, map[string]string{unpinnedX: "v0.1.3", "git.novox.be/novox/mesh-sdk/go": "v0.1.20"}) {
|
||||
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 the newer one a publish gives now (H-A-207).
|
||||
r.b.PackagePublished(unpinnedX, "v0.1.5")
|
||||
again := r.b.BuildStep(t.Context(), 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" {
|
||||
t.Errorf("the done key's end = %+v; want passed reporting x at v0.1.3, as built", again)
|
||||
}
|
||||
// A done key that keeps no pins reports none, so the runner ends the waiting steps loud.
|
||||
v, err := builds.DecodeBuilderBuild(r.st.vals[r.key])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
v.Packages = nil
|
||||
raw, err := builds.EncodeBuilderBuild(v)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.st.vals[r.key] = raw
|
||||
if bare := r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.9.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Source: 41,
|
||||
Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}); len(bare.Packages) != 0 {
|
||||
t.Errorf("a done key keeping no pins reported %v; want none", bare.Packages)
|
||||
}
|
||||
}
|
||||
|
||||
func aPackageWithNoReleaseFailsPastItsBound(t *testing.T) {
|
||||
@@ -329,6 +361,11 @@ func aStepAskWaitsForItsRevision(t *testing.T) {
|
||||
held.Store(40)
|
||||
asked := make(chan struct{}, 1)
|
||||
r, res, entry := revisionRig(t, &held, asked)
|
||||
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)
|
||||
return 0, nil, errors.New("not asked")
|
||||
}
|
||||
ended := make(chan meshbuilds.StepEnded, 1)
|
||||
go func() {
|
||||
ended <- r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.7.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Revision: 7, Source: 41,
|
||||
@@ -353,8 +390,84 @@ func aStepAskWaitsForItsRevision(t *testing.T) {
|
||||
t.Fatal("the ask was not woken by the entry the picture took in")
|
||||
}
|
||||
r.b.Wait()
|
||||
if end.Outcome != meshbuilds.StepEndedOutcomePassed || len(res.sources) != 1 || res.sources[0].Revision != 41 {
|
||||
t.Errorf("end = %+v, reserved from %+v; want passed with one version reserved from revision 41", end, res.sources)
|
||||
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-205: two pipelines of consecutive revisions run at once; the picture holds source revision 46, whose entry of m moved
|
||||
// on, while the older pipeline asks the build of revision 45. Its kept catalog revision is read by number and the build runs;
|
||||
// a kept revision naming another fingerprint fails the step, naming it.
|
||||
func anOlderKeptRevisionIsReadByNumber(t *testing.T) {
|
||||
var held atomic.Int64
|
||||
held.Store(46)
|
||||
r, res, _ := revisionRig(t, &held, make(chan struct{}, 1)) // a picture at 46 that never heard 45 (a restart)
|
||||
r.b.RevisionWait = time.Nanosecond // a wait would fail at once: the older revision is never waited for
|
||||
r.b.FirstBranch = func(branch, module string) bool { return branch == "main" && module == "m" }
|
||||
var read []string
|
||||
r.b.KeptRevision = func(_ context.Context, branch string, revision int64) (int64, map[string]string, error) {
|
||||
read = append(read, fmt.Sprintf("%s %d", branch, revision))
|
||||
return 45, map[string]string{"m": fp1}, nil
|
||||
}
|
||||
run := meshbuilds.StepRun{Pipeline: "main.47.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Revision: 47, Source: 45,
|
||||
Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}
|
||||
end := r.b.BuildStep(t.Context(), run)
|
||||
r.b.Wait()
|
||||
if end.Outcome != meshbuilds.StepEndedOutcomePassed || !slices.Equal(read, []string{"main 47"}) {
|
||||
t.Errorf("end = %+v, kept revisions read %v; want passed, revision 47 of main read once", end, read)
|
||||
}
|
||||
// Its fingerprint is recorded as the branch's: its build reserves its version from source revision 45 (H-A-155).
|
||||
// The version reserved names the catalog revision the ask named, which its package-published says (H-A-218).
|
||||
if len(res.sources) != 1 || res.sources[0].Revision != 45 || res.sources[0].CatalogRevision != 47 {
|
||||
t.Errorf("reserved from %+v; want one version reserved from source revision 45 at catalog revision 47 (H-A-218)", res.sources)
|
||||
}
|
||||
r2, _, _ := revisionRig(t, &held, make(chan struct{}, 1))
|
||||
r2.b.RevisionWait = time.Nanosecond
|
||||
r2.b.KeptRevision = func(context.Context, string, int64) (int64, map[string]string, error) {
|
||||
return 45, map[string]string{"m": "src2:other"}, nil
|
||||
}
|
||||
if end := r2.b.BuildStep(t.Context(), run); end.Outcome != meshbuilds.StepEndedOutcomeFailed || !strings.Contains(end.Said, "names m at \"src2:other\"") {
|
||||
t.Errorf("end = %+v; want failed naming the fingerprint the kept revision names", end)
|
||||
}
|
||||
// H-A-222: an ask of the very source the picture holds, whose entries the picture no longer names (a re-pin kept revision 48
|
||||
// of the same source 46 and the picture took its entries in), is held by its revision read by number, never waited for.
|
||||
r3, res3, _ := revisionRig(t, &held, make(chan struct{}, 1))
|
||||
r3.b.RevisionWait = time.Nanosecond
|
||||
r3.b.FirstBranch = func(branch, module string) bool { return branch == "main" && module == "m" }
|
||||
var read3 []string
|
||||
r3.b.KeptRevision = func(_ context.Context, branch string, revision int64) (int64, map[string]string, error) {
|
||||
read3 = append(read3, fmt.Sprintf("%s %d", branch, revision))
|
||||
return 46, map[string]string{"m": fp1}, nil
|
||||
}
|
||||
same := meshbuilds.StepRun{Pipeline: "main.48.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Revision: 48, Source: 46,
|
||||
Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}
|
||||
end3 := r3.b.BuildStep(t.Context(), same)
|
||||
r3.b.Wait()
|
||||
if end3.Outcome != meshbuilds.StepEndedOutcomePassed || !slices.Equal(read3, []string{"main 48"}) || len(res3.sources) != 1 || res3.sources[0].CatalogRevision != 48 {
|
||||
t.Errorf("end = %+v, kept revisions read %v, reserved %+v; want passed, revision 48 of main read once and reserved at it", end3, read3, res3.sources)
|
||||
}
|
||||
// H-A-218, H-A-222: a kept revision of another source than the ask names, or naming another fingerprint, is a mismatch:
|
||||
// the step fails at once naming it, never waiting out its bound (the bound here is long, the ask is not below the picture).
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
source int64
|
||||
fp string
|
||||
said string
|
||||
}{
|
||||
{"another source", 45, fp1, "the catalog's revision 48 is of source revision 45, the ask names 46"},
|
||||
{"another fingerprint", 46, "src2:other", "names m at \"src2:other\""},
|
||||
} {
|
||||
rc, resc, _ := revisionRig(t, &held, make(chan struct{}, 1))
|
||||
rc.b.RevisionWait = time.Hour
|
||||
rc.b.KeptRevision = func(context.Context, string, int64) (int64, map[string]string, error) {
|
||||
return c.source, map[string]string{"m": c.fp}, nil
|
||||
}
|
||||
end := rc.b.BuildStep(t.Context(), same)
|
||||
rc.b.Wait()
|
||||
if end.Outcome != meshbuilds.StepEndedOutcomeFailed || !strings.Contains(end.Said, c.said) || len(resc.sources) != 0 {
|
||||
t.Errorf("%s: end = %+v, reserved %+v; want failed at once saying %q, nothing reserved", c.name, end, resc.sources, c.said)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
package versions
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// **The reservations' index by digest and by version** (design 47 H H-A-269 (1), H-A-271): beside the reservations, in the same
|
||||
// state, the builder keeps which reservation keys hold a built digest and which stand at a version, so a registry seat's published
|
||||
// finds its reservation in one read and a published whose digest no reservation holds is judged from its version's keys in one
|
||||
// more, never a scan of every reservation. The index keys have three tokens, so the reservations' filter (two tokens) never lists
|
||||
// them. It is maintained at reserve, at a digest recorded, at release and at drop; an entry left behind by a write that ended
|
||||
// halfway is harmless (every read checks the reservation it names), and a missing one is written again by Reindex at the start.
|
||||
|
||||
const (
|
||||
indexDigestPrefix = "index.digest."
|
||||
indexVersionPrefix = "index.version."
|
||||
// IndexDigestFilter and IndexVersionFilter are the filters of the index's two halves.
|
||||
IndexDigestFilter = indexDigestPrefix + "*"
|
||||
IndexVersionFilter = indexVersionPrefix + "*"
|
||||
)
|
||||
|
||||
// IndexDigestKey is the index key of the reservations holding digest as a built artifact's.
|
||||
func IndexDigestKey(digest string) string { return indexDigestPrefix + EscapeToken(digest) }
|
||||
|
||||
// IndexVersionKey is the index key of the reservations standing at version (MAJOR.MINOR.PATCH).
|
||||
func IndexVersionKey(version string) string { return indexVersionPrefix + EscapeToken(version) }
|
||||
|
||||
// IndexEntry is an index key's value: the reservation keys, sorted.
|
||||
type IndexEntry struct {
|
||||
Keys []string `json:"keys"`
|
||||
}
|
||||
|
||||
// indexed reads an index key's reservation keys.
|
||||
func (r *Reserver) indexed(ctx context.Context, key string) ([]string, error) {
|
||||
raw, _, found, err := r.Store.Get(ctx, key)
|
||||
if err != nil || !found {
|
||||
return nil, err
|
||||
}
|
||||
var e IndexEntry
|
||||
if err := json.Unmarshal(raw, &e); err != nil {
|
||||
return nil, fmt.Errorf("%s holds what is no index entry: %w", key, err)
|
||||
}
|
||||
return e.Keys, nil
|
||||
}
|
||||
|
||||
// index adds (or, with add false, removes) reserved under the index key key, by compare-and-set; an entry left empty is deleted.
|
||||
func (r *Reserver) index(ctx context.Context, key, reserved string, add bool) error {
|
||||
for {
|
||||
raw, rev, found, err := r.Store.Get(ctx, key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var e IndexEntry
|
||||
if found {
|
||||
_ = json.Unmarshal(raw, &e)
|
||||
}
|
||||
has := slices.Contains(e.Keys, reserved)
|
||||
if has == add {
|
||||
return nil
|
||||
}
|
||||
if add {
|
||||
e.Keys = append(e.Keys, reserved)
|
||||
sort.Strings(e.Keys)
|
||||
} else {
|
||||
e.Keys = slices.DeleteFunc(e.Keys, func(k string) bool { return k == reserved })
|
||||
}
|
||||
if len(e.Keys) == 0 {
|
||||
return r.Store.Delete(ctx, key)
|
||||
}
|
||||
out, _ := json.Marshal(e)
|
||||
if found {
|
||||
_, err = r.Store.Update(ctx, key, out, rev)
|
||||
} else {
|
||||
_, err = r.Store.Create(ctx, key, out)
|
||||
}
|
||||
if errors.Is(err, ErrConflict) {
|
||||
continue
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// indexKeys are the index keys a reservation stands under: its version's and each built digest's.
|
||||
func indexKeys(v ReservedVersion) []string {
|
||||
out := []string{}
|
||||
if v.Version != "" {
|
||||
out = append(out, IndexVersionKey(v.Version))
|
||||
}
|
||||
for _, d := range v.Artifacts {
|
||||
if d != "" && !slices.Contains(out, IndexDigestKey(d)) {
|
||||
out = append(out, IndexDigestKey(d))
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// reindex moves reservation key from the index keys of was (its value before, zero when there was none) to those of now (zero when
|
||||
// it is gone).
|
||||
func (r *Reserver) reindex(ctx context.Context, key string, was, now ReservedVersion) error {
|
||||
add, drop := indexKeys(now), indexKeys(was)
|
||||
var errs []error
|
||||
for _, k := range add {
|
||||
if err := r.index(ctx, k, key, true); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
for _, k := range drop {
|
||||
if !slices.Contains(add, k) {
|
||||
if err := r.index(ctx, k, key, false); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := errors.Join(errs...); err != nil {
|
||||
return fmt.Errorf("the index of %s is not written (Reindex writes it at the start): %w", key, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AtVersion are the reservations standing at version, read through the index by version (H-A-271): one read of the index and
|
||||
// one of each reservation it names.
|
||||
func (r *Reserver) AtVersion(ctx context.Context, version string) ([]ReservedVersion, error) {
|
||||
keys, err := r.indexed(ctx, IndexVersionKey(version))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var out []ReservedVersion
|
||||
for _, k := range keys {
|
||||
cur, _, found, err := r.get(ctx, k)
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
if found && cur.Version == version {
|
||||
out = append(out, cur)
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Reindex writes the index again from the reservations, once at the builder's start (H-A-269 (1), H-A-271): each reservation is
|
||||
// added under its keys, and a reservation an index key names that does not stand under it (read again) is removed from it. Both
|
||||
// are the same compare-and-set as every other index write, so a reservation written meanwhile keeps its entries. It answers how
|
||||
// many reservations it read.
|
||||
func (r *Reserver) Reindex(ctx context.Context) (int, error) {
|
||||
all, err := r.All(ctx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
var errs []error
|
||||
for _, v := range all {
|
||||
key := ReservedKey(v.Module, v.Series)
|
||||
for _, k := range indexKeys(v) {
|
||||
if err := r.index(ctx, k, key, true); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, filter := range []string{IndexDigestFilter, IndexVersionFilter} {
|
||||
keys, err := r.Store.KeysOf(ctx, filter)
|
||||
if err != nil {
|
||||
return len(all), fmt.Errorf("the index cannot be listed: %w", err)
|
||||
}
|
||||
for _, k := range keys {
|
||||
named, err := r.indexed(ctx, k)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
continue
|
||||
}
|
||||
for _, rk := range named {
|
||||
cur, _, found, err := r.get(ctx, rk)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
continue
|
||||
}
|
||||
if found && slices.Contains(indexKeys(cur), k) {
|
||||
continue
|
||||
}
|
||||
if err := r.index(ctx, k, rk, false); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return len(all), errors.Join(errs...)
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package versions
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// countingReserve counts the listings of the reservations and the reads of a reservation key (two tokens), so a test sees that
|
||||
// a published reads its reservation and no other.
|
||||
type countingReserve struct {
|
||||
*reserveMem
|
||||
lists, reads atomic.Int64
|
||||
}
|
||||
|
||||
func (c *countingReserve) KeysOf(ctx context.Context, filter string) ([]string, error) {
|
||||
c.lists.Add(1)
|
||||
return c.reserveMem.KeysOf(ctx, filter)
|
||||
}
|
||||
|
||||
func (c *countingReserve) Get(ctx context.Context, key string) ([]byte, uint64, bool, error) {
|
||||
if !strings.HasPrefix(key, "index.") {
|
||||
c.reads.Add(1)
|
||||
}
|
||||
return c.reserveMem.Get(ctx, key)
|
||||
}
|
||||
|
||||
// TestTheIndexFindsAPublishedReservationInOneRead: design 47 H H-A-269 (1), H-A-271 — a registry seat's published finds its
|
||||
// reservation through the index by digest, reading that reservation alone and listing none; a published whose digest no
|
||||
// reservation holds is judged from its version's keys (kept on a build that recorded no digest yet, A-415), never a scan; the
|
||||
// index goes with a release and a drop, and is written again at the start from reservations written before it existed.
|
||||
func TestTheIndexFindsAPublishedReservationInOneRead(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
fill := func(t *testing.T) (*Reserver, *countingReserve) {
|
||||
store := &countingReserve{reserveMem: &reserveMem{mem: newMem()}}
|
||||
r := &Reserver{Store: store, ReleasedOf: func(context.Context, string) ([]string, error) { return nil, nil }}
|
||||
for i := range 40 {
|
||||
m := fmt.Sprintf("m%02d", i)
|
||||
if _, err := r.Reserve(ctx, m, "0.1", []string{m + ":a"}, Source{Fingerprint: "fp" + m}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if i%2 == 0 { // half are built, each with its own digest
|
||||
if _, err := r.Built(ctx, m, "0.1.0", m+":a", "sha256:"+m, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
store.lists.Store(0)
|
||||
store.reads.Store(0)
|
||||
return r, store
|
||||
}
|
||||
t.Run("a published by digest reads its one reservation", func(t *testing.T) {
|
||||
r, store := fill(t)
|
||||
marked, _, err := r.Published(ctx, "m10-a", "v0.1.0", "sha256:m10")
|
||||
if err != nil || len(marked) != 1 || marked[0].Reserved.Module != "m10" || marked[0].Artifact != "m10:a" {
|
||||
t.Fatalf("the published marked %+v (%v), want m10:a", marked, err)
|
||||
}
|
||||
if l, n := store.lists.Load(), store.reads.Load(); l != 0 || n != 1 {
|
||||
t.Errorf("the published listed %d times and read %d reservations, want none listed and one read", l, n)
|
||||
}
|
||||
})
|
||||
t.Run("a digest no reservation holds is judged from its version's keys", func(t *testing.T) {
|
||||
r, store := fill(t)
|
||||
marked, kept, err := r.Published(ctx, "m11-a", "0.1.0", "sha256:early")
|
||||
if err != nil || len(marked) != 0 {
|
||||
t.Fatalf("an unbuilt digest marked %v (%v)", marked, err)
|
||||
}
|
||||
// The 20 unbuilt reservations at 0.1.0 keep it as heard (A-415); the built ones are read and left.
|
||||
if len(kept) != 20 || store.lists.Load() != 0 || store.reads.Load() != 40 {
|
||||
t.Errorf("kept on %d (want 20), listed %d (want 0), read %d (want the 40 at 0.1.0)", len(kept), store.lists.Load(), store.reads.Load())
|
||||
}
|
||||
at, err := r.AtVersion(ctx, "0.9.9")
|
||||
if err != nil || len(at) != 0 || store.lists.Load() != 0 {
|
||||
t.Errorf("a version no reservation stands at answered %v (%v), listed %d", at, err, store.lists.Load())
|
||||
}
|
||||
})
|
||||
t.Run("a release and a drop take the reservation out of the index", func(t *testing.T) {
|
||||
r, store := fill(t)
|
||||
if _, err := r.Released(ctx, "m10", "0.1.0"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := r.Drop(ctx, "m12", "0.1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, k := range []string{IndexDigestKey("sha256:m10"), IndexDigestKey("sha256:m12")} {
|
||||
if _, _, found, _ := store.Get(ctx, k); found {
|
||||
t.Errorf("%s stands after its reservation went", k)
|
||||
}
|
||||
}
|
||||
keys, _ := r.indexed(ctx, IndexVersionKey("0.1.0"))
|
||||
for _, k := range keys {
|
||||
if k == ReservedKey("m10", "0.1") || k == ReservedKey("m12", "0.1") {
|
||||
t.Errorf("the version's index still names %s", k)
|
||||
}
|
||||
}
|
||||
})
|
||||
t.Run("the index is written again at the start from the reservations", func(t *testing.T) {
|
||||
store := &countingReserve{reserveMem: &reserveMem{mem: newMem()}}
|
||||
r := &Reserver{Store: store}
|
||||
// A reservation written before the index existed, and an index entry naming a reservation that is gone.
|
||||
raw, _ := json.Marshal(ReservedVersion{V: 1, Module: "old", Series: "0.2", Version: "0.2.4", Artifacts: map[string]string{"old:a": "sha256:old"}})
|
||||
if _, err := store.Create(ctx, ReservedKey("old", "0.2"), raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
stale, _ := json.Marshal(IndexEntry{Keys: []string{ReservedKey("gone", "0.1")}})
|
||||
if _, err := store.Create(ctx, IndexDigestKey("sha256:gone"), stale); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n, err := r.Reindex(ctx); err != nil || n != 1 {
|
||||
t.Fatalf("the reindex read %d reservations (%v), want 1", n, err)
|
||||
}
|
||||
if _, _, found, _ := store.Get(ctx, IndexDigestKey("sha256:gone")); found {
|
||||
t.Error("the index entry of a reservation that is gone stands after the reindex")
|
||||
}
|
||||
if keys, _ := store.KeysOf(ctx, AllFilter); len(keys) != 1 {
|
||||
t.Errorf("the reservations list %v: the index keys are listed among them", keys)
|
||||
}
|
||||
store.lists.Store(0)
|
||||
store.reads.Store(0)
|
||||
marked, _, err := r.Published(ctx, "old-a", "0.2.4", "sha256:old")
|
||||
if err != nil || len(marked) != 1 || store.lists.Load() != 0 || store.reads.Load() != 1 {
|
||||
t.Errorf("after the reindex the published marked %v (%v), listed %d, read %d", marked, err, store.lists.Load(), store.reads.Load())
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -33,8 +34,10 @@ const (
|
||||
QueueFull = "queue full"
|
||||
// NotStoredWords opens what a refused artifact is said as.
|
||||
NotStoredWords = "not stored: "
|
||||
// VerbPublish is the registry seats' verb a publish again sends.
|
||||
VerbPublish = "publish"
|
||||
// VerbPublish is the registry seats' verb a publish again sends, VerbVersions the one whose record says what a seat holds
|
||||
// (H-A-272).
|
||||
VerbPublish = "publish"
|
||||
VerbVersions = "versions"
|
||||
)
|
||||
|
||||
// RepublishTransfer is a publish again's transfer name, the builder's own (the registry part's publish: the caller names its
|
||||
@@ -77,6 +80,9 @@ type QueuedPublish struct {
|
||||
Begun bool `json:"begun,omitempty"`
|
||||
}
|
||||
|
||||
// QueueFilter is the filter of every queued version: a queue key has three tokens, which AllFilter (two) never lists on the bus.
|
||||
const QueueFilter = "*.*.*"
|
||||
|
||||
// QueueKey is the key of holder's queued version of module.
|
||||
func QueueKey(holder, module, version string) string {
|
||||
return EscapeToken(holder) + "." + EscapeToken(module) + "." + EscapeToken(version)
|
||||
@@ -402,7 +408,7 @@ const PublishAgainDescription = "Publish reserved versions again (design 47 G se
|
||||
|
||||
// Resume takes up, at the builder's start, every queued version again, a begun one sent anew (§588).
|
||||
func (r *Republisher) Resume(ctx context.Context) error {
|
||||
keys, err := r.Queue.KeysOf(ctx, AllFilter)
|
||||
keys, err := r.Queue.KeysOf(ctx, QueueFilter)
|
||||
if err != nil {
|
||||
return fmt.Errorf("the state %s cannot be listed: %w", PublishQueueState, err)
|
||||
}
|
||||
@@ -501,25 +507,11 @@ func (r *Republisher) send(ctx context.Context, q QueuedPublish) {
|
||||
}
|
||||
sort.Strings(refs)
|
||||
for _, ref := range refs {
|
||||
var art *meshcatalog.Artifact
|
||||
for i := range e.Artifacts {
|
||||
if e.Artifacts[i].Ref == ref {
|
||||
art = &e.Artifacts[i]
|
||||
}
|
||||
}
|
||||
seat, ok := "", false
|
||||
if art != nil {
|
||||
seat, ok = SeatOfArtifact(*art)
|
||||
}
|
||||
seat, name, kind, ok := publishTarget(e, q.Module, ref)
|
||||
if !ok {
|
||||
r.say(ctx, v, ref+": the catalog entry names no registry seat for it")
|
||||
return
|
||||
}
|
||||
name := NameOf(q.Module, strings.TrimPrefix(ref, q.Module+":"))
|
||||
if art.Package != nil && art.Package.Name != "" {
|
||||
name = art.Package.Name
|
||||
}
|
||||
kind := art.Kind
|
||||
bound, cancel := context.WithTimeout(ctx, UnreleasedBound) // a context's bound, no timer (ADR 0437 §8)
|
||||
err := r.Send(bound, Publish{Seat: seat, Kind: kind, Name: name, Version: v.Version, Digest: q.Artifacts[ref], Fingerprint: v.Fingerprint,
|
||||
Commit: v.Commit, Transfer: RepublishTransfer(q.Module, v.Version, strings.TrimPrefix(ref, q.Module+":"))})
|
||||
@@ -543,6 +535,28 @@ func (r *Republisher) send(ctx context.Context, q QueuedPublish) {
|
||||
}
|
||||
}
|
||||
|
||||
// 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) {
|
||||
var art *meshcatalog.Artifact
|
||||
for i := range e.Artifacts {
|
||||
if e.Artifacts[i].Ref == ref {
|
||||
art = &e.Artifacts[i]
|
||||
}
|
||||
}
|
||||
if art == nil {
|
||||
return "", "", "", false
|
||||
}
|
||||
if seat, ok = SeatOfArtifact(*art); !ok {
|
||||
return "", "", "", false
|
||||
}
|
||||
name = NameOf(module, strings.TrimPrefix(ref, module+":"))
|
||||
if art.Package != nil && art.Package.Name != "" {
|
||||
name = art.Package.Name
|
||||
}
|
||||
return seat, name, art.Kind, true
|
||||
}
|
||||
|
||||
func (r *Republisher) say(ctx context.Context, v ReservedVersion, why string) {
|
||||
r.logf("%s %s is not published again: %s", v.Module, v.Version, why)
|
||||
if r.Unreleased != nil {
|
||||
@@ -579,3 +593,105 @@ func (r *Reserver) MarkUnstored(ctx context.Context, module, version, artifact,
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// UnheardBound is how many messages the builder's durable on the events stream may hold pending and unacknowledged while a
|
||||
// publish is asked again (design 47 H H-A-269 (2), H-A-272): at or above it a published of the version may still be unheard, so
|
||||
// the try is skipped. A constant of the builder, no setting.
|
||||
const UnheardBound = 100
|
||||
|
||||
// HeldVersion is one version a registry seat's verb versions answers of a name, with its digest.
|
||||
type HeldVersion struct {
|
||||
Version, Digest 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
|
||||
}
|
||||
|
||||
// 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.
|
||||
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.
|
||||
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 {
|
||||
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)
|
||||
}
|
||||
var out Judged
|
||||
for _, ref := range missing {
|
||||
seat, name, _, ok := publishTarget(e, v.Module, ref)
|
||||
if !ok {
|
||||
if out.Lacks == "" {
|
||||
out.Lacks = ref + ": the catalog entry names no registry seat for it"
|
||||
}
|
||||
continue
|
||||
}
|
||||
held, err := versionsOf(ctx, seat, name)
|
||||
if err != nil {
|
||||
return Judged{}, fmt.Errorf("%s's versions of %s cannot be read: %w", seat, name, err)
|
||||
}
|
||||
at, found := HeldArtifact{}, 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] {
|
||||
break
|
||||
}
|
||||
}
|
||||
switch {
|
||||
case !found:
|
||||
if out.Lacks == "" {
|
||||
out.Lacks = fmt.Sprintf("%s holds no %s %s", seat, name, v.Version)
|
||||
}
|
||||
case at.Digest == v.Artifacts[ref]:
|
||||
out.Held = append(out.Held, at)
|
||||
default:
|
||||
out.Elsewhere = append(out.Elsewhere, at)
|
||||
}
|
||||
}
|
||||
out.All = len(out.Held) == len(missing)
|
||||
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) {
|
||||
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
|
||||
for _, ref := range refs {
|
||||
seat, name, _, ok := publishTarget(e, module, ref)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
held, err := versionsOf(ctx, seat, name)
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
@@ -196,3 +196,42 @@ func TestRepublish(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestTheRegistriesRecordSaysWhetherAVersionIsHeld: design 47 H H-A-272, H-A-274, H-A-275 — a missing artifact its registry seat
|
||||
// holds at the version (the Go form too) with the built digest is held; at the version with another digest it is held elsewhere;
|
||||
// a version the seat lacks is said by name. The numbers a registry holds of the module's artifacts are what reserving skips.
|
||||
func TestTheRegistriesRecordSaysWhetherAVersionIsHeld(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
entry := meshcatalog.CatalogEntry{Artifacts: []meshcatalog.Artifact{{Ref: "m:lib", Kind: "package", Language: "go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "git.example/m"}}}}
|
||||
r := &Republisher{Entry: func(context.Context, string) (meshcatalog.CatalogEntry, error) { return entry, nil }}
|
||||
v := ReservedVersion{Module: "m", Version: "0.1.37", Fingerprint: "fp", Artifacts: map[string]string{"m:lib": "sha256:a"}}
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
holds []HeldVersion
|
||||
all, elsewhere, lacks bool
|
||||
}{
|
||||
{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},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
var seat, name string
|
||||
versionsOf := func(_ context.Context, s, n string) ([]HeldVersion, error) { seat, name = s, n; return c.holds, nil }
|
||||
j, err := r.Held(ctx, v, versionsOf)
|
||||
if err != nil || j.All != c.all || (len(j.Elsewhere) == 1) != c.elsewhere || (j.Lacks != "") != c.lacks || seat != SeatGoPackages || name != "git.example/m" {
|
||||
t.Fatalf("judged %+v (%v) asking %s for %s, want all %v, elsewhere %v, lacks %v asking %s for git.example/m", j, err, seat, name, c.all, c.elsewhere, c.lacks, SeatGoPackages)
|
||||
}
|
||||
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)
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
v.Published = map[string]bool{"m:lib": true}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -35,6 +37,9 @@ const (
|
||||
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
|
||||
// H H-A-275), scope module.
|
||||
VersionHeldElsewhere = "version-held-elsewhere"
|
||||
)
|
||||
|
||||
// ReservedVersion is the value of a reservation key.
|
||||
@@ -65,12 +70,18 @@ type ReservedVersion struct {
|
||||
// (design 47 G §371, A-57): what `package-published` says of the publication.
|
||||
Branch string `json:"branch,omitempty"`
|
||||
Source int64 `json:"source,omitempty"`
|
||||
// Revision is the catalog revision number the build's step ask named, the indexer's count (design 47 H H-A-218): what
|
||||
// `package-published` names beside the source, so the runner finds the publishing pipeline; 0 when no step ask named one.
|
||||
Revision int64 `json:"revision,omitempty"`
|
||||
// Dependencies are, by artifact reference, what the step's result says each artifact resolved (kind 1) and was built with
|
||||
// (kind 3), kept for `package-published` (design 47 G §466, §673, A-57).
|
||||
Dependencies map[string][]meshbuilds.Dependency `json:"dependencies,omitempty"`
|
||||
// Kept are the registry seats' published heard while the build had not yet recorded every digest and whose digest marked
|
||||
// no artifact then: kept as heard, they mark their artifact when the build records its digests (design 47 G A-415).
|
||||
Kept []KeptPublished `json:"kept-published,omitempty"`
|
||||
// Withdrawn are the versions of the series a take-over by another fingerprint withdrew, each with the fingerprint whose
|
||||
// build it was (design 47 H H-A-225): a late publish of one is refused as withdrawn. Kept while the series' key stands.
|
||||
Withdrawn map[string]string `json:"withdrawn,omitempty"`
|
||||
}
|
||||
|
||||
// KeptPublished is a registry seat's published kept on a reservation, as heard (design 47 G A-415).
|
||||
@@ -91,6 +102,8 @@ type Source struct {
|
||||
// that catalog revision (design 47 G §371, A-57), kept on the reservation for the publication.
|
||||
Branch string
|
||||
Revision int64
|
||||
// CatalogRevision is the catalog revision number the build's step ask named (H-A-218), 0 when none did.
|
||||
CatalogRevision int64
|
||||
// Rebuild marks a build again of a done key whose version is not released: the standing reservation of Fingerprint is replaced
|
||||
// and is no floor, so the number is the next above the catalog's highest alone (design 47 G A-490b).
|
||||
Rebuild bool
|
||||
@@ -125,6 +138,50 @@ type Reserver struct {
|
||||
// DefaultReleasedKept.
|
||||
ReleasedKept int
|
||||
Now func() time.Time
|
||||
// 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)
|
||||
// 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)
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
vs, err := r.HeldNumbers(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 {
|
||||
out[p] = true
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// nextFree is the first patch after after that no registry holds, and the held numbers it skipped (H-A-275).
|
||||
func nextFree(series string, after int, held map[int]bool) (int, []string) {
|
||||
var skipped []string
|
||||
p := after + 1
|
||||
for held[p] {
|
||||
skipped = append(skipped, fmt.Sprintf("%s.%d", series, p))
|
||||
p++
|
||||
}
|
||||
return p, skipped
|
||||
}
|
||||
|
||||
// said is told the outcome of a reindex: a failure is said, the reservation's own write stands.
|
||||
func (r *Reserver) said(err error) {
|
||||
if err != nil && r.Logf != nil {
|
||||
r.Logf("%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Reserver) now() time.Time {
|
||||
@@ -149,7 +206,10 @@ func SplitVersion(version string) (series string, patch int, err error) {
|
||||
|
||||
// Reserve reserves the next version of module's series for a build that starts, for artifacts (their names), and answers
|
||||
// it. The next patch is the one after the higher of the highest released and the one reserved, 0 when there is neither. A
|
||||
// conflicting write (another build reserved first) is read again and the next taken.
|
||||
// conflicting write (another build reserved first) is read again and the next taken. A reservation standing for the same
|
||||
// fingerprint whose version is not released and is above the catalog's highest is kept and answered as it stands, a build again or a re-run after a restart
|
||||
// alike (design 47 H H-A-225, which amends G A-490b): the run already building carries that number. A reservation another
|
||||
// fingerprint takes over is withdrawn: its version is kept in Withdrawn, and Took is told so the older build is ended.
|
||||
func (r *Reserver) Reserve(ctx context.Context, module, series string, artifacts []string, src Source) (ReservedVersion, error) {
|
||||
if r.Filled != nil && !r.Filled() {
|
||||
return ReservedVersion{}, ErrNotFilled
|
||||
@@ -165,25 +225,50 @@ func (r *Reserver) Reserve(ctx context.Context, module, series string, artifacts
|
||||
}
|
||||
}
|
||||
key := ReservedKey(module, series)
|
||||
held := 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)
|
||||
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
|
||||
}
|
||||
}
|
||||
next := high
|
||||
if found && !(src.Rebuild && cur.Fingerprint == src.Fingerprint) {
|
||||
if found && (withdrawn || !(src.Rebuild && cur.Fingerprint == src.Fingerprint)) { // a withdrawn number is never taken again (H-A-226)
|
||||
if _, p, err := SplitVersion(cur.Version); err == nil && p > next {
|
||||
next = p
|
||||
}
|
||||
}
|
||||
out := ReservedVersion{V: 1, Module: module, Series: series, Version: fmt.Sprintf("%s.%d", series, next+1), Artifacts: map[string]string{}, At: r.now(),
|
||||
Repository: src.Repository, Commit: src.Commit, Fingerprint: src.Fingerprint, Branch: src.Branch, Source: src.Revision}
|
||||
patch, skipped := nextFree(series, next, held)
|
||||
out := ReservedVersion{V: 1, Module: module, Series: series, Version: fmt.Sprintf("%s.%d", series, patch), Artifacts: map[string]string{}, At: r.now(),
|
||||
Repository: src.Repository, Commit: src.Commit, Fingerprint: src.Fingerprint, Branch: src.Branch, Source: src.Revision, Revision: src.CatalogRevision}
|
||||
if src.GoPackage {
|
||||
out.Tag = GoTagOf(out.Version)
|
||||
}
|
||||
for _, a := range artifacts {
|
||||
out.Artifacts[a] = ""
|
||||
}
|
||||
if found {
|
||||
out.Withdrawn = maps.Clone(cur.Withdrawn)
|
||||
if cur.Fingerprint != src.Fingerprint {
|
||||
if out.Withdrawn == nil {
|
||||
out.Withdrawn = map[string]string{}
|
||||
}
|
||||
out.Withdrawn[cur.Version] = cur.Fingerprint // a dropped number stays a gap (H-A-226)
|
||||
}
|
||||
// One at or below the catalog's highest released is refused by the plain rule anyway: the map never grows without end.
|
||||
maps.DeleteFunc(out.Withdrawn, func(v, _ string) bool {
|
||||
_, p, err := SplitVersion(v)
|
||||
return err != nil || p <= high
|
||||
})
|
||||
if len(out.Withdrawn) == 0 {
|
||||
out.Withdrawn = nil
|
||||
}
|
||||
}
|
||||
raw, _ := json.Marshal(out)
|
||||
if found {
|
||||
_, err = r.Store.Update(ctx, key, raw, rev)
|
||||
@@ -196,6 +281,10 @@ func (r *Reserver) Reserve(ctx context.Context, module, series string, artifacts
|
||||
if err != nil {
|
||||
return ReservedVersion{}, fmt.Errorf("%s cannot be reserved: %w", key, err)
|
||||
}
|
||||
r.said(r.reindex(ctx, key, cur, out)) // cur is zero when there was none
|
||||
if len(skipped) > 0 && r.HeldElsewhere != nil {
|
||||
r.HeldElsewhere(ctx, module, skipped)
|
||||
}
|
||||
if found && r.Took != nil {
|
||||
r.Took(ctx, cur, out)
|
||||
}
|
||||
@@ -215,6 +304,38 @@ func (r *Reserver) get(ctx context.Context, key string) (ReservedVersion, uint64
|
||||
return v, rev, true, nil
|
||||
}
|
||||
|
||||
// Withdraw withdraws module's reservation of version for the build of its fingerprint, whose number a registry holds at another
|
||||
// digest (design 47 H H-A-275, H-A-279): the number is kept in Withdrawn and stays a gap (H-A-226), so the build again of that
|
||||
// fingerprint reserves the next number no registry holds, with fresh digests. It answers the reservation as withdrawn, and false
|
||||
// when none stands at version.
|
||||
func (r *Reserver) Withdraw(ctx context.Context, module, version string) (ReservedVersion, bool, error) {
|
||||
series, _, err := SplitVersion(version)
|
||||
if err != nil {
|
||||
return ReservedVersion{}, false, err
|
||||
}
|
||||
key := ReservedKey(module, series)
|
||||
for {
|
||||
cur, rev, found, err := r.get(ctx, key)
|
||||
if err != nil || !found || cur.Version != version {
|
||||
return cur, false, err
|
||||
}
|
||||
if hasKey(cur.Withdrawn, version) {
|
||||
return cur, true, nil
|
||||
}
|
||||
if cur.Withdrawn == nil {
|
||||
cur.Withdrawn = map[string]string{}
|
||||
}
|
||||
cur.Withdrawn[version] = cur.Fingerprint
|
||||
raw, _ := json.Marshal(cur)
|
||||
if _, err := r.Store.Update(ctx, key, raw, rev); errors.Is(err, ErrConflict) {
|
||||
continue
|
||||
} else if err != nil {
|
||||
return cur, false, fmt.Errorf("%s cannot be withdrawn: %w", key, err)
|
||||
}
|
||||
return cur, true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Built records artifact's digest under the reserved version of module's series; once every artifact has one the build is
|
||||
// ended (BuiltAt). A reservation moved on to another version (a newer build took the next) is left alone and answers false.
|
||||
func (r *Reserver) Built(ctx context.Context, module, version, artifact, digest string, deps []meshbuilds.Dependency) (bool, error) {
|
||||
@@ -228,6 +349,8 @@ func (r *Reserver) Built(ctx context.Context, module, version, artifact, digest
|
||||
if err != nil || !found || cur.Version != version {
|
||||
return false, err
|
||||
}
|
||||
was := cur
|
||||
was.Artifacts = maps.Clone(cur.Artifacts)
|
||||
cur.Artifacts[artifact] = digest
|
||||
if len(deps) > 0 {
|
||||
if cur.Dependencies == nil {
|
||||
@@ -244,6 +367,7 @@ func (r *Reserver) Built(ctx context.Context, module, version, artifact, digest
|
||||
} else if err != nil {
|
||||
return false, fmt.Errorf("%s cannot be written: %w", key, err)
|
||||
}
|
||||
r.said(r.reindex(ctx, key, was, cur))
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
@@ -362,6 +486,7 @@ func (r *Reserver) Released(ctx context.Context, module, version string) ([]stri
|
||||
if err := r.Store.Delete(ctx, k); err != nil {
|
||||
return gone, fmt.Errorf("%s cannot be deleted: %w", k, err)
|
||||
}
|
||||
r.said(r.reindex(ctx, k, cur, ReservedVersion{}))
|
||||
gone = append(gone, k)
|
||||
}
|
||||
sort.Strings(gone)
|
||||
@@ -425,15 +550,39 @@ func (r *Reserver) All(ctx context.Context) ([]ReservedVersion, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// TakenOver is the reservation of module's series whose withdrawn numbers hold one of the build of fingerprint (design 47 H
|
||||
// H-A-226), and whether there is one: the series moved to that reservation's fingerprint and version (H-A-244).
|
||||
func (r *Reserver) TakenOver(ctx context.Context, module, fingerprint string) (ReservedVersion, bool, error) {
|
||||
all, err := r.All(ctx)
|
||||
if err != nil {
|
||||
return ReservedVersion{}, false, err
|
||||
}
|
||||
for _, v := range all {
|
||||
if v.Module != module || v.Fingerprint == fingerprint {
|
||||
continue
|
||||
}
|
||||
for _, fp := range v.Withdrawn {
|
||||
if fp == fingerprint {
|
||||
return v, true, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return ReservedVersion{}, false, nil
|
||||
}
|
||||
|
||||
// Drop deletes module's reservation of series on a person's word (builder_reserved_drop); the caller writes the hand-act
|
||||
// log. It answers whether there was one.
|
||||
func (r *Reserver) Drop(ctx context.Context, module, series string) (bool, error) {
|
||||
key := ReservedKey(module, series)
|
||||
_, _, found, err := r.get(ctx, key)
|
||||
cur, _, found, err := r.get(ctx, key)
|
||||
if err != nil || !found {
|
||||
return false, err
|
||||
}
|
||||
return true, r.Store.Delete(ctx, key)
|
||||
if err := r.Store.Delete(ctx, key); err != nil {
|
||||
return true, err
|
||||
}
|
||||
r.said(r.reindex(ctx, key, cur, ReservedVersion{}))
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// Marked is an artifact of a reservation a registry seat's published newly marked: the reservation as it stands then.
|
||||
@@ -443,11 +592,12 @@ type Marked struct {
|
||||
}
|
||||
|
||||
// PackagePublished is the seat mesh-builds' package-published of one artifact the holder said published at the reservation's
|
||||
// version (design 47 G §52, §334, §673, A-57): the artifact reference, the version and the digest published, the watched branch and
|
||||
// the source revision the build was made from, and the dependencies its step result named.
|
||||
// version (design 47 G §52, §334, §673, A-57): the artifact reference, the version and the digest published, the watched branch,
|
||||
// the source revision the build was made from and the catalog revision its step ask named (H-A-218), and the dependencies its
|
||||
// step result named.
|
||||
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, Module: m.Reserved.Module,
|
||||
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]}
|
||||
}
|
||||
|
||||
@@ -455,29 +605,47 @@ func (m Marked) PackagePublished(digest string, at time.Time) meshbuilds.Package
|
||||
// whose built digest it names are marked published. It answers each artifact it newly marked, with the reservation as marked.
|
||||
// A published that marks no artifact of a reservation at version whose build has not recorded every digest is kept on that
|
||||
// reservation as heard (name, version, digest), and the keys it is kept on are answered too (design 47 G A-415): Kept marks
|
||||
// it when the build records its digests.
|
||||
// it when the build records its digests. The reservation is found through the index (H-A-269 (1), H-A-271): the reservations
|
||||
// holding the digest in one read, and only when none holds it at version, those standing at the version in one more; never a
|
||||
// scan of every reservation.
|
||||
func (r *Reserver) Published(ctx context.Context, name, version, digest string) ([]Marked, []string, error) {
|
||||
version = strings.TrimPrefix(version, "v")
|
||||
if version == "" || digest == "" {
|
||||
return nil, nil, nil
|
||||
}
|
||||
keys, err := r.Store.KeysOf(ctx, AllFilter)
|
||||
keys, err := r.indexed(ctx, IndexDigestKey(digest))
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("the reservations cannot be listed: %w", err)
|
||||
return nil, nil, fmt.Errorf("the index of digest %s cannot be read: %w", digest, err)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
marked, kept, matched, err := r.publishedOn(ctx, keys, name, version, digest, false)
|
||||
if err != nil || matched {
|
||||
return marked, kept, err
|
||||
}
|
||||
keys, err = r.indexed(ctx, IndexVersionKey(version))
|
||||
if err != nil {
|
||||
return marked, kept, fmt.Errorf("the index of version %s cannot be read: %w", version, err)
|
||||
}
|
||||
m, k, _, err := r.publishedOn(ctx, keys, name, version, digest, true)
|
||||
return append(marked, m...), append(kept, k...), err
|
||||
}
|
||||
|
||||
// publishedOn takes a published in on the reservations under keys: an artifact whose built digest it names is marked; with keep,
|
||||
// a reservation at version whose build has not recorded every digest and that it matches nothing of keeps it (A-415). It also
|
||||
// answers whether a reservation at version holds the digest.
|
||||
func (r *Reserver) publishedOn(ctx context.Context, keys []string, name, version, digest string, keep bool) ([]Marked, []string, bool, error) {
|
||||
var marked []Marked
|
||||
var kept []string
|
||||
anyMatched := false
|
||||
for _, k := range keys {
|
||||
again:
|
||||
cur, rev, found, err := r.get(ctx, k)
|
||||
if err != nil {
|
||||
return marked, kept, err
|
||||
return marked, kept, anyMatched, err
|
||||
}
|
||||
if !found || cur.Version != version {
|
||||
continue
|
||||
}
|
||||
changed, matched, keep := false, false, false
|
||||
changed, matched, keepIt := false, false, false
|
||||
var arts []string
|
||||
for a, d := range cur.Artifacts {
|
||||
if d != digest {
|
||||
@@ -492,10 +660,11 @@ func (r *Reserver) Published(ctx context.Context, name, version, digest string)
|
||||
arts = append(arts, a)
|
||||
}
|
||||
}
|
||||
anyMatched = anyMatched || matched
|
||||
sort.Strings(arts)
|
||||
if !matched && cur.BuiltAt.IsZero() && !cur.keeps(name, digest) {
|
||||
if keep && !matched && cur.BuiltAt.IsZero() && !cur.keeps(name, digest) {
|
||||
cur.Kept = append(cur.Kept, KeptPublished{Name: name, Version: version, Digest: digest})
|
||||
changed, keep = true, true
|
||||
changed, keepIt = true, true
|
||||
}
|
||||
if !changed {
|
||||
continue
|
||||
@@ -504,16 +673,16 @@ func (r *Reserver) Published(ctx context.Context, name, version, digest string)
|
||||
if _, err := r.Store.Update(ctx, k, raw, rev); errors.Is(err, ErrConflict) {
|
||||
goto again
|
||||
} else if err != nil {
|
||||
return marked, kept, fmt.Errorf("%s cannot be written: %w", k, err)
|
||||
return marked, kept, anyMatched, fmt.Errorf("%s cannot be written: %w", k, err)
|
||||
}
|
||||
for _, a := range arts {
|
||||
marked = append(marked, Marked{Reserved: cur, Artifact: a})
|
||||
}
|
||||
if keep {
|
||||
if keepIt {
|
||||
kept = append(kept, k)
|
||||
}
|
||||
}
|
||||
return marked, kept, nil
|
||||
return marked, kept, anyMatched, nil
|
||||
}
|
||||
|
||||
func (v ReservedVersion) keeps(name, digest string) bool {
|
||||
@@ -705,11 +874,24 @@ func AnswerReservedByName(ctx context.Context, r Reader, carriers func(context.C
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
if series, _, err := SplitVersion(version); err == nil {
|
||||
if cur, _, found, err := rs.get(ctx, ReservedKey(module, series)); err == nil && found && hasKey(cur.Withdrawn, version) {
|
||||
// A late publish of a build a take-over withdrew (H-A-225): refused as what it is.
|
||||
return meshbuilds.ReservedAnswer{Error: fmt.Sprintf("%s (%s) version %s was withdrawn: the build of %s it was reserved for was taken over by %s, which reserves %s",
|
||||
name, module, version, cur.Withdrawn[version], cur.Fingerprint, cur.Version)}, nil
|
||||
}
|
||||
}
|
||||
return meshbuilds.ReservedAnswer{Error: fmt.Sprintf("%s (%s) has no version %s reserved or released", name, module, version)}, nil
|
||||
}
|
||||
return meshbuilds.ReservedAnswer{Error: fmt.Sprintf("%s (%s) has no reserved version", name, module)}, nil
|
||||
}
|
||||
|
||||
// hasKey says whether m holds k.
|
||||
func hasKey(m map[string]string, k string) bool {
|
||||
_, ok := m[k]
|
||||
return ok
|
||||
}
|
||||
|
||||
// NoEntryCarries opens the answer of reserved given a name no entry carries.
|
||||
const NoEntryCarries = "no entry carries the name "
|
||||
|
||||
|
||||
@@ -125,7 +125,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})
|
||||
v, err := r.Reserve(ctx, "m", "1.4", []string{"m:a", "m:b"}, Source{Branch: "main", Revision: 41, CatalogRevision: 44})
|
||||
if err != nil || v.Version != "1.4.3" {
|
||||
t.Fatalf("reserved %q (%v), want 1.4.3", v.Version, err)
|
||||
}
|
||||
@@ -154,12 +154,12 @@ func TestReservationIsReadAndMarkedPublished(t *testing.T) {
|
||||
if err != nil || len(marked) != 1 {
|
||||
t.Fatalf("a published of 1.4.3 with a built digest marked %v (%v)", marked, err)
|
||||
}
|
||||
// Design 47 G §52, §673, A-57: the package-published of that artifact carries the digest published, the branch and the source
|
||||
// revision the reservation was made for, and the dependencies its step result named.
|
||||
// Design 47 G §52, §673, A-57: the package-published of that artifact carries the digest published, the branch, the source
|
||||
// revision and the catalog revision (H-A-218) the reservation was made for, and the dependencies its step result named.
|
||||
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, 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", 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 {
|
||||
@@ -221,18 +221,53 @@ func TestAReleaseIsRecordedByFingerprintBeforeItsReservationGoes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestARebuildReservesAboveTheCatalogsHighestWhateverItsStandingNumberWas: design 47 G A-490b — a build again of a done key replaces
|
||||
// its fingerprint's standing reservation (and tells Took) and numbers above the catalog's highest alone, whether the standing number
|
||||
// is below it or above it; another fingerprint's standing reservation stays a floor.
|
||||
// TestTheWithdrawnVersionsAreDroppedOnceReleasedPast: design 47 H H-A-225, H-A-226, H-A-244 — a dropped number stays a gap, kept in
|
||||
// the series key's Withdrawn while it is above the catalog's highest released; at each write those at or below it go, so the
|
||||
// map never grows without end.
|
||||
func TestTheWithdrawnVersionsAreDroppedOnceReleasedPast(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
store := &reserveMem{mem: newMem()}
|
||||
highest := "0.1.3"
|
||||
r := &Reserver{Store: store, Filled: func() bool { return true },
|
||||
ReleasedOf: func(context.Context, string) ([]string, error) { return []string{highest}, nil }}
|
||||
for _, fp := range []string{"src2:a", "src2:b", "src2:c"} {
|
||||
if _, err := r.Reserve(ctx, "m", "0.1", []string{"m:a"}, Source{Fingerprint: fp}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
cur, _, _, _ := r.get(ctx, ReservedKey("m", "0.1"))
|
||||
if cur.Version != "0.1.6" || len(cur.Withdrawn) != 2 || cur.Withdrawn["0.1.4"] != "src2:a" || cur.Withdrawn["0.1.5"] != "src2:b" {
|
||||
t.Fatalf("reservation %+v; want 0.1.6 with 0.1.4 and 0.1.5 withdrawn", cur)
|
||||
}
|
||||
// H-A-244: the build whose number was withdrawn finds the reservation its series moved to; the one standing finds none.
|
||||
if by, took, err := r.TakenOver(ctx, "m", "src2:a"); err != nil || !took || by.Fingerprint != "src2:c" || by.Version != "0.1.6" {
|
||||
t.Errorf("taken over from src2:a by %+v (%v, %v); want src2:c 0.1.6", by, took, err)
|
||||
}
|
||||
if _, took, err := r.TakenOver(ctx, "m", "src2:c"); err != nil || took {
|
||||
t.Errorf("the standing build src2:c is said taken over (%v, %v)", took, err)
|
||||
}
|
||||
highest = "0.1.5" // the catalog released past both withdrawn numbers but the newest
|
||||
got, err := r.Reserve(ctx, "m", "0.1", []string{"m:a"}, Source{Fingerprint: "src2:d"})
|
||||
if err != nil || got.Version != "0.1.7" || len(got.Withdrawn) != 1 || got.Withdrawn["0.1.6"] != "src2:c" {
|
||||
t.Errorf("reserved %+v (%v); want 0.1.7 keeping only 0.1.6 withdrawn", got, err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestARebuildReservesAboveTheCatalogsHighestWhateverItsStandingNumberWas: design 47 G A-490b as H-A-225 amends it — a build again
|
||||
// of a done key, or a re-run after a restart, keeps its fingerprint's standing reservation while it is unreleased and above the
|
||||
// catalog's highest; one at or below it is replaced (Took told) by the next above the catalog's highest alone; another
|
||||
// fingerprint's standing reservation stays a floor and is withdrawn.
|
||||
func TestARebuildReservesAboveTheCatalogsHighestWhateverItsStandingNumberWas(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
for _, c := range []struct {
|
||||
name, standing, standingFp string
|
||||
want string
|
||||
rebuild, kept bool
|
||||
}{
|
||||
{name: "standing below the catalog's highest", standing: "0.1.0", standingFp: "fp", want: "0.1.17"},
|
||||
{name: "standing above the catalog's highest", standing: "0.1.30", standingFp: "fp", want: "0.1.17"},
|
||||
{name: "another fingerprint's standing number stays a floor", standing: "0.1.30", standingFp: "other", want: "0.1.31"},
|
||||
{name: "standing below the catalog's highest", standing: "0.1.0", standingFp: "fp", want: "0.1.17", rebuild: true},
|
||||
{name: "H-A-225: standing above the catalog's highest is kept by a build again", standing: "0.1.30", standingFp: "fp", want: "0.1.30", rebuild: true, kept: true},
|
||||
{name: "H-A-225: a re-run after a restart keeps its standing number", standing: "0.1.111", standingFp: "fp", want: "0.1.111", kept: true},
|
||||
{name: "another fingerprint's standing number stays a floor", standing: "0.1.30", standingFp: "other", want: "0.1.31", rebuild: true},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
store := &reserveMem{mem: newMem()}
|
||||
@@ -246,10 +281,68 @@ func TestARebuildReservesAboveTheCatalogsHighestWhateverItsStandingNumberWas(t *
|
||||
r.Took = func(_ context.Context, older, newer ReservedVersion) {
|
||||
took = append(took, older.Version+">"+newer.Version)
|
||||
}
|
||||
got, err := r.Reserve(ctx, "m", "0.1", []string{"m:a"}, Source{Fingerprint: "fp", Rebuild: true})
|
||||
got, err := r.Reserve(ctx, "m", "0.1", []string{"m:a"}, Source{Fingerprint: "fp", Rebuild: c.rebuild})
|
||||
if c.kept {
|
||||
if err != nil || got.Version != c.want || len(took) != 0 || got.Artifacts["m:a"] != "d" {
|
||||
t.Fatalf("reserved %+v (%v), took %v; want the standing %s kept as it stands", got, err, took, c.want)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil || got.Version != c.want || len(took) != 1 || took[0] != c.standing+">"+c.want {
|
||||
t.Fatalf("reserved %q (%v), took %v; want %s replacing %s", got.Version, err, took, c.want, c.standing)
|
||||
}
|
||||
if w := got.Withdrawn[c.standing]; (c.standingFp != "fp") != (w == c.standingFp) {
|
||||
t.Errorf("withdrawn %v; want %s withdrawn only when another fingerprint stood", got.Withdrawn, c.standing)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestANumberARegistryHoldsIsNeverReserved: design 47 H H-A-275 (the rule of H-A-245 for a registry's record) — a reserve skips
|
||||
// every number a registry seat holds of the module's artifacts and says the skipped ones; a read that fails lets it proceed; a
|
||||
// done build whose number a registry holds at another digest has it withdrawn as a gap (H-A-226), and its build again reserves the
|
||||
// next free number with fresh digests (H-A-279), the index following it.
|
||||
func TestANumberARegistryHoldsIsNeverReserved(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
store := &reserveMem{mem: newMem()}
|
||||
held := []string{"0.1.37", "0.1.38", "0.2.0"}
|
||||
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) {
|
||||
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
|
||||
},
|
||||
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", GoPackage: true})
|
||||
if err != nil || v.Version != "0.1.39" || len(skipped) != 2 {
|
||||
t.Fatalf("reserved %q (%v), skipped %v: want 0.1.39 past the two numbers the registry holds", v.Version, err, skipped)
|
||||
}
|
||||
// The build ends; the registry holds 0.1.39 at another digest meanwhile: the number is withdrawn, and the build again of the same
|
||||
// fingerprint reserves the next number no registry holds, with no digest yet (H-A-279).
|
||||
if _, err := r.Built(ctx, "node-tools", "0.1.39", "node-tools:program", "sha256:7c9b10", nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if w, ok, err := r.Withdraw(ctx, "node-tools", "0.1.39"); err != nil || !ok || w.Withdrawn["0.1.39"] != "fp1" {
|
||||
t.Fatalf("withdrew %+v (%v %v), want 0.1.39 withdrawn for fp1", w, ok, err)
|
||||
}
|
||||
held = []string{"0.1.37", "0.1.38", "0.1.39", "0.1.40", "0.2.0"}
|
||||
// The build again of a done key reserves as a rebuild (A-490b): a withdrawn number is never its floor's to reuse.
|
||||
again, err := r.Reserve(ctx, "node-tools", "0.1", []string{"node-tools:program"}, Source{Fingerprint: "fp1", GoPackage: true, Rebuild: true})
|
||||
if err != nil || again.Version != "0.1.41" || again.Artifacts["node-tools:program"] != "" || again.Withdrawn["0.1.39"] != "fp1" || again.Tag != GoTagOf("0.1.41") {
|
||||
t.Fatalf("the build again reserved %+v (%v), want 0.1.41 with no digest and 0.1.39 kept withdrawn", again, err)
|
||||
}
|
||||
if at, _ := r.AtVersion(ctx, "0.1.39"); len(at) != 0 {
|
||||
t.Errorf("the index by version still names the withdrawn number: %v", at)
|
||||
}
|
||||
if _, ok, _ := r.Withdraw(ctx, "node-tools", "0.1.39"); ok {
|
||||
t.Error("a number no reservation stands at any more was withdrawn")
|
||||
}
|
||||
// A registry that cannot be read lets the reserve proceed.
|
||||
readErr, skipped = errors.New("registry down"), nil
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +67,20 @@ func TestReservedByNameAnswersFromTheViewAndTheCatalog(t *testing.T) {
|
||||
t.Errorf("%s = %+v, want error naming %q alone", name, got, c.want)
|
||||
}
|
||||
}
|
||||
// H-A-225: another fingerprint taking the series over withdraws the older's version; a late publish of it is refused as
|
||||
// withdrawn, naming the fingerprint that took it over, never as a version that was never reserved.
|
||||
if _, err := r.Reserve(ctx, "mesh-sdk", "0.1", []string{"mesh-sdk:ts"}, Source{Fingerprint: "src2:a"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := r.Reserve(ctx, "mesh-sdk", "0.1", []string{"mesh-sdk:ts"}, Source{Fingerprint: "src2:b"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := ask("@novox/mesh-sdk", "0.1.5"); !strings.Contains(got.Error, "version 0.1.5 was withdrawn: the build of src2:a it was reserved for was taken over by src2:b, which reserves 0.1.6") {
|
||||
t.Errorf("a late publish of a withdrawn version = %+v, want refused as withdrawn", got)
|
||||
}
|
||||
if got := ask("@novox/mesh-sdk", "9.9.9"); !strings.Contains(got.Error, "reserved or released") {
|
||||
t.Errorf("a version never reserved = %+v, want refused as neither reserved nor released", got)
|
||||
}
|
||||
if _, err := AnswerReservedByName(ctx, rd, Carriers(packagesMem(nil)), released, "x", ""); err == nil {
|
||||
t.Error("an unreadable view was answered as if no entry carried the name")
|
||||
}
|
||||
|
||||
@@ -4,12 +4,28 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// AllFilter is the key filter of every version of every name: two tokens.
|
||||
const AllFilter = "*.*"
|
||||
|
||||
// FilterMatches says whether key is under filter as the bus reads a key filter: token by token, a `*` any one token, so AllFilter
|
||||
// lists the two-token keys alone and never the index's three-token keys (H-A-269 (1)).
|
||||
func FilterMatches(filter, key string) bool {
|
||||
ft, kt := strings.Split(filter, "."), strings.Split(key, ".")
|
||||
if len(ft) != len(kt) {
|
||||
return false
|
||||
}
|
||||
for i := range ft {
|
||||
if ft[i] != "*" && ft[i] != kt[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ErrConflict is what a Store answers when a Create finds the key or an Update finds another revision.
|
||||
var ErrConflict = errors.New("the key exists or changed")
|
||||
|
||||
|
||||
@@ -45,13 +45,9 @@ func (s readStore) KeysOf(_ context.Context, filter string) ([]string, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if filter == AllFilter {
|
||||
return all, nil
|
||||
}
|
||||
prefix := strings.TrimSuffix(filter, "*")
|
||||
var out []string
|
||||
for _, k := range all {
|
||||
if strings.HasPrefix(k, prefix) && !strings.Contains(k[len(prefix):], ".") {
|
||||
if FilterMatches(filter, k) {
|
||||
out = append(out, k)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,21 +66,9 @@ func (m *mem) KeysOf(_ context.Context, filter string) ([]string, error) {
|
||||
if m.down != nil {
|
||||
return nil, m.down
|
||||
}
|
||||
prefix := strings.TrimSuffix(filter, "*")
|
||||
var out []string
|
||||
for k := range m.vals {
|
||||
if filter == AllFilter {
|
||||
out = append(out, k)
|
||||
continue
|
||||
}
|
||||
if strings.Count(filter, ".") == 2 { // a three-token filter, `a.*.*` as the bus reads it
|
||||
ft, kt := strings.Split(filter, "."), strings.Split(k, ".")
|
||||
if len(kt) == 3 && kt[0] == ft[0] {
|
||||
out = append(out, k)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(k, prefix) && !strings.Contains(k[len(prefix):], ".") {
|
||||
if FilterMatches(filter, k) { // token by token, as the bus reads a filter
|
||||
out = append(out, k)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,9 @@ import (
|
||||
// eventPrefix starts every event subject of the seat.
|
||||
const eventPrefix = "mesh.seat." + seat.Seat + ".event."
|
||||
|
||||
// perSource are the events said per source revision, on <event>.<branch>.<source> (design 47 H §746, H-A-72 (3)).
|
||||
var perSource = []string{seat.EventPipelineStarted, seat.EventPipelineEnded, seat.EventWaitHeld, seat.EventWaitEnded}
|
||||
// perRevision are the events said per pipeline, on <event>.<branch>.<revision>, its catalog revision's number as its key
|
||||
// names it (design 47 H §746, H-A-72 (3), H-A-221).
|
||||
var perRevision = []string{seat.EventPipelineStarted, seat.EventPipelineEnded, seat.EventWaitHeld, seat.EventWaitEnded}
|
||||
|
||||
// Subject is where the runner says a step's event or a run's start: mesh.seat.mesh-pipeline-runner.event.<event>.
|
||||
// <module>.<branch>.<commit>, each name escaped as a key's name is, so a branch holding a dot is one token (design 47 H
|
||||
@@ -27,41 +28,42 @@ func Subject(event, module, branch, commit string) string {
|
||||
return eventPrefix + event + "." + keys.EscapeName(module) + "." + keys.EscapeName(branch) + "." + keys.EscapeName(commit)
|
||||
}
|
||||
|
||||
// SourceSubject is where the runner says a pipeline's start and end and its waits: mesh.seat.mesh-pipeline-runner.
|
||||
// event.<event>.<branch>.<source>, the branch escaped as a key's name is (design 47 H §746, H-A-72 (3)).
|
||||
func SourceSubject(event, branch string, source int64) string {
|
||||
return eventPrefix + event + "." + keys.EscapeName(branch) + "." + strconv.FormatInt(source, 10)
|
||||
// RevisionSubject is where the runner says a pipeline's start and end and its waits: mesh.seat.mesh-pipeline-runner.
|
||||
// event.<event>.<branch>.<revision>, the pipeline's catalog revision number, the branch escaped as a key's name is (design
|
||||
// 47 H §746, H-A-72 (3), H-A-221).
|
||||
func RevisionSubject(event, branch string, revision int64) string {
|
||||
return eventPrefix + event + "." + keys.EscapeName(branch) + "." + strconv.FormatInt(revision, 10)
|
||||
}
|
||||
|
||||
// Of is what an event's subject names: a step's event or a run's start names the module, the branch and the commit; an
|
||||
// event per source revision names the branch and the source.
|
||||
// event per pipeline names the branch and the pipeline's catalog revision (H-A-221).
|
||||
type Of struct {
|
||||
Event, Module, Branch, Commit string
|
||||
Source int64
|
||||
Revision int64
|
||||
}
|
||||
|
||||
// Parse reads a subject Subject or SourceSubject built: an event of the seat's, and its names unescaped.
|
||||
// Parse reads a subject Subject or RevisionSubject built: an event of the seat's, and its names unescaped.
|
||||
func Parse(subject string) (Of, error) {
|
||||
rest, ok := strings.CutPrefix(subject, eventPrefix)
|
||||
toks := strings.Split(rest, ".")
|
||||
bySource := len(toks) > 0 && slices.Contains(perSource, toks[0])
|
||||
byRevision := len(toks) > 0 && slices.Contains(perRevision, toks[0])
|
||||
want := 4
|
||||
if bySource {
|
||||
if byRevision {
|
||||
want = 3
|
||||
}
|
||||
if !ok || len(toks) != want || !slices.Contains(seat.Events(), toks[0]) {
|
||||
return Of{}, fmt.Errorf("meshpipelinerunnerclient: %q is no event subject of the seat %s", subject, seat.Seat)
|
||||
}
|
||||
if bySource {
|
||||
if byRevision {
|
||||
branch, err := keys.UnescapeName(toks[1])
|
||||
if err != nil || branch == "" {
|
||||
return Of{}, fmt.Errorf("meshpipelinerunnerclient: %q: branch: %v", subject, err)
|
||||
}
|
||||
source, err := strconv.ParseInt(toks[2], 10, 64)
|
||||
if err != nil || source < 1 {
|
||||
return Of{}, fmt.Errorf("meshpipelinerunnerclient: %q: no source revision", subject)
|
||||
revision, err := strconv.ParseInt(toks[2], 10, 64)
|
||||
if err != nil || revision < 1 {
|
||||
return Of{}, fmt.Errorf("meshpipelinerunnerclient: %q: no revision", subject)
|
||||
}
|
||||
return Of{Event: toks[0], Branch: branch, Source: source}, nil
|
||||
return Of{Event: toks[0], Branch: branch, Revision: revision}, nil
|
||||
}
|
||||
names := make([]string, 0, 3)
|
||||
for i, t := range toks[1:] {
|
||||
|
||||
@@ -17,14 +17,14 @@ func TestSubjectsAndBodies(t *testing.T) {
|
||||
if of, err := Parse(s); err != nil || of != (Of{Event: seat.EventStepEnded, Module: "nats", Branch: "release.1", Commit: "c1"}) {
|
||||
t.Errorf("parse %s: %+v, %v", s, of, err)
|
||||
}
|
||||
ps := SourceSubject(seat.EventPipelineEnded, "release.1", 3589)
|
||||
ps := RevisionSubject(seat.EventPipelineEnded, "release.1", 3589)
|
||||
if ps != "mesh.seat.mesh-pipeline-runner.event.pipeline-ended.release=2e1.3589" {
|
||||
t.Errorf("pipeline-ended subject %s", ps)
|
||||
}
|
||||
if of, err := Parse(ps); err != nil || of != (Of{Event: seat.EventPipelineEnded, Branch: "release.1", Source: 3589}) {
|
||||
if of, err := Parse(ps); err != nil || of != (Of{Event: seat.EventPipelineEnded, Branch: "release.1", Revision: 3589}) {
|
||||
t.Errorf("parse %s: %+v, %v", ps, of, err)
|
||||
}
|
||||
if of, err := Parse(SourceSubject(seat.EventWaitHeld, "main", 7)); err != nil || of.Source != 7 || of.Module != "" {
|
||||
if of, err := Parse(RevisionSubject(seat.EventWaitHeld, "main", 7)); err != nil || of.Revision != 7 || of.Module != "" {
|
||||
t.Errorf("wait-held: %+v, %v", of, err)
|
||||
}
|
||||
for _, bad := range []string{"not.an.event.subject",
|
||||
|
||||
@@ -95,6 +95,8 @@ type PackagePublished struct {
|
||||
Digest string `json:"digest"`
|
||||
// the module
|
||||
Module string `json:"module"`
|
||||
// the catalog revision number of that branch the build was made from, the indexer's count (design 47 H-A-218, H-A-220); absent from a reservation made before the field
|
||||
Revision int64 `json:"revision,omitempty"`
|
||||
// the source revision of that branch the build was made from
|
||||
Source int64 `json:"source"`
|
||||
V int64 `json:"v"`
|
||||
@@ -114,9 +116,11 @@ type StepEnded struct {
|
||||
// the node the builder ran it on, as in the subject
|
||||
Node string `json:"node"`
|
||||
// never passed for a build that built nothing
|
||||
Outcome string `json:"outcome"`
|
||||
Pipeline string `json:"pipeline"`
|
||||
Rerun bool `json:"rerun,omitempty"`
|
||||
Outcome string `json:"outcome"`
|
||||
// the pins the step's entries were built with, each mesh package's version by its module path, the ones the builder took from the registry for a package the entry named with none included; the runner asks the entry's held test steps with them (H-A-207)
|
||||
Packages map[string]string `json:"packages,omitempty"`
|
||||
Pipeline string `json:"pipeline"`
|
||||
Rerun bool `json:"rerun,omitempty"`
|
||||
// why it failed or could not run: the entry not built, the part not heard
|
||||
Said string `json:"said,omitempty"`
|
||||
Started *time.Time `json:"started,omitempty"`
|
||||
|
||||
@@ -715,6 +715,10 @@ type CatalogRevision struct {
|
||||
Base int64 `json:"base,omitempty"`
|
||||
// the watched branch the revision is of
|
||||
Branch string `json:"branch,omitempty"`
|
||||
// what made the revision (design 47 H-A-212, H-A-213): a take-in's the gate's call its source revision names, a re-pin's release of <module> <version>, a take-in again's take-in again of <repository>; absent for a candidate's
|
||||
Call string `json:"call,omitempty"`
|
||||
// the kind of what made the revision, which a reader reads instead of call's words (design 47 H-A-213 (3), H-A-214, H-A-215, H-A-217): a take-in's, a re-pin's on a module's release, a take-in again's, a recompute's that moved a fingerprint (its call naming the reason); absent for a candidate's
|
||||
CallKind string `json:"call-kind,omitempty"`
|
||||
// the seat definitions it was judged with, each by its digest, read whole through seat-definitions
|
||||
Definitions []CatalogRevisionDefinitionsItem `json:"definitions,omitempty"`
|
||||
// one per module, by name
|
||||
@@ -725,8 +729,12 @@ type CatalogRevision struct {
|
||||
Heads string `json:"heads,omitempty"`
|
||||
// trunk or candidate
|
||||
Kind string `json:"kind"`
|
||||
// for call-kind release, the module released (H-A-215)
|
||||
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"`
|
||||
// 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
|
||||
Revision int64 `json:"revision"`
|
||||
// the source revision it was taken in from; for a candidate, the source revision its heads are merged onto
|
||||
@@ -735,8 +743,18 @@ type CatalogRevision struct {
|
||||
Trunk []Head `json:"trunk,omitempty"`
|
||||
// the layout version
|
||||
V int64 `json:"v,omitempty"`
|
||||
// for call-kind release, the version released (H-A-215)
|
||||
Version string `json:"version,omitempty"`
|
||||
}
|
||||
|
||||
// The values of CatalogRevision's call-kind.
|
||||
const (
|
||||
CatalogRevisionCallKindTakeIn = "take-in"
|
||||
CatalogRevisionCallKindRelease = "release"
|
||||
CatalogRevisionCallKindTakeInAgain = "take-in-again"
|
||||
CatalogRevisionCallKindRecompute = "recompute"
|
||||
)
|
||||
|
||||
// Edge is one edge of the catalog graph between artifact references, B before A (ADR 0666 section 14): kind 1 B published before A builds (a package A imports), 2 B published before A delivers (fetched by reference at its start), 3 B delivered before A builds (its build module and toolchain), 4 B delivered before A delivers (a provision, bus state, a format's reader), 5 B has acted for A's new version (an acting rule), 6 B runs a version that serves A (a verb or a manifest word A uses).
|
||||
type Edge struct {
|
||||
// declared in the artifact entry's needs of A's manifest, where nothing else says it
|
||||
@@ -1301,6 +1319,10 @@ type CatalogRevisionEvent struct {
|
||||
At *time.Time `json:"at,omitempty"`
|
||||
// the watched branch the revision is of, escaped as a key name is
|
||||
Branch string `json:"branch,omitempty"`
|
||||
// what made the revision, as the revision's call names it (design 47 H-A-212, H-A-213); absent for a candidate's
|
||||
Call string `json:"call,omitempty"`
|
||||
// the kind of what made the revision, which a reader reads instead of call's words (design 47 H-A-213 (3), H-A-214, H-A-215, H-A-217); absent for a candidate's
|
||||
CallKind string `json:"call-kind,omitempty"`
|
||||
// the modules whose entries differ from the revision before it of the same kind
|
||||
Changed []string `json:"changed,omitempty"`
|
||||
// how many entries it lists
|
||||
@@ -1308,12 +1330,26 @@ type CatalogRevisionEvent struct {
|
||||
Group string `json:"group,omitempty"`
|
||||
Heads string `json:"heads,omitempty"`
|
||||
// trunk or candidate: a candidate's moves no running part
|
||||
Kind string `json:"kind"`
|
||||
Revision int64 `json:"revision"`
|
||||
Source int64 `json:"source"`
|
||||
V int64 `json:"v"`
|
||||
Kind string `json:"kind"`
|
||||
// for call-kind release, the module released (H-A-215)
|
||||
Module string `json:"module,omitempty"`
|
||||
// for call-kind take-in-again, the repository taken in again (H-A-215)
|
||||
Repository string `json:"repository,omitempty"`
|
||||
Revision int64 `json:"revision"`
|
||||
Source int64 `json:"source"`
|
||||
V int64 `json:"v"`
|
||||
// for call-kind release, the version released (H-A-215)
|
||||
Version string `json:"version,omitempty"`
|
||||
}
|
||||
|
||||
// The values of CatalogRevisionEvent's call-kind.
|
||||
const (
|
||||
CatalogRevisionEventCallKindTakeIn = "take-in"
|
||||
CatalogRevisionEventCallKindRelease = "release"
|
||||
CatalogRevisionEventCallKindTakeInAgain = "take-in-again"
|
||||
CatalogRevisionEventCallKindRecompute = "recompute"
|
||||
)
|
||||
|
||||
// FillingEvent is the body of the event filling.
|
||||
type FillingEvent = Fill
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ func TestFixtures(t *testing.T) {
|
||||
decode func([]byte) (any, error)
|
||||
subjectIs *regexp.Regexp
|
||||
}{
|
||||
{name: "a trunk revision kept, on the seat's subject", subject: "mesh.seat.mesh-catalog.event.catalog-revision.main", given: "{\"at\":\"2026-11-09T19:00:00Z\",\"branch\":\"main\",\"changed\":[\"xclip\"],\"entries\":2,\"kind\":\"trunk\",\"revision\":12,\"source\":3589,\"v\":1}", wire: "{\"at\":\"2026-11-09T19:00:00Z\",\"branch\":\"main\",\"changed\":[\"xclip\"],\"entries\":2,\"kind\":\"trunk\",\"revision\":12,\"source\":3589,\"v\":1}",
|
||||
{name: "a trunk revision kept, on the seat's subject", subject: "mesh.seat.mesh-catalog.event.catalog-revision.main", given: "{\"at\":\"2026-11-09T19:00:00Z\",\"branch\":\"main\",\"call\":\"release of mesh-sdk 0.1.27\",\"call-kind\":\"release\",\"changed\":[\"xclip\"],\"entries\":2,\"kind\":\"trunk\",\"module\":\"mesh-sdk\",\"revision\":12,\"source\":3589,\"v\":1,\"version\":\"0.1.27\"}", wire: "{\"at\":\"2026-11-09T19:00:00Z\",\"branch\":\"main\",\"call\":\"release of mesh-sdk 0.1.27\",\"call-kind\":\"release\",\"changed\":[\"xclip\"],\"entries\":2,\"kind\":\"trunk\",\"module\":\"mesh-sdk\",\"revision\":12,\"source\":3589,\"v\":1,\"version\":\"0.1.27\"}",
|
||||
decode: func(b []byte) (any, error) { var v CatalogRevisionEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-catalog\\.event\\.catalog-revision\\.[^.*> ]+$")},
|
||||
{name: "a candidate's revision kept", subject: "mesh.seat.mesh-catalog.event.catalog-revision.main", given: "{\"branch\":\"main\",\"entries\":2,\"group\":\"feat/47-G\",\"heads\":\"0123456789ab\",\"kind\":\"candidate\",\"revision\":13,\"source\":3589,\"v\":1}", wire: "{\"branch\":\"main\",\"entries\":2,\"group\":\"feat/47-G\",\"heads\":\"0123456789ab\",\"kind\":\"candidate\",\"revision\":13,\"source\":3589,\"v\":1}",
|
||||
decode: func(b []byte) (any, error) { var v CatalogRevisionEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-catalog\\.event\\.catalog-revision\\.[^.*> ]+$")},
|
||||
@@ -59,7 +59,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\",\"definitions\":[{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"seat\":\"node-build-go\"}],\"entries\":[{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"module\":\"mesh-build-go\"},{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"module\":\"xclip\"}],\"kind\":\"trunk\",\"movers\":[{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"fingerprint\":\"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"module\":\"xclip\",\"repository\":\"novox/mesh-catalog\"}],\"revision\":12,\"source\":3589,\"trunk\":[{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"repository\":\"novox/mesh-catalog\"}],\"v\":1}", wire: "{\"at\":\"2026-11-09T19:00:00Z\",\"base\":9,\"branch\":\"main\",\"definitions\":[{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"seat\":\"node-build-go\"}],\"entries\":[{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"module\":\"mesh-build-go\"},{\"digest\":\"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\",\"module\":\"xclip\"}],\"kind\":\"trunk\",\"movers\":[{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"fingerprint\":\"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"module\":\"xclip\",\"repository\":\"novox/mesh-catalog\"}],\"revision\":12,\"source\":3589,\"trunk\":[{\"commit\":\"f469eb387a3015569d9b16c66ed418e9dd098f64\",\"repository\":\"novox/mesh-catalog\"}],\"v\":1}",
|
||||
{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\"}",
|
||||
decode: func(b []byte) (any, error) {
|
||||
var v CatalogRevisionsByBranchRevisionValue
|
||||
err := json.Unmarshal(b, &v)
|
||||
|
||||
@@ -65,9 +65,9 @@ const (
|
||||
// StreamPipelineStarted is the stream pipeline-started is kept in.
|
||||
const StreamPipelineStarted = "SEAT_mesh-pipeline-runner_pipeline-started"
|
||||
|
||||
// SubjectPipelineStarted is where pipeline-started is published, on mesh.seat.mesh-pipeline-runner.event.pipeline-started.<branch>.<source>.
|
||||
func SubjectPipelineStarted(branch, source string) string {
|
||||
return "mesh.seat.mesh-pipeline-runner.event.pipeline-started." + branch + "." + source
|
||||
// SubjectPipelineStarted is where pipeline-started is published, on mesh.seat.mesh-pipeline-runner.event.pipeline-started.<branch>.<revision>.
|
||||
func SubjectPipelineStarted(branch, revision string) string {
|
||||
return "mesh.seat.mesh-pipeline-runner.event.pipeline-started." + branch + "." + revision
|
||||
}
|
||||
|
||||
// SubjectPipelineStartedAll hears every pipeline-started.
|
||||
@@ -76,9 +76,9 @@ const SubjectPipelineStartedAll = "mesh.seat.mesh-pipeline-runner.event.pipeline
|
||||
// StreamPipelineEnded is the stream pipeline-ended is kept in.
|
||||
const StreamPipelineEnded = "SEAT_mesh-pipeline-runner_pipeline-ended"
|
||||
|
||||
// SubjectPipelineEnded is where pipeline-ended is published, on mesh.seat.mesh-pipeline-runner.event.pipeline-ended.<branch>.<source>.
|
||||
func SubjectPipelineEnded(branch, source string) string {
|
||||
return "mesh.seat.mesh-pipeline-runner.event.pipeline-ended." + branch + "." + source
|
||||
// SubjectPipelineEnded is where pipeline-ended is published, on mesh.seat.mesh-pipeline-runner.event.pipeline-ended.<branch>.<revision>.
|
||||
func SubjectPipelineEnded(branch, revision string) string {
|
||||
return "mesh.seat.mesh-pipeline-runner.event.pipeline-ended." + branch + "." + revision
|
||||
}
|
||||
|
||||
// SubjectPipelineEndedAll hears every pipeline-ended.
|
||||
@@ -120,9 +120,9 @@ const SubjectStepEndedAll = "mesh.seat.mesh-pipeline-runner.event.step-ended.*.*
|
||||
// StreamWaitHeld is the stream wait-held is kept in.
|
||||
const StreamWaitHeld = "SEAT_mesh-pipeline-runner_wait-held"
|
||||
|
||||
// SubjectWaitHeld is where wait-held is published, on mesh.seat.mesh-pipeline-runner.event.wait-held.<branch>.<source>.
|
||||
func SubjectWaitHeld(branch, source string) string {
|
||||
return "mesh.seat.mesh-pipeline-runner.event.wait-held." + branch + "." + source
|
||||
// SubjectWaitHeld is where wait-held is published, on mesh.seat.mesh-pipeline-runner.event.wait-held.<branch>.<revision>.
|
||||
func SubjectWaitHeld(branch, revision string) string {
|
||||
return "mesh.seat.mesh-pipeline-runner.event.wait-held." + branch + "." + revision
|
||||
}
|
||||
|
||||
// SubjectWaitHeldAll hears every wait-held.
|
||||
@@ -131,9 +131,9 @@ const SubjectWaitHeldAll = "mesh.seat.mesh-pipeline-runner.event.wait-held.*.*"
|
||||
// StreamWaitEnded is the stream wait-ended is kept in.
|
||||
const StreamWaitEnded = "SEAT_mesh-pipeline-runner_wait-ended"
|
||||
|
||||
// SubjectWaitEnded is where wait-ended is published, on mesh.seat.mesh-pipeline-runner.event.wait-ended.<branch>.<source>.
|
||||
func SubjectWaitEnded(branch, source string) string {
|
||||
return "mesh.seat.mesh-pipeline-runner.event.wait-ended." + branch + "." + source
|
||||
// SubjectWaitEnded is where wait-ended is published, on mesh.seat.mesh-pipeline-runner.event.wait-ended.<branch>.<revision>.
|
||||
func SubjectWaitEnded(branch, revision string) string {
|
||||
return "mesh.seat.mesh-pipeline-runner.event.wait-ended." + branch + "." + revision
|
||||
}
|
||||
|
||||
// SubjectWaitEndedAll hears every wait-ended.
|
||||
@@ -156,11 +156,11 @@ const (
|
||||
StateStepOutputs = "step-outputs"
|
||||
)
|
||||
|
||||
// PipelinesByBranchSourceKey is the key of one value of the state pipelines under the form "<branch>.<source>".
|
||||
func PipelinesByBranchSourceKey(branch, source string) string { return branch + "." + source }
|
||||
// PipelinesByBranchRevisionKey is the key of one value of the state pipelines under the form "<branch>.<revision>".
|
||||
func PipelinesByBranchRevisionKey(branch, revision string) string { return branch + "." + revision }
|
||||
|
||||
// ParsePipelinesByBranchSourceKey reads the parts of a key of the form "<branch>.<source>", in the order of the form; the last result is false for a key of another form.
|
||||
func ParsePipelinesByBranchSourceKey(key string) (string, string, bool) {
|
||||
// ParsePipelinesByBranchRevisionKey reads the parts of a key of the form "<branch>.<revision>", in the order of the form; the last result is false for a key of another form.
|
||||
func ParsePipelinesByBranchRevisionKey(key string) (string, string, bool) {
|
||||
rest := key
|
||||
v0, after0, found0 := strings.Cut(rest, ".")
|
||||
if !found0 || v0 == "" {
|
||||
@@ -178,9 +178,9 @@ func ParsePipelinesByBranchSourceKey(key string) (string, string, bool) {
|
||||
return v0, v2, true
|
||||
}
|
||||
|
||||
// DecodePipelinesByBranchSourceValue reads one value of the state pipelines under the form "<branch>.<source>", refusing a field PipelinesByBranchSourceValue does not know and any text after the value.
|
||||
func DecodePipelinesByBranchSourceValue(raw []byte) (PipelinesByBranchSourceValue, error) {
|
||||
var v PipelinesByBranchSourceValue
|
||||
// DecodePipelinesByBranchRevisionValue reads one value of the state pipelines under the form "<branch>.<revision>", refusing a field PipelinesByBranchRevisionValue does not know and any text after the value.
|
||||
func DecodePipelinesByBranchRevisionValue(raw []byte) (PipelinesByBranchRevisionValue, error) {
|
||||
var v PipelinesByBranchRevisionValue
|
||||
dec := json.NewDecoder(bytes.NewReader(raw))
|
||||
dec.DisallowUnknownFields()
|
||||
if err := dec.Decode(&v); err != nil {
|
||||
@@ -670,7 +670,7 @@ type Pipeline struct {
|
||||
// the modules the pipeline moves, its take-in's entries (design 47 H §746)
|
||||
Movers []Mover `json:"movers"`
|
||||
Outcome string `json:"outcome"`
|
||||
// the pipeline's key, <branch>.<source>, <branch>.<source>.published.<package>.<version> for a pipeline a publish started, or <branch>.run.<run> for a run on request; a branch escaped as a key's name is (design 47 H §746, §747; H-A-83)
|
||||
// the pipeline's key, <branch>.<revision>, <branch>.<source>.published.<package>.<version> for a pipeline a publish started, or <branch>.run.<run> for a run on request; a branch escaped as a key's name is (design 47 H §746, §747; H-A-83)
|
||||
Pipeline string `json:"pipeline"`
|
||||
// for a pipeline a package's publish started, that publish (A-202)
|
||||
Published *Published `json:"published,omitempty"`
|
||||
@@ -720,7 +720,7 @@ type PipelineEnded struct {
|
||||
// per mover its fingerprint, released version, step results and tier, in the delivery order (design 47 H §746, H-A-2)
|
||||
Movers []MoverEnded `json:"movers"`
|
||||
Outcome string `json:"outcome"`
|
||||
// the pipeline's key, <branch>.<source>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747)
|
||||
// the pipeline's key, <branch>.<revision>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747)
|
||||
Pipeline string `json:"pipeline"`
|
||||
// the catalog graph revision of the branch the pipeline runs for
|
||||
Revision int64 `json:"revision,omitempty"`
|
||||
@@ -753,7 +753,7 @@ type PipelineStarted struct {
|
||||
Call string `json:"call,omitempty"`
|
||||
// the pipeline's movers
|
||||
Movers []Mover `json:"movers"`
|
||||
// the pipeline's key, <branch>.<source>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747)
|
||||
// the pipeline's key, <branch>.<revision>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747)
|
||||
Pipeline string `json:"pipeline"`
|
||||
// for a pipeline a package's publish started, that publish (A-202)
|
||||
Published *Published `json:"published,omitempty"`
|
||||
@@ -814,7 +814,7 @@ type StepEvent struct {
|
||||
// the module's build-input fingerprint at the commit
|
||||
Fingerprint string `json:"fingerprint,omitempty"`
|
||||
Module string `json:"module"`
|
||||
// the pipeline's key, <branch>.<source>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747)
|
||||
// the pipeline's key, <branch>.<revision>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747)
|
||||
Pipeline string `json:"pipeline"`
|
||||
Result StepResult `json:"result"`
|
||||
// the catalog graph revision of the branch the pipeline runs for
|
||||
@@ -966,7 +966,7 @@ type ToolchainUsed struct {
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
// Wait is a step's wait, held and ended; a wait on a person is said as waiting on that person, never a stall (ADR 0283); said on <branch>.<source> (design 47 H-A-72).
|
||||
// Wait is a step's wait, held and ended; a wait on a person is said as waiting on that person, never a stall (ADR 0283); said on <branch>.<revision> (design 47 H-A-72, H-A-221).
|
||||
type Wait struct {
|
||||
Artifact string `json:"artifact,omitempty"`
|
||||
// the step's own ask, where it has one (design 47 G §731)
|
||||
@@ -983,7 +983,7 @@ type Wait struct {
|
||||
Module string `json:"module,omitempty"`
|
||||
// what the step waits on (design 47 *Health and going back*)
|
||||
On string `json:"on"`
|
||||
// the pipeline's key, <branch>.<source>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747)
|
||||
// the pipeline's key, <branch>.<revision>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747)
|
||||
Pipeline string `json:"pipeline"`
|
||||
// the catalog graph revision of the branch the pipeline runs for
|
||||
Revision int64 `json:"revision,omitempty"`
|
||||
@@ -1024,7 +1024,7 @@ const (
|
||||
|
||||
// Waiting is a pipeline waiting its turn under pipelines-at-once (design 47 H §748, H-A-72).
|
||||
type Waiting struct {
|
||||
// the pipeline's key, <branch>.<source>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747)
|
||||
// the pipeline's key, <branch>.<revision>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747)
|
||||
Pipeline string `json:"pipeline"`
|
||||
}
|
||||
|
||||
@@ -1355,8 +1355,8 @@ type FullEvent = Fill
|
||||
// RoomEvent is the body of the event room.
|
||||
type RoomEvent = Fill
|
||||
|
||||
// PipelinesByBranchSourceValue is one value of the state pipelines under the key <branch>.<source>.
|
||||
type PipelinesByBranchSourceValue = Pipeline
|
||||
// PipelinesByBranchRevisionValue is one value of the state pipelines under the key <branch>.<revision>.
|
||||
type PipelinesByBranchRevisionValue = Pipeline
|
||||
|
||||
// PipelinesByBranchSourcePublishedPackageVersionValue is one value of the state pipelines under the key <branch>.<source>.published.<package>.<version>.
|
||||
type PipelinesByBranchSourcePublishedPackageVersionValue = Pipeline
|
||||
|
||||
@@ -45,7 +45,7 @@ func TestFixtures(t *testing.T) {
|
||||
decode: func(b []byte) (any, error) { var v StepEndedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-pipeline-runner\\.event\\.step-ended\\.[^.*> ]+\\.[^.*> ]+\\.[^.*> ]+$")},
|
||||
{name: "a take-in's pipeline kept, its steps naming their mover", subject: "", given: "{\"branch\":\"main\",\"call\":\"0123456789abcdef\",\"end-count\":1,\"ended\":\"2026-11-10T10:20:00Z\",\"movers\":[{\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"repository\":\"mesh-networking\",\"tier\":1}],\"outcome\":\"passed\",\"pipeline\":\"main.3589\",\"revision\":12,\"source\":3589,\"started\":\"2026-11-10T10:00:00Z\",\"steps\":[{\"artifact\":\"nats:program\",\"ask\":\"m2kx9a1b3c4d5e\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"node\":\"anchor\",\"outcome\":\"passed\",\"seat\":\"node-build-go\",\"status\":\"required\",\"step\":\"lint\"},{\"artifact\":\"nats:program\",\"carried-from\":\"main.3588\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"outcome\":\"carried\",\"status\":\"required\",\"step\":\"unit\",\"tests\":{\"unit\":42}},{\"artifact\":\"nats:program\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"node\":\"home-server\",\"outcome\":\"failed\",\"seat\":\"node-build-go\",\"status\":\"optional\",\"step\":\"integration\",\"tests\":{\"integration\":3},\"why\":\"TestTheBusWhole failed\"},{\"module\":\"nats\",\"outcome\":\"passed\",\"seat\":\"mesh-wants\",\"status\":\"required\",\"step\":\"composition\"},{\"module\":\"nats\",\"outcome\":\"bypassed\",\"status\":\"bypass\",\"step\":\"review\"},{\"module\":\"nats\",\"outcome\":\"passed\",\"status\":\"required\",\"step\":\"approval\"}],\"v\":1}", wire: "{\"branch\":\"main\",\"call\":\"0123456789abcdef\",\"end-count\":1,\"ended\":\"2026-11-10T10:20:00Z\",\"movers\":[{\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"repository\":\"mesh-networking\",\"tier\":1}],\"outcome\":\"passed\",\"pipeline\":\"main.3589\",\"revision\":12,\"source\":3589,\"started\":\"2026-11-10T10:00:00Z\",\"steps\":[{\"artifact\":\"nats:program\",\"ask\":\"m2kx9a1b3c4d5e\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"node\":\"anchor\",\"outcome\":\"passed\",\"seat\":\"node-build-go\",\"status\":\"required\",\"step\":\"lint\"},{\"artifact\":\"nats:program\",\"carried-from\":\"main.3588\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"outcome\":\"carried\",\"status\":\"required\",\"step\":\"unit\",\"tests\":{\"unit\":42}},{\"artifact\":\"nats:program\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"node\":\"home-server\",\"outcome\":\"failed\",\"seat\":\"node-build-go\",\"status\":\"optional\",\"step\":\"integration\",\"tests\":{\"integration\":3},\"why\":\"TestTheBusWhole failed\"},{\"module\":\"nats\",\"outcome\":\"passed\",\"seat\":\"mesh-wants\",\"status\":\"required\",\"step\":\"composition\"},{\"module\":\"nats\",\"outcome\":\"bypassed\",\"status\":\"bypass\",\"step\":\"review\"},{\"module\":\"nats\",\"outcome\":\"passed\",\"status\":\"required\",\"step\":\"approval\"}],\"v\":1}",
|
||||
decode: func(b []byte) (any, error) {
|
||||
var v PipelinesByBranchSourceValue
|
||||
var v PipelinesByBranchRevisionValue
|
||||
err := json.Unmarshal(b, &v)
|
||||
return v, err
|
||||
}, subjectIs: nil},
|
||||
@@ -73,13 +73,13 @@ func TestFixtures(t *testing.T) {
|
||||
}, subjectIs: nil},
|
||||
{name: "a pipeline waiting its turn, its seq given", subject: "", given: "{\"branch\":\"main\",\"call\":\"fedcba9876543210\",\"movers\":[{\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"fingerprint\":\"fp-0124\",\"module\":\"nats\",\"repository\":\"mesh-networking\",\"tier\":1}],\"outcome\":\"waiting\",\"pipeline\":\"main.3590\",\"revision\":13,\"seq\":2,\"source\":3590,\"steps\":[],\"v\":1}", wire: "{\"branch\":\"main\",\"call\":\"fedcba9876543210\",\"movers\":[{\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"fingerprint\":\"fp-0124\",\"module\":\"nats\",\"repository\":\"mesh-networking\",\"tier\":1}],\"outcome\":\"waiting\",\"pipeline\":\"main.3590\",\"revision\":13,\"seq\":2,\"source\":3590,\"steps\":[],\"v\":1}",
|
||||
decode: func(b []byte) (any, error) {
|
||||
var v PipelinesByBranchSourceValue
|
||||
var v PipelinesByBranchRevisionValue
|
||||
err := json.Unmarshal(b, &v)
|
||||
return v, err
|
||||
}, subjectIs: nil},
|
||||
{name: "a waiting pipeline names the movers a newer take-in took out of it", subject: "", given: "{\"branch\":\"main\",\"call\":\"fedcba9876543210\",\"movers\":[{\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"fingerprint\":\"fp-0124\",\"module\":\"nats\",\"repository\":\"mesh-networking\",\"tier\":1}],\"outcome\":\"waiting\",\"pipeline\":\"main.3590\",\"revision\":13,\"seq\":2,\"source\":3590,\"steps\":[],\"superseded\":[\"mesh-config\"],\"v\":1}", wire: "{\"branch\":\"main\",\"call\":\"fedcba9876543210\",\"movers\":[{\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"fingerprint\":\"fp-0124\",\"module\":\"nats\",\"repository\":\"mesh-networking\",\"tier\":1}],\"outcome\":\"waiting\",\"pipeline\":\"main.3590\",\"revision\":13,\"seq\":2,\"source\":3590,\"steps\":[],\"superseded\":[\"mesh-config\"],\"v\":1}",
|
||||
decode: func(b []byte) (any, error) {
|
||||
var v PipelinesByBranchSourceValue
|
||||
var v PipelinesByBranchRevisionValue
|
||||
err := json.Unmarshal(b, &v)
|
||||
return v, err
|
||||
}, subjectIs: nil},
|
||||
|
||||
@@ -83,9 +83,9 @@ const SubjectWantedAll = "mesh.seat.mesh-wants.event.wanted.*.*"
|
||||
// StreamPipelineWanted is the stream pipeline-wanted is kept in.
|
||||
const StreamPipelineWanted = "SEAT_mesh-wants_pipeline-wanted"
|
||||
|
||||
// SubjectPipelineWanted is where pipeline-wanted is published, on mesh.seat.mesh-wants.event.pipeline-wanted.<branch>.<source>.
|
||||
func SubjectPipelineWanted(branch, source string) string {
|
||||
return "mesh.seat.mesh-wants.event.pipeline-wanted." + branch + "." + source
|
||||
// SubjectPipelineWanted is where pipeline-wanted is published, on mesh.seat.mesh-wants.event.pipeline-wanted.<branch>.<revision>.
|
||||
func SubjectPipelineWanted(branch, revision string) string {
|
||||
return "mesh.seat.mesh-wants.event.pipeline-wanted." + branch + "." + revision
|
||||
}
|
||||
|
||||
// SubjectPipelineWantedAll hears every pipeline-wanted.
|
||||
@@ -1001,10 +1001,12 @@ type PipelineWanted struct {
|
||||
// for tier-late, the late tier's movers not running and the machines they do not run on
|
||||
NotRunning []NotRunning `json:"not-running,omitempty"`
|
||||
Outcome string `json:"outcome"`
|
||||
// the runner's pipeline key, <branch>.<source>, a branch escaped as a key's name is (design 47 H §746)
|
||||
// the runner's pipeline key, <branch>.<revision>, a branch escaped as a key's name is (design 47 H §746, H-A-213 (4))
|
||||
Pipeline string `json:"pipeline"`
|
||||
Source int64 `json:"source"`
|
||||
V int64 `json:"v"`
|
||||
// the pipeline's catalog revision number, the number of its key; the indexer frees the pins of that revision, not of another revision of the same source (design 47 H-A-214); absent from an older event
|
||||
Revision int64 `json:"revision,omitempty"`
|
||||
Source int64 `json:"source"`
|
||||
V int64 `json:"v"`
|
||||
}
|
||||
|
||||
// The values of PipelineWanted's outcome.
|
||||
|
||||
@@ -29,7 +29,7 @@ func TestFixtures(t *testing.T) {
|
||||
decode: func(b []byte) (any, error) { var v WantedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-wants\\.event\\.wanted\\.[^.*> ]+\\.[^.*> ]+$")},
|
||||
{name: "a want removed, its node left or its module unplaced", subject: "mesh.seat.mesh-wants.event.wanted.n1.xclip", given: "{\"at\":\"2026-11-09T19:05:00Z\",\"fp\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"module\":\"xclip\",\"node\":\"n1\",\"removed\":true,\"revision\":41,\"v\":1}", wire: "{\"at\":\"2026-11-09T19:05:00Z\",\"fp\":\"src2:b427bdde1f100e2f52490cfa9df0c5112dd3700226b4892349f0c14a15a4af56\",\"module\":\"xclip\",\"node\":\"n1\",\"removed\":true,\"revision\":41,\"v\":1}",
|
||||
decode: func(b []byte) (any, error) { var v WantedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-wants\\.event\\.wanted\\.[^.*> ]+\\.[^.*> ]+$")},
|
||||
{name: "a pipeline's wants all run", subject: "mesh.seat.mesh-wants.event.pipeline-wanted.main.3589", given: "{\"branch\":\"main\",\"outcome\":\"running\",\"pipeline\":\"main.3589\",\"source\":3589,\"v\":1}", wire: "{\"branch\":\"main\",\"outcome\":\"running\",\"pipeline\":\"main.3589\",\"source\":3589,\"v\":1}",
|
||||
{name: "a pipeline's wants all run", subject: "mesh.seat.mesh-wants.event.pipeline-wanted.main.3590", given: "{\"branch\":\"main\",\"outcome\":\"running\",\"pipeline\":\"main.3590\",\"revision\":3590,\"source\":3589,\"v\":1}", wire: "{\"branch\":\"main\",\"outcome\":\"running\",\"pipeline\":\"main.3590\",\"revision\":3590,\"source\":3589,\"v\":1}",
|
||||
decode: func(b []byte) (any, error) { var v PipelineWantedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-wants\\.event\\.pipeline-wanted\\.[^.*> ]+\\.[^.*> ]+$")},
|
||||
{name: "a pipeline's tier late, naming the movers and machines not running", subject: "mesh.seat.mesh-wants.event.pipeline-wanted.main.3590", given: "{\"branch\":\"main\",\"not-running\":[{\"machines\":[\"anchor\",\"laptop\"],\"module\":\"nats\"}],\"outcome\":\"tier-late\",\"pipeline\":\"main.3590\",\"source\":3590,\"v\":1}", wire: "{\"branch\":\"main\",\"not-running\":[{\"machines\":[\"anchor\",\"laptop\"],\"module\":\"nats\"}],\"outcome\":\"tier-late\",\"pipeline\":\"main.3590\",\"source\":3590,\"v\":1}",
|
||||
decode: func(b []byte) (any, error) { var v PipelineWantedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-wants\\.event\\.pipeline-wanted\\.[^.*> ]+\\.[^.*> ]+$")},
|
||||
|
||||
@@ -905,8 +905,10 @@ type StepRun struct {
|
||||
Pipeline string `json:"pipeline"`
|
||||
// the step is asked again by the runner's rerun
|
||||
Rerun bool `json:"rerun,omitempty"`
|
||||
// the source revision of the watched branch the pipeline runs for; absent for a run on request
|
||||
// the catalog revision number of the watched branch the pipeline runs on, the indexer's count, which a build module reads a revision by (design 47 H-A-219); absent for a run on request
|
||||
Revision int64 `json:"revision,omitempty"`
|
||||
// the gate's source revision the pipeline's catalog revision was taken in from (design 47 H-A-219); absent for a run on request
|
||||
Source int64 `json:"source,omitempty"`
|
||||
// the pipeline step
|
||||
Step string `json:"step"`
|
||||
Toolchain *ToolchainUsed `json:"toolchain,omitempty"`
|
||||
|
||||
@@ -903,8 +903,10 @@ type StepRun struct {
|
||||
Pipeline string `json:"pipeline"`
|
||||
// the step is asked again by the runner's rerun
|
||||
Rerun bool `json:"rerun,omitempty"`
|
||||
// the source revision of the watched branch the pipeline runs for; absent for a run on request
|
||||
// the catalog revision number of the watched branch the pipeline runs on, the indexer's count, which a build module reads a revision by (design 47 H-A-219); absent for a run on request
|
||||
Revision int64 `json:"revision,omitempty"`
|
||||
// the gate's source revision the pipeline's catalog revision was taken in from (design 47 H-A-219); absent for a run on request
|
||||
Source int64 `json:"source,omitempty"`
|
||||
// the pipeline step
|
||||
Step string `json:"step"`
|
||||
Toolchain *ToolchainUsed `json:"toolchain,omitempty"`
|
||||
|
||||
@@ -903,8 +903,10 @@ type StepRun struct {
|
||||
Pipeline string `json:"pipeline"`
|
||||
// the step is asked again by the runner's rerun
|
||||
Rerun bool `json:"rerun,omitempty"`
|
||||
// the source revision of the watched branch the pipeline runs for; absent for a run on request
|
||||
// the catalog revision number of the watched branch the pipeline runs on, the indexer's count, which a build module reads a revision by (design 47 H-A-219); absent for a run on request
|
||||
Revision int64 `json:"revision,omitempty"`
|
||||
// the gate's source revision the pipeline's catalog revision was taken in from (design 47 H-A-219); absent for a run on request
|
||||
Source int64 `json:"source,omitempty"`
|
||||
// the pipeline step
|
||||
Step string `json:"step"`
|
||||
Toolchain *ToolchainUsed `json:"toolchain,omitempty"`
|
||||
|
||||
@@ -1521,7 +1521,11 @@
|
||||
},
|
||||
"revision": {
|
||||
"type": "integer",
|
||||
"description": "the source revision of the watched branch the pipeline runs for; absent for a run on request"
|
||||
"description": "the catalog revision number of the watched branch the pipeline runs on, the indexer's count, which a build module reads a revision by (design 47 H-A-219); absent for a run on request"
|
||||
},
|
||||
"source": {
|
||||
"type": "integer",
|
||||
"description": "the gate's source revision the pipeline's catalog revision was taken in from (design 47 H-A-219); absent for a run on request"
|
||||
},
|
||||
"fingerprint": {
|
||||
"type": "string",
|
||||
|
||||
@@ -180,6 +180,10 @@
|
||||
"type": "integer",
|
||||
"description": "the source revision of that branch the build was made from"
|
||||
},
|
||||
"revision": {
|
||||
"type": "integer",
|
||||
"description": "the catalog revision number of that branch the build was made from, the indexer's count (design 47 H-A-218, H-A-220); absent from a reservation made before the field"
|
||||
},
|
||||
"dependencies": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
@@ -363,6 +367,13 @@
|
||||
"$ref": "#/defs/BuildEntry"
|
||||
},
|
||||
"description": "each entry the step built, by module and fingerprint"
|
||||
},
|
||||
"packages": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": "the pins the step's entries were built with, each mesh package's version by its module path, the ones the builder took from the registry for a package the entry named with none included; the runner asks the entry's held test steps with them (H-A-207)"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
"revision": 12,
|
||||
"kind": "trunk",
|
||||
"source": 3589,
|
||||
"call": "release of mesh-sdk 0.1.27",
|
||||
"call-kind": "release",
|
||||
"module": "mesh-sdk",
|
||||
"version": "0.1.27",
|
||||
"entries": 2,
|
||||
"changed": [
|
||||
"xclip"
|
||||
|
||||
@@ -209,7 +209,11 @@
|
||||
"repository": "novox/mesh-catalog"
|
||||
}
|
||||
],
|
||||
"base": 9
|
||||
"base": 9,
|
||||
"call": "release of mesh-sdk 0.1.27",
|
||||
"call-kind": "release",
|
||||
"module": "mesh-sdk",
|
||||
"version": "0.1.27"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -657,6 +657,32 @@
|
||||
"source": {
|
||||
"type": "integer"
|
||||
},
|
||||
"call": {
|
||||
"type": "string",
|
||||
"description": "what made the revision, as the revision's call names it (design 47 H-A-212, H-A-213); absent for a candidate's"
|
||||
},
|
||||
"call-kind": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"take-in",
|
||||
"release",
|
||||
"take-in-again",
|
||||
"recompute"
|
||||
],
|
||||
"description": "the kind of what made the revision, which a reader reads instead of call's words (design 47 H-A-213 (3), H-A-214, H-A-215, H-A-217); absent for a candidate's"
|
||||
},
|
||||
"module": {
|
||||
"type": "string",
|
||||
"description": "for call-kind release, the module released (H-A-215)"
|
||||
},
|
||||
"version": {
|
||||
"type": "string",
|
||||
"description": "for call-kind release, the version released (H-A-215)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "string",
|
||||
"description": "for call-kind take-in-again, the repository taken in again (H-A-215)"
|
||||
},
|
||||
"group": {
|
||||
"type": "string"
|
||||
},
|
||||
@@ -1871,6 +1897,32 @@
|
||||
"type": "integer",
|
||||
"description": "the source revision it was taken in from; for a candidate, the source revision its heads are merged onto"
|
||||
},
|
||||
"call": {
|
||||
"type": "string",
|
||||
"description": "what made the revision (design 47 H-A-212, H-A-213): a take-in's the gate's call its source revision names, a re-pin's release of <module> <version>, a take-in again's take-in again of <repository>; absent for a candidate's"
|
||||
},
|
||||
"call-kind": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"take-in",
|
||||
"release",
|
||||
"take-in-again",
|
||||
"recompute"
|
||||
],
|
||||
"description": "the kind of what made the revision, which a reader reads instead of call's words (design 47 H-A-213 (3), H-A-214, H-A-215, H-A-217): a take-in's, a re-pin's on a module's release, a take-in again's, a recompute's that moved a fingerprint (its call naming the reason); absent for a candidate's"
|
||||
},
|
||||
"module": {
|
||||
"type": "string",
|
||||
"description": "for call-kind release, the module released (H-A-215)"
|
||||
},
|
||||
"version": {
|
||||
"type": "string",
|
||||
"description": "for call-kind release, the version released (H-A-215)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "string",
|
||||
"description": "for call-kind take-in-again, the repository taken in again (H-A-215)"
|
||||
},
|
||||
"group": {
|
||||
"type": "string",
|
||||
"description": "a candidate's group"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[
|
||||
{
|
||||
"name": "a take-in's pipeline kept, its steps naming their mover",
|
||||
"of": "state:pipelines/<branch>.<source>",
|
||||
"of": "state:pipelines/<branch>.<revision>",
|
||||
"given": {
|
||||
"pipeline": "main.3589",
|
||||
"branch": "main",
|
||||
@@ -200,7 +200,7 @@
|
||||
},
|
||||
{
|
||||
"name": "a pipeline waiting its turn, its seq given",
|
||||
"of": "state:pipelines/<branch>.<source>",
|
||||
"of": "state:pipelines/<branch>.<revision>",
|
||||
"given": {
|
||||
"pipeline": "main.3590",
|
||||
"branch": "main",
|
||||
@@ -224,7 +224,7 @@
|
||||
},
|
||||
{
|
||||
"name": "a waiting pipeline names the movers a newer take-in took out of it",
|
||||
"of": "state:pipelines/<branch>.<source>",
|
||||
"of": "state:pipelines/<branch>.<revision>",
|
||||
"given": {
|
||||
"pipeline": "main.3590",
|
||||
"branch": "main",
|
||||
|
||||
@@ -672,7 +672,7 @@
|
||||
"events": [
|
||||
{
|
||||
"name": "pipeline-started",
|
||||
"subject": "pipeline-started.<branch>.<source>",
|
||||
"subject": "pipeline-started.<branch>.<revision>",
|
||||
"body": {
|
||||
"$ref": "#/defs/PipelineStarted"
|
||||
},
|
||||
@@ -683,7 +683,7 @@
|
||||
},
|
||||
{
|
||||
"name": "pipeline-ended",
|
||||
"subject": "pipeline-ended.<branch>.<source>",
|
||||
"subject": "pipeline-ended.<branch>.<revision>",
|
||||
"body": {
|
||||
"$ref": "#/defs/PipelineEnded"
|
||||
},
|
||||
@@ -727,7 +727,7 @@
|
||||
},
|
||||
{
|
||||
"name": "wait-held",
|
||||
"subject": "wait-held.<branch>.<source>",
|
||||
"subject": "wait-held.<branch>.<revision>",
|
||||
"body": {
|
||||
"$ref": "#/defs/Wait"
|
||||
},
|
||||
@@ -738,7 +738,7 @@
|
||||
},
|
||||
{
|
||||
"name": "wait-ended",
|
||||
"subject": "wait-ended.<branch>.<source>",
|
||||
"subject": "wait-ended.<branch>.<revision>",
|
||||
"body": {
|
||||
"$ref": "#/defs/Wait"
|
||||
},
|
||||
@@ -778,11 +778,11 @@
|
||||
"description": "one key per pipeline, one per take-in, written by compare-and-set on its absence (design 47 H §746, §747), and one key per mover of a pipeline holding that mover's steps (H-A-187)",
|
||||
"key-forms": [
|
||||
{
|
||||
"key": "<branch>.<source>",
|
||||
"key": "<branch>.<revision>",
|
||||
"value": {
|
||||
"$ref": "#/defs/Pipeline"
|
||||
},
|
||||
"description": "a take-in's pipeline"
|
||||
"description": "a pipeline of one catalog revision, keyed by the revision's number (design 47 H-A-213 (4), H-A-219); one kept from before under its source has the same form"
|
||||
},
|
||||
{
|
||||
"key": "<branch>.<source>.published.<package>.<version>",
|
||||
@@ -1199,7 +1199,7 @@
|
||||
"properties": {
|
||||
"pipeline": {
|
||||
"type": "string",
|
||||
"description": "the pipeline's key, <branch>.<source>, <branch>.<source>.published.<package>.<version> for a pipeline a publish started, or <branch>.run.<run> for a run on request; a branch escaped as a key's name is (design 47 H §746, §747; H-A-83)"
|
||||
"description": "the pipeline's key, <branch>.<revision>, <branch>.<source>.published.<package>.<version> for a pipeline a publish started, or <branch>.run.<run> for a run on request; a branch escaped as a key's name is (design 47 H §746, §747; H-A-83)"
|
||||
},
|
||||
"branch": {
|
||||
"type": "string",
|
||||
@@ -1313,7 +1313,7 @@
|
||||
"properties": {
|
||||
"pipeline": {
|
||||
"type": "string",
|
||||
"description": "the pipeline's key, <branch>.<source>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747)"
|
||||
"description": "the pipeline's key, <branch>.<revision>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747)"
|
||||
},
|
||||
"branch": {
|
||||
"type": "string",
|
||||
@@ -1388,7 +1388,7 @@
|
||||
"properties": {
|
||||
"pipeline": {
|
||||
"type": "string",
|
||||
"description": "the pipeline's key, <branch>.<source>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747)"
|
||||
"description": "the pipeline's key, <branch>.<revision>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747)"
|
||||
},
|
||||
"branch": {
|
||||
"type": "string",
|
||||
@@ -1495,7 +1495,7 @@
|
||||
"properties": {
|
||||
"pipeline": {
|
||||
"type": "string",
|
||||
"description": "the pipeline's key, <branch>.<source>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747)"
|
||||
"description": "the pipeline's key, <branch>.<revision>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747)"
|
||||
},
|
||||
"module": {
|
||||
"type": "string"
|
||||
@@ -1550,7 +1550,7 @@
|
||||
"properties": {
|
||||
"pipeline": {
|
||||
"type": "string",
|
||||
"description": "the pipeline's key, <branch>.<source>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747)"
|
||||
"description": "the pipeline's key, <branch>.<revision>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747)"
|
||||
},
|
||||
"module": {
|
||||
"type": "string",
|
||||
@@ -1635,7 +1635,7 @@
|
||||
"description": "the run the step waits on, where the runner knows it: a test step's run key and ask (design 47 G §731, A-469v)"
|
||||
}
|
||||
},
|
||||
"description": "a step's wait, held and ended; a wait on a person is said as waiting on that person, never a stall (ADR 0283); said on <branch>.<source> (design 47 H-A-72)",
|
||||
"description": "a step's wait, held and ended; a wait on a person is said as waiting on that person, never a stall (ADR 0283); said on <branch>.<revision> (design 47 H-A-72, H-A-221)",
|
||||
"required": [
|
||||
"v",
|
||||
"pipeline",
|
||||
@@ -1978,7 +1978,7 @@
|
||||
"properties": {
|
||||
"pipeline": {
|
||||
"type": "string",
|
||||
"description": "the pipeline's key, <branch>.<source>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747)"
|
||||
"description": "the pipeline's key, <branch>.<revision>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747)"
|
||||
}
|
||||
},
|
||||
"description": "a pipeline waiting its turn under pipelines-at-once (design 47 H §748, H-A-72)",
|
||||
|
||||
@@ -65,12 +65,13 @@
|
||||
{
|
||||
"name": "a pipeline's wants all run",
|
||||
"of": "event:pipeline-wanted",
|
||||
"subject": "mesh.seat.mesh-wants.event.pipeline-wanted.main.3589",
|
||||
"subject": "mesh.seat.mesh-wants.event.pipeline-wanted.main.3590",
|
||||
"given": {
|
||||
"v": 1,
|
||||
"pipeline": "main.3589",
|
||||
"pipeline": "main.3590",
|
||||
"branch": "main",
|
||||
"source": 3589,
|
||||
"revision": 3590,
|
||||
"outcome": "running"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -434,7 +434,7 @@
|
||||
},
|
||||
{
|
||||
"name": "pipeline-wanted",
|
||||
"subject": "pipeline-wanted.<branch>.<source>",
|
||||
"subject": "pipeline-wanted.<branch>.<revision>",
|
||||
"keep": {
|
||||
"max-age-days": 30,
|
||||
"max-mib": 64
|
||||
@@ -1725,7 +1725,7 @@
|
||||
},
|
||||
"pipeline": {
|
||||
"type": "string",
|
||||
"description": "the runner's pipeline key, <branch>.<source>, a branch escaped as a key's name is (design 47 H §746)"
|
||||
"description": "the runner's pipeline key, <branch>.<revision>, a branch escaped as a key's name is (design 47 H §746, H-A-213 (4))"
|
||||
},
|
||||
"branch": {
|
||||
"type": "string"
|
||||
@@ -1733,6 +1733,10 @@
|
||||
"source": {
|
||||
"type": "integer"
|
||||
},
|
||||
"revision": {
|
||||
"type": "integer",
|
||||
"description": "the pipeline's catalog revision number, the number of its key; the indexer frees the pins of that revision, not of another revision of the same source (design 47 H-A-214); absent from an older event"
|
||||
},
|
||||
"outcome": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
|
||||
@@ -69,6 +69,8 @@ export interface PackagePublished {
|
||||
"digest": string;
|
||||
/** the module */
|
||||
"module": string;
|
||||
/** the catalog revision number of that branch the build was made from, the indexer's count (design 47 H-A-218, H-A-220); absent from a reservation made before the field */
|
||||
"revision"?: number;
|
||||
/** the source revision of that branch the build was made from */
|
||||
"source": number;
|
||||
"v": number;
|
||||
@@ -89,6 +91,8 @@ export interface StepEnded {
|
||||
"node": string;
|
||||
/** never passed for a build that built nothing */
|
||||
"outcome": "passed" | "failed" | "nothing to run" | "could not run";
|
||||
/** the pins the step's entries were built with, each mesh package's version by its module path, the ones the builder took from the registry for a package the entry named with none included; the runner asks the entry's held test steps with them (H-A-207) */
|
||||
"packages"?: Record<string, string>;
|
||||
"pipeline": string;
|
||||
"rerun"?: boolean;
|
||||
/** why it failed or could not run: the entry not built, the part not heard */
|
||||
|
||||
@@ -277,6 +277,10 @@ export interface CatalogRevision {
|
||||
"base"?: number;
|
||||
/** the watched branch the revision is of */
|
||||
"branch"?: string;
|
||||
/** what made the revision (design 47 H-A-212, H-A-213): a take-in's the gate's call its source revision names, a re-pin's release of <module> <version>, a take-in again's take-in again of <repository>; absent for a candidate's */
|
||||
"call"?: string;
|
||||
/** the kind of what made the revision, which a reader reads instead of call's words (design 47 H-A-213 (3), H-A-214, H-A-215, H-A-217): a take-in's, a re-pin's on a module's release, a take-in again's, a recompute's that moved a fingerprint (its call naming the reason); absent for a candidate's */
|
||||
"call-kind"?: "take-in" | "release" | "take-in-again" | "recompute";
|
||||
/** the seat definitions it was judged with, each by its digest, read whole through seat-definitions */
|
||||
"definitions"?: CatalogRevisionDefinitionsItem[];
|
||||
/** one per module, by name */
|
||||
@@ -287,8 +291,12 @@ export interface CatalogRevision {
|
||||
"heads"?: string;
|
||||
/** trunk or candidate */
|
||||
"kind": string;
|
||||
/** for call-kind release, the module released (H-A-215) */
|
||||
"module"?: string;
|
||||
/** 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[];
|
||||
/** for call-kind take-in-again, the repository taken in again (H-A-215) */
|
||||
"repository"?: string;
|
||||
/** the catalog graph revision's number, counted by its holder */
|
||||
"revision": number;
|
||||
/** the source revision it was taken in from; for a candidate, the source revision its heads are merged onto */
|
||||
@@ -297,6 +305,8 @@ export interface CatalogRevision {
|
||||
"trunk"?: Head[];
|
||||
/** the layout version */
|
||||
"v"?: number;
|
||||
/** for call-kind release, the version released (H-A-215) */
|
||||
"version"?: string;
|
||||
}
|
||||
|
||||
/** one edge of the catalog graph between artifact references, B before A (ADR 0666 section 14): kind 1 B published before A builds (a package A imports), 2 B published before A delivers (fetched by reference at its start), 3 B delivered before A builds (its build module and toolchain), 4 B delivered before A delivers (a provision, bus state, a format's reader), 5 B has acted for A's new version (an acting rule), 6 B runs a version that serves A (a verb or a manifest word A uses) */
|
||||
@@ -796,6 +806,10 @@ export interface CatalogRevisionEvent {
|
||||
"at"?: string;
|
||||
/** the watched branch the revision is of, escaped as a key name is */
|
||||
"branch"?: string;
|
||||
/** what made the revision, as the revision's call names it (design 47 H-A-212, H-A-213); absent for a candidate's */
|
||||
"call"?: string;
|
||||
/** the kind of what made the revision, which a reader reads instead of call's words (design 47 H-A-213 (3), H-A-214, H-A-215, H-A-217); absent for a candidate's */
|
||||
"call-kind"?: "take-in" | "release" | "take-in-again" | "recompute";
|
||||
/** the modules whose entries differ from the revision before it of the same kind */
|
||||
"changed"?: string[];
|
||||
/** how many entries it lists */
|
||||
@@ -804,9 +818,15 @@ export interface CatalogRevisionEvent {
|
||||
"heads"?: string;
|
||||
/** trunk or candidate: a candidate's moves no running part */
|
||||
"kind": string;
|
||||
/** for call-kind release, the module released (H-A-215) */
|
||||
"module"?: string;
|
||||
/** for call-kind take-in-again, the repository taken in again (H-A-215) */
|
||||
"repository"?: string;
|
||||
"revision": number;
|
||||
"source": number;
|
||||
"v": number;
|
||||
/** for call-kind release, the version released (H-A-215) */
|
||||
"version"?: string;
|
||||
}
|
||||
|
||||
/** is the body of the event filling. */
|
||||
|
||||
@@ -40,13 +40,13 @@ export declare const family: { readonly name: "mesh-pipeline-runner.events"; rea
|
||||
|
||||
export declare const pipelineStartedStream: "SEAT_mesh-pipeline-runner_pipeline-started";
|
||||
|
||||
export declare function pipelineStartedSubject(branch: string, source: string): string;
|
||||
export declare function pipelineStartedSubject(branch: string, revision: string): string;
|
||||
|
||||
export declare const pipelineStartedSubjectAll: "mesh.seat.mesh-pipeline-runner.event.pipeline-started.*.*";
|
||||
|
||||
export declare const pipelineEndedStream: "SEAT_mesh-pipeline-runner_pipeline-ended";
|
||||
|
||||
export declare function pipelineEndedSubject(branch: string, source: string): string;
|
||||
export declare function pipelineEndedSubject(branch: string, revision: string): string;
|
||||
|
||||
export declare const pipelineEndedSubjectAll: "mesh.seat.mesh-pipeline-runner.event.pipeline-ended.*.*";
|
||||
|
||||
@@ -70,13 +70,13 @@ export declare const stepEndedSubjectAll: "mesh.seat.mesh-pipeline-runner.event.
|
||||
|
||||
export declare const waitHeldStream: "SEAT_mesh-pipeline-runner_wait-held";
|
||||
|
||||
export declare function waitHeldSubject(branch: string, source: string): string;
|
||||
export declare function waitHeldSubject(branch: string, revision: string): string;
|
||||
|
||||
export declare const waitHeldSubjectAll: "mesh.seat.mesh-pipeline-runner.event.wait-held.*.*";
|
||||
|
||||
export declare const waitEndedStream: "SEAT_mesh-pipeline-runner_wait-ended";
|
||||
|
||||
export declare function waitEndedSubject(branch: string, source: string): string;
|
||||
export declare function waitEndedSubject(branch: string, revision: string): string;
|
||||
|
||||
export declare const waitEndedSubjectAll: "mesh.seat.mesh-pipeline-runner.event.wait-ended.*.*";
|
||||
|
||||
@@ -94,11 +94,11 @@ export declare const states: {
|
||||
readonly stepOutputs: "step-outputs";
|
||||
};
|
||||
|
||||
/** The key of one value of the state pipelines under the form "<branch>.<source>". */
|
||||
export declare function pipelinesByBranchSourceKey(branch: string, source: string): string;
|
||||
/** The key of one value of the state pipelines under the form "<branch>.<revision>". */
|
||||
export declare function pipelinesByBranchRevisionKey(branch: string, revision: string): string;
|
||||
|
||||
/** The parts of a key of the form "<branch>.<source>", or undefined for a key of another form. */
|
||||
export declare function parsePipelinesByBranchSourceKey(_key: string): { branch: string; source: string } | undefined;
|
||||
/** The parts of a key of the form "<branch>.<revision>", or undefined for a key of another form. */
|
||||
export declare function parsePipelinesByBranchRevisionKey(_key: string): { branch: string; revision: string } | undefined;
|
||||
|
||||
/** The key of one value of the state pipelines under the form "<branch>.<source>.published.<package>.<version>". */
|
||||
export declare function pipelinesByBranchSourcePublishedPackageVersionKey(branch: string, source: string, packagePart: string, version: string): string;
|
||||
@@ -261,7 +261,7 @@ export interface Pipeline {
|
||||
/** the modules the pipeline moves, its take-in's entries (design 47 H §746) */
|
||||
"movers": Mover[];
|
||||
"outcome": "waiting" | "running" | "passed" | "failed" | "refused" | "superseded" | "cancelled";
|
||||
/** the pipeline's key, <branch>.<source>, <branch>.<source>.published.<package>.<version> for a pipeline a publish started, or <branch>.run.<run> for a run on request; a branch escaped as a key's name is (design 47 H §746, §747; H-A-83) */
|
||||
/** the pipeline's key, <branch>.<revision>, <branch>.<source>.published.<package>.<version> for a pipeline a publish started, or <branch>.run.<run> for a run on request; a branch escaped as a key's name is (design 47 H §746, §747; H-A-83) */
|
||||
"pipeline": string;
|
||||
/** for a pipeline a package's publish started, that publish (A-202) */
|
||||
"published"?: Published;
|
||||
@@ -300,7 +300,7 @@ export interface PipelineEnded {
|
||||
/** per mover its fingerprint, released version, step results and tier, in the delivery order (design 47 H §746, H-A-2) */
|
||||
"movers": MoverEnded[];
|
||||
"outcome": "waiting" | "running" | "passed" | "failed" | "refused" | "superseded" | "cancelled";
|
||||
/** the pipeline's key, <branch>.<source>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747) */
|
||||
/** the pipeline's key, <branch>.<revision>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747) */
|
||||
"pipeline": string;
|
||||
/** the catalog graph revision of the branch the pipeline runs for */
|
||||
"revision"?: number;
|
||||
@@ -322,7 +322,7 @@ export interface PipelineStarted {
|
||||
"call"?: string;
|
||||
/** the pipeline's movers */
|
||||
"movers": Mover[];
|
||||
/** the pipeline's key, <branch>.<source>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747) */
|
||||
/** the pipeline's key, <branch>.<revision>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747) */
|
||||
"pipeline": string;
|
||||
/** for a pipeline a package's publish started, that publish (A-202) */
|
||||
"published"?: Published;
|
||||
@@ -383,7 +383,7 @@ export interface StepEvent {
|
||||
/** the module's build-input fingerprint at the commit */
|
||||
"fingerprint"?: string;
|
||||
"module": string;
|
||||
/** the pipeline's key, <branch>.<source>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747) */
|
||||
/** the pipeline's key, <branch>.<revision>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747) */
|
||||
"pipeline": string;
|
||||
"result": StepResult;
|
||||
/** the catalog graph revision of the branch the pipeline runs for */
|
||||
@@ -490,7 +490,7 @@ export interface ToolchainUsed {
|
||||
"version": string;
|
||||
}
|
||||
|
||||
/** a step's wait, held and ended; a wait on a person is said as waiting on that person, never a stall (ADR 0283); said on <branch>.<source> (design 47 H-A-72) */
|
||||
/** a step's wait, held and ended; a wait on a person is said as waiting on that person, never a stall (ADR 0283); said on <branch>.<revision> (design 47 H-A-72, H-A-221) */
|
||||
export interface Wait {
|
||||
"artifact"?: string;
|
||||
/** the step's own ask, where it has one (design 47 G §731) */
|
||||
@@ -507,7 +507,7 @@ export interface Wait {
|
||||
"module"?: string;
|
||||
/** what the step waits on (design 47 *Health and going back*) */
|
||||
"on": "person" | "build node" | "revision view" | "pipelines-at-once";
|
||||
/** the pipeline's key, <branch>.<source>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747) */
|
||||
/** the pipeline's key, <branch>.<revision>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747) */
|
||||
"pipeline": string;
|
||||
/** the catalog graph revision of the branch the pipeline runs for */
|
||||
"revision"?: number;
|
||||
@@ -527,7 +527,7 @@ export interface Wait {
|
||||
|
||||
/** a pipeline waiting its turn under pipelines-at-once (design 47 H §748, H-A-72) */
|
||||
export interface Waiting {
|
||||
/** the pipeline's key, <branch>.<source>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747) */
|
||||
/** the pipeline's key, <branch>.<revision>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747) */
|
||||
"pipeline": string;
|
||||
}
|
||||
|
||||
@@ -800,8 +800,8 @@ export type FullEvent = Fill;
|
||||
/** is the body of the event room. */
|
||||
export type RoomEvent = Fill;
|
||||
|
||||
/** is one value of the state pipelines under the key <branch>.<source>. */
|
||||
export type PipelinesByBranchSourceValue = Pipeline;
|
||||
/** is one value of the state pipelines under the key <branch>.<revision>. */
|
||||
export type PipelinesByBranchRevisionValue = Pipeline;
|
||||
|
||||
/** is one value of the state pipelines under the key <branch>.<source>.published.<package>.<version>. */
|
||||
export type PipelinesByBranchSourcePublishedPackageVersionValue = Pipeline;
|
||||
|
||||
@@ -40,16 +40,16 @@ export const family = { name: "mesh-pipeline-runner.events", maxAgeDays: 7 };
|
||||
|
||||
export const pipelineStartedStream = "SEAT_mesh-pipeline-runner_pipeline-started";
|
||||
|
||||
export function pipelineStartedSubject(branch, source) {
|
||||
return "mesh.seat.mesh-pipeline-runner.event.pipeline-started." + branch + "." + source;
|
||||
export function pipelineStartedSubject(branch, revision) {
|
||||
return "mesh.seat.mesh-pipeline-runner.event.pipeline-started." + branch + "." + revision;
|
||||
}
|
||||
|
||||
export const pipelineStartedSubjectAll = "mesh.seat.mesh-pipeline-runner.event.pipeline-started.*.*";
|
||||
|
||||
export const pipelineEndedStream = "SEAT_mesh-pipeline-runner_pipeline-ended";
|
||||
|
||||
export function pipelineEndedSubject(branch, source) {
|
||||
return "mesh.seat.mesh-pipeline-runner.event.pipeline-ended." + branch + "." + source;
|
||||
export function pipelineEndedSubject(branch, revision) {
|
||||
return "mesh.seat.mesh-pipeline-runner.event.pipeline-ended." + branch + "." + revision;
|
||||
}
|
||||
|
||||
export const pipelineEndedSubjectAll = "mesh.seat.mesh-pipeline-runner.event.pipeline-ended.*.*";
|
||||
@@ -80,16 +80,16 @@ export const stepEndedSubjectAll = "mesh.seat.mesh-pipeline-runner.event.step-en
|
||||
|
||||
export const waitHeldStream = "SEAT_mesh-pipeline-runner_wait-held";
|
||||
|
||||
export function waitHeldSubject(branch, source) {
|
||||
return "mesh.seat.mesh-pipeline-runner.event.wait-held." + branch + "." + source;
|
||||
export function waitHeldSubject(branch, revision) {
|
||||
return "mesh.seat.mesh-pipeline-runner.event.wait-held." + branch + "." + revision;
|
||||
}
|
||||
|
||||
export const waitHeldSubjectAll = "mesh.seat.mesh-pipeline-runner.event.wait-held.*.*";
|
||||
|
||||
export const waitEndedStream = "SEAT_mesh-pipeline-runner_wait-ended";
|
||||
|
||||
export function waitEndedSubject(branch, source) {
|
||||
return "mesh.seat.mesh-pipeline-runner.event.wait-ended." + branch + "." + source;
|
||||
export function waitEndedSubject(branch, revision) {
|
||||
return "mesh.seat.mesh-pipeline-runner.event.wait-ended." + branch + "." + revision;
|
||||
}
|
||||
|
||||
export const waitEndedSubjectAll = "mesh.seat.mesh-pipeline-runner.event.wait-ended.*.*";
|
||||
@@ -108,23 +108,23 @@ export const states = {
|
||||
stepOutputs: "step-outputs",
|
||||
};
|
||||
|
||||
/** The key of one value of the state pipelines under the form "<branch>.<source>". */
|
||||
export function pipelinesByBranchSourceKey(branch, source) {
|
||||
return branch + "." + source;
|
||||
/** The key of one value of the state pipelines under the form "<branch>.<revision>". */
|
||||
export function pipelinesByBranchRevisionKey(branch, revision) {
|
||||
return branch + "." + revision;
|
||||
}
|
||||
|
||||
/** The parts of a key of the form "<branch>.<source>", or undefined for a key of another form. */
|
||||
export function parsePipelinesByBranchSourceKey(_key) {
|
||||
/** The parts of a key of the form "<branch>.<revision>", or undefined for a key of another form. */
|
||||
export function parsePipelinesByBranchRevisionKey(_key) {
|
||||
let _rest = _key;
|
||||
const _at0 = _rest.indexOf(".");
|
||||
if (_at0 <= 0) return undefined;
|
||||
const branch = _rest.slice(0, _at0);
|
||||
_rest = _rest.slice(_at0 + 1);
|
||||
if (_rest === "") return undefined;
|
||||
const source = _rest;
|
||||
const revision = _rest;
|
||||
_rest = "";
|
||||
if (_rest !== "") return undefined;
|
||||
return { branch, source };
|
||||
return { branch, revision };
|
||||
}
|
||||
|
||||
/** The key of one value of the state pipelines under the form "<branch>.<source>.published.<package>.<version>". */
|
||||
|
||||
@@ -50,7 +50,7 @@ export declare const wantedSubjectAll: "mesh.seat.mesh-wants.event.wanted.*.*";
|
||||
|
||||
export declare const pipelineWantedStream: "SEAT_mesh-wants_pipeline-wanted";
|
||||
|
||||
export declare function pipelineWantedSubject(branch: string, source: string): string;
|
||||
export declare function pipelineWantedSubject(branch: string, revision: string): string;
|
||||
|
||||
export declare const pipelineWantedSubjectAll: "mesh.seat.mesh-wants.event.pipeline-wanted.*.*";
|
||||
|
||||
@@ -412,8 +412,10 @@ export interface PipelineWanted {
|
||||
/** for tier-late, the late tier's movers not running and the machines they do not run on */
|
||||
"not-running"?: NotRunning[];
|
||||
"outcome": "running" | "tier-late";
|
||||
/** the runner's pipeline key, <branch>.<source>, a branch escaped as a key's name is (design 47 H §746) */
|
||||
/** the runner's pipeline key, <branch>.<revision>, a branch escaped as a key's name is (design 47 H §746, H-A-213 (4)) */
|
||||
"pipeline": string;
|
||||
/** the pipeline's catalog revision number, the number of its key; the indexer frees the pins of that revision, not of another revision of the same source (design 47 H-A-214); absent from an older event */
|
||||
"revision"?: number;
|
||||
"source": number;
|
||||
"v": number;
|
||||
}
|
||||
|
||||
@@ -52,8 +52,8 @@ export const wantedSubjectAll = "mesh.seat.mesh-wants.event.wanted.*.*";
|
||||
|
||||
export const pipelineWantedStream = "SEAT_mesh-wants_pipeline-wanted";
|
||||
|
||||
export function pipelineWantedSubject(branch, source) {
|
||||
return "mesh.seat.mesh-wants.event.pipeline-wanted." + branch + "." + source;
|
||||
export function pipelineWantedSubject(branch, revision) {
|
||||
return "mesh.seat.mesh-wants.event.pipeline-wanted." + branch + "." + revision;
|
||||
}
|
||||
|
||||
export const pipelineWantedSubjectAll = "mesh.seat.mesh-wants.event.pipeline-wanted.*.*";
|
||||
|
||||
@@ -510,8 +510,10 @@ export interface StepRun {
|
||||
"pipeline": string;
|
||||
/** the step is asked again by the runner's rerun */
|
||||
"rerun"?: boolean;
|
||||
/** the source revision of the watched branch the pipeline runs for; absent for a run on request */
|
||||
/** the catalog revision number of the watched branch the pipeline runs on, the indexer's count, which a build module reads a revision by (design 47 H-A-219); absent for a run on request */
|
||||
"revision"?: number;
|
||||
/** the gate's source revision the pipeline's catalog revision was taken in from (design 47 H-A-219); absent for a run on request */
|
||||
"source"?: number;
|
||||
/** the pipeline step */
|
||||
"step": "lint" | "unit" | "integration";
|
||||
"toolchain"?: ToolchainUsed;
|
||||
|
||||
+3
-1
@@ -510,8 +510,10 @@ export interface StepRun {
|
||||
"pipeline": string;
|
||||
/** the step is asked again by the runner's rerun */
|
||||
"rerun"?: boolean;
|
||||
/** the source revision of the watched branch the pipeline runs for; absent for a run on request */
|
||||
/** the catalog revision number of the watched branch the pipeline runs on, the indexer's count, which a build module reads a revision by (design 47 H-A-219); absent for a run on request */
|
||||
"revision"?: number;
|
||||
/** the gate's source revision the pipeline's catalog revision was taken in from (design 47 H-A-219); absent for a run on request */
|
||||
"source"?: number;
|
||||
/** the pipeline step */
|
||||
"step": "lint" | "unit" | "integration";
|
||||
"toolchain"?: ToolchainUsed;
|
||||
|
||||
+3
-1
@@ -510,8 +510,10 @@ export interface StepRun {
|
||||
"pipeline": string;
|
||||
/** the step is asked again by the runner's rerun */
|
||||
"rerun"?: boolean;
|
||||
/** the source revision of the watched branch the pipeline runs for; absent for a run on request */
|
||||
/** the catalog revision number of the watched branch the pipeline runs on, the indexer's count, which a build module reads a revision by (design 47 H-A-219); absent for a run on request */
|
||||
"revision"?: number;
|
||||
/** the gate's source revision the pipeline's catalog revision was taken in from (design 47 H-A-219); absent for a run on request */
|
||||
"source"?: number;
|
||||
/** the pipeline step */
|
||||
"step": "lint" | "unit" | "integration";
|
||||
"toolchain"?: ToolchainUsed;
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
|
||||
"mesh-delivery-indexer/internal/index"
|
||||
)
|
||||
|
||||
// entryAnswer is what indexer_entry answers: the trunk revision read, the entry's packages (the pins: each other-repository
|
||||
// package with the version it builds against, empty while none is published), its named paths by artifact, its fingerprint
|
||||
// and its manifest's digest.
|
||||
type entryAnswer struct {
|
||||
Module string `json:"module"`
|
||||
Revision int64 `json:"revision"`
|
||||
Packages map[string]string `json:"packages"`
|
||||
Paths map[string][]string `json:"paths"`
|
||||
Fp string `json:"fp,omitempty"`
|
||||
ManifestDigest string `json:"manifest-digest,omitempty"`
|
||||
}
|
||||
|
||||
// entryReadTool is indexer_entry (H-A-204; tools-are-how-a-module-is-spoken-to) over the indexer's catalog-revisions objects:
|
||||
// one module's entry pins and paths at a trunk revision, small, so a pin can be read without the revision whole (1.3 MB,
|
||||
// more than the bus carries).
|
||||
func entryReadTool(o index.Objects) stdio.Tool {
|
||||
return stdio.Tool{Name: index.EntryPinsTool,
|
||||
Description: "Read one module's catalog graph entry pins: the packages it builds against with the version each is pinned to " +
|
||||
"(an empty version while none is published), the paths each artifact is built from, its fingerprint and its manifest " +
|
||||
"digest, at the newest trunk revision or at a trunk revision given; a small answer, for when the revision whole is too " +
|
||||
"large for the bus (H-A-204).",
|
||||
Input: map[string]any{"type": "object", "required": []string{"module"}, "properties": map[string]any{
|
||||
"module": map[string]any{"type": "string", "description": "the module whose entry is read"},
|
||||
"revision": map[string]any{"type": "integer", "description": "the trunk revision; none reads the newest"}}},
|
||||
Run: func(args map[string]any) (any, error) {
|
||||
module, _ := args["module"].(string)
|
||||
module = strings.TrimSpace(module)
|
||||
if module == "" {
|
||||
return nil, fmt.Errorf("%s names the module", index.EntryPinsTool)
|
||||
}
|
||||
revision, err := revisionArg(args["revision"])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rev, e, err := index.TrunkEntryAt(context.Background(), o, module, revision)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := entryAnswer{Module: e.Module, Revision: rev.Revision, Packages: e.Packages, Paths: map[string][]string{},
|
||||
Fp: e.Fp, ManifestDigest: e.ManifestDigest}
|
||||
if out.Packages == nil {
|
||||
out.Packages = map[string]string{}
|
||||
}
|
||||
if e.Inputs != nil && e.Inputs.Paths != nil {
|
||||
out.Paths = e.Inputs.Paths
|
||||
}
|
||||
return out, nil
|
||||
}}
|
||||
}
|
||||
|
||||
// revisionArg is the revision argument as a number: absent is 0 (the newest); a number or its digits as a string.
|
||||
func revisionArg(v any) (int64, error) {
|
||||
switch r := v.(type) {
|
||||
case nil:
|
||||
return 0, nil
|
||||
case float64:
|
||||
if r < 0 || r != float64(int64(r)) {
|
||||
return 0, fmt.Errorf("revision %v is not a trunk revision's number", r)
|
||||
}
|
||||
return int64(r), nil
|
||||
case string:
|
||||
if strings.TrimSpace(r) == "" {
|
||||
return 0, nil
|
||||
}
|
||||
n, err := strconv.ParseInt(strings.TrimSpace(r), 10, 64)
|
||||
if err != nil || n < 0 {
|
||||
return 0, fmt.Errorf("revision %q is not a trunk revision's number", r)
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
return 0, fmt.Errorf("revision %v is not a trunk revision's number", v)
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
|
||||
"mesh-delivery-indexer/internal/index"
|
||||
)
|
||||
|
||||
// memObjects is catalog-revisions in memory.
|
||||
type memObjects map[string][]byte
|
||||
|
||||
func (m memObjects) Put(_ context.Context, name string, data []byte) error {
|
||||
m[name] = data
|
||||
return nil
|
||||
}
|
||||
func (m memObjects) Get(_ context.Context, name string) ([]byte, error) {
|
||||
d, ok := m[name]
|
||||
if !ok {
|
||||
return nil, index.ErrNoObject
|
||||
}
|
||||
return d, nil
|
||||
}
|
||||
func (m memObjects) Delete(_ context.Context, name string) error { delete(m, name); return nil }
|
||||
func (m memObjects) Names(context.Context) ([]string, error) {
|
||||
var out []string
|
||||
for n := range m {
|
||||
out = append(out, n)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func (memObjects) Fill(context.Context) (int64, int64, error) { return 0, 0, nil }
|
||||
|
||||
// TestEntryTool: indexer_entry answers one entry's pins, paths, fingerprint and manifest digest, small, at the newest trunk
|
||||
// revision and at a given one read from its kept object; an unknown module or revision is an error (H-A-204).
|
||||
func TestEntryTool(t *testing.T) {
|
||||
o := memObjects{}
|
||||
keep := func(revision int64, entries ...meshcatalog.CatalogEntry) {
|
||||
rev := meshcatalog.CatalogRevision{Branch: index.TrunkBranch, Revision: revision}
|
||||
for _, e := range entries {
|
||||
e.Manifest = map[string]any{"module": e.Module, "big": strings.Repeat("x", 64<<10)} // the manifest whole is never answered
|
||||
data, _ := json.Marshal(e)
|
||||
digest := e.Module + "-" + e.Fp
|
||||
o[index.EntryObject(digest)] = data
|
||||
rev.Entries = append(rev.Entries, meshcatalog.EntryRef{Module: e.Module, Digest: digest})
|
||||
}
|
||||
data, _ := json.Marshal(rev)
|
||||
o[index.BranchObject(index.TrunkBranch, revision)] = data
|
||||
}
|
||||
paths := &meshcatalog.EntryInputs{Paths: map[string][]string{"mesh-grants:program": {"modules/mesh-grants", "sdk"}}}
|
||||
keep(7, meshcatalog.CatalogEntry{Module: "mesh-grants", Fp: "src2:old", ManifestDigest: "sha256:a", Inputs: paths,
|
||||
Packages: map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.26"}}, meshcatalog.CatalogEntry{Module: "other", Fp: "src2:o"})
|
||||
keep(9, meshcatalog.CatalogEntry{Module: "mesh-grants", Fp: "src2:new", ManifestDigest: "sha256:b", Inputs: paths,
|
||||
Packages: map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.27", "busgrants": ""}})
|
||||
tool := entryReadTool(o)
|
||||
if tool.Name != "indexer_entry" {
|
||||
t.Fatalf("name %s", tool.Name)
|
||||
}
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
args map[string]any
|
||||
want entryAnswer
|
||||
err string
|
||||
}{
|
||||
{"newest", map[string]any{"module": "mesh-grants"}, entryAnswer{Module: "mesh-grants", Revision: 9, Fp: "src2:new", ManifestDigest: "sha256:b",
|
||||
Packages: map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.27", "busgrants": ""}, Paths: paths.Paths}, ""},
|
||||
{"given", map[string]any{"module": "mesh-grants", "revision": float64(7)}, entryAnswer{Module: "mesh-grants", Revision: 7, Fp: "src2:old", ManifestDigest: "sha256:a",
|
||||
Packages: map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.26"}, Paths: paths.Paths}, ""},
|
||||
{"given as digits, no paths", map[string]any{"module": "other", "revision": "7"}, entryAnswer{Module: "other", Revision: 7, Fp: "src2:o",
|
||||
Packages: map[string]string{}, Paths: map[string][]string{}}, ""},
|
||||
{"not in the newest", map[string]any{"module": "other"}, entryAnswer{}, "holds no module other"},
|
||||
{"revision not kept", map[string]any{"module": "mesh-grants", "revision": float64(8)}, entryAnswer{}, "revision 8 is not kept"},
|
||||
{"no module", map[string]any{}, entryAnswer{}, "names the module"},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
got, err := tool.Run(c.args)
|
||||
if c.err != "" {
|
||||
if err == nil || !strings.Contains(err.Error(), c.err) {
|
||||
t.Fatalf("error %v, want %q", err, c.err)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(got, c.want) {
|
||||
t.Fatalf("answer %+v, want %+v", got, c.want)
|
||||
}
|
||||
data, _ := json.Marshal(got)
|
||||
if len(data) >= 8<<10 {
|
||||
t.Fatalf("answer of %d bytes, want under 8 KB", len(data))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -193,7 +193,7 @@ func main() {
|
||||
tools = append(tools, catalogTools(trunk.State, kept, watched)...)
|
||||
// The seat mesh-catalog's verb revision, a first view of the catalog half answered in this runtime of its own to exactly
|
||||
// the parts whose entry declares it (novox/hq ADR 0663).
|
||||
tools = append(tools, index.RevisionTool(revisions, kept), index.EntryTool(revisions, keptRead{stdio.State(index.EntryIndexState)}), index.EntriesTool(revisions, keptRead{stdio.State(index.EntryIndexState)}, keptRead{stdio.State(index.NamedState)}), index.VersionsTool(keptRead{stdio.State(index.VersionsState)}),
|
||||
tools = append(tools, index.RevisionTool(revisions, kept), index.EntryTool(revisions, keptRead{stdio.State(index.EntryIndexState)}), index.EntriesTool(revisions, keptRead{stdio.State(index.EntryIndexState)}, keptRead{stdio.State(index.NamedState)}), entryReadTool(revisions), index.VersionsTool(keptRead{stdio.State(index.VersionsState)}),
|
||||
index.OutdatedTool(&index.Indexer{Versions: keptRead{stdio.State(index.VersionsState)}, Heard: keptRead{stdio.State(index.HeardState)}, Revisions: revisions}),
|
||||
index.InputsReadTool(keptRead{stdio.State(index.InputsState)}, stateobjects.ForState(index.InputsState).Objects))
|
||||
tools = append(tools, index.CatalogRevisionTools(revisions, asks, time.Now, func(what, why string) error {
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
"time"
|
||||
@@ -289,7 +290,9 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
// The indexer's findings are the seat mesh-conditions' generated finding, written through mesh-sdk's held finding writer
|
||||
// (design 47 G §689, A-29): it holds what is written before the state is bound, and starts once the state is.
|
||||
writer, err := views.NewHeldWriter(views.WriterConfig[mcseat.Finding, mcseat.FindingCleared, mcseat.FindingsStated, mcseat.FindingsAskedEvent]{
|
||||
Module: cred.Module, State: calls.State(index.FindingsState), Node: cred.Node, Asked: mcseat.SubjectFindingsAsked, JS: js, Conn: conn, Logf: logger.Printf})
|
||||
Module: cred.Module, State: calls.State(index.FindingsState), Node: cred.Node, Asked: mcseat.SubjectFindingsAsked, JS: js, Conn: conn, Logf: logger.Printf,
|
||||
// its own kinds only (G §580, H-A-242, H-A-247): the tool runner's writer states its kinds over the same state
|
||||
Kinds: index.FindingKinds, Retired: index.RetiredFindingKinds})
|
||||
if err != nil {
|
||||
return fmt.Errorf("the indexer's finding writer cannot be made: %w", err)
|
||||
}
|
||||
@@ -378,7 +381,16 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
logger.Printf("start: %s", name)
|
||||
return func() { logger.Printf("start: %s done in %s", name, time.Since(began).Round(time.Millisecond)) }
|
||||
}
|
||||
done := step("reading the build log")
|
||||
// A module of the current trunk graph with no registration is registered once at the start, as a kept trunk revision
|
||||
// registers one entering the graph (design 47 H H-A-262, H-A-264 (1)); said loudly, whatever it answers.
|
||||
done := step("registering the trunk graph's modules that have no registration")
|
||||
if written, err := ix.RegisterTrunkGraph(ctx); err != nil {
|
||||
logger.Printf("start: the trunk graph's modules with no registration are not all registered (%d were): %v", len(written), err)
|
||||
} else {
|
||||
logger.Printf("start: %d modules of the trunk graph had no registration and are registered now: %s", len(written), strings.Join(written, ", "))
|
||||
}
|
||||
done()
|
||||
done = step("reading the build log")
|
||||
// The log's entries at the start are read before any fingerprint is computed (below).
|
||||
var started atomic.Bool
|
||||
var startEnds []stdio.LogEntry // the log's entries read at the start, whose imports are kept once the packages are published
|
||||
@@ -433,7 +445,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
done()
|
||||
done = step("following the assignments")
|
||||
followAssignments(ctx, reader, seatHolders.holders(), process.AwaitBucket(ctx, js, conn, index.Bucket(cred.Module, views.StatusState), "indexer_first_views reads nothing and indexer_first_view_again is not heard", logger.Printf), cred, js, gate, func(ctx context.Context) {
|
||||
if err := ix.Recompute(ctx); err != nil {
|
||||
if err := ix.RecomputeKept(ctx, "the assignments of a build module"); err != nil {
|
||||
logger.Printf("writing the modules again after the assignments of a build module changed: %v", err)
|
||||
}
|
||||
}, logger.Printf)
|
||||
@@ -449,7 +461,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
// the toolchain.
|
||||
return ix.ToolchainReported(ctx)
|
||||
},
|
||||
recompute: ix.Recompute}, func() []string { return buildModuleNames(ix.BuildModules()) }, logger)
|
||||
recompute: func(ctx context.Context) error { return ix.RecomputeKept(ctx, "the toolchains read") }}, func() []string { return buildModuleNames(ix.BuildModules()) }, logger)
|
||||
if err := tools.start(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path"
|
||||
"slices"
|
||||
@@ -115,10 +116,15 @@ func trunkVia(call toolCaller) func(ctx context.Context, repository, sha string)
|
||||
}
|
||||
|
||||
// filesVia asks the forge for every blob under each directory at a commit (the seat git's trees with files, ADR 0593 §2),
|
||||
// by directory, then path relative to it. An answer that lists no directory asked is an error naming it.
|
||||
// by directory, then path relative to it. An answer that lists no directory asked is an error naming it. The seat answers
|
||||
// a directory the commit does not hold with the kind not-found naming it (the contract's files field; design 47 H H-A-232):
|
||||
// that is a failure of the tree too (index.ErrNotInTree), so the indexer reads each directory alone and leaves the gone one out.
|
||||
func filesVia(call toolCaller) func(ctx context.Context, repository, sha string, dirs []string) (map[string]map[string]string, error) {
|
||||
return func(_ context.Context, repository, sha string, dirs []string) (map[string]map[string]string, error) {
|
||||
a, err := treesOf(call, repository, git.TreesInput{Commit: sha, Files: dirs})
|
||||
if errors.Is(err, index.ErrNotFound) {
|
||||
return nil, fmt.Errorf("%w: %w", err, index.ErrNotInTree)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -75,6 +75,20 @@ func TestTheTrunkIsTheDirectoriesTheForgeListsTrees(t *testing.T) { // 1900/AC3
|
||||
if _, err := filesVia(noDir)(context.Background(), "novox/mesh-sdk", strings.Repeat("a", 40), []string{"go"}); !errors.Is(err, index.ErrNotInTree) {
|
||||
t.Errorf("a missing directory: %v, want ErrNotInTree", err)
|
||||
}
|
||||
// H-A-232 (2): the seat's not-found naming a directory the commit lacks is a failure of the tree too, so the
|
||||
// one-directory fallback runs; a failed listing of another kind is not.
|
||||
gone := func(string, any) (json.RawMessage, error) {
|
||||
return json.RawMessage(`{"error":"the directory modules/mesh-build-go/buildstep is not in novox/mesh-catalog at x","error-kind":"not-found"}`), nil
|
||||
}
|
||||
if _, err := filesVia(gone)(context.Background(), "novox/mesh-catalog", strings.Repeat("a", 40), []string{"modules/mesh-build-go/buildstep"}); !errors.Is(err, index.ErrNotInTree) {
|
||||
t.Errorf("a directory the seat says not-found: %v, want ErrNotInTree", err)
|
||||
}
|
||||
failed := func(string, any) (json.RawMessage, error) {
|
||||
return json.RawMessage(`{"error":"the forge did not answer","error-kind":"failed"}`), nil
|
||||
}
|
||||
if _, err := filesVia(failed)(context.Background(), "novox/mesh-catalog", strings.Repeat("a", 40), []string{"modules/a"}); err == nil || errors.Is(err, index.ErrNotInTree) {
|
||||
t.Errorf("a listing that failed: %v, want an error that is not ErrNotInTree", err)
|
||||
}
|
||||
down := func(string, any) (json.RawMessage, error) { return nil, errors.New("down") }
|
||||
if _, err := filesVia(down)(context.Background(), "novox/mesh-sdk", strings.Repeat("a", 40), []string{"go"}); err == nil || errors.Is(err, index.ErrNotInTree) {
|
||||
t.Errorf("a failed call: %v, want an error that is not ErrNotInTree", err)
|
||||
@@ -90,7 +104,7 @@ func TestTheTrunkIsTheDirectoriesTheForgeListsTrees(t *testing.T) { // 1900/AC3
|
||||
}{
|
||||
{name: "a run started", body: `{"v":1,"run":"7","members":[{"module":"a","commit":"c"}],"by":"s"}`, acked: 1, started: "7"},
|
||||
{name: "a run's pipeline ended", body: `{"v":1,"pipeline":"p","module":"a","branch":"b","commit":"c","outcome":"passed","steps":[],"run":"7"}`, ended: true, acked: 1, endedOf: "7"},
|
||||
{name: "a pipeline's wants written to the end", body: `{"v":1,"pipeline":"main.12","branch":"main","source":12,"outcome":"tier-late"}`, wanted: true, acked: 1},
|
||||
{name: "a pipeline's wants written to the end", body: `{"v":1,"pipeline":"main.13","branch":"main","source":12,"revision":13,"outcome":"tier-late"}`, wanted: true, acked: 1},
|
||||
{name: "not json", body: `nope`, termd: 1},
|
||||
{name: "a run never taken in", body: `{"v":1,"run":"7","members":[]}`, err: fmt.Errorf("%w: no member", index.ErrUnreadable), termd: 1, started: "7"},
|
||||
{name: "a bus fault", body: `{"v":1,"run":"7","members":[{"module":"a","commit":"c"}]}`, err: errors.New("the bus did not answer"), started: "7"},
|
||||
@@ -100,8 +114,8 @@ func TestTheTrunkIsTheDirectoriesTheForgeListsTrees(t *testing.T) { // 1900/AC3
|
||||
switch {
|
||||
case row.wanted:
|
||||
heardPipelineWanted(context.Background(), ix, m, t.Logf)
|
||||
if ix.wanted != "main.12 tier-late" {
|
||||
t.Errorf("%s: was handed %q, want main.12 tier-late", row.name, ix.wanted)
|
||||
if ix.wanted != "main.12.13 tier-late" { // its revision handed beside its source (H-A-214)
|
||||
t.Errorf("%s: was handed %q, want main.12.13 tier-late", row.name, ix.wanted)
|
||||
}
|
||||
case row.ended:
|
||||
heardPipelineEnded(context.Background(), ix, m, t.Logf)
|
||||
@@ -169,8 +183,11 @@ func (f *fakeRuns) HeardPins(context.Context, *meshpipelinerunner.PipelineStarte
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *fakeRuns) HeardPipelineWanted(_ context.Context, branch string, source int64, outcome string) error {
|
||||
func (f *fakeRuns) HeardPipelineWanted(_ context.Context, branch string, source, revision int64, outcome string) error {
|
||||
f.wanted = fmt.Sprintf("%s.%d %s", branch, source, outcome)
|
||||
if revision > 0 {
|
||||
f.wanted = fmt.Sprintf("%s.%d.%d %s", branch, source, revision, outcome)
|
||||
}
|
||||
return f.err
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ type runTaker interface {
|
||||
StartRun(ctx context.Context, e meshpipelinerunner.RunStarted) error
|
||||
EndRunPipeline(ctx context.Context, e meshpipelinerunner.PipelineEnded) error
|
||||
HeardPins(ctx context.Context, started *meshpipelinerunner.PipelineStarted, ended *meshpipelinerunner.PipelineEnded) error
|
||||
HeardPipelineWanted(ctx context.Context, branch string, source int64, outcome string) error
|
||||
HeardPipelineWanted(ctx context.Context, branch string, source, revision int64, outcome string) error
|
||||
JudgePins(ctx context.Context)
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ func heardPipelineWanted(ctx context.Context, ix runTaker, m delivered, logf fun
|
||||
_ = m.Term()
|
||||
return
|
||||
}
|
||||
err := ix.HeardPipelineWanted(ctx, e.Branch, e.Source, e.Outcome)
|
||||
err := ix.HeardPipelineWanted(ctx, e.Branch, e.Source, e.Revision, e.Outcome)
|
||||
settleRun(m, err, "pipeline-wanted of "+e.Pipeline, logf)
|
||||
if err == nil {
|
||||
ix.JudgePins(ctx)
|
||||
|
||||
@@ -22,8 +22,9 @@ var (
|
||||
)
|
||||
|
||||
// heardVersion reads one message of the consumer as a version, false for any other subject. A package's is kept in its
|
||||
// series; one that does not decode is said and acknowledged; a write that fails is left unacknowledged, so the bus gives
|
||||
// it again.
|
||||
// series; one that does not decode is said and acknowledged; a write that fails is left unacknowledged, so the bus gives it
|
||||
// again. It recomputes no module: a fingerprint moves only with a kept catalog revision, a release's by the re-pin its
|
||||
// package-published starts, one revision per module release (design 47 H-A-211, H-A-213 (2)).
|
||||
func heardVersion(ctx context.Context, ix *index.Indexer, m jetstream.Msg, logf func(string, ...any)) bool {
|
||||
var h index.HeardVersion
|
||||
switch seat, ok := publishedSeats[m.Subject()]; {
|
||||
@@ -51,12 +52,6 @@ func heardVersion(ctx context.Context, ix *index.Indexer, m jetstream.Msg, logf
|
||||
if kept {
|
||||
logf("packages: %s %s kept in its series (published %v)", h.Package, h.Version, h.Published)
|
||||
}
|
||||
if kept && h.Published {
|
||||
// A series' newest moved: its users' fingerprints take it (DLV-I6), in the same turn as the publish is heard.
|
||||
if err := ix.Recompute(ctx); err != nil {
|
||||
logf("writing the modules again after %s %s was published: %v", h.Package, h.Version, err)
|
||||
}
|
||||
}
|
||||
_ = m.Ack()
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/gopackageregistry"
|
||||
|
||||
"mesh-delivery-indexer/internal/index"
|
||||
)
|
||||
|
||||
// ackedMsg is a message that counts its acknowledgements.
|
||||
type ackedMsg struct {
|
||||
jetstream.Msg
|
||||
subject string
|
||||
data []byte
|
||||
acked int
|
||||
}
|
||||
|
||||
func (a *ackedMsg) Subject() string { return a.subject }
|
||||
func (a *ackedMsg) Data() []byte { return a.data }
|
||||
func (a *ackedMsg) Ack() error { a.acked++; return nil }
|
||||
|
||||
// unlistedStore is a store whose listing fails: a recompute over it fails.
|
||||
type unlistedStore struct{ memStore }
|
||||
|
||||
func (unlistedStore) Keys(context.Context) ([]string, error) {
|
||||
return nil, errors.New("the bus does not answer")
|
||||
}
|
||||
|
||||
// TestHeardVersionMovesNoFingerprint: a registry's published is kept in its series and acknowledged, and recomputes no
|
||||
// module: a fingerprint moves only with a kept revision, a release's by its re-pin on the package-published (design 47
|
||||
// H-A-211, H-A-213 (2); the pin specification's leftover L3). The modules state here fails any recompute.
|
||||
func TestHeardVersionMovesNoFingerprint(t *testing.T) {
|
||||
data, err := json.Marshal(gopackageregistry.PublishedEvent{Kind: "package", Name: "git.example/novox/lib", Version: "0.1.4"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ix := &index.Indexer{Packages: &memStore{vals: map[string][]byte{}}, Modules: &unlistedStore{memStore{vals: map[string][]byte{}}},
|
||||
Manifests: &memStore{vals: map[string][]byte{}}}
|
||||
m := &ackedMsg{subject: gopackageregistry.SubjectPublished, data: data}
|
||||
if !heardVersion(context.Background(), ix, m, t.Logf) {
|
||||
t.Fatal("the registry's published is not taken as a version")
|
||||
}
|
||||
if m.acked != 1 {
|
||||
t.Errorf("acknowledged %d times, want once: a publish recomputes nothing that could fail", m.acked)
|
||||
}
|
||||
}
|
||||
@@ -286,6 +286,14 @@ func (a actor) HeldAgain(ctx context.Context, branch string) index.TakenIn {
|
||||
return r
|
||||
}
|
||||
|
||||
// TakeInAgain takes a repository in again at its kept merge commit (indexer_take_in_again, H-A-208, H-A-210), one take-in
|
||||
// again at a time beside the held ones.
|
||||
func (a actor) TakeInAgain(ctx context.Context, repository string) index.TakenIn {
|
||||
a.s.again.Lock()
|
||||
defer a.s.again.Unlock()
|
||||
return a.Indexer.TakeInAgain(ctx, repository)
|
||||
}
|
||||
|
||||
// HeldSkip ends a branch's held source revision unwritten (indexer_take_in_skip): take-in.taken says it skipped.
|
||||
func (a actor) HeldSkip(ctx context.Context, branch string, source int64, by, why string) index.TakenIn {
|
||||
r := index.TakenIn{Module: branch}
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -172,25 +174,43 @@ func (f *fakeBranchJS) Consumer(_ context.Context, stream, name string) (jetstre
|
||||
|
||||
func (f *fakeBranchJS) CreateConsumer(_ context.Context, stream string, cfg jetstream.ConsumerConfig) (jetstream.Consumer, error) {
|
||||
f.made = append(f.made, cfg)
|
||||
c := &fakeBranchConsumer{}
|
||||
c := newFakeBranchConsumer(stream, cfg.Durable)
|
||||
f.held[stream+"/"+cfg.Durable] = c
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// fakeBranchConsumer hands one source-moved to the hearing as soon as it is consumed.
|
||||
// fakeBranchConsumer hands one source-moved to the hearing as soon as it is consumed. It answers its CachedInfo as the bus
|
||||
// does, with its stream, name and created time, which the SDK's guard of one pull per durable keys by (design 47 H-A-196).
|
||||
type fakeBranchConsumer struct {
|
||||
jetstream.Consumer
|
||||
info jetstream.ConsumerInfo
|
||||
heard int
|
||||
}
|
||||
|
||||
type fakeConsumeContext struct{ jetstream.ConsumeContext }
|
||||
// fakeConsumersMade numbers the fakes, so each is created at a time of its own, as each durable the bus makes is.
|
||||
var fakeConsumersMade atomic.Int64
|
||||
|
||||
func (fakeConsumeContext) Stop() {}
|
||||
func newFakeBranchConsumer(stream, durable string) *fakeBranchConsumer {
|
||||
return &fakeBranchConsumer{info: jetstream.ConsumerInfo{Stream: stream, Name: durable, Config: jetstream.ConsumerConfig{Durable: durable},
|
||||
Created: time.Unix(0, fakeConsumersMade.Add(1)).UTC()}}
|
||||
}
|
||||
|
||||
func (c *fakeBranchConsumer) CachedInfo() *jetstream.ConsumerInfo { return &c.info }
|
||||
|
||||
// fakeConsumeContext is a consume that ends when stopped, as the guard's release waits for (H-A-196).
|
||||
type fakeConsumeContext struct {
|
||||
jetstream.ConsumeContext
|
||||
stop sync.Once
|
||||
closed chan struct{}
|
||||
}
|
||||
|
||||
func (c *fakeConsumeContext) Stop() { c.stop.Do(func() { close(c.closed) }) }
|
||||
func (c *fakeConsumeContext) Closed() <-chan struct{} { return c.closed }
|
||||
|
||||
func (c *fakeBranchConsumer) Consume(handle jetstream.MessageHandler, _ ...jetstream.PullConsumeOpt) (jetstream.ConsumeContext, error) {
|
||||
c.heard++
|
||||
handle(msgOf{f: &fakeMsg{subject: "mesh.seat.mesh-delivery.event.source-moved.main.2"}})
|
||||
return fakeConsumeContext{}, nil
|
||||
return &fakeConsumeContext{closed: make(chan struct{})}, nil
|
||||
}
|
||||
|
||||
// Design 47 H §743, H-A-134: a branch's durable the bus does not hold the indexer makes, as a module's seat-event consumer is
|
||||
@@ -207,7 +227,7 @@ func TestABranchDurableNotThereIsMadeAndHeard(t *testing.T) {
|
||||
name := "n1_mesh-delivery-indexer_" + keys.EscapeName("main")
|
||||
var existing *fakeBranchConsumer
|
||||
if tc.held {
|
||||
existing = &fakeBranchConsumer{}
|
||||
existing = newFakeBranchConsumer(meshdelivery.StreamSourceMoved, name)
|
||||
js.held[meshdelivery.StreamSourceMoved+"/"+name] = existing
|
||||
}
|
||||
var heard []string
|
||||
|
||||
@@ -24,6 +24,8 @@ type takerIn interface {
|
||||
// HeldAgain and HeldSkip act on a watched branch's held source-moved (design 47 H §744).
|
||||
HeldAgain(ctx context.Context, branch string) index.TakenIn
|
||||
HeldSkip(ctx context.Context, branch string, source int64, by, why string) index.TakenIn
|
||||
// TakeInAgain takes a repository in again at its kept merge commit (H-A-208, H-A-210).
|
||||
TakeInAgain(ctx context.Context, repository string) index.TakenIn
|
||||
}
|
||||
|
||||
// takenIn answers one value of the takeins state (a hand act, issue 1945): a value not yet answered is acted on now and
|
||||
@@ -53,6 +55,9 @@ func takenIn(ctx context.Context, ix takerIn, kv jetstream.KeyValue, e jetstream
|
||||
} else if a.Held != "" {
|
||||
asked, r = "take-in again of a held take-in", ix.HeldAgain(ctx, a.Held)
|
||||
a.Module = a.Held
|
||||
} else if a.Again != "" {
|
||||
asked, r = "take-in again of a repository", ix.TakeInAgain(ctx, a.Again)
|
||||
a.Module = a.Again
|
||||
} else if a.Registry != nil {
|
||||
asked, r = "registrations' act "+a.Registry.Verb, ix.RegistryAct(ctx, a)
|
||||
} else if a.Recompute {
|
||||
|
||||
+28
-22
@@ -6,6 +6,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"slices"
|
||||
"strconv"
|
||||
@@ -447,37 +448,42 @@ func TestIndexerWhole(t *testing.T) {
|
||||
|
||||
// The first revision: no mover, no pin; its entries are the base.
|
||||
sayMoved(t, ctx, js, "main", 10, c10, true)
|
||||
if first := heard.next(t, "main", 10); len(first.Entries) != 0 || first.Revision != 10 {
|
||||
t.Fatalf("the first revision said %+v, want revision 10 with no entries", first)
|
||||
// A revision's number is the indexer's own count, the branch's newest + 1 (design 47 H-A-213 (1)): the later take-ins of
|
||||
// sources 11 to 13 are counted on from the number of source 10's.
|
||||
first := heard.next(t, "main", 10)
|
||||
r := func(source int64) int64 { return first.Revision + source - 10 }
|
||||
rn := func(source int64) string { return fmt.Sprintf("main.%d", r(source)) }
|
||||
if len(first.Entries) != 0 || first.Revision != 2 || first.Source != 10 {
|
||||
t.Fatalf("the first revision said %+v, want revision 2 (the bed's seed is main.1, of source 0) of source 10 with no entries", first)
|
||||
}
|
||||
untilKey(t, ctx, pins, index.PinKey("main", 10), absent)
|
||||
untilKey(t, ctx, pins, index.PinKey("main", r(10)), absent)
|
||||
|
||||
// One take-in, one revision carrying its movers, pinned for its pipeline; said again from the kept movers.
|
||||
sayMoved(t, ctx, js, "main", 11, c11, false)
|
||||
taken := heard.next(t, "main", 11)
|
||||
if len(taken.Entries) != 1 || taken.Entries[0].Module != "avahi" || taken.Entries[0].Commit != c11 || taken.Entries[0].Fingerprint == "" ||
|
||||
taken.Entries[0].Repository != "novox/mesh-catalog" || taken.Revision != 11 || taken.Call == "" {
|
||||
taken.Entries[0].Repository != "novox/mesh-catalog" || taken.Revision != r(11) || taken.Call == "" {
|
||||
t.Fatalf("take-in.taken of main 11 = %+v, want avahi at %s as its one mover", taken, c11)
|
||||
}
|
||||
rev, _, err := index.ReadRevision(ctx, objects, "main.11")
|
||||
rev, _, err := index.ReadRevision(ctx, objects, rn(11))
|
||||
if err != nil || len(rev.Movers) != 1 || rev.Movers[0] != taken.Entries[0] {
|
||||
t.Fatalf("main.11 = %+v (%v), want it kept carrying the movers said", rev, err)
|
||||
}
|
||||
untilKey(t, ctx, pins, index.PinKey("main", 11), pinned("pipeline.main.11"))
|
||||
untilKey(t, ctx, pins, index.PinKey("main", 10), pinned("pipeline.main.11")) // validate's base, H-A-147
|
||||
untilKey(t, ctx, pins, index.PinKey("main", r(11)), pinned("pipeline."+rn(11)))
|
||||
untilKey(t, ctx, pins, index.PinKey("main", r(10)), pinned("pipeline."+rn(11))) // validate's base, H-A-147
|
||||
info, err := objects.open(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
before, err := info.GetInfo(ctx, "main.11")
|
||||
before, err := info.GetInfo(ctx, rn(11))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sayMoved(t, ctx, js, "main", 11, c11, false)
|
||||
if again := heard.next(t, "main", 11); len(again.Entries) != 1 || again.Entries[0] != taken.Entries[0] || again.Revision != 11 {
|
||||
if again := heard.next(t, "main", 11); len(again.Entries) != 1 || again.Entries[0] != taken.Entries[0] || again.Revision != r(11) {
|
||||
t.Errorf("the source-moved given again said %+v, want the kept movers %+v", again, taken.Entries)
|
||||
}
|
||||
if after, err := info.GetInfo(ctx, "main.11"); err != nil || after.NUID != before.NUID {
|
||||
if after, err := info.GetInfo(ctx, rn(11)); err != nil || after.NUID != before.NUID {
|
||||
t.Errorf("main.11 was written again (%v): a source-moved given again keeps no second revision", err)
|
||||
}
|
||||
|
||||
@@ -485,11 +491,11 @@ func TestIndexerWhole(t *testing.T) {
|
||||
// (H-A-147), which the take-in pinned for it.
|
||||
sayMoved(t, ctx, js, "main", 12, c12, false)
|
||||
heard.next(t, "main", 12)
|
||||
if err := pins.Delete(ctx, index.PinKey("main", 12)); err != nil { // the take-in's own pin, so pipeline-started alone writes it below
|
||||
if err := pins.Delete(ctx, index.PinKey("main", r(12))); err != nil { // the take-in's own pin, so pipeline-started alone writes it below
|
||||
t.Fatal(err)
|
||||
}
|
||||
sayPipeline(t, ctx, js, false, "main", 12)
|
||||
untilKey(t, ctx, pins, index.PinKey("main", 12), pinned("pipeline.main.12"))
|
||||
sayPipeline(t, ctx, js, false, "main", r(12))
|
||||
untilKey(t, ctx, pins, index.PinKey("main", r(12)), pinned("pipeline."+rn(12)))
|
||||
// A run on request: its candidate and its key written on run-started, from avahi's files at the run's commit (A-160, A-174).
|
||||
manifest, err := os.ReadFile("../../internal/index/testdata/catalogue-a67f0196-avahi.module.json")
|
||||
if err != nil {
|
||||
@@ -515,7 +521,7 @@ func TestIndexerWhole(t *testing.T) {
|
||||
heard.acked(t, "main")
|
||||
}
|
||||
restart()
|
||||
for _, name := range []string{"main.10", "main.11"} {
|
||||
for _, name := range []string{rn(10), rn(11)} {
|
||||
if _, _, err := index.ReadRevision(ctx, objects, name); err != nil {
|
||||
t.Fatalf("%s is not kept across a restart while main.11's pipeline runs: %v", name, err)
|
||||
}
|
||||
@@ -553,27 +559,27 @@ func TestIndexerWhole(t *testing.T) {
|
||||
t.Errorf("the held source-moved's consumer %+v (%v), want nothing unacknowledged", info, err)
|
||||
}
|
||||
setCap(t, ctx, js, 1<<30) // a larger cap alone wakes nothing: no timer takes a held take-in in
|
||||
sayPipeline(t, ctx, js, true, "main", 11)
|
||||
sayPipeline(t, ctx, js, true, "main", r(11))
|
||||
if got := heard.next(t, "main", 13); len(got.Entries) != 1 || got.Entries[0].Commit != c13 {
|
||||
t.Errorf("main 13 taken in on room said %+v, want avahi at %s", got, c13)
|
||||
}
|
||||
untilKey(t, ctx, held, keys.EscapeName("main"), absent)
|
||||
// main.12's validate base stays (H-A-147), and main.11's passed pipeline's release pins it (H-A-168, H-A-170).
|
||||
untilKey(t, ctx, pins, index.PinKey("main", 11), pinned("pipeline.main.12", index.ReleaseRecord("main", "avahi")))
|
||||
untilRevisionGone(t, ctx, js, "main.10") // the end freed both of main.11's pins
|
||||
untilKey(t, ctx, pins, index.PinKey("main", r(11)), pinned("pipeline."+rn(12), index.ReleaseRecord("main", "avahi")))
|
||||
untilRevisionGone(t, ctx, js, rn(10)) // the end freed both of main.11's pins
|
||||
// main.12's passed pipeline releases avahi again; its pipeline-wanted, the seat mesh-wants' (its wants written to the end),
|
||||
// frees main.11's older release, and main.11 goes (H-A-168, H-A-170, H-A-173).
|
||||
sayPipeline(t, ctx, js, true, "main", 12)
|
||||
untilKey(t, ctx, pins, index.PinKey("main", 12), func(v []byte) bool {
|
||||
sayPipeline(t, ctx, js, true, "main", r(12))
|
||||
untilKey(t, ctx, pins, index.PinKey("main", r(12)), func(v []byte) bool {
|
||||
var p index.PinValue
|
||||
return v != nil && json.Unmarshal(v, &p) == nil && slices.Contains(p.Records, index.ReleaseRecord("main", "avahi"))
|
||||
})
|
||||
wantedRaw, _ := json.Marshal(meshwants.PipelineWanted{V: 1, Pipeline: "main.12", Branch: "main", Source: 12, Outcome: meshwants.PipelineWantedOutcomeRunning})
|
||||
wantedRaw, _ := json.Marshal(meshwants.PipelineWanted{V: 1, Pipeline: rn(12), Branch: "main", Source: 12, Outcome: meshwants.PipelineWantedOutcomeRunning})
|
||||
if _, err := js.Publish(ctx, meshwants.SubjectPipelineWanted("main", "12"), wantedRaw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
untilKey(t, ctx, pins, index.PinKey("main", 11), absent)
|
||||
untilRevisionGone(t, ctx, js, "main.11")
|
||||
untilKey(t, ctx, pins, index.PinKey("main", r(11)), absent)
|
||||
untilRevisionGone(t, ctx, js, rn(11))
|
||||
if n := len(heard.pending); n != 0 {
|
||||
t.Errorf("take-in.pending said %d more times for one held source revision, want once", n)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"mesh-delivery-indexer/internal/index"
|
||||
)
|
||||
|
||||
// askedBy is a takerIn that names the hand act it was asked.
|
||||
type askedBy struct{ asked []string }
|
||||
|
||||
func (s *askedBy) did(act string) index.TakenIn {
|
||||
s.asked = append(s.asked, act)
|
||||
return index.TakenIn{Module: "m", Stored: true, Answer: act}
|
||||
}
|
||||
func (s *askedBy) SeatDefinitionsAgain(context.Context, string) index.TakenIn {
|
||||
return s.did("seat-definitions")
|
||||
}
|
||||
func (s *askedBy) FingerprintsAgain(context.Context, string) index.TakenIn {
|
||||
return s.did("fingerprints")
|
||||
}
|
||||
func (s *askedBy) RecomputeByHand(context.Context, string, string) index.TakenIn {
|
||||
return s.did("recompute")
|
||||
}
|
||||
func (s *askedBy) DropCandidateGraph(context.Context, string, string, string, string) index.TakenIn {
|
||||
return s.did("candidate-group")
|
||||
}
|
||||
func (s *askedBy) NamedDrop(context.Context, string, string, string, string) index.TakenIn {
|
||||
return s.did("named-fingerprint")
|
||||
}
|
||||
func (s *askedBy) PinDrop(context.Context, string, string, string) index.TakenIn {
|
||||
return s.did("pin-drop")
|
||||
}
|
||||
func (s *askedBy) DropRunByHand(context.Context, string, string, string) index.TakenIn {
|
||||
return s.did("run-drop")
|
||||
}
|
||||
func (s *askedBy) RegistryAct(context.Context, index.TakeInAsk) index.TakenIn {
|
||||
return s.did("registry")
|
||||
}
|
||||
func (s *askedBy) HeldAgain(context.Context, string) index.TakenIn { return s.did("held") }
|
||||
func (s *askedBy) HeldSkip(context.Context, string, int64, string, string) index.TakenIn {
|
||||
return s.did("held-skip")
|
||||
}
|
||||
func (s *askedBy) TakeInAgain(context.Context, string) index.TakenIn { return s.did("again") }
|
||||
|
||||
// answeredKV keeps the answer takenIn writes back.
|
||||
type answeredKV struct {
|
||||
jetstream.KeyValue
|
||||
written []byte
|
||||
}
|
||||
|
||||
func (k *answeredKV) Update(_ context.Context, _ string, value []byte, _ uint64) (uint64, error) {
|
||||
k.written = value
|
||||
return 2, nil
|
||||
}
|
||||
|
||||
type askEntry struct {
|
||||
jetstream.KeyValueEntry
|
||||
key string
|
||||
value []byte
|
||||
}
|
||||
|
||||
func (e askEntry) Key() string { return e.key }
|
||||
func (e askEntry) Value() []byte { return e.value }
|
||||
func (e askEntry) Revision() uint64 { return 1 }
|
||||
func (e askEntry) Operation() jetstream.KeyValueOp { return jetstream.KeyValuePut }
|
||||
|
||||
// Design 47 H-A-208, H-A-210, H §774: every hand tool's takeins value, built by the tool's own Run path (or the constructor it
|
||||
// calls), is read by DecodeTakeIn and acted on by takenIn as the act it names; indexer_take_in_again's was refused, its Again
|
||||
// missing from a hand-kept list. Every field of TakeInAsk says by its tag whether it is an act, so an act added is read.
|
||||
func TestEveryHandToolsAskIsReadAndActedOn(t *testing.T) {
|
||||
t.Run("every field is classed", func(t *testing.T) {
|
||||
ty := reflect.TypeFor[index.TakeInAsk]()
|
||||
for i := range ty.NumField() {
|
||||
if c := ty.Field(i).Tag.Get("takein"); !slices.Contains([]string{"act", "argument", "ask"}, c) {
|
||||
t.Errorf("TakeInAsk.%s has takein %q, want act, argument or ask", ty.Field(i).Name, c)
|
||||
}
|
||||
}
|
||||
})
|
||||
var values [][]byte
|
||||
ask := func(_ string, value []byte) (index.TakeInAsk, error) {
|
||||
values = append(values, value)
|
||||
return index.TakeInAsk{V: 1, Result: &index.TakenIn{Stored: true}, Answered: time.Now()}, nil
|
||||
}
|
||||
record := func(string, string) error { return nil }
|
||||
tools := map[string]func(map[string]any) (any, error){}
|
||||
for _, tl := range slices.Concat(index.HeldTools(nil, ask, time.Now, record), index.PinsTools(nil, nil, ask, time.Now, record),
|
||||
index.RunsTools(nil, nil, ask, time.Now, record), index.NamedTools(ask, time.Now, record),
|
||||
index.FingerprintsTools(ask, time.Now, record, time.Minute), index.CatalogRevisionTools(nil, ask, time.Now, record),
|
||||
index.RegistrationTools(nil, nil, ask, time.Now, func(string, string, string, string) error { return nil })) {
|
||||
tools[tl.Name] = tl.Run
|
||||
}
|
||||
tools[index.SeatDefinitionsAgainTool] = func(args map[string]any) (any, error) { // its tool lives in the tools bundle
|
||||
_, value, err := index.NewSeatDefinitionsAgain(args["module"].(string), "why", "by", time.Now())
|
||||
values = append(values, value)
|
||||
return nil, err
|
||||
}
|
||||
for _, c := range []struct {
|
||||
tool string
|
||||
args map[string]any
|
||||
act string
|
||||
}{
|
||||
{index.TakeInAgainTool, map[string]any{"repository": "novox/mesh-host", "why": "rule changed"}, "again"},
|
||||
{index.TakeInPendingTool, map[string]any{"branch": "main"}, "held"},
|
||||
{index.TakeInSkipTool, map[string]any{"branch": "main", "source": float64(4), "why": "stale"}, "held-skip"},
|
||||
{index.PinDropTool, map[string]any{"key": "main.7", "why": "no pipeline"}, "pin-drop"},
|
||||
{index.RunDropTool, map[string]any{"run": "run-12", "why": "never ends"}, "run-drop"},
|
||||
{index.NamedDropTool, map[string]any{"fingerprint": "abc", "member": "ace.feh", "why": "gone"}, "named-fingerprint"},
|
||||
{index.FingerprintsAgainTool, map[string]any{"module": "feh", "why": "unread packages"}, "fingerprints"},
|
||||
{index.RecomputeTool, map[string]any{"why": "check"}, "recompute"},
|
||||
{index.DropCandidateGraphTool, map[string]any{"group": "g", "heads": "h", "why": "no gate event"}, "candidate-group"},
|
||||
{index.SeedAgainTool, map[string]any{"why": "empty"}, "registry"},
|
||||
{index.SeatDefinitionsAgainTool, map[string]any{"module": "mesh-contracts"}, "seat-definitions"},
|
||||
} {
|
||||
t.Run(c.tool, func(t *testing.T) {
|
||||
run, ok := tools[c.tool]
|
||||
if !ok {
|
||||
t.Fatalf("no tool %s", c.tool)
|
||||
}
|
||||
values = nil
|
||||
if _, err := run(c.args); err != nil || len(values) != 1 {
|
||||
t.Fatalf("%s wrote %d values (%v)", c.tool, len(values), err)
|
||||
}
|
||||
if _, err := index.DecodeTakeIn(values[0]); err != nil {
|
||||
t.Fatalf("DecodeTakeIn refuses %s: %v", values[0], err)
|
||||
}
|
||||
ix, kv := &askedBy{}, &answeredKV{}
|
||||
var said []string
|
||||
takenIn(t.Context(), ix, kv, askEntry{key: "k", value: values[0]}, func(f string, a ...any) { said = append(said, f) })
|
||||
if !slices.Equal(ix.asked, []string{c.act}) {
|
||||
t.Errorf("takenIn asked %v of %s, want %s (said %s)", ix.asked, values[0], c.act, strings.Join(said, "; "))
|
||||
}
|
||||
var answered index.TakeInAsk
|
||||
if err := json.Unmarshal(kv.written, &answered); err != nil || !answered.Done() {
|
||||
t.Errorf("takenIn wrote back %s (%v), want the answered ask", kv.written, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,9 @@ func checkCandidateModule(m meshcatalog.CandidatesByGroupValuePullsItemFpsValue)
|
||||
return fmt.Errorf("index: the named path %q names no git object", p)
|
||||
}
|
||||
}
|
||||
if err := sdkstep.PackageVersions(m.Packages).Check(); err != nil {
|
||||
// An entry names a package with no published version yet with an empty version (design 47 H S8, H-A-204): it is checked
|
||||
// as an entry's packages, not as an ask's.
|
||||
if err := sdkstep.PackageVersions(m.Packages).CheckEntry(); err != nil {
|
||||
return err
|
||||
}
|
||||
if m.Fp2 != "" {
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package index
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
)
|
||||
|
||||
// TestCheckCandidateModulePins: an entry's package with no published version (an empty pin) passes a run on request's
|
||||
// candidate; a pin that is no version is refused (design 47 H S8, the pin specification's item 4).
|
||||
func TestCheckCandidateModulePins(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
packages map[string]string
|
||||
ok bool
|
||||
}{
|
||||
{"an empty pin", map[string]string{"git.example/novox/lib/go": ""}, true},
|
||||
{"a version", map[string]string{"git.example/novox/lib/go": "v0.1.4"}, true},
|
||||
{"no version", map[string]string{"git.example/novox/lib/go": "latest"}, false},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
m := meshcatalog.CandidatesByGroupValuePullsItemFpsValue{Fp2: "src2:" + strings.Repeat("ab", 32), Packages: c.packages}
|
||||
err := checkCandidateModule(m)
|
||||
if (err == nil) != c.ok {
|
||||
t.Errorf("checkCandidateModule(%v) = %v, want ok %v", c.packages, err, c.ok)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -156,6 +156,7 @@ type Indexer struct {
|
||||
filling atomic.Bool // a FillTaken runs in the background (KickFill)
|
||||
fillAgain atomic.Bool // a kick arrived while it ran
|
||||
underSeats bool // a dry run inside judge.WithSeats: its judge passes do not hold the seat list (verdicts.go)
|
||||
isDry bool // a dry run (dryrun.go): it shares the live packages state, so it drops no kept package key (packages.go)
|
||||
judgeMu sync.Mutex // one judge pass at a time (verdicts.go)
|
||||
keepMu sync.Mutex // one catalog graph revision kept at a time (keepEntries)
|
||||
// Pins is the state pins (pins.go); nil keeps none. PinsPending says how many messages the indexer's durable consumer of the
|
||||
|
||||
@@ -36,13 +36,13 @@ func TestACatalogRevisionIsKeptPerWatchedBranch(t *testing.T) {
|
||||
for _, n := range names {
|
||||
have[n] = true
|
||||
}
|
||||
for _, want := range []string{"main.5", "feature/x=2ey.7", "feature/x=2ey.8"} {
|
||||
for _, want := range []string{"main.1", "feature/x=2ey.1", "feature/x=2ey.2"} {
|
||||
if !have[want] {
|
||||
t.Errorf("the objects hold %v, want %s", names, want)
|
||||
}
|
||||
}
|
||||
if len(said) != 3 || said[0].Branch != "main" || said[1].Branch != "feature/x=2ey" || said[2].Revision != 8 {
|
||||
t.Errorf("said %+v, want main 5, then the escaped branch 7 and 8", said)
|
||||
if len(said) != 3 || said[0].Branch != "main" || said[1].Branch != "feature/x=2ey" || said[2].Revision != 2 || said[2].Source != 8 {
|
||||
t.Errorf("said %+v, want main 1 of source 5, then the escaped branch 1 and 2 of sources 7 and 8", said)
|
||||
}
|
||||
answer := func(branch string, revision int64) meshcatalog.RevisionAnswer {
|
||||
a, err := Revision(ctx, ix.Revisions, nil, meshcatalog.RevisionInput{Branch: branch, Revision: revision})
|
||||
@@ -51,14 +51,14 @@ func TestACatalogRevisionIsKeptPerWatchedBranch(t *testing.T) {
|
||||
}
|
||||
return a
|
||||
}
|
||||
if a := answer("main", 0); a.Revision.Revision != 5 || a.Entries[0].Commit != "c1" {
|
||||
if a := answer("main", 0); a.Revision.Revision != 1 || a.Revision.Source != 5 || a.Entries[0].Commit != "c1" {
|
||||
t.Errorf("main answered %+v", a)
|
||||
}
|
||||
if a := answer("feature/x=2ey", 0); a.Revision.Revision != 8 || a.Revision.Branch != "feature/x.y" || a.Entries[0].Commit != "c3" {
|
||||
t.Errorf("the branch's newest answered %+v, want its revision 8 at c3", a.Revision)
|
||||
if a := answer("feature/x=2ey", 0); a.Revision.Revision != 2 || a.Revision.Branch != "feature/x.y" || a.Entries[0].Commit != "c3" {
|
||||
t.Errorf("the branch's newest answered %+v, want its revision 2 at c3", a.Revision)
|
||||
}
|
||||
if a := answer("feature/x=2ey", 7); a.Revision.Revision != 7 || a.Entries[0].Commit != "c2" {
|
||||
t.Errorf("the branch's revision 7 answered %+v", a.Revision)
|
||||
if a := answer("feature/x=2ey", 1); a.Revision.Revision != 1 || a.Entries[0].Commit != "c2" {
|
||||
t.Errorf("the branch's revision 1 answered %+v", a.Revision)
|
||||
}
|
||||
if a := answer("beta", 0); !a.NoneYet {
|
||||
t.Errorf("a branch with no revision answered %+v, want none-yet", a)
|
||||
@@ -68,15 +68,22 @@ func TestACatalogRevisionIsKeptPerWatchedBranch(t *testing.T) {
|
||||
bySource := func(branch string, source int64) (meshcatalog.RevisionAnswer, error) {
|
||||
return Revision(ctx, ix.Revisions, nil, meshcatalog.RevisionInput{Branch: branch, Source: source})
|
||||
}
|
||||
if a, err := bySource("main", 5); err != nil || a.Revision.Revision != 5 || a.Entries[0].Commit != "c1" {
|
||||
if a, err := bySource("main", 5); err != nil || a.Revision.Revision != 1 || a.Revision.Source != 5 || a.Entries[0].Commit != "c1" {
|
||||
t.Errorf("main's source 5 answered %+v (%v)", a.Revision, err)
|
||||
}
|
||||
if a, err := bySource("feature/x=2ey", 7); err != nil || a.Revision.Revision != 7 || a.Entries[0].Commit != "c2" {
|
||||
t.Errorf("the branch's source 7 answered %+v (%v), want its revision 7 at c2", a.Revision, err)
|
||||
if a, err := bySource("feature/x=2ey", 7); err != nil || a.Revision.Revision != 1 || a.Entries[0].Commit != "c2" {
|
||||
t.Errorf("the branch's source 7 answered %+v (%v), want its revision 1 at c2", a.Revision, err)
|
||||
}
|
||||
if a, err := bySource("feature/x=2ey", 8); err != nil || a.Revision.Revision != 8 {
|
||||
if a, err := bySource("feature/x=2ey", 8); err != nil || a.Revision.Revision != 2 {
|
||||
t.Errorf("the branch's source 8 answered %+v (%v)", a.Revision, err)
|
||||
}
|
||||
// H-A-213: a re-pin's revision of source 8 answers below the take-in's: source 8 answers revision 2.
|
||||
if _, err := ix.keepBranchEntries(ctx, "feature/x.y", 8, releaseCall("mesh-sdk", "0.1.27"), tip("c4"), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if a, err := bySource("feature/x=2ey", 8); err != nil || a.Revision.Revision != 2 || a.Entries[0].Commit != "c3" {
|
||||
t.Errorf("the branch's source 8 after a re-pin answered %+v (%v), want the take-in's revision 2", a.Revision, err)
|
||||
}
|
||||
if _, err := bySource("feature/x=2ey", 9); err == nil {
|
||||
t.Error("a source no revision was taken in from was answered")
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -87,6 +88,37 @@ func BranchRevisionOf(branch, name string) (int64, bool) {
|
||||
return r, err == nil && r > 0
|
||||
}
|
||||
|
||||
// watchedBranches are the watched branches the bucket keeps a revision of, the first included when it keeps one, sorted:
|
||||
// each name <branch>.<n> but an entry's, a candidate's and the earlier forms' (earlierForm).
|
||||
func (ix *Indexer) watchedBranches(ctx context.Context) ([]string, error) {
|
||||
if ix.Revisions == nil {
|
||||
return nil, nil
|
||||
}
|
||||
names, err := ix.Revisions.Names(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the objects %s: %w", CatalogRevisionsObjects, err)
|
||||
}
|
||||
seen := map[string]bool{}
|
||||
for _, n := range names {
|
||||
if strings.HasPrefix(n, "entry.") || strings.HasPrefix(n, "candidate.") || earlierForm(n) {
|
||||
continue
|
||||
}
|
||||
i := strings.LastIndexByte(n, '.')
|
||||
if i <= 0 {
|
||||
continue
|
||||
}
|
||||
if r, err := strconv.ParseInt(n[i+1:], 10, 64); err != nil || r <= 0 {
|
||||
continue
|
||||
}
|
||||
branch, err := keys.UnescapeName(n[:i])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
seen[branch] = true
|
||||
}
|
||||
return slices.Sorted(maps.Keys(seen)), nil
|
||||
}
|
||||
|
||||
// TrunkRevisionOf is the revision number a trunk object's name holds, and whether it is one.
|
||||
func TrunkRevisionOf(name string) (int64, bool) { return BranchRevisionOf(TrunkBranch, name) }
|
||||
|
||||
@@ -210,6 +242,54 @@ func readNewestOf(ctx context.Context, o Objects, branch string) (meshcatalog.Ca
|
||||
}
|
||||
}
|
||||
|
||||
// TrunkEntryAt is a module's entry in a trunk revision, with that revision's list (H-A-204): for revision 0 the newest trunk
|
||||
// revision read as entryOf reads it (readNewestOf); else the kept list of that trunk revision and only the module's entry
|
||||
// object, so one entry is read without the revision whole.
|
||||
func TrunkEntryAt(ctx context.Context, o Objects, module string, revision int64) (meshcatalog.CatalogRevision, meshcatalog.CatalogEntry, error) {
|
||||
if revision == 0 {
|
||||
rev, entries, found, err := readNewestOf(ctx, o, TrunkBranch)
|
||||
if err != nil {
|
||||
return rev, meshcatalog.CatalogEntry{}, err
|
||||
}
|
||||
if !found {
|
||||
return rev, meshcatalog.CatalogEntry{}, errors.New("the indexer keeps no trunk revision yet")
|
||||
}
|
||||
for _, e := range entries {
|
||||
if e.Module == module {
|
||||
return rev, e, nil
|
||||
}
|
||||
}
|
||||
return rev, meshcatalog.CatalogEntry{}, fmt.Errorf("the trunk revision %d holds no module %s", rev.Revision, module)
|
||||
}
|
||||
name := BranchObject(TrunkBranch, revision)
|
||||
var rev meshcatalog.CatalogRevision
|
||||
data, err := o.Get(ctx, name)
|
||||
if errors.Is(err, ErrNoObject) {
|
||||
return rev, meshcatalog.CatalogEntry{}, fmt.Errorf("the trunk revision %d is not kept", revision)
|
||||
}
|
||||
if err != nil {
|
||||
return rev, meshcatalog.CatalogEntry{}, fmt.Errorf("revision %s: %w", name, err)
|
||||
}
|
||||
if err := json.Unmarshal(data, &rev); err != nil {
|
||||
return rev, meshcatalog.CatalogEntry{}, fmt.Errorf("revision %s: %w", name, err)
|
||||
}
|
||||
for _, ref := range rev.Entries {
|
||||
if ref.Module != module {
|
||||
continue
|
||||
}
|
||||
data, err := o.Get(ctx, EntryObject(ref.Digest))
|
||||
if err != nil {
|
||||
return rev, meshcatalog.CatalogEntry{}, fmt.Errorf("revision %s, the entry of %s (%s): %w", name, module, ref.Digest, err)
|
||||
}
|
||||
var e meshcatalog.CatalogEntry
|
||||
if err := json.Unmarshal(data, &e); err != nil {
|
||||
return rev, meshcatalog.CatalogEntry{}, fmt.Errorf("revision %s, the entry of %s: %w", name, module, err)
|
||||
}
|
||||
return rev, e, nil
|
||||
}
|
||||
return rev, meshcatalog.CatalogEntry{}, fmt.Errorf("the trunk revision %d holds no module %s", revision, module)
|
||||
}
|
||||
|
||||
// changedEntries are the modules whose entry differs between two revisions' lists, one gone or added included, by name.
|
||||
func changedEntries(before, after []meshcatalog.EntryRef) []string {
|
||||
was := map[string]string{}
|
||||
@@ -266,17 +346,22 @@ func (ix *Indexer) viewEntries(ctx context.Context) (map[string]meshcatalog.Cata
|
||||
}
|
||||
|
||||
// KeepBranchEntries keeps entries as the catalog revision of a watched branch taken in from its source revision src (design
|
||||
// 47 H §743, H-A-32): <branch>.<src>, the trunk's included, numbered by the source, and says catalog-revision naming the
|
||||
// branch. movers are the take-in's: kept on the revision (H-A-92), and the revision pinned for the take-in's pipeline,
|
||||
// pipeline.<branch>.<src>, in the same write when there is one (A-449a), with the branch's previous revision (H-A-147). A revision already kept under that name is not written
|
||||
// again (read before write, under the branch's one consumer); ErrObjectsFull is a store too full to keep it.
|
||||
// 47 H §743, H-A-32), as keepBranchEntries does with no call.
|
||||
func (ix *Indexer) KeepBranchEntries(ctx context.Context, branch string, src int64, entries map[string]meshcatalog.CatalogEntry, movers []meshcatalog.TakeInEntry) error {
|
||||
return ix.keepBranchEntries(ctx, branch, src, entries, movers)
|
||||
_, err := ix.keepBranchEntries(ctx, branch, src, revisionCall{}, entries, movers)
|
||||
return err
|
||||
}
|
||||
|
||||
func (ix *Indexer) keepBranchEntries(ctx context.Context, branch string, src int64, entries map[string]meshcatalog.CatalogEntry, movers []meshcatalog.TakeInEntry) error {
|
||||
// keepBranchEntries keeps entries as the next catalog revision of a watched branch, <branch>.<n>, the trunk's included: n is
|
||||
// the indexer's own count, the branch's newest revision + 1, and src the gate's source revision it was read at, its field
|
||||
// source (design 47 H-A-213 (1)); call is what made it (H-A-212, H-A-213 (3)): a take-in's the gate's call, a re-pin's
|
||||
// "release of <module> <version>", a take-in again's "take-in again of <repository>". It says catalog-revision naming the
|
||||
// branch, its source and its call. movers are kept on the revision (H-A-92), and the revision pinned for its one pipeline,
|
||||
// pipeline.<branch>.<n>, in the same write when there is one (A-449a, H-A-213 (4)), with the branch's previous revision
|
||||
// (H-A-147). It answers the number it kept; ErrObjectsFull is a store too full to keep it.
|
||||
func (ix *Indexer) keepBranchEntries(ctx context.Context, branch string, src int64, call revisionCall, entries map[string]meshcatalog.CatalogEntry, movers []meshcatalog.TakeInEntry) (int64, error) {
|
||||
if ix.Revisions == nil {
|
||||
return nil
|
||||
return 0, nil
|
||||
}
|
||||
if branch == "" {
|
||||
branch = TrunkBranch
|
||||
@@ -286,28 +371,24 @@ func (ix *Indexer) keepBranchEntries(ctx context.Context, branch string, src int
|
||||
newest, _, err := newestOf(ctx, ix.Revisions, branch)
|
||||
if errors.Is(err, process.ErrNotYet) {
|
||||
ix.logf("catalog graph: no revision is kept: its objects %s are not on the bus yet", CatalogRevisionsObjects)
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
if err != nil {
|
||||
ix.logf("catalog graph: no revision is kept: the newest is not read: %v", err)
|
||||
return fmt.Errorf("the newest catalog graph revision: %w", err)
|
||||
}
|
||||
if _, err := ix.Revisions.Get(ctx, BranchObject(branch, src)); err == nil {
|
||||
ix.logf("catalog graph: revision %s is kept already: not written again", BranchObject(branch, src))
|
||||
return nil
|
||||
} else if !errors.Is(err, ErrNoObject) {
|
||||
return fmt.Errorf("revision %s: %w", BranchObject(branch, src), err)
|
||||
return 0, fmt.Errorf("the newest catalog graph revision: %w", err)
|
||||
}
|
||||
number := newest.Revision + 1
|
||||
entries = WithEdges(ix.withActs(ctx, entries)) // the acting rules and the edges between artifact references are written here, once, for every reader (A-208)
|
||||
at := ix.now().UTC()
|
||||
rev, objects, err := CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: src, Kind: "trunk", Branch: branch, Source: src, At: &at}, entries)
|
||||
rev, objects, err := CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: number, Kind: "trunk", Branch: branch, Source: src, Call: call.Call,
|
||||
CallKind: call.Kind, Module: call.Module, Version: call.Version, Repository: call.Repository, At: &at}, entries)
|
||||
if err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
rev.Movers = movers
|
||||
// The base of the validate step's case before: the newest revision kept before this write, which the take-in pins for its
|
||||
// pipeline below, named on the revision in this same write (H-A-147, H-A-151, H-A-154); none on the branch's first take-in.
|
||||
pinsBase := len(movers) > 0 && ix.Pins != nil && newest.Revision > 0 && newest.Revision != src
|
||||
pinsBase := len(movers) > 0 && ix.Pins != nil && newest.Revision > 0
|
||||
if pinsBase {
|
||||
rev.Base = newest.Revision
|
||||
}
|
||||
@@ -319,32 +400,32 @@ func (ix *Indexer) keepBranchEntries(ctx context.Context, branch string, src int
|
||||
refused := fmt.Sprintf("the next revision; source revision %d held pending with the reason %s", src, HeldObjectsFull)
|
||||
ix.logf("catalog graph: revision %d of source revision %d is not kept: %s is full (%d of %d bytes)", rev.Revision, src, CatalogRevisionsObjects, used, capacity)
|
||||
ix.sayFill(ctx, meshcatalog.EventFull, fmt.Sprintf("%d", src), meshcatalog.Fill{Bytes: used, Cap: capacity, Refused: refused})
|
||||
return fmt.Errorf("revision %d of source revision %d: %w", rev.Revision, src, ErrObjectsFull)
|
||||
return 0, fmt.Errorf("revision %d of source revision %d: %w", rev.Revision, src, ErrObjectsFull)
|
||||
}
|
||||
if err := ix.indexEntries(ctx, rev, entries); err != nil {
|
||||
ix.logf("catalog graph: revision %d of source revision %d is not kept: %v", rev.Revision, src, err)
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
if err := KeepRevision(ctx, ix.Revisions, rev, objects); err != nil {
|
||||
ix.logf("catalog graph: revision %d of source revision %d is not kept: %v", rev.Revision, src, err)
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
// The take-in's revision pinned for its one pipeline before any judge can remove it (§743, §749, A-449a).
|
||||
if len(movers) > 0 && ix.Pins != nil {
|
||||
record := PipelineRecord(runner.PipelinesByBranchSourceKey(keys.EscapeName(branch), strconv.FormatInt(src, 10)))
|
||||
if err := ix.pin(ctx, PinKey(branch, src), record); err != nil {
|
||||
ix.logf("pins: the revision %s is not pinned for %s: %v", BranchObject(branch, src), record, err)
|
||||
return fmt.Errorf("the pin of %s: %w", BranchObject(branch, src), err)
|
||||
record := PipelineRecord(runner.PipelinesByBranchRevisionKey(keys.EscapeName(branch), strconv.FormatInt(number, 10)))
|
||||
if err := ix.pin(ctx, PinKey(branch, number), record); err != nil {
|
||||
ix.logf("pins: the revision %s is not pinned for %s: %v", BranchObject(branch, number), record, err)
|
||||
return 0, fmt.Errorf("the pin of %s: %w", BranchObject(branch, number), err)
|
||||
}
|
||||
// The branch's previous revision, the newest kept before this write, pinned for the same pipeline: it is the base of
|
||||
// the validate step's case before (H-A-108 (3), H-A-147), kept as long as the pipeline that needs it.
|
||||
if pinsBase {
|
||||
if err := ix.pin(ctx, PinKey(branch, rev.Base), record); err != nil {
|
||||
ix.logf("pins: the previous revision %s is not pinned for %s: %v", BranchObject(branch, newest.Revision), record, err)
|
||||
return fmt.Errorf("the pin of %s: %w", BranchObject(branch, newest.Revision), err)
|
||||
return 0, fmt.Errorf("the pin of %s: %w", BranchObject(branch, newest.Revision), err)
|
||||
}
|
||||
} else {
|
||||
ix.logf("pins: %s has no revision before it on its branch: none is pinned for %s as its validate base", BranchObject(branch, src), record)
|
||||
ix.logf("pins: %s has no revision before it on its branch: none is pinned for %s as its validate base", BranchObject(branch, number), record)
|
||||
}
|
||||
}
|
||||
// The revision before this one in its branch ceases to be current (§579): it goes unless a record pins it.
|
||||
@@ -364,16 +445,53 @@ func (ix *Indexer) keepBranchEntries(ctx context.Context, branch string, src int
|
||||
if after, capacity, err := ix.Revisions.Fill(ctx); fillErr == nil && err == nil && capacity > 0 && used*5 < capacity*4 && after*5 >= capacity*4 {
|
||||
ix.sayFill(ctx, meshcatalog.EventFilling, fmt.Sprintf("%d", rev.Revision), meshcatalog.Fill{Bytes: after, Cap: capacity})
|
||||
}
|
||||
ix.logf("catalog graph: revision %d of source revision %d kept, %d entries, %d changed", rev.Revision, src, len(rev.Entries), len(changed))
|
||||
ix.logf("catalog graph: revision %d of source revision %d kept (%s), %d entries, %d changed", rev.Revision, src, call.Call, len(rev.Entries), len(changed))
|
||||
// A module entering the trunk's graph is registered before the revision is said, at every kind of kept trunk revision
|
||||
// (design 47 H H-A-262, H-A-264).
|
||||
if isTrunkBranch(branch) {
|
||||
ix.registerEntering(ctx, slices.Collect(maps.Values(entries)))
|
||||
}
|
||||
if ix.SayCatalogRevision != nil {
|
||||
if err := ix.SayCatalogRevision(ctx, meshcatalog.CatalogRevisionEvent{V: CatalogEntryLayout, Revision: rev.Revision, Kind: rev.Kind,
|
||||
Branch: keys.EscapeName(branch), Source: src, At: &at, Changed: changed, Entries: int64(len(rev.Entries))}); err != nil {
|
||||
Branch: keys.EscapeName(branch), Source: src, Call: call.Call, CallKind: call.Kind, Module: call.Module, Version: call.Version,
|
||||
Repository: call.Repository, At: &at, Changed: changed, Entries: int64(len(rev.Entries))}); err != nil {
|
||||
ix.logf("catalog graph: revision %d is not said: %v", rev.Revision, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return number, nil
|
||||
}
|
||||
|
||||
// revisionCall is what made a catalog revision (design 47 H-A-213 (3), H-A-215): call, the words for a person; Kind, one of the
|
||||
// seat mesh-catalog's three call kinds, which a reader reads instead of the words; Module and Version for a release, Repository
|
||||
// for a take-in again. The zero value names no call (a revision kept by hand or a test).
|
||||
type revisionCall struct {
|
||||
Call, Kind, Module, Version, Repository string
|
||||
}
|
||||
|
||||
// takeInCall is a take-in's: the gate's call its source revision names.
|
||||
func takeInCall(call string) revisionCall {
|
||||
return revisionCall{Call: call, Kind: meshcatalog.CatalogRevisionCallKindTakeIn}
|
||||
}
|
||||
|
||||
// releaseCall is a re-pin's on the release of module at version (H-A-213 (2)).
|
||||
func releaseCall(module, version string) revisionCall {
|
||||
return revisionCall{Call: ReleaseCall(module, version), Kind: meshcatalog.CatalogRevisionCallKindRelease, Module: module, Version: version}
|
||||
}
|
||||
|
||||
// takeInAgainCall is a take-in again's of repository (H-A-212).
|
||||
func takeInAgainCall(repository string) revisionCall {
|
||||
return revisionCall{Call: TakeInAgainCall(repository), Kind: meshcatalog.CatalogRevisionCallKindTakeInAgain, Repository: repository}
|
||||
}
|
||||
|
||||
// recomputeCall is a recompute's that moved a fingerprint, its call naming the reason (H-A-217).
|
||||
func recomputeCall(reason string) revisionCall {
|
||||
return revisionCall{Call: RecomputeCall(reason), Kind: meshcatalog.CatalogRevisionCallKindRecompute}
|
||||
}
|
||||
|
||||
// RecomputeCall is the call of the catalog revision a recompute keeps: its reason, such as the assignments of a build module,
|
||||
// a toolchain or a hand act (design 47 H-A-217).
|
||||
func RecomputeCall(reason string) string { return "recompute on " + reason }
|
||||
|
||||
// HeldObjectsFull is the reason a pending merge is held while the catalog graph revisions are full (Pending.Held).
|
||||
const HeldObjectsFull = "objects full"
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ func (ix *Indexer) dry() *dryRun {
|
||||
// requirements, findings, seat definitions, holds and their bounds are not overlaid, nothing is said, and no hold is
|
||||
// weighed (Holds and Counted nil hold nothing); ReadFile only reads.
|
||||
Requirements: nil, Findings: nil, SeatDefinitions: nil, ReadFile: ix.ReadFile, SaySeatDefinition: nil,
|
||||
Heard: nil, underSeats: true,
|
||||
Heard: nil, underSeats: true, isDry: true,
|
||||
// A dry run keeps no catalog graph revision (catalog_revisions.go): its revision is the take-in's to keep.
|
||||
Revisions: nil, SayCatalogRevision: nil, SayFill: nil, EntryIndex: nil, NamedSets: nil, Versions: nil, SayVersionReleased: nil, SayVersionsFilled: nil, Inputs: nil, InputObjects: nil, Pins: nil, PinsPending: nil,
|
||||
// A dry run writes no registration and asks no one.
|
||||
|
||||
@@ -21,6 +21,8 @@ const (
|
||||
EntryIndexState = "entry-index"
|
||||
// EntryIndexTool is the tool that reads a fingerprint's key and its object's digest (class read).
|
||||
EntryIndexTool = "indexer_entries"
|
||||
// EntryPinsTool is the tool that reads one module's entry pins and paths at a trunk revision (class read; H-A-204).
|
||||
EntryPinsTool = "indexer_entry"
|
||||
)
|
||||
|
||||
// EntryIndexValue is one key of entry-index: the digest of the entry object of the fingerprint the key names.
|
||||
|
||||
@@ -49,7 +49,7 @@ func TestAKeptRevisionIndexesItsEntries(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
fp := "src2:" + strings.Repeat("d", 64)
|
||||
ix := &Indexer{Module: testSelf, Revisions: newMemObjects(1 << 20), EntryIndex: newMem(), Now: func() time.Time { return time.Date(2026, 11, 1, 3, 0, 0, 0, time.UTC) }}
|
||||
if err := ix.keepBranchEntries(ctx, TrunkBranch, 1, map[string]meshcatalog.CatalogEntry{"avahi": {Module: "avahi", Repository: "novox/r", Commit: "c", Fp: fp, Manifest: map[string]any{}}}, nil); err != nil {
|
||||
if err := ix.KeepBranchEntries(ctx, TrunkBranch, 1, map[string]meshcatalog.CatalogEntry{"avahi": {Module: "avahi", Repository: "novox/r", Commit: "c", Fp: fp, Manifest: map[string]any{}}}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got, err := Entry(ctx, ix.Revisions, ix.EntryIndex, meshcatalog.EntryInput{Fingerprint: fp}); err != nil || got.Entry.Module != "avahi" {
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
package index
|
||||
|
||||
import (
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient/heard"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
)
|
||||
|
||||
// Design 47 H H-A-240, H-A-242, H-A-247, G §580: every finding kind the daemon's code raises or clears is one its writer owns
|
||||
// (FindingKinds, and a views reader's views.ViewKinds), so the writer never refuses a kind of the indexer's own. The test
|
||||
// reads the daemon's code (this package and cmd/mesh-delivery-indexer) for every place a kind is given to the writer: the
|
||||
// kind argument of observed, finding, clearFinding, clearHeld and a writer's Clear, the Kind of a Finding literal, and the
|
||||
// kinds of an SDK part handed the writer (partKinds). mcc.KindCallUnanswered stays readable, so a return to the tool runner's
|
||||
// kind fails the test. A
|
||||
// kind there is a string, a constant of the package or a constant named in imported below; any other form fails the test,
|
||||
// naming its place, but for the pass-through parameter `kind`, a held finding's `.Kind` and the kind cut from a key a views
|
||||
// reader names, which carry a kind given elsewhere.
|
||||
func TestFindingKindsHoldEveryKindTheCodeRaises(t *testing.T) {
|
||||
imported := map[string]string{"mcc.KindCallUnanswered": mcc.KindCallUnanswered, "views.ViewWaitsKind": views.ViewWaitsKind}
|
||||
// kindArg is the place of the kind among a raising call's arguments.
|
||||
kindArg := map[string]int{"observed": 2, "finding": 2, "clearFinding": 3, "clearHeld": 4, "Clear": 3}
|
||||
// partKinds are the kinds each SDK part raises through the writer it is handed (H-A-247 (1)); handed says a literal's field
|
||||
// gives it the writer.
|
||||
partKinds := map[string][]string{"views.ProcessReader": {views.EventUnhandledKind}, "views.Emitter": {views.UnsaidKind, views.TooLargeKind},
|
||||
"heard.Writer": {heard.Kind}}
|
||||
handed := func(e ast.Expr) bool {
|
||||
kv, ok := e.(*ast.KeyValueExpr)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
id, ok := kv.Key.(*ast.Ident)
|
||||
return ok && (id.Name == "Findings" || id.Name == "Put")
|
||||
}
|
||||
fset := token.NewFileSet()
|
||||
var files []*ast.File
|
||||
consts := map[string]string{}
|
||||
for _, dir := range []string{".", filepath.Join("..", "..", "cmd", "mesh-delivery-indexer")} {
|
||||
entries, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, e := range entries {
|
||||
if !strings.HasSuffix(e.Name(), ".go") || strings.HasSuffix(e.Name(), "_test.go") {
|
||||
continue
|
||||
}
|
||||
f, err := parser.ParseFile(fset, filepath.Join(dir, e.Name()), nil, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
files = append(files, f)
|
||||
if dir != "." {
|
||||
continue
|
||||
}
|
||||
for _, d := range f.Decls {
|
||||
g, ok := d.(*ast.GenDecl)
|
||||
if !ok || g.Tok != token.CONST {
|
||||
continue
|
||||
}
|
||||
for _, s := range g.Specs {
|
||||
v := s.(*ast.ValueSpec)
|
||||
for i, n := range v.Names {
|
||||
if i < len(v.Values) {
|
||||
if l, ok := v.Values[i].(*ast.BasicLit); ok && l.Kind == token.STRING {
|
||||
consts[n.Name], _ = strconv.Unquote(l.Value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
declared := append(slices.Clone(FindingKinds), views.ViewKinds...)
|
||||
raised := map[string]string{} // kind -> a place it is raised
|
||||
kindOf := func(e ast.Expr) (string, bool) {
|
||||
switch x := e.(type) {
|
||||
case *ast.BasicLit:
|
||||
s, err := strconv.Unquote(x.Value)
|
||||
return s, err == nil
|
||||
case *ast.Ident:
|
||||
if x.Name == "kind" {
|
||||
return "", true // a pass-through parameter: its callers give the kind
|
||||
}
|
||||
s, ok := consts[x.Name]
|
||||
if !ok {
|
||||
s, ok = imported["index."+x.Name]
|
||||
}
|
||||
return s, ok
|
||||
case *ast.SliceExpr:
|
||||
return "", true // the kind of a key a views reader names: its own kinds (views.ViewKinds)
|
||||
case *ast.SelectorExpr:
|
||||
if x.Sel.Name == "Kind" {
|
||||
return "", true // a held finding's kind, given when it was raised
|
||||
}
|
||||
if p, ok := x.X.(*ast.Ident); ok {
|
||||
if p.Name == "index" {
|
||||
s, ok := consts[x.Sel.Name]
|
||||
return s, ok
|
||||
}
|
||||
s, ok := imported[p.Name+"."+x.Sel.Name]
|
||||
return s, ok
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
note := func(e ast.Expr) {
|
||||
k, ok := kindOf(e)
|
||||
if !ok {
|
||||
t.Errorf("%s: a finding kind the test cannot read; give it as a constant (or name it in imported)", fset.Position(e.Pos()))
|
||||
return
|
||||
}
|
||||
if k != "" {
|
||||
raised[k] = fset.Position(e.Pos()).String()
|
||||
}
|
||||
}
|
||||
for _, f := range files {
|
||||
ast.Inspect(f, func(n ast.Node) bool {
|
||||
switch x := n.(type) {
|
||||
case *ast.CallExpr:
|
||||
var name string
|
||||
switch fn := x.Fun.(type) {
|
||||
case *ast.Ident:
|
||||
name = fn.Name
|
||||
case *ast.SelectorExpr:
|
||||
name = fn.Sel.Name
|
||||
}
|
||||
if i, ok := kindArg[name]; ok && len(x.Args) > i {
|
||||
if name == "Clear" && len(x.Args) != 5 {
|
||||
return true // not a finding writer's Clear(ctx, scope, id, kind, why)
|
||||
}
|
||||
note(x.Args[i])
|
||||
}
|
||||
case *ast.CompositeLit:
|
||||
// an SDK part handed the writer raises its own kinds through it (H-A-247 (1))
|
||||
if s, ok := x.Type.(*ast.SelectorExpr); ok && slices.ContainsFunc(x.Elts, handed) {
|
||||
if p, ok := s.X.(*ast.Ident); ok && p.Name != "index" { // the indexer's own code is read above
|
||||
part := p.Name + "." + s.Sel.Name
|
||||
if kinds, ok := partKinds[part]; ok {
|
||||
for _, k := range kinds {
|
||||
raised[k] = fset.Position(x.Pos()).String() + " (" + part + ")"
|
||||
}
|
||||
} else {
|
||||
t.Errorf("%s: %s is handed the finding writer, and the test does not know its kinds: name them in partKinds",
|
||||
fset.Position(x.Pos()), part)
|
||||
}
|
||||
}
|
||||
}
|
||||
if s, ok := x.Type.(*ast.SelectorExpr); ok && s.Sel.Name == "Finding" {
|
||||
for _, el := range x.Elts {
|
||||
if kv, ok := el.(*ast.KeyValueExpr); ok {
|
||||
if id, ok := kv.Key.(*ast.Ident); ok && id.Name == "Kind" {
|
||||
note(kv.Value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
for _, k := range []string{PinMissingKind, OutOfStepKind, PackagesNotPublishedKind, CallUnansweredKind, views.EventUnhandledKind, heard.Kind} {
|
||||
if _, ok := raised[k]; !ok {
|
||||
t.Errorf("the test no longer finds the kind %s the code raises: it reads the code wrongly", k)
|
||||
}
|
||||
}
|
||||
for k, at := range raised {
|
||||
if !slices.Contains(declared, k) {
|
||||
t.Errorf("%s: the code raises the finding kind %q, which the writer's list FindingKinds does not declare", at, k)
|
||||
}
|
||||
}
|
||||
// a retired kind is one no code raises and the writer does not own (H-A-247 (3))
|
||||
for _, r := range RetiredFindingKinds {
|
||||
if at, ok := raised[r.Kind]; ok || slices.Contains(declared, r.Kind) {
|
||||
t.Errorf("the retired kind %q is still declared or raised (%s)", r.Kind, at)
|
||||
}
|
||||
}
|
||||
// H-A-249: the retired call-unanswered names the ids the indexer's unanswered calls are written under, as in a key
|
||||
covers := func(scope, id string) bool {
|
||||
for _, r := range RetiredFindingKinds {
|
||||
if r.Kind == mcc.KindCallUnanswered && (r.Scope == "" || r.Scope == scope) && (slices.Contains(r.IDs, id) ||
|
||||
slices.ContainsFunc(r.Prefixes, func(p string) bool { return strings.HasPrefix(id, p) })) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
for _, id := range []string{keyID("node-build-go." + StepsVerb), keyID("node-build-image." + StepsVerb), keyID(floorKey("mesh-tools")),
|
||||
keyID(BuilderVersionsCall)} {
|
||||
if !covers(mcc.ScopeCall, id) {
|
||||
t.Errorf("the retired call-unanswered does not cover the indexer's id %s", id)
|
||||
}
|
||||
}
|
||||
// the approval gate's findings: scope machine, id <node>=2e<ask>
|
||||
if covers("machine", "novox=2eask-1") || covers("machine", "node-build-go.steps") || covers(mcc.ScopeCall, "novox=2eask-1") {
|
||||
t.Error("the retired call-unanswered covers an id of the tool runner's")
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,9 @@ import (
|
||||
"context"
|
||||
|
||||
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient/heard"
|
||||
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
)
|
||||
|
||||
// FindingsState is the indexer's state of its findings (design 47 G §383, §687).
|
||||
@@ -12,6 +14,26 @@ const (
|
||||
FindingsState = "findings"
|
||||
)
|
||||
|
||||
// CallUnansweredKind is the indexer's finding of a call nobody answered within its bound (scope call, its id the call): a kind
|
||||
// of its own, since the tool runner's writer over the same state owns call-unanswered (design 47 H H-A-247 (2)).
|
||||
const CallUnansweredKind = "indexer-call-unanswered"
|
||||
|
||||
// FindingKinds are the finding kinds the indexer's daemon raises, the kinds its writer owns (design 47 G §580, H H-A-240,
|
||||
// H-A-242, H-A-247): its own, the process reader's event-unhandled and the family-not-heard of the heard writer it is handed
|
||||
// (H-A-247 (1)); a views reader's and the emitter's (views.ViewKinds) are always the writer's besides. The tool runner's
|
||||
// writer over the same state `findings` owns its own. TestFindingKindsHoldEveryKindTheCodeRaises holds the code to this list.
|
||||
var FindingKinds = []string{PinMissingKind, OutOfStepKind, PackagesNotPublishedKind, HistoryFillingKind, SeedWaitsKind,
|
||||
SeedLeftOutKind, SeatDefinitionUnparsedKind, SeatDefinedTwiceKind, SeatOutsideItsDomainKind, CallUnansweredKind,
|
||||
views.EventUnhandledKind, heard.Kind}
|
||||
|
||||
// RetiredFindingKinds are kinds no code of the indexer raises any more, which its writer clears once at its start (H-A-247
|
||||
// (3)): merge-untaken went with H-A-82; call-unanswered became indexer-call-unanswered (H-A-247 (2)), and since the tool
|
||||
// runner's writer owns call-unanswered in the same state, only the ids the indexer wrote under it, in scope call, are cleared (H-A-249):
|
||||
// the seed's <build seat>.steps (every build seat is named node-build-<kind>), the floor's mesh-catalog.versions-floor.<module>
|
||||
// and the versions fill's mesh-delivery-builder.builder_versions.
|
||||
var RetiredFindingKinds = []views.RetiredKind{{Kind: "merge-untaken"}, {Kind: mcc.KindCallUnanswered, Scope: mcc.ScopeCall,
|
||||
IDs: []string{keyID(BuilderVersionsCall)}, Prefixes: []string{"node-build-", keyID(FloorCall) + "."}}}
|
||||
|
||||
// FindingWriter is the indexer's finding writer, mesh-sdk's held writer of the seat mesh-conditions' generated finding (design
|
||||
// 47 G A-29, A-38): Write raises a finding, Clear clears one, Held answers the findings it holds, so the indexer reads what
|
||||
// stands from the writer.
|
||||
|
||||
@@ -0,0 +1,246 @@
|
||||
package index
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
|
||||
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
)
|
||||
|
||||
// seedSteps are the seed's module-wide statuses (§8, design 47 H §745): the statuses the check judged until then, lint, unit
|
||||
// tests, integration tests, composition and validate required, code review optional, approval bypass.
|
||||
func seedSteps() meshcatalog.StepStatuses {
|
||||
return meshcatalog.StepStatuses{Lint: "required", Unit: "required", Integration: "required",
|
||||
Composition: "required", Review: "optional", Approval: "bypass", Validate: "required"}
|
||||
}
|
||||
|
||||
// GraphModule is a module of a trunk revision's module graph as its registration is composed when it enters the graph
|
||||
// (design 47 H H-A-262): its repository, the path of its manifest and the names of its artifacts.
|
||||
type GraphModule struct {
|
||||
Module string
|
||||
Origin string
|
||||
Path string
|
||||
Artifacts []string
|
||||
// LeftOut says why the seed left the module out (its finding seed-left-out, A-324): such a module is not registered by
|
||||
// the graph (H-A-265 (2)). Empty: it is registered.
|
||||
LeftOut string
|
||||
}
|
||||
|
||||
// GraphModulesOf are the modules of a trunk revision's entries, sorted by module.
|
||||
func GraphModulesOf(entries []meshcatalog.CatalogEntry) []GraphModule {
|
||||
out := make([]GraphModule, 0, len(entries))
|
||||
for _, e := range entries {
|
||||
m := GraphModule{Module: e.Module, Origin: e.Repository, Path: path.Join(e.Path, ModuleManifest)}
|
||||
for _, a := range e.Artifacts {
|
||||
m.Artifacts = append(m.Artifacts, artifactName(a.Ref))
|
||||
}
|
||||
out = append(out, m)
|
||||
}
|
||||
slices.SortFunc(out, func(a, b GraphModule) int { return strings.Compare(a.Module, b.Module) })
|
||||
return out
|
||||
}
|
||||
|
||||
// enteringPolicy is the policy of a module entering the graph (H-A-262, H-A-263): the module-wide steps every other
|
||||
// registered module of its repository holds alike, else the seed's; a per-artifact status only for an artifact name the module
|
||||
// has that every sibling naming it holds identically; nothing else.
|
||||
func enteringPolicy(m GraphModule, siblings []meshcatalog.Registration) meshcatalog.Policy {
|
||||
p := meshcatalog.Policy{Steps: seedSteps()}
|
||||
if len(siblings) > 0 {
|
||||
alike := true
|
||||
for _, s := range siblings[1:] {
|
||||
alike = alike && s.Policy.Steps == siblings[0].Policy.Steps
|
||||
}
|
||||
if alike {
|
||||
p.Steps = siblings[0].Policy.Steps
|
||||
}
|
||||
}
|
||||
for _, a := range m.Artifacts {
|
||||
var held []meshcatalog.StepStatuses
|
||||
for _, s := range siblings {
|
||||
if st, ok := s.Policy.Artifacts[a]; ok {
|
||||
held = append(held, st)
|
||||
}
|
||||
}
|
||||
if len(held) == 0 || slices.ContainsFunc(held[1:], func(st meshcatalog.StepStatuses) bool { return st != held[0] }) {
|
||||
continue
|
||||
}
|
||||
if p.Artifacts == nil {
|
||||
p.Artifacts = map[string]meshcatalog.StepStatuses{}
|
||||
}
|
||||
p.Artifacts[a] = held[0]
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
// RegisterEntering registers every module of mods that has no registration (design 47 H H-A-262 to H-A-266; the operator,
|
||||
// 2026-11-14: a module in the module graph is a registration): origin its repository, path its manifest's, the branch its
|
||||
// repository's registered modules watch first alike, else the repository's default branch read through the seat git
|
||||
// (enteringBranch), the policy of its repository's other registered modules (enteringPolicy), version 1 with no ask, said
|
||||
// registration-changed. A module already registered is left as it is, and none is ever removed here. Skipped, each said in the
|
||||
// journal: a module with a register proposal pending (its ask stands, H-A-265 (1)), one the seed left out (LeftOut, H-A-265
|
||||
// (2)), and one whose default branch is not read (registered at the next kept revision, H-A-266). While no registration is
|
||||
// held it registers none: the seed writes the first (H-A-264 (2)). It answers the modules it registered, sorted.
|
||||
func (r *Registry) RegisterEntering(ctx context.Context, mods []GraphModule, by string) ([]string, error) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
// One listing finds the modules with no registration; the registrations themselves are read only when one has none.
|
||||
keys, err := r.Registrations.Keys(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the registrations are not listed: %w", err)
|
||||
}
|
||||
if len(keys) == 0 {
|
||||
// With none held, the seed is the first and only writer: its policy reads the build seats' steps (H-A-264 (2)).
|
||||
r.logf("registrations: none is held, so no module entering the module graph is registered here: the seed writes the first (H-A-264)")
|
||||
return nil, nil
|
||||
}
|
||||
listed := map[string]bool{}
|
||||
for _, k := range keys {
|
||||
listed[k] = true
|
||||
}
|
||||
var entering []GraphModule
|
||||
for _, m := range mods {
|
||||
if m.Module != "" && !listed[RegistrationKey(m.Module)] {
|
||||
entering = append(entering, m)
|
||||
}
|
||||
}
|
||||
if len(entering) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
held, err := r.RegistrationsAnswer(ctx, meshcatalog.RegistrationsInput{})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the registrations are not read: %w", err)
|
||||
}
|
||||
have := map[string]bool{}
|
||||
byOrigin := map[string][]meshcatalog.Registration{}
|
||||
for _, reg := range held.Registrations {
|
||||
have[reg.Module] = true
|
||||
byOrigin[reg.Origin] = append(byOrigin[reg.Origin], reg)
|
||||
}
|
||||
var written []string
|
||||
var errs []string
|
||||
for _, m := range entering {
|
||||
if have[m.Module] {
|
||||
continue
|
||||
}
|
||||
if m.LeftOut != "" {
|
||||
r.logf("registrations: %s entered the module graph and is not registered: the seed left it out (%s), so it keeps seed-left-out (H-A-265)", m.Module, m.LeftOut)
|
||||
continue
|
||||
}
|
||||
if p, _, found, err := r.load(ctx, ProposalKey(verbRegister, m.Module, "")); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%s: its register proposal is not read: %v", m.Module, err))
|
||||
continue
|
||||
} else if found && p.State == ProposalOpen {
|
||||
r.logf("registrations: %s entered the module graph with a register proposal pending (ask %s): it is not registered here, the operator's Approve registers it (H-A-265)", m.Module, p.Ask)
|
||||
continue
|
||||
}
|
||||
branch, err := r.enteringBranch(m.Origin, byOrigin[m.Origin])
|
||||
if err != nil {
|
||||
r.logf("registrations: %s entered the module graph and is not registered now: %v; the next kept trunk revision registers it (H-A-266)", m.Module, err)
|
||||
continue
|
||||
}
|
||||
reg := meshcatalog.Registration{Module: m.Module, Origin: m.Origin, Path: m.Path, Branches: []string{branch},
|
||||
Policy: enteringPolicy(m, byOrigin[m.Origin])}
|
||||
p := Proposal{V: 1, Verb: verbRegister, Module: m.Module, Caller: by, At: r.now(), State: ProposalOpen,
|
||||
Lines: []string{fmt.Sprintf("%s: registered as it entered the module graph (%s, %s)", m.Module, m.Origin, m.Path)}}
|
||||
if err := r.write(ctx, "", p, reg, oc.Warrant{Ask: "module-graph"}); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%s: %v", m.Module, err))
|
||||
continue
|
||||
}
|
||||
have[m.Module] = true
|
||||
written = append(written, m.Module)
|
||||
r.logf("registrations: %s entered the module graph of %s with no registration: registered as version 1 from %s (%s), watching %s (H-A-262)",
|
||||
m.Module, TrunkBranch, m.Origin, m.Path, branch)
|
||||
}
|
||||
if len(errs) > 0 {
|
||||
return written, fmt.Errorf("the registrations of modules entering the module graph are not written: %s", strings.Join(errs, "; "))
|
||||
}
|
||||
return written, nil
|
||||
}
|
||||
|
||||
// enteringBranch is the branch a module entering the graph watches (H-A-265 (3), H-A-266): the first watched branch every
|
||||
// registered module of its repository holds alike, else the repository's default branch as the seed reads it from the seat
|
||||
// git; an error when that is not read.
|
||||
func (r *Registry) enteringBranch(origin string, siblings []meshcatalog.Registration) (string, error) {
|
||||
first := ""
|
||||
alike := len(siblings) > 0
|
||||
for _, s := range siblings {
|
||||
if len(s.Branches) == 0 || (first != "" && s.Branches[0] != first) {
|
||||
alike = false
|
||||
break
|
||||
}
|
||||
first = s.Branches[0]
|
||||
}
|
||||
if alike && first != "" {
|
||||
return first, nil
|
||||
}
|
||||
if r.Branch == nil {
|
||||
return "", fmt.Errorf("the default branch of %s is not asked of the seat git", origin)
|
||||
}
|
||||
b, err := r.Branch(origin, "")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("the seat git does not answer the default branch of %s: %w", origin, err)
|
||||
}
|
||||
if b.Error != "" || b.Branch == "" {
|
||||
return "", fmt.Errorf("the default branch of %s is not read: %s", origin, b.Error)
|
||||
}
|
||||
return b.Branch, nil
|
||||
}
|
||||
|
||||
// registerEntering registers each module of a kept trunk revision's entries that has no registration (H-A-262, H-A-264 (1),
|
||||
// (3)): a module entering the trunk's graph, at any kind of kept trunk revision. A dry run, or an indexer with no
|
||||
// registrations, registers none. A failure is said in the journal: the revision is kept whatever it answers.
|
||||
func (ix *Indexer) registerEntering(ctx context.Context, entries []meshcatalog.CatalogEntry) {
|
||||
if ix.isDry || ix.Registry == nil || ix.Registry.Registrations == nil {
|
||||
return
|
||||
}
|
||||
written, err := ix.Registry.RegisterEntering(ctx, ix.withLeftOut(GraphModulesOf(entries)), ix.Registry.Module)
|
||||
if len(written) > 0 {
|
||||
ix.logf("registrations: %d modules entering the module graph of %s registered: %s (H-A-262)", len(written), TrunkBranch, strings.Join(written, ", "))
|
||||
}
|
||||
if err != nil {
|
||||
ix.logf("registrations: %v (H-A-262)", err)
|
||||
}
|
||||
}
|
||||
|
||||
// RegisterTrunkGraph registers, once at the indexer's start, each module of the current trunk graph that has no registration
|
||||
// (H-A-264 (1)), as a kept trunk revision does; it answers the modules it registered.
|
||||
func (ix *Indexer) RegisterTrunkGraph(ctx context.Context) ([]string, error) {
|
||||
if ix.isDry || ix.Registry == nil || ix.Registry.Registrations == nil || ix.Revisions == nil {
|
||||
return nil, nil
|
||||
}
|
||||
_, entries, found, err := readNewestOf(ctx, ix.Revisions, TrunkBranch)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the newest trunk revision is not read: %w", err)
|
||||
}
|
||||
if !found {
|
||||
return nil, nil
|
||||
}
|
||||
return ix.Registry.RegisterEntering(ctx, ix.withLeftOut(GraphModulesOf(entries)), ix.Registry.Module)
|
||||
}
|
||||
|
||||
// withLeftOut marks each module the indexer holds the finding seed-left-out of (A-324, H-A-265 (2)).
|
||||
func (ix *Indexer) withLeftOut(mods []GraphModule) []GraphModule {
|
||||
if ix.Findings == nil {
|
||||
return mods
|
||||
}
|
||||
left := map[string]string{}
|
||||
for _, f := range ix.Findings.Held() {
|
||||
if f.Kind == SeedLeftOutKind && f.Scope == mcc.ScopeModule {
|
||||
left[f.ID] = f.Summary
|
||||
}
|
||||
}
|
||||
for i := range mods {
|
||||
if why, ok := left[keyID(mods[i].Module)]; ok {
|
||||
if why == "" {
|
||||
why = "seed-left-out"
|
||||
}
|
||||
mods[i].LeftOut = why
|
||||
}
|
||||
}
|
||||
return mods
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user