Node-engine: a running module without an entry resolves as the newest build its want names
Builds: design 47 G §421, lead answers A-405 and A-407
This commit is contained in:
@@ -228,6 +228,12 @@ func (c *Composer) wantedBuilds() map[string]bool {
|
|||||||
if module != agent.NodeModule && strings.HasPrefix(w.Fp, meshcatalogclient.SourcePrefix2) {
|
if module != agent.NodeModule && strings.HasPrefix(w.Fp, meshcatalogclient.SourcePrefix2) {
|
||||||
out[w.Fp] = true
|
out[w.Fp] = true
|
||||||
}
|
}
|
||||||
|
// The build its want says is being built describes, for resolution alone, a module whose wanted build has no entry (A-405, A-407).
|
||||||
|
if module != agent.NodeModule && strings.HasPrefix(w.Newest, meshcatalogclient.SourcePrefix2) {
|
||||||
|
if _, named := out[w.Newest]; !named {
|
||||||
|
out[w.Newest] = false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for _, mods := range c.heard {
|
for _, mods := range c.heard {
|
||||||
for _, run := range mods {
|
for _, run := range mods {
|
||||||
@@ -309,6 +315,12 @@ func (c *Composer) syncEntries(ctx context.Context) {
|
|||||||
// layModules lays c.modules and c.manifests from the entries held: what each node was heard to run first, then each module this
|
// layModules lays c.modules and c.manifests from the entries held: what each node was heard to run first, then each module this
|
||||||
// node's want names, at the want's fingerprint (a want wins).
|
// node's want names, at the want's fingerprint (a want wins).
|
||||||
func (c *Composer) layModules() {
|
func (c *Composer) layModules() {
|
||||||
|
var said []string
|
||||||
|
defer func() {
|
||||||
|
for _, line := range said {
|
||||||
|
c.sayOnceEach(line)
|
||||||
|
}
|
||||||
|
}()
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
modules := map[string]meshcatalog.ModulesByModuleValue{}
|
modules := map[string]meshcatalog.ModulesByModuleValue{}
|
||||||
@@ -343,9 +355,26 @@ func (c *Composer) layModules() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for module, w := range c.wants {
|
for module, w := range c.wants {
|
||||||
if module != agent.NodeModule && w.Fp != "" {
|
if module == agent.NodeModule || w.Fp == "" {
|
||||||
lay(module, w.Fp)
|
continue
|
||||||
}
|
}
|
||||||
|
if k, ok := c.keptEnt[w.Fp]; ok && k.entry.Module != "" {
|
||||||
|
lay(module, w.Fp)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// A module the node runs whose wanted build has no entry stands as the build its want says is being built, for resolution
|
||||||
|
// alone: what that entry provides, claims and requires stands for the running build. Its want stays held (entryHolds), at
|
||||||
|
// the want's fingerprint, and nothing new of it is composed (A-405, A-407).
|
||||||
|
if k, ok := c.keptEnt[w.Newest]; ok && w.Newest != "" && k.entry.Module != "" && c.runsHere(module) {
|
||||||
|
lay(module, w.Newest)
|
||||||
|
if m, laid := modules[module]; laid {
|
||||||
|
m.Fp2 = w.Fp
|
||||||
|
modules[module] = m
|
||||||
|
said = append(said, fmt.Sprintf("%s runs a build whose entry the catalog half does not hold, so the node resolves around it as the build %s its want says is being built; its want stays held", module, w.Newest))
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
lay(module, w.Fp)
|
||||||
}
|
}
|
||||||
// A module an assignment places whose entry is not held (not wanted here, not heard running, or its entry asked and not
|
// A module an assignment places whose entry is not held (not wanted here, not heard running, or its entry asked and not
|
||||||
// answered) stands in the catalogue as its name alone, so the placement still finds it: a module held for its entry offers
|
// answered) stands in the catalogue as its name alone, so the placement still finds it: a module held for its entry offers
|
||||||
@@ -651,3 +680,19 @@ func (c *Composer) askBuildsEntries(fps map[string]string) (pending string) {
|
|||||||
}
|
}
|
||||||
return pending
|
return pending
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// runsHere says whether this node runs the module: heard to, or in what the node runs now (c.mu held; env.Running reads the
|
||||||
|
// agent's own record).
|
||||||
|
func (c *Composer) runsHere(module string) bool {
|
||||||
|
if run, ok := c.heard[c.env.Node][module]; ok && !run.stopped {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if c.env.Running != nil {
|
||||||
|
for _, r := range c.env.Running() {
|
||||||
|
if r.Module == module {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
@@ -259,3 +259,55 @@ func (c *Composer) holdEntry(t *testing.T, module, fp, body string) {
|
|||||||
}
|
}
|
||||||
c.keptEnt[fp] = keptEntry{entry: half[fp]}
|
c.keptEnt[fp] = keptEntry{entry: half[fp]}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A-405, A-407: a module the node runs whose wanted build has no entry stands, for resolution alone, as the build its want says
|
||||||
|
// is being built, at the want's fingerprint, so its want stays held; one not running here, or whose want names no newer build the
|
||||||
|
// half holds, stands as its name alone.
|
||||||
|
func TestRunningModuleWithoutEntryStandsAsTheNewestBuild(t *testing.T) {
|
||||||
|
old := meshcatalogclient.SourcePrefix2 + strings.Repeat("1", 64)
|
||||||
|
newest := meshcatalogclient.SourcePrefix2 + strings.Repeat("2", 64)
|
||||||
|
body := `{"module":"postgres","version":"2"}`
|
||||||
|
for _, tc := range []struct {
|
||||||
|
name string
|
||||||
|
runs bool
|
||||||
|
newest string
|
||||||
|
holds bool
|
||||||
|
laid bool
|
||||||
|
wantFp string
|
||||||
|
}{
|
||||||
|
{"runs, newest entry held", true, newest, true, true, old},
|
||||||
|
{"not running here", false, newest, true, false, old},
|
||||||
|
{"names no newer build", true, "", false, false, old},
|
||||||
|
{"newest entry not held", true, newest, false, false, old},
|
||||||
|
} {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
env := newFakeBus().env()
|
||||||
|
env.Node = "n1"
|
||||||
|
c := New(env)
|
||||||
|
c.mu.Lock()
|
||||||
|
c.wants["postgres"] = meshwants.WantsByWantNodeModuleValue{Fp: old, Newest: tc.newest}
|
||||||
|
c.assignments["n1"] = meshmoduleassigner.Assignments{Node: "n1", Modules: []meshmoduleassigner.PlacedModule{{Module: "postgres"}}}
|
||||||
|
if tc.runs {
|
||||||
|
c.heard = map[string]map[string]heardRun{"n1": {"postgres": {fingerprint: old}}}
|
||||||
|
}
|
||||||
|
c.mu.Unlock()
|
||||||
|
if tc.holds {
|
||||||
|
c.holdEntry(t, "postgres", newest, body)
|
||||||
|
}
|
||||||
|
if got := c.wantedBuilds()[newest]; tc.newest != "" && got {
|
||||||
|
t.Errorf("the newest build is named by a want, want only asked")
|
||||||
|
}
|
||||||
|
c.layModules()
|
||||||
|
c.mu.Lock()
|
||||||
|
m, ok := c.modules["postgres"]
|
||||||
|
raw := c.manifests[m.Manifest]
|
||||||
|
c.mu.Unlock()
|
||||||
|
if !ok || m.Fp2 != tc.wantFp {
|
||||||
|
t.Fatalf("modules[postgres] = %+v (%v), want fingerprint %s", m, ok, tc.wantFp)
|
||||||
|
}
|
||||||
|
if got := strings.Contains(string(raw), `"version":"2"`); got != tc.laid {
|
||||||
|
t.Errorf("manifest of the newest build laid = %v, want %v (%s)", got, tc.laid, raw)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user