Selfcompose, compose: the trunk build stands where a placement names none; the fallback is another node's only; only the store listen refusal holds fetchers (A-461b)
Builds: design 47 G A-461b
This commit is contained in:
@@ -98,9 +98,14 @@ func (c *composer) places(nodeName string, resolved Resolved) (Placed, error) {
|
||||
// Where no address is known (the holder opens no listen to the mesh, or two), only the modules that fetch from the store
|
||||
// wait, with the words of an unanswered requirement; the node composes the rest (design 47 G A-461, A-452).
|
||||
store, err := c.artifactStoreAddress(nodeName)
|
||||
if err != nil {
|
||||
var noAddress *storeListenError
|
||||
if errors.As(err, &noAddress) {
|
||||
// Only the store holder's listen refusal holds its fetchers; any other error still refuses the node (A-461b).
|
||||
out.storeHeld = modulesNeedingTheStore(plan.Modules, err)
|
||||
store = ""
|
||||
store, err = "", nil
|
||||
}
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
r.ArtifactStore = store
|
||||
r.Built = make(map[string]bool, len(c.in.Built))
|
||||
@@ -392,6 +397,11 @@ func (c *composer) storeHolders() map[string]catalogue.Manifest {
|
||||
return out
|
||||
}
|
||||
|
||||
// storeListenError is the refusal of a holder that opens no listen to the mesh, or two: the store has no address (A-461).
|
||||
type storeListenError struct{ said string }
|
||||
|
||||
func (e *storeListenError) Error() string { return e.said }
|
||||
|
||||
// storeListen is the store holder's listen every machine pulls from: its one listen open to the mesh. A holder opening
|
||||
// none, or more than one, says no address, by name: which of two ports is the store is no guess the composer makes.
|
||||
func storeListen(m catalogue.Manifest) (catalogue.Listening, error) {
|
||||
@@ -405,15 +415,15 @@ func storeListen(m catalogue.Manifest) (catalogue.Listening, error) {
|
||||
case 1:
|
||||
return open[0], nil
|
||||
case 0:
|
||||
return catalogue.Listening{}, fmt.Errorf("%s holds %s and opens no tcp listen to the mesh: the artifact store has no "+
|
||||
"address (novox/hq ADR 0632 §1)", m.Module, StoreSeat)
|
||||
return catalogue.Listening{}, &storeListenError{fmt.Sprintf("%s holds %s and opens no tcp listen to the mesh: the artifact store has no "+
|
||||
"address (novox/hq ADR 0632 §1)", m.Module, StoreSeat)}
|
||||
}
|
||||
var said []string
|
||||
for _, l := range open {
|
||||
said = append(said, fmt.Sprintf("%s (%d)", l.Name, l.Port))
|
||||
}
|
||||
return catalogue.Listening{}, fmt.Errorf("%s holds %s and opens %s to the mesh: the artifact store's address is its one "+
|
||||
"listen open to the mesh (novox/hq ADR 0632 §1)", m.Module, StoreSeat, strings.Join(said, ", "))
|
||||
return catalogue.Listening{}, &storeListenError{fmt.Sprintf("%s holds %s and opens %s to the mesh: the artifact store's address is its one "+
|
||||
"listen open to the mesh (novox/hq ADR 0632 §1)", m.Module, StoreSeat, strings.Join(said, ", "))}
|
||||
}
|
||||
|
||||
// artifactStoreOnNetwork is the machine on this network that holds the store's seat, and the port that machine put the
|
||||
|
||||
@@ -282,7 +282,7 @@ func (c *Composer) wantedBuilds() map[string]bool {
|
||||
}
|
||||
}
|
||||
// The build the assignment places for another node's module stands for its want where the running build has no entry (A-461).
|
||||
if built := c.placedBuild(node, module); !run.stopped && built != "" && strings.HasPrefix(built, meshcatalogclient.SourcePrefix2) {
|
||||
if built := c.placedBuild(node, module); c.lacksEntry(node, module, run) && strings.HasPrefix(built, meshcatalogclient.SourcePrefix2) {
|
||||
if _, named := out[built]; !named {
|
||||
out[built] = false
|
||||
}
|
||||
@@ -305,6 +305,7 @@ func (c *Composer) wantedBuilds() map[string]bool {
|
||||
// composes from, and lays the picture frombus reads (c.modules, c.manifests) from the entries it holds. It runs at the start of
|
||||
// each pass.
|
||||
func (c *Composer) syncEntries(ctx context.Context) {
|
||||
c.askTrunkBuilds()
|
||||
need := c.wantedBuilds()
|
||||
for fp := range need {
|
||||
c.entryOf(fp)
|
||||
@@ -407,7 +408,7 @@ func (c *Composer) layModules() {
|
||||
if !run.stopped && run.fingerprint != "" {
|
||||
// Where the running build has no entry, the module is laid from the entry of the build the assignment places
|
||||
// for that node, the mesh's truth of what it runs there (A-461); with neither it stays name-only below.
|
||||
if !lay(module, run.fingerprint) {
|
||||
if !lay(module, run.fingerprint) && node != c.env.Node {
|
||||
if built := c.placedBuild(node, module); built != "" && built != run.fingerprint {
|
||||
lay(module, built)
|
||||
}
|
||||
@@ -456,17 +457,60 @@ func (c *Composer) layModules() {
|
||||
c.modules = modules
|
||||
}
|
||||
|
||||
// placedBuild is the build the assignment places for module on node (c.mu held): empty where none is held or it names none (the
|
||||
// newest delivered of the branch, which the composer cannot name).
|
||||
// placedBuild is the build the assignment places for module on node (c.mu held), the mesh's truth of what it runs there; where the
|
||||
// placement names none, the module's trunk build as syncEntries asked it (A-461b). Empty where neither is known.
|
||||
func (c *Composer) placedBuild(node, module string) string {
|
||||
for _, pm := range c.assignments[node].Modules {
|
||||
if pm.Module == module {
|
||||
return pm.Build
|
||||
if pm.Build != "" {
|
||||
return pm.Build
|
||||
}
|
||||
return c.trunkBuilds[module].fp
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// lacksEntry says whether the build another node's module runs has no entry held (c.mu held): the only case the placed build stands
|
||||
// in (A-461b). It is never so for this node's own modules.
|
||||
func (c *Composer) lacksEntry(node, module string, run heardRun) bool {
|
||||
if node == c.env.Node || run.stopped || run.fingerprint == "" {
|
||||
return false
|
||||
}
|
||||
k, ok := c.keptEnt[run.fingerprint]
|
||||
return !ok || k.entry.Module == ""
|
||||
}
|
||||
|
||||
// askTrunkBuilds asks, for each module another node runs at a build with no entry and whose placement names no build, the trunk
|
||||
// build by the seat's verb `module`, once per running build (A-461b). Called before the lock is taken: the verb is a call.
|
||||
func (c *Composer) askTrunkBuilds() {
|
||||
type ask struct{ node, module, running string }
|
||||
var asks []ask
|
||||
c.mu.Lock()
|
||||
for node, mods := range c.heard {
|
||||
for module, run := range mods {
|
||||
if !c.lacksEntry(node, module, run) {
|
||||
continue
|
||||
}
|
||||
for _, pm := range c.assignments[node].Modules {
|
||||
if pm.Module == module && pm.Build == "" && c.trunkBuilds[module].running != run.fingerprint {
|
||||
asks = append(asks, ask{node, module, run.fingerprint})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
c.mu.Unlock()
|
||||
for _, a := range asks {
|
||||
fp, _ := c.trunkFp(a.module)
|
||||
c.mu.Lock()
|
||||
if c.trunkBuilds == nil {
|
||||
c.trunkBuilds = map[string]trunkBuild{}
|
||||
}
|
||||
c.trunkBuilds[a.module] = trunkBuild{running: a.running, fp: fp}
|
||||
c.mu.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
// entryManifest is an entry's manifest as a reader takes it, with its digest: the one the indexer set at take-in, or, where it set
|
||||
// none, the digest of the manifest's bytes.
|
||||
func entryManifest(e meshcatalog.CatalogEntry) (digest string, raw []byte, err error) {
|
||||
@@ -675,30 +719,38 @@ func (c *Composer) syncShadowEntries(ctx context.Context) (pending bool) {
|
||||
// moduleVerb is the seat mesh-catalog's verb `module`: one module's trunk fingerprint and manifest by name.
|
||||
const moduleVerb = "seat:" + meshcatalog.Seat + "." + meshcatalog.VerbModule
|
||||
|
||||
// trunkFp is the fingerprint of a module's trunk build, by the seat's verb `module`; empty with why where the catalog half gives none.
|
||||
func (c *Composer) trunkFp(module string) (fp, why string) {
|
||||
if c.env.Entry == nil {
|
||||
return "", "this node reads no module of the catalog half"
|
||||
}
|
||||
raw, err := c.env.Entry(moduleVerb, meshcatalog.ModuleInput{Module: module})
|
||||
if err != nil {
|
||||
return "", fmt.Sprintf("the catalog half's answer for %s: %v", module, err)
|
||||
}
|
||||
answer, said, ok := buscalls.Unwrap(raw)
|
||||
if !ok {
|
||||
return "", fmt.Sprintf("the catalog half holds no module %s: %s", module, said)
|
||||
}
|
||||
var a meshcatalog.ModuleAnswer
|
||||
if err := json.Unmarshal(answer, &a); err != nil {
|
||||
return "", fmt.Sprintf("the catalog half's answer for %s cannot be read: %v", module, err)
|
||||
}
|
||||
if a.Module.Fp == "" {
|
||||
return "", fmt.Sprintf("the catalog half gives %s no fingerprint: %s", module, a.Module.None)
|
||||
}
|
||||
return a.Module.Fp, ""
|
||||
}
|
||||
|
||||
// addedModule is the trunk's build of a module an assignment candidate adds to this node when no want here names it yet: the
|
||||
// fingerprint the seat's verb `module` answers, then its entry by the verb `entry` as for a wanted module (design 47 G §421, A-312).
|
||||
// A call, not a watch: nothing of the catalog is kept. It answers the entry when held; otherwise why not: a module with no
|
||||
// fingerprint says the verb's reason, an entry asked says so (its answer wakes the shadow, which composes again).
|
||||
func (c *Composer) addedModule(ctx context.Context, module string) (fp string, entry meshcatalog.CatalogEntry, held, pending bool, why string) {
|
||||
if c.env.Entry == nil {
|
||||
return "", entry, false, false, "this node reads no module of the catalog half"
|
||||
fp, why = c.trunkFp(module)
|
||||
if fp == "" {
|
||||
return "", entry, false, false, why
|
||||
}
|
||||
raw, err := c.env.Entry(moduleVerb, meshcatalog.ModuleInput{Module: module})
|
||||
if err != nil {
|
||||
return "", entry, false, false, fmt.Sprintf("the catalog half's answer for %s: %v", module, err)
|
||||
}
|
||||
answer, said, ok := buscalls.Unwrap(raw)
|
||||
if !ok {
|
||||
return "", entry, false, false, fmt.Sprintf("the catalog half holds no module %s: %s", module, said)
|
||||
}
|
||||
var a meshcatalog.ModuleAnswer
|
||||
if err := json.Unmarshal(answer, &a); err != nil {
|
||||
return "", entry, false, false, fmt.Sprintf("the catalog half's answer for %s cannot be read: %v", module, err)
|
||||
}
|
||||
if a.Module.Fp == "" {
|
||||
return "", entry, false, false, fmt.Sprintf("the catalog half gives %s no fingerprint: %s", module, a.Module.None)
|
||||
}
|
||||
fp = a.Module.Fp
|
||||
c.mu.Lock()
|
||||
if c.addedFps == nil {
|
||||
c.addedFps = map[string]bool{}
|
||||
|
||||
@@ -341,37 +341,43 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) {
|
||||
if still {
|
||||
t.Error("an entry of the running build was answered, and the composition was not handed again")
|
||||
}
|
||||
}
|
||||
|
||||
// A-461: another node's module whose running build has no entry is laid from the entry of the build the assignment places for it
|
||||
// on that node; where neither has one, it stays as its name alone.
|
||||
func TestAnotherNodesModuleIsLaidFromItsPlacedBuildWhenItsRunningBuildHasNoEntry(t *testing.T) {
|
||||
running := meshcatalogclient.SourcePrefix2 + strings.Repeat("1", 64)
|
||||
placed := meshcatalogclient.SourcePrefix2 + strings.Repeat("2", 64)
|
||||
body := `{"module":"distribution","version":"2"}`
|
||||
// A-461, A-461a, A-461b: another node's module whose running build has no entry is laid from the entry of the build the assignment
|
||||
// places for it on that node, or, where the placement names none, of its trunk build; with neither entry it stays as its name
|
||||
// alone, and this node's own module is never laid from a placement.
|
||||
placedFp := meshcatalogclient.SourcePrefix2 + strings.Repeat("3", 64)
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
build string
|
||||
holds bool
|
||||
laid bool
|
||||
name string
|
||||
node string
|
||||
build, trunk string
|
||||
holds, laid bool
|
||||
}{
|
||||
{"placed build has an entry", placed, true, true},
|
||||
{"neither build has an entry", placed, false, false},
|
||||
{"placement names no build", "", false, false},
|
||||
{"placed build has an entry", "n2", placedFp, "", true, true},
|
||||
{"neither build has an entry", "n2", placedFp, "", false, false},
|
||||
{"placement names no build, trunk build has an entry", "n2", "", placedFp, true, true},
|
||||
{"placement names no build, trunk names none", "n2", "", "", false, false},
|
||||
{"this node's own module is not laid from a placement", "n1", placedFp, "", true, false},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
env := newFakeBus().env()
|
||||
env.Node = "n1"
|
||||
env.Entry = EntryCall(func(_ context.Context, _, verb string, _ any) (json.RawMessage, error) {
|
||||
if verb == meshcatalog.VerbModule {
|
||||
return json.Marshal(meshcatalog.ModuleAnswer{Module: meshcatalog.ModuleAnswerModule{Fp: tc.trunk}})
|
||||
}
|
||||
return nil, errors.New("not held")
|
||||
})
|
||||
c := New(env)
|
||||
c.mu.Lock()
|
||||
c.assignments["n2"] = meshmoduleassigner.Assignments{Node: "n2", Modules: []meshmoduleassigner.PlacedModule{{Module: "distribution", Build: tc.build}}}
|
||||
c.heard = map[string]map[string]heardRun{"n2": {"distribution": {fingerprint: running}}}
|
||||
c.assignments[tc.node] = meshmoduleassigner.Assignments{Node: tc.node, Modules: []meshmoduleassigner.PlacedModule{{Module: "distribution", Build: tc.build}}}
|
||||
c.heard = map[string]map[string]heardRun{tc.node: {"distribution": {fingerprint: old}}}
|
||||
c.mu.Unlock()
|
||||
if tc.holds {
|
||||
c.holdEntry(t, "distribution", placed, body)
|
||||
c.holdEntry(t, "distribution", placedFp, `{"module":"distribution","version":"2"}`)
|
||||
}
|
||||
if _, asked := c.wantedBuilds()[placed]; asked != (tc.build != "") {
|
||||
t.Errorf("the placed build asked = %v, want %v", asked, tc.build != "")
|
||||
c.askTrunkBuilds()
|
||||
if _, asked := c.wantedBuilds()[placedFp]; asked != (tc.node == "n2" && (tc.build != "" || tc.trunk != "")) {
|
||||
t.Errorf("the placed build asked = %v", asked)
|
||||
}
|
||||
c.layModules()
|
||||
c.mu.Lock()
|
||||
|
||||
@@ -209,8 +209,10 @@ type Composer struct {
|
||||
addedFps map[string]bool
|
||||
// heard is, by node and module, what each node's event running last said it runs, kept from the seat's stream by this
|
||||
// node's own consumer (NoteRunning), under mu; heardRead is whether the first read of the stream ended (RunningRead).
|
||||
heard map[string]map[string]heardRun
|
||||
heardRead bool
|
||||
heard map[string]map[string]heardRun
|
||||
// trunkBuilds is, by module, the trunk build asked for another node's module whose placement names none, with the running build it was asked for (A-461b).
|
||||
trunkBuilds map[string]trunkBuild
|
||||
heardRead bool
|
||||
// ends is, by module, the last build end naming no branch the builder said of it (NoteBuildEnded), its newest build that
|
||||
// ended, under mu; endsRead is whether the first read of the builder's stream ended (BuildEndsRead) (design 47 G A-293).
|
||||
ends map[string]builds.BuildEnded
|
||||
@@ -2311,6 +2313,8 @@ func (c *Composer) WhyUnmade(module string) string {
|
||||
return c.last.Unmade[module]
|
||||
}
|
||||
|
||||
type trunkBuild struct{ running, fp string }
|
||||
|
||||
// heardRun is one running event as the composer keeps it, with when it was said.
|
||||
type heardRun struct {
|
||||
at time.Time
|
||||
|
||||
Reference in New Issue
Block a user