indexer: take-in.taken names its branch, source revision and entries; runner: one with no entries starts nothing
The pipeline runner heard every take-in.taken with branch "" and source 0 and started no pipeline, asking the bus for each again for ever: the indexer's event body never gained design 47 G §476, §493 and §648's fields. Every taken event of one take-in now names the watched branch, the source revision it makes (one above the newest seen or said, A-431) and one entry per module written; a taken event with no entries starts nothing and is journaled (§493).
This commit is contained in:
@@ -171,6 +171,7 @@ type Indexer struct {
|
||||
|
||||
mu sync.Mutex // guards source, toolchains and previews, which the watches and the forge messages all reach
|
||||
source sourceNow
|
||||
saidSource map[string]uint64 // the newest source revision a take-in.taken named, by watched branch (nextSource)
|
||||
previews map[string]meshdeliverychecker.PreviewsByRepositoryHeadTrunkValue // by previews key (previews.go)
|
||||
toolchains map[string]map[string]nodebuildgo.Toolchain // language, then node (toolchains.go)
|
||||
buildModules map[string]BuildModule // by language: the build modules whose toolchains are taken in (buildmodules.go)
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
@@ -1167,14 +1168,71 @@ func (ix *Indexer) takeInWholeBy(ctx context.Context, entries []PendingEntry, ow
|
||||
}
|
||||
}
|
||||
ix.forget(claimed...)
|
||||
ix.logf("take-in: %d merges taken in as one revision by %s%s, oldest %s", len(claimed), own, byWords(by), claimed[0].Key)
|
||||
branch, src, took := ix.takenWhat(ctx, claimed, applied)
|
||||
ix.logf("take-in: %d merges taken in as one revision by %s%s, oldest %s: source revision %d of %s, %d entries", len(claimed), own, byWords(by), claimed[0].Key, src, branch, len(took))
|
||||
for _, t := range takenWaits(claimed) {
|
||||
t.By, t.Why = who, why
|
||||
t.Branch, t.Source, t.Entries = branch, src, took
|
||||
ix.sayTakeIn(ctx, t)
|
||||
}
|
||||
return applied, nil
|
||||
}
|
||||
|
||||
// takenWhat is what one take-in took in (design 47 G §476, §493, §648): the watched branch its merges landed on (the
|
||||
// trunk for a merge that names none, as before G), the source revision it makes of that branch (nextSource) and one entry
|
||||
// per module it wrote, with the commit, fingerprint and repository the catalog entry holds now and the pull request of
|
||||
// that repository's merge. A module with no fingerprint (no build) is no entry; one the view cannot read is said.
|
||||
func (ix *Indexer) takenWhat(ctx context.Context, claimed []PendingEntry, applied Applied) (string, int64, []meshcatalog.TakeInEntry) {
|
||||
branch := TrunkBranch
|
||||
pulls := map[string]int64{}
|
||||
for _, e := range claimed {
|
||||
if e.Forge.Base != "" {
|
||||
branch = e.Forge.Base
|
||||
}
|
||||
if e.Forge.Number != 0 {
|
||||
pulls[strings.ToLower(e.Forge.Repository)] = int64(e.Forge.Number)
|
||||
}
|
||||
}
|
||||
src := ix.nextSource(branch)
|
||||
written := writtenModules(applied.Written)
|
||||
if len(written) == 0 {
|
||||
return branch, src, nil
|
||||
}
|
||||
view, err := ix.viewEntries(ctx)
|
||||
if err != nil {
|
||||
ix.logf("take-in: the entries of source revision %d of %s cannot be read, so its take-in.taken names none and starts no pipeline: %v", src, branch, err)
|
||||
return branch, src, nil
|
||||
}
|
||||
var out []meshcatalog.TakeInEntry
|
||||
for _, m := range slices.Sorted(slices.Values(written)) {
|
||||
e, ok := view[m]
|
||||
if !ok || e.Fp == "" {
|
||||
ix.logf("take-in: %s is written in source revision %d of %s with no fingerprint (%s): no pipeline entry", m, src, branch, e.None)
|
||||
continue
|
||||
}
|
||||
out = append(out, meshcatalog.TakeInEntry{Module: m, Commit: e.Commit, Fingerprint: e.Fp, Repository: e.Repository,
|
||||
Pull: pulls[strings.ToLower(e.Repository)]})
|
||||
}
|
||||
return branch, src, out
|
||||
}
|
||||
|
||||
// nextSource is the source revision a take-in of branch makes: one above the newest the indexer has seen for it (the gate's
|
||||
// source-moved, the trunk's alone held here) or named in a take-in.taken before, which the gate's source.<branch> then moves
|
||||
// to (A-34; the lead's answer A-431, principle 7).
|
||||
func (ix *Indexer) nextSource(branch string) int64 {
|
||||
ix.mu.Lock()
|
||||
defer ix.mu.Unlock()
|
||||
n := ix.saidSource[branch]
|
||||
if isTrunkBranch(branch) && ix.source.rev > n {
|
||||
n = ix.source.rev
|
||||
}
|
||||
if ix.saidSource == nil {
|
||||
ix.saidSource = map[string]uint64{}
|
||||
}
|
||||
ix.saidSource[branch] = n + 1
|
||||
return int64(n + 1)
|
||||
}
|
||||
|
||||
// takenWaits are the taken events of a take-in: every wait the entries were said under (saidWaits), every wait
|
||||
// indexer_pending names the claimed entries by now (WaitsOf: a revision by its oldest merge's key, a group by its g. key) and
|
||||
// the key of every claimed entry, since indexer_pending named it by that key earlier when it waited behind a group. So a wait
|
||||
|
||||
@@ -1007,6 +1007,16 @@ func TestTakeIn(t *testing.T) { // 1585/T3-T13 (ADR 0633)
|
||||
if len(b.keys()) != 0 || b.commit(t, "avahi") != sha('d') || len(b.said) != 1 || b.said[0].Kind != takein.TakeInTaken || b.said[0].By != "lead@shanks" {
|
||||
t.Errorf("hand take-in: pending %v, avahi at %s, said %+v", b.keys(), b.commit(t, "avahi"), b.said)
|
||||
}
|
||||
// §476, §493: a hand take-in's taken event carries the branch, the source revision it makes and its entries.
|
||||
if len(b.said) == 1 {
|
||||
got := b.said[0]
|
||||
if got.Branch != TrunkBranch || got.Source <= 0 || len(got.Entries) != 1 || got.Entries[0].Module != "avahi" ||
|
||||
got.Entries[0].Commit != sha('d') || got.Entries[0].Fingerprint == "" {
|
||||
t.Errorf("hand take-in said branch %q source %d entries %+v: want main, a source revision and avahi at its commit", got.Branch, got.Source, got.Entries)
|
||||
} else if _, err := takein.EncodeTakeIn(got); err != nil {
|
||||
t.Errorf("the taken event is refused by its own contract: %v", err)
|
||||
}
|
||||
}
|
||||
b.arrive(t, 4, b.merge(23, sha('e'), "tree-avahi-5", "tree-indexer-2"))
|
||||
if r := b.ix.DropPending(ctx, takein.PendingKey(4), "lead@shanks", "abandoned on the operator's word", true); !r.Stored || len(b.keys()) != 0 {
|
||||
t.Errorf("an abandoned drop: %+v, pending %v", r, b.keys())
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
)
|
||||
|
||||
@@ -147,6 +148,12 @@ type TakeIn struct {
|
||||
// Unknown is why the indexer holds a merge it does not take in although no indexer build is named: it cannot learn the build
|
||||
// it runs itself (ADR 0633 §1), so Since is when it began not to know. A pending revision names WaitsFor or Unknown.
|
||||
Unknown string `json:"own-build-unknown,omitempty"`
|
||||
// Branch, Source and Entries are what a take-in took in (design 47 G §476, §493, §648): the watched branch, the source
|
||||
// revision it makes of that branch, and one entry per module it wrote. Every taken event of one take-in carries the same;
|
||||
// a taken event that ends a wait without a take-in (a group's end, a drop) carries none and starts no pipeline.
|
||||
Branch string `json:"branch,omitempty"`
|
||||
Source int64 `json:"source,omitempty"`
|
||||
Entries []meshcatalog.TakeInEntry `json:"entries,omitempty"`
|
||||
}
|
||||
|
||||
func (t TakeIn) check() error {
|
||||
@@ -194,6 +201,12 @@ func (t TakeIn) check() error {
|
||||
if t.Kind != TakeInTaken && (t.By != "" || t.Why != "" || t.Dropped) {
|
||||
return fmt.Errorf("delivery: only a taken event names the hand act that ended a wait")
|
||||
}
|
||||
if t.Kind != TakeInTaken && (t.Source != 0 || len(t.Entries) > 0) {
|
||||
return fmt.Errorf("delivery: only a taken event names the source revision and the entries taken in")
|
||||
}
|
||||
if len(t.Entries) > 0 && (t.Branch == "" || t.Source <= 0) {
|
||||
return fmt.Errorf("delivery: the taken event %s names entries without its watched branch and source revision", t.Key)
|
||||
}
|
||||
if (t.Why != "" || t.Dropped) && t.By == "" {
|
||||
return fmt.Errorf("delivery: a hand act's take-in event names who acted (by)")
|
||||
}
|
||||
|
||||
@@ -436,6 +436,11 @@ func (s *Starter) TakenIn(ev catalog.TakeInTaken, view func(branch string) (Half
|
||||
s.logf("the take-in %s was dropped by %s: it starts no pipeline", ev.Key, ev.By)
|
||||
return 0, nil
|
||||
}
|
||||
if len(ev.Entries) == 0 {
|
||||
// A taken event that took nothing in (a group's end, one said before G and read again) starts nothing (§493).
|
||||
s.logf("the take-in %s names no entries: it starts no pipeline", ev.Key)
|
||||
return 0, nil
|
||||
}
|
||||
if ev.Branch == "" || ev.Source <= 0 {
|
||||
return 0, fmt.Errorf("a take-in.taken names its watched branch and source revision: key %q branch %q source %d", ev.Key, ev.Branch, ev.Source)
|
||||
}
|
||||
|
||||
@@ -118,9 +118,13 @@ func TestTakenInStarts(t *testing.T) {
|
||||
if n, err := s.TakenIn(catalog.TakeInTaken{Kind: "taken", Dropped: true, By: "op", Branch: "main", Source: 8, Entries: ev.Entries}, view); n != 0 || err != nil {
|
||||
t.Errorf("a hand drop started %d (%v)", n, err)
|
||||
}
|
||||
if _, err := s.TakenIn(catalog.TakeInTaken{Kind: "taken", Branch: "main"}, view); err == nil {
|
||||
if _, err := s.TakenIn(catalog.TakeInTaken{Kind: "taken", Branch: "main", Entries: ev.Entries}, view); err == nil {
|
||||
t.Error("a take-in naming no source revision is refused")
|
||||
}
|
||||
// §493: a taken event with no entries (a group's end, one said before G) starts nothing and is not heard again.
|
||||
if n, err := s.TakenIn(catalog.TakeInTaken{Kind: "taken", Key: "m.9"}, view); n != 0 || err != nil {
|
||||
t.Errorf("a take-in with no entries started %d (%v)", n, err)
|
||||
}
|
||||
}
|
||||
|
||||
// A-327 (design 47 G §21, §23, §54): a pipeline started before its module has a registration starts with no step; the
|
||||
|
||||
Reference in New Issue
Block a user