composer: one search for culprits, inside the node-engine's composition, bounded by blame_tries (G-24 H2 review r1)
ComposeSent no longer runs the node-engine's own culprit search (fixed at eight modules), and the composer's own loop, which reran that search at every try, is gone: ComposeSent holds the case's changed modules on the machine one at a time, one composition each, at most blame_tries, and blames the first whose hold ends the problem; past the bound the untried are named. Without blame_tries there is no search. A module the node holds composing without the change is held as there, and two owners of one path are blamed outside the search. Builds: design 47 G §721, A-468i, A-468l, A-469j, A-469k, A-470c
This commit is contained in:
@@ -75,7 +75,7 @@ func Answer(ctx context.Context, r Reader, mesh Mesh, s Scope, fps map[string]st
|
||||
return refuse(fmt.Errorf("frombus: the credentials of %s: %w", s.Node, err))
|
||||
}
|
||||
}
|
||||
composed, skipped, stood, err := composeEach(in, s.Node, fps, false, s.Running, failed, ranOf(ctx, r, mesh, s.Running, fps), nil)
|
||||
composed, skipped, stood, err := composeEach(in, s.Node, fps, false, s.Running, failed, ranOf(ctx, r, mesh, s.Running, fps), true)
|
||||
if err != nil {
|
||||
// Not one module's: the node's own (a value served elsewhere, the mesh's network), said once as the node's.
|
||||
if len(failed) == 0 {
|
||||
@@ -332,10 +332,11 @@ func standsInFor(x, node string) (string, string) {
|
||||
// (culprit): de-spiegel's routes, its names unset, leave route-proxy without them while mailu keeps its smtp account,
|
||||
// and the hold says so.
|
||||
//
|
||||
// owned, where not nil, is told each culprit held for a refusal that names paths two modules both own, with those pairs
|
||||
// (resolution.Refusal.OwnedTwice): a composer blames both owners with the path (design 47 G §721; A-468l).
|
||||
// search says a refusal is laid on a culprit (culprit). The node composing itself always searches; a composer's sandbox
|
||||
// (ComposeSent) does not, since it runs the one search for culprits itself, bounded by its request (design 47 G §721;
|
||||
// A-469j): there the first refusal no hold of the read answers is the node's (err).
|
||||
func composeEach(in compose.Input, node string, fps map[string]string, applied bool, running []compositions.Composed, failed map[string]string,
|
||||
ran func(module string) (catalogue.Manifest, bool), owned func(culprit string, twice []resolution.OwnedTwice)) (out map[string]compositions.Composed, skipped, stood []string, err error) {
|
||||
ran func(module string) (catalogue.Manifest, bool), search bool) (out map[string]compositions.Composed, skipped, stood []string, err error) {
|
||||
mode := compose.Foreseeing
|
||||
if applied {
|
||||
mode = compose.Reading
|
||||
@@ -382,13 +383,13 @@ func composeEach(in compose.Input, node string, fps map[string]string, applied b
|
||||
var leftOut map[string]string
|
||||
out, skipped, stood, leftOut, err = compose.CompositionsHolding(in, node, fps, mode)
|
||||
if err != nil {
|
||||
if !search {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
module, leave := culprit(in, node, fps, mode, failed, err)
|
||||
if module == "" {
|
||||
return nil, nil, nil, firstReason(err, failed)
|
||||
}
|
||||
if refusal := (*resolution.Refusal)(nil); owned != nil && errors.As(err, &refusal) && len(refusal.OwnedTwice) > 0 {
|
||||
owned(module, refusal.OwnedTwice)
|
||||
}
|
||||
hold(module, err.Error(), leave)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -703,7 +703,7 @@ func Compose(ctx context.Context, r Reader, mesh Mesh, s Scope, fps map[string]s
|
||||
return nil, nil, held, fmt.Errorf("frombus: the credentials of %s: %w", s.Node, err)
|
||||
}
|
||||
}
|
||||
out, skipped, _, err = composeEach(in, s.Node, fps, true, s.Running, held, ranOf(ctx, r, mesh, s.Running, fps), nil)
|
||||
out, skipped, _, err = composeEach(in, s.Node, fps, true, s.Running, held, ranOf(ctx, r, mesh, s.Running, fps), true)
|
||||
return out, skipped, held, err
|
||||
}
|
||||
|
||||
@@ -731,49 +731,56 @@ func ComposingInput(ctx context.Context, r Reader, mesh Mesh, s Scope, fps map[s
|
||||
// ComposeSent composes node from an input ComposingInput read, through the path Compose takes (composeEach, the read's holds
|
||||
// first): what a check's sandbox runs. False when the input says no way of composing node (an input from a node-engine
|
||||
// before ComposedHow): the caller cannot compose it as the node does. A node the change refuses is a *Refuses.
|
||||
func ComposeSent(in compose.Input, node string) (map[string]engcomp.Composed, bool, error) {
|
||||
//
|
||||
// It runs the one search for culprits (design 47 G §721; A-469j, A-468i): where the composition fails with no module held
|
||||
// that the node held neither in the read nor before the change, and no path owned twice names its owners, each of
|
||||
// s.Changed is held in turn, one composition each, and the first whose hold ends the problem (the try composes or fails
|
||||
// otherwise) is blamed with it. At most s.Tries tries; past them each module not yet tried is blamed NotTried. With no
|
||||
// tries there is no search: the failure is the node's own (err).
|
||||
func ComposeSent(in compose.Input, node string, s Search) (map[string]engcomp.Composed, bool, error) {
|
||||
c := in.ComposedHow
|
||||
if c == nil || c.Node != node {
|
||||
return nil, false, nil
|
||||
}
|
||||
held := maps.Clone(c.Held)
|
||||
if held == nil {
|
||||
held = map[string]string{}
|
||||
}
|
||||
twice := map[string][]resolution.OwnedTwice{}
|
||||
out, _, _, err := composeEach(in, node, c.Builds, false, c.Running, held, nil, func(culprit string, pairs []resolution.OwnedTwice) {
|
||||
for _, p := range pairs {
|
||||
if p.Modules[0] == culprit || p.Modules[1] == culprit {
|
||||
twice[culprit] = append(twice[culprit], p)
|
||||
compose1 := func(also string) (map[string]engcomp.Composed, map[string]string, error) {
|
||||
held := maps.Clone(c.Held)
|
||||
if held == nil {
|
||||
held = map[string]string{}
|
||||
}
|
||||
// A module the node holds composing without the change is held as there: the candidate keeps it as the node does,
|
||||
// which is no change and no search (issue 1126; design 47 G §721, HeldBefore left out of blamed).
|
||||
for m, why := range c.HeldBefore {
|
||||
if _, was := held[m]; !was {
|
||||
held[m] = why
|
||||
}
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
return nil, true, err
|
||||
if also != "" {
|
||||
held[also] = triedHeld
|
||||
}
|
||||
out, _, _, err := composeEach(in, node, c.Builds, false, c.Running, held, nil, false)
|
||||
return out, held, err
|
||||
}
|
||||
// A module the sandbox held that the node-engine held neither in the read nor composing without the change is the change
|
||||
// refusing it: the node does not compose, said in that module's words, never passed with the rest composed (issue 774,
|
||||
// review of the sandbox input).
|
||||
var refused []string
|
||||
blamed := map[string]string{}
|
||||
ours := func(m string) bool {
|
||||
_, was := c.Held[m]
|
||||
_, before := c.HeldBefore[m]
|
||||
return !was && !before
|
||||
}
|
||||
out, held, err := compose1("")
|
||||
// A module the sandbox held that the node-engine held neither in the read nor composing without the change is the change
|
||||
// refusing it: the node does not compose, said in that module's words, never passed with the rest composed (issue 774,
|
||||
// review of the sandbox input).
|
||||
var refused []string
|
||||
blamed := map[string]string{}
|
||||
for _, m := range sortedKeys(held) {
|
||||
if ours(m) {
|
||||
refused = append(refused, m+": "+held[m])
|
||||
blamed[m] = held[m]
|
||||
}
|
||||
}
|
||||
if len(refused) == 0 {
|
||||
return out, true, nil
|
||||
}
|
||||
// Two modules owning one path are each blamed, with that path, the one held for it and the one it was held beside
|
||||
// (design 47 G §721; A-468l).
|
||||
for _, m := range sortedKeys(blamed) {
|
||||
for _, p := range twice[m] {
|
||||
// Two modules owning one path are each blamed, with that path, outside the search (design 47 G §721; A-468l).
|
||||
var refusal *resolution.Refusal
|
||||
if err != nil && errors.As(err, &refusal) {
|
||||
for _, p := range refusal.OwnedTwice {
|
||||
words := fmt.Sprintf("%s and %s both declare the path %q", p.Modules[0], p.Modules[1], p.Path)
|
||||
for _, owner := range p.Modules {
|
||||
if ours(owner) {
|
||||
@@ -782,13 +789,48 @@ func ComposeSent(in compose.Input, node string) (map[string]engcomp.Composed, bo
|
||||
}
|
||||
}
|
||||
}
|
||||
e := &Refuses{Node: node, words: strings.Join(refused, "; ")}
|
||||
if err != nil && len(blamed) == 0 && s.Tries > 0 {
|
||||
problem := err.Error()
|
||||
for i, mod := range s.Changed {
|
||||
if i == s.Tries {
|
||||
for _, untried := range s.Changed[i:] {
|
||||
blamed[untried] = NotTried
|
||||
}
|
||||
break
|
||||
}
|
||||
if _, _, again := compose1(mod); again == nil || again.Error() != problem {
|
||||
blamed[mod] = problem
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(blamed) == 0 {
|
||||
return out, true, err
|
||||
}
|
||||
words := strings.Join(refused, "; ")
|
||||
if err != nil {
|
||||
words = err.Error()
|
||||
}
|
||||
e := &Refuses{Node: node, words: words}
|
||||
for _, m := range sortedKeys(blamed) {
|
||||
e.Blamed = append(e.Blamed, Blamed{Module: m, Problem: blamed[m]})
|
||||
}
|
||||
return nil, true, e
|
||||
}
|
||||
|
||||
// Search is the composer's one search for culprits in ComposeSent (design 47 G §721): the candidate's changed modules
|
||||
// placed on the node, in assignment order, and the request's blame_tries.
|
||||
type Search struct {
|
||||
Changed []string
|
||||
Tries int
|
||||
}
|
||||
|
||||
// NotTried is the problem of a changed module the search for culprits did not hold, its bound reached (design 47 G §721).
|
||||
const NotTried = "not tried: the search reached its bound"
|
||||
|
||||
// triedHeld is the words a module is held with while the search for culprits tries it.
|
||||
const triedHeld = "held by the composer's search for the module the machine's problem is of"
|
||||
|
||||
// Refuses is ComposeSent's refusal of a node by the change, answered structured (design 47 G §721; A-469j): each module
|
||||
// the sandbox held that its node-engine held neither in the read nor composing without the change (HeldBefore), and
|
||||
// each other owner of a path one of them was held for, with its problem.
|
||||
|
||||
Reference in New Issue
Block a user