node-engine: compose-candidate reads a branch pipeline's catalog revision through mesh-catalog.revision and composes it as the candidate (A-226b)
Builds: design 47 G (G-22 lead answers 2) A-226b; ADR 0593 §7
This commit is contained in:
@@ -9,6 +9,8 @@ import (
|
||||
"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-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
"github.com/novox/mesh-host/internal/buckets"
|
||||
engcomp "github.com/novox/mesh-host/internal/compositions"
|
||||
"maps"
|
||||
@@ -143,35 +145,55 @@ func (s *Shadow) composeCandidate(ctx context.Context, c *Composer, ask nodeengi
|
||||
a.Verdict = nec.Unready
|
||||
return a
|
||||
}
|
||||
group, heads, err := nec.ParseCompositionKey(ask.Candidate)
|
||||
key, err := nec.ParseCandidateKey(ask.Candidate)
|
||||
if err != nil {
|
||||
return refuse(err.Error())
|
||||
}
|
||||
// The ask names the check (the composition key, `<group>.<heads hash>`); the indexer keys the group's candidate by
|
||||
// the group alone (buckets.CandidateKey) and holds its heads hash in the value.
|
||||
ckey, err := buckets.CandidateKey(group)
|
||||
if err != nil {
|
||||
return refuse(err.Error())
|
||||
if key.Kind == nec.CandidateRun {
|
||||
// A run on request's candidate is named by `run-<id>` (A-226b); the node-engine reads none yet.
|
||||
return refuse("the node-engine reads no run on request's candidate yet: " + ask.Candidate)
|
||||
}
|
||||
if !s.ready.Load() {
|
||||
return unready(errNotReady.Error())
|
||||
}
|
||||
base := run.add(c.scratch())
|
||||
raw, err := base.get(ctx, buckets.Candidates, ckey)
|
||||
if err != nil {
|
||||
return unready(fmt.Sprintf("the indexer's candidate %s cannot be read: %v", ask.Candidate, err))
|
||||
}
|
||||
if raw == nil {
|
||||
return refuse("the indexer holds no candidate " + ask.Candidate)
|
||||
}
|
||||
cand, err := meshcatalog.DecodeCandidatesByGroupValue(raw)
|
||||
if err != nil {
|
||||
return refuse(fmt.Sprintf("the indexer's candidate %s cannot be read: %v", ask.Candidate, err))
|
||||
}
|
||||
if cand.Heads != heads {
|
||||
// The group moved to other heads: the check asked is replaced, and this node composes not a candidate it was
|
||||
// not asked about. No answer (ADR 0593 §9), never a verdict on the wrong heads.
|
||||
return unready(fmt.Sprintf("the indexer's candidate of the group %s is at heads %s, not %s: the check asked is replaced", group, cand.Heads, heads))
|
||||
var cand meshcatalog.CandidatesByGroupValue
|
||||
var group, heads string
|
||||
if key.Kind == nec.CandidateRevision {
|
||||
// A branch pipeline's catalog graph revision (A-226b): its entries are read through the seat mesh-catalog's verb
|
||||
// revision and composed as the candidate, each module at the revision's fingerprint.
|
||||
var answered bool
|
||||
cand, answered, err = s.revisionCandidate(ctx, base, key)
|
||||
if err != nil {
|
||||
return unready(err.Error())
|
||||
}
|
||||
if !answered {
|
||||
return refuse(fmt.Sprintf("the catalog holds no revision %d of the branch %s", key.Revision, key.Branch))
|
||||
}
|
||||
} else {
|
||||
group, heads = key.Group, key.HeadsHash
|
||||
// The ask names the check (the composition key, `<group>.<heads hash>`); the indexer keys the group's candidate by
|
||||
// the group alone (buckets.CandidateKey) and holds its heads hash in the value.
|
||||
ckey, err := buckets.CandidateKey(group)
|
||||
if err != nil {
|
||||
return refuse(err.Error())
|
||||
}
|
||||
raw, err := base.get(ctx, buckets.Candidates, ckey)
|
||||
if err != nil {
|
||||
return unready(fmt.Sprintf("the indexer's candidate %s cannot be read: %v", ask.Candidate, err))
|
||||
}
|
||||
if raw == nil {
|
||||
return refuse("the indexer holds no candidate " + ask.Candidate)
|
||||
}
|
||||
cand, err = meshcatalog.DecodeCandidatesByGroupValue(raw)
|
||||
if err != nil {
|
||||
return refuse(fmt.Sprintf("the indexer's candidate %s cannot be read: %v", ask.Candidate, err))
|
||||
}
|
||||
if cand.Heads != heads {
|
||||
// The group moved to other heads: the check asked is replaced, and this node composes not a candidate it was
|
||||
// not asked about. No answer (ADR 0593 §9), never a verdict on the wrong heads.
|
||||
return unready(fmt.Sprintf("the indexer's candidate of the group %s is at heads %s, not %s: the check asked is replaced", group, cand.Heads, heads))
|
||||
}
|
||||
}
|
||||
// Every module's manifest is read before either composition, several at once, into the shadow's own: a composition
|
||||
// reads every manifest in the mesh one by one, which off the control-node took about 35 s each (issue 1126).
|
||||
@@ -481,3 +503,69 @@ func (c *Composer) composeShadow(ctx context.Context, running []engcomp.Composed
|
||||
// candidateNoneNoModule is the words the indexer writes in a candidate's module that the merge preview names no manifest
|
||||
// for: the change removes the module. It is the indexer's text, kept here until the catalogue client names it.
|
||||
const candidateNoneNoModule = "the merge preview names no manifest for the module's directory"
|
||||
|
||||
// revisionCandidate reads the catalog graph revision key names, whole, page by page, through the seat mesh-catalog's verb
|
||||
// revision (the Entry call, the engine's own name), and makes the candidate it composes as: one pull per repository and
|
||||
// commit with each module's fingerprint and manifest digest, and a module the base holds that the revision does not marked as
|
||||
// removed. answered is false when the catalog holds no such revision.
|
||||
func (s *Shadow) revisionCandidate(ctx context.Context, base *Composer, key nec.Candidate) (cand meshcatalog.CandidatesByGroupValue, answered bool, err error) {
|
||||
call := base.env.Entry
|
||||
if call == nil {
|
||||
return cand, false, errors.New("this node's engine cannot ask the catalog for a revision")
|
||||
}
|
||||
in := meshcatalog.RevisionInput{Branch: keys.EscapeName(key.Branch), Revision: key.Revision}
|
||||
type group struct{ repository, commit string }
|
||||
pulls := map[group]map[string]meshcatalog.CandidatesByGroupValuePullsItemFpsValue{}
|
||||
seen := map[string]bool{}
|
||||
for {
|
||||
raw, err := call(meshcatalogclient.RevisionVerb, in)
|
||||
if err != nil {
|
||||
return cand, false, fmt.Errorf("the catalog's revision %d of %s cannot be read: %w", key.Revision, key.Branch, err)
|
||||
}
|
||||
body, said, ok := buscalls.Unwrap(raw)
|
||||
if !ok {
|
||||
return cand, false, fmt.Errorf("the catalog's revision %d of %s cannot be read: %s", key.Revision, key.Branch, said)
|
||||
}
|
||||
var a meshcatalog.RevisionAnswer
|
||||
if err := json.Unmarshal(body, &a); err != nil {
|
||||
return cand, false, fmt.Errorf("the catalog's revision %d of %s is not a revision answer: %w", key.Revision, key.Branch, err)
|
||||
}
|
||||
if a.NoneYet || a.Revision == nil || a.Revision.Revision != key.Revision {
|
||||
return cand, false, nil
|
||||
}
|
||||
for _, e := range a.Entries {
|
||||
seen[e.Module] = true
|
||||
if e.Fp == "" {
|
||||
continue // no build at the revision: composed as the trunk holds it
|
||||
}
|
||||
g := group{e.Repository, e.Commit}
|
||||
if pulls[g] == nil {
|
||||
pulls[g] = map[string]meshcatalog.CandidatesByGroupValuePullsItemFpsValue{}
|
||||
}
|
||||
pulls[g][e.Module] = meshcatalog.CandidatesByGroupValuePullsItemFpsValue{Fp2: e.Fp, Manifest: e.ManifestDigest}
|
||||
}
|
||||
if a.Next == "" {
|
||||
break
|
||||
}
|
||||
in.After = a.Next
|
||||
}
|
||||
removed := map[string]meshcatalog.CandidatesByGroupValuePullsItemFpsValue{}
|
||||
base.mu.Lock()
|
||||
for module := range base.modules {
|
||||
if !seen[module] {
|
||||
removed[module] = meshcatalog.CandidatesByGroupValuePullsItemFpsValue{None2: candidateNoneNoModule}
|
||||
}
|
||||
}
|
||||
base.mu.Unlock()
|
||||
cand.Group = key.Branch
|
||||
for g, fps := range pulls {
|
||||
cand.Pulls = append(cand.Pulls, meshcatalog.CandidatesByGroupValuePullsItem{Repository: g.repository, Head: g.commit, Fps: fps})
|
||||
}
|
||||
sort.Slice(cand.Pulls, func(i, j int) bool {
|
||||
return cand.Pulls[i].Repository+cand.Pulls[i].Head < cand.Pulls[j].Repository+cand.Pulls[j].Head
|
||||
})
|
||||
if len(removed) > 0 {
|
||||
cand.Pulls = append(cand.Pulls, meshcatalog.CandidatesByGroupValuePullsItem{Fps: removed})
|
||||
}
|
||||
return cand, true, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user