B17 build-holds-its-entry: a build takes the newest entry of its fingerprint and its origin at its start; an older revision's entry never moves the origin back
Builds: design 47 H2 H-A-707 (1) (2)
This commit is contained in:
@@ -311,7 +311,11 @@ func (b *Builder) take(ctx context.Context, o Origin, key string, m meshcatalog.
|
||||
if bk, err := builds.BuilderBuildKey(key, m.Fp2); err == nil && m.Fp2 != "" {
|
||||
// A fingerprint a watched branch carries is built from that branch's commit, whoever asked for it first.
|
||||
b.trunkFP[bk] = true
|
||||
b.origin[bk] = o
|
||||
// The key's origin is never moved back (design 47 H2 H-A-707 (2)): an entry of an older revision with the same fingerprint
|
||||
// leaves the origin of the newer one as it was.
|
||||
if cur, held := b.origin[bk]; !held || !originNewer(cur, o) {
|
||||
b.origin[bk] = o
|
||||
}
|
||||
b.edges[bk] = e
|
||||
}
|
||||
b.mu.Unlock()
|
||||
@@ -339,7 +343,7 @@ const withdrawnPrefix = "withdrawn: "
|
||||
|
||||
// supersededBy is the fingerprint that supersedes fp, a fingerprint of module whose build key is key, when fp is of its
|
||||
// registration's first watched branch and is no longer the newest entry heard on that branch (H-A-489); "" otherwise. A key no
|
||||
// entry named is of the first branch, as originOf has it.
|
||||
// entry named is of the first branch, as originLocked has it.
|
||||
func (b *Builder) supersededBy(module, key, fp string) string {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
@@ -433,17 +437,38 @@ func everyArtifactNamesPaths(e meshcatalog.CatalogEntry) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// originOf is the catalog revision the entry of a build key came from; a key no entry named is of the first branch, as a build
|
||||
// of the trunk's value was before branches were watched.
|
||||
func (b *Builder) originOf(key string) Origin {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
// originLocked is the catalog revision the entry of a build key came from; a key no entry named is of the first branch, as a build
|
||||
// of the trunk's value was before branches were watched. It is read under the lock the caller holds.
|
||||
func (b *Builder) originLocked(key string) Origin {
|
||||
if o, ok := b.origin[key]; ok {
|
||||
return o
|
||||
}
|
||||
return Origin{First: true}
|
||||
}
|
||||
|
||||
// originNewer says whether the origin cur is of a newer module graph revision than o: known by their revisions, else their sources.
|
||||
func originNewer(cur, o Origin) bool {
|
||||
newer, known := newerRevision(cur, o)
|
||||
return known && newer
|
||||
}
|
||||
|
||||
// entryAndOrigin is what a build holds from its start (design 47 H2 H-A-707 (1)): the entry its picture holds for the module on the
|
||||
// branch of the key's origin when that entry is of the key's fingerprint, with the origin it was heard at, else the entry that woke it
|
||||
// with the key's origin. Taken under one lock, it is read by the build's reservation, pins and revision wait, never the key's origin
|
||||
// as it stands later.
|
||||
func (b *Builder) entryAndOrigin(module, key string, woke meshcatalog.ModulesByModuleValue) (meshcatalog.ModulesByModuleValue, Origin) {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
o := b.originLocked(key)
|
||||
if h, ok := b.heard[o.Branch+"\x00"+module]; ok && h.Fp2 == woke.Fp2 {
|
||||
if at, ok := b.heardAt[o.Branch+"\x00"+module]; ok {
|
||||
return h, at
|
||||
}
|
||||
return h, o
|
||||
}
|
||||
return woke, o
|
||||
}
|
||||
|
||||
// NodesChanged is Reconsider after a toolchain moved, so a build that waited for the nodes to agree on one may go on.
|
||||
func (b *Builder) NodesChanged(ctx context.Context) { b.Reconsider(ctx) }
|
||||
|
||||
@@ -704,6 +729,7 @@ func (b *Builder) startOnce(ctx context.Context, key, module string, m meshcatal
|
||||
// building by this builder: it takes it again when it starts (ADR 0478 clause 5).
|
||||
func (b *Builder) try(ctx context.Context, module string, m meshcatalog.ModulesByModuleValue) {
|
||||
key, _ := builds.BuilderBuildKey(module, m.Fp2)
|
||||
m, origin := b.entryAndOrigin(module, key, m) // the build holds one entry and its origin (design 47 H2 H-A-707 (1))
|
||||
whyEnded := ""
|
||||
defer func() { b.handEnded(key, whyEnded) }()
|
||||
defer b.unrelease(key)
|
||||
@@ -752,8 +778,8 @@ func (b *Builder) try(ctx context.Context, module string, m meshcatalog.ModulesB
|
||||
delete(b.events, key)
|
||||
b.mu.Unlock()
|
||||
// Only a build of the registration's first watched branch reserves and releases a version (design 47 G §371).
|
||||
reserving := trunk && b.originOf(key).First && planErr == nil && !nothing && b.reserves(ctx, module, m, plan)
|
||||
if trunk && b.originOf(key).First && planErr == nil && !nothing && !reserving {
|
||||
reserving := trunk && origin.First && planErr == nil && !nothing && b.reserves(ctx, module, m, plan)
|
||||
if trunk && origin.First && planErr == nil && !nothing && !reserving {
|
||||
// A done build whose digests its end did not record is recorded at the next look (design 47 H2 H-A-492).
|
||||
if _, err := b.RecordAgain(ctx, module, m.Fp2, "at a look"); err != nil {
|
||||
b.logf("%v", err)
|
||||
@@ -807,12 +833,12 @@ func (b *Builder) try(ctx context.Context, module string, m meshcatalog.ModulesB
|
||||
// Reserved as A-490b amended by H-A-225 has it: this fingerprint's standing reservation is kept while it is unreleased
|
||||
// and above the highest the catalog's versions answers, else the next above that highest is taken (A-455); the build's
|
||||
// own publish then runs.
|
||||
reserved, hasReserved = b.reserve(ctx, module, m, plan, b.originOf(key), true)
|
||||
reserved, hasReserved = b.reserve(ctx, module, m, plan, origin, true)
|
||||
reserving = true
|
||||
} else if reserving && cl.Build.State != builds.BuildDone {
|
||||
// Looked at again just before it reserves (H-A-489): a newer entry heard since the claim is not taken over.
|
||||
if supersededNow = b.supersededBy(module, key, m.Fp2); supersededNow == "" {
|
||||
reserved, hasReserved = b.reserve(ctx, module, m, plan, b.originOf(key), false)
|
||||
reserved, hasReserved = b.reserve(ctx, module, m, plan, origin, false)
|
||||
}
|
||||
}
|
||||
if hasReserved && supersededNow == "" && cl.Build.State != builds.BuildDone {
|
||||
|
||||
@@ -184,6 +184,7 @@ func TestABuildStepPassesAReservingBuildOnlyWithItsReservedVersion(t *testing.T)
|
||||
}
|
||||
t.Run("H-A-508: built now, superseded: a newer entry heard while the build runs ends the step superseded", aNewerEntryWhileTheBuildRunsSupersedesTheStep)
|
||||
t.Run("H-A-650: a superseded end the builder knows no revision for is could-not-run, never superseded with a zero", aSupersededEndWithNoRevisionIsCouldNotRun)
|
||||
t.Run("H-A-707 (1) (2): a build holds the newest entry of its fingerprint and its origin, which an older entry never moves back", aBuildHoldsItsNewestEntryAndOrigin)
|
||||
t.Run("H-A-155: an ask waits for the picture to take its revision in, then builds with its version reserved", aStepAskWaitsForItsRevision)
|
||||
t.Run("H-A-155: past the bound the ask fails naming its revision, and nothing is built", aStepAskPastItsRevisionBoundFails)
|
||||
t.Run("H-A-205: an ask of a revision below the picture's newest is read by number and built", anOlderKeptRevisionIsReadByNumber)
|
||||
@@ -777,3 +778,36 @@ func aSupersededEndWithNoRevisionIsCouldNotRun(t *testing.T) {
|
||||
t.Errorf("end = %+v, want could not run naming that no superseding revision was heard", end)
|
||||
}
|
||||
}
|
||||
|
||||
func aBuildHoldsItsNewestEntryAndOrigin(t *testing.T) {
|
||||
var held atomic.Int64
|
||||
r, _, entry := revisionRig(t, &held, make(chan struct{}, 1))
|
||||
key, _ := builds.BuilderBuildKey("m", fp1)
|
||||
val := func(commit string) meshcatalog.ModulesByModuleValue {
|
||||
v, err := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Repository: "novox/mesh-catalog", Commit: commit, Fp2: fp1, Manifest: mdigest('a'), Path: "modules/m", Toolchains: CatalogToolchains(agreedToolchains)})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m, _ := meshcatalogclient.DecodeModule(v)
|
||||
return m
|
||||
}
|
||||
_ = entry
|
||||
r.b.init()
|
||||
o511 := Origin{Branch: "main", Source: 155, Revision: 511, First: true}
|
||||
o510 := Origin{Branch: "main", Source: 154, Revision: 510, First: true}
|
||||
r.b.take(t.Context(), o511, "m", val("7a74cee83f88e6585a5511c3cc53bdf0f5303d20"), nil)
|
||||
r.b.Wait()
|
||||
r.b.take(t.Context(), o510, "m", val("1111111111111111111111111111111111111111"), nil) // the same fingerprint, an older revision's entry
|
||||
r.b.Wait()
|
||||
r.b.mu.Lock()
|
||||
got := r.b.origin[key]
|
||||
r.b.mu.Unlock()
|
||||
if got != o511 {
|
||||
t.Errorf("the key's origin is %+v after an older revision's entry was taken; want revision 511's %+v as it was", got, o511)
|
||||
}
|
||||
// a build woken by revision 510's value takes the entry its picture holds, revision 511's, with its origin
|
||||
m, o := r.b.entryAndOrigin("m", key, val("1111111111111111111111111111111111111111"))
|
||||
if o != o511 || m.Commit != "7a74cee83f88e6585a5511c3cc53bdf0f5303d20" {
|
||||
t.Errorf("the build woken by revision 510's value holds %+v at %+v; want revision 511's entry and origin", m.Commit, o)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user