Selfcompose: another node's module whose running build has no entry is laid from its placed build's entry (A-461, A-461a)
Builds: design 47 G A-461 (first sentence), A-461a
This commit is contained in:
@@ -274,13 +274,19 @@ func (c *Composer) wantedBuilds() map[string]bool {
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, mods := range c.heard {
|
||||
for _, run := range mods {
|
||||
for node, mods := range c.heard {
|
||||
for module, run := range mods {
|
||||
if !run.stopped && strings.HasPrefix(run.fingerprint, meshcatalogclient.SourcePrefix2) {
|
||||
if _, named := out[run.fingerprint]; !named {
|
||||
out[run.fingerprint] = false
|
||||
}
|
||||
}
|
||||
// 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 _, named := out[built]; !named {
|
||||
out[built] = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// The build each module runs here, as the node's own record of it says: its entry, kept in the composition state, stays held
|
||||
@@ -372,15 +378,15 @@ func (c *Composer) layModules() {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
modules := map[string]meshcatalog.ModulesByModuleValue{}
|
||||
lay := func(module, fp string) {
|
||||
lay := func(module, fp string) bool {
|
||||
k, ok := c.keptEnt[fp]
|
||||
if !ok || k.entry.Module == "" {
|
||||
return
|
||||
return false
|
||||
}
|
||||
e := k.entry
|
||||
digest, raw, err := entryManifest(e)
|
||||
if err != nil {
|
||||
return
|
||||
return false
|
||||
}
|
||||
m := meshcatalog.ModulesByModuleValue{Fp2: fp, Manifest: digest, Repository: e.Repository, Commit: e.Commit, Path: e.Path,
|
||||
Needs: e.Needs, Packages: e.Packages, Verdict: e.Verdict}
|
||||
@@ -389,6 +395,7 @@ func (c *Composer) layModules() {
|
||||
}
|
||||
modules[module] = m
|
||||
c.manifests[digest] = raw
|
||||
return true
|
||||
}
|
||||
nodes := make([]string, 0, len(c.heard))
|
||||
for node := range c.heard {
|
||||
@@ -398,7 +405,13 @@ func (c *Composer) layModules() {
|
||||
for _, node := range nodes {
|
||||
for module, run := range c.heard[node] {
|
||||
if !run.stopped && run.fingerprint != "" {
|
||||
lay(module, 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 built := c.placedBuild(node, module); built != "" && built != run.fingerprint {
|
||||
lay(module, built)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -443,6 +456,17 @@ 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).
|
||||
func (c *Composer) placedBuild(node, module string) string {
|
||||
for _, pm := range c.assignments[node].Modules {
|
||||
if pm.Module == module {
|
||||
return pm.Build
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// 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) {
|
||||
|
||||
@@ -342,3 +342,45 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) {
|
||||
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"}`
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
build string
|
||||
holds bool
|
||||
laid bool
|
||||
}{
|
||||
{"placed build has an entry", placed, true, true},
|
||||
{"neither build has an entry", placed, false, false},
|
||||
{"placement names no build", "", false, false},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
env := newFakeBus().env()
|
||||
env.Node = "n1"
|
||||
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.mu.Unlock()
|
||||
if tc.holds {
|
||||
c.holdEntry(t, "distribution", placed, body)
|
||||
}
|
||||
if _, asked := c.wantedBuilds()[placed]; asked != (tc.build != "") {
|
||||
t.Errorf("the placed build asked = %v, want %v", asked, tc.build != "")
|
||||
}
|
||||
c.layModules()
|
||||
c.mu.Lock()
|
||||
m, ok := c.modules["distribution"]
|
||||
raw := c.manifests[m.Manifest]
|
||||
c.mu.Unlock()
|
||||
if got := ok && strings.Contains(string(raw), `"version":"2"`); got != tc.laid {
|
||||
t.Errorf("laid from the placed build = %v, want %v (%+v %s)", got, tc.laid, m, raw)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user